[lld] r280209 - [ELF] - Introduce DiscardPolicy instead of 3 relative bool fields.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 31 01:46:31 PDT 2016
Author: grimar
Date: Wed Aug 31 03:46:30 2016
New Revision: 280209
URL: http://llvm.org/viewvc/llvm-project?rev=280209&view=rev
Log:
[ELF] - Introduce DiscardPolicy instead of 3 relative bool fields.
DiscardPolicy is enum replacing several boolean options.
This approach is not only consistent with what we use for
unresolveds (UnresolvedPolicy), but also should help to solve a problem
of options with opposing meanings, mentioned in PR28843
Differential revision: https://reviews.llvm.org/D23868
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/OutputSections.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=280209&r1=280208&r2=280209&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Wed Aug 31 03:46:30 2016
@@ -33,6 +33,9 @@ enum ELFKind {
// For --build-id.
enum class BuildIdKind { None, Fnv1, Md5, Sha1, Hexstring, Uuid };
+// For --discard-{all,locals,none}.
+enum class DiscardPolicy { Default, All, Locals, None };
+
// For --strip-{all,debug}.
enum class StripPolicy { None, All, Debug };
@@ -84,9 +87,6 @@ struct Configuration {
bool BsymbolicFunctions;
bool Demangle = true;
bool DisableVerify;
- bool DiscardAll;
- bool DiscardLocals;
- bool DiscardNone;
bool EhFrameHdr;
bool EnableNewDtags;
bool ExportDynamic;
@@ -118,6 +118,7 @@ struct Configuration {
bool ZNow;
bool ZOrigin;
bool ZRelro;
+ DiscardPolicy Discard;
StripPolicy Strip = StripPolicy::None;
UnresolvedPolicy UnresolvedSymbols;
BuildIdKind BuildId = BuildIdKind::None;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=280209&r1=280208&r2=280209&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Aug 31 03:46:30 2016
@@ -344,6 +344,25 @@ static bool isOutputFormatBinary(opt::In
return false;
}
+static DiscardPolicy getDiscardOption(opt::InputArgList &Args) {
+ auto *Arg =
+ Args.getLastArg(OPT_discard_all, OPT_discard_locals, OPT_discard_none);
+ if (!Arg)
+ return DiscardPolicy::Default;
+
+ switch (Arg->getOption().getID()) {
+ case OPT_discard_all:
+ return DiscardPolicy::All;
+ case OPT_discard_locals:
+ return DiscardPolicy::Locals;
+ case OPT_discard_none:
+ return DiscardPolicy::None;
+ default:
+ llvm_unreachable("unknown discard option");
+ }
+}
+
+
static StripPolicy getStripOption(opt::InputArgList &Args) {
if (auto *Arg = Args.getLastArg(OPT_strip_all, OPT_strip_debug)) {
if (Arg->getOption().getID() == OPT_strip_all)
@@ -376,9 +395,7 @@ void LinkerDriver::readConfigs(opt::Inpu
Config->BsymbolicFunctions = Args.hasArg(OPT_Bsymbolic_functions);
Config->Demangle = !Args.hasArg(OPT_no_demangle);
Config->DisableVerify = Args.hasArg(OPT_disable_verify);
- Config->DiscardAll = Args.hasArg(OPT_discard_all);
- Config->DiscardLocals = Args.hasArg(OPT_discard_locals);
- Config->DiscardNone = Args.hasArg(OPT_discard_none);
+ Config->Discard = getDiscardOption(Args);
Config->EhFrameHdr = Args.hasArg(OPT_eh_frame_hdr);
Config->EnableNewDtags = !Args.hasArg(OPT_disable_new_dtags);
Config->ExportDynamic = Args.hasArg(OPT_export_dynamic);
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=280209&r1=280208&r2=280209&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Wed Aug 31 03:46:30 2016
@@ -1373,7 +1373,7 @@ template <class ELFT> void SymbolTableSe
// All symbols with STB_LOCAL binding precede the weak and global symbols.
// .dynsym only contains global symbols.
- if (!Config->DiscardAll && !StrTabSec.isDynamic())
+ if (Config->Discard != DiscardPolicy::All && !StrTabSec.isDynamic())
writeLocalSymbols(Buf);
writeGlobalSymbols(Buf);
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=280209&r1=280208&r2=280209&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Aug 31 03:46:30 2016
@@ -240,7 +240,7 @@ static std::vector<DefinedCommon<ELFT> *
// The main function of the writer.
template <class ELFT> void Writer<ELFT>::run() {
- if (!Config->DiscardAll)
+ if (Config->Discard != DiscardPolicy::All)
copyLocalSymbols();
addReservedSymbols();
@@ -329,7 +329,7 @@ static bool shouldKeepInSymtab(InputSect
if (Sec == &InputSection<ELFT>::Discarded)
return false;
- if (Config->DiscardNone)
+ if (Config->Discard == DiscardPolicy::None)
return true;
// In ELF assembly .L symbols are normally discarded by the assembler.
@@ -340,7 +340,7 @@ static bool shouldKeepInSymtab(InputSect
if (!SymName.startswith(".L") && !SymName.empty())
return true;
- if (Config->DiscardLocals)
+ if (Config->Discard == DiscardPolicy::Locals)
return false;
return !(Sec->getSectionHdr()->sh_flags & SHF_MERGE);
More information about the llvm-commits
mailing list