From 45192b3746db6a2066f78dfe47e2c30f7785266d Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Mon, 9 Jul 2018 20:22:28 +0000 Subject: [PATCH] Factor out code to parse -pack-dyn-relocs. NFC. llvm-svn: 336599 --- lld/ELF/Config.h | 4 ++-- lld/ELF/Driver.cpp | 29 ++++++++++++++++------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index a346f32a28d3..1f374862713c 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -113,7 +113,7 @@ struct Configuration { uint64_t> CallGraphProfile; bool AllowMultipleDefinition; - bool AndroidPackDynRelocs = false; + bool AndroidPackDynRelocs; bool ARMHasBlx = false; bool ARMHasMovtMovw = false; bool ARMJ1J2BranchEncoding = false; @@ -153,7 +153,7 @@ struct Configuration { bool PrintGcSections; bool PrintIcfSections; bool Relocatable; - bool RelrPackDynRelocs = false; + bool RelrPackDynRelocs; bool SaveTemps; bool SingleRoRx; bool Shared; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index b8ee026a6ee1..386c63a31341 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -607,6 +607,20 @@ getBuildId(opt::InputArgList &Args) { return {BuildIdKind::None, {}}; } +static std::pair getPackDynRelocs(opt::InputArgList &Args) { + StringRef S = Args.getLastArgValue(OPT_pack_dyn_relocs, "none"); + if (S == "android") + return {true, false}; + if (S == "relr") + return {false, true}; + if (S == "android+relr") + return {true, true}; + + if (S != "none") + error("unknown -pack-dyn-relocs format: " + S); + return {false, false}; +} + static void readCallGraph(MemoryBufferRef MB) { // Build a map from symbol name to section DenseMap SymbolNameToSymbol; @@ -873,19 +887,8 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) { std::tie(Config->BuildId, Config->BuildIdVector) = getBuildId(Args); - if (auto *Arg = Args.getLastArg(OPT_pack_dyn_relocs)) { - StringRef S = Arg->getValue(); - if (S == "android") { - Config->AndroidPackDynRelocs = true; - } else if (S == "relr") { - Config->RelrPackDynRelocs = true; - } else if (S == "android+relr") { - Config->AndroidPackDynRelocs = true; - Config->RelrPackDynRelocs = true; - } else if (S != "none") { - error("unknown -pack-dyn-relocs format: " + S); - } - } + std::tie(Config->AndroidPackDynRelocs, Config->RelrPackDynRelocs) = + getPackDynRelocs(Args); if (auto *Arg = Args.getLastArg(OPT_symbol_ordering_file)) if (Optional Buffer = readFile(Arg->getValue()))