Skip to content

Commit 1610d41

Browse files
authored
[llvm] annotate interfaces in llvm/DWARFLinker and llvm/DWP for DLL export (#140782)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/DWARFLinker` and `llvm/DWP` libraries. These annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build. ## Background This effort is tracked in #109483. Additional context is provided in [this discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307), and documentation for `LLVM_ABI` and related annotations is found in the LLVM repo [here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst). These changes were generated automatically using the [Interface Definition Scanner (IDS)](https://github.com/compnerd/ids) tool, followed formatting with `git clang-format`. ## Validation Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: - Windows with MSVC - Windows with Clang - Linux with GCC - Linux with Clang - Darwin with Clang
1 parent 63385e7 commit 1610d41

File tree

7 files changed

+66
-49
lines changed

7 files changed

+66
-49
lines changed

llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
2222
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
2323
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
24+
#include "llvm/Support/Compiler.h"
2425
#include <map>
2526

2627
namespace llvm {
@@ -211,7 +212,7 @@ using UnitListTy = std::vector<std::unique_ptr<CompileUnit>>;
211212
/// a variable). These relocations are called ValidRelocs in the
212213
/// AddressesInfo and are gathered as a very first step when we start
213214
/// processing a object file.
214-
class DWARFLinker : public DWARFLinkerBase {
215+
class LLVM_ABI DWARFLinker : public DWARFLinkerBase {
215216
public:
216217
DWARFLinker(MessageHandlerTy ErrorHandler, MessageHandlerTy WarningHandler,
217218
std::function<StringRef(StringRef)> StringsTranslator)
@@ -586,28 +587,31 @@ class DWARFLinker : public DWARFLinkerBase {
586587
/// applied to the entry point of the function to get the linked address.
587588
/// \param Die the output DIE to use, pass NULL to create one.
588589
/// \returns the root of the cloned tree or null if nothing was selected.
589-
DIE *cloneDIE(const DWARFDie &InputDIE, const DWARFFile &File,
590-
CompileUnit &U, int64_t PCOffset, uint32_t OutOffset,
591-
unsigned Flags, bool IsLittleEndian, DIE *Die = nullptr);
590+
LLVM_ABI DIE *cloneDIE(const DWARFDie &InputDIE, const DWARFFile &File,
591+
CompileUnit &U, int64_t PCOffset, uint32_t OutOffset,
592+
unsigned Flags, bool IsLittleEndian,
593+
DIE *Die = nullptr);
592594

593595
/// Construct the output DIE tree by cloning the DIEs we
594596
/// chose to keep above. If there are no valid relocs, then there's
595597
/// nothing to clone/emit.
596-
uint64_t cloneAllCompileUnits(DWARFContext &DwarfContext,
597-
const DWARFFile &File, bool IsLittleEndian);
598+
LLVM_ABI uint64_t cloneAllCompileUnits(DWARFContext &DwarfContext,
599+
const DWARFFile &File,
600+
bool IsLittleEndian);
598601

599602
/// Emit the .debug_addr section for the \p Unit.
600-
void emitDebugAddrSection(CompileUnit &Unit,
601-
const uint16_t DwarfVersion) const;
603+
LLVM_ABI void emitDebugAddrSection(CompileUnit &Unit,
604+
const uint16_t DwarfVersion) const;
602605

603606
using ExpressionHandlerRef = function_ref<void(
604607
SmallVectorImpl<uint8_t> &, SmallVectorImpl<uint8_t> &,
605608
int64_t AddrRelocAdjustment)>;
606609

607610
/// Compute and emit debug locations (.debug_loc, .debug_loclists)
608611
/// for \p Unit, patch the attributes referencing it.
609-
void generateUnitLocations(CompileUnit &Unit, const DWARFFile &File,
610-
ExpressionHandlerRef ExprHandler);
612+
LLVM_ABI void generateUnitLocations(CompileUnit &Unit,
613+
const DWARFFile &File,
614+
ExpressionHandlerRef ExprHandler);
611615

612616
private:
613617
using AttributeSpec = DWARFAbbreviationDeclaration::AttributeSpec;

llvm/include/llvm/DWARFLinker/Classic/DWARFLinkerCompileUnit.h

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "llvm/ADT/DenseMap.h"
1414
#include "llvm/CodeGen/DIE.h"
1515
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
16+
#include "llvm/Support/Compiler.h"
1617
#include <optional>
1718

1819
namespace llvm {
@@ -142,9 +143,9 @@ class CompileUnit {
142143

143144
bool hasODR() const { return HasODR; }
144145
bool isClangModule() const { return !ClangModuleName.empty(); }
145-
uint16_t getLanguage();
146+
LLVM_ABI uint16_t getLanguage();
146147
/// Return the DW_AT_LLVM_sysroot of the compile unit or an empty StringRef.
147-
StringRef getSysRoot();
148+
LLVM_ABI StringRef getSysRoot();
148149

149150
const std::string &getClangModuleName() const { return ClangModuleName; }
150151

@@ -185,60 +186,62 @@ class CompileUnit {
185186
/// Mark every DIE in this unit as kept. This function also
186187
/// marks variables as InDebugMap so that they appear in the
187188
/// reconstructed accelerator tables.
188-
void markEverythingAsKept();
189+
LLVM_ABI void markEverythingAsKept();
189190

190191
/// Compute the end offset for this unit. Must be called after the CU's DIEs
191192
/// have been cloned. \returns the next unit offset (which is also the
192193
/// current debug_info section size).
193-
uint64_t computeNextUnitOffset(uint16_t DwarfVersion);
194+
LLVM_ABI uint64_t computeNextUnitOffset(uint16_t DwarfVersion);
194195

195196
/// Keep track of a forward reference to DIE \p Die in \p RefUnit by \p
196197
/// Attr. The attribute should be fixed up later to point to the absolute
197198
/// offset of \p Die in the debug_info section or to the canonical offset of
198199
/// \p Ctxt if it is non-null.
199-
void noteForwardReference(DIE *Die, const CompileUnit *RefUnit,
200-
DeclContext *Ctxt, PatchLocation Attr);
200+
LLVM_ABI void noteForwardReference(DIE *Die, const CompileUnit *RefUnit,
201+
DeclContext *Ctxt, PatchLocation Attr);
201202

202203
/// Apply all fixups recorded by noteForwardReference().
203-
void fixupForwardReferences();
204+
LLVM_ABI void fixupForwardReferences();
204205

205206
/// Add the low_pc of a label that is relocated by applying
206207
/// offset \p PCOffset.
207-
void addLabelLowPc(uint64_t LabelLowPc, int64_t PcOffset);
208+
LLVM_ABI void addLabelLowPc(uint64_t LabelLowPc, int64_t PcOffset);
208209

209210
/// Add a function range [\p LowPC, \p HighPC) that is relocated by applying
210211
/// offset \p PCOffset.
211-
void addFunctionRange(uint64_t LowPC, uint64_t HighPC, int64_t PCOffset);
212+
LLVM_ABI void addFunctionRange(uint64_t LowPC, uint64_t HighPC,
213+
int64_t PCOffset);
212214

213215
/// Keep track of a DW_AT_range attribute that we will need to patch up later.
214-
void noteRangeAttribute(const DIE &Die, PatchLocation Attr);
216+
LLVM_ABI void noteRangeAttribute(const DIE &Die, PatchLocation Attr);
215217

216218
/// Keep track of a location attribute pointing to a location list in the
217219
/// debug_loc section.
218-
void noteLocationAttribute(PatchLocation Attr);
220+
LLVM_ABI void noteLocationAttribute(PatchLocation Attr);
219221

220222
// Record that the given DW_AT_LLVM_stmt_sequence attribute may need to be
221223
// patched later.
222-
void noteStmtSeqListAttribute(PatchLocation Attr);
224+
LLVM_ABI void noteStmtSeqListAttribute(PatchLocation Attr);
223225

224226
/// Add a name accelerator entry for \a Die with \a Name.
225-
void addNamespaceAccelerator(const DIE *Die, DwarfStringPoolEntryRef Name);
227+
LLVM_ABI void addNamespaceAccelerator(const DIE *Die,
228+
DwarfStringPoolEntryRef Name);
226229

227230
/// Add a name accelerator entry for \a Die with \a Name.
228-
void addNameAccelerator(const DIE *Die, DwarfStringPoolEntryRef Name,
229-
bool SkipPubnamesSection = false);
231+
LLVM_ABI void addNameAccelerator(const DIE *Die, DwarfStringPoolEntryRef Name,
232+
bool SkipPubnamesSection = false);
230233

231234
/// Add various accelerator entries for \p Die with \p Name which is stored
232235
/// in the string table at \p Offset. \p Name must be an Objective-C
233236
/// selector.
234-
void addObjCAccelerator(const DIE *Die, DwarfStringPoolEntryRef Name,
235-
bool SkipPubnamesSection = false);
237+
LLVM_ABI void addObjCAccelerator(const DIE *Die, DwarfStringPoolEntryRef Name,
238+
bool SkipPubnamesSection = false);
236239

237240
/// Add a type accelerator entry for \p Die with \p Name which is stored in
238241
/// the string table at \p Offset.
239-
void addTypeAccelerator(const DIE *Die, DwarfStringPoolEntryRef Name,
240-
bool ObjcClassImplementation,
241-
uint32_t QualifiedNameHash);
242+
LLVM_ABI void addTypeAccelerator(const DIE *Die, DwarfStringPoolEntryRef Name,
243+
bool ObjcClassImplementation,
244+
uint32_t QualifiedNameHash);
242245

243246
struct AccelInfo {
244247
/// Name of the entry.

llvm/include/llvm/DWARFLinker/Classic/DWARFStreamer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/MC/MCObjectFileInfo.h"
1919
#include "llvm/MC/MCRegisterInfo.h"
2020
#include "llvm/MC/MCSubtargetInfo.h"
21+
#include "llvm/Support/Compiler.h"
2122
#include "llvm/Target/TargetMachine.h"
2223

2324
namespace llvm {
@@ -41,7 +42,7 @@ namespace classic {
4142
///
4243
/// All interactions with the MC layer that is used to build the debug
4344
/// information binary representation are handled in this class.
44-
class DwarfStreamer : public DwarfEmitter {
45+
class LLVM_ABI DwarfStreamer : public DwarfEmitter {
4546
public:
4647
DwarfStreamer(DWARFLinkerBase::OutputFileType OutFileType,
4748
raw_pwrite_stream &OutFile,

llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
1818
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
1919
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
20+
#include "llvm/Support/Compiler.h"
2021
#include <map>
2122
namespace llvm {
2223
class DWARFUnit;
@@ -68,7 +69,7 @@ getSectionName(DebugSectionKind SectionKind) {
6869
}
6970

7071
/// Recognise the table name and match it with the DebugSectionKind.
71-
std::optional<DebugSectionKind> parseDebugTableName(StringRef Name);
72+
LLVM_ABI std::optional<DebugSectionKind> parseDebugTableName(StringRef Name);
7273

7374
/// The base interface for DWARFLinker implementations.
7475
class DWARFLinkerBase {

llvm/include/llvm/DWARFLinker/Parallel/DWARFLinker.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
1616
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
1717
#include "llvm/MC/MCDwarf.h"
18+
#include "llvm/Support/Compiler.h"
1819
#include "llvm/TargetParser/Triple.h"
1920

2021
/// ------------------------------------------------------------------
@@ -122,7 +123,7 @@ class DWARFLinker : public DWARFLinkerBase {
122123
virtual ~DWARFLinker() = default;
123124

124125
/// Creates dwarf linker instance.
125-
static std::unique_ptr<DWARFLinker>
126+
LLVM_ABI static std::unique_ptr<DWARFLinker>
126127
createLinker(MessageHandlerTy ErrorHandler, MessageHandlerTy WarningHandler);
127128

128129
/// Set output DWARF handler. Result of linking DWARF is set of sections

llvm/include/llvm/DWP/DWP.h

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "llvm/MC/MCSection.h"
1111
#include "llvm/MC/MCStreamer.h"
1212
#include "llvm/Object/ObjectFile.h"
13+
#include "llvm/Support/Compiler.h"
1314
#include "llvm/Support/Error.h"
1415
#include <deque>
1516
#include <vector>
@@ -66,12 +67,13 @@ struct CompileUnitIdentifiers {
6667
const char *DWOName = "";
6768
};
6869

69-
Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
70-
OnCuIndexOverflow OverflowOptValue);
70+
LLVM_ABI Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
71+
OnCuIndexOverflow OverflowOptValue);
7172

72-
unsigned getContributionIndex(DWARFSectionKind Kind, uint32_t IndexVersion);
73+
LLVM_ABI unsigned getContributionIndex(DWARFSectionKind Kind,
74+
uint32_t IndexVersion);
7375

74-
Error handleSection(
76+
LLVM_ABI Error handleSection(
7577
const StringMap<std::pair<MCSection *, DWARFSectionKind>> &KnownSections,
7678
const MCSection *StrSection, const MCSection *StrOffsetSection,
7779
const MCSection *TypesSection, const MCSection *CUIndexSection,
@@ -85,20 +87,24 @@ Error handleSection(
8587
StringRef &CurCUIndexSection, StringRef &CurTUIndexSection,
8688
std::vector<std::pair<DWARFSectionKind, uint32_t>> &SectionLength);
8789

88-
Expected<InfoSectionUnitHeader> parseInfoSectionUnitHeader(StringRef Info);
90+
LLVM_ABI Expected<InfoSectionUnitHeader>
91+
parseInfoSectionUnitHeader(StringRef Info);
8992

90-
void writeStringsAndOffsets(MCStreamer &Out, DWPStringPool &Strings,
91-
MCSection *StrOffsetSection,
92-
StringRef CurStrSection,
93-
StringRef CurStrOffsetSection, uint16_t Version);
93+
LLVM_ABI void writeStringsAndOffsets(MCStreamer &Out, DWPStringPool &Strings,
94+
MCSection *StrOffsetSection,
95+
StringRef CurStrSection,
96+
StringRef CurStrOffsetSection,
97+
uint16_t Version);
9498

95-
Error buildDuplicateError(const std::pair<uint64_t, UnitIndexEntry> &PrevE,
96-
const CompileUnitIdentifiers &ID, StringRef DWPName);
99+
LLVM_ABI Error
100+
buildDuplicateError(const std::pair<uint64_t, UnitIndexEntry> &PrevE,
101+
const CompileUnitIdentifiers &ID, StringRef DWPName);
97102

98-
void writeIndex(MCStreamer &Out, MCSection *Section,
99-
ArrayRef<unsigned> ContributionOffsets,
100-
const MapVector<uint64_t, UnitIndexEntry> &IndexEntries,
101-
uint32_t IndexVersion);
103+
LLVM_ABI void
104+
writeIndex(MCStreamer &Out, MCSection *Section,
105+
ArrayRef<unsigned> ContributionOffsets,
106+
const MapVector<uint64_t, UnitIndexEntry> &IndexEntries,
107+
uint32_t IndexVersion);
102108

103109
} // namespace llvm
104110
#endif // LLVM_DWP_DWP_H

llvm/include/llvm/DWP/DWPError.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef LLVM_DWP_DWPERROR_H
22
#define LLVM_DWP_DWPERROR_H
33

4+
#include "llvm/Support/Compiler.h"
45
#include "llvm/Support/Error.h"
56
#include "llvm/Support/ErrorHandling.h"
67
#include <string>
@@ -13,7 +14,7 @@ class DWPError : public ErrorInfo<DWPError> {
1314
std::error_code convertToErrorCode() const override {
1415
llvm_unreachable("Not implemented");
1516
}
16-
static char ID;
17+
LLVM_ABI static char ID;
1718

1819
private:
1920
std::string Info;

0 commit comments

Comments
 (0)