summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2016-08-31 08:38:11 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2016-08-31 08:38:11 +0000
commitf21aade0d8d96417b4a7e25c7ddc300b0ea6d718 (patch)
tree2ca62a0058b26722cc70d19f53e604e2a909e695
parent20889c51b7633419ed2162b247acb9f6ce532b07 (diff)
downloadbcm5719-llvm-f21aade0d8d96417b4a7e25c7ddc300b0ea6d718.tar.gz
bcm5719-llvm-f21aade0d8d96417b4a7e25c7ddc300b0ea6d718.zip
[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
-rw-r--r--lld/ELF/Config.h8
-rw-r--r--lld/ELF/Driver.cpp21
-rw-r--r--lld/ELF/InputFiles.cpp2
-rw-r--r--lld/ELF/Writer.cpp2
4 files changed, 20 insertions, 13 deletions
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 1144b2fa159..25ec18b64d2 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 89d5bb51163..3f2071b1fdf 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<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;
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index e0fd5f475b6..71ca4a1934e 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -323,7 +323,7 @@ elf::ObjectFile<ELFT>::createInputSection(const Elf_Shdr &Sec) {
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
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 8543fbf83d9..1c1f02c22c0 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -176,7 +176,7 @@ template <class ELFT> void elf::writeResult() {
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));
}
OpenPOWER on IntegriCloud