LLVM 23.0.0git
DWARFLinkerBase.h
Go to the documentation of this file.
1//===- DWARFLinkerBase.h ----------------------------------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_DWARFLINKER_DWARFLINKERBASE_H
10#define LLVM_DWARFLINKER_DWARFLINKERBASE_H
11#include "AddressesMap.h"
12#include "DWARFFile.h"
14#include "llvm/ADT/DenseMap.h"
21#include <map>
22namespace llvm {
23class DWARFUnit;
25
26namespace dwarf_linker {
27
28/// List of tracked debug tables.
54
55static constexpr size_t SectionKindsNum =
56 static_cast<size_t>(DebugSectionKind::NumberOfEnumEntries);
57
59 "debug_info", "debug_line", "debug_frame", "debug_ranges",
60 "debug_rnglists", "debug_loc", "debug_loclists", "debug_aranges",
61 "debug_abbrev", "debug_macinfo", "debug_macro", "debug_addr",
62 "debug_str", "debug_line_str", "debug_str_offsets", "debug_pubnames",
63 "debug_pubtypes", "debug_names", "apple_names", "apple_namespac",
64 "apple_objc", "apple_types"};
65
66/// Return the name of the section.
67static constexpr const StringLiteral &
71
72/// Recognise the table name and match it with the DebugSectionKind.
73LLVM_ABI std::optional<DebugSectionKind> parseDebugTableName(StringRef Name);
74
75/// The base interface for DWARFLinker implementations.
77public:
78 virtual ~DWARFLinkerBase() = default;
79 using MessageHandlerTy = std::function<void(
80 const Twine &Warning, StringRef Context, const DWARFDie *DIE)>;
81 using ObjFileLoaderTy = std::function<ErrorOr<DWARFFile &>(
82 StringRef ContainerName, StringRef Path)>;
84 std::function<void(const DWARFFile &File, llvm::StringRef Output)>;
85 using ObjectPrefixMapTy = std::map<std::string, std::string>;
86 using CompileUnitHandlerTy = function_ref<void(const DWARFUnit &Unit)>;
87 using SwiftInterfacesMapTy = std::map<std::string, std::string>;
88 /// Type of output file.
93 /// The kind of accelerator tables to be emitted.
94 enum class AccelTableKind : uint8_t {
95 Apple, ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
96 Pub, ///< .debug_pubnames, .debug_pubtypes
97 DebugNames ///< .debug_names.
98 };
99 /// Add an object file to be linked. Pre-load compile unit die. Call
100 /// \p OnCUDieLoaded for each compile unit die. If \p File has reference to
101 /// a Clang module and UpdateIndexTablesOnly == false then the module is be
102 /// pre-loaded by \p Loader.
103 ///
104 /// \pre a call to setNoODR(true) and/or setUpdateIndexTablesOnly(bool Update)
105 /// must be made when required.
106 virtual void addObjectFile(
107 DWARFFile &File, ObjFileLoaderTy Loader = nullptr,
108 CompileUnitHandlerTy OnCUDieLoaded = [](const DWARFUnit &) {}) = 0;
109 /// Link the debug info for all object files added through calls to
110 /// addObjectFile.
111 virtual Error link() = 0;
112 /// A number of methods setting various linking options:
113 /// Enable logging to standard output.
114 virtual void setVerbosity(bool Verbose) = 0;
115 /// Print statistics to standard output.
116 virtual void setStatistics(bool Statistics) = 0;
117 /// Verify the input DWARF.
118 virtual void setVerifyInputDWARF(bool Verify) = 0;
119 /// Do not unique types according to ODR.
120 virtual void setNoODR(bool NoODR) = 0;
121 /// Update index tables only (do not modify rest of DWARF).
122 virtual void setUpdateIndexTablesOnly(bool Update) = 0;
123 /// Set whether to keep the enclosing function for a static variable.
124 virtual void setKeepFunctionForStatic(bool KeepFunctionForStatic) = 0;
125 /// Use specified number of threads for parallel files linking.
126 virtual void setNumThreads(unsigned NumThreads) = 0;
127 /// Add kind of accelerator tables to be generated.
128 virtual void addAccelTableKind(AccelTableKind Kind) = 0;
129 /// Set prepend path for clang modules.
130 virtual void setPrependPath(StringRef Ppath) = 0;
131 /// Set estimated objects files amount, for preliminary data allocation.
132 virtual void setEstimatedObjfilesAmount(unsigned ObjFilesNum) = 0;
133 /// Set verification handler used to report verification errors.
134 virtual void
136 /// Set map for Swift interfaces.
138 /// Set prefix map for objects.
139 virtual void setObjectPrefixMap(ObjectPrefixMapTy *Map) = 0;
140 /// Set target DWARF version.
141 virtual Error setTargetDWARFVersion(uint16_t TargetDWARFVersion) = 0;
142 /// Set the thread pool used to link the object files.
143 virtual void setThreadPool(ThreadPoolInterface *Pool) = 0;
144};
145} // end namespace dwarf_linker
146} // end namespace llvm
147#endif // LLVM_DWARFLINKER_DWARFLINKERBASE_H
#define LLVM_ABI
Definition Compiler.h:215
This file defines the DenseMap class.
ppc ctr loops PowerPC CTR Loops Verify
A structured debug information entry.
Definition DIE.h:828
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
Definition DWARFDie.h:43
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition SectionKind.h:22
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:882
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
This defines the abstract base interface for a ThreadPool allowing asynchronous parallel execution on...
Definition ThreadPool.h:51
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
This class represents DWARF information for source file and it's address map.
Definition DWARFFile.h:25
The base interface for DWARFLinker implementations.
virtual void setNumThreads(unsigned NumThreads)=0
Use specified number of threads for parallel files linking.
std::map< std::string, std::string > ObjectPrefixMapTy
virtual void setThreadPool(ThreadPoolInterface *Pool)=0
Set the thread pool used to link the object files.
virtual void addObjectFile(DWARFFile &File, ObjFileLoaderTy Loader=nullptr, CompileUnitHandlerTy OnCUDieLoaded=[](const DWARFUnit &) {})=0
Add an object file to be linked.
virtual void setEstimatedObjfilesAmount(unsigned ObjFilesNum)=0
Set estimated objects files amount, for preliminary data allocation.
virtual void setKeepFunctionForStatic(bool KeepFunctionForStatic)=0
Set whether to keep the enclosing function for a static variable.
virtual void setSwiftInterfacesMap(SwiftInterfacesMapTy *Map)=0
Set map for Swift interfaces.
function_ref< void(const DWARFUnit &Unit)> CompileUnitHandlerTy
virtual Error link()=0
Link the debug info for all object files added through calls to addObjectFile.
std::function< void( const Twine &Warning, StringRef Context, const DWARFDie *DIE)> MessageHandlerTy
virtual void setObjectPrefixMap(ObjectPrefixMapTy *Map)=0
Set prefix map for objects.
virtual void addAccelTableKind(AccelTableKind Kind)=0
Add kind of accelerator tables to be generated.
virtual void setVerbosity(bool Verbose)=0
A number of methods setting various linking options: Enable logging to standard output.
virtual Error setTargetDWARFVersion(uint16_t TargetDWARFVersion)=0
Set target DWARF version.
AccelTableKind
The kind of accelerator tables to be emitted.
@ Apple
.apple_names, .apple_namespaces, .apple_types, .apple_objc.
virtual void setVerifyInputDWARF(bool Verify)=0
Verify the input DWARF.
virtual void setUpdateIndexTablesOnly(bool Update)=0
Update index tables only (do not modify rest of DWARF).
virtual void setStatistics(bool Statistics)=0
Print statistics to standard output.
std::map< std::string, std::string > SwiftInterfacesMapTy
std::function< ErrorOr< DWARFFile & >( StringRef ContainerName, StringRef Path)> ObjFileLoaderTy
std::function< void(const DWARFFile &File, llvm::StringRef Output)> InputVerificationHandlerTy
virtual void setPrependPath(StringRef Ppath)=0
Set prepend path for clang modules.
virtual void setInputVerificationHandler(InputVerificationHandlerTy Handler)=0
Set verification handler used to report verification errors.
virtual void setNoODR(bool NoODR)=0
Do not unique types according to ODR.
An efficient, type-erasing, non-owning reference to a callable.
static constexpr StringLiteral SectionNames[SectionKindsNum]
LLVM_ABI std::optional< DebugSectionKind > parseDebugTableName(StringRef Name)
Recognise the table name and match it with the DebugSectionKind.
static constexpr const StringLiteral & getSectionName(DebugSectionKind SectionKind)
Return the name of the section.
DebugSectionKind
List of tracked debug tables.
static constexpr size_t SectionKindsNum
This is an optimization pass for GlobalISel generic memory operations.