176 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 -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-readelf -x .got %t.so | FileCheck --check-prefix=HEX-LE %s8// RUN: llvm-objdump -d --no-show-raw-insn %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 -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-readelf -x .got %t.so | FileCheck --check-prefix=HEX-BE %s15// RUN: llvm-objdump -d --no-show-raw-insn %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 addi 4, 3, i@dtprel36 lwa 4, i@dtprel(3)37 ld 0, 16(1)38 mtlr 039 blr40 41 .globl test_6442 .p2align 443 .type test_64,@function44 45 .globl test_adjusted46 .p2align 447 .type test_adjusted,@function48test_adjusted:49.Lfunc_gep1:50 addis 2, 12, .TOC.-.Lfunc_gep1@ha51 addi 2, 2, .TOC.-.Lfunc_gep1@l52.Lfunc_lep1:53 .localentry test_adjusted, .Lfunc_lep1-.Lfunc_gep154 mflr 055 std 0, 16(1)56 stdu 1, -32(1)57 addis 3, 2, k@got@tlsld@ha58 addi 3, 3, k@got@tlsld@l59 bl __tls_get_addr(k@tlsld)60 nop61 lis 4, k@dtprel@highesta62 ori 4, 4, k@dtprel@highera63 lis 5, k@dtprel@ha64 addi 5, 5, k@dtprel@l65 sldi 4, 4, 3266 or 4, 4, 567 add 3, 3, 468 addi 1, 1, 3269 ld 0, 16(1)70 mtlr 071 blr72 73 .globl test_not_adjusted74 .p2align 475 .type test_not_adjusted,@function76test_not_adjusted:77.Lfunc_gep2:78 addis 2, 12, .TOC.-.Lfunc_gep2@ha79 addi 2, 2, .TOC.-.Lfunc_gep2@l80.Lfunc_lep2:81 .localentry test_not_adjusted, .Lfunc_lep2-.Lfunc_gep282 mflr 083 std 0, 16(1)84 stdu 1, -32(1)85 addis 3, 2, i@got@tlsld@ha86 addi 3, 3, i@got@tlsld@l87 bl __tls_get_addr(k@tlsld)88 nop89 lis 4, k@dtprel@highest90 ori 4, 4, k@dtprel@higher91 sldi 4, 4, 3292 oris 4, 4, k@dtprel@h93 ori 4, 4, k@dtprel@l94 add 3, 3, 495 addi 1, 1, 3296 ld 0, 16(1)97 mtlr 098 blr99 100 .section .debug_addr,"",@progbits101 .quad i@dtprel+32768102 103 .type i,@object104 .section .tdata,"awT",@progbits105 .space 1024106 .p2align 2107i:108 .long 55109 .size i, 4110 111 .space 1024 * 1024 * 4112 .type k,@object113 .p2align 2114k:115 .long 128116 .size k,4117 118// Verify the input has all the remaining DTPREL based relocations we want to119// test.120// InputRelocs: Relocation section '.rela.text'121// InputRelocs: R_PPC64_DTPREL16 {{[0-9a-f]+}} i + 0122// InputRelocs: R_PPC64_DTPREL16_DS {{[0-9a-f]+}} i + 0123// InputRelocs: R_PPC64_DTPREL16_HIGHESTA {{[0-9a-f]+}} k + 0124// InputRelocs: R_PPC64_DTPREL16_HIGHERA {{[0-9a-f]+}} k + 0125// InputRelocs: R_PPC64_DTPREL16_HA {{[0-9a-f]+}} k + 0126// InputRelocs: R_PPC64_DTPREL16_LO {{[0-9a-f]+}} k + 0127// InputRelocs: R_PPC64_DTPREL16_HIGHEST {{[0-9a-f]+}} k + 0128// InputRelocs: R_PPC64_DTPREL16_HIGHER {{[0-9a-f]+}} k + 0129// InputRelocs: R_PPC64_DTPREL16_HI {{[0-9a-f]+}} k + 0130// InputRelocs: R_PPC64_DTPREL16_LO {{[0-9a-f]+}} k + 0131// InputRelocs: Relocation section '.rela.debug_addr'132// InputRelocs: R_PPC64_DTPREL64 {{[0-9a-f]+}} i + 8000133 134// Expect a single dynamic relocation in the '.rela.dyn section for the module id.135// OutputRelocs: Relocation section '.rela.dyn' at offset 0x{{[0-9a-f]+}} contains 1 entries:136// OutputRelocs-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend137// OutputRelocs-NEXT: R_PPC64_DTPMOD64138 139 140// The got entry for i is at .got+8*1 = 0x4209e0141// i@dtprel = 1024 - 0x8000 = -31744 = 0xffffffffffff8400142// HEX-LE: section '.got':143// HEX-LE-NEXT: 4209e0 e0894200 00000000 00000000 00000000144// HEX-LE-NEXT: 4209f0 00000000 00000000145 146// HEX-BE: section '.got':147// HEX-BE-NEXT: 4209e0 00000000 004289e0 00000000 00000000148// HEX-BE-NEXT: 4209f0 00000000 00000000149 150// Dis: <test>:151// Dis: addi 4, 3, -31744152// Dis-NEXT: lwa 4, -31744(3)153 154// #k@dtprel(1024 + 4 + 1024 * 1024 * 4) = 0x400404155 156// #highesta(k@dtprel) --> ((0x400404 - 0x8000 + 0x8000) >> 48) & 0xffff = 0157// #highera(k@dtprel) --> ((0x400404 - 0x8000 + 0x8000) >> 32) & 0xffff = 0158// #ha(k@dtprel) --> ((0x400404 - 0x8000 + 0x8000) >> 16) & 0xffff = 64159// #lo(k@dtprel) --> ((0x400404 - 0x8000) & 0xffff = -31740160// Dis: <test_adjusted>:161// Dis: lis 4, 0162// Dis: ori 4, 4, 0163// Dis: lis 5, 64164// Dis: addi 5, 5, -31740165 166// #highest(k@dtprel) --> ((0x400404 - 0x8000) >> 48) & 0xffff = 0167// #higher(k@dtprel) --> ((0x400404 - 0x8000) >> 32) & 0xffff = 0168// #hi(k@dtprel) --> ((0x400404 - 0x8000) >> 16) & 0xffff = 63169// #lo(k@dtprel) --> ((0x400404 - 0x8000) & 0xffff = 33796170// Dis: <test_not_adjusted>:171// Dis: lis 4, 0172// Dis: ori 4, 4, 0173// Dis: oris 4, 4, 63174// Dis: ori 4, 4, 33796175 176