[lld] r360955 - Revert r358069 "Discard debuginfo for object files empty after GC"
Bob Haarman via llvm-commits
llvm-commits at lists.llvm.org
Thu May 16 16:33:07 PDT 2019
Author: inglorion
Date: Thu May 16 16:33:06 2019
New Revision: 360955
URL: http://llvm.org/viewvc/llvm-project?rev=360955&view=rev
Log:
Revert r358069 "Discard debuginfo for object files empty after GC"
The change broke some scenarios where debug information is still
needed, although MarkLive cannot see it, including the
Chromium/Android build. Reverting to unbreak that build.
Removed:
lld/trunk/test/ELF/linkerscript/debuginfo-gc.s
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/InputFiles.h
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/InputSection.h
lld/trunk/ELF/MarkLive.cpp
lld/trunk/test/ELF/linkerscript/comdat-gc.s
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=360955&r1=360954&r2=360955&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu May 16 16:33:06 2019
@@ -1670,8 +1670,11 @@ template <class ELFT> void LinkerDriver:
// We do not want to emit debug sections if --strip-all
// or -strip-debug are given.
- if (Config->Strip != StripPolicy::None)
- llvm::erase_if(InputSections, [](InputSectionBase *S) { return S->Debug; });
+ if (Config->Strip != StripPolicy::None) {
+ llvm::erase_if(InputSections, [](InputSectionBase *S) {
+ return S->Name.startswith(".debug") || S->Name.startswith(".zdebug");
+ });
+ }
Config->EFlags = Target->calcEFlags();
// MaxPageSize (sometimes called abi page size) is the maximum page size that
Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=360955&r1=360954&r2=360955&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Thu May 16 16:33:06 2019
@@ -237,10 +237,6 @@ public:
// but had one or more functions with the no_split_stack attribute.
bool SomeNoSplitStack = false;
- // True if the file has any live Regular or Merge sections that aren't
- // the LDSA section.
- bool HasLiveCodeOrData = false;
-
// Pointer to this input file's .llvm_addrsig section, if it has one.
const Elf_Shdr *AddrsigSec = nullptr;
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=360955&r1=360954&r2=360955&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Thu May 16 16:33:06 2019
@@ -71,7 +71,6 @@ InputSectionBase::InputSectionBase(Input
NumRelocations = 0;
AreRelocsRela = false;
- Debug = Name.startswith(".debug") || Name.startswith(".zdebug");
// The ELF spec states that a value of 0 means the section has
// no alignment constraits.
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=360955&r1=360954&r2=360955&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Thu May 16 16:33:06 2019
@@ -51,7 +51,7 @@ public:
unsigned SectionKind : 3;
- // The next four bit fields are only used by InputSectionBase, but we
+ // The next three bit fields are only used by InputSectionBase, but we
// put them here so the struct packs better.
// The garbage collector sets sections' Live bits.
@@ -73,9 +73,6 @@ public:
unsigned Bss : 1;
- // True if this is a debuginfo section.
- unsigned Debug : 1;
-
// Set for sections that should not be folded by ICF.
unsigned KeepUnique : 1;
@@ -103,9 +100,8 @@ protected:
uint64_t Entsize, uint64_t Alignment, uint32_t Type,
uint32_t Info, uint32_t Link)
: Name(Name), Repl(this), SectionKind(SectionKind), Live(false),
- Assigned(false), Bss(false), Debug(false), KeepUnique(false),
- Alignment(Alignment), Flags(Flags), Entsize(Entsize), Type(Type),
- Link(Link), Info(Info) {}
+ Assigned(false), Bss(false), KeepUnique(false), Alignment(Alignment),
+ Flags(Flags), Entsize(Entsize), Type(Type), Link(Link), Info(Info) {}
};
// This corresponds to a section of an input file.
Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=360955&r1=360954&r2=360955&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Thu May 16 16:33:06 2019
@@ -47,7 +47,7 @@ public:
void run();
private:
- void enqueue(InputSectionBase *Sec, uint64_t Offset, bool IsLSDA);
+ void enqueue(InputSectionBase *Sec, uint64_t Offset);
void markSymbol(Symbol *Sym);
template <class RelTy>
@@ -97,7 +97,7 @@ void MarkLive<ELFT>::resolveReloc(InputS
Offset += getAddend<ELFT>(Sec, Rel);
if (!IsLSDA || !(RelSec->Flags & SHF_EXECINSTR))
- enqueue(RelSec, Offset, IsLSDA);
+ enqueue(RelSec, Offset);
return;
}
@@ -106,7 +106,7 @@ void MarkLive<ELFT>::resolveReloc(InputS
SS->getFile().IsNeeded = true;
for (InputSectionBase *Sec : CNamedSections.lookup(Sym.getName()))
- enqueue(Sec, 0, IsLSDA);
+ enqueue(Sec, 0);
}
// The .eh_frame section is an unfortunate special case.
@@ -169,8 +169,7 @@ static bool isReserved(InputSectionBase
}
template <class ELFT>
-void MarkLive<ELFT>::enqueue(InputSectionBase *Sec, uint64_t Offset,
- bool IsLSDA) {
+void MarkLive<ELFT>::enqueue(InputSectionBase *Sec, uint64_t Offset) {
// 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.
@@ -184,26 +183,19 @@ void MarkLive<ELFT>::enqueue(InputSectio
if (auto *MS = dyn_cast<MergeInputSection>(Sec))
MS->getSectionPiece(Offset)->Live = true;
- InputSection *S = dyn_cast<InputSection>(Sec);
- // LSDA does not count as "live code or data" in the object file.
- // The section may already have been marked live for LSDA in which
- // case we still need to mark the file.
- if (S && !IsLSDA && Sec->File)
- Sec->getFile<ELFT>()->HasLiveCodeOrData = true;
-
if (Sec->Live)
return;
-
Sec->Live = true;
+
// Add input section to the queue.
- if (S)
+ if (InputSection *S = dyn_cast<InputSection>(Sec))
Queue.push_back(S);
}
template <class ELFT> void MarkLive<ELFT>::markSymbol(Symbol *Sym) {
if (auto *D = dyn_cast_or_null<Defined>(Sym))
if (auto *IS = dyn_cast_or_null<InputSectionBase>(D->Section))
- enqueue(IS, D->Value, false);
+ enqueue(IS, D->Value);
}
// This is the main function of the garbage collector.
@@ -247,7 +239,7 @@ template <class ELFT> void MarkLive<ELFT
continue;
if (isReserved(Sec) || Script->shouldKeep(Sec)) {
- enqueue(Sec, 0, false);
+ enqueue(Sec, 0);
} else if (isValidCIdentifier(Sec->Name)) {
CNamedSections[Saver.save("__start_" + Sec->Name)].push_back(Sec);
CNamedSections[Saver.save("__stop_" + Sec->Name)].push_back(Sec);
@@ -267,7 +259,7 @@ template <class ELFT> void MarkLive<ELFT
}
for (InputSectionBase *IS : Sec.DependentSections)
- enqueue(IS, 0, false);
+ enqueue(IS, 0);
}
}
@@ -293,7 +285,7 @@ template <class ELFT> void elf::markLive
// The -gc-sections option works only for SHF_ALLOC sections
// (sections that are memory-mapped at runtime). So we can
// unconditionally make non-SHF_ALLOC sections alive except
- // SHF_LINK_ORDER and SHT_REL/SHT_RELA sections and .debug sections.
+ // SHF_LINK_ORDER and SHT_REL/SHT_RELA sections.
//
// Usually, SHF_ALLOC sections are not removed even if they are
// unreachable through relocations because reachability is not
@@ -314,19 +306,13 @@ template <class ELFT> void elf::markLive
bool IsLinkOrder = (Sec->Flags & SHF_LINK_ORDER);
bool IsRel = (Sec->Type == SHT_REL || Sec->Type == SHT_RELA);
- if (!IsAlloc && !IsLinkOrder && !IsRel && !Sec->Debug)
+ if (!IsAlloc && !IsLinkOrder && !IsRel)
Sec->Live = true;
}
// Follow the graph to mark all live sections.
MarkLive<ELFT>().run();
- // Mark debug sections as live in any object file that has a live
- // Regular or Merge section.
- for (InputSectionBase *Sec : InputSections)
- if (Sec->Debug && Sec->getFile<ELFT>()->HasLiveCodeOrData)
- Sec->Live = true;
-
// Report garbage-collected sections.
if (Config->PrintGcSections)
for (InputSectionBase *Sec : InputSections)
Modified: lld/trunk/test/ELF/linkerscript/comdat-gc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/comdat-gc.s?rev=360955&r1=360954&r2=360955&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/comdat-gc.s (original)
+++ lld/trunk/test/ELF/linkerscript/comdat-gc.s Thu May 16 16:33:06 2019
@@ -8,9 +8,6 @@
# GC1: Name: .debug_line
-# Add .ctors section so all debuginfo isn't GCed
-.section .ctors,"ax", at progbits
-
.file 1 "test/ELF/linkerscript/comdat_gc.s"
.section .text._Z3fooIiEvv,"axG", at progbits,_Z3fooIiEvv,comdat
.loc 1 14
Removed: lld/trunk/test/ELF/linkerscript/debuginfo-gc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/debuginfo-gc.s?rev=360954&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/debuginfo-gc.s (original)
+++ lld/trunk/test/ELF/linkerscript/debuginfo-gc.s (removed)
@@ -1,14 +0,0 @@
-# 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 %s
-
-# CHECK-NOT: 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