Page 1 of 1

Extremely illogical unresolved references [SOLVED]

Posted: Thu Dec 29, 2011 9:23 am
by zhiayang
Hi, again. So I've been following Bran's tutorial. I can never get the GDT, IDT, ISR and IRQ bits to link. Ever. Not even after downloading the complete source (bkerndev.zip) and trying to compile it.

When I don't modify anything, ie (OUTPUT_FORMAT is binary, nasm compiles to aout), GRUB refuses to read my file, (error 13). When I modify OUTPUT_FORMAT to elf32-i386 and nasm -f elf, ld complains about all the calls from C>ASM, but not the other way around. I have used -fleading-underscore, adding the necessary '_'s, and fno-leading-underscore, removing those '_'s, but to no avail.

Objdump -t on the problem files (gdt.o, idt.o, isrs.o, irq.o and start.o) seriously makes this illogical. The symbol tables all include things like irq0 etc, but neither of them have underscores, anywhere. all the names match, I seriously don't understand what is going on.

Ubuntu 10.04LTS, standard NASM, GCC and LD. I don't see how the lack of a cross compiler will solve this.

Output below.
(Some things like "Assembling... Linking... etc are part of my script. The following is the output of ELF output, in both nasm and ld, with fno-leading-underscore in gcc.)




Build.sh

Code: Select all

Clearing old files...
Assembling...
Compiling...
Linking...
ld: warning: cannot find entry symbol start; defaulting to 0000000000100000
gdt.o: In function `gdt_install':
gdt.c:(.text+0x10e): undefined reference to `gdt_flush'
idt.o: In function `idt_install':
idt.c:(.text+0x64): undefined reference to `idt_load'
isrs.o: In function `isrs_install':
isrs.c:(.text+0x48): undefined reference to `isr0'
isrs.c:(.text+0x6c): undefined reference to `isr1'
isrs.c:(.text+0x90): undefined reference to `isr2'
isrs.c:(.text+0xb4): undefined reference to `isr3'
isrs.c:(.text+0xd8): undefined reference to `isr4'
isrs.c:(.text+0xfc): undefined reference to `isr5'
isrs.c:(.text+0x120): undefined reference to `isr6'
isrs.c:(.text+0x144): undefined reference to `isr7'
isrs.c:(.text+0x168): undefined reference to `isr8'
isrs.c:(.text+0x18c): undefined reference to `isr9'
isrs.c:(.text+0x1b0): undefined reference to `isr10'
isrs.c:(.text+0x1d4): undefined reference to `isr11'
isrs.c:(.text+0x1f8): undefined reference to `isr12'
isrs.c:(.text+0x21c): undefined reference to `isr13'
isrs.c:(.text+0x240): undefined reference to `isr14'
isrs.c:(.text+0x264): undefined reference to `isr15'
isrs.c:(.text+0x288): undefined reference to `isr16'
isrs.c:(.text+0x2ac): undefined reference to `isr17'
isrs.c:(.text+0x2d0): undefined reference to `isr18'
isrs.c:(.text+0x2f4): undefined reference to `isr19'
isrs.c:(.text+0x318): undefined reference to `isr20'
isrs.c:(.text+0x33c): undefined reference to `isr21'
isrs.c:(.text+0x360): undefined reference to `isr22'
isrs.c:(.text+0x384): undefined reference to `isr23'
isrs.c:(.text+0x3a8): undefined reference to `isr24'
isrs.c:(.text+0x3cc): undefined reference to `isr25'
isrs.c:(.text+0x3f0): undefined reference to `isr26'
isrs.c:(.text+0x414): undefined reference to `isr27'
isrs.c:(.text+0x438): undefined reference to `isr28'
isrs.c:(.text+0x45c): undefined reference to `isr29'
isrs.c:(.text+0x480): undefined reference to `isr30'
isrs.c:(.text+0x4a4): undefined reference to `isr31'
irq.o: In function `irq_install':
irq.c:(.text+0x159): undefined reference to `irq0'
irq.c:(.text+0x17d): undefined reference to `irq1'
irq.c:(.text+0x1a1): undefined reference to `irq2'
irq.c:(.text+0x1c5): undefined reference to `irq3'
irq.c:(.text+0x1e9): undefined reference to `irq4'
irq.c:(.text+0x20d): undefined reference to `irq5'
irq.c:(.text+0x231): undefined reference to `irq6'
irq.c:(.text+0x255): undefined reference to `irq7'
irq.c:(.text+0x279): undefined reference to `irq8'
irq.c:(.text+0x29d): undefined reference to `irq9'
irq.c:(.text+0x2c1): undefined reference to `irq10'
irq.c:(.text+0x2e5): undefined reference to `irq11'
irq.c:(.text+0x309): undefined reference to `irq12'
irq.c:(.text+0x32d): undefined reference to `irq13'
irq.c:(.text+0x351): undefined reference to `irq14'
irq.c:(.text+0x375): undefined reference to `irq15'
Writing kernel to floppy image...
Missing kernel.bin!
Aborting...



Objdump -t start.o

Code: Select all


start.o:     file format elf32-i386

SYMBOL TABLE:
00000000 l    df *ABS*	00000000 start.asm
00000000 l    d  .bss	00000000 .bss
00000000 l    d  .text	00000000 .text
00000000 l       *UND*	00000000 mboot
00000001 l       *ABS*	00000000 MULTIBOOT_PAGE_ALIGN
00000002 l       *ABS*	00000000 MULTIBOOT_MEMORY_INFO
00010000 l       *ABS*	00000000 MULTIBOOT_AOUT_KLUDGE
1badb002 l       *ABS*	00000000 MULTIBOOT_HEADER_MAGIC
00010003 l       *ABS*	00000000 MULTIBOOT_HEADER_FLAGS
e4514ffb l       *ABS*	00000000 MULTIBOOT_CHECKSUM
00000000 l       *UND*	00000000 stublet
00000000 l       *UND*	00000000 flush2
00000000 l       *UND*	00000000 isr_common_stub
00000000 l       *UND*	00000000 irq_common_stub
00002000 l       .bss	00000000 sys_stack
00000000         *UND*	00000000 code
00000000         *UND*	00000000 bss
00000000         *UND*	00000000 end
00000000         *UND*	00000000 main
00000000         *UND*	00000000 gp
00000000         *UND*	00000000 idtp
00000000         *UND*	00000000 fault_handler
00000000         *UND*	00000000 irq_handler
00000000         *UND*	00000000 start
00000000         *UND*	00000000 gdt_flush
00000000         *UND*	00000000 idt_load
00000000         *UND*	00000000 isr0
00000000         *UND*	00000000 isr1
00000000         *UND*	00000000 isr2
00000000         *UND*	00000000 isr3
00000000         *UND*	00000000 isr4
00000000         *UND*	00000000 isr5
00000000         *UND*	00000000 isr6
00000000         *UND*	00000000 isr7
00000000         *UND*	00000000 isr8
00000000         *UND*	00000000 isr9
00000000         *UND*	00000000 isr10
00000000         *UND*	00000000 isr11
00000000         *UND*	00000000 isr12
00000000         *UND*	00000000 isr13
00000000         *UND*	00000000 isr14
00000000         *UND*	00000000 isr15
00000000         *UND*	00000000 isr16
00000000         *UND*	00000000 isr17
00000000         *UND*	00000000 isr18
00000000         *UND*	00000000 isr19
00000000         *UND*	00000000 isr20
00000000         *UND*	00000000 isr21
00000000         *UND*	00000000 isr22
00000000         *UND*	00000000 isr23
00000000         *UND*	00000000 isr24
00000000         *UND*	00000000 isr25
00000000         *UND*	00000000 isr26
00000000         *UND*	00000000 isr27
00000000         *UND*	00000000 isr28
00000000         *UND*	00000000 isr29
00000000         *UND*	00000000 isr30
00000000         *UND*	00000000 isr31
00000000         *UND*	00000000 irq0
00000000         *UND*	00000000 irq1
00000000         *UND*	00000000 irq2
00000000         *UND*	00000000 irq3
00000000         *UND*	00000000 irq4
00000000         *UND*	00000000 irq5
00000000         *UND*	00000000 irq6
00000000         *UND*	00000000 irq7
00000000         *UND*	00000000 irq8
00000000         *UND*	00000000 irq9
00000000         *UND*	00000000 irq10
00000000         *UND*	00000000 irq11
00000000         *UND*	00000000 irq12
00000000         *UND*	00000000 irq13
00000000         *UND*	00000000 irq14
00000000         *UND*	00000000 irq15



Objdump -t isrs.o

Code: Select all


isrs.o:     file format elf32-i386

SYMBOL TABLE:
00000000 l    df *ABS*	00000000 isrs.c
00000000 l    d  .text	00000000 .text
00000000 l    d  .data	00000000 .data
00000000 l    d  .bss	00000000 .bss
00000000 l    d  .rodata.str1.1	00000000 .rodata.str1.1
00000000 l    d  .note.GNU-stack	00000000 .note.GNU-stack
00000000 l    d  .comment	00000000 .comment
00000000 g     F .text	00000031 fault_handler
00000000 g     O .data	00000080 exception_messages
00000000         *UND*	00000000 puts
00000031 g     F .text	00000487 isrs_install
00000000         *UND*	00000000 isr0
00000000         *UND*	00000000 idt_set_gate
00000000         *UND*	00000000 isr1
00000000         *UND*	00000000 isr2
00000000         *UND*	00000000 isr3
00000000         *UND*	00000000 isr4
00000000         *UND*	00000000 isr5
00000000         *UND*	00000000 isr6
00000000         *UND*	00000000 isr7
00000000         *UND*	00000000 isr8
00000000         *UND*	00000000 isr9
00000000         *UND*	00000000 isr10
00000000         *UND*	00000000 isr11
00000000         *UND*	00000000 isr12
00000000         *UND*	00000000 isr13
00000000         *UND*	00000000 isr14
00000000         *UND*	00000000 isr15
00000000         *UND*	00000000 isr16
00000000         *UND*	00000000 isr17
00000000         *UND*	00000000 isr18
00000000         *UND*	00000000 isr19
00000000         *UND*	00000000 isr20
00000000         *UND*	00000000 isr21
00000000         *UND*	00000000 isr22
00000000         *UND*	00000000 isr23
00000000         *UND*	00000000 isr24
00000000         *UND*	00000000 isr25
00000000         *UND*	00000000 isr26
00000000         *UND*	00000000 isr27
00000000         *UND*	00000000 isr28
00000000         *UND*	00000000 isr29
00000000         *UND*	00000000 isr30
00000000         *UND*	00000000 isr31



Objdump -t irq.o

Code: Select all


irq.o:     file format elf32-i386

SYMBOL TABLE:
00000000 l    df *ABS*	00000000 irq.c
00000000 l    d  .text	00000000 .text
00000000 l    d  .data	00000000 .data
00000000 l    d  .bss	00000000 .bss
00000000 l    d  .note.GNU-stack	00000000 .note.GNU-stack
00000000 l    d  .comment	00000000 .comment
00000000 g     F .text	00000010 irq_install_handler
00000000 g     O .bss	00000040 irq_routines
00000010 g     F .text	00000010 irq_uninstall_handler
00000020 g     F .text	0000004e irq_handler
00000000         *UND*	00000000 outportb
0000006e g     F .text	000000cf irq_remap
0000013d g     F .text	0000024c irq_install
00000000         *UND*	00000000 irq0
00000000         *UND*	00000000 idt_set_gate
00000000         *UND*	00000000 irq1
00000000         *UND*	00000000 irq2
00000000         *UND*	00000000 irq3
00000000         *UND*	00000000 irq4
00000000         *UND*	00000000 irq5
00000000         *UND*	00000000 irq6
00000000         *UND*	00000000 irq7
00000000         *UND*	00000000 irq8
00000000         *UND*	00000000 irq9
00000000         *UND*	00000000 irq10
00000000         *UND*	00000000 irq11
00000000         *UND*	00000000 irq12
00000000         *UND*	00000000 irq13
00000000         *UND*	00000000 irq14
00000000         *UND*	00000000 irq15

Re: Extremely illogical unresolved references

Posted: Thu Dec 29, 2011 9:43 am
by bluemoon
requimrar wrote:I don't see how the lack of a cross compiler will solve this.
Indeed, cross-compiler is used with that tutorial.

With hosted gcc, some versions it may default to private symbols.

Re: Extremely illogical unresolved references

Posted: Thu Dec 29, 2011 10:03 am
by zhiayang
yes, but if gcc is using private symbols, wouldn't objdump reflect that?

Re: Extremely illogical unresolved references

Posted: Thu Dec 29, 2011 1:00 pm
by zhiayang
no, not yet. i can never seem to get the darn thing built. i do suppose that a "pre-built" cross compiler defeats its own purpose, and that no such thing exists? so, the problem here is my default ld?

Re: Extremely illogical unresolved references

Posted: Thu Dec 29, 2011 1:04 pm
by AJ
Hi,

The Cross-Compiler tutorial is tried and tested - it does work. What is the issue that stops it building for you?

Cheers,
Adam

Re: Extremely illogical unresolved references

Posted: Thu Dec 29, 2011 9:45 pm
by eryjus
I had some trouble building my cross-compiler as well. I finally had to build under su (instead of my own user) and it was successful.

Re: Extremely illogical unresolved references

Posted: Thu Dec 29, 2011 11:20 pm
by zhiayang
AJ wrote:Hi,

The Cross-Compiler tutorial is tried and tested - it does work. What is the issue that stops it building for you?

Cheers,
Adam

The first time, I can't tell what happened, it all just "errored out" on me. Subsequent times, any attempt to "make all" will result in

Code: Select all


configure: error: source directory already configured; run "make distclean" there first

. Problem? I have no idea where the "already configured source directory is." MAKE should be WAY less vague. I've tried deleting every folder, running make-distclean everywhere... doesn't work.



EDIT: I am getting extremely frustrated. Is there an easier way to make this darn Cross compiler?

Re: Extremely illogical unresolved references

Posted: Thu Dec 29, 2011 11:51 pm
by zhiayang
requimrar wrote:
AJ wrote:Hi,

The Cross-Compiler tutorial is tried and tested - it does work. What is the issue that stops it building for you?

Cheers,
Adam

The first time, I can't tell what happened, it all just "errored out" on me. Subsequent times, any attempt to "make all" will result in

Code: Select all


configure: error: source directory already configured; run "make distclean" there first

. Problem? I have no idea where the "already configured source directory is." MAKE should be WAY less vague. I've tried deleting every folder, running make-distclean everywhere... doesn't work.



EDIT: I am getting extremely frustrated. Is there an easier way to make this darn Cross compiler?

EDIT2: I still haven't got the cross compiler to work, but I managed to make my code work! Following this thread: http://forum.osdev.org/viewtopic.php?f=1&t=20150, I inserted section .text right after BITS 32 and it works! Thanks everyone for your input!

Re: Extremely illogical unresolved references [SOLVED]

Posted: Fri Dec 30, 2011 5:24 pm
by AJ
Hi,

Still a little worrying - this sounds like a temporary fix and we like to know that the Cross-Compiler tutorial works. Could you remove every directory under /usr/src, download the source from scratch and follow the tutorial again? If you follow it to the letter, it should all go ok. Just to confirm, you are building in 'build-gcc' and 'build-binutils' rather than attempting to build in the source directory? You should only get the error regarding make distclean if binutils/gcc have already been configured. Normally, if you 'rm -rf' your build directories, the error should go away.
requimrar wrote:Subsequent times, any attempt to "make all" will result in
Do check that you are using 'make all-gcc install-gcc' when you come to the gcc part. Because you are building a freestanding cross compiler, 'make all install' will fail.

Cheers,
Adam

Re: Extremely illogical unresolved references [SOLVED]

Posted: Sun Jan 01, 2012 4:30 am
by zhiayang
AJ wrote:Hi,

Still a little worrying - this sounds like a temporary fix and we like to know that the Cross-Compiler tutorial works. Could you remove every directory under /usr/src, download the source from scratch and follow the tutorial again? If you follow it to the letter, it should all go ok. Just to confirm, you are building in 'build-gcc' and 'build-binutils' rather than attempting to build in the source directory? You should only get the error regarding make distclean if binutils/gcc have already been configured. Normally, if you 'rm -rf' your build directories, the error should go away.
requimrar wrote:Subsequent times, any attempt to "make all" will result in
Do check that you are using 'make all-gcc install-gcc' when you come to the gcc part. Because you are building a freestanding cross compiler, 'make all install' will fail.

Cheers,
Adam
Well yes, I am building in build-lala. I've only tried building binutils so far, because i think that's the most important one anyway.

Re: Extremely illogical unresolved references [SOLVED]

Posted: Sun Jan 01, 2012 4:58 am
by Jvac
AJ wrote:Still a little worrying - this sounds like a temporary fix and we like to know that the Cross-Compiler tutorial works.
It works!

Built my Cross-Compiler with Cygwin just a few days ago.