<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 - hwasan does not link with lld due to pc-relative relocations to .text"
href="https://bugs.llvm.org/show_bug.cgi?id=35931">35931</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>hwasan does not link with lld due to pc-relative relocations to .text
</td>
</tr>
<tr>
<th>Product</th>
<td>compiler-rt
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</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>compiler-rt
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>peter.smith@linaro.org
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>When lld is used as the linker the compiler-rt fails when linking
libclang_rt.hwasan-aarch64.so
ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against
symbol __interceptor_signal; recompile with -fPIC
<span class="quote">>>> defined in lib/hwasan/CMakeFiles/RTHwasan_dynamic.aarch64.dir/hwasan_interceptors.cc.o
>>> referenced by sanitizer_signal_interceptors.inc:85 (/linaro/crosslibcxx/llvm/projects/compiler-rt/lib/hwasan/../sanitizer_common/sanitizer_signal_interceptors.inc:85)
>>> lib/hwasan/CMakeFiles/RTHwasan_dynamic.aarch64.dir/hwasan_interceptors.cc.o:(__hwasan::InitializeInterceptors())</span >
The object files for libclang_rt.hwasan-aarch64.so appear to be compiled with
-fPIE and not with -fPIC. As no symbol is preemptible in an executable the
compiler will use static non GOT-generating relocations for code like:
typedef int fptr(void);
int func(void) {
return 0;
}
fptr* func2(void) {
return &func;
}
In the context of a shared library the symbols are preemptible and therefore it
is not safe to resolve the relocations at static link-time as the destination
can move at run-time.
As it happens ld.bfd and ld.gold will silently resolve the relocations at
static link time, which lets the link succeed. In theory the library will cease
to work if a symbol is preempted but I'm guessing that the use-case of hwasan
makes that extremely unlikely. Unfortunately the linker can't know that so I
think lld is right to give an error here.
I've raised PR35929 on lld to see whether it should handle this case with
-znotext. However I think it is worth not producing these relocations in
hwasan. I think that this could be achieved by either giving the symbols
STV_PROTECTED visibility or creating a STV_HIDDEN alias at the same address
that internal callers/address takers can use. If neither lld or hwasan will
change it will be worth removing the -fPIE flag if lld is detected as the
linker.</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>