[PATCH] D85056: [ELF] Add --keep-section to expose linkerscript KEEP directive as a linker flag

Christy Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 31 16:39:53 PDT 2020


christylee added a comment.

In D85056#2188496 <https://reviews.llvm.org/D85056#2188496>, @MaskRay wrote:

>> --gc-sections throw away all unreferenced sections, but we sometimes need to keep some of them.
>
> If an input section defines a non-local symbol, you can use `-u` to retain the section.
>
>> Although it's possible to use a linkerscript with the KEEP directive, it is often cumbersome for large repositories where each binary might have its own linkerscript.

For our use case, the input sections sometimes only define local symbols.

> -T can be specified multiple times. The linker scripts are essentially concatenated. What might be inconvenient is that once a linker script (unless the INSERT AFTER|BEFORE) is specified, it is considered an external linker script (GNU ld --verbose), and several built-in rules (!hasSectionsCommand) are disabled. If such requests are common, we should communicate with binutils to get a syntax.

One of the complaints we got is that linkers cripts are intrusive to build systems, and that they are difficult to experiment with.  Keeping sections via a linker flag would be more light weight than full linker scripts.

Given we already have `--keep-unique` to keep symbol from being folded during icf, I feel that adding `--keep-section` would be analogous to that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85056



More information about the llvm-commits mailing list