[PATCH] D70146: [ELF] Improve --gc-sections compatibility with GNU ld regarding section groups

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 12 14:40:33 PST 2019


MaskRay created this revision.
MaskRay added reviewers: bd1976llvm, grimar, peter.smith, ruiu, serge-sans-paille.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

Based on D70020 <https://reviews.llvm.org/D70020> by serge-sans-paille.

The ELF spec says:

> Furthermore, there may be internal references among these sections that would not make sense if one of the sections were removed or replaced by a duplicate from another object. Therefore, such groups must be included or omitted from the linked object as a unit. A section cannot be a member of more than one group.

GNU ld has 2 behaviors that we don't have:

- Group members (nextInGroup != nullptr) are subject to garbage collection. This includes non-SHF_ALLOC SHT_NOTE sections. In particular, discarding non-SHF_ALLOC SHT_NOTE sections is an expected behavior by the Annobin project. See https://developers.redhat.com/blog/2018/02/20/annobin-storing-information-binaries/ for more information.
- Groups members are retained or discarded as a unit. Members may have internal references that are not expressed as SHF_LINK_ORDER, relocations, etc. It seems that we should be more conservative here: if a section is marked live, mark all the other member within the group.

Both behaviors are reasonable. This patch implements them.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70146

Files:
  lld/ELF/InputFiles.cpp
  lld/ELF/InputSection.h
  lld/ELF/MarkLive.cpp
  lld/test/ELF/gc-sections-group.s
  lld/test/ELF/linkerscript/discard-group.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70146.228963.patch
Type: text/x-patch
Size: 6941 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191112/7e8e100e/attachment.bin>


More information about the llvm-commits mailing list