[PATCH] D94072: [MC][ELF] Fix accepting abbreviated form with sh_flags and sh_entsize

Tobias Burnus via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 27 05:36:54 PST 2021


burnus added a comment.

In D94072#2524692 <https://reviews.llvm.org/D94072#2524692>, @jhenderson wrote:

> I'm struggling to follow the initial explanation. Could you post an example of what didn't work before, and what the failure mode was, and which now works?

As discussed in in D92052 <https://reviews.llvm.org/D92052>, many assemblers support that flags are only added to the first use (e.g.: .section .foo,"aM", at progbits,1) and subsequent uses omit the flag (e.g.: .section .foo).

However, for certain prefixes such as ".rodata", LLVM-MC adds default flags, namely:

  if (hasPrefix(SectionName, ".rodata.") || SectionName == ".rodata1")
    Flags |= ELF::SHF_ALLOC;

Thus, the current check that for subsequent use "Flags == 0" does not as the default value is not 0 (but SHF_ALLOC).

The patch now checks for user-added flags (i.e "extraFlags == 0") instead, where "Flags" is initially the default value, "extraFlags" is what the parser returns and both are combined with "Flags |= extraFlags".

The real-world code has: (a) the .section with all flags

  .section        .rodata.cst8,"aM", at progbits,8

and then (b) the section without any explicit flags

  .section        .rodata.cst8

but as llvm-mc adds SHF_ALLOC due to the name, there is a mismatch as the first .section has additional flags.
(Leading to the "error: changed section flags for .rodata.cst8, expected: 0x12".)

As the user did not add any flag, it makes sense to only check for the explicitly added flags (extraFlags == 0) and not for the implicitly added ones.
For code generation, only the first-used flag is used (Section->getFlags()), thus, there is no consistency problem, either.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94072/new/

https://reviews.llvm.org/D94072



More information about the llvm-commits mailing list