<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 - Crash when building arm64 Linux kernel with --emit-relocs"
href="https://bugs.llvm.org/show_bug.cgi?id=48357">48357</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Crash when building arm64 Linux kernel with --emit-relocs
</td>
</tr>
<tr>
<th>Product</th>
<td>lld
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>ELF
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>david.brazdil@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, smithp352@googlemail.com
</td>
</tr></table>
<p>
<div>
<pre>Hi,
I've been experimenting with relocs in the arm64 Linux kernel and managed to
get an LLD crash.
Checked llvm-project ToT (commit e0bf2349303f6b40e3ddd5377ea08a5c0867ece4) and
it still happens there.
>From quick debugging, it is a null-pointer `first` in
lld/ELF/OutputSections.cpp, OutputSection::finalize():
```
if (!config->copyRelocs || (type != SHT_RELA && type != SHT_REL))
return;
if (isa<SyntheticSection>(first)) // <<<< HERE
return;
link = in.symTab->getParent()->sectionIndex;
```
The kernel is v5.10-rc1 built with `CONFIG_RELOCATABLE=n` and the following
diff:
```
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 5789c2d18d43..aa68f6b6524a 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -18,6 +18,8 @@ ifeq ($(CONFIG_RELOCATABLE), y)
# with the relocation offsets always being zero.
LDFLAGS_vmlinux += -shared -Bsymbolic -z notext \
$(call ld-option, --no-apply-dynamic-relocs)
+else
+LDFLAGS_vmlinux += --emit-relocs
endif
ifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
```
The crash:
+ ld.lld -EL -maarch64elf --no-undefined -X -z norelro --emit-relocs
--fix-cortex-a53-843419 --orphan-handling=warn --build-id=sha1 --strip-debug -o
.tmp_vmlinux.kallsyms1 -T ./arch/arm64/kernel/vmlinux.lds --whole-archive
arch/arm64/kernel/head.o init/built-in.a usr/built-in.a arch/arm64/built-in.a
kernel/built-in.a certs/built-in.a mm/built-in.a fs/built-in.a ipc/built-in.a
security/built-in.a crypto/built-in.a block/built-in.a
arch/arm64/lib/built-in.a lib/built-in.a arch/arm64/lib/lib.a lib/lib.a
drivers/built-in.a sound/built-in.a net/built-in.a virt/built-in.a
--no-whole-archive --start-group ./drivers/firmware/efi/libstub/lib.a
--end-group
PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash
backtrace.
Stack dump:
0. Program arguments: ld.lld -EL -maarch64elf --no-undefined -X -z norelro
--emit-relocs --fix-cortex-a53-843419 --orphan-handling=warn --build-id=sha1
--strip-debug -o .tmp_vmlinux.kallsyms1 -T ./arch/arm64/kernel/vmlinux.lds
--whole-archive arch/arm64/kernel/head.o init/built-in.a usr/built-in.a
arch/arm64/built-in.a kernel/built-in.a certs/built-in.a mm/built-in.a
fs/built-in.a ipc/built-in.a security/built-in.a crypto/built-in.a
block/built-in.a arch/arm64/lib/built-in.a lib/built-in.a arch/arm64/lib/lib.a
lib/lib.a drivers/built-in.a sound/built-in.a net/built-in.a virt/
built-in.a --no-whole-archive --start-group
./drivers/firmware/efi/libstub/lib.a --end-group
#0 0x000000000162fa63 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
(/usr/local/google/home/dbrazdil/dev/tc-build/install/bin/lld+0x162fa63)
#1 0x000000000162d9be llvm::sys::RunSignalHandlers()
(/usr/local/google/home/dbrazdil/dev/tc-build/install/bin/lld+0x162d9be)
#2 0x00000000016301f5 SignalHandler(int)
(/usr/local/google/home/dbrazdil/dev/tc-build/install/bin/lld+0x16301f5)
#3 0x00007fc459efa140 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x14140)
#4 0x00000000017b8e7e lld::elf::OutputSection::finalize()
(/usr/local/google/home/dbrazdil/dev/tc-build/install/bin/lld+0x17b8e7e)
#5 0x00000000018eca68 (anonymous
namespace)::Writer<llvm::object::ELFType<(llvm::support::endianness)1, true>
<span class="quote">>::finalizeSections()</span >
(/usr/local/google/home/dbrazdil/dev/tc-build/install/bin/lld+0x18eca68)
#6 0x00000000018b868b void
lld::elf::writeResult<llvm::object::ELFType<(llvm::support::endianness)1, true>
<span class="quote">>() (/usr/local/google/home/dbrazdil/dev/tc-build/install/bin/lld+0x18b868b)</span >
#7 0x000000000170fad6 void
lld::elf::LinkerDriver::link<llvm::object::ELFType<(llvm::support::endianness)1,
true> >(llvm::opt::InputArgList&)
(/usr/local/google/home/dbrazdil/dev/tc-build/install/bin/lld+0x170fad6)
#8 0x00000000017008e1 lld::elf::LinkerDriver::main(llvm::ArrayRef<char
const*>)
(/usr/local/google/home/dbrazdil/dev/tc-build/install/bin/lld+0x17008e1)
#9 0x00000000016fe15f lld::elf::link(llvm::ArrayRef<char const*>, bool,
llvm::raw_ostream&, llvm::raw_ostream&)
(/usr/local/google/home/dbrazdil/dev/tc-build/install/bin/lld+0x16fe15f)
#10 0x000000000159be55 lldMain(int, char const**, llvm::raw_ostream&,
llvm::raw_ostream&, bool)
(/usr/local/google/home/dbrazdil/dev/tc-build/install/bin/lld+0x159be55)
#11 0x000000000159b6c0 main
(/usr/local/google/home/dbrazdil/dev/tc-build/install/bin/lld+0x159b6c0)
#12 0x00007fc4599eccca __libc_start_main ./csu/../csu/libc-start.c:308:16
#13 0x000000000159b3ba _start
(/usr/local/google/home/dbrazdil/dev/tc-build/install/bin/lld+0x159b3ba)
../scripts/link-vmlinux.sh: line 89: 43038 Segmentation fault ${LD}
${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} ${strip_debug#-Wl,} -o ${output} -T ${lds}
${objects}</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>