Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:49

0001 //===- DWARFLinkerBase.h ----------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DWARFLINKER_DWARFLINKERBASE_H
0010 #define LLVM_DWARFLINKER_DWARFLINKERBASE_H
0011 #include "AddressesMap.h"
0012 #include "DWARFFile.h"
0013 #include "llvm/ADT/AddressRanges.h"
0014 #include "llvm/ADT/DenseMap.h"
0015 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
0016 #include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
0017 #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
0018 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
0019 #include "llvm/DebugInfo/DWARF/DWARFExpression.h"
0020 #include <map>
0021 namespace llvm {
0022 class DWARFUnit;
0023 
0024 namespace dwarf_linker {
0025 
0026 /// List of tracked debug tables.
0027 enum class DebugSectionKind : uint8_t {
0028   DebugInfo = 0,
0029   DebugLine,
0030   DebugFrame,
0031   DebugRange,
0032   DebugRngLists,
0033   DebugLoc,
0034   DebugLocLists,
0035   DebugARanges,
0036   DebugAbbrev,
0037   DebugMacinfo,
0038   DebugMacro,
0039   DebugAddr,
0040   DebugStr,
0041   DebugLineStr,
0042   DebugStrOffsets,
0043   DebugPubNames,
0044   DebugPubTypes,
0045   DebugNames,
0046   AppleNames,
0047   AppleNamespaces,
0048   AppleObjC,
0049   AppleTypes,
0050   NumberOfEnumEntries // must be last
0051 };
0052 
0053 static constexpr size_t SectionKindsNum =
0054     static_cast<size_t>(DebugSectionKind::NumberOfEnumEntries);
0055 
0056 static constexpr StringLiteral SectionNames[SectionKindsNum] = {
0057     "debug_info",     "debug_line",     "debug_frame",       "debug_ranges",
0058     "debug_rnglists", "debug_loc",      "debug_loclists",    "debug_aranges",
0059     "debug_abbrev",   "debug_macinfo",  "debug_macro",       "debug_addr",
0060     "debug_str",      "debug_line_str", "debug_str_offsets", "debug_pubnames",
0061     "debug_pubtypes", "debug_names",    "apple_names",       "apple_namespac",
0062     "apple_objc",     "apple_types"};
0063 
0064 /// Return the name of the section.
0065 static constexpr const StringLiteral &
0066 getSectionName(DebugSectionKind SectionKind) {
0067   return SectionNames[static_cast<uint8_t>(SectionKind)];
0068 }
0069 
0070 /// Recognise the table name and match it with the DebugSectionKind.
0071 std::optional<DebugSectionKind> parseDebugTableName(StringRef Name);
0072 
0073 /// The base interface for DWARFLinker implementations.
0074 class DWARFLinkerBase {
0075 public:
0076   virtual ~DWARFLinkerBase() = default;
0077   using MessageHandlerTy = std::function<void(
0078       const Twine &Warning, StringRef Context, const DWARFDie *DIE)>;
0079   using ObjFileLoaderTy = std::function<ErrorOr<DWARFFile &>(
0080       StringRef ContainerName, StringRef Path)>;
0081   using InputVerificationHandlerTy =
0082       std::function<void(const DWARFFile &File, llvm::StringRef Output)>;
0083   using ObjectPrefixMapTy = std::map<std::string, std::string>;
0084   using CompileUnitHandlerTy = function_ref<void(const DWARFUnit &Unit)>;
0085   using SwiftInterfacesMapTy = std::map<std::string, std::string>;
0086   /// Type of output file.
0087   enum class OutputFileType : uint8_t {
0088     Object,
0089     Assembly,
0090   };
0091   /// The kind of accelerator tables to be emitted.
0092   enum class AccelTableKind : uint8_t {
0093     Apple,     ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
0094     Pub,       ///< .debug_pubnames, .debug_pubtypes
0095     DebugNames ///< .debug_names.
0096   };
0097   /// Add an object file to be linked. Pre-load compile unit die. Call
0098   /// \p OnCUDieLoaded for each compile unit die. If \p File has reference to
0099   /// a Clang module and UpdateIndexTablesOnly == false then the module is be
0100   /// pre-loaded by \p Loader.
0101   ///
0102   /// \pre a call to setNoODR(true) and/or setUpdateIndexTablesOnly(bool Update)
0103   ///      must be made when required.
0104   virtual void addObjectFile(
0105       DWARFFile &File, ObjFileLoaderTy Loader = nullptr,
0106       CompileUnitHandlerTy OnCUDieLoaded = [](const DWARFUnit &) {}) = 0;
0107   /// Link the debug info for all object files added through calls to
0108   /// addObjectFile.
0109   virtual Error link() = 0;
0110   /// A number of methods setting various linking options:
0111   /// Enable logging to standard output.
0112   virtual void setVerbosity(bool Verbose) = 0;
0113   /// Print statistics to standard output.
0114   virtual void setStatistics(bool Statistics) = 0;
0115   /// Verify the input DWARF.
0116   virtual void setVerifyInputDWARF(bool Verify) = 0;
0117   /// Do not unique types according to ODR.
0118   virtual void setNoODR(bool NoODR) = 0;
0119   /// Update index tables only (do not modify rest of DWARF).
0120   virtual void setUpdateIndexTablesOnly(bool Update) = 0;
0121   /// Allows generating non-deterministic output in exchange for more
0122   /// parallelism.
0123   virtual void setAllowNonDeterministicOutput(bool) = 0;
0124   /// Set whether to keep the enclosing function for a static variable.
0125   virtual void setKeepFunctionForStatic(bool KeepFunctionForStatic) = 0;
0126   /// Use specified number of threads for parallel files linking.
0127   virtual void setNumThreads(unsigned NumThreads) = 0;
0128   /// Add kind of accelerator tables to be generated.
0129   virtual void addAccelTableKind(AccelTableKind Kind) = 0;
0130   /// Set prepend path for clang modules.
0131   virtual void setPrependPath(StringRef Ppath) = 0;
0132   /// Set estimated objects files amount, for preliminary data allocation.
0133   virtual void setEstimatedObjfilesAmount(unsigned ObjFilesNum) = 0;
0134   /// Set verification handler used to report verification errors.
0135   virtual void
0136   setInputVerificationHandler(InputVerificationHandlerTy Handler) = 0;
0137   /// Set map for Swift interfaces.
0138   virtual void setSwiftInterfacesMap(SwiftInterfacesMapTy *Map) = 0;
0139   /// Set prefix map for objects.
0140   virtual void setObjectPrefixMap(ObjectPrefixMapTy *Map) = 0;
0141   /// Set target DWARF version.
0142   virtual Error setTargetDWARFVersion(uint16_t TargetDWARFVersion) = 0;
0143 };
0144 } // end namespace dwarf_linker
0145 } // end namespace llvm
0146 #endif // LLVM_DWARFLINKER_DWARFLINKERBASE_H