[PATCH] D85867: [ELF] Assign file offsets of non-SHF_ALLOC after SHF_ALLOC and set sh_addr=0 to non-SHF_ALLOC

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 17:13:36 PDT 2020


MaskRay created this revision.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
MaskRay requested review of this revision.

- GNU ld places non-SHF_ALLOC sections after SHF_ALLOC sections. This has the advantage that the file offsets of a non-SHF_ALLOC cannot be contained in a PT_LOAD. This patch matches the behavior.
- For non-SHF_ALLOC non-orphan sections, GNU ld may assign non-zero sh_addr and keep sh_addr unchanged (similar to SHT_NOBITS, sh_size does not advance the address). This patch sets sh_addr to 0 instead. 0 arguably is better because non-SHF_ALLOC sections don't appear in the memory image. With this change, we can drop special cases in createSection and findOrphanPos by D85100 <https://reviews.llvm.org/D85100>.

ELF spec says:

> sh_addr - If the section will appear in the memory image of a process, this
> member gives the address at which the section's first byte should
> reside. Otherwise, the member contains 0.

D85100 <https://reviews.llvm.org/D85100> appeared to take a detour. If we take a combined view on D85100 <https://reviews.llvm.org/D85100> and this
patch, the overall complexity slightly increases (onre more loop) and
compatibility with GNU ld improves.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85867

Files:
  lld/ELF/LinkerScript.cpp
  lld/ELF/Writer.cpp
  lld/test/ELF/linkerscript/memory-region-alignment.test
  lld/test/ELF/linkerscript/sections-nonalloc.s
  lld/test/ELF/linkerscript/sections.s
  lld/test/ELF/linkerscript/symbols-non-alloc.test

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85867.285216.patch
Type: text/x-patch
Size: 15070 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200813/9ba7c1dc/attachment-0001.bin>


More information about the llvm-commits mailing list