[lld] r323366 - Fix lld crash introduced by r321154.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 24 11:16:31 PST 2018
Author: rafael
Date: Wed Jan 24 11:16:31 2018
New Revision: 323366
URL: http://llvm.org/viewvc/llvm-project?rev=323366&view=rev
Log:
Fix lld crash introduced by r321154.
Since SyntheticSection::getParent() may return null, dereferencing
this pointer in ARMExidxSentinelSection::empty() call from
removeUnusedSyntheticSections() results in crashes when linking ARM
binaries.
Patch by vit9696!
Added:
lld/trunk/test/ELF/arm-exidx-discard.s
Modified:
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=323366&r1=323365&r2=323366&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Jan 24 11:16:31 2018
@@ -1309,7 +1309,7 @@ static void removeUnusedSyntheticSection
if (!SS)
return;
OutputSection *OS = SS->getParent();
- if (!SS->empty() || !OS)
+ if (!OS || !SS->empty())
continue;
std::vector<BaseCommand *>::iterator Empty = OS->SectionCommands.end();
Added: lld/trunk/test/ELF/arm-exidx-discard.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/arm-exidx-discard.s?rev=323366&view=auto
==============================================================================
--- lld/trunk/test/ELF/arm-exidx-discard.s (added)
+++ lld/trunk/test/ELF/arm-exidx-discard.s Wed Jan 24 11:16:31 2018
@@ -0,0 +1,14 @@
+// RUN: llvm-mc -filetype=obj -triple arm-gnu-linux-eabi -mcpu cortex-a7 -arm-add-build-attributes %s -o %t.o
+// RUN: echo "ENTRY(__entrypoint) SECTIONS { . = 0x10000; .text : { *(.text .text.*) } /DISCARD/ : { *(.ARM.exidx*) *(.gnu.linkonce.armexidx.*) } }" > %t.script
+// RUN: ld.lld -T %t.script %t.o -o %t.elf 2>&1
+// RUN: llvm-readobj -sections %t.elf | FileCheck %s
+// REQUIRES: arm
+
+.globl __entrypoint
+__entrypoint:
+ bx lr
+
+// Check that .ARM.exidx/.gnu.linkonce.armexidx
+// are correctly removed if they were added.
+// CHECK-NOT: .ARM.exidx
+// CHECK-NOT: .gnu.linkonce.armexidx.
More information about the llvm-commits
mailing list