llvm.org GIT mirror llvm / 1b709aa
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244160 91177308-0d34-0410-b5e6-96231b3b80d8 Frederic Riss 5 years ago
6 changed file(s) with 89 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
0 Processing of the -arch option happens at debug map parsing time, thus just
1 looking at the dumped debug maps is enough to validate their effects.
2
3 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
4 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
5 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
6 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
7 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
8 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
9 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
10 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
11 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
12
13
14 ARMV7: ---
15 ARMV7-NOT: ...
16 ARMV7: triple: 'thumbv7-apple-darwin'
17 ARMV7-NOT: ...
18 ARMV7: sym: _armv7_var
19 ARMV7-NOT: ---
20
21 ARMV7S: ---
22 ARMV7S-NOT: ...
23 ARMV7S: triple: 'thumbv7s-apple-darwin'
24 ARMV7S-NOT: ...
25 ARMV7S: sym: _armv7s_var
26 ARMV7S-NOT: ---
27
28 ARM64: ---
29 ARM64-NOT: ...
30 ARM64: triple: 'arm64-apple-darwin'
31 ARM64-NOT: ...
32 ARM64: sym: _arm64_var
33 ARM64-NOT: ---
34
35 CHECK: ...
36
37 BADARCH: error: Unsupported cpu architecture: 'arm42'
38 EMPTY: error: no architecture to link
2020
2121 class MachODebugMapParser {
2222 public:
23 MachODebugMapParser(StringRef BinaryPath, StringRef PathPrefix = "",
24 bool Verbose = false)
25 : BinaryPath(BinaryPath), PathPrefix(PathPrefix),
26 MainBinaryHolder(Verbose), CurrentObjectHolder(Verbose),
27 CurrentDebugMapObject(nullptr) {}
23 MachODebugMapParser(StringRef BinaryPath, ArrayRef Archs,
24 StringRef PathPrefix = "", bool Verbose = false)
25 : BinaryPath(BinaryPath), Archs(Archs.begin(), Archs.end()),
26 PathPrefix(PathPrefix), MainBinaryHolder(Verbose),
27 CurrentObjectHolder(Verbose), CurrentDebugMapObject(nullptr) {}
2828
2929 /// \brief Parses and returns the DebugMaps of the input binary.
3030 /// The binary contains multiple maps in case it is a universal
3535
3636 private:
3737 std::string BinaryPath;
38 SmallVector Archs;
3839 std::string PathPrefix;
3940
4041 /// Owns the MemoryBuffer for the main binary.
132133 return std::move(Result);
133134 }
134135
136 static bool shouldLinkArch(SmallVectorImpl &Archs, StringRef Arch) {
137 if (Archs.empty() ||
138 std::find(Archs.begin(), Archs.end(), "all") != Archs.end() ||
139 std::find(Archs.begin(), Archs.end(), "*") != Archs.end())
140 return true;
141
142 if (Arch.startswith("arm") && Arch != "arm64" &&
143 std::find(Archs.begin(), Archs.end(), "arm") != Archs.end())
144 return true;
145
146 return std::find(Archs.begin(), Archs.end(), Arch) != Archs.end();
147 }
148
135149 /// This main parsing routine tries to open the main binary and if
136150 /// successful iterates over the STAB entries. The real parsing is
137151 /// done in handleStabSymbolTableEntry.
142156 return Error;
143157
144158 std::vector> Results;
159 Triple T;
145160 for (const auto *Binary : *MainBinOrError)
146 Results.push_back(parseOneBinary(*Binary, BinaryPath));
161 if (shouldLinkArch(Archs, Binary->getArch(nullptr, &T).getArchName()))
162 Results.push_back(parseOneBinary(*Binary, BinaryPath));
147163
148164 return std::move(Results);
149165 }
265281 namespace llvm {
266282 namespace dsymutil {
267283 llvm::ErrorOr>>
268 parseDebugMap(StringRef InputFile, StringRef PrependPath, bool Verbose,
269 bool InputIsYAML) {
284 parseDebugMap(StringRef InputFile, ArrayRef Archs,
285 StringRef PrependPath, bool Verbose, bool InputIsYAML) {
270286 if (!InputIsYAML) {
271 MachODebugMapParser Parser(InputFile, PrependPath, Verbose);
287 MachODebugMapParser Parser(InputFile, Archs, PrependPath, Verbose);
272288 return Parser.parse();
273289 } else {
274290 return DebugMap::parseYAMLDebugMap(InputFile, PrependPath, Verbose);
1414 #include "DebugMap.h"
1515 #include "MachOUtils.h"
1616 #include "dsymutil.h"
17 #include "llvm/Object/MachO.h"
1718 #include "llvm/Support/FileUtilities.h"
1819 #include "llvm/Support/ManagedStatic.h"
1920 #include "llvm/Support/Options.h"
5253 NoOutput("no-output",
5354 desc("Do the link in memory, but do not emit the result file."),
5455 init(false), cat(DsymCategory));
56
57 static list ArchFlags(
58 "arch",
59 desc("Link DWARF debug information only for specified CPU architecture\n"
60 "types. This option can be specified multiple times, once for each\n"
61 "desired architecture. All cpu architectures will be linked by\n"
62 "default."),
63 ZeroOrMore, cat(DsymCategory));
5564
5665 static opt
5766 NoODR("no-odr",
137146 return 1;
138147 }
139148
149 for (const auto &Arch : ArchFlags)
150 if (Arch != "*" && Arch != "all" &&
151 !llvm::object::MachOObjectFile::isValidArch(Arch)) {
152 llvm::errs() << "error: Unsupported cpu architecture: '" << Arch << "'\n";
153 exitDsymutil(1);
154 }
155
140156 for (auto &InputFile : InputFiles) {
141 auto DebugMapPtrsOrErr =
142 parseDebugMap(InputFile, OsoPrependPath, Verbose, InputIsYAMLDebugMap);
157 auto DebugMapPtrsOrErr = parseDebugMap(InputFile, ArchFlags, OsoPrependPath,
158 Verbose, InputIsYAMLDebugMap);
143159
144160 if (auto EC = DebugMapPtrsOrErr.getError()) {
145161 llvm::errs() << "error: cannot parse the debug map for \"" << InputFile
146162 << "\": " << EC.message() << '\n';
163 exitDsymutil(1);
164 }
165
166 if (DebugMapPtrsOrErr->empty()) {
167 llvm::errs() << "error: no architecture to link\n";
147168 exitDsymutil(1);
148169 }
149170
3535 /// The file has to be a MachO object file. Multiple debug maps can be
3636 /// returned when the file is universal (aka fat) binary.
3737 llvm::ErrorOr>>
38 parseDebugMap(StringRef InputFile, StringRef PrependPath, bool Verbose,
39 bool InputIsYAML);
38 parseDebugMap(StringRef InputFile, ArrayRef Archs,
39 StringRef PrependPath, bool Verbose, bool InputIsYAML);
4040
4141 /// \brief Link the Dwarf debuginfo as directed by the passed DebugMap
4242 /// \p DM into a DwarfFile named \p OutputFilename.