[PATCH] D100944: [MC][ELF] Emit separate unique sections for different flags

ben via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 29 11:41:01 PDT 2021


bd1976llvm added a comment.

Thanks for replying with some potential solutions. I'm sorry for not raising this earlier we have been slow to keep up with upstream changes recently so this change didn't get merged and tested until last week.

In D100944#2847086 <https://reviews.llvm.org/D100944#2847086>, @tmatheson wrote:

> Not sure I fully understand the issue, but it sounds like the final combined `debug_special` section the linker is trying to create is allocatable at address 0, whereas before it was non-allocatable at address zero. Therefore now it conflicts with other allocatable sections at the same address.

Exactly.

> The solution looks like one of the following to me:
>
> - Use a linkerscript that enforces non-alloc for `debug_special`. I don't know if either `ld` or `lld` support setting flags explicitly.
> - Allow the user to specify flags through the frontend, or at least in IR.
>
> Users can specify section flags in the attribute with GCC by exploiting string quoting, e.g. `__attribute__((section("debug_special,\"\", at progbits#")))` in which the section name is actually given the desired assembly followed by a comment character `#`, effectively commenting out whatever assembly GCC was going to output for the section and using the user supplied string instead.

Thanks - I didn't know about this. What a hack!!! Sadly (or maybe not sadly) it doesn't seem to work with Clang: https://godbolt.org/z/YhjGPn4qE.

> A better solution for llvm would be to expand the `__attribute__((section(name)))` to accept flags, and to expand the LLVM IR `section` to allow specifying flags, section type, etc. If the `attribute` can't be changed then being able to express this in IR would still enable clang to make more sensible choices.

Right - much better than string trickery :)

Another potential solution I thought of is to bring back the behaviour for "default" sections (see the behaviour change in llvm/test/CodeGen/X86/explicit-section-mergeable.ll). "default" sections, created by the assembler upfront, tend to correspond to sections where the name implies the flags e.g. .debug_info/line etc... so in these cases it is reasonable to assign symbols with different flags to "default" sections rather than creating a new unique section. In our downstream toolchain I could then make debug_special a "default" non-ALLOC section.

Actually, here's the full list of possible fixes I have considered:

- linkerscript feature to force the input sections to an output section to be considered non-ALLOC e.g. NOADDR (analogous to the existing NOLOAD).
- Linker doesn't check for overlap if a section is assigned to the NONE phdr.
- Modify https://reviews.llvm.org/D100944 not to use unique sections for assignments to "default" sections and then make debug_special section a "default" section for our toolchain.
- Augment compiler section attribute to allow specifying the section flags as well as the section name.
- Assembler feature to override the section flags for specified section.
- Add linker feature to disable address overlap checks for specific sections (currently there is -no-check-sections but it disables checks on all sections).

@MaskRay what do you think about a solution in the linker?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100944



More information about the llvm-commits mailing list