ld: final link failed

H.J. Lu hjl.tools@gmail.com
Sat Dec 14 08:25:47 GMT 2024


On Sat, Dec 14, 2024 at 3:36 PM <ywx120702@tuta.io> wrote:
>
> 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.
>

Can you reproduce it with binutils 2.43 branch built from
source? If yes, please open a binutils bug.

-- 
H.J.


More information about the Binutils mailing list