[llvm-bugs] [Bug 36755] New: [PPC64] V2 ABI: Functions global entry point sets the toc pointer to the wrong address.

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Mar 15 09:59:28 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=36755

            Bug ID: 36755
           Summary: [PPC64] V2 ABI: Functions global entry point sets the
                    toc pointer to the wrong address.
           Product: lld
           Version: unspecified
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: ELF
          Assignee: unassignedbugs at nondot.org
          Reporter: sfertile at ca.ibm.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 20070
  --> https://bugs.llvm.org/attachment.cgi?id=20070&action=edit
assembly to ilistrate the bad offset calcualtion directly.

The global entry point of a function is supposed to set-up the toc pointer in
register r2. When entering the global entry point, register r12 will hold the
address of the function and the TOC value is calculated by  adding the
difference between the TOC value and the address of the function to r12.

Here is an example of the calculation.

foo:                                    # @foo
.Lfunc_begin0:
.Lfunc_gep0:
        addis 2, 12, .TOC.-.Lfunc_gep0 at ha
        addi 2, 2, .TOC.-.Lfunc_gep0 at l
.Lfunc_lep0:
        .localentry     foo, .Lfunc_lep0-.Lfunc_gep0

We can observe the problem directly by objdumping the executable generated from
the attached assembly.
~/install/LLD/bin/llvm-mc -filetype=obj  -triple=powerpc64le-unknown-linux
global_access.s -o offset_test.o
~/install/LLD/bin/ld.lld  offset_test.o

***********************************************************

a.out:     file format elf64-powerpcle


Disassembly of section .text:

0000000010010000 <_start>:
    10010000:   01 10 80 3c     lis     r4,4097
    10010004:   00 00 84 38     addi    r4,r4,0
    10010008:   02 10 a0 3c     lis     r5,4098
    1001000c:   0c 00 a5 38     addi    r5,r5,12
    10010010:   01 00 00 38     li      r0,1
    10010014:   37 00 60 38     li      r3,55
    10010018:   02 00 00 44     sc      

Disassembly of section .got:

0000000010020000 <.TOC.>:
    10020000:   00 80 02 10     vaddubm v0,v2,v16
    10020004:   00 00 00 00     .long 0x0

*********************************************************

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180315/c5c7d0c4/attachment.html>


More information about the llvm-bugs mailing list