[lld] r326891 - [ELF] - Allow discarding .hash and .gnu.hash from linker script.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 7 03:47:16 PST 2018
Author: grimar
Date: Wed Mar 7 03:47:15 2018
New Revision: 326891
URL: http://llvm.org/viewvc/llvm-project?rev=326891&view=rev
Log:
[ELF] - Allow discarding .hash and .gnu.hash from linker script.
Currently, LLD segfaults when linker script attempts to discard
one of the hash sections. This patch fixes that.
Differential revision: https://reviews.llvm.org/D44012
Added:
lld/trunk/test/ELF/linkerscript/discard-gnu-hash.s
Modified:
lld/trunk/ELF/LinkerScript.cpp
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=326891&r1=326890&r2=326891&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Mar 7 03:47:15 2018
@@ -380,6 +380,14 @@ void LinkerScript::discard(ArrayRef<Inpu
S == InX::DynStrTab)
error("discarding " + S->Name + " section is not allowed");
+ // You can discard .hash and .gnu.hash sections by linker scripts. Since
+ // they are synthesized sections, we need to handle them differently than
+ // other regular sections.
+ if (S == InX::GnuHashTab)
+ InX::GnuHashTab = nullptr;
+ if (S == InX::HashTab)
+ InX::HashTab = nullptr;
+
S->Assigned = false;
S->Live = false;
discard(S->DependentSections);
Added: lld/trunk/test/ELF/linkerscript/discard-gnu-hash.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/discard-gnu-hash.s?rev=326891&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/discard-gnu-hash.s (added)
+++ lld/trunk/test/ELF/linkerscript/discard-gnu-hash.s Wed Mar 7 03:47:15 2018
@@ -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
More information about the llvm-commits
mailing list