Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,30 @@ static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
void SparcMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
switch(getKind()) {
default: return;
case VK_Sparc_TLS_GD_CALL:
case VK_Sparc_TLS_LDM_CALL: {
// The corresponding relocations reference __tls_get_addr, as they call it,
// but this is only implicit; there is no connection in the ELF file
// between the relocation and the symbol, other than the specification for
// the semantics of the relocations. However, the symbol must be included
// in our symbol table despite the lack of references to it, since it needs
// to be bound during linking for these relocations. For details see
// https://sourceware.org/bugzilla/show_bug.cgi?id=22832.
MCSymbol *Symbol = Asm.getContext().getOrCreateSymbol("__tls_get_addr");
Asm.registerSymbol(*Symbol);
auto ELFSymbol = cast<MCSymbolELF>(Symbol);
if (!ELFSymbol->isBindingSet()) {
ELFSymbol->setBinding(ELF::STB_GLOBAL);
ELFSymbol->setExternal(true);
}
LLVM_FALLTHROUGH;
}
case VK_Sparc_TLS_GD_HI22:
case VK_Sparc_TLS_GD_LO10:
case VK_Sparc_TLS_GD_ADD:
case VK_Sparc_TLS_GD_CALL:
case VK_Sparc_TLS_LDM_HI22:
case VK_Sparc_TLS_LDM_LO10:
case VK_Sparc_TLS_LDM_ADD:
case VK_Sparc_TLS_LDM_CALL:
case VK_Sparc_TLS_LDO_HIX22:
case VK_Sparc_TLS_LDO_LOX10:
case VK_Sparc_TLS_LDO_ADD:
Expand Down
19 changes: 15 additions & 4 deletions test/CodeGen/SPARC/tls.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
; RUN: llc <%s -march=sparc -relocation-model=pic | FileCheck %s --check-prefix=pic
; RUN: llc <%s -march=sparcv9 -relocation-model=pic | FileCheck %s --check-prefix=pic

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

@local_symbol = internal thread_local global i32 0
@extern_symbol = external thread_local global i32
Expand Down Expand Up @@ -116,4 +116,15 @@ entry:
; pic-obj: 0x{{[0-9,A-F]+}} R_SPARC_TLS_GD_ADD extern_symbol 0x0
; pic-obj: 0x{{[0-9,A-F]+}} R_SPARC_TLS_GD_CALL extern_symbol 0x0
; pic-obj: ]
; pic-obj: Symbols [
; pic-obj: Symbol {
; pic-obj: Name: __tls_get_addr ({{[0-9]+}})
; pic-obj-NEXT: Value: 0x0
; pic-obj-NEXT: Size: 0
; pic-obj-NEXT: Binding: Global (0x1)
; pic-obj-NEXT: Type: None (0x0)
; pic-obj-NEXT: Other: 0
; pic-obj-NEXT: Section: Undefined (0x0)
; pic-obj-NEXT: }
; pic-obj: ]