[lld] r282393 - Linkerscript: don't crash when GC .debug_line
Eugene Leviant via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 26 02:04:16 PDT 2016
Author: evgeny777
Date: Mon Sep 26 04:04:16 2016
New Revision: 282393
URL: http://llvm.org/viewvc/llvm-project?rev=282393&view=rev
Log:
Linkerscript: don't crash when GC .debug_line
Differential revision: https://reviews.llvm.org/D24870
Added:
lld/trunk/test/ELF/linkerscript/Inputs/comdat-gc.s
lld/trunk/test/ELF/linkerscript/comdat-gc.s
Modified:
lld/trunk/ELF/MarkLive.cpp
Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=282393&r1=282392&r2=282393&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Mon Sep 26 04:04:16 2016
@@ -81,13 +81,6 @@ static ResolvedReloc<ELFT> resolveReloc(
template <class ELFT>
static void forEachSuccessor(InputSection<ELFT> &Sec,
std::function<void(ResolvedReloc<ELFT>)> Fn) {
- // Skip over discarded sections. This in theory shouldn't happen, because
- // the ELF spec doesn't allow a relocation to point to a deduplicated
- // COMDAT section directly. Unfortunately this happens in practice (e.g.
- // .eh_frame) so we need to add a check.
- if (&Sec == &InputSection<ELFT>::Discarded)
- return;
-
ELFFile<ELFT> &Obj = Sec.getFile()->getObj();
for (const typename ELFT::Shdr *RelSec : Sec.RelocSections) {
if (RelSec->sh_type == SHT_RELA) {
@@ -198,7 +191,11 @@ template <class ELFT> void elf::markLive
SmallVector<InputSection<ELFT> *, 256> Q;
auto Enqueue = [&](ResolvedReloc<ELFT> R) {
- if (!R.Sec)
+ // Skip over discarded sections. This in theory shouldn't happen, because
+ // the ELF spec doesn't allow a relocation to point to a deduplicated
+ // COMDAT section directly. Unfortunately this happens in practice (e.g.
+ // .eh_frame) so we need to add a check.
+ if (!R.Sec || R.Sec == &InputSection<ELFT>::Discarded)
return;
// Usually, a whole section is marked as live or dead, but in mergeable
Added: lld/trunk/test/ELF/linkerscript/Inputs/comdat-gc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/Inputs/comdat-gc.s?rev=282393&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/Inputs/comdat-gc.s (added)
+++ lld/trunk/test/ELF/linkerscript/Inputs/comdat-gc.s Mon Sep 26 04:04:16 2016
@@ -0,0 +1,5 @@
+.file 1 "test/ELF/linkerscript/Inputs/comdat_gc.s"
+
+.section .text._Z3fooIiEvv,"axG", at progbits,_Z3fooIiEvv,comdat
+.loc 1 5
+ ret
Added: lld/trunk/test/ELF/linkerscript/comdat-gc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/comdat-gc.s?rev=282393&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/comdat-gc.s (added)
+++ lld/trunk/test/ELF/linkerscript/comdat-gc.s Mon Sep 26 04:04:16 2016
@@ -0,0 +1,14 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/comdat-gc.s -o %t1
+# RUN: echo "SECTIONS { .text : { *(.text*) } }" > %t.script
+# RUN: ld.lld --gc-sections --script %t.script %t %t1 -o %t2
+# RUN: llvm-readobj -sections -symbols %t2 | FileCheck -check-prefix=GC1 %s
+
+# GC1: Name: .debug_line
+
+.file 1 "test/ELF/linkerscript/comdat_gc.s"
+.section .text._Z3fooIiEvv,"axG", at progbits,_Z3fooIiEvv,comdat
+.loc 1 14
+ ret
More information about the llvm-commits
mailing list