Hello
I can't link my .o files with ld, it sais "section .data overlaps section .text" and that there is not enough room for headers. Im using binutils 2.16.1.
The linker script I use:
[pre]
OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}
[/pre]
Most files are assembled by gcc 3.4.0, but one of them is produced by nasm 0.98.39.
Thx for your help
cannot link with ld
Re:cannot link with ld
I can't see anything wrong relating to the problem (you are missing "*(.rodata*)" in the .text section), I suggest you generate a link map:
ld ... --print-map ...
ld ... -Map LinkMap.txt ...
ld ... --print-map ...
ld ... -Map LinkMap.txt ...
Re:cannot link with ld
All i get is this, i dont't think it's usefull (I dont think the -M command should work like this):
[pre]
Allocating common symbols
Common symbol size file
gp 0x6 bin/gdt.o
idtp 0x6 bin/idt.o
gdt 0x18 bin/gdt.o
idt 0x800 bin/idt.o
textmemptr 0x4 bin/scrn.o
[/pre]
The program worked in the beginning, so i've tried to strip away everything so all ive got now is an endless loop, but still no luck(in which case the above symbols do not appear and the section overlep is gone, but it is still complaining about room for headers).
Is it possible that the problem is with my toolset setup? I've already tried recompileing evreything, and I've also tried the newest gcc 4.0.2. G00gle gives no usefull info. to build the things i use the cross-compiler tutor in the os-faq wiki.
[pre]
Allocating common symbols
Common symbol size file
gp 0x6 bin/gdt.o
idtp 0x6 bin/idt.o
gdt 0x18 bin/gdt.o
idt 0x800 bin/idt.o
textmemptr 0x4 bin/scrn.o
[/pre]
The program worked in the beginning, so i've tried to strip away everything so all ive got now is an endless loop, but still no luck(in which case the above symbols do not appear and the section overlep is gone, but it is still complaining about room for headers).
Is it possible that the problem is with my toolset setup? I've already tried recompileing evreything, and I've also tried the newest gcc 4.0.2. G00gle gives no usefull info. to build the things i use the cross-compiler tutor in the os-faq wiki.
Re:cannot link with ld
Now, now, look what i've found:
using the original ld in the cygwin download, the problem with the headers is gone. However, it always exists when using the newly compiled one (i586-elf-ld). So, another question arises, how to compile ld correctly (altough i actually dont need to compile it, everything works fine with the ld of cygwin, but still i'd like to know)
BUT
the problem of sections overlapping is still there when i enable varius parts of my code. what could possibly cause this. I think i'm lacking some technical knowledge: if I only knew what could cause this error.
Another sideffect of using the "original" ld is that now i get a correct linkmap. It's a bit bigger so instead of pasting it here, i attach it as a file:
using the original ld in the cygwin download, the problem with the headers is gone. However, it always exists when using the newly compiled one (i586-elf-ld). So, another question arises, how to compile ld correctly (altough i actually dont need to compile it, everything works fine with the ld of cygwin, but still i'd like to know)
BUT
the problem of sections overlapping is still there when i enable varius parts of my code. what could possibly cause this. I think i'm lacking some technical knowledge: if I only knew what could cause this error.
Another sideffect of using the "original" ld is that now i get a correct linkmap. It's a bit bigger so instead of pasting it here, i attach it as a file:
Re:cannot link with ld
That linkmap is packed with Windows specific stuff. The header error is blatantly strange since flat binaries don't have headers.
What's your commandline for LD? Also, what's your basic commandline for NASM and GCC?
What's your commandline for LD? Also, what's your basic commandline for NASM and GCC?
Re:cannot link with ld
extracted from my make file:
nasm -f elf -o $@ $<
CFLAGS = -Wall -s -Os -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I plib/include
$(CC) $(CFLAGS) -c $< -o $@
LFLAGS = link.ld --strip-all -Map linkmap.txt
ld $(LFLAGS) -o $@ $(OBJS) $(PLIB)
PLIB and stuff like stdlib.o and string.o in the linkermap are just my own platform-independent routines implementing things like strlen, memcpy, itoa etc... They are compiled with the same CFLAGS you can see above.
About the "blatantly strange" heder error: now that i'm NOT using the cross-compiled ld, it is gone. But the overlapping is still there.
nasm -f elf -o $@ $<
CFLAGS = -Wall -s -Os -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I plib/include
$(CC) $(CFLAGS) -c $< -o $@
LFLAGS = link.ld --strip-all -Map linkmap.txt
ld $(LFLAGS) -o $@ $(OBJS) $(PLIB)
PLIB and stuff like stdlib.o and string.o in the linkermap are just my own platform-independent routines implementing things like strlen, memcpy, itoa etc... They are compiled with the same CFLAGS you can see above.
About the "blatantly strange" heder error: now that i'm NOT using the cross-compiled ld, it is gone. But the overlapping is still there.
Re:cannot link with ld
LFLAGS is incorrect.You were trying to use link.ld as a file to be linked rather than a link script, the header error was likely caused by the lack thereof in the linkscript since it isn't an object binary.
Code: Select all
LFLAGS = -T link.ld --strip-all -Map linkmap.txt
Re:cannot link with ld
Geeees...thanks a lot!!
That solved everything! No more header problems, no more sections overlapping, and with the -T switch, the cross-compiled version works too.
Stupid me
Thank you
That solved everything! No more header problems, no more sections overlapping, and with the -T switch, the cross-compiled version works too.
Stupid me
Thank you