Skip to content

Commit 2652d1b

Browse files
authored
[llvm] annotate interfaces in llvm/TextAPI for DLL export (#143447)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/TextAPI` library. 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 8f8ed23 commit 2652d1b

16 files changed

+138
-108
lines changed

llvm/include/llvm/TextAPI/Architecture.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_TEXTAPI_ARCHITECTURE_H
1414
#define LLVM_TEXTAPI_ARCHITECTURE_H
1515

16+
#include "llvm/Support/Compiler.h"
1617
#include <cstdint>
1718
#include <utility>
1819

@@ -32,24 +33,26 @@ enum Architecture : uint8_t {
3233
};
3334

3435
/// Convert a CPU Type and Subtype pair to an architecture slice.
35-
Architecture getArchitectureFromCpuType(uint32_t CPUType, uint32_t CPUSubType);
36+
LLVM_ABI Architecture getArchitectureFromCpuType(uint32_t CPUType,
37+
uint32_t CPUSubType);
3638

3739
/// Convert a name to an architecture slice.
38-
Architecture getArchitectureFromName(StringRef Name);
40+
LLVM_ABI Architecture getArchitectureFromName(StringRef Name);
3941

4042
/// Convert an architecture slice to a string.
41-
StringRef getArchitectureName(Architecture Arch);
43+
LLVM_ABI StringRef getArchitectureName(Architecture Arch);
4244

4345
/// Convert an architecture slice to a CPU Type and Subtype pair.
44-
std::pair<uint32_t, uint32_t> getCPUTypeFromArchitecture(Architecture Arch);
46+
LLVM_ABI std::pair<uint32_t, uint32_t>
47+
getCPUTypeFromArchitecture(Architecture Arch);
4548

4649
/// Convert a target to an architecture slice.
47-
Architecture mapToArchitecture(const llvm::Triple &Target);
50+
LLVM_ABI Architecture mapToArchitecture(const llvm::Triple &Target);
4851

4952
/// Check if architecture is 64 bit.
50-
bool is64Bit(Architecture);
53+
LLVM_ABI bool is64Bit(Architecture);
5154

52-
raw_ostream &operator<<(raw_ostream &OS, Architecture Arch);
55+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, Architecture Arch);
5356

5457
} // end namespace MachO.
5558
} // end namespace llvm.

llvm/include/llvm/TextAPI/ArchitectureSet.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_TEXTAPI_ARCHITECTURESET_H
1414
#define LLVM_TEXTAPI_ARCHITECTURESET_H
1515

16+
#include "llvm/Support/Compiler.h"
1617
#include "llvm/TextAPI/Architecture.h"
1718
#include <cstddef>
1819
#include <iterator>
@@ -38,7 +39,7 @@ class ArchitectureSet {
3839
constexpr ArchitectureSet() = default;
3940
constexpr ArchitectureSet(ArchSetType Raw) : ArchSet(Raw) {}
4041
ArchitectureSet(Architecture Arch) : ArchitectureSet() { set(Arch); }
41-
ArchitectureSet(const std::vector<Architecture> &Archs);
42+
LLVM_ABI ArchitectureSet(const std::vector<Architecture> &Archs);
4243

4344
static ArchitectureSet All() { return ArchitectureSet(EndIndexVal); }
4445

@@ -61,7 +62,7 @@ class ArchitectureSet {
6162
return (ArchSet & Archs.ArchSet) == Archs.ArchSet;
6263
}
6364

64-
size_t count() const;
65+
LLVM_ABI size_t count() const;
6566

6667
bool empty() const { return ArchSet == 0; }
6768

@@ -158,17 +159,17 @@ class ArchitectureSet {
158159
const_iterator begin() const { return {&ArchSet}; }
159160
const_iterator end() const { return {&ArchSet, EndIndexVal}; }
160161

161-
operator std::string() const;
162-
operator std::vector<Architecture>() const;
163-
void print(raw_ostream &OS) const;
162+
LLVM_ABI operator std::string() const;
163+
LLVM_ABI operator std::vector<Architecture>() const;
164+
LLVM_ABI void print(raw_ostream &OS) const;
164165
};
165166

166167
inline ArchitectureSet operator|(const Architecture &lhs,
167168
const Architecture &rhs) {
168169
return ArchitectureSet(lhs) | ArchitectureSet(rhs);
169170
}
170171

171-
raw_ostream &operator<<(raw_ostream &OS, ArchitectureSet Set);
172+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, ArchitectureSet Set);
172173

