[lld] r282845 - Fix --gc-sections crash.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 29 23:37:29 PDT 2016
Author: rafael
Date: Fri Sep 30 01:37:29 2016
New Revision: 282845
URL: http://llvm.org/viewvc/llvm-project?rev=282845&view=rev
Log:
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.
Added:
lld/trunk/test/ELF/gc-sections-non-alloc-to-merge.s
Modified:
lld/trunk/ELF/InputSection.cpp
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=282845&r1=282844&r2=282845&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Fri Sep 30 01:37:29 2016
@@ -623,7 +623,9 @@ typename ELFT::uint MergeInputSection<EL
// 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;
}
Added: lld/trunk/test/ELF/gc-sections-non-alloc-to-merge.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gc-sections-non-alloc-to-merge.s?rev=282845&view=auto
==============================================================================
--- lld/trunk/test/ELF/gc-sections-non-alloc-to-merge.s (added)
+++ lld/trunk/test/ELF/gc-sections-non-alloc-to-merge.s Fri Sep 30 01:37:29 2016
@@ -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", at progbits,4
+ .p2align 2
+.Lfoo:
+ .long 1
+.Lbar:
+ .long 2
+
+ .section bar
+ .quad .Lbar
More information about the llvm-commits
mailing list