[lld] r316418 - [ELF] - Do not collect SHT_REL[A] sections unconditionally when --gc-sections and --emit-relocs used together.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 24 01:26:32 PDT 2017
Author: grimar
Date: Tue Oct 24 01:26:32 2017
New Revision: 316418
URL: http://llvm.org/viewvc/llvm-project?rev=316418&view=rev
Log:
[ELF] - Do not collect SHT_REL[A] sections unconditionally when --gc-sections and --emit-relocs used together.
This is "Bug 34836 - --gc-sections remove relocations from --emit-relocs",
When --emit-relocs is used, LLD currently always drops SHT_REL[A] sections from
output if --gc-sections is present. Patch fixes the issue.
Differential revision: https://reviews.llvm.org/D38724
Modified:
lld/trunk/ELF/InputSection.h
lld/trunk/ELF/MarkLive.cpp
lld/trunk/test/ELF/emit-relocs-gc.s
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=316418&r1=316417&r2=316418&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Tue Oct 24 01:26:32 2017
@@ -237,8 +237,8 @@ public:
// Mark the piece at a given offset live. Used by GC.
void markLiveAt(uint64_t Offset) {
- assert(this->Flags & llvm::ELF::SHF_ALLOC);
- LiveOffsets.insert(Offset);
+ if (this->Flags & llvm::ELF::SHF_ALLOC)
+ LiveOffsets.insert(Offset);
}
// Translate an offset in the input section to an offset
Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=316418&r1=316417&r2=316418&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Tue Oct 24 01:26:32 2017
@@ -162,9 +162,9 @@ scanEhFrameSection(EhInputSection &EH,
scanEhFrameSection<ELFT>(EH, EH.template rels<ELFT>(), Fn);
}
-// We do not garbage-collect two types of sections:
-// 1) Sections used by the loader (.init, .fini, .ctors, .dtors or .jcr)
-// 2) Non-allocatable sections which typically contain debugging information
+// Some sections are used directly by the loader, so they should never be
+// garbage-collected. This function returns true if a given section is such
+// section.
template <class ELFT> static bool isReserved(InputSectionBase *Sec) {
switch (Sec->Type) {
case SHT_FINI_ARRAY:
@@ -173,9 +173,6 @@ template <class ELFT> static bool isRese
case SHT_PREINIT_ARRAY:
return true;
default:
- if (!(Sec->Flags & SHF_ALLOC))
- return true;
-
StringRef S = Sec->Name;
return S.startswith(".ctors") || S.startswith(".dtors") ||
S.startswith(".init") || S.startswith(".fini") ||
@@ -198,9 +195,6 @@ template <class ELFT> static void doGcSe
if (Sec == &InputSection::Discarded)
return;
- // We don't gc non alloc sections.
- if (!(Sec->Flags & SHF_ALLOC))
- return;
// Usually, a whole section is marked as live or dead, but in mergeable
// (splittable) sections, each piece of data has independent liveness bit.
Modified: lld/trunk/test/ELF/emit-relocs-gc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/emit-relocs-gc.s?rev=316418&r1=316417&r2=316418&view=diff
==============================================================================
--- lld/trunk/test/ELF/emit-relocs-gc.s (original)
+++ lld/trunk/test/ELF/emit-relocs-gc.s Tue Oct 24 01:26:32 2017
@@ -1,18 +1,30 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
-## Show that we emit .rela.bar when GC is disabled.
+## Show that we emit .rela.bar and .rela.text when GC is disabled.
# RUN: ld.lld --emit-relocs %t.o -o %t
# RUN: llvm-objdump %t -section-headers | FileCheck %s --check-prefix=NOGC
+# NOGC: .rela.text
# NOGC: .rela.bar
-## GC collects .bar section and we exclude .rela.bar from output.
+## GC collects .bar section and we exclude .rela.bar from output. We keep
+## .rela.text because we keep .text.
# RUN: ld.lld --gc-sections --emit-relocs --print-gc-sections %t.o -o %t \
# RUN: | FileCheck --check-prefix=MSG %s
# MSG: removing unused section from '.bar' in file
# MSG: removing unused section from '.rela.bar' in file
# RUN: llvm-objdump %t -section-headers | FileCheck %s --check-prefix=GC
# GC-NOT: rela.bar
+# GC: rela.text
+# GC-NOT: rela.bar
.section .bar,"a"
.quad .bar
+
+.text
+relocs:
+.quad _start
+
+.global _start
+_start:
+ nop
More information about the llvm-commits
mailing list