Skip to content
Closed
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
3 changes: 3 additions & 0 deletions llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,9 @@ endif()
configure_file(
${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
configure_file(
${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/export-config.h.cmake
${LLVM_INCLUDE_DIR}/llvm/Config/export-config.h)
configure_file(
${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
Expand Down
20 changes: 3 additions & 17 deletions llvm/include/llvm-c/Visibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,15 @@
#ifndef LLVM_C_VISIBILITY_H
#define LLVM_C_VISIBILITY_H

#include "llvm/Config/llvm-config.h"
#include "llvm/Config/export-config.h"

/// LLVM_C_ABI is the export/visibility macro used to mark symbols declared in
/// llvm-c as exported when built as a shared library.

#if !defined(LLVM_ABI_GENERATING_ANNOTATIONS)
// TODO(https://github.com/llvm/llvm-project/issues/145406): eliminate need for
// two preprocessor definitions to gate LLVM_ABI macro definitions.
#if defined(LLVM_ENABLE_LLVM_C_EXPORT_ANNOTATIONS) && \
!defined(LLVM_BUILD_STATIC)
#if defined(_WIN32) && !defined(__MINGW32__)
#if defined(LLVM_EXPORTS)
#define LLVM_C_ABI __declspec(dllexport)
#if defined(LLVM_ENABLE_LLVM_C_EXPORT_ANNOTATIONS)
#define LLVM_C_ABI LLVM_INTERFACE_ABI
#else
#define LLVM_C_ABI __declspec(dllimport)
#endif
#elif defined(__has_attribute) && __has_attribute(visibility)
#define LLVM_C_ABI __attribute__((visibility("default")))
#endif
#endif
#if !defined(LLVM_C_ABI)
#define LLVM_C_ABI
#endif
#endif

#endif
88 changes: 88 additions & 0 deletions llvm/include/llvm/Config/export-config.h.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*===------- llvm/Config/export-config.h - export configuration ----- 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 contains configuration definitions controling which LLVM projects
and components require public ABI export for shared library builds. It also
contains generic LLVM_INTERFACE_ macro definitions that can be aliased by
libraries and components and used to decorate their public interface. */

#ifndef LLVM_EXPORT_CONFIG_H
#define LLVM_EXPORT_CONFIG_H

/* Define if exporting LLVM public interface for shared library */
#cmakedefine LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS

/* Define if exporting LLVM-C public interface for shared library */
#cmakedefine LLVM_ENABLE_LLVM_C_EXPORT_ANNOTATIONS

/// LLVM_INTERFACE_ABI is the main export/visibility macro to mark something as explicitly
/// exported when llvm is built as a shared library with everything else that is
/// unannotated will have internal visibility.
///
/// LLVM_INTERFACE_ABI_EXPORT is for the special case for things like plugin symbol
/// declarations or definitions where we don't want the macro to be switching
/// between dllexport and dllimport on windows based on what codebase is being
/// built, it will only be dllexport. For non windows platforms this macro
/// behaves the same as LLVM_ABI.
///
/// LLVM_INTERFACE_EXPORT_TEMPLATE is used on explicit template instantiations in source
/// files that were declared extern in a header. This macro is only set as a
/// compiler export attribute on windows, on other platforms it does nothing.
///
/// LLVM_INTERFACE_TEMPLATE_ABI is for annotating extern template declarations in headers
/// for both functions and classes. On windows its turned in to dllimport for
/// library consumers, for other platforms its a default visibility attribute.
///
/// LLVM_INTERFACE_ABI_FOR_TEST is for annotating symbols that are only exported because
/// they are imported from a test. These symbols are not technically part of the
/// LLVM public interface and could be conditionally excluded when not building
/// tests in the future.
///
// Marker to add to classes or functions in public headers that should not have
// export macros added to them by the clang tool
#define LLVM_INTERFACE_ABI_NOT_EXPORTED
// 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)
#if defined(_WIN32) && !defined(__MINGW32__)
#if defined(LLVM_EXPORTS)
Copy link
Member

@compnerd compnerd Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work. This defines the interface as to how LLVM was built. If I build LLVM dynamically, llvm-c statically, and LLVM Demangle dynamically, I need 2 independent sets of definitions for LLVM and LLVM Demangle. Doing something else really doesn't work. The de-duplication is not worth additional complexity and introducing new patterns IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The de-duplication is not worth additional complexity and introducing new patterns IMO.

I am completely on-board with the complexity argument for not doing it this way. I will put up the abi-breaking PR again with the duplicated logic.

#define LLVM_INTERFACE_ABI __declspec(dllexport)
#define LLVM_INTERFACE_TEMPLATE_ABI
#define LLVM_INTERFACE_EXPORT_TEMPLATE __declspec(dllexport)
#else
#define LLVM_INTERFACE_ABI __declspec(dllimport)
#define LLVM_INTERFACE_TEMPLATE_ABI __declspec(dllimport)
#define LLVM_INTERFACE_EXPORT_TEMPLATE
#endif
#define LLVM_INTERFACE_ABI_EXPORT __declspec(dllexport)
#elif defined(__has_attribute) && __has_attribute(visibility)
#if defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \
defined(__MVS__) || defined(__CYGWIN__)
#define LLVM_INTERFACE_ABI __attribute__((visibility("default")))
#define LLVM_INTERFACE_TEMPLATE_ABI LLVM_INTERFACE_ABI
#define LLVM_INTERFACE_EXPORT_TEMPLATE
#define LLVM_INTERFACE_ABI_EXPORT LLVM_INTERFACE_ABI
#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__)
#define LLVM_INTERFACE_ABI __attribute__((visibility("default")))
#define LLVM_INTERFACE_TEMPLATE_ABI
#define LLVM_INTERFACE_EXPORT_TEMPLATE
#define LLVM_INTERFACE_ABI_EXPORT LLVM_INTERFACE_ABI
#endif
#endif
#endif
#if !defined(LLVM_INTERFACE_ABI)
#define LLVM_INTERFACE_ABI
#define LLVM_INTERFACE_TEMPLATE_ABI
#define LLVM_INTERFACE_EXPORT_TEMPLATE
#define LLVM_INTERFACE_ABI_EXPORT
#endif
#define LLVM_INTERFACE_ABI_FOR_TEST LLVM_INTERFACE_ABI

#endif
6 changes: 0 additions & 6 deletions llvm/include/llvm/Config/llvm-config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@
/* Define if building LLVM with BUILD_SHARED_LIBS */
#cmakedefine LLVM_BUILD_SHARED_LIBS

/* Define if exporting LLVM public interface for shared library */
#cmakedefine LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS

/* Define if exporting LLVM-C public interface for shared library */
#cmakedefine LLVM_ENABLE_LLVM_C_EXPORT_ANNOTATIONS

/* Define if building LLVM with LLVM_FORCE_USE_OLD_TOOLCHAIN_LIBS */
#cmakedefine LLVM_FORCE_USE_OLD_TOOLCHAIN ${LLVM_FORCE_USE_OLD_TOOLCHAIN}

Expand Down
45 changes: 10 additions & 35 deletions llvm/include/llvm/Support/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef LLVM_SUPPORT_COMPILER_H
#define LLVM_SUPPORT_COMPILER_H

#include "llvm/Config/export-config.h"
#include "llvm/Config/llvm-config.h"

#include <stddef.h>
Expand Down Expand Up @@ -176,46 +177,20 @@
/// LLVM public interface and could be conditionally excluded when not building
/// tests in the future.
///
#ifndef LLVM_ABI_GENERATING_ANNOTATIONS
// Marker to add to classes or functions in public headers that should not have
// export macros added to them by the clang tool
#define LLVM_ABI_NOT_EXPORTED
// TODO(https://github.com/llvm/llvm-project/issues/145406): eliminate need for
// two preprocessor definitions to gate LLVM_ABI macro definitions.
#if defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS) && !defined(LLVM_BUILD_STATIC)
#if defined(_WIN32) && !defined(__MINGW32__)
#if defined(LLVM_EXPORTS)
#define LLVM_ABI __declspec(dllexport)
#define LLVM_TEMPLATE_ABI
#define LLVM_EXPORT_TEMPLATE __declspec(dllexport)
#if defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS)
#define LLVM_ABI_NOT_EXPORTED LLVM_INTERFACE_ABI_NOT_EXPORTED
#define LLVM_ABI LLVM_INTERFACE_ABI
#define LLVM_TEMPLATE_ABI LLVM_INTERFACE_TEMPLATE_ABI
#define LLVM_EXPORT_TEMPLATE LLVM_INTERFACE_EXPORT_TEMPLATE
#define LLVM_ABI_EXPORT LLVM_INTERFACE_ABI_EXPORT
#define LLVM_ABI_FOR_TEST LLVM_INTERFACE_ABI_FOR_TEST
#else
#define LLVM_ABI __declspec(dllimport)
#define LLVM_TEMPLATE_ABI __declspec(dllimport)
#define LLVM_EXPORT_TEMPLATE
#endif
#define LLVM_ABI_EXPORT __declspec(dllexport)
#elif __has_attribute(visibility)
#if defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \
defined(__MVS__) || defined(__CYGWIN__)
#define LLVM_ABI __attribute__((visibility("default")))
#define LLVM_TEMPLATE_ABI LLVM_ABI
#define LLVM_EXPORT_TEMPLATE
#define LLVM_ABI_EXPORT LLVM_ABI
#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__)
#define LLVM_ABI __attribute__((visibility("default")))
#define LLVM_TEMPLATE_ABI
#define LLVM_EXPORT_TEMPLATE
#define LLVM_ABI_EXPORT LLVM_ABI
#endif
#endif
#endif
#if !defined(LLVM_ABI)
#define LLVM_ABI_NOT_EXPORTED
#define LLVM_ABI
#define LLVM_TEMPLATE_ABI
#define LLVM_EXPORT_TEMPLATE
#define LLVM_ABI_EXPORT
#endif
#define LLVM_ABI_FOR_TEST LLVM_ABI
#define LLVM_ABI_FOR_TEST
#endif

#if defined(__GNUC__)
Expand Down
Loading