[PATCH] D92301: [LLD][ELF] - Don't keep empty output sections that are explicitly assigned to segment.

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 1 11:54:53 PST 2020


MaskRay accepted this revision.
MaskRay added a comment.

Suggest a rewrite of the description:

This reverts a side effect introduced in the code cleanup patch D43571 <https://reviews.llvm.org/D43571>: LLD started to emit empty output sections that are explicitly assigned to a segment.

This patch fixes the issue by removing the `!sec.phdrs.empty()` special case from `isDiscardable`. As a compensation, we add an early phdrs propagation step (see the inline comment).
This is similar to one that we do in adjustSectionsAfterSorting.



================
Comment at: lld/ELF/LinkerScript.cpp:1073
 
+    // In the code below we are removing empty sections from the output.
+    // There are cases where we want to propagate program headers when they are
----------------
Suggest:

```
// The code below may remove empty output sections. We should save the specified program headers (if exist) and propagate them to subsequent sections which do not specify program headers.
// An example of such linker script is:
// SECTIONS { .empty : { *(.empty) } :rw
// .foo : { *(.foo) } }
// Note: at this point the order of output sections has not been finalized, because orphans have not been inserted into their expected positions. We will handle them in adjustSectionsAfterSorting().
```


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

https://reviews.llvm.org/D92301



More information about the llvm-commits mailing list