Index: lld/trunk/ELF/Config.h =================================================================== --- lld/trunk/ELF/Config.h +++ lld/trunk/ELF/Config.h @@ -30,8 +30,13 @@ 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 @@ bool SaveTemps; bool Shared; bool Static = false; - bool StripAll; - bool StripDebug; bool SysvHash = true; bool Target1Rel; bool Threads; @@ -115,6 +118,7 @@ bool ZNow; bool ZOrigin; bool ZRelro; + StripPolicy Strip = StripPolicy::None; UnresolvedPolicy UnresolvedSymbols; BuildIdKind BuildId = BuildIdKind::None; ELFKind EKind = ELFNoneKind; Index: lld/trunk/ELF/Driver.cpp =================================================================== --- lld/trunk/ELF/Driver.cpp +++ lld/trunk/ELF/Driver.cpp @@ -344,6 +344,15 @@ 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 @@ 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 @@ 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; Index: lld/trunk/ELF/InputFiles.cpp =================================================================== --- lld/trunk/ELF/InputFiles.cpp +++ lld/trunk/ELF/InputFiles.cpp @@ -323,7 +323,7 @@ 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 Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -176,7 +176,7 @@ 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)); }