[PATCH] D95199: [ELF] Write output sections in PT_LOAD segment order

Patrick Oppenlander via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 8 21:22:42 PST 2021


pattop updated this revision to Diff 322280.
pattop added a comment.
Herald added a subscriber: mgrang.

Thanks for the feedback!

peter.smith's comment suggesting reordering sections made me rethink my approach to the problem.

I don't think we can reorder outputSections as many parts of the code depend on this. What I have done instead is add a segment to section mapping in the PhdrEntry struct. I think this is a good approach as it allows us to sort the sections in a segment by address without affecting anything else. Doing this greatly simplifies the logic in assignFileOffsets().

As a further cleanup the firstSec and lastSec members of PhdrEntry can probably become simple inline functions returning the first and last entry in the sections vector. I didn't want to do this unless the direction is OK to simplify review.

I have limited this to only affect the output when a PHDRS command is in use as per peter.smith's suggestion, but that won't cover all cases. A link script containing just a SECTIONS command can place sections at arbitrary addresses which also needs this new logic to work properly. Unfortunately, doing so with the current logic brings back some previously discussed undesirable side effects.

As MaskRay said the new output of implicit-program-header.test isn't great. As far as I can tell the reason this happens is beause we place .dynsym .hash and .dynstr before .foo rather than after .text. I'm not sure how to resolve this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95199

Files:
  lld/ELF/LinkerScript.cpp
  lld/ELF/Writer.cpp
  lld/ELF/Writer.h
  lld/test/ELF/linkerscript/implicit-program-header.test
  lld/test/ELF/linkerscript/out-of-order-sections.s
  lld/test/ELF/linkerscript/sections-va-overflow.test

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95199.322280.patch
Type: text/x-patch
Size: 6938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210209/24ee5260/attachment.bin>


More information about the llvm-commits mailing list