Page 1 of 2
Linking Problem
Posted: Sun Feb 17, 2008 6:06 am
by Kieran
I am having problems when linking my kernel.
I have an application that produces an LD linker script, but once i add a certain file it no longer produces working binary's or coff exe's.
Here is the linker script:
Code: Select all
INPUT("fdd.o")
INPUT("gdt.o")
INPUT("hdd.o")
INPUT("idt.o")
INPUT("irq.o")
INPUT("isrs.o")
INPUT("kbd.o")
INPUT("kprintf.o")
INPUT("main.o")
INPUT("mm.o")
INPUT("paging.o")
INPUT("start.o")
INPUT("timer.o")
INPUT("vga.o")
INPUT("video.o")
INPUT("../lib/libc.a")
OUTPUT_FORMAT("binary")
SECTIONS
{
.text 0x100000 :
{
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(8192);
}
.data :
{
data = .; _data = .; __data = .;
*(.data)
. = ALIGN(8192);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
*(COMMON)
. = ALIGN(8192);
}
end = .; _end = .; __end = .;
}
The file causing the problem is hdd.c. I am not getting any build warnings or errors from it. I have attached it...
If anyone has any ideas I would be grateful.
Thanks in advance, Kieran
Posted: Sun Feb 17, 2008 12:00 pm
by gzaloprgm
Very weird problem.
Why don't you try replacing all input files in linker script:
Code: Select all
INPUT("fdd.o")
INPUT("gdt.o")
INPUT("hdd.o")
INPUT("idt.o")
INPUT("irq.o")
INPUT("isrs.o")
INPUT("kbd.o")
INPUT("kprintf.o")
INPUT("main.o")
INPUT("mm.o")
INPUT("paging.o")
INPUT("start.o")
INPUT("timer.o")
INPUT("vga.o")
INPUT("video.o")
INPUT("../lib/libc.a")
with this line in the makefile or batch maker
ld -T link.ld -o kernel.bin *.o ../lib/libc.a
Cheers,
Gonzalo
Posted: Sun Feb 17, 2008 5:27 pm
by pcmattman
Why are you trying to link with libc.a?
Posted: Sun Feb 17, 2008 8:44 pm
by gzaloprgm
Hmm, because he might have printf, itoa, and all string functions in libc.a ?
Posted: Sun Feb 17, 2008 10:40 pm
by jerryleecooper
I don't know a lot about linker scripts, but isn't outputting as "BINARY" format requires that the first function to be called the first to be linked?
And what is it with "coff"?
Do you use optimization? It can cause problems with -ffreestanding in a binary file format.
Posted: Mon Feb 18, 2008 12:22 am
by pcmattman
gzaloprgm wrote:Hmm, because he might have printf, itoa, and all string functions in libc.a ?
In a kernel? It's making life harder, imho, to have a libc.a for a kernel.
Posted: Mon Feb 18, 2008 12:31 am
by Brynet-Inc
pcmattman wrote:gzaloprgm wrote:Hmm, because he might have printf, itoa, and all string functions in libc.a ?
In a kernel? It's making life harder, imho, to have a libc.a for a kernel.
To be fair pcmattman, you don't know the purpose of that library for his specific project.
He could be developing a C library for both kernel-land and user-land functions, The BSD's do a similar thing with a few #ifdefs..
I don't see the problem... unless he's linking with his host OS's C library.
Re: Linking Problem
Posted: Mon Feb 18, 2008 12:33 am
by pcmattman
Brynet-Inc:
Kieran wrote:I am having problems when linking my kernel.
OP: Could you please clarify what that libc.a is? Is it your host OS one or one you have made?
Also, could you please tell us what your compiler and linker command lines are? (And your batch/make files if you have any).
Posted: Mon Feb 18, 2008 5:24 pm
by Kieran
libc.a is a library of common functions made by me...
Posted: Tue Feb 19, 2008 2:50 am
by JamesM
In your linker script the object file is spelled "hdd.o", but your attached file is "HDD.c". Check your capitalisations.
Posted: Fri Feb 22, 2008 9:40 am
by Kieran
sorry James, that isn't the problem. All of my files are saved in upper case and they all compile in lower case from the linker script.
Posted: Fri Feb 22, 2008 3:59 pm
by nick8325
Your linker script doesn't have an .rodata section. Does it help to add the line
on the next line after *(.text) in the linker script? (GCC stores strings in this section.)
Posted: Sat Feb 23, 2008 11:15 am
by Kieran
I have tried adding the .rodata section into the linker script with no avail...
Posted: Sat Feb 23, 2008 11:45 am
by Wave
You don't specify an entry point. It probably starts somewhere you don't want it to.
Posted: Sat Feb 23, 2008 12:50 pm
by nick8325
Are you using GRUB? If so, the multiboot header has to be in the first 8KB of the kernel. You could try moving INPUT("start.o") to the very top of the linker script.