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 TranslatorFuncTy = std::function<StringRef(StringRef)>; 251db9f3b2SDimitry Andric using MessageHandlerTy = std::function<void( 261db9f3b2SDimitry Andric const Twine &Warning, StringRef Context, const DWARFDie *DIE)>; 271db9f3b2SDimitry Andric 281db9f3b2SDimitry Andric /// linking options 291db9f3b2SDimitry Andric struct DWARFLinkerOptions { 301db9f3b2SDimitry Andric /// DWARF version for the output. 311db9f3b2SDimitry Andric uint16_t TargetDWARFVersion = 0; 321db9f3b2SDimitry Andric 331db9f3b2SDimitry Andric /// Generate processing log to the standard output. 341db9f3b2SDimitry Andric bool Verbose = false; 351db9f3b2SDimitry Andric 361db9f3b2SDimitry Andric /// Print statistics. 371db9f3b2SDimitry Andric bool Statistics = false; 381db9f3b2SDimitry Andric 391db9f3b2SDimitry Andric /// Verify the input DWARF. 401db9f3b2SDimitry Andric bool VerifyInputDWARF = false; 411db9f3b2SDimitry Andric 421db9f3b2SDimitry Andric /// Do not unique types according to ODR 431db9f3b2SDimitry Andric bool NoODR = false; 441db9f3b2SDimitry Andric 451db9f3b2SDimitry Andric /// Update index tables. 461db9f3b2SDimitry Andric bool UpdateIndexTablesOnly = false; 471db9f3b2SDimitry Andric 481db9f3b2SDimitry Andric /// Whether we want a static variable to force us to keep its enclosing 491db9f3b2SDimitry Andric /// function. 501db9f3b2SDimitry Andric bool KeepFunctionForStatic = false; 511db9f3b2SDimitry Andric 521db9f3b2SDimitry Andric /// Allow to generate valid, but non deterministic output. 531db9f3b2SDimitry Andric bool AllowNonDeterministicOutput = false; 541db9f3b2SDimitry Andric 551db9f3b2SDimitry Andric /// Number of threads. 561db9f3b2SDimitry Andric unsigned Threads = 1; 571db9f3b2SDimitry Andric 581db9f3b2SDimitry Andric /// The accelerator table kinds 59*7a6dacacSDimitry Andric SmallVector<DWARFLinkerBase::AccelTableKind, 1> AccelTables; 601db9f3b2SDimitry Andric 611db9f3b2SDimitry Andric /// Prepend path for the clang modules. 621db9f3b2SDimitry Andric std::string PrependPath; 631db9f3b2SDimitry Andric 641db9f3b2SDimitry Andric /// input verification handler(it might be called asynchronously). 65*7a6dacacSDimitry Andric DWARFLinkerBase::InputVerificationHandlerTy InputVerificationHandler = 66*7a6dacacSDimitry Andric nullptr; 671db9f3b2SDimitry Andric 681db9f3b2SDimitry Andric /// A list of all .swiftinterface files referenced by the debug 691db9f3b2SDimitry Andric /// info, mapping Module name to path on disk. The entries need to 701db9f3b2SDimitry Andric /// be uniqued and sorted and there are only few entries expected 711db9f3b2SDimitry Andric /// per compile unit, which is why this is a std::map. 721db9f3b2SDimitry Andric /// this is dsymutil specific fag. 731db9f3b2SDimitry Andric /// 741db9f3b2SDimitry Andric /// (it might be called asynchronously). 75*7a6dacacSDimitry Andric DWARFLinkerBase::SwiftInterfacesMapTy *ParseableSwiftInterfaces = nullptr; 761db9f3b2SDimitry Andric 771db9f3b2SDimitry Andric /// A list of remappings to apply to file paths. 781db9f3b2SDimitry Andric /// 791db9f3b2SDimitry Andric /// (it might be called asynchronously). 80*7a6dacacSDimitry Andric DWARFLinkerBase::ObjectPrefixMapTy *ObjectPrefixMap = nullptr; 811db9f3b2SDimitry Andric }; 821db9f3b2SDimitry Andric 831db9f3b2SDimitry Andric class DWARFLinkerImpl; 841db9f3b2SDimitry Andric 851db9f3b2SDimitry Andric /// This class keeps data and services common for the whole linking process. 861db9f3b2SDimitry Andric class LinkingGlobalData { 871db9f3b2SDimitry Andric friend DWARFLinkerImpl; 881db9f3b2SDimitry Andric 891db9f3b2SDimitry Andric public: 901db9f3b2SDimitry Andric /// Returns global per-thread allocator. 911db9f3b2SDimitry Andric llvm::parallel::PerThreadBumpPtrAllocator &getAllocator() { 921db9f3b2SDimitry Andric return Allocator; 931db9f3b2SDimitry Andric } 941db9f3b2SDimitry Andric 951db9f3b2SDimitry Andric /// Returns global string pool. 961db9f3b2SDimitry Andric StringPool &getStringPool() { return Strings; } 971db9f3b2SDimitry Andric 981db9f3b2SDimitry Andric /// Set translation function. 991db9f3b2SDimitry Andric void setTranslator(TranslatorFuncTy Translator) { 1001db9f3b2SDimitry Andric this->Translator = Translator; 1011db9f3b2SDimitry Andric } 1021db9f3b2SDimitry Andric 1031db9f3b2SDimitry Andric /// Translate specified string. 1041db9f3b2SDimitry Andric StringRef translateString(StringRef String) { 1051db9f3b2SDimitry Andric if (Translator) 1061db9f3b2SDimitry Andric return Translator(String); 1071db9f3b2SDimitry Andric 1081db9f3b2SDimitry Andric return String; 1091db9f3b2SDimitry Andric } 1101db9f3b2SDimitry Andric 1111db9f3b2SDimitry Andric /// Returns linking options. 1121db9f3b2SDimitry Andric const DWARFLinkerOptions &getOptions() const { return Options; } 1131db9f3b2SDimitry Andric 1141db9f3b2SDimitry Andric /// Set warning handler. 1151db9f3b2SDimitry Andric void setWarningHandler(MessageHandlerTy Handler) { WarningHandler = Handler; } 1161db9f3b2SDimitry Andric 1171db9f3b2SDimitry Andric /// Set error handler. 1181db9f3b2SDimitry Andric void setErrorHandler(MessageHandlerTy Handler) { ErrorHandler = Handler; } 1191db9f3b2SDimitry Andric 1201db9f3b2SDimitry Andric /// Report warning. 1211db9f3b2SDimitry Andric void warn(const Twine &Warning, StringRef Context, 1221db9f3b2SDimitry Andric const DWARFDie *DIE = nullptr) { 1231db9f3b2SDimitry Andric if (WarningHandler) 1241db9f3b2SDimitry Andric (WarningHandler)(Warning, Context, DIE); 1251db9f3b2SDimitry Andric } 1261db9f3b2SDimitry Andric 1271db9f3b2SDimitry Andric /// Report warning. 1281db9f3b2SDimitry Andric void warn(Error Warning, StringRef Context, const DWARFDie *DIE = nullptr) { 1291db9f3b2SDimitry Andric handleAllErrors(std::move(Warning), [&](ErrorInfoBase &Info) { 1301db9f3b2SDimitry Andric warn(Info.message(), Context, DIE); 1311db9f3b2SDimitry Andric }); 1321db9f3b2SDimitry Andric } 1331db9f3b2SDimitry Andric 1341db9f3b2SDimitry Andric /// Report error. 1351db9f3b2SDimitry Andric void error(const Twine &Err, StringRef Context, 1361db9f3b2SDimitry Andric const DWARFDie *DIE = nullptr) { 1371db9f3b2SDimitry Andric if (ErrorHandler) 1381db9f3b2SDimitry Andric (ErrorHandler)(Err, Context, DIE); 1391db9f3b2SDimitry Andric } 1401db9f3b2SDimitry Andric 1411db9f3b2SDimitry Andric /// Report error. 1421db9f3b2SDimitry Andric void error(Error Err, StringRef Context, const DWARFDie *DIE = nullptr) { 1431db9f3b2SDimitry Andric handleAllErrors(std::move(Err), [&](ErrorInfoBase &Info) { 1441db9f3b2SDimitry Andric error(Info.message(), Context, DIE); 1451db9f3b2SDimitry Andric }); 1461db9f3b2SDimitry Andric } 1471db9f3b2SDimitry Andric 148*7a6dacacSDimitry Andric /// Set target triple. 149*7a6dacacSDimitry Andric void setTargetTriple(const Triple &TargetTriple) { 150*7a6dacacSDimitry Andric this->TargetTriple = TargetTriple; 151*7a6dacacSDimitry Andric } 152*7a6dacacSDimitry Andric 153*7a6dacacSDimitry Andric /// Optionally return target triple. 154*7a6dacacSDimitry Andric std::optional<std::reference_wrapper<const Triple>> getTargetTriple() { 155*7a6dacacSDimitry Andric if (TargetTriple) 156*7a6dacacSDimitry Andric return std::cref(*TargetTriple); 157*7a6dacacSDimitry Andric 158*7a6dacacSDimitry Andric return std::nullopt; 159*7a6dacacSDimitry Andric } 160*7a6dacacSDimitry Andric 1611db9f3b2SDimitry Andric protected: 1621db9f3b2SDimitry Andric llvm::parallel::PerThreadBumpPtrAllocator Allocator; 1631db9f3b2SDimitry Andric StringPool Strings; 1641db9f3b2SDimitry Andric TranslatorFuncTy Translator; 1651db9f3b2SDimitry Andric DWARFLinkerOptions Options; 1661db9f3b2SDimitry Andric MessageHandlerTy WarningHandler; 1671db9f3b2SDimitry Andric MessageHandlerTy ErrorHandler; 168*7a6dacacSDimitry Andric 169*7a6dacacSDimitry Andric /// Triple for output data. May be not set if generation of output 170*7a6dacacSDimitry Andric /// data is not requested. 171*7a6dacacSDimitry Andric std::optional<Triple> TargetTriple; 1721db9f3b2SDimitry Andric }; 1731db9f3b2SDimitry Andric 1741db9f3b2SDimitry Andric } // end of namespace parallel 1751db9f3b2SDimitry Andric } // end of namespace dwarf_linker 1761db9f3b2SDimitry Andric } // end of namespace llvm 1771db9f3b2SDimitry Andric 1781db9f3b2SDimitry Andric #endif // LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERGLOBALDATA_H 179