[llvm-bugs] [Bug 39525] New: /usr/bin/ld: /tmp/lto-llvm-e9c16c.o: relocation R_X86_64_32S against `.text._ZL4foo2v' can not be used when making a shared object; recompile with -fPIC

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Nov 1 16:05:47 PDT 2018


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

            Bug ID: 39525
           Summary: /usr/bin/ld: /tmp/lto-llvm-e9c16c.o: relocation
                    R_X86_64_32S against `.text._ZL4foo2v' can not be used
                    when making a shared object; recompile with -fPIC
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: yeouln at uci.edu
                CC: llvm-bugs at lists.llvm.org

Created attachment 21064
  --> https://bugs.llvm.org/attachment.cgi?id=21064&action=edit
The C source code with inline assembly that is mis-compiled when the PIC is
enabled.

When I try to create a shared library containing inline assembly, I get this
link error.

relocation R_X86_64_32S against `.text._ZL4foo2v' can not be used when making a
shared object; recompile with -fPIC

To reproduce the error:

clang -O2 -fPIC -c test_static.c -o test_static.o
clang -fPIC -shared test_static.o -o test_static.so


objdump -Dtx test_static.o:

0000000000000000 <_Z3foov>:
   0:›  48 8b 05 00 00 00 00 ›  mov    0x0(%rip),%rax        # 7 <_Z3foov+0x7>
›   ›   ›   3: R_X86_64_GOTPCREL›   offset-0x4
   7:›  8b 00                ›  mov    (%rax),%eax
   9:›  65 67 48 c7 00 00 00 ›  movq   $0x0,%gs:(%eax)
  10:›  00 00•
›   ›   ›   e: R_X86_64_32S›.text+0x20
  12:›  48 8d 3d 00 00 00 00 ›  lea    0x0(%rip),%rdi        # 19
<_Z3foov+0x19>
›   ›   ›   15: R_X86_64_PC32›  .Lstr-0x4
  19:›  e9 00 00 00 00       ›  jmpq   1e <_Z3foov+0x1e>
›   ›   ›   1a: R_X86_64_PLT32› puts-0x4
  1e:›  66 90                ›  xchg   %ax,%ax

0000000000000020 <_ZL4foo2v>:
  20:›  48 8d 3d 00 00 00 00 ›  lea    0x0(%rip),%rdi        # 27
<_ZL4foo2v+0x7>
›   ›   ›   23: R_X86_64_PC32›  .Lstr.2-0x4
  27:›  e9 00 00 00 00       ›  jmpq   2c <_ZL4foo2v+0xc>
›   ›   ›   28: R_X86_64_PLT32› puts-0x4


The compiler generates the position dependent code (movq at address 9 with
R_X86_64_32S), even though the code is compiled with -fPIC. The mis-compilation
appears only when the function foo2() is a static function. I believe the
correct compilation of address 9 should be like the following <FIX> block. 

<FIX>
   9: 48 8d 0d 20 00 00 00  lea    0x20(%rip),%rcx        # 30 <_ZL4foo2v>
  10: 65 67 48 89 08        mov    %rcx,%gs:(%eax)

-- 
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/20181101/1e767180/attachment.html>


More information about the llvm-bugs mailing list