[lld] r301475 - Factor out code to parse -build-id. NFC.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 26 14:23:11 PDT 2017
Author: ruiu
Date: Wed Apr 26 16:23:11 2017
New Revision: 301475
URL: http://llvm.org/viewvc/llvm-project?rev=301475&view=rev
Log:
Factor out code to parse -build-id. NFC.
Modified:
lld/trunk/ELF/Driver.cpp
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=301475&r1=301474&r2=301475&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Apr 26 16:23:11 2017
@@ -550,6 +550,33 @@ static std::pair<bool, bool> getHashStyl
return {true, true};
}
+// Parse --build-id or --build-id=<style>. We handle "tree" as a
+// synonym for "sha1" because all our hash functions including
+// -build-id=sha1 are actually tree hashes for performance reasons.
+static std::pair<BuildIdKind, std::vector<uint8_t>>
+getBuildId(opt::InputArgList &Args) {
+ if (Args.hasArg(OPT_build_id))
+ return {BuildIdKind::Fast, {}};
+
+ auto *Arg = Args.getLastArg(OPT_build_id_eq);
+ if (!Arg)
+ return {BuildIdKind::None, {}};
+
+ StringRef S = Arg->getValue();
+ if (S == "md5")
+ return {BuildIdKind::Md5, {}};
+ if (S == "sha1" || S == "tree")
+ return {BuildIdKind::Sha1, {}};
+ if (S == "uuid")
+ return {BuildIdKind::Uuid, {}};
+ if (S.startswith("0x"))
+ return {BuildIdKind::Hexstring, parseHex(S.substr(2))};
+
+ if (S != "none")
+ error("unknown --build-id style: " + S);
+ return {BuildIdKind::None, {}};
+}
+
static std::vector<StringRef> getLines(MemoryBufferRef MB) {
SmallVector<StringRef, 0> Arr;
MB.getBuffer().split(Arr, '\n');
@@ -679,29 +706,7 @@ void LinkerDriver::readConfigs(opt::Inpu
Config->ZRelro = false;
std::tie(Config->SysvHash, Config->GnuHash) = getHashStyle(Args);
-
- // Parse --build-id or --build-id=<style>. We handle "tree" as a
- // synonym for "sha1" because all of our hash functions including
- // -build-id=sha1 are tree hashes for performance reasons.
- if (Args.hasArg(OPT_build_id))
- Config->BuildId = BuildIdKind::Fast;
- if (auto *Arg = Args.getLastArg(OPT_build_id_eq)) {
- StringRef S = Arg->getValue();
- if (S == "md5") {
- Config->BuildId = BuildIdKind::Md5;
- } else if (S == "sha1" || S == "tree") {
- Config->BuildId = BuildIdKind::Sha1;
- } else if (S == "uuid") {
- Config->BuildId = BuildIdKind::Uuid;
- } else if (S == "none") {
- Config->BuildId = BuildIdKind::None;
- } else if (S.startswith("0x")) {
- Config->BuildId = BuildIdKind::Hexstring;
- Config->BuildIdVector = parseHex(S.substr(2));
- } else {
- error("unknown --build-id style: " + S);
- }
- }
+ std::tie(Config->BuildId, Config->BuildIdVector) = getBuildId(Args);
if (!Config->Shared && !Config->AuxiliaryList.empty())
error("-f may not be used without -shared");
More information about the llvm-commits
mailing list