[PATCH] D112925: [ELF] Place an orphan section to the same memory region as its anchor section

Igor Kudrin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 8 22:12:44 PST 2021


ikudrin added inline comments.


================
Comment at: lld/ELF/LinkerScript.cpp:903
 
+  // An allocatable orphan section should continue the previous memory region.
+  if (sec->sectionIndex == UINT32_MAX && sec->flags & SHF_ALLOC && prev)
----------------
peter.smith wrote:
> My first reaction is that I'd expect this to be below the // See if a region can be found by matching section flags.
> 
> Looking at LD https://sourceware.org/binutils/docs/ld/MEMORY.html 
> ```
> The attr string is an optional list of attributes that specify whether to use a particular memory region for an input section which is not explicitly mapped in the linker script. As described in SECTIONS, if you do not specify an output section for some input section, the linker will create an output section with the same name as the input section. If you define region attributes, the linker will use them to select the memory region for the output section that it creates.
> ```
> That implies that if there are attributes/flags for the memory region then we should try these first to make sure that we respect RO, RW etc. If the MEMORY region doesn't have flags then we could fall back on prev in that case. Apologies if I've missed something obvious.
It looks like their implementation does not fully follow that rule. If the script in the test is changed like this:
```
MEMORY
{
  TEXT (rwx) : ORIGIN = 0x8000, LENGTH = 0x1000
  DATA (rwx) : ORIGIN = 0x9000, LENGTH = 0x1000
}
...
```
GNU ld still puts `.init_array` into `DATA`, not `TEXT`.


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

https://reviews.llvm.org/D112925



More information about the llvm-commits mailing list