From f21aade0d8d96417b4a7e25c7ddc300b0ea6d718 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Wed, 31 Aug 2016 08:38:11 +0000 Subject: [PATCH] [ELF] - Introduce StripPolicy instead of Config->StripAll/StripDebug flags. This approach is not only consistent with UnresolvedPolicy, but also should help to solve a problem of options with opposing meanings, mentioned in PR28843 Differential revision: https://reviews.llvm.org/D23869 llvm-svn: 280206 --- lld/ELF/Config.h | 8 ++++++-- lld/ELF/Driver.cpp | 21 ++++++++++++--------- lld/ELF/InputFiles.cpp | 2 +- lld/ELF/Writer.cpp | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index 1144b2f..25ec18b 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -30,8 +30,13 @@ enum ELFKind { ELF64BEKind }; +// For --build-id. enum class BuildIdKind { None, Fnv1, Md5, Sha1, Hexstring, Uuid }; +// For --strip-{all,debug}. +enum class StripPolicy { None, All, Debug }; + +// For --unresolved-symbols. enum class UnresolvedPolicy { NoUndef, Error, Warn, Ignore }; struct SymbolVersion { @@ -101,8 +106,6 @@ struct Configuration { bool SaveTemps; bool Shared; bool Static = false; - bool StripAll; - bool StripDebug; bool SysvHash = true; bool Target1Rel; bool Threads; @@ -115,6 +118,7 @@ struct Configuration { bool ZNow; bool ZOrigin; bool ZRelro; + StripPolicy Strip = StripPolicy::None; UnresolvedPolicy UnresolvedSymbols; BuildIdKind BuildId = BuildIdKind::None; ELFKind EKind = ELFNoneKind; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 89d5bb5..3f2071b 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -344,6 +344,15 @@ static bool isOutputFormatBinary(opt::InputArgList &Args) { return false; } +static StripPolicy getStripOption(opt::InputArgList &Args) { + if (auto *Arg = Args.getLastArg(OPT_strip_all, OPT_strip_debug)) { + if (Arg->getOption().getID() == OPT_strip_all) + return StripPolicy::All; + return StripPolicy::Debug; + } + return StripPolicy::None; +} + // Initializes Config members by the command line options. void LinkerDriver::readConfigs(opt::InputArgList &Args) { for (auto *Arg : Args.filtered(OPT_L)) @@ -383,8 +392,6 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) { Config->Relocatable = Args.hasArg(OPT_relocatable); Config->SaveTemps = Args.hasArg(OPT_save_temps); Config->Shared = Args.hasArg(OPT_shared); - Config->StripAll = Args.hasArg(OPT_strip_all); - Config->StripDebug = Args.hasArg(OPT_strip_debug); Config->Target1Rel = Args.hasArg(OPT_target1_rel); Config->Threads = Args.hasArg(OPT_threads); Config->Trace = Args.hasArg(OPT_trace); @@ -416,17 +423,13 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) { Config->ZOrigin = hasZOption(Args, "origin"); Config->ZRelro = !hasZOption(Args, "norelro"); + if (!Config->Relocatable) + Config->Strip = getStripOption(Args); + if (Optional Value = getZOptionValue(Args, "stack-size")) if (Value->getAsInteger(0, Config->ZStackSize)) error("invalid stack size: " + *Value); - if (Config->Relocatable) - Config->StripAll = false; - - // --strip-all implies --strip-debug. - if (Config->StripAll) - Config->StripDebug = true; - // Config->Pic is true if we are generating position-independent code. Config->Pic = Config->Pie || Config->Shared; diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index e0fd5f4..71ca4a1 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -323,7 +323,7 @@ elf::ObjectFile::createInputSection(const Elf_Shdr &Sec) { return &InputSection::Discarded; } - if (Config->StripDebug && Name.startswith(".debug")) + if (Config->Strip != StripPolicy::None && Name.startswith(".debug")) return &InputSection::Discarded; // The linker merges EH (exception handling) frames and creates a diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 8543fbf..1c1f02c 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -176,7 +176,7 @@ template void elf::writeResult() { StringRef S = Config->Rela ? ".rela.plt" : ".rel.plt"; GotPlt.reset(new GotPltSection); RelaPlt.reset(new RelocationSection(S, false /*Sort*/)); - if (!Config->StripAll) { + if (Config->Strip != StripPolicy::All) { StrTab.reset(new StringTableSection(".strtab", false)); SymTabSec.reset(new SymbolTableSection(*StrTab)); } -- 2.7.4