<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 - /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"
href="https://bugs.llvm.org/show_bug.cgi?id=39525">39525</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>/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
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>yeouln@uci.edu
</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=21064" name="attach_21064" title="The C source code with inline assembly that is mis-compiled when the PIC is enabled.">attachment 21064</a> <a href="attachment.cgi?id=21064&action=edit" title="The C source code with inline assembly that is mis-compiled when the PIC is enabled.">[details]</a></span>
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)</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>