The issue seems to be that --image-base sets the base address of the ELF image (i.e. the text segment), whereas -Ttext sets the actual section start of it. See the documentation here https://sourceware.org/binutils/docs/ld/Options.html#index-image-base-address_002c-cmd-line Given that .text is offset from the start of the file due to the ELF headers, it puts the actual address of .text to 0x9000 + offset, whereas -Ttext puts .text at 0x9000.
This becomes pretty clear in the readelf -e output: -------------------------- ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: Intel 80386 Version: 0x1 Entry point address: 0x9074 Start of program headers: 52 (bytes into file) Start of section headers: 37336 (bytes into file) Flags: 0x0 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 2 Size of section headers: 40 (bytes) Number of section headers: 8 Section header string table index: 7 Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 00009074 000074 006cb0 00 WAX 0 0 1 [ 2] .rodata PROGBITS 0000fd40 006d40 001ae3 00 A 0 0 32 [ 3] .module_license PROGBITS 00011824 008824 00000f 00 A 0 0 4 [ 4] .data PROGBITS 00011840 008840 00093c 00 WA 0 0 32 [ 5] .bss NOBITS 00012180 00917c 0077c4 00 WA 0 0 32 [ 6] .gnu_debuglink PROGBITS 00000000 00917c 000018 00 0 0 4 [ 7] .shstrtab STRTAB 00000000 009194 000043 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), D (mbind), p (processor specific) Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x000074 0x00009074 0x00009074 0x09108 0x108d0 RWE 0x20 GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x10 Section to Segment mapping: Segment Sections... 00 .text .rodata .module_license .data .bss 01 ------------------------------ 0x74 is 116, which is precisely 52 + 2 * 32. Expected is the following layout though: Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x000080 0x00009000 0x00009000 0x090fc 0x108c4 RWE 0x20 GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x10 Section to Segment mapping: Segment Sections... 00 .text .rodata .module_license .data .bss 01 In this case, 0x74 gets increased to 0x20 to fit the alignment. > -----Original Message----- > From: Christian Hesse <[email protected]> > Sent: 01 December 2025 16:03 > To: Nicholas Vinson <[email protected]> > Cc: The development of GNU GRUB <[email protected]>; cpfeiffer@rev- > crew.info > Subject: Re: [PATCH v2 1/1] Check linker for --image-base support > > Nicholas Vinson <[email protected]> on Tue, 2025/11/18 19:38: > > In several scenarios, configure tests assume it's safe to use > > '-Wl,-Ttext,<address>', but starting with ld.lld-21, blindly using > > that flag may result in configure-test failures due to ld.lld failing > > to link. The failure is because ld.lld-21 no longer allows the > > specified address is less than the base address. > > > > However, ld.lld-21+ and ld.bfd-2.44+ both provide support for the > > --image-base flag making it preferable over the older `-Ttext` flag. > > This breaks the start address in i386-pc/kernel.img, which should be 0x9000, > but became 0x9074. > > The error message is: > > /usr/bin/grub-install: error: `/usr/lib/grub/i386-pc/kernel.img' is > miscompiled: its start address is 0x9074 instead of 0x9000: ld.gold bug?. > -- > main(a){char*c=/* Schoene Gruesse */"B?IJj;MEH" > "CX:;",b;for(a/* Best regards my address: */=0;b=c[a++];) > putchar(b-1/(/* Chris cc -ox -xc - && ./x */b/42*2-3)*42);}
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
