<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 - Wrong relocation type in relocatable LTO link"
   href="https://bugs.llvm.org/show_bug.cgi?id=33096">33096</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Wrong relocation type in relocatable LTO link
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>gold-plugin
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>eugeni.stepanov@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Normally, with -fno-PIC, address of external symbol is generated as R_X86_64_64
relocation to that symbol. During the final link the relocation may be
re-written to PLT if the symbol is not resolved.

This does not work when an IR input is used in relocatable link. The output
contains R_X86_64_GOTPCREL relocation.

This does not reproduce with LLD. The problem is specific to gold-plugin.

This is an issue when building linux kernel modules with LTO. The modules are
relocatable object files, and the runtime loader in the kernel does not do
fancy things like GOT or PLT. It expects all text relocations.

$ cat a.c
void f(void);
void *address_of_f(void) {
  return &f;
}

BAD CASE:

$ ./bin/clang a.c -c -flto -fno-PIC  && ld.gold --plugin lib/LLVMgold.so  -r
a.o -o 2.o  && objdump -drl 2.o
...
0000000000000000 <address_of_f>:
address_of_f():
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # b
<address_of_f+0xb>
                        7: R_X86_64_GOTPCREL    f-0x4
   b:   5d                      pop    %rbp
   c:   c3                      retq   

GOOD CASE:

$ ./bin/clang a.c -c  -fno-PIC  && ld.gold --plugin lib/LLVMgold.so  -r a.o -o
2.o  && objdump -drl 2.o
...
0000000000000000 <address_of_f>:
address_of_f():
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   48 b8 00 00 00 00 00    movabs $0x0,%rax
   b:   00 00 00 
                        6: R_X86_64_64  f
   e:   5d                      pop    %rbp
   f:   c3                      retq</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>