[PATCH] D71819: [ELF] Support input section description .gnu.version* in /DISCARD/

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 22 15:30:46 PST 2019


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

Linux powerpc discards `*(.gnu.version)` (arch/powerpc/kernel/vmlinux.lds.S)
to suppress --orphan-handling=warn warnings in a -pie output `.tmp_vmlinux1`

The support is trivial, except that it currently trips an assertion in
SectionBase::getPartition() called by VersionTableSection::isNeeded().

Fix the assertion failure and add a test manifesting that all of
.gnu.version{,_d,_r} can be discarded.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71819

Files:
  lld/ELF/SyntheticSections.cpp
  lld/test/ELF/linkerscript/discard-gnu-version.s


Index: lld/test/ELF/linkerscript/discard-gnu-version.s
===================================================================
--- /dev/null
+++ lld/test/ELF/linkerscript/discard-gnu-version.s
@@ -0,0 +1,21 @@
+# REQUIRES: x86
+# RUN: echo '.globl f; f:' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o
+# RUN: echo 'v1 { f; };' > %t1.ver
+# RUN: ld.lld -shared --version-script %t1.ver %t1.o -o %t1.so
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
+# RUN: echo 'v1 { foo; };' > %t.ver
+# RUN: ld.lld -shared --version-script %t.ver %t.o %t1.so -o %t.so
+# RUN: llvm-readelf -S %t.so | FileCheck %s
+
+# CHECK: .gnu.version
+# CHECK: .gnu.version_d
+# CHECK: .gnu.version_r
+
+# RUN: echo 'SECTIONS { /DISCARD/ : { *(.gnu.version*) } }' > %t.script
+# RUN: ld.lld -shared --version-script %t.ver -T %t.script %t.o %t1.so -o %t.so
+# RUN: llvm-readelf -S %t.so | FileCheck /dev/null --implicit-check-not=.gnu.version
+
+.globl foo
+foo:
+  call f at plt
Index: lld/ELF/SyntheticSections.cpp
===================================================================
--- lld/ELF/SyntheticSections.cpp
+++ lld/ELF/SyntheticSections.cpp
@@ -2963,7 +2963,8 @@
 }
 
 bool VersionTableSection::isNeeded() const {
-  return getPartition().verDef || getPartition().verNeed->isNeeded();
+  return isLive() &&
+         (getPartition().verDef || getPartition().verNeed->isNeeded());
 }
 
 void addVerneed(Symbol *ss) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71819.235079.patch
Type: text/x-patch
Size: 1408 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191222/2732e02b/attachment.bin>


More information about the llvm-commits mailing list