forked from OSchip/llvm-project
[ELF] Optimize "Strip sections"
If SHT_LLVM_SYMPART is unused, don't iterate over inputSections. If neither --strip-debug/--strip-all, don't iterate over inputSections.
This commit is contained in:
parent
9daf576583
commit
1a590232f4
|
@ -363,6 +363,8 @@ struct Ctx {
|
||||||
// Symbols in a non-prevailing COMDAT group which should be changed to an
|
// Symbols in a non-prevailing COMDAT group which should be changed to an
|
||||||
// Undefined.
|
// Undefined.
|
||||||
SmallVector<std::pair<Symbol *, unsigned>, 0> nonPrevailingSyms;
|
SmallVector<std::pair<Symbol *, unsigned>, 0> nonPrevailingSyms;
|
||||||
|
// True if SHT_LLVM_SYMPART is used.
|
||||||
|
std::atomic<bool> hasSympart{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
// The only instance of Ctx struct.
|
// The only instance of Ctx struct.
|
||||||
|
|
|
@ -2601,17 +2601,18 @@ void LinkerDriver::link(opt::InputArgList &args) {
|
||||||
|
|
||||||
{
|
{
|
||||||
llvm::TimeTraceScope timeScope("Strip sections");
|
llvm::TimeTraceScope timeScope("Strip sections");
|
||||||
|
if (ctx->hasSympart.load(std::memory_order_relaxed)) {
|
||||||
llvm::erase_if(inputSections, [](InputSectionBase *s) {
|
llvm::erase_if(inputSections, [](InputSectionBase *s) {
|
||||||
if (s->type == SHT_LLVM_SYMPART) {
|
if (s->type != SHT_LLVM_SYMPART)
|
||||||
|
return false;
|
||||||
invokeELFT(readSymbolPartitionSection, s);
|
invokeELFT(readSymbolPartitionSection, s);
|
||||||
return true;
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// We do not want to emit debug sections if --strip-all
|
// We do not want to emit debug sections if --strip-all
|
||||||
// or --strip-debug are given.
|
// or --strip-debug are given.
|
||||||
if (config->strip == StripPolicy::None)
|
if (config->strip != StripPolicy::None) {
|
||||||
return false;
|
llvm::erase_if(inputSections, [](InputSectionBase *s) {
|
||||||
|
|
||||||
if (isDebugSection(*s))
|
if (isDebugSection(*s))
|
||||||
return true;
|
return true;
|
||||||
if (auto *isec = dyn_cast<InputSection>(s))
|
if (auto *isec = dyn_cast<InputSection>(s))
|
||||||
|
@ -2622,6 +2623,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Since we now have a complete set of input files, we can create
|
// Since we now have a complete set of input files, we can create
|
||||||
// a .d file to record build dependencies.
|
// a .d file to record build dependencies.
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "InputFiles.h"
|
#include "InputFiles.h"
|
||||||
|
#include "Config.h"
|
||||||
#include "DWARF.h"
|
#include "DWARF.h"
|
||||||
#include "Driver.h"
|
#include "Driver.h"
|
||||||
#include "InputSection.h"
|
#include "InputSection.h"
|
||||||
|
@ -600,6 +601,9 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
|
||||||
case SHT_RELA:
|
case SHT_RELA:
|
||||||
case SHT_NULL:
|
case SHT_NULL:
|
||||||
break;
|
break;
|
||||||
|
case SHT_LLVM_SYMPART:
|
||||||
|
ctx->hasSympart.store(true, std::memory_order_relaxed);
|
||||||
|
LLVM_FALLTHROUGH;
|
||||||
default:
|
default:
|
||||||
this->sections[i] =
|
this->sections[i] =
|
||||||
createInputSection(i, sec, check(obj.getSectionName(sec, shstrtab)));
|
createInputSection(i, sec, check(obj.getSectionName(sec, shstrtab)));
|
||||||
|
|
Loading…
Reference in New Issue