Compilation fails after re-installing Ubuntu 12.04

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
snasim2002
Member
Member
Posts: 37
Joined: Sat Apr 11, 2015 9:37 am

Compilation fails after re-installing Ubuntu 12.04

Post by snasim2002 »

I recently re-installed Ubuntu 12.04 LTS. Before I Did that, all of the source code compiled (and ran in qemu) correctly. Now, every time i try to compile the code, it ends up in this error messege:

Code: Select all

echo "** Building Core files.."
** Building Core files..
nasm -f elf32 kernel/kernel.asm -o kasm.o
echo "		*** *** Kernel."
		*** *** Kernel.
gcc -m32 -nostdlib -nostdinc -w -I./include  -c kernel/kernel.c -o kernel.o
gcc -m32 -nostdlib -nostdinc -w -I./include  -c kernel/io.c -o io.o
nasm -f elf32 kernel/int32.asm -o int32.o
echo "		*** *** GDT."
		*** *** GDT.
gcc -m32 -nostdlib -nostdinc -w -I./include  -c kernel/gdt.c -o gdt.o
echo "		*** *** IDT."
		*** *** IDT.
gcc -m32 -nostdlib -nostdinc -w -I./include  -c kernel/idt.c -o idt.o
echo "		*** *** ISRs."
		*** *** ISRs.
gcc -m32 -nostdlib -nostdinc -w -I./include  -c kernel/isrs.c -o isrs.o
echo "		*** *** IRQ."
		*** *** IRQ.
gcc -m32 -nostdlib -nostdinc -w -I./include  -c kernel/irq.c -o irq.o
echo "** Finished building Core files."
** Finished building Core files.
echo "** Building Kernel Drivers.."
** Building Kernel Drivers..
gcc -m32 -nostdlib -nostdinc -w -I./include  -c drivers/display/screen.c -o screen.o
echo "		*** *** Display."
		*** *** Display.
gcc -m32 -nostdlib -nostdinc -w -I./include  -c drivers/keyboard/kb.c -o kb.o
echo "		*** *** PS/2 Keyboard."
		*** *** PS/2 Keyboard.
echo "** Finished Building Kernel drivers."
** Finished Building Kernel drivers.
echo "** Linking Stuffs Together.."
** Linking Stuffs Together..
ld  -m elf_i386 -T scripts/link.ld -o kernel.bin kasm.o kernel.o int32.o io.o screen.o gdt.o idt.o isrs.o irq.o kb.o
ld: warning: cannot find entry symbol start; defaulting to 0000000000100000
gdt.o: In function `gdt_install':
gdt.c:(.text+0x139): undefined reference to `gdt_flush'
idt.o: In function `idt_install':
idt.c:(.text+0x95): undefined reference to `idt_load'
isrs.o: In function `isrs_install':
isrs.c:(.text+0x7): undefined reference to `isr0'
isrs.c:(.text+0x2c): undefined reference to `isr1'
isrs.c:(.text+0x51): undefined reference to `isr2'
isrs.c:(.text+0x76): undefined reference to `isr3'
isrs.c:(.text+0x9b): undefined reference to `isr4'
isrs.c:(.text+0xc0): undefined reference to `isr5'
isrs.c:(.text+0xe5): undefined reference to `isr6'
isrs.c:(.text+0x10a): undefined reference to `isr7'
isrs.c:(.text+0x12f): undefined reference to `isr8'
isrs.c:(.text+0x154): undefined reference to `isr9'
isrs.c:(.text+0x179): undefined reference to `isr10'
isrs.c:(.text+0x19e): undefined reference to `isr11'
isrs.c:(.text+0x1c3): undefined reference to `isr12'
isrs.c:(.text+0x1e8): undefined reference to `isr13'
isrs.c:(.text+0x20d): undefined reference to `isr14'
isrs.c:(.text+0x232): undefined reference to `isr15'
isrs.c:(.text+0x257): undefined reference to `isr16'
isrs.c:(.text+0x27c): undefined reference to `isr17'
isrs.c:(.text+0x2a1): undefined reference to `isr18'
isrs.c:(.text+0x2c6): undefined reference to `isr19'
isrs.c:(.text+0x2eb): undefined reference to `isr20'
isrs.c:(.text+0x310): undefined reference to `isr21'
isrs.c:(.text+0x335): undefined reference to `isr22'
isrs.c:(.text+0x35a): undefined reference to `isr23'
isrs.c:(.text+0x37f): undefined reference to `isr24'
isrs.c:(.text+0x3a4): undefined reference to `isr25'
isrs.c:(.text+0x3c9): undefined reference to `isr26'
isrs.c:(.text+0x3ee): undefined reference to `isr27'
isrs.c:(.text+0x413): undefined reference to `isr28'
isrs.c:(.text+0x438): undefined reference to `isr29'
isrs.c:(.text+0x45d): undefined reference to `isr30'
isrs.c:(.text+0x482): undefined reference to `isr31'
irq.o: In function `irq_install':
irq.c:(.text+0x101): undefined reference to `irq0'
irq.c:(.text+0x126): undefined reference to `irq1'
irq.c:(.text+0x14b): undefined reference to `irq2'
irq.c:(.text+0x170): undefined reference to `irq3'
irq.c:(.text+0x195): undefined reference to `irq4'
irq.c:(.text+0x1ba): undefined reference to `irq5'
irq.c:(.text+0x1df): undefined reference to `irq6'
irq.c:(.text+0x204): undefined reference to `irq7'
irq.c:(.text+0x229): undefined reference to `irq8'
irq.c:(.text+0x24e): undefined reference to `irq9'
irq.c:(.text+0x273): undefined reference to `irq10'
irq.c:(.text+0x298): undefined reference to `irq11'
irq.c:(.text+0x2bd): undefined reference to `irq12'
irq.c:(.text+0x2e2): undefined reference to `irq13'
irq.c:(.text+0x307): undefined reference to `irq14'
irq.c:(.text+0x32c): undefined reference to `irq15'
make: *** [kernel.bin] Error 1
So, it basically means that LD can't find entry symbol "start", but why is it so ?? Afterall, it all went well before i re-installed ubuntu?

