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

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 8 08:41:24 PST 2021


peter.smith 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)
----------------
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.


================
Comment at: lld/test/ELF/linkerscript/orphan-memory.test:38
+{
+  TEXT : ORIGIN = 0x8000, LENGTH = 0x4
+  DATA : ORIGIN = 0x9000, LENGTH = 0x18
----------------
Would be good to add a test with attributes (https://sourceware.org/binutils/docs/ld/MEMORY.html) for the memory region as well to make sure that these are respected.


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

https://reviews.llvm.org/D112925



More information about the llvm-commits mailing list