[PATCH] D33041: [ELF] - Set DF_STATIC_TLS flag for x86_64 target.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu May 11 11:32:26 PDT 2017


On Thu, May 11, 2017 at 6:08 AM, Rafael Avila de Espindola <
rafael.espindola at gmail.com> wrote:

> I just cloned musl and DF_STATIC_TLS is not used anywhere.
>
> glibc used to use it, but doesn't since 2002
> (2430d57a13f4f10312e13c58962cd9104e6428fd).
>
> It is also not used by the freebsd one.
>
> Given the above, I think we should remove support for the flag for now.
>

I wouldn't object.


> Cheers,
> Rafael
>
>
> George Rimar via Phabricator <reviews at reviews.llvm.org> writes:
>
> > grimar created this revision.
> >
> > DF_STATIC_TLS
> > If set in a shared object or executable, this flag instructs the dynamic
> linker to reject attempts to load this file dynamically. It indicates that
> the shared object or executable contains code using a static thread-local
> storage scheme. Implementations need not support any form of thread-local
> storage.
> >
> > The is same as https://reviews.llvm.org/D32354, but for x86_64 target.
> >
> >
> > https://reviews.llvm.org/D33041
> >
> > Files:
> >   ELF/Target.cpp
> >   test/ELF/Inputs/x86-64-static-tls-model1.s
> >   test/ELF/Inputs/x86-64-static-tls-model2.s
> >   test/ELF/tls-dynamic.s
> >   test/ELF/tls-got.s
> >   test/ELF/tls-initial-exec-local.s
> >   test/ELF/x86_64-static-tls-model.s
> >
> > Index: test/ELF/x86_64-static-tls-model.s
> > ===================================================================
> > --- test/ELF/x86_64-static-tls-model.s
> > +++ test/ELF/x86_64-static-tls-model.s
> > @@ -0,0 +1,12 @@
> > +# REQUIRES: x86
> > +
> > +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux
> %S/Inputs/x86-64-static-tls-model1.s -o %t.o
> > +# RUN: ld.lld %t.o -o %t1 -shared
> > +# RUN: llvm-readobj -dynamic-table %t1 | FileCheck %s
> > +
> > +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux
> %S/Inputs/x86-64-static-tls-model2.s -o %t.o
> > +# RUN: ld.lld %t.o -o %t2 -shared
> > +# RUN: llvm-readobj -dynamic-table %t2 | FileCheck %s
> > +
> > +# CHECK: DynamicSection [
> > +# CHECK: FLAGS STATIC_TLS
> > Index: test/ELF/tls-initial-exec-local.s
> > ===================================================================
> > --- test/ELF/tls-initial-exec-local.s
> > +++ test/ELF/tls-initial-exec-local.s
> > @@ -10,21 +10,21 @@
> >  // CHECK-NEXT:   SHF_ALLOC (0x2)
> >  // CHECK-NEXT:   SHF_WRITE (0x1)
> >  // CHECK-NEXT: ]
> > -// CHECK-NEXT: Address: 0x2090
> > +// CHECK-NEXT: Address: 0x20A0
> >
> >  // CHECK:      Relocations [
> >  // CHECK-NEXT:   Section ({{.*}}) .rela.dyn {
> > -// CHECK-NEXT:     0x2090 R_X86_64_TPOFF64 - 0x0
> > -// CHECK-NEXT:     0x2098 R_X86_64_TPOFF64 - 0x4
> > +// CHECK-NEXT:     0x20A0 R_X86_64_TPOFF64 - 0x0
> > +// CHECK-NEXT:     0x20A8 R_X86_64_TPOFF64 - 0x4
> >  // CHECK-NEXT:   }
> >  // CHECK-NEXT: ]
> >
> > -// 0x1007 + 4233 = 0x2090
> > -// 0x100e + 4234 = 0x2098
> > +// 0x1007 + 4249 = 0x20A0
> > +// 0x100e + 4250 = 0x20A8
> >  // DISASM:      Disassembly of section .text:
> >  // DISASM-NEXT: .text:
> > -// DISASM-NEXT:  1000: {{.*}} addq      4233(%rip), %rax
> > -// DISASM-NEXT:  1007: {{.*}} addq      4234(%rip), %rax
> > +// DISASM-NEXT:  1000: {{.*}} addq      4249(%rip), %rax
> > +// DISASM-NEXT:  1007: {{.*}} addq      4250(%rip), %rax
> >
> >          addq    foo at GOTTPOFF(%rip), %rax
> >          addq    bar at GOTTPOFF(%rip), %rax
> > Index: test/ELF/tls-got.s
> > ===================================================================
> > --- test/ELF/tls-got.s
> > +++ test/ELF/tls-got.s
> > @@ -14,7 +14,7 @@
> >  // CHECK-NEXT:   SHF_WRITE
> >  // CHECK-NEXT: ]
> >  // CHECK-NEXT: Address: [[ADDR:.*]]
> > -// CHECK-NEXT: Offset: 0x20B0
> > +// CHECK-NEXT: Offset: 0x20C0
> >  // CHECK-NEXT: Size: 16
> >  // CHECK-NEXT: Link: 0
> >  // CHECK-NEXT: Info: 0
> > @@ -24,22 +24,22 @@
> >
> >  // CHECK:      Relocations [
> >  // CHECK-NEXT:   Section (4) .rela.dyn {
> > -// CHECK-NEXT:     0x2020B8 R_X86_64_TPOFF64 tls0 0x0
> > +// CHECK-NEXT:     0x2020C8 R_X86_64_TPOFF64 tls0 0x0
> >  // CHECK-NEXT:     [[ADDR]] R_X86_64_TPOFF64 tls1 0x0
> >  // CHECK-NEXT:   }
> >  // CHECK-NEXT: ]
> >
> > -//0x201000 + 4249 + 7 = 0x2020B0
> > -//0x20100A + 4247 + 7 = 0x2020B8
> > -//0x201014 + 4237 + 7 = 0x2020B8
> > +//0x201000 + 4281 + 7 = 0x2020C0
> > +//0x20100A + 4279 + 7 = 0x2020C8
> > +//0x201014 + 4269 + 7 = 0x2020C8
> >  //DISASM:      Disassembly of section .text:
> >  //DISASM-NEXT: main:
> > -//DISASM-NEXT: 201000: 48 8b 05 a9 10 00 00 movq 4265(%rip), %rax
> > -//DISASM-NEXT: 201007: 64 8b 00 movl %fs:(%rax), %eax
> > -//DISASM-NEXT: 20100a: 48 8b 05 a7 10 00 00 movq 4263(%rip), %rax
> > -//DISASM-NEXT: 201011: 64 8b 00 movl %fs:(%rax), %eax
> > -//DISASM-NEXT: 201014: 48 8b 05 9d 10 00 00 movq 4253(%rip), %rax
> > -//DISASM-NEXT: 20101b: 64 8b 00 movl %fs:(%rax), %eax
> > +//DISASM-NEXT: 201000: {{.*}} movq 4281(%rip), %rax
> > +//DISASM-NEXT: 201007: {{.*}} movl %fs:(%rax), %eax
> > +//DISASM-NEXT: 20100a: {{.*}} movq 4279(%rip), %rax
> > +//DISASM-NEXT: 201011: {{.*}} movl %fs:(%rax), %eax
> > +//DISASM-NEXT: 201014: {{.*}} movq 4269(%rip), %rax
> > +//DISASM-NEXT: 20101b: {{.*}} movl %fs:(%rax), %eax
> >  //DISASM-NEXT: 20101e: c3 retq
> >
> >  .section .tdata,"awT", at progbits
> > Index: test/ELF/tls-dynamic.s
> > ===================================================================
> > --- test/ELF/tls-dynamic.s
> > +++ test/ELF/tls-dynamic.s
> > @@ -48,39 +48,39 @@
> >  // CHECK-NEXT:       SHF_ALLOC
> >  // CHECK-NEXT:       SHF_WRITE
> >  // CHECK-NEXT:     ]
> > -// CHECK-NEXT:     Address: 0x30D0
> > +// CHECK-NEXT:     Address: 0x30E0
> >  // CHECK-NEXT:     Offset:
> >  // CHECK-NEXT:     Size: 40
> >
> >  // CHECK:      Relocations [
> >  // CHECK:        Section ({{.+}}) .rela.dyn {
> > -// CHECK-NEXT:     0x30D0 R_X86_64_DTPMOD64 - 0x0
> > -// CHECK-NEXT:     0x30E0 R_X86_64_DTPMOD64 c 0x0
> > -// CHECK-NEXT:     0x30E8 R_X86_64_DTPOFF64 c 0x0
> > -// CHECK-NEXT:     0x30F0 R_X86_64_TPOFF64 c 0x0
> > +// CHECK-NEXT:     0x30E0 R_X86_64_DTPMOD64 - 0x0
> > +// CHECK-NEXT:     0x30F0 R_X86_64_DTPMOD64 c 0x0
> > +// CHECK-NEXT:     0x30F8 R_X86_64_DTPOFF64 c 0x0
> > +// CHECK-NEXT:     0x3100 R_X86_64_TPOFF64 c 0x0
> >  // CHECK-NEXT:   }
> >
> > -// 4297 = (0x20D0 + -4) - (0x1000 + 3) // PC relative offset to got
> entry.
> > -// 4285 = (0x20D0 + -4) - (0x100c + 3) // PC relative offset to got
> entry.
> > -// 4267 = (0x20E0 + -4) - (0x102e + 3) // PC relative offset to got
> entry.
> > -// 4263 = (0x20F0 + -4) - (0x1042 + 3) // PC relative offset to got
> entry.
> > +// 8409 = (0x30E0 + -4) - (0x1000 + 3) // PC relative offset to got
> entry.
> > +// 8397 = (0x30F0 + -4) - (0x100c + 3) // PC relative offset to got
> entry.
> > +// 8379 = (0x30F8 + -4) - (0x102e + 3) // PC relative offset to got
> entry.
> > +// 8375 = (0x3100 + -4) - (0x1042 + 3) // PC relative offset to got
> entry.
> >
> >  // DIS:      Disassembly of section .text:
> >  // DIS-NEXT: .text:
> > -// DIS-NEXT:     1000: {{.+}} leaq    8393(%rip), %rdi
> > +// DIS-NEXT:     1000: {{.+}} leaq    8409(%rip), %rdi
> >  // DIS-NEXT:     1007: {{.+}} callq
> > -// DIS-NEXT:     100c: {{.+}} leaq    8381(%rip), %rdi
> > +// DIS-NEXT:     100c: {{.+}} leaq    8397(%rip), %rdi
> >  // DIS-NEXT:     1013: {{.+}} callq
> >  // DIS-NEXT:     1018: {{.+}} leaq    (%rax), %rcx
> >  // DIS-NEXT:     101f: {{.+}} leaq    4(%rax), %rcx
> >  // DIS-NEXT:     1026: 04 00
> >  // DIS-NEXT:     1028: 00 00
> >  // DIS-NEXT:     102a: 00 00
> >  // DIS-NEXT:     102c: 00 00
> > -// DIS-NEXT:     102e: {{.+}} leaq    8363(%rip), %rdi
> > +// DIS-NEXT:     102e: {{.+}} leaq    8379(%rip), %rdi
> >  // DIS-NEXT:     1035: {{.+}} callq
> >  // DIS-NEXT:     103b: {{.+}} leaq    (%rax), %rcx
> > -// DIS-NEXT:     1042: {{.+}} movq    8359(%rip), %rax
> > +// DIS-NEXT:     1042: {{.+}} movq    8375(%rip), %rax
> >  // DIS-NEXT:     1049: {{.+}} movq    %fs:(%rax), %rax
> >  // DIS-NEXT:     104d: {{.+}} movabsq $0, %rax
> >  // DIS-NEXT:     1057: {{.+}} movabsq $4, %rax
> > Index: test/ELF/Inputs/x86-64-static-tls-model2.s
> > ===================================================================
> > --- test/ELF/Inputs/x86-64-static-tls-model2.s
> > +++ test/ELF/Inputs/x86-64-static-tls-model2.s
> > @@ -0,0 +1,6 @@
> > +.section ".tdata", "awT", @progbits
> > +.globl var
> > +var:
> > +
> > +movq %fs:0, %rax
> > +leaq var at TPOFF(%rax),%rax
> > Index: test/ELF/Inputs/x86-64-static-tls-model1.s
> > ===================================================================
> > --- test/ELF/Inputs/x86-64-static-tls-model1.s
> > +++ test/ELF/Inputs/x86-64-static-tls-model1.s
> > @@ -0,0 +1,6 @@
> > +.section ".tdata", "awT", @progbits
> > +.globl var
> > +var:
> > +
> > +movq var at GOTTPOFF(%rip), %rax
> > +movl %fs:0(%rax), %eax
> > Index: ELF/Target.cpp
> > ===================================================================
> > --- ELF/Target.cpp
> > +++ ELF/Target.cpp
> > @@ -673,6 +673,9 @@
> >  template <class ELFT>
> >  RelExpr X86_64TargetInfo<ELFT>::getRelExpr(uint32_t Type, const
> SymbolBody &S,
> >                                             const uint8_t *Loc) const {
> > +  if (Type == R_X86_64_GOTTPOFF || Type == R_X86_64_TPOFF32)
> > +    Config->HasStaticTlsModel = true;
> > +
> >    switch (Type) {
> >    case R_X86_64_8:
> >    case R_X86_64_16:
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170511/66b50eb4/attachment.html>


More information about the llvm-commits mailing list