here is the linkerscript, followed by my "kasm.s" ..

Code: Select all

OUTPUT_FORMAT("elf32-i386")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    . = ALIGN(4096);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .;
}
*************************************************************************************

Code: Select all

[BITS 32]
global start
global _read_cr0
global _read_cr3
global _write_cr0
global _write_cr3
start:
    mov esp, sys_stack     ; This points the stack to our new stack area
    jmp stublet

ALIGN 4
mboot:

    MULTIBOOT_PAGE_ALIGN	equ 1<<0
    MULTIBOOT_MEMORY_INFO	equ 1<<1
    MULTIBOOT_AOUT_KLUDGE	equ 1<<16
    MULTIBOOT_HEADER_MAGIC	equ 0x1BADB002
    MULTIBOOT_HEADER_FLAGS	equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
    MULTIBOOT_CHECKSUM	equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
    EXTERN code, bss, end

    ; This is the GRUB Multiboot header. A boot signature
    dd MULTIBOOT_HEADER_MAGIC
    dd MULTIBOOT_HEADER_FLAGS
    dd MULTIBOOT_CHECKSUM

    dd mboot
    dd code
    dd bss
    dd end
    dd start

stublet:
    extern kmain
    push ebx
    cli
    call kmain
    jmp $

global gdt_flush     ; Allows the C code to link to this
extern gp            ; Says that '_gp' is in another file
gdt_flush:
    lgdt [gp]        ; Load the GDT with our '_gp' which is a special pointer
    mov ax, 0x10      ; 0x10 is the offset in the GDT to our data segment
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    mov ss, ax
    jmp 0x08:flush2   ; 0x08 is the offset to our code segment: Far jump!
flush2:
    ret               ; Returns back to the C code!
global idt_load
extern idtp
idt_load:
    lidt [idtp]
    ret

global isr0
global isr1
global isr2
global isr3
global isr4
global isr5
global isr6
global isr7
global isr8
global isr9
global isr10
global isr11
global isr12
global isr13
global isr14
global isr15
global isr16
global isr17
global isr18
global isr19
global isr20
global isr21
global isr22
global isr23
global isr24
global isr25
global isr26
global isr27
global isr28
global isr29
global isr30
global isr31

;  0: Divide By Zero Exception
isr0:
    cli
    push byte 0
    push byte 0
    jmp isr_common_stub

