[PATCH] D32223: [LLD][ELF] Add InputSectionDescriptions for Orphan Sections

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 25 04:09:39 PDT 2017


peter.smith added a comment.

The main difficulty in creating and adding the Orphan OutputSectionCommand in addOrphanSections() is that we don't have a good idea of where in the order of OutputSectionCommands to insert them. The placeOrphanSections() is intentionally run immediately after sortSections() has been called so that it can insert the OutputSectionCommands in the right place. There is a comment in Writer.c in sortSections() that says:

  // The way we define an order then is:
  // *  First put script sections at the start and sort the script and
  //    non-script sections independently.
  // *  Move each non-script section to its preferred position. We try
  //    to put each section in the last position where it it can share
  //    a PT_LOAD.

It may be possible to create the Orphan OutputSectionCommands early and have the comparison routine work out the ordering, although there is a comment in the same block as the one above that claims that coming up with a strict weak ordering to get the desired result is not easy.

I did consider creating the InputSectionDescription commands for pre-existing OutputSections in placeOrphanSections but it seemed easier to reuse the existing lookup of OutputSectionCommand in addOrphanSections().


https://reviews.llvm.org/D32223





More information about the llvm-commits mailing list