[dsymutil] Make the triple detection more strict.
authorFrederic Riss <friss@apple.com>
Fri, 24 Jul 2015 06:41:04 +0000 (06:41 +0000)
committerFrederic Riss <friss@apple.com>
Fri, 24 Jul 2015 06:41:04 +0000 (06:41 +0000)
MachOObjectFile offers a method for detecting the correct triple, use
it instead of the previous approximation. This doesn't matter right
now, but it will become important for mach-o universal (fat) binaries.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243095 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/dsymutil/X86/frame-1.test
test/tools/dsymutil/X86/frame-2.test
test/tools/dsymutil/X86/odr-1.test
test/tools/dsymutil/archive-timestamp.test
test/tools/dsymutil/debug-map-parsing.test
test/tools/dsymutil/yaml-object-address-rewrite.test
tools/dsymutil/BinaryHolder.cpp
tools/dsymutil/BinaryHolder.h
tools/dsymutil/MachODebugMapParser.cpp

index 7852e68a142ab62c61513fc7f2d356c9608e89b7..fed18122d008e3d9a8c2be477997a6a5e647382d 100644 (file)
@@ -9,7 +9,7 @@
 # link twice the same file using this made-up debug map:
 
 ---
-triple:          'i386-unknown-unknown-macho'
+triple:          'i386-apple-darwin'
 objects:
   - filename: frame-dw2.o
     symbols:
index 168e342a4f74323eacdc07794b929a69030b2bbe..92520290dad57035c9324b4ae0da18d8500a6d62 100644 (file)
@@ -12,7 +12,7 @@
 # appears again. This is a behavior we inherited from dsymutil-classic
 # but this should be fixed (see comment in patchFrameInfoForObject())
 ---
-triple:          'i386-unknown-unknown-macho'
+triple:          'i386-apple-darwin'
 objects:
   - filename: frame-dw2.o
     symbols:
index b650dc098bfe6fa56288176b56d22ccce822d908..607cd054b19ea951017afb041a66d1f882b80a60 100644 (file)
@@ -14,7 +14,7 @@
 # Totally made up debug map to test ODR uniquing
 
 ---
-triple:          'x86_64-unknown-unknown-macho'
+triple:          'x86_64-apple-darwin'
 objects:
   - filename: odr1.o
     symbols:
index 11add6d0b72cf46ff8db2c9879ab8838c5167e28..1daff8fcf6380ea5508e3d785cc527ca92db184e 100644 (file)
@@ -6,7 +6,7 @@
 # CHECK: warning: {{.*}}libbasic.a(basic3.macho.x86_64.o): {{[Nn]o}} such file
 
 ---
-triple:          'x86_64-unknown-unknown-macho'
+triple:          'x86_64-apple-darwin'
 objects:
   - filename:        '/Inputs/libbasic.a(basic2.macho.x86_64.o)'
     timestamp:       141869239
index 5091dfbfc24d6b42f7fab755df2e01783b08a557..d8763e3b2923038dcb3d1ec63414e49f3682be88 100644 (file)
@@ -9,7 +9,7 @@ Check that We can parse the debug map of the basic executable.
 
 CHECK-NOT: error
 CHECK: ---
-CHECK: triple: 'x86_64-unknown-unknown-macho'
+CHECK: triple: 'x86_64-apple-darwin'
 CHECK: filename:{{.*}}/Inputs/basic1.macho.x86_64.o
 CHECK-DAG: sym: _main, objAddr: 0x0000000000000000, binAddr: 0x0000000100000EA0, size: 0x00000024
 CHECK: filename{{.*}}/Inputs/basic2.macho.x86_64.o
@@ -28,7 +28,7 @@ Check that we can parse the debug-map of the basic-lto executable
 
 CHECK-LTO-NOT: error
 CHECK-LTO: ---
-CHECK-LTO: triple: 'x86_64-unknown-unknown-macho'
+CHECK-LTO: triple: 'x86_64-apple-darwin'
 CHECK-LTO: /Inputs/basic-lto.macho.x86_64.o
 CHECK-LTO-DAG:         sym: _bar, objAddr: 0x0000000000000050, binAddr: 0x0000000100000F90, size: 0x00000024
 CHECK-LTO-DAG:         sym: _baz, objAddr: 0x0000000000000658, binAddr: 0x0000000100001000, size: 0x00000000
@@ -51,7 +51,7 @@ CHECK-ARCHIVE-NEXT:   found member in current archive.
 CHECK-ARCHIVE-NEXT: trying to open {{.*}}/libbasic.a(basic3.macho.x86_64.o)'
 CHECK-ARCHIVE-NEXT:    found member in current archive.
 CHECK-ARCHIVE: ---
-CHECK-ARCHIVE: triple: 'x86_64-unknown-unknown-macho'
+CHECK-ARCHIVE: triple: 'x86_64-apple-darwin'
 CHECK-ARCHIVE: /Inputs/basic1.macho.x86_64.o
 CHECK-ARCHIVE-DAG:     sym: _main, objAddr: 0x0000000000000000, binAddr: 0x0000000100000EA0, size: 0x00000024
 CHECK-ARCHIVE: /Inputs/./libbasic.a(basic2.macho.x86_64.o)
