11db9f3b2SDimitry Andric //===- DWARFLinkerGlobalData.h ----------------------------------*- C++ -*-===// 21db9f3b2SDimitry Andric // 31db9f3b2SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 41db9f3b2SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 51db9f3b2SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 61db9f3b2SDimitry Andric // 71db9f3b2SDimitry Andric //===----------------------------------------------------------------------===// 81db9f3b2SDimitry Andric 91db9f3b2SDimitry Andric #ifndef LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERGLOBALDATA_H 101db9f3b2SDimitry Andric #define LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERGLOBALDATA_H 111db9f3b2SDimitry Andric 121db9f3b2SDimitry Andric #include "TypePool.h" 131db9f3b2SDimitry Andric #include "llvm/DWARFLinker/Parallel/DWARFLinker.h" 141db9f3b2SDimitry Andric #include "llvm/DWARFLinker/StringPool.h" 151db9f3b2SDimitry Andric #include "llvm/Support/PerThreadBumpPtrAllocator.h" 161db9f3b2SDimitry Andric 171db9f3b2SDimitry Andric namespace llvm { 181db9f3b2SDimitry Andric 191db9f3b2SDimitry Andric class DWARFDie; 201db9f3b2SDimitry Andric 211db9f3b2SDimitry Andric namespace dwarf_linker { 221db9f3b2SDimitry Andric namespace parallel { 231db9f3b2SDimitry Andric 241db9f3b2SDimitry Andric using MessageHandlerTy = std::function<void( 251db9f3b2SDimitry Andric const Twine &Warning, StringRef Context, const DWARFDie *DIE)>; 261db9f3b2SDimitry Andric 271db9f3b2SDimitry Andric /// linking options 281db9f3b2SDimitry Andric struct DWARFLinkerOptions { 291db9f3b2SDimitry Andric /// DWARF version for the output. 301db9f3b2SDimitry Andric uint16_t TargetDWARFVersion = 0; 311db9f3b2SDimitry Andric 321db9f3b2SDimitry Andric /// Generate processing log to the standard output. 331db9f3b2SDimitry Andric bool Verbose = false; 341db9f3b2SDimitry Andric 351db9f3b2SDimitry Andric /// Print statistics. 361db9f3b2SDimitry Andric bool Statistics = false; 371db9f3b2SDimitry Andric 381db9f3b2SDimitry Andric /// Verify the input DWARF. 391db9f3b2SDimitry Andric bool VerifyInputDWARF = false; 401db9f3b2SDimitry Andric 411db9f3b2SDimitry Andric /// Do not unique types according to ODR 421db9f3b2SDimitry Andric bool NoODR = false; 431db9f3b2SDimitry Andric 441db9f3b2SDimitry Andric /// Update index tables. 451db9f3b2SDimitry Andric bool UpdateIndexTablesOnly = false; 461db9f3b2SDimitry Andric 471db9f3b2SDimitry Andric /// Whether we want a static variable to force us to keep its enclosing 481db9f3b2SDimitry Andric /// function. 491db9f3b2SDimitry Andric bool KeepFunctionForStatic = false; 501db9f3b2SDimitry Andric 511db9f3b2SDimitry Andric /// Allow to generate valid, but non deterministic output. 521db9f3b2SDimitry Andric bool AllowNonDeterministicOutput = false; 531db9f3b2SDimitry Andric 541db9f3b2SDimitry Andric /// Number of threads. 551db9f3b2SDimitry Andric unsigned Threads = 1; 561db9f3b2SDimitry Andric 571db9f3b2SDimitry Andric /// The accelerator table kinds 58*7a6dacacSDimitry Andric SmallVector<DWARFLinkerBase::AccelTableKind, 1> AccelTables; 591db9f3b2SDimitry Andric 601db9f3b2SDimitry Andric /// Prepend path for the clang modules. 611db9f3b2SDimitry Andric std::string PrependPath; 621db9f3b2SDimitry Andric 631db9f3b2SDimitry Andric /// input verification handler(it might be called asynchronously). 64*7a6dacacSDimitry Andric DWARFLinkerBase::InputVerificationHandlerTy InputVerificationHandler = 65*7a6dacacSDimitry Andric nullptr; 661db9f3b2SDimitry Andric 671db9f3b2SDimitry Andric /// A list of all .swiftinterface files referenced by the debug 681db9f3b2SDimitry Andric /// info, mapping Module name to path on disk. The entries need to 691db9f3b2SDimitry Andric /// be uniqued and sorted and there are only few entries expected 701db9f3b2SDimitry Andric /// per compile unit, which is why this is a std::map. 711db9f3b2SDimitry Andric /// this is dsymutil specific fag. 721db9f3b2SDimitry Andric /// 731db9f3b2SDimitry Andric /// (it might be called asynchronously). 74*7a6dacacSDimitry Andric DWARFLinkerBase::SwiftInterfacesMapTy *ParseableSwiftInterfaces = nullptr; 751db9f3b2SDimitry Andric 761db9f3b2SDimitry Andric /// A list of remappings to apply to file paths. 771db9f3b2SDimitry Andric /// 781db9f3b2SDimitry Andric /// (it might be called asynchronously). 79*7a6dacacSDimitry Andric DWARFLinkerBase::ObjectPrefixMapTy *ObjectPrefixMap = nullptr; 801db9f3b2SDimitry Andric }; 811db9f3b2SDimitry Andric 821db9f3b2SDimitry Andric class DWARFLinkerImpl; 831db9f3b2SDimitry Andric 841db9f3b2SDimitry Andric /// This class keeps data and services common for the whole linking process. 851db9f3b2SDimitry Andric class LinkingGlobalData { 861db9f3b2SDimitry Andric friend DWARFLinkerImpl; 871db9f3b2SDimitry Andric 881db9f3b2SDimitry Andric public: 891db9f3b2SDimitry Andric /// Returns global per-thread allocator. 901db9f3b2SDimitry Andric llvm::parallel::PerThreadBumpPtrAllocator &getAllocator() { 911db9f3b2SDimitry Andric return Allocator; 921db9f3b2SDimitry Andric } 931db9f3b2SDimitry Andric 941db9f3b2SDimitry Andric /// Returns global string pool. 951db9f3b2SDimitry Andric StringPool &getStringPool() { return Strings; } 961db9f3b2SDimitry Andric 971db9f3b2SDimitry Andric /// Returns linking options. 981db9f3b2SDimitry Andric const DWARFLinkerOptions &getOptions() const { return Options; } 991db9f3b2SDimitry Andric 1001db9f3b2SDimitry Andric /// Set warning handler. 1011db9f3b2SDimitry Andric void setWarningHandler(MessageHandlerTy Handler) { WarningHandler = Handler; } 1021db9f3b2SDimitry Andric 1031db9f3b2SDimitry Andric /// Set error handler. 1041db9f3b2SDimitry Andric void setErrorHandler(MessageHandlerTy Handler) { ErrorHandler = Handler; } 1051db9f3b2SDimitry Andric 1061db9f3b2SDimitry Andric /// Report warning. 1071db9f3b2SDimitry Andric void warn(const Twine &Warning, StringRef Context, 1081db9f3b2SDimitry Andric const DWARFDie *DIE = nullptr) { 1091db9f3b2SDimitry Andric if (WarningHandler) 1101db9f3b2SDimitry Andric (WarningHandler)(Warning, Context, DIE); 1111db9f3b2SDimitry Andric } 1121db9f3b2SDimitry Andric 1131db9f3b2SDimitry Andric /// Report warning. 1141db9f3b2SDimitry Andric void warn(Error Warning, StringRef Context, const DWARFDie *DIE = nullptr) { 1151db9f3b2SDimitry Andric handleAllErrors(std::move(Warning), [&](ErrorInfoBase &Info) { 1161db9f3b2SDimitry Andric warn(Info.message(), Context, DIE); 1171db9f3b2SDimitry Andric }); 1181db9f3b2SDimitry Andric } 1191db9f3b2SDimitry Andric 1201db9f3b2SDimitry Andric /// Report error. 1211db9f3b2SDimitry Andric void error(const Twine &Err, StringRef Context, 1221db9f3b2SDimitry Andric const DWARFDie *DIE = nullptr) { 1231db9f3b2SDimitry Andric if (ErrorHandler) 1241db9f3b2SDimitry Andric (ErrorHandler)(Err, Context, DIE); 1251db9f3b2SDimitry Andric } 1261db9f3b2SDimitry Andric 1271db9f3b2SDimitry Andric /// Report error. 1281db9f3b2SDimitry Andric void error(Error Err, StringRef Context, const DWARFDie *DIE = nullptr) { 1291db9f3b2SDimitry Andric handleAllErrors(std::move(Err), [&](ErrorInfoBase &Info) { 1301db9f3b2SDimitry Andric error(Info.message(), Context, DIE); 1311db9f3b2SDimitry Andric }); 1321db9f3b2SDimitry Andric } 1331db9f3b2SDimitry Andric 134*7a6dacacSDimitry Andric /// Set target triple. 135*7a6dacacSDimitry Andric void setTargetTriple(const Triple &TargetTriple) { 136*7a6dacacSDimitry Andric this->TargetTriple = TargetTriple; 137*7a6dacacSDimitry Andric } 138*7a6dacacSDimitry Andric 139*7a6dacacSDimitry Andric /// Optionally return target triple. 140*7a6dacacSDimitry Andric std::optional<std::reference_wrapper<const Triple>> getTargetTriple() { 141*7a6dacacSDimitry Andric if (TargetTriple) 142*7a6dacacSDimitry Andric return std::cref(*TargetTriple); 143*7a6dacacSDimitry Andric 144*7a6dacacSDimitry Andric return std::nullopt; 145*7a6dacacSDimitry Andric } 146*7a6dacacSDimitry Andric 1471db9f3b2SDimitry Andric protected: 1481db9f3b2SDimitry Andric llvm::parallel::PerThreadBumpPtrAllocator Allocator; 1491db9f3b2SDimitry Andric StringPool Strings; 1501db9f3b2SDimitry Andric DWARFLinkerOptions Options; 1511db9f3b2SDimitry Andric MessageHandlerTy WarningHandler; 1521db9f3b2SDimitry Andric MessageHandlerTy ErrorHandler; 153*7a6dacacSDimitry Andric 154*7a6dacacSDimitry Andric /// Triple for output data. May be not set if generation of output 155*7a6dacacSDimitry Andric /// data is not requested. 156*7a6dacacSDimitry Andric std::optional<Triple> TargetTriple; 1571db9f3b2SDimitry Andric }; 1581db9f3b2SDimitry Andric 1591db9f3b2SDimitry Andric } // end of namespace parallel 1601db9f3b2SDimitry Andric } // end of namespace dwarf_linker 1611db9f3b2SDimitry Andric } // end of namespace llvm 1621db9f3b2SDimitry Andric 1631db9f3b2SDimitry Andric #endif // LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERGLOBALDATA_H 164