LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 45370 - wrong/misleading "SHF_MERGE section size must be a multiple of sh_entsize"
Summary: wrong/misleading "SHF_MERGE section size must be a multiple of sh_entsize"
Status: RESOLVED FIXED
Alias: None
Product: lld
Classification: Unclassified
Component: ELF (show other bugs)
Version: unspecified
Hardware: All All
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-31 02:57 PDT by Andrew Gierth
Modified: 2020-04-03 15:03 PDT (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments
trivial reproducer (5.00 KB, application/octet-stream)
2020-04-02 21:14 PDT, Andrew Gierth
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Gierth 2020-03-31 02:57:53 PDT
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.
Comment 1 Andrew Gierth 2020-04-02 21:14:22 PDT
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
Comment 2 Fangrui Song 2020-04-02 22:23:53 PDT
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
Comment 3 Fangrui Song 2020-04-03 15:03:27 PDT
commit 56decd982dc03a74d1796d9d4dbd7d9e0cea98dc (will be included in lld 11)

GNU as 2.35 will hopefully be fixed in 2.35 if my commit is merged.