[PATCH] D45462: Add missing nullptr check before getSection() to AArch64MachObjectWriter::recordRelocation
Jessica Paquette via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 9 15:17:00 PDT 2018
paquette created this revision.
paquette added reviewers: espindola, t.p.northover, thegameg.
Herald added subscribers: kristof.beyls, javed.absar, rengolin.
There was a missing nullptr check in AArch64MachObjectWriter::recordRelocation which would cause a segfault in code like the attached test.
This patch adds the missing check and ensures that we get an error message instead of a crash.
https://reviews.llvm.org/D45462
Files:
lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
test/MC/AArch64/arm64-no-section.ll
Index: test/MC/AArch64/arm64-no-section.ll
===================================================================
--- /dev/null
+++ test/MC/AArch64/arm64-no-section.ll
@@ -0,0 +1,10 @@
+; RUN: llc -mtriple=aarch64-darwin-- -filetype=obj %s -o -
+; CHECK: <inline asm>:1:2: error: unsupported relocation of local symbol
+; CHECK-SAME: 'L_foo_end'. Must have non-local symbol earlier in section.
+
+; Make sure that we emit an error when we try to reference something that
+; doesn't belong to a section.
+define void @foo() local_unnamed_addr {
+ tail call void asm sideeffect "b L_foo_end\0A", ""()
+ ret void
+}
Index: lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
===================================================================
--- lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
+++ lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
@@ -305,7 +305,8 @@
bool CanUseLocalRelocation =
canUseLocalRelocation(Section, *Symbol, Log2Size);
- if (Symbol->isTemporary() && (Value || !CanUseLocalRelocation)) {
+ if (Symbol->isTemporary() && Symbol->isInSection() &&
+ (Value || !CanUseLocalRelocation)) {
const MCSection &Sec = Symbol->getSection();
if (!Asm.getContext().getAsmInfo()->isSectionAtomizableBySymbols(Sec))
Symbol->setUsedInReloc();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45462.141750.patch
Type: text/x-patch
Size: 1332 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180409/c3121150/attachment.bin>
More information about the llvm-commits
mailing list