From 2629602f28a451b9d0edb70392414bffec0aed7b Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 30 Sep 2016 06:48:09 +0000 Subject: [PATCH] Fix another --gc-sections crash. The missing case was when a merge section was only referenced from non-alloca sections. llvm-svn: 282847 --- lld/ELF/InputSection.cpp | 3 +++ lld/test/ELF/gc-sections-non-alloc-to-merge.s | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 1c01972fc8a1..6e73f6ff1d00 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -620,6 +620,9 @@ typename ELFT::uint MergeInputSection::getOffset(uintX_t Offset) const { if (It != OffsetMap.end()) return It->second; + if (!this->Live) + return 0; + // 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); diff --git a/lld/test/ELF/gc-sections-non-alloc-to-merge.s b/lld/test/ELF/gc-sections-non-alloc-to-merge.s index cdc11de88893..37b0328d8455 100644 --- a/lld/test/ELF/gc-sections-non-alloc-to-merge.s +++ b/lld/test/ELF/gc-sections-non-alloc-to-merge.s @@ -17,5 +17,11 @@ _start: .Lbar: .long 2 + .section .merge2,"aM",@progbits,4 + .p2align 2 +.Lzed: + .long 1 + .section bar .quad .Lbar + .quad .Lzed