diff options
| author | Andrew Rogers <andrurogerz@gmail.com> | 2025-07-24 03:50:16 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-24 12:50:16 +0200 |
| commit | 04f5198e3ecb5592cec3297a782b8179f95434bf (patch) | |
| tree | e0b74c32282d6d3d4e4bdfeb321f29e83b646178 /libcxxabi | |
| parent | 9c5f8ec561e059bdaa585e75209cb5c658953e90 (diff) | |
[llvm] annotate interfaces in Demangle for DLL export (#147564)
## Purpose
This patch is one in a series of code-mods that annotate LLVM’s public
interface for export. This patch annotates the `Demangle` interface with
a new `DEMANGLE_ABI` annotation, which behaves like the `LLVM_ABI`. This
annotation currently has no meaningful impact on the LLVM build;
however, it is a prerequisite to support an LLVM Windows DLL (shared
library) build.
## Overview
1. Add a new `Demangle/Visibility.h` header file that defines a new
`DEMANGLE_ABI` macro. The macro resolves to the proper DLL export/import
annotation on Windows and a "default" visibility annotation elsewhere.
2. Add a new `LLVM_ENABLE_DEMANGLE_EXPORT_ANNOTATIONS ` `#cmakedefine`
that is used to gate the definition of `DEMANGLE_ABI`.
3. Code-mod annotate the public `Demangle` interface using the
[Interface Definition Scanner (IDS)](https://github.com/compnerd/ids)
tool.
4. Manually fix-up `#include` statements for consistency.
5. Format the changes with `clang-format`.
6. Add a "stub" version of `Visibility.h` under `libcxxabi/src/demangle`
that always defines `DEMANGLE_ABI` to nothing.
7. Update the canonical `libcxxabi/src/demangle/ItaniumDemangle.h`
instead of the llvm copy, and run `cp-to-llvm.sh` to ensure the llvm
copy matches. NOTE: we rely on `ccp-to-llvm.sh` not copying
`Visibillity.h` as is already the case for `DemangleConfig.h`.
## Background
This PR follows the pattern established with the `llvm-c` changes made
in #141701.
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).
## 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
---------
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
Diffstat (limited to 'libcxxabi')
| -rw-r--r-- | libcxxabi/src/demangle/DemangleConfig.h | 4 | ||||
| -rw-r--r-- | libcxxabi/src/demangle/ItaniumDemangle.h | 3 |
2 files changed, 6 insertions, 1 deletions
diff --git a/libcxxabi/src/demangle/DemangleConfig.h b/libcxxabi/src/demangle/DemangleConfig.h index 06fd223f5553..a88e6ce65d70 100644 --- a/libcxxabi/src/demangle/DemangleConfig.h +++ b/libcxxabi/src/demangle/DemangleConfig.h @@ -107,4 +107,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 diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h index b306b2013445..6f27da7b9cad 100644 --- a/libcxxabi/src/demangle/ItaniumDemangle.h +++ b/libcxxabi/src/demangle/ItaniumDemangle.h @@ -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 |
