[llvm] r329716 - Add missing nullptr check to AArch64MachObjectWriter::recordRelocation

Jessica Paquette via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 10 08:53:28 PDT 2018


Author: paquette
Date: Tue Apr 10 08:53:28 2018
New Revision: 329716

URL: http://llvm.org/viewvc/llvm-project?rev=329716&view=rev
Log:
Add missing nullptr check to AArch64MachObjectWriter::recordRelocation

There was missing nullptr check before a call to getSection() in
recordRelocation. This would result in a segfault in code like the attached
test.

This adds the missing check and a test which makes sure we get the expected 
error output.


Added:
    llvm/trunk/test/MC/AArch64/arm64-no-section.ll
Modified:
    llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp

Modified: llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp?rev=329716&r1=329715&r2=329716&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp Tue Apr 10 08:53:28 2018
@@ -305,7 +305,8 @@ void AArch64MachObjectWriter::recordRelo
 
     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();

Added: llvm/trunk/test/MC/AArch64/arm64-no-section.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AArch64/arm64-no-section.ll?rev=329716&view=auto
==============================================================================
--- llvm/trunk/test/MC/AArch64/arm64-no-section.ll (added)
+++ llvm/trunk/test/MC/AArch64/arm64-no-section.ll Tue Apr 10 08:53:28 2018
@@ -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
+}




More information about the llvm-commits mailing list