brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · be9046e Raw
77 lines · plain
1# REQUIRES: ppc2 3# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o4# RUN: llvm-readobj -r %t.o | FileCheck -check-prefix=RELOCS-LE %s5# RUN: ld.lld %t.o -o %t6# RUN: llvm-nm %t | FileCheck --check-prefix=NM %s7# RUN: llvm-readelf -x .got %t | FileCheck --check-prefix=HEX-LE %s8# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=CHECK %s9 10# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o11# RUN: llvm-readobj -r %t.o | FileCheck -check-prefix=RELOCS-BE %s12# RUN: ld.lld %t.o -o %t13# RUN: llvm-nm %t | FileCheck --check-prefix=NM %s14# RUN: llvm-readelf -x .got %t | FileCheck --check-prefix=HEX-BE %s15# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=CHECK %s16 17# Make sure we calculate the offset correctly for a toc-relative access to a18# global variable as described by the PPC64 Elf V2 abi.19.abiversion 220 21#  int global_a = 5522   .globl      global_a23   .section    ".data"24   .align      225   .type       global_a, @object26   .size       global_a, 427   .p2align    228global_a:29   .long   4130 31 32   .section        ".text"33   .align 234   .global _start35   .type   _start, @function36_start:37.Lfunc_gep0:38    addis 2, 12, .TOC.-.Lfunc_gep0@ha39    addi 2, 2, .TOC.-.Lfunc_gep0@l40.Lfunc_lep0:41    .localentry _start, .Lfunc_lep0-.Lfunc_gep042 43    addis 3, 2, global_a@toc@ha44    addi 3, 3, global_a@toc@l45    li 0,146    lwa 3, 0(3)47    sc48.size   _start,.-_start49 50# Verify the relocations that get emitted for the global variable are the51# expected ones.52# RELOCS-LE:      Relocations [53# RELOCS-LE-NEXT:   .rela.text {54# RELOCS-LE:          0x8 R_PPC64_TOC16_HA global_a 0x055# RELOCS-LE:          0xC R_PPC64_TOC16_LO global_a 0x056 57# RELOCS-BE:      Relocations [58# RELOCS-BE-NEXT:   .rela.text {59# RELOCS-BE:          0xA R_PPC64_TOC16_HA global_a 0x060# RELOCS-BE:          0xE R_PPC64_TOC16_LO global_a 0x061 62# The .TOC. symbol represents the TOC base address: .got + 0x8000 = 0x10028000,63# which is stored in the first entry of .got64# NM: 00000000100281e8 d .TOC.65# NM: 00000000100301f0 D global_a66# HEX-LE:     section '.got':67# HEX-LE-NEXT: 0x100201e8 e8810210 0000000068# HEX-BE:     section '.got':69# HEX-BE-NEXT: 0x100201e8 00000000 100281e870 71# r2 stores the TOC base address. To access global_a with r3, it72# computes the address with TOC plus an offset.73# global_a - .TOC. = 0x100301f0 - 0x100281e8 = (1 << 16) - 3276074# CHECK:      <_start>:75# CHECK:      100101d0:       addis 3, 2, 176# CHECK-NEXT: 100101d4:       addi 3, 3, -3276077