Skip to content

[llvm] annotate interfaces in llvm/TextAPI for DLL export #143447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions llvm/include/llvm/TextAPI/Architecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef LLVM_TEXTAPI_ARCHITECTURE_H
#define LLVM_TEXTAPI_ARCHITECTURE_H

#include "llvm/Support/Compiler.h"
#include <cstdint>
#include <utility>

Expand All @@ -32,24 +33,26 @@ enum Architecture : uint8_t {
};

/// Convert a CPU Type and Subtype pair to an architecture slice.
Architecture getArchitectureFromCpuType(uint32_t CPUType, uint32_t CPUSubType);
LLVM_ABI Architecture getArchitectureFromCpuType(uint32_t CPUType,
uint32_t CPUSubType);

/// Convert a name to an architecture slice.
Architecture getArchitectureFromName(StringRef Name);
LLVM_ABI Architecture getArchitectureFromName(StringRef Name);

/// Convert an architecture slice to a string.
StringRef getArchitectureName(Architecture Arch);
LLVM_ABI StringRef getArchitectureName(Architecture Arch);

/// Convert an architecture slice to a CPU Type and Subtype pair.
std::pair<uint32_t, uint32_t> getCPUTypeFromArchitecture(Architecture Arch);
LLVM_ABI std::pair<uint32_t, uint32_t>
getCPUTypeFromArchitecture(Architecture Arch);

/// Convert a target to an architecture slice.
Architecture mapToArchitecture(const llvm::Triple &Target);
LLVM_ABI Architecture mapToArchitecture(const llvm::Triple &Target);

/// Check if architecture is 64 bit.
bool is64Bit(Architecture);
LLVM_ABI bool is64Bit(Architecture);

raw_ostream &operator<<(raw_ostream &OS, Architecture Arch);
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, Architecture Arch);

} // end namespace MachO.
} // end namespace llvm.
Expand Down
13 changes: 7 additions & 6 deletions llvm/include/llvm/TextAPI/ArchitectureSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef LLVM_TEXTAPI_ARCHITECTURESET_H
#define LLVM_TEXTAPI_ARCHITECTURESET_H

#include "llvm/Support/Compiler.h"
#include "llvm/TextAPI/Architecture.h"
#include <cstddef>
#include <iterator>
Expand All @@ -38,7 +39,7 @@ class ArchitectureSet {
constexpr ArchitectureSet() = default;
constexpr ArchitectureSet(ArchSetType Raw) : ArchSet(Raw) {}
ArchitectureSet(Architecture Arch) : ArchitectureSet() { set(Arch); }
ArchitectureSet(const std::vector<Architecture> &Archs);
LLVM_ABI ArchitectureSet(const std::vector<Architecture> &Archs);

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

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

size_t count() const;
LLVM_ABI size_t count() const;

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

Expand Down Expand Up @@ -158,17 +159,17 @@ class ArchitectureSet {
const_iterator begin() const { return {&ArchSet}; }
const_iterator end() const { return {&ArchSet, EndIndexVal}; }

operator std::string() const;
operator std::vector<Architecture>() const;
void print(raw_ostream &OS) const;
LLVM_ABI operator std::string() const;
LLVM_ABI operator std::vector<Architecture>() const;
LLVM_ABI void print(raw_ostream &OS) const;
};

inline ArchitectureSet operator|(const Architecture &lhs,
const Architecture &rhs) {
return ArchitectureSet(lhs) | ArchitectureSet(rhs);
}

raw_ostream &operator<<(raw_ostream &OS, ArchitectureSet Set);
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, ArchitectureSet Set);

} // end namespace MachO.
} // end namespace llvm.
Expand Down
10 changes: 6 additions & 4 deletions llvm/include/llvm/TextAPI/DylibReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define LLVM_TEXTAPI_DYLIBREADER_H

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

/// Get TAPI file representation of binary dylib.
///
/// \param Buffer Data that points to dylib.
Expected<std::unique_ptr<InterfaceFile>> get(MemoryBufferRef Buffer);
LLVM_ABI Expected<std::unique_ptr<InterfaceFile>> get(MemoryBufferRef Buffer);

using SymbolToSourceLocMap = llvm::StringMap<RecordLoc>;
/// Get the source location for each symbol from dylib.
///
/// \param DSYM Path to DSYM file.
/// \param T Requested target slice for dylib.
SymbolToSourceLocMap accumulateSourceLocFromDSYM(const StringRef DSYM,
const Target &T);
LLVM_ABI SymbolToSourceLocMap accumulateSourceLocFromDSYM(const StringRef DSYM,
const Target &T);

} // namespace llvm::MachO::DylibReader

