[PATCH] D75225: [ELF] Keep orphan section names (.rodata.foo .text.foo) unchanged if !hasSectionsCommand

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 27 09:07:40 PST 2020


MaskRay marked 2 inline comments as done.
MaskRay added inline comments.


================
Comment at: lld/ELF/Writer.cpp:136
   if (s->name == "COMMON")
     return ".bss";
 
----------------
grimar wrote:
> 2 questions regarding the current code.
> 
> 1) Seems we always rename `COMMON` to `.bss`. Does not look right for the non-linker script case?
> 2) If (1) is true, what about doing in the following way?
> 
> ```
> if (script->hasSectionsCommand) {
>   // CommonSection is identified as "COMMON" in linker scripts.
>   // By default, it should go to .bss section.
>   if (s->name == "COMMON")
>     return ".bss";
>   return s->name;
> }
> 
> // When no SECTIONS is specified, emulate GNU ld's internal linker scripts...
> <code>
> ```
> 
1.  "COMMON" sections are created this way: `auto *bss = make<BssSection>("COMMON", s->size, s->alignment);`
  With a linker script without mentioning an input section description `COMMON`, GNU ld can still place COMMON in `.bss`
  The logic here is compatible with GNU ld.

2. I feel that an early return pattern here does not improve readability.


================
Comment at: lld/test/ELF/text-section-prefix.s:20
+# RUN: echo 'SECTIONS {}' > %t.script
+# RUN: ld.lld -T %t.script -z keep-text-section-prefix %t -o %t5
+# RUN: llvm-readelf -S %t5 | FileCheck --check-prefix=SCRIPT %s
----------------
grimar wrote:
> Do you need -z keep-text-section-prefix? Seems both ld.bfd and ld.gold produce the same output without this option.
This is to emphasize that a SECTIONS command overrides `-z keep-text-section-prefix`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75225





More information about the llvm-commits mailing list