[PATCH] D44012: [ELF] - Allow discarding .hash and .gnu.hash from linker script.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 2 06:48:11 PST 2018


grimar created this revision.
grimar added reviewers: ruiu, espindola.
Herald added subscribers: arichardson, emaste.

Currently, LLD segfaults when linker script attempts to discard
one of the hash sections. This patch fixes that.


https://reviews.llvm.org/D44012

Files:
  ELF/LinkerScript.cpp
  test/ELF/linkerscript/discard-gnu-hash.s


Index: test/ELF/linkerscript/discard-gnu-hash.s
===================================================================
--- test/ELF/linkerscript/discard-gnu-hash.s
+++ test/ELF/linkerscript/discard-gnu-hash.s
@@ -0,0 +1,23 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+
+# RUN: ld.lld --hash-style both -shared -o %t1 %t
+# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
+# CHECK: .gnu.hash
+# CHECK: .hash
+
+# RUN: echo "SECTIONS { /DISCARD/ : { *(.hash) } }" > %t.script
+# RUN: ld.lld --hash-style both -shared -o %t1 --script %t.script %t
+# RUN: llvm-objdump -section-headers %t1 \
+# RUN:   | FileCheck %s --check-prefix=HASH
+# HASH-NOT: .hash
+# HASH:     .gnu.hash
+# HASH-NOT: .hash
+
+# RUN: echo "SECTIONS { /DISCARD/ : { *(.gnu.hash) } }" > %t.script
+# RUN: ld.lld --hash-style both -shared -o %t1 --script %t.script %t
+# RUN: llvm-objdump -section-headers %t1 \
+# RUN:   | FileCheck %s --check-prefix=GNUHASH
+# GNUHASH-NOT: .gnu.hash
+# GNUHASH:     .hash
+# GNUHASH-NOT: .gnu.hash
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -360,6 +360,13 @@
         S == InX::DynStrTab)
       error("discarding " + S->Name + " section is not allowed");
 
+    // It's normal to discard the following sections. We drop the pointer to adjust
+    // the rest code behavior as there were no such sections from the begining.
+    if (S == InX::GnuHashTab)
+      InX::GnuHashTab = nullptr;
+    if (S == InX::HashTab)
+      InX::HashTab = nullptr;
+
     S->Assigned = false;
     S->Live = false;
     discard(S->DependentSections);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44012.136739.patch
Type: text/x-patch
Size: 1690 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180302/2944d1f9/attachment.bin>


More information about the llvm-commits mailing list