ld: final link failed
ywx120702@tuta.io
ywx120702@tuta.io
Sat Dec 14 07:35:55 GMT 2024
Hi all:
After upgrade from Fedora 40 to 41, I tried to rebuild my toy kernel, but failed. All I got was "ld: final link failed". I guess normally, there would be some error message like "File truncated" after that.
I narrowed down the problem a little bit
realmode.c
void _start() { __asm__("ljmpl $0x08, $longmode_start"); }
longmode.c
void longmode_start() { }
linker.ld
SECTIONS {
.text : {
*(.text);
}
/DISCARD/ : {
*(.eh_frame);
*(.note*);
}
}
command line to reproduce the problem
gcc -m16 -ffreestanding -c -o realmode.o realmode.c
objcopy -I elf32-i386 -O elf64-x86-64 realmode.o
gcc -ffreestanding -c -o longmode.o longmode.c
ld --oformat=binary -Tlinker.ld -o kernel.bin realmode.o longmode.o
however, ld won't complain if output format is elf
ld -Tlinker.ld -o kernel.elf realmode.o longmode.o
objcopy -I elf64-x86-64 -O binary kernel.elf kernel.elf.bin
Then I tried in docker a few different distros that comes with ld 2.43. They are all the same.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20241214/23226112/attachment.htm>
More information about the Binutils
mailing list