@@ -72,7 +72,7 @@ NOT-FOUND: cannot open{{.*}}"/Inputs/basic1.macho.x86_64.o": {{[Nn]o}} such file
 NOT-FOUND: cannot open{{.*}}"/Inputs/basic2.macho.x86_64.o": {{[Nn]o}} such file
 NOT-FOUND: cannot open{{.*}}"/Inputs/basic3.macho.x86_64.o": {{[Nn]o}} such file
 NOT-FOUND: ---
-NOT-FOUND-NEXT: triple: 'x86_64-unknown-unknown-macho'
+NOT-FOUND-NEXT: triple: 'x86_64-apple-darwin'
 NOT-FOUND-NEXT: ...
 
 Check that we correctly error out on invalid executatble.
index 73697d4a6e5b8043cffb5e76fda5a4018575f915..f553745d64e8290b9e332a74a6130a68310c4322 100644 (file)
@@ -5,7 +5,7 @@
 # rewrite these addresses to the right values.
 #
 # CHECK: ---
-# CHECK-NEXT: triple:{{.*}}'x86_64-unknown-unknown-macho'
+# CHECK-NEXT: triple:{{.*}}'x86_64-apple-darwin'
 # CHECK-NEXT: objects:
 # CHECK-NEXT: filename:{{.*}}/Inputs/basic1.macho.x86_64.o
 # CHECK-NEXT: timestamp: 0
@@ -28,7 +28,7 @@
 # CHECK-NOT: { sym:
 # CHECK-NEXT: ...
 ---
-triple:          'x86_64-unknown-unknown-macho'
+triple:          'x86_64-apple-darwin'
 objects:
   - filename: /Inputs/basic1.macho.x86_64.o
     symbols:
index 1774cf21e71f593a93732cae4a859d92b2f62e7a..3f0c9b1126033f944d14dd851d3a0dbed955fc06 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #include "BinaryHolder.h"
+#include "llvm/Object/MachO.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace llvm {
 namespace dsymutil {
 
+Triple BinaryHolder::getTriple(const object::MachOObjectFile &Obj) {
+  // If a ThumbTriple is returned, use it instead of the standard
+  // one. This is because the thumb triple always allows to create a
+  // target, whereas the non-thumb one might not.
+  Triple ThumbTriple;
+  Triple T = Obj.getArch(nullptr, &ThumbTriple);
+  return ThumbTriple.getArch() ? ThumbTriple : T;
+}
+
 void BinaryHolder::changeBackingMemoryBuffer(
     std::unique_ptr<MemoryBuffer> &&Buf) {
   CurrentArchive.reset();
index c072acac2b2eee2ca173252a8d68001986889e4c..e4558580f9a7dfb54dd888f2b760bc5aa4d611fc 100644 (file)
@@ -14,6 +14,7 @@
 #ifndef LLVM_TOOLS_DSYMUTIL_BINARYHOLDER_H
 #define LLVM_TOOLS_DSYMUTIL_BINARYHOLDER_H
 
+#include "llvm/ADT/Triple.h"
 #include "llvm/Object/Archive.h"
 #include "llvm/Object/Error.h"
 #include "llvm/Object/ObjectFile.h"
@@ -108,6 +109,8 @@ public:
   template <typename ObjectFileType> const ObjectFileType &GetAs() {
     return cast<ObjectFileType>(*CurrentObjectFile);
   }
+
+  static Triple getTriple(const object::MachOObjectFile &Obj);
 };
 }
 }
index 8f3ca6ca0045a5126ebab9a4717b6b6359c8c57e..cda43494b9b4ece27718be8e87de24c84d67b3a5 100644 (file)
@@ -103,13 +103,6 @@ void MachODebugMapParser::switchToNewDebugMapObject(StringRef Filename,
   CurrentDebugMapObject = &Result->addDebugMapObject(Path, Timestamp);
 }
 
-static Triple getTriple(const object::MachOObjectFile &Obj) {
-  Triple TheTriple("unknown-unknown-unknown");
-  TheTriple.setArch(Triple::ArchType(Obj.getArch()));
-  TheTriple.setObjectFormat(Triple::MachO);
-  return TheTriple;
-}
-
 /// 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.
@@ -120,7 +113,7 @@ ErrorOr<std::unique_ptr<DebugMap>> MachODebugMapParser::parse() {
 
   const MachOObjectFile &MainBinary = *MainBinOrError;
   loadMainBinarySymbols();
-  Result = make_unique<DebugMap>(getTriple(MainBinary));
+  Result = make_unique<DebugMap>(BinaryHolder::getTriple(MainBinary));
   MainBinaryStrings = MainBinary.getStringTableData();
   for (const SymbolRef &Symbol : MainBinary.symbols()) {
     const DataRefImpl &DRI = Symbol.getRawDataRefImpl();