<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 - [PowerPC64] relocation R_PPC64_REL24 out of range when building LLDB"
href="https://bugs.llvm.org/show_bug.cgi?id=42331">42331</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[PowerPC64] relocation R_PPC64_REL24 out of range when building LLDB
</td>
</tr>
<tr>
<th>Product</th>
<td>lld
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Other
</td>
</tr>
<tr>
<th>OS</th>
<td>FreeBSD
</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>ELF
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>alfredo.junior@eldorado.org.br
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org
</td>
</tr></table>
<p>
<div>
<pre>In a x86_64 host using LLVM 8.0.1 to cross compile FreeBSD to PowerPC64 target,
LLD refuses to link target LLDB with the following error:
ld: error:
/usr/home/alfredo.junior/src/freebsd/contrib/llvm/include/llvm/IR/BasicBlock.h:103:(.text._ZN5clang7CodeGen15CodeGenFunction22EmitNullInitializationENS0_7AddressENS_8QualTypeE+0x54C):
relocation R_PPC64_REL24 out of range: 33554432 is not in [-33554432, 33554431]
This is a very large binary (256 MB) and with recent introduction of
'getThunkSpacing' to allow large binaries to be linked (discussed in
<a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED FIXED - [PowerPC64] [ELFv2] wrong .init section for large binaries (long branch thunk)"
href="show_bug.cgi?id=40740">https://bugs.llvm.org/show_bug.cgi?id=40740</a>), I reviewed the code and I think
same logic used for ARM might be necessary to PowerPC64 too.
I was able to workaround (or fix?) the issue with the following change:
-- a/contrib/llvm/tools/lld/ELF/Arch/PPC64.cpp
+++ b/contrib/llvm/tools/lld/ELF/Arch/PPC64.cpp
@@ -764,8 +764,14 @@ uint32_t PPC64::getThunkSectionSpacing() const {
// See comment in Arch/ARM.cpp for a more detailed explanation of
// getThunkSectionSpacing(). For PPC64 we pick the constant here based on
// R_PPC64_REL24, which is used by unconditional branch instructions.
+ //
+ // Reducing it in 0x80000 allow creating 32,768 16 byte Thunks at any
+ // offset in a ThunkSection without risk of a branch to one of the
+ // Thunks going out of range.
+ //
// 0x2000000 = (1 << 24-1) * 4
- return 0x2000000;
+ // 0x80000 = 32768 * 16 byte thunk
+ return 0x2000000 - 0x80000;
}
I also noticed that issue isn't reproduced with LLD from LLVM 9, version 8 is
required. I'm not able to ensure that LLVM9 already has a fix, as it sounds
more like a coincidence due to changes in LLVM9.</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>