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.
Kieran
Member
Posts: 54 Joined: Mon Apr 11, 2005 11:00 pm
Post
by Kieran » Sun Feb 17, 2008 6:06 am
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
Attachments
HDD.c
(3 KiB) Downloaded 58 times
gzaloprgm
Member
Posts: 141 Joined: Sun Sep 23, 2007 4:53 pm
Location: Buenos Aires, Argentina
Contact:
Post
by gzaloprgm » Sun Feb 17, 2008 12:00 pm
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
pcmattman
Member
Posts: 2566 Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:
Post
by pcmattman » Sun Feb 17, 2008 5:27 pm
Why are you trying to link with libc.a?
gzaloprgm
Member
Posts: 141 Joined: Sun Sep 23, 2007 4:53 pm
Location: Buenos Aires, Argentina
Contact:
Post
by gzaloprgm » Sun Feb 17, 2008 8:44 pm
Hmm, because he might have printf, itoa, and all string functions in libc.a ?
jerryleecooper
Member
Posts: 233 Joined: Mon Aug 06, 2007 6:32 pm
Location: Canada
Post
by jerryleecooper » Sun Feb 17, 2008 10:40 pm
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.
pcmattman
Member
Posts: 2566 Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:
Post
by pcmattman » Mon Feb 18, 2008 12:22 am
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.
Brynet-Inc
Member
Posts: 2426 Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:
Post
by Brynet-Inc » Mon Feb 18, 2008 12:31 am
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.
Twitter: @canadianbryan . Award by smcerm, I stole it. Original was larger.
pcmattman
Member
Posts: 2566 Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:
Post
by pcmattman » Mon Feb 18, 2008 12:33 am
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).
Kieran
Member
Posts: 54 Joined: Mon Apr 11, 2005 11:00 pm
Post
by Kieran » Mon Feb 18, 2008 5:24 pm
libc.a is a library of common functions made by me...
JamesM
Member
Posts: 2935 Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:
Post
by JamesM » Tue Feb 19, 2008 2:50 am
In your linker script the object file is spelled "hdd.o", but your attached file is "HDD.c". Check your capitalisations.
Kieran
Member
Posts: 54 Joined: Mon Apr 11, 2005 11:00 pm
Post
by Kieran » Fri Feb 22, 2008 9:40 am
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.
nick8325
Member
Posts: 200 Joined: Wed Oct 18, 2006 5:49 am
Post
by nick8325 » Fri Feb 22, 2008 3:59 pm
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.)
Kieran
Member
Posts: 54 Joined: Mon Apr 11, 2005 11:00 pm
Post
by Kieran » Sat Feb 23, 2008 11:15 am
I have tried adding the .rodata section into the linker script with no avail...
Wave
Member
Posts: 50 Joined: Sun Jan 20, 2008 5:51 am
Post
by Wave » Sat Feb 23, 2008 11:45 am
You don't specify an entry point. It probably starts somewhere you don't want it to.
Conway's Law: If you have four groups working on a compiler, you'll get a 4-pass compiler.
Melvin Conway
nick8325
Member
Posts: 200 Joined: Wed Oct 18, 2006 5:49 am
Post
by nick8325 » Sat Feb 23, 2008 12:50 pm
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.