Closed ubyte closed 6 months ago
Have you seen a real program with a misaligned SHF_COMPRESSED
section? I would expect that tools that generate such sections would use an sh_align
field that keeps the compressed section properly aligned. That is what I see when testing with the GNU linker.
I'm using LD LLD linker from the LLVM project.
$ clang++ --version
clang version 16.0.6
Target: x86_64-unknown-linux-gnu
$ ./ld.lld --version
LLD 16.0.6 (compatible with GNU linkers)
Have you seen a real program with a misaligned SHF_COMPRESSED section?
Yes, it was a real program for which I recently started using the -gz=zlib
option to build.
In fact, almost every program produced by this toolchain began to have unaligned debug sections.
This didn't cause any problems until I tried to run the program with the UB-sanitizer.
Thanks. That looks like a bug in lld. It should be setting sh_align
to 8, not 1, for a compressed section.
I guess we should work around the bug, though.
Thanks, I committed the patch upstream and merged it back into this repo.
Thank you!
On ELF64, it looks like BFD uses 8-byte alignment for compressed .debug_*
sections while gold/lld/mold use 1-byte alignment. I do not know how the Solaris linker sets the alignment.
The specification's wording makes me confused whether it really requires 8-byte alignment, even if a non-packed Elf64_Chdr
surely requires 8.
The sh_size and sh_addralign fields of the section header for a compressed section reflect the requirements of the compressed section.
There are many .debug_*
sections. So avoiding some alignment padding seems a very natural extension, even if the specification doesn't allow it with a very strict interpretation.
The compressed section starts with a struct that requires 8-byte alignment on a 64-bit system, so it seems to me that the compressed section should have 8-byte alignment. That's how every other ELF structure works, after all. If this is an exception, then the standard should explicitly call it out as such. What it does say is that sh_align
is the alignment requirement for the compressed section, which to me means the alignment required for the data in that section, which to me means requiring 8-byte alignment.
The type
b_elf_chd
requires 8 byte alignment on a 64-bit platform, but a compressed debug section may be stored with less restrictive alignment. That misalignment read may cause program termination if it was compiled with the UndefinedBehaviorSanitizer enabled.