Skip to content

Commit 7c1f15e

Browse files
committed
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
1 parent 0d754fd commit 7c1f15e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lld/ELF/Writer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,11 @@ static bool shouldKeepInSymtab(SectionBase *Sec, StringRef SymName,
547547
if (Config->Discard == DiscardPolicy::None)
548548
return true;
549549

550+
// If -emit-reloc is given, all symbols including local ones need to be
551+
// copied because they may be referenced by relocations.
552+
if (Config->EmitRelocs)
553+
return true;
554+
550555
// In ELF assembly .L symbols are normally discarded by the assembler.
551556
// If the assembler fails to do so, the linker discards them if
552557
// * --discard-locals is used.

lld/test/ELF/emit-relocs-mergeable2.s

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# REQUIRES: x86
2+
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
3+
# RUN: ld.lld --emit-relocs %t.o -o %t.exe
4+
# RUN: llvm-readelf --relocations %t.exe | FileCheck %s
5+
6+
# CHECK: 0000000000201004 000000010000000b R_X86_64_32S 0000000000200120 .Lfoo + 8
7+
8+
.globl _start
9+
_start:
10+
movq .Lfoo+8, %rax
11+
.section .rodata.cst16,"aM",@progbits,16
12+
.Lfoo:
13+
.quad 0
14+
.quad 0

0 commit comments

Comments
 (0)