Expand Down
34 changes: 18 additions & 16 deletions llvm/include/llvm/TextAPI/InterfaceFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Compiler.h"
#include "llvm/TextAPI/ArchitectureSet.h"
#include "llvm/TextAPI/FileTypes.h"
#include "llvm/TextAPI/PackedVersion.h"
Expand Down Expand Up @@ -60,7 +61,7 @@ class InterfaceFileRef {

StringRef getInstallName() const { return InstallName; };

void addTarget(const Target &Target);
LLVM_ABI void addTarget(const Target &Target);
template <typename RangeT> void addTargets(RangeT &&Targets) {
for (const auto &Target : Targets)
addTarget(Target(Target));
Expand Down Expand Up @@ -146,7 +147,7 @@ class InterfaceFile {
/// Set and add target.
///
/// \param Target the target to add into.
void addTarget(const Target &Target);
LLVM_ABI void addTarget(const Target &Target);

/// Determine if target triple slice exists in file.
///
Expand Down Expand Up @@ -174,7 +175,7 @@ class InterfaceFile {
std::function<bool(const Target &)>>;
using const_filtered_target_range =
llvm::iterator_range<const_filtered_target_iterator>;
const_filtered_target_range targets(ArchitectureSet Archs) const;
LLVM_ABI const_filtered_target_range targets(ArchitectureSet Archs) const;

/// Set the install name of the library.
void setInstallName(StringRef InstallName_) {
Expand Down Expand Up @@ -241,7 +242,7 @@ class InterfaceFile {
/// Set the parent umbrella frameworks.
/// \param Target_ The target applicable to Parent
/// \param Parent The name of Parent
void addParentUmbrella(const Target &Target_, StringRef Parent);
LLVM_ABI void addParentUmbrella(const Target &Target_, StringRef Parent);

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

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

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

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

/// Get the list of runpath search paths.
///
Expand Down Expand Up @@ -373,14 +375,14 @@ class InterfaceFile {
///
/// \param Arch architecture to extract from.
/// \return New InterfaceFile with extracted architecture slice.
llvm::Expected<std::unique_ptr<InterfaceFile>>
LLVM_ABI llvm::Expected<std::unique_ptr<InterfaceFile>>
extract(Architecture Arch) const;

/// Remove architecture slice from Interface.
///
/// \param Arch architecture to remove.
/// \return New Interface File with removed architecture slice.
llvm::Expected<std::unique_ptr<InterfaceFile>>
LLVM_ABI llvm::Expected<std::unique_ptr<InterfaceFile>>
remove(Architecture Arch) const;

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

/// Inline reexported library into Interface.
///
/// \param Library Interface of reexported library.
/// \param Overwrite Whether to overwrite preexisting inlined library.
void inlineLibrary(std::shared_ptr<InterfaceFile> Library,
bool Overwrite = false);
LLVM_ABI void inlineLibrary(std::shared_ptr<InterfaceFile> Library,
bool Overwrite = false);

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

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

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

Expand Down
9 changes: 5 additions & 4 deletions llvm/include/llvm/TextAPI/PackedVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef LLVM_TEXTAPI_PACKEDVERSION_H
#define LLVM_TEXTAPI_PACKEDVERSION_H

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

bool parse32(StringRef Str);
std::pair<bool, bool> parse64(StringRef Str);
LLVM_ABI bool parse32(StringRef Str);
LLVM_ABI std::pair<bool, bool> parse64(StringRef Str);

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

Expand All @@ -64,9 +65,9 @@ class PackedVersion {

uint32_t rawValue() const { return Version; }

operator std::string() const;
LLVM_ABI operator std::string() const;

void print(raw_ostream &OS) const;
LLVM_ABI void print(raw_ostream &OS) const;
};

inline raw_ostream &operator<<(raw_ostream &OS, const PackedVersion &Version) {
Expand Down
17 changes: 9 additions & 8 deletions llvm/include/llvm/TextAPI/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "llvm/ADT/SmallSet.h"
#include "llvm/BinaryFormat/MachO.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/VersionTuple.h"

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

PlatformType mapToPlatformType(PlatformType Platform, bool WantSim);
PlatformType mapToPlatformType(const Triple &Target);
PlatformSet mapToPlatformSet(ArrayRef<Triple> Targets);
StringRef getPlatformName(PlatformType Platform);
PlatformType getPlatformFromName(StringRef Name);
std::string getOSAndEnvironmentName(PlatformType Platform,
std::string Version = "");
VersionTuple mapToSupportedOSVersion(const Triple &Triple);
LLVM_ABI PlatformType mapToPlatformType(PlatformType Platform, bool WantSim);
LLVM_ABI PlatformType mapToPlatformType(const Triple &Target);
LLVM_ABI PlatformSet mapToPlatformSet(ArrayRef<Triple> Targets);
LLVM_ABI StringRef getPlatformName(PlatformType Platform);
LLVM_ABI PlatformType getPlatformFromName(StringRef Name);
LLVM_ABI std::string getOSAndEnvironmentName(PlatformType Platform,
std::string Version = "");
LLVM_ABI VersionTuple mapToSupportedOSVersion(const Triple &Triple);

} // end namespace MachO.
} // end namespace llvm.
Expand Down
18 changes: 10 additions & 8 deletions llvm/include/llvm/TextAPI/Record.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/TextAPI/Symbol.h"
#include <string>

Expand Down Expand Up @@ -104,7 +105,7 @@ class Record {
SymbolFlags getFlags() const { return Flags; }

private:
SymbolFlags mergeFlags(SymbolFlags Flags, RecordLinkage Linkage);
LLVM_ABI SymbolFlags mergeFlags(SymbolFlags Flags, RecordLinkage Linkage);

protected:
StringRef Name;
Expand Down Expand Up @@ -164,9 +165,9 @@ class ObjCContainerRecord : public Record {
ObjCContainerRecord(StringRef Name, RecordLinkage Linkage)
: Record({Name, Linkage, SymbolFlags::Data}) {}

ObjCIVarRecord *addObjCIVar(StringRef IVar, RecordLinkage Linkage);
ObjCIVarRecord *findObjCIVar(StringRef IVar) const;
std::vector<ObjCIVarRecord *> getObjCIVars() const;
LLVM_ABI ObjCIVarRecord *addObjCIVar(StringRef IVar, RecordLinkage Linkage);
LLVM_ABI ObjCIVarRecord *findObjCIVar(StringRef IVar) const;
LLVM_ABI std::vector<ObjCIVarRecord *> getObjCIVars() const;
RecordLinkage getLinkage() const { return Linkage; }

private:
Expand Down Expand Up @@ -207,11 +208,12 @@ class ObjCInterfaceRecord : public ObjCContainerRecord {
return getLinkageForSymbol(CurrType) >= RecordLinkage::Rexported;
}

RecordLinkage getLinkageForSymbol(ObjCIFSymbolKind CurrType) const;
void updateLinkageForSymbols(ObjCIFSymbolKind SymType, RecordLinkage Link);
LLVM_ABI RecordLinkage getLinkageForSymbol(ObjCIFSymbolKind CurrType) const;
LLVM_ABI void updateLinkageForSymbols(ObjCIFSymbolKind SymType,
RecordLinkage Link);

bool addObjCCategory(ObjCCategoryRecord *Record);
std::vector<ObjCCategoryRecord *> getObjCCategories() const;
LLVM_ABI bool addObjCCategory(ObjCCategoryRecord *Record);
LLVM_ABI std::vector<ObjCCategoryRecord *> getObjCCategories() const;

private:
/// Linkage level for each symbol represented in ObjCInterfaceRecord.
Expand Down
5 changes: 3 additions & 2 deletions llvm/include/llvm/TextAPI/RecordVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
#ifndef LLVM_TEXTAPI_RECORDVISITOR_H
#define LLVM_TEXTAPI_RECORDVISITOR_H

#include "llvm/Support/Compiler.h"
#include "llvm/TextAPI/Record.h"
#include "llvm/TextAPI/SymbolSet.h"

namespace llvm {
namespace MachO {

/// Base class for any usage of traversing over collected Records.
class RecordVisitor {
class LLVM_ABI RecordVisitor {
public:
virtual ~RecordVisitor();

Expand All @@ -32,7 +33,7 @@ class RecordVisitor {
/// Specialized RecordVisitor for collecting exported symbols
/// and undefined symbols if RecordSlice being visited represents a
/// flat-namespaced library.
class SymbolConverter : public RecordVisitor {
class LLVM_ABI SymbolConverter : public RecordVisitor {
public:
SymbolConverter(SymbolSet *Symbols, const Target &T,
const bool RecordUndefs = false)
Expand Down
Loading
Loading