;  1: Debug Exception
isr1:
    cli
    push byte 0
    push byte 1
    jmp isr_common_stub

;  2: Non Maskable Interrupt Exception
isr2:
    cli
    push byte 0
    push byte 2
    jmp isr_common_stub

;  3: Int 3 Exception
isr3:
    cli
    push byte 0
    push byte 3
    jmp isr_common_stub

;  4: INTO Exception
isr4:
    cli
    push byte 0
    push byte 4
    jmp isr_common_stub

;  5: Out of Bounds Exception
isr5:
    cli
    push byte 0
    push byte 5
    jmp isr_common_stub

;  6: Invalid Opcode Exception
isr6:
    cli
    push byte 0
    push byte 6
    jmp isr_common_stub

;  7: Coprocessor Not Available Exception
isr7:
    cli
    push byte 0
    push byte 7
    jmp isr_common_stub

;  8: Double Fault Exception (With Error Code!)
isr8:
    cli
    push byte 8
    jmp isr_common_stub

;  9: Coprocessor Segment Overrun Exception
isr9:
    cli
    push byte 0
    push byte 9
    jmp isr_common_stub

; 10: Bad TSS Exception (With Error Code!)
isr10:
    cli
    push byte 10
    jmp isr_common_stub

; 11: Segment Not Present Exception (With Error Code!)
isr11:
    cli
    push byte 11
    jmp isr_common_stub

; 12: Stack Fault Exception (With Error Code!)
isr12:
    cli
    push byte 12
    jmp isr_common_stub

; 13: General Protection Fault Exception (With Error Code!)
isr13:
    cli
    push byte 13
    jmp isr_common_stub

; 14: Page Fault Exception (With Error Code!)
isr14:
    cli
    push byte 14
    jmp isr_common_stub

; 15: Reserved Exception
isr15:
    cli
    push byte 0
    push byte 15
    jmp isr_common_stub

; 16: Floating Point Exception
isr16:
    cli
    push byte 0
    push byte 16
    jmp isr_common_stub

; 17: Alignment Check Exception
isr17:
    cli
    push byte 0
    push byte 17
    jmp isr_common_stub

; 18: Machine Check Exception
isr18:
    cli
    push byte 0
    push byte 18
    jmp isr_common_stub

; 19: Reserved
isr19:
    cli
    push byte 0
    push byte 19
    jmp isr_common_stub

; 20: Reserved
isr20:
    cli
    push byte 0
    push byte 20
    jmp isr_common_stub

; 21: Reserved
isr21:
    cli
    push byte 0
    push byte 21
    jmp isr_common_stub

; 22: Reserved
isr22:
    cli
    push byte 0
    push byte 22
    jmp isr_common_stub

; 23: Reserved
isr23:
    cli
    push byte 0
    push byte 23
    jmp isr_common_stub

; 24: Reserved
isr24:
    cli
    push byte 0
    push byte 24
    jmp isr_common_stub

; 25: Reserved
isr25:
    cli
    push byte 0
    push byte 25
    jmp isr_common_stub

; 26: Reserved
isr26:
    cli
    push byte 0
    push byte 26
    jmp isr_common_stub

; 27: Reserved
isr27:
    cli
    push byte 0
    push byte 27
    jmp isr_common_stub

; 28: Reserved
isr28:
    cli
    push byte 0
    push byte 28
    jmp isr_common_stub

; 29: Reserved
isr29:
    cli
    push byte 0
    push byte 29
    jmp isr_common_stub

; 30: Reserved
isr30:
    cli
    push byte 0
    push byte 30
    jmp isr_common_stub

; 31: Reserved
isr31:
    cli
    push byte 0
    push byte 31
    jmp isr_common_stub

extern fault_handler

isr_common_stub:
    pusha
    push ds
    push es
    push fs
    push gs
    mov ax, 0x10
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    mov eax, esp
    push eax
    mov eax, fault_handler
    call eax
    pop eax
    pop gs
    pop fs
    pop es
    pop ds
    popa
    add esp, 8
    iret

global irq0
global irq1
global irq2
global irq3
global irq4
global irq5
global irq6
global irq7
global irq8
global irq9
global irq10
global irq11
global irq12
global irq13
global irq14
global irq15

