[lld] r280206 - [ELF] - Introduce StripPolicy instead of Config->StripAll/StripDebug flags.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 31 01:38:12 PDT 2016
Author: grimar
Date: Wed Aug 31 03:38:11 2016
New Revision: 280206
URL: http://llvm.org/viewvc/llvm-project?rev=280206&view=rev
Log:
[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
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=280206&r1=280205&r2=280206&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Wed Aug 31 03:38:11 2016
@@ -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;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=280206&r1=280205&r2=280206&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Aug 31 03:38:11 2016
@@ -344,6 +344,15 @@ static bool isOutputFormatBinary(opt::In
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::Inpu
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::Inpu
Config->ZOrigin = hasZOption(Args, "origin");
Config->ZRelro = !hasZOption(Args, "norelro");
+ if (!Config->Relocatable)
+ Config->Strip = getStripOption(Args);
+
if (Optional<StringRef> 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;
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=280206&r1=280205&r2=280206&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Wed Aug 31 03:38:11 2016
@@ -323,7 +323,7 @@ elf::ObjectFile<ELFT>::createInputSectio
return &InputSection<ELFT>::Discarded;
}
- if (Config->StripDebug && Name.startswith(".debug"))
+ if (Config->Strip != StripPolicy::None && Name.startswith(".debug"))
return &InputSection<ELFT>::Discarded;
// The linker merges EH (exception handling) frames and creates a
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=280206&r1=280205&r2=280206&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Aug 31 03:38:11 2016
@@ -176,7 +176,7 @@ template <class ELFT> void elf::writeRes
StringRef S = Config->Rela ? ".rela.plt" : ".rel.plt";
GotPlt.reset(new GotPltSection<ELFT>);
RelaPlt.reset(new RelocationSection<ELFT>(S, false /*Sort*/));
- if (!Config->StripAll) {
+ if (Config->Strip != StripPolicy::All) {
StrTab.reset(new StringTableSection<ELFT>(".strtab", false));
SymTabSec.reset(new SymbolTableSection<ELFT>(*StrTab));
}
More information about the llvm-commits
mailing list