diff options
Diffstat (limited to 'lld')
-rw-r--r-- | lld/ELF/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lld/ELF/Driver.cpp | 3 | ||||
-rw-r--r-- | lld/ELF/DriverUtils.cpp | 16 | ||||
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 25 | ||||
-rw-r--r-- | lld/ELF/LinkerScript.h | 2 | ||||
-rw-r--r-- | lld/ELF/ScriptParser.cpp | 15 | ||||
-rw-r--r-- | lld/ELF/ScriptParser.h | 2 | ||||
-rw-r--r-- | lld/ELF/Strings.cpp | 57 | ||||
-rw-r--r-- | lld/ELF/Strings.h | 23 | ||||
-rw-r--r-- | lld/ELF/SymbolTable.cpp | 1 |
10 files changed, 85 insertions, 60 deletions
diff --git a/lld/ELF/CMakeLists.txt b/lld/ELF/CMakeLists.txt index 8f1f60322a4..1875a1ebbcb 100644 --- a/lld/ELF/CMakeLists.txt +++ b/lld/ELF/CMakeLists.txt @@ -16,6 +16,7 @@ add_lld_library(lldELF OutputSections.cpp Relocations.cpp ScriptParser.cpp + Strings.cpp SymbolListFile.cpp SymbolTable.cpp Symbols.cpp diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 68f89b65dfe..e614db02673 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -14,6 +14,7 @@ #include "InputFiles.h" #include "InputSection.h" #include "LinkerScript.h" +#include "Strings.h" #include "SymbolListFile.h" #include "SymbolTable.h" #include "Target.h" @@ -402,7 +403,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) { Config->BuildId = BuildIdKind::None; } else if (S.startswith("0x")) { Config->BuildId = BuildIdKind::Hexstring; - Config->BuildIdVector = parseHexstring(S.substr(2)); + Config->BuildIdVector = parseHex(S.substr(2)); } else { error("unknown --build-id style: " + S); } diff --git a/lld/ELF/DriverUtils.cpp b/lld/ELF/DriverUtils.cpp index c32429e900f..ed25ae8cce7 100644 --- a/lld/ELF/DriverUtils.cpp +++ b/lld/ELF/DriverUtils.cpp @@ -88,22 +88,6 @@ std::string elf::getVersionString() { return "LLD " + Version + " " + Repo + "\n"; } -// Converts a hex string (e.g. "0x123456") to a vector. -std::vector<uint8_t> elf::parseHexstring(StringRef S) { - if (S.find_first_not_of("0123456789abcdefABCDEF") != StringRef::npos || - S.size() % 2) { - error("malformed hexstring: " + S); - return {}; - } - std::vector<uint8_t> V; - for (; !S.empty(); S = S.substr(2)) { - int I; - S.substr(0, 2).getAsInteger(16, I); - V.push_back(I); - } - return V; -} - // Makes a given pathname an absolute path first, and then remove // beginning /. For example, "../foo.o" is converted to "home/john/foo.o", // assuming that the current directory is "/home/john/bar". diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index c8aaffb659b..0bc7dd6d7f9 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -19,6 +19,7 @@ #include "InputSection.h" #include "OutputSections.h" #include "ScriptParser.h" +#include "Strings.h" #include "SymbolTable.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/ELF.h" @@ -286,30 +287,6 @@ int LinkerScript<ELFT>::compareSections(StringRef A, StringRef B) { return I < J ? -1 : 1; } -// Returns true if S matches T. S can contain glob meta-characters. -// The asterisk ('*') matches zero or more characters, and the question -// mark ('?') matches one character. -bool elf::globMatch(StringRef S, StringRef T) { - for (;;) { - if (S.empty()) - return T.empty(); - if (S[0] == '*') { - S = S.substr(1); - if (S.empty()) - // Fast path. If a pattern is '*', it matches anything. - return true; - for (size_t I = 0, E = T.size(); I < E; ++I) - if (globMatch(S, T.substr(I))) - return true; - return false; - } - if (T.empty() || (S[0] != T[0] && S[0] != '?')) - return false; - S = S.substr(1); - T = T.substr(1); - } -} - class elf::ScriptParser : public ScriptParserBase { typedef void (ScriptParser::*Handler)(); diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index 0d2285d3db2..95f9f135903 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -19,8 +19,6 @@ namespace lld { namespace elf { -bool globMatch(StringRef S, StringRef T); - // Parses a linker script. Calling this function updates // Config and ScriptConfig. void readLinkerScript(MemoryBufferRef MB); diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp index cb8de972090..559ec1be0e3 100644 --- a/lld/ELF/ScriptParser.cpp +++ b/lld/ELF/ScriptParser.cpp @@ -161,18 +161,3 @@ size_t ScriptParserBase::getPos() { const char *Tok = Tokens[Pos - 1].data(); return StringRef(Begin, Tok - Begin).count('\n') + 1; } - -std::vector<uint8_t> ScriptParserBase::parseHex(StringRef S) { - std::vector<uint8_t> Hex; - while (!S.empty()) { - StringRef B = S.substr(0, 2); - S = S.substr(2); - uint8_t H; - if (B.getAsInteger(16, H)) { - setError("not a hexadecimal value: " + B); - return {}; - } - Hex.push_back(H); - } - return Hex; -} diff --git a/lld/ELF/ScriptParser.h b/lld/ELF/ScriptParser.h index 4014cf08980..20735f78da8 100644 --- a/lld/ELF/ScriptParser.h +++ b/lld/ELF/ScriptParser.h @@ -37,8 +37,6 @@ protected: size_t getPos(); void printErrorPos(); - std::vector<uint8_t> parseHex(StringRef S); - StringRef Input; std::vector<StringRef> Tokens; size_t Pos = 0; diff --git a/lld/ELF/Strings.cpp b/lld/ELF/Strings.cpp new file mode 100644 index 00000000000..a7aecf09035 --- /dev/null +++ b/lld/ELF/Strings.cpp @@ -0,0 +1,57 @@ +//===- Strings.cpp -------------------------------------------------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "Strings.h" +#include "Error.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Twine.h" + +using namespace llvm; +using namespace lld; +using namespace lld::elf; + +// Returns true if S matches T. S can contain glob meta-characters. +// The asterisk ('*') matches zero or more characters, and the question +// mark ('?') matches one character. +bool elf::globMatch(StringRef S, StringRef T) { + for (;;) { + if (S.empty()) + return T.empty(); + if (S[0] == '*') { + S = S.substr(1); + if (S.empty()) + // Fast path. If a pattern is '*', it matches anything. + return true; + for (size_t I = 0, E = T.size(); I < E; ++I) + if (globMatch(S, T.substr(I))) + return true; + return false; + } + if (T.empty() || (S[0] != T[0] && S[0] != '?')) + return false; + S = S.substr(1); + T = T.substr(1); + } +} + +// Converts a hex string (e.g. "deadbeef") to a vector. +std::vector<uint8_t> elf::parseHex(StringRef S) { + std::vector<uint8_t> Hex; + while (!S.empty()) { + StringRef B = S.substr(0, 2); + S = S.substr(2); + uint8_t H; + if (B.getAsInteger(16, H)) { + error("not a hexadecimal value: " + B); + return {}; + } + Hex.push_back(H); + } + return Hex; +} diff --git a/lld/ELF/Strings.h b/lld/ELF/Strings.h new file mode 100644 index 00000000000..1930a0aab10 --- /dev/null +++ b/lld/ELF/Strings.h @@ -0,0 +1,23 @@ +//===- Strings.h ------------------------------------------------*- C++ -*-===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLD_COFF_STRINGS_H +#define LLD_COFF_STRINGS_H + +#include "lld/Core/LLVM.h" +#include <vector> + +namespace lld { +namespace elf { +bool globMatch(StringRef S, StringRef T); +std::vector<uint8_t> parseHex(StringRef S); +} +} + +#endif diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index f4e61771c44..08755b4ddb1 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -18,6 +18,7 @@ #include "Config.h" #include "Error.h" #include "LinkerScript.h" +#include "Strings.h" #include "Symbols.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Support/StringSaver.h" |