Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 4d4f5d0

Browse files
authored
Merge pull request #105 from glaubitz/rust-llvm-release-6-0-0
[Sparc] Include __tls_get_addr in symbol table for TLS calls to it
2 parents ba52c6e + 24a2acf commit 4d4f5d0

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,30 @@ static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
193193
void SparcMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
194194
switch(getKind()) {
195195
default: return;
196+
case VK_Sparc_TLS_GD_CALL:
197+
case VK_Sparc_TLS_LDM_CALL: {
198+
// The corresponding relocations reference __tls_get_addr, as they call it,
199+
// but this is only implicit; there is no connection in the ELF file
200+
// between the relocation and the symbol, other than the specification for
201+
// the semantics of the relocations. However, the symbol must be included
202+
// in our symbol table despite the lack of references to it, since it needs
203+
// to be bound during linking for these relocations. For details see
204+
// https://sourceware.org/bugzilla/show_bug.cgi?id=22832.
205+
MCSymbol *Symbol = Asm.getContext().getOrCreateSymbol("__tls_get_addr");
206+
Asm.registerSymbol(*Symbol);
207+
auto ELFSymbol = cast<MCSymbolELF>(Symbol);
208+
if (!ELFSymbol->isBindingSet()) {
209+
ELFSymbol->setBinding(ELF::STB_GLOBAL);
210+
ELFSymbol->setExternal(true);
211+
}
212+
LLVM_FALLTHROUGH;
213+
}
196214
case VK_Sparc_TLS_GD_HI22:
197215
case VK_Sparc_TLS_GD_LO10:
198216
case VK_Sparc_TLS_GD_ADD:
199-
case VK_Sparc_TLS_GD_CALL:
200217
case VK_Sparc_TLS_LDM_HI22:
201218
case VK_Sparc_TLS_LDM_LO10:
202219
case VK_Sparc_TLS_LDM_ADD:
203-
case VK_Sparc_TLS_LDM_CALL:
204220
case VK_Sparc_TLS_LDO_HIX22:
205221
case VK_Sparc_TLS_LDO_LOX10:
206222
case VK_Sparc_TLS_LDO_ADD:

test/CodeGen/SPARC/tls.ll

+15-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
; RUN: llc <%s -march=sparc -relocation-model=pic | FileCheck %s --check-prefix=pic
44
; RUN: llc <%s -march=sparcv9 -relocation-model=pic | FileCheck %s --check-prefix=pic
55

6-
; RUN: llc <%s -march=sparc -relocation-model=static -filetype=obj | llvm-readobj -r | FileCheck %s --check-prefix=v8abs-obj
7-
; RUN: llc <%s -march=sparcv9 -relocation-model=static -filetype=obj | llvm-readobj -r | FileCheck %s --check-prefix=v9abs-obj
8-
; RUN: llc <%s -march=sparc -relocation-model=pic -filetype=obj | llvm-readobj -r | FileCheck %s --check-prefix=pic-obj
9-
; RUN: llc <%s -march=sparcv9 -relocation-model=pic -filetype=obj | llvm-readobj -r | FileCheck %s --check-prefix=pic-obj
6+
; RUN: llc <%s -march=sparc -relocation-model=static -filetype=obj | llvm-readobj -r -t | FileCheck %s --check-prefix=v8abs-obj
7+
; RUN: llc <%s -march=sparcv9 -relocation-model=static -filetype=obj | llvm-readobj -r -t | FileCheck %s --check-prefix=v9abs-obj
8+
; RUN: llc <%s -march=sparc -relocation-model=pic -filetype=obj | llvm-readobj -r -t | FileCheck %s --check-prefix=pic-obj
9+
; RUN: llc <%s -march=sparcv9 -relocation-model=pic -filetype=obj | llvm-readobj -r -t | FileCheck %s --check-prefix=pic-obj
1010

1111
@local_symbol = internal thread_local global i32 0
1212
@extern_symbol = external thread_local global i32
@@ -116,4 +116,15 @@ entry:
116116
; pic-obj: 0x{{[0-9,A-F]+}} R_SPARC_TLS_GD_ADD extern_symbol 0x0
117117
; pic-obj: 0x{{[0-9,A-F]+}} R_SPARC_TLS_GD_CALL extern_symbol 0x0
118118
; pic-obj: ]
119+
; pic-obj: Symbols [
120+
; pic-obj: Symbol {
121+
; pic-obj: Name: __tls_get_addr ({{[0-9]+}})
122+
; pic-obj-NEXT: Value: 0x0
123+
; pic-obj-NEXT: Size: 0
124+
; pic-obj-NEXT: Binding: Global (0x1)
125+
; pic-obj-NEXT: Type: None (0x0)
126+
; pic-obj-NEXT: Other: 0
127+
; pic-obj-NEXT: Section: Undefined (0x0)
128+
; pic-obj-NEXT: }
129+
; pic-obj: ]
119130

0 commit comments

Comments
 (0)