From 0abde0aaf9f84d30616d39255c3f02668e92ba7c Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Tue, 8 Jul 2025 09:32:40 -0700 Subject: [PATCH 1/6] [llvm] define export annotations for Demangle library --- llvm/CMakeLists.txt | 5 +-- llvm/include/llvm/Demangle/Visibility.h | 43 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 llvm/include/llvm/Demangle/Visibility.h diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 3f8201fa426fe..506bb2343745b 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -1071,9 +1071,10 @@ if (LLVM_BUILD_LLVM_DYLIB OR LLVM_BUILD_SHARED_LIBS OR LLVM_ENABLE_PLUGINS) set(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS ON) endif() -# Because LLVM-C is built into the LLVM library, for now export its symbols -# whenever LLVM symbols are exported. +# Because LLVM-C and Demangle libraries are built into the LLVM library, for now +# we export their symbols if LLVM symbols are exported. set(LLVM_ENABLE_LLVM_C_EXPORT_ANNOTATIONS ${LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS}) +set(LLVM_ENABLE_DEMANGLE_EXPORT_ANNOTATIONS ${LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS}) set(LLVM_ENABLE_NEW_PASS_MANAGER TRUE CACHE BOOL "Enable the new pass manager by default.") diff --git a/llvm/include/llvm/Demangle/Visibility.h b/llvm/include/llvm/Demangle/Visibility.h new file mode 100644 index 0000000000000..35ea238b446b6 --- /dev/null +++ b/llvm/include/llvm/Demangle/Visibility.h @@ -0,0 +1,43 @@ +/*===-- Demangle/Visibility.h - Visibility macros for Demangle --*- C++ -*-===*\ +|* *| +|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| +|* Exceptions. *| +|* See https://llvm.org/LICENSE.txt for license information. *| +|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| +|* *| +|*===----------------------------------------------------------------------===*| +|* *| +|* This header defines visibility macros used for the Demangle library. These *| +|* macros are used to annotate functions that should be exported as part of a *| +|* shared library or DLL. *| +|* *| +\*===----------------------------------------------------------------------===*/ + +#ifndef LLVM_DEMANGLE_VISIBILITY_H +#define LLVM_DEMANGLE_VISIBILITY_H + +#include "llvm/Config/llvm-config.h" +#include "llvm/Demangle/DemangleConfig.h" + +/// 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_ABI_GENERATING_ANNOTATIONS) +#if defined(LLVM_ENABLE_DEMANGLE_EXPORT_ANNOTATIONS) && \ + !defined(LLVM_BUILD_STATIC) +#if defined(_WIN32) && !defined(__MINGW32__) +#if defined(LLVM_EXPORTS) +#define DEMANGLE_ABI __declspec(dllexport) +#else +#define DEMANGLE_ABI __declspec(dllimport) +#endif +#elif __has_attribute(visibility) +#define DEMANGLE_ABI __attribute__((visibility("default"))) +#endif +#endif +#if !defined(DEMANGLE_ABI) +#define DEMANGLE_ABI +#endif +#endif + +#endif From 23a57977de033aad4cdae1ea1e8e94d85fdae4a0 Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Tue, 8 Jul 2025 09:35:00 -0700 Subject: [PATCH 2/6] [llvm] auto-annotate Demangle library interface with IDS --- llvm/include/llvm/Demangle/Demangle.h | 49 +++++++-------- llvm/include/llvm/Demangle/ItaniumDemangle.h | 3 +- .../include/llvm/Demangle/MicrosoftDemangle.h | 7 ++- .../llvm/Demangle/MicrosoftDemangleNodes.h | 59 ++++++++++--------- 4 files changed, 61 insertions(+), 57 deletions(-) diff --git a/llvm/include/llvm/Demangle/Demangle.h b/llvm/include/llvm/Demangle/Demangle.h index 21e7457b6336f..77127d993f5f8 100644 --- a/llvm/include/llvm/Demangle/Demangle.h +++ b/llvm/include/llvm/Demangle/Demangle.h @@ -9,6 +9,7 @@ #ifndef LLVM_DEMANGLE_DEMANGLE_H #define LLVM_DEMANGLE_DEMANGLE_H +#include "llvm/Demangle/Visibility.h" #include #include #include @@ -33,7 +34,7 @@ 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, @@ -52,26 +53,26 @@ 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, +DEMANGLE_ABI char *microsoftDemangle(std::string_view mangled_name, size_t *n_read, int *status, MSDemangleFlags Flags = MSDF_None); -std::optional +DEMANGLE_ABI std::optional 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, +DEMANGLE_ABI bool nonMicrosoftDemangle(std::string_view MangledName, std::string &Result, bool CanHaveLeadingDot = true, bool ParseParams = true); @@ -79,60 +80,60 @@ bool nonMicrosoftDemangle(std::string_view MangledName, std::string &Result, /// (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" 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 . 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; diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h index 5533652736dc8..dfa5839d12a5a 100644 --- a/llvm/include/llvm/Demangle/ItaniumDemangle.h +++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h @@ -16,6 +16,7 @@ #ifndef DEMANGLE_ITANIUMDEMANGLE_H #define DEMANGLE_ITANIUMDEMANGLE_H +#include "llvm/Demangle/Visibility.h" #include "DemangleConfig.h" #include "StringViewExtras.h" #include "Utility.h" @@ -3049,7 +3050,7 @@ template 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); // ::= // N // ::= # See Scope Encoding below // Z diff --git a/llvm/include/llvm/Demangle/MicrosoftDemangle.h b/llvm/include/llvm/Demangle/MicrosoftDemangle.h index b9a25e361eec0..60a0ccab438b3 100644 --- a/llvm/include/llvm/Demangle/MicrosoftDemangle.h +++ b/llvm/include/llvm/Demangle/MicrosoftDemangle.h @@ -9,6 +9,7 @@ #ifndef LLVM_DEMANGLE_MICROSOFTDEMANGLE_H #define LLVM_DEMANGLE_MICROSOFTDEMANGLE_H +#include "llvm/Demangle/Visibility.h" #include "llvm/Demangle/Demangle.h" #include "llvm/Demangle/MicrosoftDemangleNodes.h" @@ -151,14 +152,14 @@ class Demangler { // You are supposed to call parse() first and then check if error is true. If // it is false, call output() to write the formatted name to the given stream. - SymbolNode *parse(std::string_view &MangledName); + DEMANGLE_ABI SymbolNode *parse(std::string_view &MangledName); - TagTypeNode *parseTagUniqueName(std::string_view &MangledName); + DEMANGLE_ABI TagTypeNode *parseTagUniqueName(std::string_view &MangledName); // True if an error occurred. bool Error = false; - void dumpBackReferences(); + DEMANGLE_ABI void dumpBackReferences(); private: SymbolNode *demangleEncodedSymbol(std::string_view &MangledName, diff --git a/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h b/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h index a9cfe726a73d3..4ac18d31ceeff 100644 --- a/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h +++ b/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h @@ -13,6 +13,7 @@ #ifndef LLVM_DEMANGLE_MICROSOFTDEMANGLENODES_H #define LLVM_DEMANGLE_MICROSOFTDEMANGLENODES_H +#include "llvm/Demangle/Visibility.h" #include #include #include @@ -281,7 +282,7 @@ struct Node { virtual void output(OutputBuffer &OB, OutputFlags Flags) const = 0; - std::string toString(OutputFlags Flags = OF_Default) const; + DEMANGLE_ABI std::string toString(OutputFlags Flags = OF_Default) const; private: NodeKind Kind; @@ -332,7 +333,7 @@ struct TypeNode : public Node { Qualifiers Quals = Q_None; }; -struct PrimitiveTypeNode : public TypeNode { +struct DEMANGLE_ABI PrimitiveTypeNode : public TypeNode { explicit PrimitiveTypeNode(PrimitiveKind K) : TypeNode(NodeKind::PrimitiveType), PrimKind(K) {} @@ -346,7 +347,7 @@ struct PrimitiveTypeNode : public TypeNode { PrimitiveKind PrimKind; }; -struct FunctionSignatureNode : public TypeNode { +struct DEMANGLE_ABI FunctionSignatureNode : public TypeNode { explicit FunctionSignatureNode(NodeKind K) : TypeNode(K) {} FunctionSignatureNode() : TypeNode(NodeKind::FunctionSignature) {} @@ -394,10 +395,10 @@ struct IdentifierNode : public Node { NodeArrayNode *TemplateParams = nullptr; protected: - void outputTemplateParameters(OutputBuffer &OB, OutputFlags Flags) const; + DEMANGLE_ABI void outputTemplateParameters(OutputBuffer &OB, OutputFlags Flags) const; }; -struct VcallThunkIdentifierNode : public IdentifierNode { +struct DEMANGLE_ABI VcallThunkIdentifierNode : public IdentifierNode { VcallThunkIdentifierNode() : IdentifierNode(NodeKind::VcallThunkIdentifier) {} void output(OutputBuffer &OB, OutputFlags Flags) const override; @@ -409,7 +410,7 @@ struct VcallThunkIdentifierNode : public IdentifierNode { uint64_t OffsetInVTable = 0; }; -struct DynamicStructorIdentifierNode : public IdentifierNode { +struct DEMANGLE_ABI DynamicStructorIdentifierNode : public IdentifierNode { DynamicStructorIdentifierNode() : IdentifierNode(NodeKind::DynamicStructorIdentifier) {} @@ -424,7 +425,7 @@ struct DynamicStructorIdentifierNode : public IdentifierNode { bool IsDestructor = false; }; -struct NamedIdentifierNode : public IdentifierNode { +struct DEMANGLE_ABI NamedIdentifierNode : public IdentifierNode { NamedIdentifierNode() : IdentifierNode(NodeKind::NamedIdentifier) {} void output(OutputBuffer &OB, OutputFlags Flags) const override; @@ -436,7 +437,7 @@ struct NamedIdentifierNode : public IdentifierNode { std::string_view Name; }; -struct IntrinsicFunctionIdentifierNode : public IdentifierNode { +struct DEMANGLE_ABI IntrinsicFunctionIdentifierNode : public IdentifierNode { explicit IntrinsicFunctionIdentifierNode(IntrinsicFunctionKind Operator) : IdentifierNode(NodeKind::IntrinsicFunctionIdentifier), Operator(Operator) {} @@ -450,7 +451,7 @@ struct IntrinsicFunctionIdentifierNode : public IdentifierNode { IntrinsicFunctionKind Operator; }; -struct LiteralOperatorIdentifierNode : public IdentifierNode { +struct DEMANGLE_ABI LiteralOperatorIdentifierNode : public IdentifierNode { LiteralOperatorIdentifierNode() : IdentifierNode(NodeKind::LiteralOperatorIdentifier) {} @@ -463,7 +464,7 @@ struct LiteralOperatorIdentifierNode : public IdentifierNode { std::string_view Name; }; -struct LocalStaticGuardIdentifierNode : public IdentifierNode { +struct DEMANGLE_ABI LocalStaticGuardIdentifierNode : public IdentifierNode { LocalStaticGuardIdentifierNode() : IdentifierNode(NodeKind::LocalStaticGuardIdentifier) {} @@ -477,7 +478,7 @@ struct LocalStaticGuardIdentifierNode : public IdentifierNode { uint32_t ScopeIndex = 0; }; -struct ConversionOperatorIdentifierNode : public IdentifierNode { +struct DEMANGLE_ABI ConversionOperatorIdentifierNode : public IdentifierNode { ConversionOperatorIdentifierNode() : IdentifierNode(NodeKind::ConversionOperatorIdentifier) {} @@ -491,7 +492,7 @@ struct ConversionOperatorIdentifierNode : public IdentifierNode { TypeNode *TargetType = nullptr; }; -struct StructorIdentifierNode : public IdentifierNode { +struct DEMANGLE_ABI StructorIdentifierNode : public IdentifierNode { StructorIdentifierNode() : IdentifierNode(NodeKind::StructorIdentifier) {} explicit StructorIdentifierNode(bool IsDestructor) : IdentifierNode(NodeKind::StructorIdentifier), @@ -508,7 +509,7 @@ struct StructorIdentifierNode : public IdentifierNode { bool IsDestructor = false; }; -struct ThunkSignatureNode : public FunctionSignatureNode { +struct DEMANGLE_ABI ThunkSignatureNode : public FunctionSignatureNode { ThunkSignatureNode() : FunctionSignatureNode(NodeKind::ThunkSignature) {} void outputPre(OutputBuffer &OB, OutputFlags Flags) const override; @@ -528,7 +529,7 @@ struct ThunkSignatureNode : public FunctionSignatureNode { ThisAdjustor ThisAdjust; }; -struct PointerTypeNode : public TypeNode { +struct DEMANGLE_ABI PointerTypeNode : public TypeNode { PointerTypeNode() : TypeNode(NodeKind::PointerType) {} void outputPre(OutputBuffer &OB, OutputFlags Flags) const override; void outputPost(OutputBuffer &OB, OutputFlags Flags) const override; @@ -550,7 +551,7 @@ struct PointerTypeNode : public TypeNode { TypeNode *Pointee = nullptr; }; -struct TagTypeNode : public TypeNode { +struct DEMANGLE_ABI TagTypeNode : public TypeNode { explicit TagTypeNode(TagKind Tag) : TypeNode(NodeKind::TagType), Tag(Tag) {} void outputPre(OutputBuffer &OB, OutputFlags Flags) const override; @@ -562,7 +563,7 @@ struct TagTypeNode : public TypeNode { TagKind Tag; }; -struct ArrayTypeNode : public TypeNode { +struct DEMANGLE_ABI ArrayTypeNode : public TypeNode { ArrayTypeNode() : TypeNode(NodeKind::ArrayType) {} void outputPre(OutputBuffer &OB, OutputFlags Flags) const override; @@ -591,7 +592,7 @@ struct IntrinsicNode : public TypeNode { } }; -struct CustomTypeNode : public TypeNode { +struct DEMANGLE_ABI CustomTypeNode : public TypeNode { CustomTypeNode() : TypeNode(NodeKind::Custom) {} void outputPre(OutputBuffer &OB, OutputFlags Flags) const override; @@ -602,7 +603,7 @@ struct CustomTypeNode : public TypeNode { IdentifierNode *Identifier = nullptr; }; -struct NodeArrayNode : public Node { +struct DEMANGLE_ABI NodeArrayNode : public Node { NodeArrayNode() : Node(NodeKind::NodeArray) {} void output(OutputBuffer &OB, OutputFlags Flags) const override; @@ -618,7 +619,7 @@ struct NodeArrayNode : public Node { size_t Count = 0; }; -struct QualifiedNameNode : public Node { +struct DEMANGLE_ABI QualifiedNameNode : public Node { QualifiedNameNode() : Node(NodeKind::QualifiedName) {} void output(OutputBuffer &OB, OutputFlags Flags) const override; @@ -635,7 +636,7 @@ struct QualifiedNameNode : public Node { } }; -struct TemplateParameterReferenceNode : public Node { +struct DEMANGLE_ABI TemplateParameterReferenceNode : public Node { TemplateParameterReferenceNode() : Node(NodeKind::TemplateParameterReference) {} @@ -653,7 +654,7 @@ struct TemplateParameterReferenceNode : public Node { bool IsMemberPointer = false; }; -struct IntegerLiteralNode : public Node { +struct DEMANGLE_ABI IntegerLiteralNode : public Node { IntegerLiteralNode() : Node(NodeKind::IntegerLiteral) {} IntegerLiteralNode(uint64_t Value, bool IsNegative) : Node(NodeKind::IntegerLiteral), Value(Value), IsNegative(IsNegative) {} @@ -668,7 +669,7 @@ struct IntegerLiteralNode : public Node { bool IsNegative = false; }; -struct RttiBaseClassDescriptorNode : public IdentifierNode { +struct DEMANGLE_ABI RttiBaseClassDescriptorNode : public IdentifierNode { RttiBaseClassDescriptorNode() : IdentifierNode(NodeKind::RttiBaseClassDescriptor) {} @@ -684,7 +685,7 @@ struct RttiBaseClassDescriptorNode : public IdentifierNode { uint32_t Flags = 0; }; -struct SymbolNode : public Node { +struct DEMANGLE_ABI SymbolNode : public Node { explicit SymbolNode(NodeKind K) : Node(K) {} void output(OutputBuffer &OB, OutputFlags Flags) const override; @@ -696,7 +697,7 @@ struct SymbolNode : public Node { QualifiedNameNode *Name = nullptr; }; -struct SpecialTableSymbolNode : public SymbolNode { +struct DEMANGLE_ABI SpecialTableSymbolNode : public SymbolNode { explicit SpecialTableSymbolNode() : SymbolNode(NodeKind::SpecialTableSymbol) {} @@ -710,7 +711,7 @@ struct SpecialTableSymbolNode : public SymbolNode { Qualifiers Quals = Qualifiers::Q_None; }; -struct LocalStaticGuardVariableNode : public SymbolNode { +struct DEMANGLE_ABI LocalStaticGuardVariableNode : public SymbolNode { LocalStaticGuardVariableNode() : SymbolNode(NodeKind::LocalStaticGuardVariable) {} @@ -723,7 +724,7 @@ struct LocalStaticGuardVariableNode : public SymbolNode { bool IsVisible = false; }; -struct EncodedStringLiteralNode : public SymbolNode { +struct DEMANGLE_ABI EncodedStringLiteralNode : public SymbolNode { EncodedStringLiteralNode() : SymbolNode(NodeKind::EncodedStringLiteral) {} void output(OutputBuffer &OB, OutputFlags Flags) const override; @@ -737,7 +738,7 @@ struct EncodedStringLiteralNode : public SymbolNode { CharKind Char = CharKind::Char; }; -struct VariableSymbolNode : public SymbolNode { +struct DEMANGLE_ABI VariableSymbolNode : public SymbolNode { VariableSymbolNode() : SymbolNode(NodeKind::VariableSymbol) {} void output(OutputBuffer &OB, OutputFlags Flags) const override; @@ -750,7 +751,7 @@ struct VariableSymbolNode : public SymbolNode { TypeNode *Type = nullptr; }; -struct FunctionSymbolNode : public SymbolNode { +struct DEMANGLE_ABI FunctionSymbolNode : public SymbolNode { FunctionSymbolNode() : SymbolNode(NodeKind::FunctionSymbol) {} void output(OutputBuffer &OB, OutputFlags Flags) const override; @@ -762,7 +763,7 @@ struct FunctionSymbolNode : public SymbolNode { FunctionSignatureNode *Signature = nullptr; }; -struct PointerAuthQualifierNode : public Node { +struct DEMANGLE_ABI PointerAuthQualifierNode : public Node { PointerAuthQualifierNode() : Node(NodeKind::PointerAuthQualifier) {} // __ptrauth takes three arguments: From f2d1a28630f377bcc22765c6c0090bcb049b7069 Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Tue, 8 Jul 2025 09:37:33 -0700 Subject: [PATCH 3/6] [llvm] manual fix-ups to Demangle library code-mod --- llvm/include/llvm/Demangle/Demangle.h | 2 +- llvm/include/llvm/Demangle/ItaniumDemangle.h | 2 +- llvm/include/llvm/Demangle/MicrosoftDemangle.h | 2 +- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/Demangle/Demangle.h b/llvm/include/llvm/Demangle/Demangle.h index 77127d993f5f8..cd6f49883bae7 100644 --- a/llvm/include/llvm/Demangle/Demangle.h +++ b/llvm/include/llvm/Demangle/Demangle.h @@ -9,7 +9,7 @@ #ifndef LLVM_DEMANGLE_DEMANGLE_H #define LLVM_DEMANGLE_DEMANGLE_H -#include "llvm/Demangle/Visibility.h" +#include "Visibility.h" #include #include #include diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h index dfa5839d12a5a..f9e8dade4fd83 100644 --- a/llvm/include/llvm/Demangle/ItaniumDemangle.h +++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h @@ -16,10 +16,10 @@ #ifndef DEMANGLE_ITANIUMDEMANGLE_H #define DEMANGLE_ITANIUMDEMANGLE_H -#include "llvm/Demangle/Visibility.h" #include "DemangleConfig.h" #include "StringViewExtras.h" #include "Utility.h" +#include "Visibility.h" #include #include #include diff --git a/llvm/include/llvm/Demangle/MicrosoftDemangle.h b/llvm/include/llvm/Demangle/MicrosoftDemangle.h index 60a0ccab438b3..4e1baf05dd886 100644 --- a/llvm/include/llvm/Demangle/MicrosoftDemangle.h +++ b/llvm/include/llvm/Demangle/MicrosoftDemangle.h @@ -9,9 +9,9 @@ #ifndef LLVM_DEMANGLE_MICROSOFTDEMANGLE_H #define LLVM_DEMANGLE_MICROSOFTDEMANGLE_H -#include "llvm/Demangle/Visibility.h" #include "llvm/Demangle/Demangle.h" #include "llvm/Demangle/MicrosoftDemangleNodes.h" +#include "llvm/Demangle/Visibility.h" #include #include diff --git a/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h b/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h index 4ac18d31ceeff..48e4271a0cc4e 100644 --- a/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h +++ b/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h @@ -13,7 +13,7 @@ #ifndef LLVM_DEMANGLE_MICROSOFTDEMANGLENODES_H #define LLVM_DEMANGLE_MICROSOFTDEMANGLENODES_H -#include "llvm/Demangle/Visibility.h" +#include "Visibility.h" #include #include #include From 4b59cf6290ef63f4e11cb9408f946cbf2ccb4c2f Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Tue, 8 Jul 2025 09:41:11 -0700 Subject: [PATCH 4/6] [llvm] clang format changes --- llvm/include/llvm/Demangle/Demangle.h | 18 +++++++++++------- llvm/include/llvm/Demangle/ItaniumDemangle.h | 3 ++- .../llvm/Demangle/MicrosoftDemangleNodes.h | 3 ++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/llvm/include/llvm/Demangle/Demangle.h b/llvm/include/llvm/Demangle/Demangle.h index cd6f49883bae7..24fd9ba8b2fe4 100644 --- a/llvm/include/llvm/Demangle/Demangle.h +++ b/llvm/include/llvm/Demangle/Demangle.h @@ -34,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. -DEMANGLE_ABI 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, @@ -53,8 +54,9 @@ 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. -DEMANGLE_ABI 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); DEMANGLE_ABI std::optional getArm64ECInsertionPointInMangledName(std::string_view MangledName); @@ -72,9 +74,10 @@ DEMANGLE_ABI char *dlangDemangle(std::string_view MangledName); /// demangling occurred. DEMANGLE_ABI std::string demangle(std::string_view MangledName); -DEMANGLE_ABI 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 @@ -83,7 +86,8 @@ struct ItaniumPartialDemangler { DEMANGLE_ABI ItaniumPartialDemangler(); DEMANGLE_ABI ItaniumPartialDemangler(ItaniumPartialDemangler &&Other); - DEMANGLE_ABI ItaniumPartialDemangler &operator=(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. diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h index f9e8dade4fd83..802802a978a4a 100644 --- a/llvm/include/llvm/Demangle/ItaniumDemangle.h +++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h @@ -3050,7 +3050,8 @@ template struct AbstractManglingParser { Node *parse(bool ParseParams = true); }; -DEMANGLE_ABI const char* parse_discriminator(const char* first, const char* last); +DEMANGLE_ABI const char *parse_discriminator(const char *first, + const char *last); // ::= // N // ::= # See Scope Encoding below // Z diff --git a/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h b/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h index 48e4271a0cc4e..611fcdf7999b2 100644 --- a/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h +++ b/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h @@ -395,7 +395,8 @@ struct IdentifierNode : public Node { NodeArrayNode *TemplateParams = nullptr; protected: - DEMANGLE_ABI void outputTemplateParameters(OutputBuffer &OB, OutputFlags Flags) const; + DEMANGLE_ABI void outputTemplateParameters(OutputBuffer &OB, + OutputFlags Flags) const; }; struct DEMANGLE_ABI VcallThunkIdentifierNode : public IdentifierNode { From dd5dc10c3d4401736e349536afc017e281a9d6e1 Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Tue, 8 Jul 2025 12:39:01 -0700 Subject: [PATCH 5/6] fix test failures --- libcxxabi/src/demangle/ItaniumDemangle.h | 4 +++- libcxxabi/src/demangle/Visibility.h | 18 ++++++++++++++++++ libcxxabi/src/demangle/cp-to-llvm.sh | 5 +++-- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 libcxxabi/src/demangle/Visibility.h diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h index b306b2013445c..ed73b1aaf4363 100644 --- a/libcxxabi/src/demangle/ItaniumDemangle.h +++ b/libcxxabi/src/demangle/ItaniumDemangle.h @@ -19,6 +19,7 @@ #include "DemangleConfig.h" #include "StringViewExtras.h" #include "Utility.h" +#include "Visibility.h" #include #include #include @@ -3049,7 +3050,8 @@ template 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); // ::= // N // ::= # See Scope Encoding below // Z diff --git a/libcxxabi/src/demangle/Visibility.h b/libcxxabi/src/demangle/Visibility.h new file mode 100644 index 0000000000000..90ca0e5e87335 --- /dev/null +++ b/libcxxabi/src/demangle/Visibility.h @@ -0,0 +1,18 @@ +//===--- Visibility.h -------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// This file is contains noop definitions of the DEMANGLE_ABI macro defined in +// llvm/include/llvm/Demangle/Visibility.h. +//===----------------------------------------------------------------------===// + +#ifndef LIBCXXABI_DEMANGLE_VISIBILITY_H +#define LIBCXXABI_DEMANGLE_VISIBILITY_H + +// The DEMANGLE_ABI macro resovles to nothing when building libcxxabi. Only +// the llvm copy defines DEMANGLE_ABI as a visibility attribute. +#define DEMANGLE_ABI + +#endif diff --git a/libcxxabi/src/demangle/cp-to-llvm.sh b/libcxxabi/src/demangle/cp-to-llvm.sh index f773dff9f0a8b..30bcd42191175 100755 --- a/libcxxabi/src/demangle/cp-to-llvm.sh +++ b/libcxxabi/src/demangle/cp-to-llvm.sh @@ -1,7 +1,8 @@ #!/bin/bash -# Copies the 'demangle' library, excluding 'DemangleConfig.h', to llvm. If no -# llvm directory is specified, then assume a monorepo layout. +# Copies the 'demangle' library, excluding 'DemangleConfig.h' and +# 'Visibility.h', to llvm. If no llvm directory is specified, then assume a +# monorepo layout. set -e From 84cd131e8f6d24e442849f1f709e9d1c3bb9afb3 Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Tue, 8 Jul 2025 17:34:22 -0700 Subject: [PATCH 6/6] simply alias DEMANGLE_ABI to LLVM_ABI when building llvm --- llvm/CMakeLists.txt | 5 ++--- llvm/include/llvm/Demangle/Visibility.h | 24 +++--------------------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 506bb2343745b..3f8201fa426fe 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -1071,10 +1071,9 @@ if (LLVM_BUILD_LLVM_DYLIB OR LLVM_BUILD_SHARED_LIBS OR LLVM_ENABLE_PLUGINS) set(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS ON) endif() -# Because LLVM-C and Demangle libraries are built into the LLVM library, for now -# we export their symbols if LLVM symbols are exported. +# Because LLVM-C is built into the LLVM library, for now export its symbols +# whenever LLVM symbols are exported. set(LLVM_ENABLE_LLVM_C_EXPORT_ANNOTATIONS ${LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS}) -set(LLVM_ENABLE_DEMANGLE_EXPORT_ANNOTATIONS ${LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS}) set(LLVM_ENABLE_NEW_PASS_MANAGER TRUE CACHE BOOL "Enable the new pass manager by default.") diff --git a/llvm/include/llvm/Demangle/Visibility.h b/llvm/include/llvm/Demangle/Visibility.h index 35ea238b446b6..20103d37b5b98 100644 --- a/llvm/include/llvm/Demangle/Visibility.h +++ b/llvm/include/llvm/Demangle/Visibility.h @@ -16,28 +16,10 @@ #ifndef LLVM_DEMANGLE_VISIBILITY_H #define LLVM_DEMANGLE_VISIBILITY_H -#include "llvm/Config/llvm-config.h" -#include "llvm/Demangle/DemangleConfig.h" +#include "llvm/Support/Compiler.h" /// 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_ABI_GENERATING_ANNOTATIONS) -#if defined(LLVM_ENABLE_DEMANGLE_EXPORT_ANNOTATIONS) && \ - !defined(LLVM_BUILD_STATIC) -#if defined(_WIN32) && !defined(__MINGW32__) -#if defined(LLVM_EXPORTS) -#define DEMANGLE_ABI __declspec(dllexport) -#else -#define DEMANGLE_ABI __declspec(dllimport) -#endif -#elif __has_attribute(visibility) -#define DEMANGLE_ABI __attribute__((visibility("default"))) -#endif -#endif -#if !defined(DEMANGLE_ABI) -#define DEMANGLE_ABI -#endif -#endif +/// llvm/Demangle as exported when LLVM is built as a shared library. +#define DEMANGLE_ABI LLVM_ABI #endif