1 //===- llvm-ifs.cpp -------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===-----------------------------------------------------------------------===/
9 #include "ErrorCollector.h"
10 #include "llvm/ADT/StringRef.h"
11 #include "llvm/ADT/StringSwitch.h"
12 #include "llvm/BinaryFormat/ELF.h"
13 #include "llvm/InterfaceStub/ELFObjHandler.h"
14 #include "llvm/InterfaceStub/IFSHandler.h"
15 #include "llvm/InterfaceStub/IFSStub.h"
16 #include "llvm/ObjectYAML/yaml2obj.h"
17 #include "llvm/Option/Arg.h"
18 #include "llvm/Option/ArgList.h"
19 #include "llvm/Option/Option.h"
20 #include "llvm/Support/CommandLine.h"
21 #include "llvm/Support/Debug.h"
22 #include "llvm/Support/Errc.h"
23 #include "llvm/Support/Error.h"
24 #include "llvm/Support/FileOutputBuffer.h"
25 #include "llvm/Support/LLVMDriver.h"
26 #include "llvm/Support/MemoryBuffer.h"
27 #include "llvm/Support/Path.h"
28 #include "llvm/Support/VersionTuple.h"
29 #include "llvm/Support/WithColor.h"
30 #include "llvm/Support/YAMLTraits.h"
31 #include "llvm/Support/raw_ostream.h"
32 #include "llvm/TargetParser/Triple.h"
33 #include "llvm/TextAPI/InterfaceFile.h"
34 #include "llvm/TextAPI/TextAPIReader.h"
35 #include "llvm/TextAPI/TextAPIWriter.h"
42 using namespace llvm::yaml
;
43 using namespace llvm::MachO
;
44 using namespace llvm::ifs
;
46 #define DEBUG_TYPE "llvm-ifs"
49 const VersionTuple
IfsVersionCurrent(3, 0);
51 enum class FileFormat
{ IFS
, ELF
, TBD
};
52 } // end anonymous namespace
54 using namespace llvm::opt
;
56 OPT_INVALID
= 0, // This is not an option ID.
57 #define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
62 #define PREFIX(NAME, VALUE) \
63 static constexpr StringLiteral NAME##_init[] = VALUE; \
64 static constexpr ArrayRef<StringLiteral> NAME(NAME##_init, \
65 std::size(NAME##_init) - 1);
69 static constexpr opt::OptTable::Info InfoTable
[] = {
70 #define OPTION(...) LLVM_CONSTRUCT_OPT_INFO(__VA_ARGS__),
75 class IFSOptTable
: public opt::GenericOptTable
{
77 IFSOptTable() : opt::GenericOptTable(InfoTable
) {
78 setGroupedShortOptions(true);
83 std::vector
<std::string
> InputFilePaths
;
85 std::optional
<FileFormat
> InputFormat
;
86 std::optional
<FileFormat
> OutputFormat
;
88 std::optional
<std::string
> HintIfsTarget
;
89 std::optional
<std::string
> OptTargetTriple
;
90 std::optional
<IFSArch
> OverrideArch
;
91 std::optional
<IFSBitWidthType
> OverrideBitWidth
;
92 std::optional
<IFSEndiannessType
> OverrideEndianness
;
94 bool StripIfsArch
= false;
95 bool StripIfsBitwidth
= false;
96 bool StripIfsEndianness
= false;
97 bool StripIfsTarget
= false;
98 bool StripNeeded
= false;
99 bool StripSize
= false;
100 bool StripUndefined
= false;
102 std::vector
<std::string
> Exclude
;
104 std::optional
<std::string
> SoName
;
106 std::optional
<std::string
> Output
;
107 std::optional
<std::string
> OutputElf
;
108 std::optional
<std::string
> OutputIfs
;
109 std::optional
<std::string
> OutputTbd
;
111 bool WriteIfChanged
= false;
114 static std::string
getTypeName(IFSSymbolType Type
) {
116 case IFSSymbolType::NoType
:
118 case IFSSymbolType::Func
:
120 case IFSSymbolType::Object
:
122 case IFSSymbolType::TLS
:
124 case IFSSymbolType::Unknown
:
127 llvm_unreachable("Unexpected ifs symbol type.");
130 static Expected
<std::unique_ptr
<IFSStub
>>
131 readInputFile(std::optional
<FileFormat
> &InputFormat
, StringRef FilePath
) {
133 ErrorOr
<std::unique_ptr
<MemoryBuffer
>> BufOrError
=
134 MemoryBuffer::getFileOrSTDIN(FilePath
, /*IsText=*/true);
136 return createStringError(BufOrError
.getError(), "Could not open `%s`",
139 std::unique_ptr
<MemoryBuffer
> FileReadBuffer
= std::move(*BufOrError
);
140 ErrorCollector
EC(/*UseFatalErrors=*/false);
142 // First try to read as a binary (fails fast if not binary).
143 if (!InputFormat
|| *InputFormat
== FileFormat::ELF
) {
144 Expected
<std::unique_ptr
<IFSStub
>> StubFromELF
=
145 readELFFile(FileReadBuffer
->getMemBufferRef());
147 InputFormat
= FileFormat::ELF
;
148 (*StubFromELF
)->IfsVersion
= IfsVersionCurrent
;
149 return std::move(*StubFromELF
);
151 EC
.addError(StubFromELF
.takeError(), "BinaryRead");
154 // Fall back to reading as a ifs.
155 if (!InputFormat
|| *InputFormat
== FileFormat::IFS
) {
156 Expected
<std::unique_ptr
<IFSStub
>> StubFromIFS
=
157 readIFSFromBuffer(FileReadBuffer
->getBuffer());
159 InputFormat
= FileFormat::IFS
;
160 if ((*StubFromIFS
)->IfsVersion
> IfsVersionCurrent
)
162 createStringError(errc::not_supported
,
164 (*StubFromIFS
)->IfsVersion
.getAsString() +
168 return std::move(*StubFromIFS
);
170 EC
.addError(StubFromIFS
.takeError(), "YamlParse");
174 // If both readers fail, build a new error that includes all information.
175 EC
.addError(createStringError(errc::not_supported
,
176 "No file readers succeeded reading `%s` "
177 "(unsupported/malformed file?)",
180 EC
.escalateToFatal();
181 return EC
.makeError();
184 static int writeTbdStub(const Triple
&T
, const std::vector
<IFSSymbol
> &Symbols
,
185 const StringRef Format
, raw_ostream
&Out
) {
187 auto PlatformTypeOrError
=
188 [](const llvm::Triple
&T
) -> llvm::Expected
<llvm::MachO::PlatformType
> {
190 return llvm::MachO::PLATFORM_MACOS
;
192 return llvm::MachO::PLATFORM_TVOS
;
194 return llvm::MachO::PLATFORM_WATCHOS
;
195 // Note: put isiOS last because tvOS and watchOS are also iOS according
198 return llvm::MachO::PLATFORM_IOS
;
200 return createStringError(errc::not_supported
, "Invalid Platform.\n");
203 if (!PlatformTypeOrError
)
206 PlatformType Plat
= PlatformTypeOrError
.get();
207 TargetList
Targets({Target(llvm::MachO::mapToArchitecture(T
), Plat
)});
210 File
.setFileType(FileType::TBD_V3
); // Only supporting v3 for now.
211 File
.addTargets(Targets
);
213 for (const auto &Symbol
: Symbols
) {
214 auto Name
= Symbol
.Name
;
215 auto Kind
= EncodeKind::GlobalSymbol
;
216 switch (Symbol
.Type
) {
218 case IFSSymbolType::NoType
:
219 Kind
= EncodeKind::GlobalSymbol
;
221 case IFSSymbolType::Object
:
222 Kind
= EncodeKind::GlobalSymbol
;
224 case IFSSymbolType::Func
:
225 Kind
= EncodeKind::GlobalSymbol
;
229 File
.addSymbol(Kind
, Name
, Targets
, SymbolFlags::WeakDefined
);
231 File
.addSymbol(Kind
, Name
, Targets
);
234 SmallString
<4096> Buffer
;
235 raw_svector_ostream
OS(Buffer
);
236 if (Error Result
= TextAPIWriter::writeToStream(OS
, File
))
242 static void fatalError(Error Err
) {
243 WithColor::defaultErrorHandler(std::move(Err
));
247 static void fatalError(Twine T
) {
248 WithColor::error() << T
.str() << '\n';
252 /// writeIFS() writes a Text-Based ELF stub to a file using the latest version
253 /// of the YAML parser.
254 static Error
writeIFS(StringRef FilePath
, IFSStub
&Stub
, bool WriteIfChanged
) {
255 // Write IFS to memory first.
257 raw_string_ostream
OutStr(IFSStr
);
258 Error YAMLErr
= writeIFSToOutputStream(OutStr
, Stub
);
263 if (WriteIfChanged
) {
264 if (ErrorOr
<std::unique_ptr
<MemoryBuffer
>> BufOrError
=
265 MemoryBuffer::getFile(FilePath
)) {
266 // Compare IFS output with the existing IFS file. If unchanged, avoid
267 // changing the file.
268 if ((*BufOrError
)->getBuffer() == IFSStr
)
269 return Error::success();
272 // Open IFS file for writing.
273 std::error_code SysErr
;
274 raw_fd_ostream
Out(FilePath
, SysErr
);
276 return createStringError(SysErr
, "Couldn't open `%s` for writing",
279 return Error::success();
282 static DriverConfig
parseArgs(int argc
, char *const *argv
) {
284 StringSaver
Saver(A
);
286 StringRef ToolName
= argv
[0];
287 llvm::opt::InputArgList Args
= Tbl
.parseArgs(
288 argc
, argv
, OPT_UNKNOWN
, Saver
, [&](StringRef Msg
) { fatalError(Msg
); });
289 if (Args
.hasArg(OPT_help
)) {
290 Tbl
.printHelp(llvm::outs(),
291 (Twine(ToolName
) + " <input_file> <output_file> [options]")
294 "shared object stubbing tool");
297 if (Args
.hasArg(OPT_version
)) {
298 llvm::outs() << ToolName
<< '\n';
299 cl::PrintVersionMessage();
304 for (const opt::Arg
*A
: Args
.filtered(OPT_INPUT
))
305 Config
.InputFilePaths
.push_back(A
->getValue());
306 if (const opt::Arg
*A
= Args
.getLastArg(OPT_input_format_EQ
)) {
307 Config
.InputFormat
= StringSwitch
<std::optional
<FileFormat
>>(A
->getValue())
308 .Case("IFS", FileFormat::IFS
)
309 .Case("ELF", FileFormat::ELF
)
310 .Default(std::nullopt
);
311 if (!Config
.InputFormat
)
312 fatalError(Twine("invalid argument '") + A
->getValue());
315 auto OptionNotFound
= [ToolName
](StringRef FlagName
, StringRef OptionName
) {
316 fatalError(Twine(ToolName
) + ": for the " + FlagName
+
317 " option: Cannot find option named '" + OptionName
+ "'!");
319 if (const opt::Arg
*A
= Args
.getLastArg(OPT_output_format_EQ
)) {
320 Config
.OutputFormat
= StringSwitch
<std::optional
<FileFormat
>>(A
->getValue())
321 .Case("IFS", FileFormat::IFS
)
322 .Case("ELF", FileFormat::ELF
)
323 .Case("TBD", FileFormat::TBD
)
324 .Default(std::nullopt
);
325 if (!Config
.OutputFormat
)
326 OptionNotFound("--output-format", A
->getValue());
328 if (const opt::Arg
*A
= Args
.getLastArg(OPT_arch_EQ
)) {
329 uint16_t eMachine
= ELF::convertArchNameToEMachine(A
->getValue());
330 if (eMachine
== ELF::EM_NONE
) {
331 fatalError(Twine("unknown arch '") + A
->getValue() + "'");
333 Config
.OverrideArch
= eMachine
;
335 if (const opt::Arg
*A
= Args
.getLastArg(OPT_bitwidth_EQ
)) {
337 llvm::StringRef
S(A
->getValue());
338 if (!S
.getAsInteger
<size_t>(10, Width
) || Width
== 64 || Width
== 32)
339 Config
.OverrideBitWidth
=
340 Width
== 64 ? IFSBitWidthType::IFS64
: IFSBitWidthType::IFS32
;
342 OptionNotFound("--bitwidth", A
->getValue());
344 if (const opt::Arg
*A
= Args
.getLastArg(OPT_endianness_EQ
)) {
345 Config
.OverrideEndianness
=
346 StringSwitch
<std::optional
<IFSEndiannessType
>>(A
->getValue())
347 .Case("little", IFSEndiannessType::Little
)
348 .Case("big", IFSEndiannessType::Big
)
349 .Default(std::nullopt
);
350 if (!Config
.OverrideEndianness
)
351 OptionNotFound("--endianness", A
->getValue());
353 if (const opt::Arg
*A
= Args
.getLastArg(OPT_target_EQ
))
354 Config
.OptTargetTriple
= A
->getValue();
355 if (const opt::Arg
*A
= Args
.getLastArg(OPT_hint_ifs_target_EQ
))
356 Config
.HintIfsTarget
= A
->getValue();
358 Config
.StripIfsArch
= Args
.hasArg(OPT_strip_ifs_arch
);
359 Config
.StripIfsBitwidth
= Args
.hasArg(OPT_strip_ifs_bitwidth
);
360 Config
.StripIfsEndianness
= Args
.hasArg(OPT_strip_ifs_endianness
);
361 Config
.StripIfsTarget
= Args
.hasArg(OPT_strip_ifs_target
);
362 Config
.StripUndefined
= Args
.hasArg(OPT_strip_undefined
);
363 Config
.StripNeeded
= Args
.hasArg(OPT_strip_needed
);
364 Config
.StripSize
= Args
.hasArg(OPT_strip_size
);
366 for (const opt::Arg
*A
: Args
.filtered(OPT_exclude_EQ
))
367 Config
.Exclude
.push_back(A
->getValue());
368 if (const opt::Arg
*A
= Args
.getLastArg(OPT_soname_EQ
))
369 Config
.SoName
= A
->getValue();
370 if (const opt::Arg
*A
= Args
.getLastArg(OPT_output_EQ
))
371 Config
.Output
= A
->getValue();
372 if (const opt::Arg
*A
= Args
.getLastArg(OPT_output_elf_EQ
))
373 Config
.OutputElf
= A
->getValue();
374 if (const opt::Arg
*A
= Args
.getLastArg(OPT_output_ifs_EQ
))
375 Config
.OutputIfs
= A
->getValue();
376 if (const opt::Arg
*A
= Args
.getLastArg(OPT_output_tbd_EQ
))
377 Config
.OutputTbd
= A
->getValue();
378 Config
.WriteIfChanged
= Args
.hasArg(OPT_write_if_changed
);
382 int llvm_ifs_main(int argc
, char **argv
, const llvm::ToolContext
&) {
383 DriverConfig Config
= parseArgs(argc
, argv
);
385 if (Config
.InputFilePaths
.empty())
386 Config
.InputFilePaths
.push_back("-");
388 // If input files are more than one, they can only be IFS files.
389 if (Config
.InputFilePaths
.size() > 1)
390 Config
.InputFormat
= FileFormat::IFS
;
392 // Attempt to merge input.
394 std::map
<std::string
, IFSSymbol
> SymbolMap
;
395 std::string PreviousInputFilePath
;
396 for (const std::string
&InputFilePath
: Config
.InputFilePaths
) {
397 Expected
<std::unique_ptr
<IFSStub
>> StubOrErr
=
398 readInputFile(Config
.InputFormat
, InputFilePath
);
400 fatalError(StubOrErr
.takeError());
402 std::unique_ptr
<IFSStub
> TargetStub
= std::move(StubOrErr
.get());
403 if (PreviousInputFilePath
.empty()) {
404 Stub
.IfsVersion
= TargetStub
->IfsVersion
;
405 Stub
.Target
= TargetStub
->Target
;
406 Stub
.SoName
= TargetStub
->SoName
;
407 Stub
.NeededLibs
= TargetStub
->NeededLibs
;
409 if (Stub
.IfsVersion
!= TargetStub
->IfsVersion
) {
410 if (Stub
.IfsVersion
.getMajor() != IfsVersionCurrent
.getMajor()) {
412 << "Interface Stub: IfsVersion Mismatch."
413 << "\nFilenames: " << PreviousInputFilePath
<< " "
414 << InputFilePath
<< "\nIfsVersion Values: " << Stub
.IfsVersion
415 << " " << TargetStub
->IfsVersion
<< "\n";
418 if (TargetStub
->IfsVersion
> Stub
.IfsVersion
)
419 Stub
.IfsVersion
= TargetStub
->IfsVersion
;
421 if (Stub
.Target
!= TargetStub
->Target
&& !TargetStub
->Target
.empty()) {
422 WithColor::error() << "Interface Stub: Target Mismatch."
423 << "\nFilenames: " << PreviousInputFilePath
<< " "
427 if (Stub
.SoName
!= TargetStub
->SoName
) {
428 WithColor::error() << "Interface Stub: SoName Mismatch."
429 << "\nFilenames: " << PreviousInputFilePath
<< " "
431 << "\nSoName Values: " << Stub
.SoName
<< " "
432 << TargetStub
->SoName
<< "\n";
435 if (Stub
.NeededLibs
!= TargetStub
->NeededLibs
) {
436 WithColor::error() << "Interface Stub: NeededLibs Mismatch."
437 << "\nFilenames: " << PreviousInputFilePath
<< " "
438 << InputFilePath
<< "\n";
443 for (auto Symbol
: TargetStub
->Symbols
) {
444 auto [SI
, Inserted
] = SymbolMap
.try_emplace(Symbol
.Name
, Symbol
);
448 assert(Symbol
.Name
== SI
->second
.Name
&& "Symbol Names Must Match.");
451 if (Symbol
.Type
!= SI
->second
.Type
) {
452 WithColor::error() << "Interface Stub: Type Mismatch for "
453 << Symbol
.Name
<< ".\nFilename: " << InputFilePath
454 << "\nType Values: " << getTypeName(SI
->second
.Type
)
455 << " " << getTypeName(Symbol
.Type
) << "\n";
459 if (Symbol
.Size
!= SI
->second
.Size
) {
460 WithColor::error() << "Interface Stub: Size Mismatch for "
461 << Symbol
.Name
<< ".\nFilename: " << InputFilePath
462 << "\nSize Values: " << SI
->second
.Size
<< " "
463 << Symbol
.Size
<< "\n";
467 if (Symbol
.Weak
!= SI
->second
.Weak
) {
471 // TODO: Not checking Warning. Will be dropped.
474 PreviousInputFilePath
= InputFilePath
;
477 if (Stub
.IfsVersion
!= IfsVersionCurrent
)
478 if (Stub
.IfsVersion
.getMajor() != IfsVersionCurrent
.getMajor()) {
479 WithColor::error() << "Interface Stub: Bad IfsVersion: "
480 << Stub
.IfsVersion
<< ", llvm-ifs supported version: "
481 << IfsVersionCurrent
<< ".\n";
485 for (auto &Entry
: SymbolMap
)
486 Stub
.Symbols
.push_back(Entry
.second
);
488 // Change SoName before emitting stubs.
490 Stub
.SoName
= *Config
.SoName
;
492 Error OverrideError
=
493 overrideIFSTarget(Stub
, Config
.OverrideArch
, Config
.OverrideEndianness
,
494 Config
.OverrideBitWidth
, Config
.OptTargetTriple
);
496 fatalError(std::move(OverrideError
));
498 if (Config
.StripNeeded
)
499 Stub
.NeededLibs
.clear();
501 if (Error E
= filterIFSSyms(Stub
, Config
.StripUndefined
, Config
.Exclude
))
502 fatalError(std::move(E
));
504 if (Config
.StripSize
)
505 for (IFSSymbol
&Sym
: Stub
.Symbols
)
508 if (!Config
.OutputElf
&& !Config
.OutputIfs
&& !Config
.OutputTbd
) {
509 if (!Config
.OutputFormat
) {
510 WithColor::error() << "at least one output should be specified.";
513 } else if (Config
.OutputFormat
) {
514 WithColor::error() << "'--output-format' cannot be used with "
515 "'--output-{FILE_FORMAT}' options at the same time";
518 if (Config
.OutputFormat
) {
519 // TODO: Remove OutputFormat flag in the next revision.
520 WithColor::warning() << "--output-format option is deprecated, please use "
521 "--output-{FILE_FORMAT} options instead\n";
522 switch (*Config
.OutputFormat
) {
523 case FileFormat::TBD
: {
524 std::error_code SysErr
;
525 raw_fd_ostream
Out(*Config
.Output
, SysErr
);
527 WithColor::error() << "Couldn't open " << *Config
.Output
528 << " for writing.\n";
531 if (!Stub
.Target
.Triple
) {
533 << "Triple should be defined when output format is TBD";
536 return writeTbdStub(llvm::Triple(*Stub
.Target
.Triple
), Stub
.Symbols
,
539 case FileFormat::IFS
: {
540 Stub
.IfsVersion
= IfsVersionCurrent
;
541 if (*Config
.InputFormat
== FileFormat::ELF
&& Config
.HintIfsTarget
) {
542 std::error_code
HintEC(1, std::generic_category());
543 IFSTarget HintTarget
= parseTriple(*Config
.HintIfsTarget
);
544 if (*Stub
.Target
.Arch
!= *HintTarget
.Arch
)
545 fatalError(make_error
<StringError
>(
546 "Triple hint does not match the actual architecture", HintEC
));
547 if (*Stub
.Target
.Endianness
!= *HintTarget
.Endianness
)
548 fatalError(make_error
<StringError
>(
549 "Triple hint does not match the actual endianness", HintEC
));
550 if (*Stub
.Target
.BitWidth
!= *HintTarget
.BitWidth
)
551 fatalError(make_error
<StringError
>(
552 "Triple hint does not match the actual bit width", HintEC
));
554 stripIFSTarget(Stub
, true, false, false, false);
555 Stub
.Target
.Triple
= *Config
.HintIfsTarget
;
557 stripIFSTarget(Stub
, Config
.StripIfsTarget
, Config
.StripIfsArch
,
558 Config
.StripIfsEndianness
, Config
.StripIfsBitwidth
);
560 Error IFSWriteError
=
561 writeIFS(*Config
.Output
, Stub
, Config
.WriteIfChanged
);
563 fatalError(std::move(IFSWriteError
));
566 case FileFormat::ELF
: {
567 Error TargetError
= validateIFSTarget(Stub
, true);
569 fatalError(std::move(TargetError
));
570 Error BinaryWriteError
=
571 writeBinaryStub(*Config
.Output
, Stub
, Config
.WriteIfChanged
);
572 if (BinaryWriteError
)
573 fatalError(std::move(BinaryWriteError
));
578 // Check if output path for individual format.
579 if (Config
.OutputElf
) {
580 Error TargetError
= validateIFSTarget(Stub
, true);
582 fatalError(std::move(TargetError
));
583 Error BinaryWriteError
=
584 writeBinaryStub(*Config
.OutputElf
, Stub
, Config
.WriteIfChanged
);
585 if (BinaryWriteError
)
586 fatalError(std::move(BinaryWriteError
));
588 if (Config
.OutputIfs
) {
589 Stub
.IfsVersion
= IfsVersionCurrent
;
590 if (*Config
.InputFormat
== FileFormat::ELF
&& Config
.HintIfsTarget
) {
591 std::error_code
HintEC(1, std::generic_category());
592 IFSTarget HintTarget
= parseTriple(*Config
.HintIfsTarget
);
593 if (*Stub
.Target
.Arch
!= *HintTarget
.Arch
)
594 fatalError(make_error
<StringError
>(
595 "Triple hint does not match the actual architecture", HintEC
));
596 if (*Stub
.Target
.Endianness
!= *HintTarget
.Endianness
)
597 fatalError(make_error
<StringError
>(
598 "Triple hint does not match the actual endianness", HintEC
));
599 if (*Stub
.Target
.BitWidth
!= *HintTarget
.BitWidth
)
600 fatalError(make_error
<StringError
>(
601 "Triple hint does not match the actual bit width", HintEC
));
603 stripIFSTarget(Stub
, true, false, false, false);
604 Stub
.Target
.Triple
= *Config
.HintIfsTarget
;
606 stripIFSTarget(Stub
, Config
.StripIfsTarget
, Config
.StripIfsArch
,
607 Config
.StripIfsEndianness
, Config
.StripIfsBitwidth
);
609 Error IFSWriteError
=
610 writeIFS(*Config
.OutputIfs
, Stub
, Config
.WriteIfChanged
);
612 fatalError(std::move(IFSWriteError
));
614 if (Config
.OutputTbd
) {
615 std::error_code SysErr
;
616 raw_fd_ostream
Out(*Config
.OutputTbd
, SysErr
);
618 WithColor::error() << "Couldn't open " << *Config
.OutputTbd
619 << " for writing.\n";
622 if (!Stub
.Target
.Triple
) {
624 << "Triple should be defined when output format is TBD";
627 return writeTbdStub(llvm::Triple(*Stub
.Target
.Triple
), Stub
.Symbols
,