<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 - Add support for R_AARCH64_LD64_GOTPAGE_LO15 relocation"
   href="https://bugs.llvm.org/show_bug.cgi?id=40357">40357</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Add support for R_AARCH64_LD64_GOTPAGE_LO15 relocation
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

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

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </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>peter.smith@linaro.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This relocation is not currently supported in LLD. GCC can generate this
relocation when compiling -fpie. For example:

int ii;

void f(void) {
    int* i = &ii;
}

At -O0 
generates:
        .comm   ii,4,4
        .text
        .align  2
        .global f
        .type   f, %function
f:
        sub     sp, sp, #16
        adrp    x0, _GLOBAL_OFFSET_TABLE_
        ldr     x0, [x0, #:gotpage_lo15:ii]
        str     x0, [sp, 8]
        nop
        add     sp, sp, 16
        ret

The :gotpage_lo15:ii generates the relocation R_AARCH64_LD64_GOTPAGE_LO15 which
evaluates to "Address of GotSlot containing address of ii" - "Address of page
containing start of GOT (x0 after the adrp X), _GLOBAL_OFFSET_TABLE_ above".

Curiously clang generates:
        .globl  f                       // -- Begin function f
        .p2align        2
        .type   f,@function
f:                                      // @f
// %bb.0:                               // %entry
        sub     sp, sp, #16             // =16
        adrp    x8, ii
        add     x8, x8, :lo12:ii
        str     x8, [sp, #8]
        add     sp, sp, #16             // =16
        ret
.Lfunc_end0:
        .size   f, .Lfunc_end0-f
                                        // -- End function
        .type   ii,@object              // @ii
        .comm   ii,4,4

Note that the address of ii is computed relative to the place and does not go
via the .got. This saves a dynamic relocation but seems to be causing some
problems with ifunc pointer equivalence. Will need to investigate that further
in a separate pr.

Reference: ELF for the 64-bit ARM Architecture for definition of relocation.
<a href="http://infocenter.arm.com/help/topic/com.arm.doc.ihi0056c/IHI0056C_beta_aaelf64.pdf">http://infocenter.arm.com/help/topic/com.arm.doc.ihi0056c/IHI0056C_beta_aaelf64.pdf</a></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>