Skip to content

[llvm] support Windows DLL build of LLVM #11117

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

Open
wants to merge 6 commits into
base: stable/21.x
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions libcxxabi/src/demangle/DemangleConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,8 @@
#define DEMANGLE_NAMESPACE_BEGIN namespace { namespace itanium_demangle {
#define DEMANGLE_NAMESPACE_END } }

// The DEMANGLE_ABI macro resolves to nothing when building libc++abi. Only
// the llvm copy defines DEMANGLE_ABI as a visibility attribute.
#define DEMANGLE_ABI

#endif // LIBCXXABI_DEMANGLE_DEMANGLE_CONFIG_H
3 changes: 2 additions & 1 deletion libcxxabi/src/demangle/ItaniumDemangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -3049,7 +3049,8 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
Node *parse(bool ParseParams = true);
};

const char* parse_discriminator(const char* first, const char* last);
DEMANGLE_ABI const char *parse_discriminator(const char *first,
const char *last);

// <name> ::= <nested-name> // N
// ::= <local-name> # See Scope Encoding below // Z
Expand Down
30 changes: 15 additions & 15 deletions llvm/include/llvm/Analysis/IR2Vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,28 +164,28 @@ class Vocabulary {

public:
Vocabulary() = default;
Vocabulary(VocabVector &&Vocab);
LLVM_ABI Vocabulary(VocabVector &&Vocab);

bool isValid() const;
unsigned getDimension() const;
size_t size() const;
LLVM_ABI bool isValid() const;
LLVM_ABI unsigned getDimension() const;
LLVM_ABI size_t size() const;

/// Helper function to get vocabulary key for a given Opcode
static StringRef getVocabKeyForOpcode(unsigned Opcode);
LLVM_ABI static StringRef getVocabKeyForOpcode(unsigned Opcode);

/// Helper function to get vocabulary key for a given TypeID
static StringRef getVocabKeyForTypeID(Type::TypeID TypeID);
LLVM_ABI static StringRef getVocabKeyForTypeID(Type::TypeID TypeID);

/// Helper function to get vocabulary key for a given OperandKind
static StringRef getVocabKeyForOperandKind(OperandKind Kind);
LLVM_ABI static StringRef getVocabKeyForOperandKind(OperandKind Kind);

/// Helper function to classify an operand into OperandKind
static OperandKind getOperandKind(const Value *Op);
LLVM_ABI static OperandKind getOperandKind(const Value *Op);

/// Accessors to get the embedding for a given entity.
const ir2vec::Embedding &operator[](unsigned Opcode) const;
const ir2vec::Embedding &operator[](Type::TypeID TypeId) const;
const ir2vec::Embedding &operator[](const Value *Arg) const;
LLVM_ABI const ir2vec::Embedding &operator[](unsigned Opcode) const;
LLVM_ABI const ir2vec::Embedding &operator[](Type::TypeID TypeId) const;
LLVM_ABI const ir2vec::Embedding &operator[](const Value *Arg) const;

/// Const Iterator type aliases
using const_iterator = VocabVector::const_iterator;
Expand All @@ -212,13 +212,13 @@ class Vocabulary {
/// Returns the string key for a given index position in the vocabulary.
/// This is useful for debugging or printing the vocabulary. Do not use this
/// for embedding generation as string based lookups are inefficient.
static StringRef getStringKey(unsigned Pos);
LLVM_ABI static StringRef getStringKey(unsigned Pos);

/// Create a dummy vocabulary for testing purposes.
static VocabVector createDummyVocabForTest(unsigned Dim = 1);
LLVM_ABI static VocabVector createDummyVocabForTest(unsigned Dim = 1);

bool invalidate(Module &M, const PreservedAnalyses &PA,
ModuleAnalysisManager::Invalidator &Inv) const;
LLVM_ABI bool invalidate(Module &M, const PreservedAnalyses &PA,
ModuleAnalysisManager::Invalidator &Inv) const;
};

/// Embedder provides the interface to generate embeddings (vector
Expand Down
28 changes: 14 additions & 14 deletions llvm/include/llvm/CodeGen/GCMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ class GCFunctionInfo {
// are live per safe point (1.5% on 64-bit hosts).

public:
GCFunctionInfo(const Function &F, GCStrategy &S);
~GCFunctionInfo();
LLVM_ABI GCFunctionInfo(const Function &F, GCStrategy &S);
LLVM_ABI ~GCFunctionInfo();

/// Handle invalidation explicitly.
bool invalidate(Function &F, const PreservedAnalyses &PA,
FunctionAnalysisManager::Invalidator &Inv);
LLVM_ABI bool invalidate(Function &F, const PreservedAnalyses &PA,
FunctionAnalysisManager::Invalidator &Inv);

/// getFunction - Return the function to which this metadata applies.
const Function &getFunction() const { return F; }
Expand Down Expand Up @@ -163,8 +163,8 @@ class GCStrategyMap {
GCStrategyMap(GCStrategyMap &&) = default;

/// Handle invalidation explicitly.
bool invalidate(Module &M, const PreservedAnalyses &PA,
ModuleAnalysisManager::Invalidator &Inv);
LLVM_ABI bool invalidate(Module &M, const PreservedAnalyses &PA,
ModuleAnalysisManager::Invalidator &Inv);

using iterator = MapT::iterator;
using const_iterator = MapT::const_iterator;
Expand Down Expand Up @@ -205,7 +205,7 @@ class CollectorMetadataAnalysis

public:
using Result = GCStrategyMap;
Result run(Module &M, ModuleAnalysisManager &MAM);
LLVM_ABI Result run(Module &M, ModuleAnalysisManager &MAM);
};

/// An analysis pass which caches information about the Function.
Expand All @@ -217,7 +217,7 @@ class GCFunctionAnalysis : public AnalysisInfoMixin<GCFunctionAnalysis> {

public:
using Result = GCFunctionInfo;
Result run(Function &F, FunctionAnalysisManager &FAM);
LLVM_ABI Result run(Function &F, FunctionAnalysisManager &FAM);
};

/// LowerIntrinsics - This pass rewrites calls to the llvm.gcread or
Expand All @@ -228,7 +228,7 @@ class GCFunctionAnalysis : public AnalysisInfoMixin<GCFunctionAnalysis> {
/// This pass requires `CollectorMetadataAnalysis`.
class GCLoweringPass : public PassInfoMixin<GCLoweringPass> {
public:
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
};

/// An analysis pass which caches information about the entire Module.
Expand All @@ -244,7 +244,7 @@ class GCModuleInfo : public ImmutablePass {
/// Lookup the GCStrategy object associated with the given gc name.
/// Objects are owned internally; No caller should attempt to delete the
/// returned objects.
GCStrategy *getGCStrategy(const StringRef Name);
LLVM_ABI GCStrategy *getGCStrategy(const StringRef Name);

/// List of per function info objects. In theory, Each of these
/// may be associated with a different GC.
Expand All @@ -265,14 +265,14 @@ class GCModuleInfo : public ImmutablePass {
public:
using iterator = SmallVector<std::unique_ptr<GCStrategy>, 1>::const_iterator;

static char ID;
LLVM_ABI static char ID;

GCModuleInfo();
LLVM_ABI GCModuleInfo();

/// clear - Resets the pass. Any pass, which uses GCModuleInfo, should
/// call it in doFinalization().
///
void clear();
LLVM_ABI void clear();

/// begin/end - Iterators for used strategies.
///
Expand All @@ -282,7 +282,7 @@ class GCModuleInfo : public ImmutablePass {
/// get - Look up function metadata. This is currently assumed
/// have the side effect of initializing the associated GCStrategy. That
/// will soon change.
GCFunctionInfo &getFunctionInfo(const Function &F);
LLVM_ABI GCFunctionInfo &getFunctionInfo(const Function &F);
};

} // end namespace llvm
Expand Down
33 changes: 31 additions & 2 deletions llvm/include/llvm/Config/abi-breaking.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,41 @@
#ifndef LLVM_ABI_BREAKING_CHECKS_H
#define LLVM_ABI_BREAKING_CHECKS_H

// llvm-config.h is required for LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS
#include "llvm/Config/llvm-config.h"

/* Define to enable checks that alter the LLVM C++ ABI */
#cmakedefine01 LLVM_ENABLE_ABI_BREAKING_CHECKS

/* Define to enable reverse iteration of unordered llvm containers */
#cmakedefine01 LLVM_ENABLE_REVERSE_ITERATION

#if !defined(__has_attribute)
#define __has_attribute(attribute) 0
#endif

// Properly annotate EnableABIBreakingChecks or DisableABIBreakingChecks for
// export from shared library.
// TODO(https://github.com/llvm/llvm-project/issues/145406): eliminate need for
// two preprocessor definitions to gate LLVM_ABI macro definitions.
#if defined(LLVM_BUILD_STATIC) || !defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS)
#define ABI_BREAKING_EXPORT_ABI
#else
#if defined(_WIN32)
#if defined(LLVM_EXPORTS)
#define ABI_BREAKING_EXPORT_ABI __declspec(dllexport)
#else
#define ABI_BREAKING_EXPORT_ABI __declspec(dllimport)
#endif
#else
#if __has_attribute(visibility)
#define ABI_BREAKING_EXPORT_ABI __attribute__((__visibility__("default")))
#else
#define ABI_BREAKING_EXPORT_ABI
#endif
#endif
#endif

/* Allow selectively disabling link-time mismatch checking so that header-only
ADT content from LLVM can be used without linking libSupport. */
#if !defined(LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING) || !LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING
Expand All @@ -43,12 +72,12 @@
#endif
namespace llvm {
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
extern int EnableABIBreakingChecks;
ABI_BREAKING_EXPORT_ABI extern int EnableABIBreakingChecks;
LLVM_HIDDEN_VISIBILITY
__attribute__((weak)) int *VerifyEnableABIBreakingChecks =
&EnableABIBreakingChecks;
#else
extern int DisableABIBreakingChecks;
ABI_BREAKING_EXPORT_ABI extern int DisableABIBreakingChecks;
LLVM_HIDDEN_VISIBILITY
__attribute__((weak)) int *VerifyDisableABIBreakingChecks =
&DisableABIBreakingChecks;
Expand Down
59 changes: 32 additions & 27 deletions llvm/include/llvm/Demangle/Demangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef LLVM_DEMANGLE_DEMANGLE_H
#define LLVM_DEMANGLE_DEMANGLE_H

#include "DemangleConfig.h"
#include <cstddef>
#include <optional>
#include <string>
Expand All @@ -33,7 +34,8 @@ enum : int {
/// Returns a non-NULL pointer to a NUL-terminated C style string
/// that should be explicitly freed, if successful. Otherwise, may return
/// nullptr if mangled_name is not a valid mangling or is nullptr.
char *itaniumDemangle(std::string_view mangled_name, bool ParseParams = true);
DEMANGLE_ABI char *itaniumDemangle(std::string_view mangled_name,
bool ParseParams = true);

enum MSDemangleFlags {
MSDF_None = 0,
Expand All @@ -52,87 +54,90 @@ enum MSDemangleFlags {
/// bytes of the input string were consumed.
/// status receives one of the demangle_ enum entries above if it's not nullptr.
/// Flags controls various details of the demangled representation.
char *microsoftDemangle(std::string_view mangled_name, size_t *n_read,
int *status, MSDemangleFlags Flags = MSDF_None);
DEMANGLE_ABI char *microsoftDemangle(std::string_view mangled_name,
size_t *n_read, int *status,
MSDemangleFlags Flags = MSDF_None);

std::optional<size_t>
DEMANGLE_ABI std::optional<size_t>
getArm64ECInsertionPointInMangledName(std::string_view MangledName);

// Demangles a Rust v0 mangled symbol.
char *rustDemangle(std::string_view MangledName);
DEMANGLE_ABI char *rustDemangle(std::string_view MangledName);

// Demangles a D mangled symbol.
char *dlangDemangle(std::string_view MangledName);
DEMANGLE_ABI char *dlangDemangle(std::string_view MangledName);

/// Attempt to demangle a string using different demangling schemes.
/// The function uses heuristics to determine which demangling scheme to use.
/// \param MangledName - reference to string to demangle.
/// \returns - the demangled string, or a copy of the input string if no
/// demangling occurred.
std::string demangle(std::string_view MangledName);
DEMANGLE_ABI std::string demangle(std::string_view MangledName);

bool nonMicrosoftDemangle(std::string_view MangledName, std::string &Result,
bool CanHaveLeadingDot = true,
bool ParseParams = true);
DEMANGLE_ABI bool nonMicrosoftDemangle(std::string_view MangledName,
std::string &Result,
bool CanHaveLeadingDot = true,
bool ParseParams = true);

/// "Partial" demangler. This supports demangling a string into an AST
/// (typically an intermediate stage in itaniumDemangle) and querying certain
/// properties or partially printing the demangled name.
struct ItaniumPartialDemangler {
ItaniumPartialDemangler();
DEMANGLE_ABI ItaniumPartialDemangler();

ItaniumPartialDemangler(ItaniumPartialDemangler &&Other);
ItaniumPartialDemangler &operator=(ItaniumPartialDemangler &&Other);
DEMANGLE_ABI ItaniumPartialDemangler(ItaniumPartialDemangler &&Other);
DEMANGLE_ABI ItaniumPartialDemangler &
operator=(ItaniumPartialDemangler &&Other);

/// Demangle into an AST. Subsequent calls to the rest of the member functions
/// implicitly operate on the AST this produces.
/// \return true on error, false otherwise
bool partialDemangle(const char *MangledName);
DEMANGLE_ABI bool partialDemangle(const char *MangledName);

/// Just print the entire mangled name into Buf. Buf and N behave like the
/// second and third parameters to __cxa_demangle.
char *finishDemangle(char *Buf, size_t *N) const;
DEMANGLE_ABI char *finishDemangle(char *Buf, size_t *N) const;

/// See \ref finishDemangle
///
/// \param[in] OB A llvm::itanium_demangle::OutputBuffer that the demangled
/// name will be printed into.
///
char *finishDemangle(void *OB) const;
DEMANGLE_ABI char *finishDemangle(void *OB) const;

/// Get the base name of a function. This doesn't include trailing template
/// arguments, ie for "a::b<int>" this function returns "b".
char *getFunctionBaseName(char *Buf, size_t *N) const;
DEMANGLE_ABI char *getFunctionBaseName(char *Buf, size_t *N) const;

/// Get the context name for a function. For "a::b::c", this function returns
/// "a::b".
char *getFunctionDeclContextName(char *Buf, size_t *N) const;
DEMANGLE_ABI char *getFunctionDeclContextName(char *Buf, size_t *N) const;

/// Get the entire name of this function.
char *getFunctionName(char *Buf, size_t *N) const;
DEMANGLE_ABI char *getFunctionName(char *Buf, size_t *N) const;

/// Get the parameters for this function.
char *getFunctionParameters(char *Buf, size_t *N) const;
char *getFunctionReturnType(char *Buf, size_t *N) const;
DEMANGLE_ABI char *getFunctionParameters(char *Buf, size_t *N) const;
DEMANGLE_ABI char *getFunctionReturnType(char *Buf, size_t *N) const;

/// If this function has any cv or reference qualifiers. These imply that
/// the function is a non-static member function.
bool hasFunctionQualifiers() const;
DEMANGLE_ABI bool hasFunctionQualifiers() const;

/// If this symbol describes a constructor or destructor.
bool isCtorOrDtor() const;
DEMANGLE_ABI bool isCtorOrDtor() const;

/// If this symbol describes a function.
bool isFunction() const;
DEMANGLE_ABI bool isFunction() const;

/// If this symbol describes a variable.
bool isData() const;
DEMANGLE_ABI bool isData() const;

/// If this symbol is a <special-name>. These are generally implicitly
/// generated by the implementation, such as vtables and typeinfo names.
bool isSpecialName() const;
DEMANGLE_ABI bool isSpecialName() const;

~ItaniumPartialDemangler();
DEMANGLE_ABI ~ItaniumPartialDemangler();

private:
void *RootNode;
Expand Down
23 changes: 23 additions & 0 deletions llvm/include/llvm/Demangle/DemangleConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#ifndef LLVM_DEMANGLE_DEMANGLECONFIG_H
#define LLVM_DEMANGLE_DEMANGLECONFIG_H

// llvm-config.h is required for LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS
#include "llvm/Config/llvm-config.h"

#ifndef __has_feature
#define __has_feature(x) 0
#endif
Expand Down Expand Up @@ -94,4 +97,24 @@
#define DEMANGLE_NAMESPACE_BEGIN namespace llvm { namespace itanium_demangle {
#define DEMANGLE_NAMESPACE_END } }

/// DEMANGLE_ABI is the export/visibility macro used to mark symbols delcared in
/// llvm/Demangle as exported when built as a shared library.
#if defined(LLVM_BUILD_STATIC) || !defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS)
#define DEMANGLE_ABI
#else
#if defined(_WIN32)
#if defined(LLVM_EXPORTS)
#define DEMANGLE_ABI __declspec(dllexport)
#else
#define DEMANGLE_ABI __declspec(dllimport)
#endif
#else
#if __has_attribute(visibility)
#define DEMANGLE_ABI __attribute__((__visibility__("default")))
#else
#define DEMANGLE_ABI
#endif
#endif
#endif

#endif
Loading