[lld] r282708 - Don't GC non-alloc mergeable section pieces
Eugene Leviant via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 29 03:27:11 PDT 2016
Author: evgeny777
Date: Thu Sep 29 05:27:10 2016
New Revision: 282708
URL: http://llvm.org/viewvc/llvm-project?rev=282708&view=rev
Log:
Don't GC non-alloc mergeable section pieces
Differential revision: https://reviews.llvm.org/D25033
Added:
lld/trunk/test/ELF/Inputs/comment-gc.s
lld/trunk/test/ELF/comment-gc.s
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/MarkLive.cpp
lld/trunk/test/ELF/debug-gc.s
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=282708&r1=282707&r2=282708&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Thu Sep 29 05:27:10 2016
@@ -572,9 +572,16 @@ template <class ELFT> void MergeInputSec
else
this->Pieces = splitNonStrings(Data, EntSize);
- if (Config->GcSections)
- for (uintX_t Off : LiveOffsets)
- this->getSectionPiece(Off)->Live = true;
+ if (Config->GcSections) {
+ if (this->getSectionHdr()->sh_flags & SHF_ALLOC) {
+ for (uintX_t Off : LiveOffsets)
+ this->getSectionPiece(Off)->Live = true;
+ return;
+ }
+
+ for (SectionPiece &Piece : this->Pieces)
+ Piece.Live = true;
+ }
}
template <class ELFT>
Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=282708&r1=282707&r2=282708&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Thu Sep 29 05:27:10 2016
@@ -64,11 +64,6 @@ static typename ELFT::uint getAddend(Inp
return Rel.r_addend;
}
-template <class ELFT> static bool IsAlloc(InputSectionBase<ELFT> &Sec) {
- return (&Sec != &InputSection<ELFT>::Discarded) &&
- (Sec.getSectionHdr()->sh_flags & SHF_ALLOC);
-}
-
template <class ELFT, class RelT>
static ResolvedReloc<ELFT> resolveReloc(InputSectionBase<ELFT> &Sec,
RelT &Rel) {
@@ -76,8 +71,6 @@ static ResolvedReloc<ELFT> resolveReloc(
auto *D = dyn_cast<DefinedRegular<ELFT>>(&B);
if (!D || !D->Section)
return {nullptr, 0};
- if (!IsAlloc<ELFT>(Sec) && IsAlloc<ELFT>(*D->Section))
- return {nullptr, 0};
typename ELFT::uint Offset = D->Value;
if (D->isSection())
Offset += getAddend(Sec, Rel);
@@ -214,8 +207,12 @@ template <class ELFT> void elf::markLive
if (R.Sec->Live)
return;
R.Sec->Live = true;
+ // Add input section to the queue. We don't want to consider relocations
+ // from non-allocatable input sections, because we can bring those
+ // allocatable sections to living which otherwise would be dead.
if (InputSection<ELFT> *S = dyn_cast<InputSection<ELFT>>(R.Sec))
- Q.push_back(S);
+ if (S->getSectionHdr()->sh_flags & SHF_ALLOC)
+ Q.push_back(S);
};
auto MarkSymbol = [&](const SymbolBody *Sym) {
Added: lld/trunk/test/ELF/Inputs/comment-gc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/comment-gc.s?rev=282708&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/comment-gc.s (added)
+++ lld/trunk/test/ELF/Inputs/comment-gc.s Thu Sep 29 05:27:10 2016
@@ -0,0 +1 @@
+.ident "bar"
Added: lld/trunk/test/ELF/comment-gc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/comment-gc.s?rev=282708&view=auto
==============================================================================
--- lld/trunk/test/ELF/comment-gc.s (added)
+++ lld/trunk/test/ELF/comment-gc.s Thu Sep 29 05:27:10 2016
@@ -0,0 +1,14 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/comment-gc.s -o %t2.o
+# RUN: ld.lld %t.o %t2.o -o %t1 --gc-sections -shared
+# RUN: llvm-objdump -s %t1 | FileCheck %s
+
+# CHECK: Contents of section .comment:
+# CHECK-NEXT: 0000 00666f6f 00626172 00 .foo.bar.
+
+.ident "foo"
+
+.globl _start
+_start:
+ nop
Modified: lld/trunk/test/ELF/debug-gc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/debug-gc.s?rev=282708&r1=282707&r2=282708&view=diff
==============================================================================
--- lld/trunk/test/ELF/debug-gc.s (original)
+++ lld/trunk/test/ELF/debug-gc.s Thu Sep 29 05:27:10 2016
@@ -4,7 +4,7 @@
# RUN: llvm-objdump -s %t1 | FileCheck %s
# CHECK: Contents of section .debug_str:
-# CHECK-NEXT: 0000 41414100 42424200 AAA.BBB.
+# CHECK-NEXT: 0000 41414100 42424200 43434300 AAA.BBB.CCC.
# CHECK: Contents of section .debug_info:
# CHECK-NEXT: 0000 00000000 04000000
More information about the llvm-commits
mailing list