From 335fad1c24d0dbeb3ae366bfa8a7ffb54cfc4bb5 Mon Sep 17 00:00:00 2001 From: Shoaib Meenai Date: Sat, 5 Aug 2017 05:01:07 +0000 Subject: [PATCH] [lld] Allow rel iplt symbols with dynamic symbol table Emit these symbols as long as we're building in a static configuration, even if we're emitting a dynamic symbol table. This is consistent with both bfd and gold. Ordinarily, the combination of -static and -export-dynamic wouldn't make much sense. Unfortunately, cmake versions prior to 3.4 forcefully injected -rdynamic [1], so it seems worthwhile to support. [1] https://cmake.org/cmake/help/v3.4/policy/CMP0065.html Differential Revision: https://reviews.llvm.org/D36350 llvm-svn: 310168 --- lld/ELF/Writer.cpp | 2 +- lld/test/ELF/gnu-ifunc-dynsym.s | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 lld/test/ELF/gnu-ifunc-dynsym.s diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 2fe592e90239..e82be4f86f22 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -774,7 +774,7 @@ addOptionalRegular(StringRef Name, SectionBase *Sec, uint64_t Val, // need these symbols, since IRELATIVE relocs are resolved through GOT // and PLT. For details, see http://www.airs.com/blog/archives/403. template void Writer::addRelIpltSymbols() { - if (InX::DynSymTab) + if (!Config->Static) return; StringRef S = Config->IsRela ? "__rela_iplt_start" : "__rel_iplt_start"; addOptionalRegular(S, In::RelaIplt, 0, STV_HIDDEN, STB_WEAK); diff --git a/lld/test/ELF/gnu-ifunc-dynsym.s b/lld/test/ELF/gnu-ifunc-dynsym.s new file mode 100644 index 000000000000..fca15462dcb1 --- /dev/null +++ b/lld/test/ELF/gnu-ifunc-dynsym.s @@ -0,0 +1,19 @@ +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +// RUN: ld.lld -static -export-dynamic %t.o -o %tout +// RUN: llvm-nm -U %tout | FileCheck %s +// REQUIRES: x86 + +// CHECK: __rela_iplt_end +// CHECK: __rela_iplt_start + +.text +.type foo STT_GNU_IFUNC +.globl foo +foo: + ret + +.globl _start +_start: + call foo + movl $__rela_iplt_start,%edx + movl $__rela_iplt_end,%edx