New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lld has different section attribute merging vs ld.bfd #29763
Comments
Why is having multiple PT_LOADs a problem? |
If you want to merge it all in one output section, I think you can do .all : { *(.text) *(.data) *(.bss) } |
Sorry, multiple PT_LOADs is not a problem per se, but the resulting binary produced by lld is too large. |
With that I end up failing because there's no section for relocations: mbr.o: In function |
Can you check if this is still a problem and upload a cpio if it is? |
A little more information: FreeBSD switched to a linker script for these boot loaders in r305353 (https://svnweb.freebsd.org/base?view=revision&revision=305353, https://reviews.freebsd.org/D7409) However, it broke one of the loaders when using ld.bfd (https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=213491) Most of the boot components worked with the linker script version though, and I expect we'll fix the breakage and restore the use of the linker script. I will try re-applying r305353 and generating a reproduction cpio at some point, but I believe the EFI loaders are more important to fix first and am helping George investigate those first. |
Note that given that we already support putting ro and rx together because of linker scripts, supporting the original feature might not be a big problem. |
lld doesn't create one single RWX PT_LOAD now. Closing because the issue has been fixed for a while. I test on a Linux machine, but the FreeBSD case is similar.% clang -fuse-ld=lld -m32 a.c a.x -o a # 5008 bytes Program Headers: After D64903 and D64906 are merged, the non-linker script case will look similar to this layout. % clang -fuse-ld=bfd -m32 a.c a.x -o a.bfd # 7148 bytes
After https://reviews.llvm.org/rLLD281978, we place R and RX sections in the RX PT_LOAD ( People who want separate R PT_LOAD and RX PT_LOAD in linker script cases can enable --no-rosegment. |
Extended Description
LLD is not necessarily wrong here and what ld.bfd is doing is arguably a bug, but I'm submitting this PR for tracking one of the few outstanding issues linking FreeBSD/amd64 with LLD while looking for a solution.
We recently migrated to using a linker script instead of the seemingly obsolete -N command line flag for FreeBSD's boot loader components: https://svnweb.freebsd.org/base?view=revision&revision=305353
The linker script is straightforward:
/*$FreeBSD$ /
/ Merge text, data and bss together almost no padding */
OUTPUT_FORMAT("elf32-i386-freebsd")
OUTPUT_ARCH(i386)
ENTRY(_start)
SECTIONS {
. = 0x08048000 + SIZEOF_HEADERS;
.text : { (.text) } =0x90909090 / Pad with nops, if needed */
.data : { *(.data) } PROVIDE(_edata = .);
.bss : { *(.bss) } PROVIDE(_end = .);
}
From this GNU ld produces an object with all sections packed into a single RWE segment:
% readelf -l boot2.out
Elf file type is EXEC (Executable file)
Entry point 0x2000
There are 2 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x000080 0x00002000 0x00002000 0x01456 0x027f8 RWE 0x10
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0x4
Section to Segment mapping:
Segment Sections...
00 .text .rodata .data .bss
01
while LLD produces an object with separate segments for sections with different permissions.
The text was updated successfully, but these errors were encountered: