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

            Bug ID: 33096
           Summary: Wrong relocation type in relocatable LTO link
           Product: tools
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: gold-plugin
          Assignee: unassignedb...@nondot.org
          Reporter: eugeni.stepa...@gmail.com
                CC: llvm-bugs@lists.llvm.org

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to