brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.4 KiB · 393901e Raw
129 lines · plain
1// REQUIRES: ppc2 3// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o4// RUN: ld.lld -shared %t.o -z separate-code -o %t.so5// RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s6// RUN: llvm-readelf -r %t.so | FileCheck --check-prefix=OutputRelocs %s7// RUN: llvm-objdump --section-headers %t.so | FileCheck --check-prefix=CheckGot %s8// RUN: llvm-objdump -d %t.so | FileCheck --check-prefix=Dis %s9 10// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o11// RUN: ld.lld -shared %t.o -z separate-code -o %t.so12// RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s13// RUN: llvm-readelf -r %t.so | FileCheck --check-prefix=OutputRelocs %s14// RUN: llvm-objdump --section-headers %t.so | FileCheck --check-prefix=CheckGot %s15// RUN: llvm-objdump -d %t.so | FileCheck --check-prefix=Dis %s16 17        .text18        .abiversion 219        .globl  test20        .p2align        421        .type   test,@function22test:23.Lfunc_gep0:24        addis 2, 12, .TOC.-.Lfunc_gep0@ha25        addi 2, 2, .TOC.-.Lfunc_gep0@l26.Lfunc_lep0:27        .localentry     test, .Lfunc_lep0-.Lfunc_gep028        mflr 029        std 0, 16(1)30        stdu 1, -32(1)31        addis 3, 2, i@got@tlsld@ha32        addi 3, 3, i@got@tlsld@l33        bl __tls_get_addr(i@tlsld)34        nop35        addis 3, 3, i@dtprel@ha36        lwa 3, i@dtprel@l(3)37        ld 0, 16(1)38        mtlr 039        blr40 41        .globl test_hi42        .p2align 443        .type test_hi,@function44test_hi:45         lis 3, j@got@tlsld@h46         blr47 48        .globl test_1649        .p2align 450        .type test_16,@function51test_16:52         li 3, k@got@tlsld53         blr54 55        .type   i,@object56        .section        .tdata,"awT",@progbits57        .p2align        258i:59        .long   5560        .size   i, 461 62        .type   j,@object63        .section        .tbss,"awT",@nobits64        .p2align        265j:66        .long   067        .size   j, 468 69        .type   k,@object70        .section        .tdata,"awT",@progbits71        .p2align        372k:73        .quad   6674        .size   k, 875 76// Verify that the input contains all the R_PPC64_GOT_TLSLD16* relocations, as77// well as the DTPREL relocations used in a typical medium code model78// local-dynamic variable access.79// InputRelocs: Relocation section '.rela.text'80// InputRelocs:     R_PPC64_GOT_TLSLD16_HA {{[0-9a-f]+}} i + 081// InputRelocs:     R_PPC64_GOT_TLSLD16_LO {{[0-9a-f]+}} i + 082// InputRelocs:     R_PPC64_TLSLD          {{[0-9a-f]+}} i + 083// InputRelocs:     R_PPC64_DTPREL16_HA    {{[0-9a-f]+}} i + 084// InputRelocs:     R_PPC64_DTPREL16_LO_DS {{[0-9a-f]+}} i + 085// InputRelocs:     R_PPC64_GOT_TLSLD16_HI {{[0-9a-f]+}} j + 086// InputRelocs:     R_PPC64_GOT_TLSLD16    {{[0-9a-f]+}} k + 087 88// The local dynamic version of tls needs to use the same mechanism to look up89// a variables address as general-dynamic. ie a call to __tls_get_addr with the90// address of a tls_index struct as the argument. However for local-dynamic91// variables  all will have the same ti_module, and the offset field is left as92// as 0, so the same struct can be used for every local-dynamic variable93// used in the shared-object.94// OutputRelocs:      Relocation section '.rela.dyn' at offset 0x{{[0-9a-f]+}} contains 1 entries:95// OutputRelocs-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend96// OutputRelocs-NEXT: R_PPC64_DTPMOD6497 98// Check that the got has 3 entries, 1 for the TOC and 1 structure of 2 entries99// for the tls variables. Also verify the address so we can check the offsets100// we calculate for each relocation type.101// CheckGot: got          00000018 0000000000020110102 103// got starts at 0x20100 so .TOC. will be 0x28100, and the tls_index struct is104// at 0x20108.105 106// #ha(i@got@tlsld) --> (0x20108 - 0x28100 + 0x8000) >> 16 = 0107// #lo(i@got@tlsld) --> (0x20108 - 0x28100) = -7ff8 = -32760108// When calculating offset relative to the dynamic thread pointer we have to109// adjust by 0x8000 since each DTV pointer points 0x8000 bytes past the start of110// its TLS block.111// #ha(i@dtprel) --> (0x0 -0x8000 + 0x8000) >> 16 = 0112// #lo(i@dtprel) --> (0x0 -0x8000) = -0x8000 = -32768113// Dis:     <test>:114// Dis:        addis 3, 2, 0115// Dis-NEXT:   addi 3, 3, -32760116// Dis-NEXT:   bl 0x10060117// Dis-NEXT:   ld 2, 24(1)118// Dis-NEXT:   addis 3, 3, 0119// Dis-NEXT:   lwa 3, -32768(3)120 121 122// #hi(j@got@tlsld) --> (0x20108 - 0x28100 ) > 16 = -1123// Dis: <test_hi>:124// Dis:   lis 3, -1125 126// k@got@tlsld --> (0x20108 - 0x28100) = -7ff8 = -32760127// Dis: <test_16>:128// Dis:   li 3, -32760129