[PATCH] D43271: [Sparc] Include __tls_get_addr in symbol table for TLS calls to it
James Clarke via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 20 14:46:39 PST 2018
On 20 Feb 2018, at 19:14, Rafael Avila de Espindola <rafael.espindola at gmail.com> wrote:
>
> This can be tested with llvm-mc, no?
If by that you mean writing a test that invokes llvm-mc to assemble
hand-written TLS sequences, no; llvm-mc currently gives an error[1] when told
to parse an add with four arguments, an ld with three arguments or a call with
two arguments on sparc (the last argument being the relocation information).
James
[1] error: invalid operand for instruction
Example assembly for sparc64:
f:
save %sp, -144, %sp
sethi %hi(_GLOBAL_OFFSET_TABLE_+4), %l7
call 1f
or %l7, %lo(_GLOBAL_OFFSET_TABLE_-4), %l7
1: add %l7, %o7, %l7
! Global Dynamic
sethi %tgd_hi22(x), %i1
add %i1, %tgd_lo10(x), %i1
call __tls_get_addr, %tgd_call(x) ! error
add %l7, %i1, %o0, %tgd_add(x) ! error
! Local Dynamic
sethi %tldm_hi22(x), %i1
add %i1, %tldm_lo10(x), %i1
call __tls_get_addr, %tldm_call(x) ! error
add %l7, %i1, %o0, %tldm_add(x) ! error
sethi %tldo_hix22(x), %i1
xor %i1, %tldo_lox10(x), %i1
add %o0, %i1, %i1, %tldo_add(x) ! error
! Initial Exec
sethi %tie_hi22(x), %i1
add %i1, %tie_lo10(x), %i1
ldx [%l7+%i1], %i1, %tie_ldx(x) ! error
add %g7, %i1, %i1, %tie_add(x) ! error
! Local Exec
sethi %tle_hix22(x), %i1
xor %i1, %tle_lox10(x), %i1
add %g7, %i1, %i1
ret
restore
> James Clarke via Phabricator via llvm-commits
> <llvm-commits at lists.llvm.org> writes:
>
>> jrtc27 created this revision.
>> jrtc27 added a reviewer: JDevlieghere.
>> Herald added subscribers: llvm-commits, fedor.sergeev, jyknight.
>>
>> Global Dynamic and Local Dynamic call relocations only implicitly
>> reference __tls_get_addr, but it still needs to be in the symbol table
>> to be bound at link time otherwise it fails to link. For details, see
>> https://sourceware.org/bugzilla/show_bug.cgi?id=22832.
>>
>>
>> Repository:
>> rL LLVM
>>
>> https://reviews.llvm.org/D43271
>>
>> Files:
>> lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp
>> test/CodeGen/SPARC/tls.ll
>>
>>
>> Index: test/CodeGen/SPARC/tls.ll
>> ===================================================================
>> --- test/CodeGen/SPARC/tls.ll
>> +++ test/CodeGen/SPARC/tls.ll
>> @@ -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
>> @@ -116,4 +116,15 @@
>> ; 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: ]
>>
>> Index: lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp
>> ===================================================================
>> --- lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp
>> +++ lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp
>> @@ -193,14 +193,30 @@
>> 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:
>>
>>
>> Index: test/CodeGen/SPARC/tls.ll
>> ===================================================================
>> --- test/CodeGen/SPARC/tls.ll
>> +++ test/CodeGen/SPARC/tls.ll
>> @@ -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
>> @@ -116,4 +116,15 @@
>> ; 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: ]
>>
>> Index: lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp
>> ===================================================================
>> --- lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp
>> +++ lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp
>> @@ -193,14 +193,30 @@
>> 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:
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list