File indexing completed on 2026-05-10 08:43:49
0001
0002
0003
0004
0005
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
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
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
0065 static constexpr const StringLiteral &
0066 getSectionName(DebugSectionKind SectionKind) {
0067 return SectionNames[static_cast<uint8_t>(SectionKind)];
0068 }
0069
0070
0071 std::optional<DebugSectionKind> parseDebugTableName(StringRef Name);
0072
0073
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
0087 enum class OutputFileType : uint8_t {
0088 Object,
0089 Assembly,
0090 };
0091
0092 enum class AccelTableKind : uint8_t {
0093 Apple,
0094 Pub,
0095 DebugNames
0096 };
0097
0098
0099
0100
0101
0102
0103
0104 virtual void addObjectFile(
0105 DWARFFile &File, ObjFileLoaderTy Loader = nullptr,
0106 CompileUnitHandlerTy OnCUDieLoaded = [](const DWARFUnit &) {}) = 0;
0107
0108
0109 virtual Error link() = 0;
0110
0111
0112 virtual void setVerbosity(bool Verbose) = 0;
0113
0114 virtual void setStatistics(bool Statistics) = 0;
0115
0116 virtual void setVerifyInputDWARF(bool Verify) = 0;
0117
0118 virtual void setNoODR(bool NoODR) = 0;
0119
0120 virtual void setUpdateIndexTablesOnly(bool Update) = 0;
0121
0122
0123 virtual void setAllowNonDeterministicOutput(bool) = 0;
0124
0125 virtual void setKeepFunctionForStatic(bool KeepFunctionForStatic) = 0;
0126
0127 virtual void setNumThreads(unsigned NumThreads) = 0;
0128
0129 virtual void addAccelTableKind(AccelTableKind Kind) = 0;
0130
0131 virtual void setPrependPath(StringRef Ppath) = 0;
0132
0133 virtual void setEstimatedObjfilesAmount(unsigned ObjFilesNum) = 0;
0134
0135 virtual void
0136 setInputVerificationHandler(InputVerificationHandlerTy Handler) = 0;
0137
0138 virtual void setSwiftInterfacesMap(SwiftInterfacesMapTy *Map) = 0;
0139
0140 virtual void setObjectPrefixMap(ObjectPrefixMapTy *Map) = 0;
0141
0142 virtual Error setTargetDWARFVersion(uint16_t TargetDWARFVersion) = 0;
0143 };
0144 }
0145 }
0146 #endif