Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -32,6 +32,8 @@ enum class BuildIdKind { None, Fnv1, Md5, Sha1, Hexstring }; +enum class StripPolicy { None, All, Debug }; + enum class UnresolvedPolicy { NoUndef, Error, Warn, Ignore }; struct SymbolVersion { @@ -101,8 +103,6 @@ bool SaveTemps; bool Shared; bool Static = false; - bool StripAll; - bool StripDebug; bool SysvHash = true; bool Target1Rel; bool Threads; @@ -115,6 +115,7 @@ bool ZNow; bool ZOrigin; bool ZRelro; + StripPolicy Strip; UnresolvedPolicy UnresolvedSymbols; BuildIdKind BuildId = BuildIdKind::None; ELFKind EKind = ELFNoneKind; Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -344,6 +344,18 @@ return false; } +static StripPolicy getStripOption(opt::InputArgList &Args) { + if (Config->Relocatable) + return StripPolicy::None; + + if (auto *Arg = Args.getLastArg(OPT_strip_all, OPT_strip_debug)) + if (Arg->getOption().getID() == OPT_strip_all) + return StripPolicy::All; + else + 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 +395,7 @@ 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->Strip = getStripOption(Args); Config->Target1Rel = Args.hasArg(OPT_target1_rel); Config->Threads = Args.hasArg(OPT_threads); Config->Trace = Args.hasArg(OPT_trace); @@ -420,13 +431,6 @@ 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: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ 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: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -174,7 +174,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)); }