; 32: IRQ0
irq0:
    cli
    push byte 0
    push byte 32
    jmp irq_common_stub

; 33: IRQ1
irq1:
    cli
    push byte 0
    push byte 33
    jmp irq_common_stub

; 34: IRQ2
irq2:
    cli
    push byte 0
    push byte 34
    jmp irq_common_stub

; 35: IRQ3
irq3:
    cli
    push byte 0
    push byte 35
    jmp irq_common_stub

; 36: IRQ4
irq4:
    cli
    push byte 0
    push byte 36
    jmp irq_common_stub

; 37: IRQ5
irq5:
    cli
    push byte 0
    push byte 37
    jmp irq_common_stub

; 38: IRQ6
irq6:
    cli
    push byte 0
    push byte 38
    jmp irq_common_stub

; 39: IRQ7
irq7:
    cli
    push byte 0
    push byte 39
    jmp irq_common_stub

; 40: IRQ8
irq8:
    cli
    push byte 0
    push byte 40
    jmp irq_common_stub

; 41: IRQ9
irq9:
    cli
    push byte 0
    push byte 41
    jmp irq_common_stub

; 42: IRQ10
irq10:
    cli
    push byte 0
    push byte 42
    jmp irq_common_stub

; 43: IRQ11
irq11:
    cli
    push byte 0
    push byte 43
    jmp irq_common_stub

; 44: IRQ12
irq12:
    cli
    push byte 0
    push byte 44
    jmp irq_common_stub

; 45: IRQ13
irq13:
    cli
    push byte 0
    push byte 45
    jmp irq_common_stub

; 46: IRQ14
irq14:
    cli
    push byte 0
    push byte 46
    jmp irq_common_stub

; 47: IRQ15
irq15:
    cli
    push byte 0
    push byte 47
    jmp irq_common_stub

extern irq_handler

irq_common_stub:
    pusha
    push ds
    push es
    push fs
    push gs

    mov ax, 0x10
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    mov eax, esp

    push eax
    mov eax, irq_handler
    call eax
    pop eax

    pop gs
    pop fs
    pop es
    pop ds
    popa
    add esp, 8
    iret

;
;..... And now some routines to read & write from cr0 and cr3........
;

_read_cr0:
    mov     eax, cr0
    retn

_write_cr0:
    push    ebp
    mov     ebp, esp
    mov     eax, [ebp+8]
    mov     cr0, eax
    pop     ebp
    retn

_read_cr3:
    mov     eax, cr3
    retn

_write_cr3:
    push    ebp
    mov     ebp, esp
    mov     eax, [ebp+8]
    mov     cr3, eax
    pop     ebp
    retn

SECTION .bss
    resb 8192            
sys_stack:


I'm using GCC 4.6.3 and Binutils 2.22.
Octocontrabass
Member
Member
Posts: 6298
Joined: Mon Mar 25, 2013 7:01 pm

Re: Compilation fails after re-installing Ubuntu 12.04

Post by Octocontrabass »

Why aren't you using a cross-compiler?
snasim2002
Member
Member
Posts: 37
Joined: Sat Apr 11, 2015 9:37 am

Re: Compilation fails after re-installing Ubuntu 12.04

Post by snasim2002 »

I am currently using cross-Binutils.
Furthermore, I did not use cross gcc/binutils before I reinstalled Ubuntu, And it worked fine.
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Compilation fails after re-installing Ubuntu 12.04

Post by abcdef4bfd »

Use the full cross-toolchain.
snasim2002
Member
Member
Posts: 37
Joined: Sat Apr 11, 2015 9:37 am

Re: Compilation fails after re-installing Ubuntu 12.04

Post by snasim2002 »

I even used tcc to compile and link the project, but the results are the same, "warning: cannot find entry symbol start; defaulting to 0000000000100000".
I was also able to compile,link,and run a normal Linux program using both tcc and the GNU toolchain.
snasim2002
Member
Member
Posts: 37
Joined: Sat Apr 11, 2015 9:37 am

Re: Compilation fails after re-installing Ubuntu 12.04

Post by snasim2002 »

Oh yeah!!
I just re-installed NASM through apt-get, and the things are working (and running) now.
The problem was in NASM (and not in GCC or TCC, or LD), which I compiled from source when I re-installed Ubuntu.
Post Reply