ld link error

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
dlh

ld link error

Post by dlh »

Hey everyone,

I'm a bit confused on this one:  I compiled and linked the multiboot example kernel (with ld script) and then I added some additional code to it, and now ld complains:

...
ld: image: Not enough room for program headers, try linking with -N
ld: final link failed: Bad value

Could anybody tell me what I'm doing wrong???

TIA, David
Gnome

RE:ld link error

Post by Gnome »

That's interesting... I've never seen that error before. The help on -N didn't help either. I suspect

I need some more information:
    1) How are you invoking ld? What arguments are you giving it?
    2) Are you using a linker script? If so, paste it here.

Gnome.
Gnome

RE:ld link error

Post by Gnome »

I came across this page that may solve your problem: http://sources.redhat.com/ml/bug-binuti ... 00306.html

Essentially, make sure your .text section does not start at 0x0, because then the linker will try to put it at that location in the file. This causes a problem, because that's where the program headers are supposed to be.

Gnome.
dlh

RE:ld link error

Post by dlh »

1) I'm running ld with the following command (file1...n.o are the compiled and assembled object files):

$ ld -Tldscript -o image (file1.o file2.o ...)

2) My linker script:

===== START ldscript =====
OUTPUT_FORMAT("elf32-i386")

ENTRY(start)

/*
virt = 0xC0000000; 3 GB
phys = 0x100000; 1 MB
*/

SECTIONS
{
/*.text virt : AT(phys)*/
.text 0x100000 :
{
code = .;
*(.text)
}

/*.data :  AT(phys + (data - code))*/
.data ALIGN(4096) :
{
data = .;
*(.data)
}

/*.bss :  AT(phys + (bss - code))*/
.bss ALIGN(4096) :
{
bss = .;
*(.bss)
*(COMMON)
}

end = ALIGN(4096);
}
===== END ldscript =====

I've been googling around a bit, but I can't find any references to this problem, other than that I could be doing something wrong.  If you can help me out with this problem, I'd be very grateful!

TIA, David
Post Reply