[PATCH] D44584: [PPC64LE] Add a V2 abi test case for toc-relative access.
Sean Fertile via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 16 14:48:21 PDT 2018
sfertile updated this revision to Diff 138775.
sfertile added a comment.
fixed spelling mistake.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D44584
Files:
test/ELF/ppc64le-toc-rel.s
Index: test/ELF/ppc64le-toc-rel.s
===================================================================
--- /dev/null
+++ test/ELF/ppc64le-toc-rel.s
@@ -0,0 +1,64 @@
+# REQUIRES: ppc
+# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
+# RUN: llvm-readobj -relocations %t.o | FileCheck -check-prefix=RELOCS %s
+# RUN: ld.lld %t.o -o %t2
+# RUN: llvm-objdump -D %t2 | FileCheck %s
+
+# Make sure we calculate the offset correctly for a toc-relative access to a
+# global variable as described by the PPC64 Elf V2 abi.
+.abiversion 2
+
+# int global_a = 55
+ .globl global_a
+ .section ".data"
+ .align 2
+ .type global_a, @object
+ .size global_a, 4
+ .p2align 2
+global_a:
+ .long 41
+
+
+ .section ".text"
+ .align 2
+ .global _start
+ .type _start, @function
+_start:
+.Lfunc_gep0:
+ addis 2, 12, .TOC.-.Lfunc_gep0 at ha
+ addi 2, 2, .TOC.-.Lfunc_gep0 at l
+.Lfunc_lep0:
+ .localentry _start, .Lfunc_lep0-.Lfunc_gep0
+
+ addis 3, 2, global_a at toc@ha
+ addi 3, 3, global_a at toc@l
+ li 0,1
+ lwa 3, 0(3)
+ sc
+.size _start,.-_start
+
+# Verify the relocations that get emitted for the global variable are the
+# expected ones.
+# RELOCS: Relocations [
+# RELOCS-NEXT: .rela.text {
+# RELOCS: 0x8 R_PPC64_TOC16_HA global_a 0x0
+# RELOCS: 0xC R_PPC64_TOC16_LO global_a 0x0
+
+# Want to check _start for the values used to build the offset from the TOC base
+# to global_a. The .TOC. symbol is expected at address 0x10030000, and the
+# TOC base is address-of(.TOC.) + 0x8000. The expected offset is:
+# 0x10020000(global_a) - 0x10038000(Toc base) = -0x18000(Offset)
+# which gets materialized into r3 as ((-1 << 16) - 32768).
+
+# CHECK: Disassembly of section .text:
+# CHECK-NEXT: _start:
+# CHECK: 10010008: ff ff 62 3c addis 3, 2, -1
+# CHECK-NEXT: 1001000c: 00 80 63 38 addi 3, 3, -32768
+
+# CHECK: Disassembly of section .data:
+# CHECK-NEXT: global_a:
+# CHECK-NEXT: 10020000: 29 00 00 00
+
+# CHECK: Disassembly of section .got:
+# CHECK-NEXT: .got:
+# CHECK-NEXT: 10030000: 00 80 03 10
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44584.138775.patch
Type: text/x-patch
Size: 2173 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180316/add990f0/attachment.bin>
More information about the llvm-commits
mailing list