summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2016-09-30 06:37:29 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2016-09-30 06:37:29 +0000
commitc1eff79f61ff76e181fa73e0478d14a9d3d58008 (patch)
treed9a8876bca729f0c969f305e4c2c43e3553ab5fc
parentacac3ab7797c69fcb3a55277dc59bf286351ab96 (diff)
downloadbcm5719-llvm-c1eff79f61ff76e181fa73e0478d14a9d3d58008.tar.gz
bcm5719-llvm-c1eff79f61ff76e181fa73e0478d14a9d3d58008.zip
Fix --gc-sections crash.
We would crash when a non-alloca section pointed to a gced part of a merge section. That can happen when a C/c++ constant in put in a merge section and debug info is present. llvm-svn: 282845
-rw-r--r--lld/ELF/InputSection.cpp4
-rw-r--r--lld/test/ELF/gc-sections-non-alloc-to-merge.s21
2 files changed, 24 insertions, 1 deletions
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 964bf392dd8..1c01972fc8a 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -623,7 +623,9 @@ typename ELFT::uint MergeInputSection<ELFT>::getOffset(uintX_t Offset) const {
// If Offset is not at beginning of a section piece, it is not in the map.
// In that case we need to search from the original section piece vector.
const SectionPiece &Piece = *this->getSectionPiece(Offset);
- assert(Piece.Live);
+ if (!Piece.Live)
+ return 0;
+
uintX_t Addend = Offset - Piece.InputOff;
return Piece.OutputOff + Addend;
}
diff --git a/lld/test/ELF/gc-sections-non-alloc-to-merge.s b/lld/test/ELF/gc-sections-non-alloc-to-merge.s
new file mode 100644
index 00000000000..cdc11de8889
--- /dev/null
+++ b/lld/test/ELF/gc-sections-non-alloc-to-merge.s
@@ -0,0 +1,21 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o -o %t --gc-sections
+# RUN: llvm-readobj -s --elf-output-style=GNU %t | FileCheck %s
+
+# CHECK: .merge1 PROGBITS {{[0-9a-z]*}} {{[0-9a-z]*}} 000004
+
+ .global _start
+_start:
+ .quad .Lfoo
+
+ .section .merge1,"aM",@progbits,4
+ .p2align 2
+.Lfoo:
+ .long 1
+.Lbar:
+ .long 2
+
+ .section bar
+ .quad .Lbar
OpenPOWER on IntegriCloud