173174
} // end namespace MachO.
174175
} // end namespace llvm.

llvm/include/llvm/TextAPI/DylibReader.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LLVM_TEXTAPI_DYLIBREADER_H
1515

1616
#include "llvm/ADT/StringMap.h"
17+
#include "llvm/Support/Compiler.h"
1718
#include "llvm/Support/Error.h"
1819
#include "llvm/Support/MemoryBuffer.h"
1920
#include "llvm/TextAPI/ArchitectureSet.h"
@@ -37,20 +38,21 @@ struct ParseOption {
3738
/// \param Buffer Data that points to dylib.
3839
/// \param Options Determines which attributes to extract.
3940
/// \return List of record slices.
40-
Expected<Records> readFile(MemoryBufferRef Buffer, const ParseOption &Opt);
41+
LLVM_ABI Expected<Records> readFile(MemoryBufferRef Buffer,
42+
const ParseOption &Opt);
4143

4244
/// Get TAPI file representation of binary dylib.
4345
///
4446
/// \param Buffer Data that points to dylib.
45-
Expected<std::unique_ptr<InterfaceFile>> get(MemoryBufferRef Buffer);
47+
LLVM_ABI Expected<std::unique_ptr<InterfaceFile>> get(MemoryBufferRef Buffer);
4648

4749
using SymbolToSourceLocMap = llvm::StringMap<RecordLoc>;
4850
/// Get the source location for each symbol from dylib.
4951
///
5052
/// \param DSYM Path to DSYM file.
5153
/// \param T Requested target slice for dylib.
52-
SymbolToSourceLocMap accumulateSourceLocFromDSYM(const StringRef DSYM,
53-
const Target &T);
54+
LLVM_ABI SymbolToSourceLocMap accumulateSourceLocFromDSYM(const StringRef DSYM,
55+
const Target &T);
5456

5557
} // namespace llvm::MachO::DylibReader
5658

