summaryrefslogtreecommitdiffstats
path: root/llvm/tools
diff options
context:
space:
mode:
authorFrederic Riss <friss@apple.com>2015-08-05 22:33:28 +0000
committerFrederic Riss <friss@apple.com>2015-08-05 22:33:28 +0000
commitae0d4365454456203a6f284c5d0e6ed994883c86 (patch)
tree21d2818dc07aead11ba9b370815bd05ff8b71e83 /llvm/tools
parent10cac7a190ef21a75e832a834f6b7d22d13b70ad (diff)
downloadbcm5719-llvm-ae0d4365454456203a6f284c5d0e6ed994883c86.tar.gz
bcm5719-llvm-ae0d4365454456203a6f284c5d0e6ed994883c86.zip
[dsymutil] Add support for the -arch option.
This option allows to select a subset of the architectures when performing a universal binary link. The filter is done completely in the mach-o specific part of the code. llvm-svn: 244160
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/dsymutil/MachODebugMapParser.cpp34
-rw-r--r--llvm/tools/dsymutil/dsymutil.cpp25
-rw-r--r--llvm/tools/dsymutil/dsymutil.h4
3 files changed, 50 insertions, 13 deletions
diff --git a/llvm/tools/dsymutil/MachODebugMapParser.cpp b/llvm/tools/dsymutil/MachODebugMapParser.cpp
index aa034cb683c..cd427cb1d94 100644
--- a/llvm/tools/dsymutil/MachODebugMapParser.cpp
+++ b/llvm/tools/dsymutil/MachODebugMapParser.cpp
@@ -21,11 +21,11 @@ using namespace llvm::object;
class MachODebugMapParser {
public:
- MachODebugMapParser(StringRef BinaryPath, StringRef PathPrefix = "",
- bool Verbose = false)
- : BinaryPath(BinaryPath), PathPrefix(PathPrefix),
- MainBinaryHolder(Verbose), CurrentObjectHolder(Verbose),
- CurrentDebugMapObject(nullptr) {}
+ MachODebugMapParser(StringRef BinaryPath, ArrayRef<std::string> Archs,
+ StringRef PathPrefix = "", bool Verbose = false)
+ : BinaryPath(BinaryPath), Archs(Archs.begin(), Archs.end()),
+ PathPrefix(PathPrefix), MainBinaryHolder(Verbose),
+ CurrentObjectHolder(Verbose), CurrentDebugMapObject(nullptr) {}
/// \brief Parses and returns the DebugMaps of the input binary.
/// The binary contains multiple maps in case it is a universal
@@ -36,6 +36,7 @@ public:
private:
std::string BinaryPath;
+ SmallVector<StringRef, 1> Archs;
std::string PathPrefix;
/// Owns the MemoryBuffer for the main binary.
@@ -133,6 +134,19 @@ MachODebugMapParser::parseOneBinary(const MachOObjectFile &MainBinary,
return std::move(Result);
}
+static bool shouldLinkArch(SmallVectorImpl<StringRef> &Archs, StringRef Arch) {
+ if (Archs.empty() ||
+ std::find(Archs.begin(), Archs.end(), "all") != Archs.end() ||
+ std::find(Archs.begin(), Archs.end(), "*") != Archs.end())
+ return true;
+
+ if (Arch.startswith("arm") && Arch != "arm64" &&
+ std::find(Archs.begin(), Archs.end(), "arm") != Archs.end())
+ return true;
+
+ return std::find(Archs.begin(), Archs.end(), Arch) != Archs.end();
+}
+
/// This main parsing routine tries to open the main binary and if
/// successful iterates over the STAB entries. The real parsing is
/// done in handleStabSymbolTableEntry.
@@ -143,8 +157,10 @@ ErrorOr<std::vector<std::unique_ptr<DebugMap>>> MachODebugMapParser::parse() {
return Error;
std::vector<std::unique_ptr<DebugMap>> Results;
+ Triple T;
for (const auto *Binary : *MainBinOrError)
- Results.push_back(parseOneBinary(*Binary, BinaryPath));
+ if (shouldLinkArch(Archs, Binary->getArch(nullptr, &T).getArchName()))
+ Results.push_back(parseOneBinary(*Binary, BinaryPath));
return std::move(Results);
}
@@ -266,10 +282,10 @@ void MachODebugMapParser::loadMainBinarySymbols(
namespace llvm {
namespace dsymutil {
llvm::ErrorOr<std::vector<std::unique_ptr<DebugMap>>>
-parseDebugMap(StringRef InputFile, StringRef PrependPath, bool Verbose,
- bool InputIsYAML) {
+parseDebugMap(StringRef InputFile, ArrayRef<std::string> Archs,
+ StringRef PrependPath, bool Verbose, bool InputIsYAML) {
if (!InputIsYAML) {
- MachODebugMapParser Parser(InputFile, PrependPath, Verbose);
+ MachODebugMapParser Parser(InputFile, Archs, PrependPath, Verbose);
return Parser.parse();
} else {
return DebugMap::parseYAMLDebugMap(InputFile, PrependPath, Verbose);
diff --git a/llvm/tools/dsymutil/dsymutil.cpp b/llvm/tools/dsymutil/dsymutil.cpp
index 48eb9a14f0a..581da4ebfa0 100644
--- a/llvm/tools/dsymutil/dsymutil.cpp
+++ b/llvm/tools/dsymutil/dsymutil.cpp
@@ -15,6 +15,7 @@
#include "DebugMap.h"
#include "MachOUtils.h"
#include "dsymutil.h"
+#include "llvm/Object/MachO.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Options.h"
@@ -54,6 +55,14 @@ static opt<bool>
desc("Do the link in memory, but do not emit the result file."),
init(false), cat(DsymCategory));
+static list<std::string> ArchFlags(
+ "arch",
+ desc("Link DWARF debug information only for specified CPU architecture\n"
+ "types. This option can be specified multiple times, once for each\n"
+ "desired architecture. All cpu architectures will be linked by\n"
+ "default."),
+ ZeroOrMore, cat(DsymCategory));
+
static opt<bool>
NoODR("no-odr",
desc("Do not use ODR (One Definition Rule) for type uniquing."),
@@ -138,9 +147,16 @@ int main(int argc, char **argv) {
return 1;
}
+ for (const auto &Arch : ArchFlags)
+ if (Arch != "*" && Arch != "all" &&
+ !llvm::object::MachOObjectFile::isValidArch(Arch)) {
+ llvm::errs() << "error: Unsupported cpu architecture: '" << Arch << "'\n";
+ exitDsymutil(1);
+ }
+
for (auto &InputFile : InputFiles) {
- auto DebugMapPtrsOrErr =
- parseDebugMap(InputFile, OsoPrependPath, Verbose, InputIsYAMLDebugMap);
+ auto DebugMapPtrsOrErr = parseDebugMap(InputFile, ArchFlags, OsoPrependPath,
+ Verbose, InputIsYAMLDebugMap);
if (auto EC = DebugMapPtrsOrErr.getError()) {
llvm::errs() << "error: cannot parse the debug map for \"" << InputFile
@@ -148,6 +164,11 @@ int main(int argc, char **argv) {
exitDsymutil(1);
}
+ if (DebugMapPtrsOrErr->empty()) {
+ llvm::errs() << "error: no architecture to link\n";
+ exitDsymutil(1);
+ }
+
// If there is more than one link to execute, we need to generate
// temporary files.
bool NeedsTempFiles = !DumpDebugMap && (*DebugMapPtrsOrErr).size() != 1;
diff --git a/llvm/tools/dsymutil/dsymutil.h b/llvm/tools/dsymutil/dsymutil.h
index 82f0deeb2e0..239439a6a86 100644
--- a/llvm/tools/dsymutil/dsymutil.h
+++ b/llvm/tools/dsymutil/dsymutil.h
@@ -36,8 +36,8 @@ struct LinkOptions {
/// The file has to be a MachO object file. Multiple debug maps can be
/// returned when the file is universal (aka fat) binary.
llvm::ErrorOr<std::vector<std::unique_ptr<DebugMap>>>
-parseDebugMap(StringRef InputFile, StringRef PrependPath, bool Verbose,
- bool InputIsYAML);
+parseDebugMap(StringRef InputFile, ArrayRef<std::string> Archs,
+ StringRef PrependPath, bool Verbose, bool InputIsYAML);
/// \brief Link the Dwarf debuginfo as directed by the passed DebugMap
/// \p DM into a DwarfFile named \p OutputFilename.
OpenPOWER on IntegriCloud