Corresponding FreeBSD bug linked as "see also"; see that bug's own "see also" link for where this came from. In ObjFile<ELFT>::shouldMerge in lld/ELF/InputFiles.cpp: if (sec.sh_size % entSize) fatal(toString(this) + ":(" + name + "): SHF_MERGE section size (" + Twine(sec.sh_size) + ") must be a multiple of sh_entsize (" + Twine(entSize) + ")"); uint64_t flags = sec.sh_flags; if (!(flags & SHF_MERGE)) return false; Notice that the size is being checked _before_ the SHF_MERGE flag is checked. This means that either the logic is incorrect, or the error message is incorrect (since this error will then occur for sections without SHF_MERGE). If this size check is only needed for mergeable sections, then surely it should be made _after_ SHF_MERGE is checked for. Since this check is skipped when -O0 is in effect, I do not believe it is actually necessary to check that size is a multiple of sh_entsize when _not_ merging sections. If I'm wrong about that, though, then the check would need to be both moved to somewhere else and changed to not mention SHF_MERGE in the error message.
Created attachment 23306 [details] trivial reproducer Added a reproducer. The .o file here is the output of `as --gstabs` (using the freebsd 12-stable base system version of `as`, which admittedly is very old, but the error is exactly the same when using a current binutils version) applied to the following trivial input: .text .align 16 .global _start _start: movl $0x01, %eax xorq %rdi,%rdi syscall int3
https://reviews.llvm.org/D77368(In reply to Andrew Gierth from comment #1) > Created attachment 23306 [details] > trivial reproducer > > Added a reproducer. The .o file here is the output of `as --gstabs` (using > the freebsd 12-stable base system version of `as`, which admittedly is very > old, but the error is exactly the same when using a current binutils > version) applied to the following trivial input: > > .text > .align 16 > .global _start > _start: > movl $0x01, %eax > xorq %rdi,%rdi > syscall > int3 https://sourceware.org/bugzilla/show_bug.cgi?id=25768 The issue has existed since "19990502 sourceware import". Created https://reviews.llvm.org/D77368
commit 56decd982dc03a74d1796d9d4dbd7d9e0cea98dc (will be included in lld 11) GNU as 2.35 will hopefully be fixed in 2.35 if my commit is merged.