aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Stellard <tstellar@redhat.com>2019-05-04 02:51:01 +0000
committerTom Stellard <tstellar@redhat.com>2019-05-04 02:51:01 +0000
commit7c1f15e355fbbf8e238ffc4e8ffd7b80db4d9f93 (patch)
treec8f6e29b06fceae282304421353c3f965c69832a
parent0d754fd0166c80c6bad1a8e0fac8e76557bafa7d (diff)
downloadllvm-7c1f15e355fbbf8e238ffc4e8ffd7b80db4d9f93.zip
llvm-7c1f15e355fbbf8e238ffc4e8ffd7b80db4d9f93.tar.gz
llvm-7c1f15e355fbbf8e238ffc4e8ffd7b80db4d9f93.tar.bz2
Merging r357885:
------------------------------------------------------------------------ r357885 | ruiu | 2019-04-07 23:45:07 -0700 (Sun, 07 Apr 2019) | 13 lines Fix -emit-reloc against local symbols. Previously, we drop symbols starting with .L from the symbol table, so if there is a relocation that refers a .L symbol, it ended up referencing a null -- which happened to be interpreted as an absolute symbol. This patch copies all symbols including local ones if -emit-reloc is given. Fixes https://bugs.llvm.org/show_bug.cgi?id=41385 Differential Revision: https://reviews.llvm.org/D60306 ------------------------------------------------------------------------ llvm-svn: 359956
-rw-r--r--lld/ELF/Writer.cpp5
-rw-r--r--lld/test/ELF/emit-relocs-mergeable2.s14
2 files changed, 19 insertions, 0 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 17f4c79..a3ef3f1 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -547,6 +547,11 @@ static bool shouldKeepInSymtab(SectionBase *Sec, StringRef SymName,
if (Config->Discard == DiscardPolicy::None)
return true;
+ // If -emit-reloc is given, all symbols including local ones need to be
+ // copied because they may be referenced by relocations.
+ if (Config->EmitRelocs)
+ return true;
+
// In ELF assembly .L symbols are normally discarded by the assembler.
// If the assembler fails to do so, the linker discards them if
// * --discard-locals is used.
diff --git a/lld/test/ELF/emit-relocs-mergeable2.s b/lld/test/ELF/emit-relocs-mergeable2.s
new file mode 100644
index 0000000..22d4cf4
--- /dev/null
+++ b/lld/test/ELF/emit-relocs-mergeable2.s
@@ -0,0 +1,14 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld --emit-relocs %t.o -o %t.exe
+# RUN: llvm-readelf --relocations %t.exe | FileCheck %s
+
+# CHECK: 0000000000201004 000000010000000b R_X86_64_32S 0000000000200120 .Lfoo + 8
+
+.globl _start
+_start:
+ movq .Lfoo+8, %rax
+.section .rodata.cst16,"aM",@progbits,16
+.Lfoo:
+ .quad 0
+ .quad 0