llvm/include/llvm/TextAPI/InterfaceFile.h

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/ADT/StringRef.h"
1919
#include "llvm/ADT/iterator.h"
2020
#include "llvm/Support/Allocator.h"
21+
#include "llvm/Support/Compiler.h"
2122
#include "llvm/TextAPI/ArchitectureSet.h"
2223
#include "llvm/TextAPI/FileTypes.h"
2324
#include "llvm/TextAPI/PackedVersion.h"
@@ -60,7 +61,7 @@ class InterfaceFileRef {
6061

6162
StringRef getInstallName() const { return InstallName; };
6263

63-
void addTarget(const Target &Target);
64+
LLVM_ABI void addTarget(const Target &Target);
6465
template <typename RangeT> void addTargets(RangeT &&Targets) {
6566
for (const auto &Target : Targets)
6667
addTarget(Target(Target));
@@ -146,7 +147,7 @@ class InterfaceFile {
146147
/// Set and add target.
147148
///
148149
/// \param Target the target to add into.
149-
void addTarget(const Target &Target);
150+
LLVM_ABI void addTarget(const Target &Target);
150151

151152
/// Determine if target triple slice exists in file.
152153
///
@@ -174,7 +175,7 @@ class InterfaceFile {
174175
std::function<bool(const Target &)>>;
175176
using const_filtered_target_range =
176177
llvm::iterator_range<const_filtered_target_iterator>;
177-
const_filtered_target_range targets(ArchitectureSet Archs) const;
178+
LLVM_ABI const_filtered_target_range targets(ArchitectureSet Archs) const;
178179

179180
/// Set the install name of the library.
180181
void setInstallName(StringRef InstallName_) {
@@ -241,7 +242,7 @@ class InterfaceFile {
241242
/// Set the parent umbrella frameworks.
242243
/// \param Target_ The target applicable to Parent
243244
/// \param Parent The name of Parent
244-
void addParentUmbrella(const Target &Target_, StringRef Parent);
245+
LLVM_ABI void addParentUmbrella(const Target &Target_, StringRef Parent);
245246

246247
/// Get the list of Parent Umbrella frameworks.
247248
///
@@ -261,7 +262,7 @@ class InterfaceFile {
261262
/// \param InstallName The name of the client that is allowed to link this
262263
/// library.
263264
/// \param Target The target triple for which this applies.
264-
void addAllowableClient(StringRef InstallName, const Target &Target);
265+
LLVM_ABI void addAllowableClient(StringRef InstallName, const Target &Target);
265266

266267
/// Get the list of allowable clients.
267268
///
@@ -274,7 +275,8 @@ class InterfaceFile {
274275
///
275276
/// \param InstallName The name of the library to re-export.
276277
/// \param Target The target triple for which this applies.
277-
void addReexportedLibrary(StringRef InstallName, const Target &Target);
278+
LLVM_ABI void addReexportedLibrary(StringRef InstallName,
279+
const Target &Target);
278280

279281
/// Get the list of re-exported libraries.
280282
///
@@ -286,7 +288,7 @@ class InterfaceFile {
286288
/// Add a library for inlining to top level library.
287289
///
288290
///\param Document The library to inline with top level library.
289-
void addDocument(std::shared_ptr<InterfaceFile> &&Document);
291+
LLVM_ABI void addDocument(std::shared_ptr<InterfaceFile> &&Document);
290292

291293
/// Returns the pointer to parent document if exists or nullptr otherwise.
292294
InterfaceFile *getParent() const { return Parent; }
@@ -301,7 +303,7 @@ class InterfaceFile {
301303
/// Set the runpath search paths.
302304
/// \param RPath The name of runpath.
303305
/// \param InputTarget The target applicable to runpath search path.
304-
void addRPath(StringRef RPath, const Target &InputTarget);
306+
LLVM_ABI void addRPath(StringRef RPath, const Target &InputTarget);
305307

306308
/// Get the list of runpath search paths.
307309
///
@@ -373,14 +375,14 @@ class InterfaceFile {
373375
///
374376
/// \param Arch architecture to extract from.
375377
/// \return New InterfaceFile with extracted architecture slice.
376-
llvm::Expected<std::unique_ptr<InterfaceFile>>
378+
LLVM_ABI llvm::Expected<std::unique_ptr<InterfaceFile>>
377379
extract(Architecture Arch) const;
378380

379381
/// Remove architecture slice from Interface.
380382
///
381383
/// \param Arch architecture to remove.
382384
/// \return New Interface File with removed architecture slice.
383-
llvm::Expected<std::unique_ptr<InterfaceFile>>
385+
LLVM_ABI llvm::Expected<std::unique_ptr<InterfaceFile>>
384386
remove(Architecture Arch) const;
385387

386388
/// Merge Interfaces for the same library. The following library attributes
@@ -390,29 +392,29 @@ class InterfaceFile {
390392
///
391393
/// \param O The Interface to merge.
392394
/// \return New Interface File that was merged.
393-
llvm::Expected<std::unique_ptr<InterfaceFile>>
395+
LLVM_ABI llvm::Expected<std::unique_ptr<InterfaceFile>>
394396
merge(const InterfaceFile *O) const;
395397

396398
/// Inline reexported library into Interface.
397399
///
398400
/// \param Library Interface of reexported library.
399401
/// \param Overwrite Whether to overwrite preexisting inlined library.
400-
void inlineLibrary(std::shared_ptr<InterfaceFile> Library,
401-
bool Overwrite = false);
402+
LLVM_ABI void inlineLibrary(std::shared_ptr<InterfaceFile> Library,
403+
bool Overwrite = false);
402404

403405
/// Set InterfaceFile properties from pre-gathered binary attributes,
404406
/// if they are not set already.
405407
///
406408
/// \param BA Attributes typically represented in load commands.
407409
/// \param Targ MachO Target slice to add attributes to.
408-
void setFromBinaryAttrs(const RecordsSlice::BinaryAttrs &BA,
409-
const Target &Targ);
410+
LLVM_ABI void setFromBinaryAttrs(const RecordsSlice::BinaryAttrs &BA,
411+
const Target &Targ);
410412

411413
/// The equality is determined by attributes that impact linking
412414
/// compatibilities. Path, & FileKind are irrelevant since these by
413415
/// itself should not impact linking.
414416
/// This is an expensive operation.
415-
bool operator==(const InterfaceFile &O) const;
417+
LLVM_ABI bool operator==(const InterfaceFile &O) const;
416418

417419
bool operator!=(const InterfaceFile &O) const { return !(*this == O); }
418420

llvm/include/llvm/TextAPI/PackedVersion.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_TEXTAPI_PACKEDVERSION_H
1414
#define LLVM_TEXTAPI_PACKEDVERSION_H
1515

16+
#include "llvm/Support/Compiler.h"
1617
#include "llvm/Support/VersionTuple.h"
1718
#include <cstdint>
1819
#include <string>
@@ -53,8 +54,8 @@ class PackedVersion {
5354
/// Retrieve the subminor version number, if provided.
5455
unsigned getSubminor() const { return Version & 0xff; }
5556

56-
bool parse32(StringRef Str);
57-
std::pair<bool, bool> parse64(StringRef Str);
57+
LLVM_ABI bool parse32(StringRef Str);
58+
LLVM_ABI std::pair<bool, bool> parse64(StringRef Str);
5859

5960
bool operator<(const PackedVersion &O) const { return Version < O.Version; }
6061

@@ -64,9 +65,9 @@ class PackedVersion {
6465

6566
uint32_t rawValue() const { return Version; }
6667

67-
operator std::string() const;
68+
LLVM_ABI operator std::string() const;
6869

69-
void print(raw_ostream &OS) const;
70+
LLVM_ABI void print(raw_ostream &OS) const;
7071
};
7172

7273
inline raw_ostream &operator<<(raw_ostream &OS, const PackedVersion &Version) {

llvm/include/llvm/TextAPI/Platform.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "llvm/ADT/SmallSet.h"
1616
#include "llvm/BinaryFormat/MachO.h"
17+
#include "llvm/Support/Compiler.h"
1718
#include "llvm/Support/VersionTuple.h"
1819

1920
namespace llvm {
@@ -22,14 +23,14 @@ namespace MachO {
2223
using PlatformSet = SmallSet<PlatformType, 3>;
2324
using PlatformVersionSet = SmallSet<std::pair<PlatformType, VersionTuple>, 3>;
2425

25-
PlatformType mapToPlatformType(PlatformType Platform, bool WantSim);
26-
PlatformType mapToPlatformType(const Triple &Target);
27-
PlatformSet mapToPlatformSet(ArrayRef<Triple> Targets);
28-
StringRef getPlatformName(PlatformType Platform);
29-
PlatformType getPlatformFromName(StringRef Name);
30-
std::string getOSAndEnvironmentName(PlatformType Platform,
31-
std::string Version = "");
32-
VersionTuple mapToSupportedOSVersion(const Triple &Triple);
26+
LLVM_ABI PlatformType mapToPlatformType(PlatformType Platform, bool WantSim);
27+
LLVM_ABI PlatformType mapToPlatformType(const Triple &Target);
28+
LLVM_ABI PlatformSet mapToPlatformSet(ArrayRef<Triple> Targets);
29+
LLVM_ABI StringRef getPlatformName(PlatformType Platform);
30+
LLVM_ABI PlatformType getPlatformFromName(StringRef Name);
31+
LLVM_ABI std::string getOSAndEnvironmentName(PlatformType Platform,
32+
std::string Version = "");
33+
LLVM_ABI VersionTuple mapToSupportedOSVersion(const Triple &Triple);
3334

3435
} // end namespace MachO.
3536
} // end namespace llvm.

llvm/include/llvm/TextAPI/Record.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/ADT/MapVector.h"
1818
#include "llvm/ADT/StringRef.h"
1919
#include "llvm/Support/Casting.h"
20+
#include "llvm/Support/Compiler.h"
2021
#include "llvm/TextAPI/Symbol.h"
2122
#include <string>
2223

@@ -104,7 +105,7 @@ class Record {
104105
SymbolFlags getFlags() const { return Flags; }
105106

106107
private:
107-
SymbolFlags mergeFlags(SymbolFlags Flags, RecordLinkage Linkage);
108+
LLVM_ABI SymbolFlags mergeFlags(SymbolFlags Flags, RecordLinkage Linkage);
108109

109110
protected:
110111
StringRef Name;
@@ -164,9 +165,9 @@ class ObjCContainerRecord : public Record {
164165
ObjCContainerRecord(StringRef Name, RecordLinkage Linkage)
165166
: Record({Name, Linkage, SymbolFlags::Data}) {}
166167

167-
ObjCIVarRecord *addObjCIVar(StringRef IVar, RecordLinkage Linkage);
168-
ObjCIVarRecord *findObjCIVar(StringRef IVar) const;
169-
std::vector<ObjCIVarRecord *> getObjCIVars() const;
168+
LLVM_ABI ObjCIVarRecord *addObjCIVar(StringRef IVar, RecordLinkage Linkage);
169+
LLVM_ABI ObjCIVarRecord *findObjCIVar(StringRef IVar) const;
170+
LLVM_ABI std::vector<ObjCIVarRecord *> getObjCIVars() const;
170171
RecordLinkage getLinkage() const { return Linkage; }
171172

172173
private:
@@ -207,11 +208,12 @@ class ObjCInterfaceRecord : public ObjCContainerRecord {
207208
return getLinkageForSymbol(CurrType) >= RecordLinkage::Rexported;
208209
}
209210

210-
RecordLinkage getLinkageForSymbol(ObjCIFSymbolKind CurrType) const;
211-
void updateLinkageForSymbols(ObjCIFSymbolKind SymType, RecordLinkage Link);
211+
LLVM_ABI RecordLinkage getLinkageForSymbol(ObjCIFSymbolKind CurrType) const;
212+
LLVM_ABI void updateLinkageForSymbols(ObjCIFSymbolKind SymType,
213+
RecordLinkage Link);
212214

213-
bool addObjCCategory(ObjCCategoryRecord *Record);
214-
std::vector<ObjCCategoryRecord *> getObjCCategories() const;
215+
LLVM_ABI bool addObjCCategory(ObjCCategoryRecord *Record);
216+
LLVM_ABI std::vector<ObjCCategoryRecord *> getObjCCategories() const;
215217

216218
private:
217219
/// Linkage level for each symbol represented in ObjCInterfaceRecord.

llvm/include/llvm/TextAPI/RecordVisitor.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
#ifndef LLVM_TEXTAPI_RECORDVISITOR_H
1414
#define LLVM_TEXTAPI_RECORDVISITOR_H
1515

16+
#include "llvm/Support/Compiler.h"
1617
#include "llvm/TextAPI/Record.h"
1718
#include "llvm/TextAPI/SymbolSet.h"
1819

1920
namespace llvm {
2021
namespace MachO {
2122

2223
/// Base class for any usage of traversing over collected Records.
23-
class RecordVisitor {
24+
class LLVM_ABI RecordVisitor {
2425
public:
2526
virtual ~RecordVisitor();
2627

@@ -32,7 +33,7 @@ class RecordVisitor {
3233
/// Specialized RecordVisitor for collecting exported symbols
3334
/// and undefined symbols if RecordSlice being visited represents a
3435
/// flat-namespaced library.
35-
class SymbolConverter : public RecordVisitor {
36+
class LLVM_ABI SymbolConverter : public RecordVisitor {
3637
public:
3738
SymbolConverter(SymbolSet *Symbols, const Target &T,
3839
const bool RecordUndefs = false)

0 commit comments

Comments
 (0)