Page 1 of 2
Linking error - undefined references
Posted: Wed Sep 23, 2015 9:46 am
by abcdef4bfd
I'm tried to implement IDT & ISRs for my OS. I known that it requires a lot of assembly code, added it to other .asm file, compiled and linked it. But ld is gived me errors.
kernel.cpp:(.text+0x4971): undefined reference to 'isr0()'
Lots of this errors is appeared. I think that the problem is in my link command:
Code: Select all
i686-elf-ld -T link.ld -o os365.bin -O2 -nostdlib idt.o boot.o kernel.o
And, more global,
any assembly code in separate files is not linking for me.
Re: Linking error - undefined references
Posted: Wed Sep 23, 2015 10:34 am
by Roman
And, more global, any assembly code in separate files is not linking for me.
Perhaps you miss using the .globl directive?
Re: Linking error - undefined references
Posted: Wed Sep 23, 2015 10:46 am
by abcdef4bfd
Roman wrote:And, more global, any assembly code in separate files is not linking for me.
Perhaps you miss using the .globl directive?
No, i'm written in ASM code that:
Code: Select all
global isr0
; 0 to 31.
global isr31
Re: Linking error - undefined references
Posted: Wed Sep 23, 2015 10:49 am
by Roman
And how do you build your assembly file?
Re: Linking error - undefined references
Posted: Wed Sep 23, 2015 10:53 am
by abcdef4bfd
Roman wrote:And how do you build your assembly file?
yasm idt.asm -o idt.o -f elf32
Re: Linking error - undefined references
Posted: Wed Sep 23, 2015 10:56 am
by Techel
Since magic isn't discovered yet you should post your linker script, I bet, so we can help you in the way we can check it and reply.
Re: Linking error - undefined references
Posted: Wed Sep 23, 2015 11:00 am
by abcdef4bfd
Roflo wrote:Since magic isn't discovered yet you should post your linker script, I bet, so we can help you in the way we can check it and reply.
It's the same as in the Bare Bones tutorial.
Code: Select all
ENTRY(_start)
SECTIONS
{
. = 1M;
.text BLOCK(4K) : ALIGN(4K)
{
*(.multiboot)
*(.text)
}
.rodata BLOCK(4K) : ALIGN(4K)
{
*(.rodata)
}
.data BLOCK(4K) : ALIGN(4K)
{
*(.data)
}
.bss BLOCK(4K) : ALIGN(4K)
{
*(COMMON)
*(.bss)
*(.bootstrap_stack)
}
}
Re: Linking error - undefined references
Posted: Wed Sep 23, 2015 11:11 am
by Roman
How does the assembly code look like?
Re: Linking error - undefined references
Posted: Wed Sep 23, 2015 11:29 am
by abcdef4bfd
Roman wrote:How does the assembly code look like?
It's from Bran's kernel development tutorial.
Re: Linking error - undefined references
Posted: Wed Sep 23, 2015 11:43 am
by Techel
So it is exactly the same? Then it are the tools from where the problem came.
And, keep in mind, the c++ compiler is not very kind. It will mangle the symbols in a way its not easy detecting such errors, I can say.
Re: Linking error - undefined references
Posted: Wed Sep 23, 2015 11:51 am
by Combuster
It's the same as in the Bare Bones
It's from Bran's kernel development tutorial.
Shame on you for mix&matching tutorials, and then complaining here because you can't even sort out
the simple things such as an undefined symbol, as it is basically the first error you encounter as a C developer when you make a typo.
The solution is in every case a homework exercise:
- Which source file or library should have that symbol? Does it? Really?
- Which object file should have that symbol? Does it? Really?
- Are you actually adding it in the linking process?
My crystal ball says you failed at both #1 and #3.
Re: Linking error - undefined references
Posted: Wed Sep 23, 2015 12:18 pm
by abcdef4bfd
Combuster wrote:It's the same as in the Bare Bones
It's from Bran's kernel development tutorial.
Shame on you for mix&matching tutorials, and then complaining here because you can't even sort out
the simple things such as an undefined symbol, as it is basically the first error you encounter as a C developer when you make a typo.
The solution is in every case a homework exercise:
- Which source file or library should have that symbol? Does it? Really?
- Which object file should have that symbol? Does it? Really?
- Are you actually adding it in the linking process?
My crystal ball says you failed at both #1 and #3.
1) idt.asm, and really haves it.
2) idt.o.
3) Adding.
Re: Linking error - undefined references
Posted: Wed Sep 23, 2015 12:42 pm
by Techel
Your c++ compiler, when referring to 'idt0()', will import it as a mangled symbol, eg 'xz164_v0idt0' or something like this. Use 'extern "c"' to import it as '_idt0'. Then you also have to change your asm file to export '_idt0'.
Re: Linking error - undefined references
Posted: Wed Sep 23, 2015 1:16 pm
by abcdef4bfd
Roflo wrote:Your c++ compiler, when referring to 'idt0()', will import it as a mangled symbol, eg 'xz164_v0idt0' or something like this. Use 'extern "c"' to import it as '_idt0'. Then you also have to change your asm file to export '_idt0'.
Tried your method, not working for me. Can you give me your linker script, please?
Re: Linking error - undefined references
Posted: Thu Sep 24, 2015 12:39 am
by Combuster
Roflo wrote:Use 'extern "c"' to import it as '_idt0'. Then you also have to change your asm file to export '_idt0'.
Why are you still not using a crosscompiler?