[llvm] r244160 - [dsymutil] Add support for the -arch option.

Frederic Riss friss at apple.com
Wed Aug 5 15:33:28 PDT 2015


Author: friss
Date: Wed Aug  5 17:33:28 2015
New Revision: 244160

URL: http://llvm.org/viewvc/llvm-project?rev=244160&view=rev
Log:
[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.

Added:
    llvm/trunk/test/tools/dsymutil/Inputs/fat-test.arm.dylib   (with props)
    llvm/trunk/test/tools/dsymutil/Inputs/fat-test.arm.o
    llvm/trunk/test/tools/dsymutil/arch-option.test
Modified:
    llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp
    llvm/trunk/tools/dsymutil/dsymutil.cpp
    llvm/trunk/tools/dsymutil/dsymutil.h

Added: llvm/trunk/test/tools/dsymutil/Inputs/fat-test.arm.dylib
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/fat-test.arm.dylib?rev=244160&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/dsymutil/Inputs/fat-test.arm.dylib (added) and llvm/trunk/test/tools/dsymutil/Inputs/fat-test.arm.dylib Wed Aug  5 17:33:28 2015 differ

Propchange: llvm/trunk/test/tools/dsymutil/Inputs/fat-test.arm.dylib
------------------------------------------------------------------------------
    svn:executable = *

Added: llvm/trunk/test/tools/dsymutil/Inputs/fat-test.arm.o
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/fat-test.arm.o?rev=244160&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/dsymutil/Inputs/fat-test.arm.o (added) and llvm/trunk/test/tools/dsymutil/Inputs/fat-test.arm.o Wed Aug  5 17:33:28 2015 differ

Added: llvm/trunk/test/tools/dsymutil/arch-option.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/arch-option.test?rev=244160&view=auto
==============================================================================
--- llvm/trunk/test/tools/dsymutil/arch-option.test (added)
+++ llvm/trunk/test/tools/dsymutil/arch-option.test Wed Aug  5 17:33:28 2015
@@ -0,0 +1,39 @@
+Processing of the -arch option happens at debug map parsing time, thus just
+looking at the dumped debug maps is enough to validate their effects.
+
+RUN: llvm-dsymutil -oso-prepend-path %p -dump-debug-map %p/Inputs/fat-test.arm.dylib | FileCheck %s -check-prefix=ARM64 -check-prefix=ARMV7S -check-prefix=ARMV7 -check-prefix=CHECK
+RUN: llvm-dsymutil -oso-prepend-path %p -dump-debug-map %p/Inputs/fat-test.arm.dylib -arch all | FileCheck %s -check-prefix=ARM64 -check-prefix=ARMV7S -check-prefix=ARMV7 -check-prefix=CHECK
+RUN: llvm-dsymutil -oso-prepend-path %p -dump-debug-map %p/Inputs/fat-test.arm.dylib -arch '*' | FileCheck %s -check-prefix=ARM64 -check-prefix=ARMV7S -check-prefix=ARMV7 -check-prefix=CHECK
+RUN: llvm-dsymutil -oso-prepend-path %p -dump-debug-map %p/Inputs/fat-test.arm.dylib -arch arm64 | FileCheck %s -check-prefix=ARM64 -check-prefix=CHECK
+RUN: llvm-dsymutil -oso-prepend-path %p -dump-debug-map %p/Inputs/fat-test.arm.dylib -arch arm | FileCheck %s -check-prefix=ARMV7S -check-prefix=ARMV7 -check-prefix=CHECK
+RUN: llvm-dsymutil -oso-prepend-path %p -dump-debug-map %p/Inputs/fat-test.arm.dylib -arch armv7 | FileCheck %s -check-prefix=ARMV7 -check-prefix=CHECK
+RUN: llvm-dsymutil -oso-prepend-path %p -dump-debug-map %p/Inputs/fat-test.arm.dylib -arch arm64 -arch armv7s | FileCheck %s -check-prefix=ARM64 -check-prefix=ARMV7S -check-prefix=CHECK
+RUN: not llvm-dsymutil -oso-prepend-path %p -dump-debug-map %p/Inputs/fat-test.arm.dylib -arch arm42 2>&1 | FileCheck %s -check-prefix=BADARCH
+RUN: not llvm-dsymutil -oso-prepend-path %p -dump-debug-map %p/Inputs/fat-test.arm.dylib -arch i386 2>&1 | FileCheck %s -check-prefix=EMPTY
+
+
+ARMV7: ---
+ARMV7-NOT: ...
+ARMV7: triple:          'thumbv7-apple-darwin'
+ARMV7-NOT: ...
+ARMV7: sym: _armv7_var
+ARMV7-NOT: ---
+
+ARMV7S: ---
+ARMV7S-NOT: ...
+ARMV7S: triple:          'thumbv7s-apple-darwin'
+ARMV7S-NOT: ...
+ARMV7S: sym: _armv7s_var
+ARMV7S-NOT: ---
+
+ARM64: ---
+ARM64-NOT: ...
+ARM64: triple:          'arm64-apple-darwin'
+ARM64-NOT: ...
+ARM64: sym: _arm64_var
+ARM64-NOT: ---
+
+CHECK: ...
+
+BADARCH: error: Unsupported cpu architecture: 'arm42'
+EMPTY: error: no architecture to link

Modified: llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp?rev=244160&r1=244159&r2=244160&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp (original)
+++ llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp Wed Aug  5 17:33:28 2015
@@ -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(cons
   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<Debu
     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::loadMainBinary
 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);

Modified: llvm/trunk/tools/dsymutil/dsymutil.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/dsymutil.cpp?rev=244160&r1=244159&r2=244160&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/dsymutil.cpp (original)
+++ llvm/trunk/tools/dsymutil/dsymutil.cpp Wed Aug  5 17:33:28 2015
@@ -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;

Modified: llvm/trunk/tools/dsymutil/dsymutil.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/dsymutil.h?rev=244160&r1=244159&r2=244160&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/dsymutil.h (original)
+++ llvm/trunk/tools/dsymutil/dsymutil.h Wed Aug  5 17:33:28 2015
@@ -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.




More information about the llvm-commits mailing list