<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [PPC64] V2 ABI: Functions global entry point sets the toc pointer to the wrong address."
   href="https://bugs.llvm.org/show_bug.cgi?id=36755">36755</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[PPC64] V2 ABI: Functions global entry point sets the toc pointer to the wrong address.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>ELF
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>sfertile@ca.ibm.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=20070" name="attach_20070" title="assembly to ilistrate the bad offset calcualtion directly.">attachment 20070</a> <a href="attachment.cgi?id=20070&action=edit" title="assembly to ilistrate the bad offset calcualtion directly.">[details]</a></span>
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@ha
        addi 2, 2, .TOC.-.Lfunc_gep0@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

*********************************************************</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>