<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 - clang++ cannot compile an executable with -fPIE because of possibly incorrect linking of"
href="https://bugs.llvm.org/show_bug.cgi?id=44594">44594</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang++ cannot compile an executable with -fPIE because of possibly incorrect linking of
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>10.0
</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>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>kolan_n@mail.ru
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>```
clang++-10 ./hw.cpp -o hw -fPIE -Wl,-pie -Wl,-O1 -Wl,--sort-common
-Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-z,shstk -Wl,-z,notext
-Wl,--verbose
GNU ld (GNU Binutils for Ubuntu) 2.33
...
/usr/bin/ld: mode elf_x86_64
....
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o succeeded
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o
.....
/usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o: relocation
R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a
PIE object
/usr/bin/ld: final link failed: nonrepresentable section on output
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```
```
clang++-10 ./hw.cpp -o hw -fPIE -Wl,-pie -Wl,-O1 -Wl,--sort-common
-Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-z,shstk -Wl,-z,notext -fuse-ld=lld
-Wl,--verbose
...
ld.lld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o
....
ld.lld: error: cannot preempt symbol: __TMC_END__
<span class="quote">>>> defined in /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtend.o
>>> referenced by crtstuff.c
>>> /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o:(.text+0x1)</span >
ld.lld: error: relocation R_X86_64_32S cannot be used against local symbol;
recompile with -fPIC
<span class="quote">>>> defined in /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o
>>> referenced by crtstuff.c
>>> /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o:(.text+0x7)</span >
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol;
recompile with -fPIC
<span class="quote">>>> defined in /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o
>>> referenced by crtstuff.c
>>> /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o:(.text+0x18)</span >
ld.lld: error: cannot preempt symbol: __TMC_END__
<span class="quote">>>> defined in /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtend.o
>>> referenced by crtstuff.c
>>> /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o:(.text+0x31)</span >
ld.lld: error: relocation R_X86_64_32S cannot be used against local symbol;
recompile with -fPIC
<span class="quote">>>> defined in /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o
>>> referenced by crtstuff.c
>>> /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o:(.text+0x38)</span >
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol;
recompile with -fPIC
<span class="quote">>>> defined in /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o
>>> referenced by crtstuff.c
>>> /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o:(.text+0x5A)</span >
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```
```
g++-9 ./hw.cpp -o hw -fPIE -Wl,-pic -Wl,-O1 -Wl,--sort-common -Wl,--as-needed
-Wl,-flto -Wl,-z,relro -Wl,-z,now -Wl,-z,ibtplt -Wl,-z,ibt -Wl,-z,shstk
-Wl,--verbose
GNU ld (GNU Binutils for Ubuntu) 2.33
....
/usr/bin/ld: mode elf_x86_64
....
attempt to open /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o succeeded
/usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o
```
compiles and links OK
<a href="https://dev.gentoo.org/~vapier/crt.txt">https://dev.gentoo.org/~vapier/crt.txt</a> says:
<span class="quote">>crtbegin.o
> GCC uses this to find the start of the constructors.
>crtbeginS.o
> Used in place of crtbegin.o when generating shared objects/PIEs.
>crtend.o
> GCC uses this to find the start of the destructors.
>crtendS.o
> Used in place of crtend.o when generating shared objects/PIEs.</span ></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>