[llvm] Sketch of build and code changes for llvm shared library build using explicit visibility annotations (PR #96630)
Thomas Fransham via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 12 14:32:33 PDT 2024
https://github.com/fsfod updated https://github.com/llvm/llvm-project/pull/96630
>From 68e421a90f55f866dc936caff0906b2bea1405ef Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Mon, 17 Jun 2024 05:45:15 +0100
Subject: [PATCH 01/25] Remove the hardcoded cmake error from using
LLVM_BUILD_LLVM_DYLIB on windows
---
llvm/tools/llvm-shlib/CMakeLists.txt | 3 ---
1 file changed, 3 deletions(-)
diff --git a/llvm/tools/llvm-shlib/CMakeLists.txt b/llvm/tools/llvm-shlib/CMakeLists.txt
index b20ac318e768d..d8a833b80d8b9 100644
--- a/llvm/tools/llvm-shlib/CMakeLists.txt
+++ b/llvm/tools/llvm-shlib/CMakeLists.txt
@@ -11,9 +11,6 @@ if(LLVM_LINK_LLVM_DYLIB AND LLVM_DYLIB_EXPORTED_SYMBOL_FILE)
endif()
if(LLVM_BUILD_LLVM_DYLIB)
- if(MSVC)
- message(FATAL_ERROR "Generating libLLVM is not supported on MSVC")
- endif()
if(ZOS)
message(FATAL_ERROR "Generating libLLVM is not supported on z/OS")
endif()
>From ee8944978a6d00fe2b7c6ae8305815cff793626f Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Tue, 25 Jun 2024 02:51:39 +0100
Subject: [PATCH 02/25] Change the CMake definition for LLVM_LINK_LLVM_DYLIB
not to be hidden on windows
---
llvm/CMakeLists.txt | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 3208147101c0d..829fd31ae4a6f 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -815,22 +815,20 @@ endif()
if(MSVC)
option(LLVM_BUILD_LLVM_C_DYLIB "Build LLVM-C.dll (Windows only)" ON)
- # Set this variable to OFF here so it can't be set with a command-line
- # argument.
- set (LLVM_LINK_LLVM_DYLIB OFF)
if (BUILD_SHARED_LIBS)
message(FATAL_ERROR "BUILD_SHARED_LIBS options is not supported on Windows.")
endif()
-else()
- option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
+ else()
option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin only)" OFF)
- set(LLVM_BUILD_LLVM_DYLIB_default OFF)
- if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
- set(LLVM_BUILD_LLVM_DYLIB_default ON)
- endif()
- option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default})
endif()
+option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
+set(LLVM_BUILD_LLVM_DYLIB_default OFF)
+if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
+ set(LLVM_BUILD_LLVM_DYLIB_default ON)
+endif()
+option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default})
+
if (LLVM_LINK_LLVM_DYLIB AND BUILD_SHARED_LIBS)
message(FATAL_ERROR "Cannot enable BUILD_SHARED_LIBS with LLVM_LINK_LLVM_DYLIB. We recommend disabling BUILD_SHARED_LIBS.")
endif()
>From 05b9f6b7e98f09a8a55d6c3a5c7be3ba4dcae6bc Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Mon, 17 Jun 2024 05:40:57 +0100
Subject: [PATCH 03/25] Define macros in cmake to enable export macros
---
llvm/cmake/modules/AddLLVM.cmake | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 03f4e1f190fd9..8658495033614 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -643,6 +643,7 @@ function(llvm_add_library name)
if(ARG_COMPONENT_LIB)
set_target_properties(${name} PROPERTIES LLVM_COMPONENT TRUE)
+ target_compile_definitions(${name} PRIVATE LLVM_ABI_EXPORTS)
set_property(GLOBAL APPEND PROPERTY LLVM_COMPONENT_LIBS ${name})
endif()
@@ -740,6 +741,7 @@ function(llvm_add_library name)
elseif (NOT ARG_COMPONENT_LIB)
if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
set(llvm_libs LLVM)
+ target_compile_definitions(${name} PRIVATE LLVM_DLL_IMPORT)
else()
llvm_map_components_to_libnames(llvm_libs
${ARG_LINK_COMPONENTS}
@@ -1111,6 +1113,10 @@ macro(add_llvm_executable name)
endif()
llvm_codesign(${name} ENTITLEMENTS ${ARG_ENTITLEMENTS} BUNDLE_PATH ${ARG_BUNDLE_PATH})
+
+ if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
+ target_compile_definitions(${name} PRIVATE LLVM_DLL_IMPORT)
+ endif()
endmacro(add_llvm_executable name)
# add_llvm_pass_plugin(name [NO_MODULE] ...)
>From 57c2386dfc31f437e7f93ff114bfff1b20ef2ede Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Mon, 17 Jun 2024 14:21:36 +0100
Subject: [PATCH 04/25] Add support for building on windows to llvm-shlib cmake
file by appending /WHOLEARCHIVE:lib to the linker options
---
llvm/tools/llvm-shlib/CMakeLists.txt | 33 ++++++++++++++++++----------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/llvm/tools/llvm-shlib/CMakeLists.txt b/llvm/tools/llvm-shlib/CMakeLists.txt
index d8a833b80d8b9..7ca61aae83704 100644
--- a/llvm/tools/llvm-shlib/CMakeLists.txt
+++ b/llvm/tools/llvm-shlib/CMakeLists.txt
@@ -46,18 +46,27 @@ if(LLVM_BUILD_LLVM_DYLIB)
${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in
${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map)
- # GNU ld doesn't resolve symbols in the version script.
- set(LIB_NAMES -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive)
- if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT MINGW)
- # Solaris ld does not accept global: *; so there is no way to version *all* global symbols
- set(LIB_NAMES -Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map ${LIB_NAMES})
- endif()
- if (NOT MINGW AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS)
- # Optimize function calls for default visibility definitions to avoid PLT and
- # reduce dynamic relocations.
- # Note: for -fno-pic default, the address of a function may be different from
- # inside and outside libLLVM.so.
- target_link_options(LLVM PRIVATE LINKER:-Bsymbolic-functions)
+ if(MSVC)
+ target_link_directories(LLVM PRIVATE ${LLVM_LIBRARY_DIR})
+ foreach(library ${LIB_NAMES})
+ # FIXME figure out how to use LINK_LIBRARY:WHOLE_ARCHIVE without cmake errors
+ # target_link_libraries(LLVM PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,${library}>" )
+ target_link_options(LLVM PRIVATE /WHOLEARCHIVE:${library}.lib)
+ endforeach()
+ else()
+ # GNU ld doesn't resolve symbols in the version script.
+ set(LIB_NAMES -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive)
+ if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT MINGW)
+ # Solaris ld does not accept global: *; so there is no way to version *all* global symbols
+ set(LIB_NAMES -Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map ${LIB_NAMES})
+ endif()
+ if (NOT MINGW AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS)
+ # Optimize function calls for default visibility definitions to avoid PLT and
+ # reduce dynamic relocations.
+ # Note: for -fno-pic default, the address of a function may be different from
+ # inside and outside libLLVM.so.
+ target_link_options(LLVM PRIVATE LINKER:-Bsymbolic-functions)
+ endif()
endif()
endif()
>From b334dc8f8a9f7f54efc9098f51a0d70d0b91e462 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Mon, 17 Jun 2024 05:43:01 +0100
Subject: [PATCH 05/25] Use /Zc:dllexportInlines- when compiling with clang-cl
This halves the number of symbols exported compared MSVC and reduces compile time, but
it makes the DLL incompatible with MSVC because of the missing exports from inline members
https://blog.llvm.org/2018/11/30-faster-windows-builds-with-clang-cl_14.html
Add a cmake option to opt out of using it
Add a cmake option to force dll exporting inline class members when building with clang-cl
so the dll will be compatible with MSVC.
---
llvm/CMakeLists.txt | 5 +++++
llvm/cmake/modules/AddLLVM.cmake | 11 +++++++++++
2 files changed, 16 insertions(+)
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 829fd31ae4a6f..02ac5c8994e12 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -829,6 +829,11 @@ if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
endif()
option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default})
+if(MSVC)
+ option(LLVM_DYLIB_EXPORT_INLNES "Force inline members of class to be dll exported when
+ building with clang-cl so the libllvm dll is compatible with MSVC" OFF)
+endif()
+
if (LLVM_LINK_LLVM_DYLIB AND BUILD_SHARED_LIBS)
message(FATAL_ERROR "Cannot enable BUILD_SHARED_LIBS with LLVM_LINK_LLVM_DYLIB. We recommend disabling BUILD_SHARED_LIBS.")
endif()
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 8658495033614..95ee87e5ebf54 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -641,6 +641,14 @@ function(llvm_add_library name)
endif()
set_target_properties(${name} PROPERTIES FOLDER "${subproject_title}/Libraries")
+ ## If were compiling with clang-cl use /Zc:dllexportInlines- to exclude inline
+ ## class members from being dllexport'ed to reduce compile time.
+ ## This will also keep us below the 64k exported symbol limit
+ ## https://blog.llvm.org/2018/11/30-faster-windows-builds-with-clang-cl_14.html
+ if(LLVM_BUILD_LLVM_DYLIB AND NOT LLVM_DYLIB_EXPORT_INLNES AND MSVC AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
+ target_compile_options(${name} PUBLIC /Zc:dllexportInlines-)
+ endif()
+
if(ARG_COMPONENT_LIB)
set_target_properties(${name} PROPERTIES LLVM_COMPONENT TRUE)
target_compile_definitions(${name} PRIVATE LLVM_ABI_EXPORTS)
@@ -1116,6 +1124,9 @@ macro(add_llvm_executable name)
if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
target_compile_definitions(${name} PRIVATE LLVM_DLL_IMPORT)
+ if(MSVC AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
+ target_compile_options(${name} PRIVATE /Zc:dllexportInlines-)
+ endif()
endif()
endmacro(add_llvm_executable name)
>From ebb311a029e91d8041ac2ac7a6c9ec0827619407 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Sun, 23 Jun 2024 15:19:53 +0100
Subject: [PATCH 06/25] Set the default symbol visibility for COMPONENT_LIB
libraries to hidden by default
---
llvm/cmake/modules/AddLLVM.cmake | 13 +++++++++++++
llvm/lib/Target/CMakeLists.txt | 11 -----------
2 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 95ee87e5ebf54..d5fc78a1a1c85 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -652,6 +652,19 @@ function(llvm_add_library name)
if(ARG_COMPONENT_LIB)
set_target_properties(${name} PROPERTIES LLVM_COMPONENT TRUE)
target_compile_definitions(${name} PRIVATE LLVM_ABI_EXPORTS)
+
+ # When building shared objects for each target there are some internal APIs
+ # that are used across shared objects which we can't hide.
+ if (NOT BUILD_SHARED_LIBS AND NOT APPLE AND
+ (NOT (WIN32 OR CYGWIN) OR (MINGW AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND
+ NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX") AND
+ NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET)
+
+ set_target_properties(${name} PROPERTIES
+ C_VISIBILITY_PRESET hidden
+ CXX_VISIBILITY_PRESET hidden
+ VISIBILITY_INLINES_HIDDEN YES)
+ endif()
set_property(GLOBAL APPEND PROPERTY LLVM_COMPONENT_LIBS ${name})
endif()
diff --git a/llvm/lib/Target/CMakeLists.txt b/llvm/lib/Target/CMakeLists.txt
index 2739233f9ccb3..2a0edbe058984 100644
--- a/llvm/lib/Target/CMakeLists.txt
+++ b/llvm/lib/Target/CMakeLists.txt
@@ -20,17 +20,6 @@ add_llvm_component_library(LLVMTarget
TargetParser
)
-# When building shared objects for each target there are some internal APIs
-# that are used across shared objects which we can't hide.
-if (NOT BUILD_SHARED_LIBS AND NOT APPLE AND
- (NOT (WIN32 OR CYGWIN) OR (MINGW AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND
- NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX") AND
- NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET)
- # Set default visibility to hidden, so we don't export all the Target classes
- # in libLLVM.so.
- set(CMAKE_CXX_VISIBILITY_PRESET hidden)
-endif()
-
foreach(t ${LLVM_TARGETS_TO_BUILD})
message(STATUS "Targeting ${t}")
add_subdirectory(${t})
>From d3e8927b17045fe90304b6407dad573f0a3a90ee Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Mon, 17 Jun 2024 15:13:29 +0100
Subject: [PATCH 07/25] Declare the conditional export macros in
llvm/Support/Compiler.h
---
llvm/include/llvm/Support/Compiler.h | 57 +++++++++++++++++++++++++++-
1 file changed, 56 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index d8e3794babc74..3eaff49b5e4ec 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -114,7 +114,7 @@
/// this attribute will be made public and visible outside of any shared library
/// they are linked in to.
-#if LLVM_HAS_CPP_ATTRIBUTE(gnu::visibility)
+#if LLVM_HAS_CPP_ATTRIBUTE(gnu::visibility) && defined(__GNUC__) && !defined(__clang__)
#define LLVM_ATTRIBUTE_VISIBILITY_HIDDEN [[gnu::visibility("hidden")]]
#define LLVM_ATTRIBUTE_VISIBILITY_DEFAULT [[gnu::visibility("default")]]
#elif __has_attribute(visibility)
@@ -139,6 +139,61 @@
#define LLVM_EXTERNAL_VISIBILITY
#endif
+/// LLVM_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_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_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_C_ABI is used to annotated functions and data that need to be exported
+/// for the libllvm-c API. This used both for the llvm-c headers and for the
+/// functions declared in the different Target's c++ source files that don't include
+/// the header forward declaring them.
+#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
+#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS)
+#if defined(_WIN32)
+#if defined(LLVM_ABI_EXPORTS)
+#define LLVM_ABI __declspec(dllexport)
+#define LLVM_TEMPLATE_ABI
+#define LLVM_EXPORT_TEMPLATE LLVM_ABI
+#elif defined(LLVM_DLL_IMPORT)
+#define LLVM_ABI __declspec(dllimport)
+#define LLVM_TEMPLATE_ABI __declspec(dllimport)
+#define LLVM_EXPORT_TEMPLATE
+#else
+#define LLVM_ABI
+#define LLVM_TEMPLATE_ABI
+#define LLVM_EXPORT_TEMPLATE
+#endif
+#elif defined(__ELF__)
+#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
+#define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
+#define LLVM_EXPORT_TEMPLATE
+#elif defined(__MACH__) || defined(__WASM__)
+#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
+#define LLVM_TEMPLATE_ABI
+#define LLVM_EXPORT_TEMPLATE
+#endif
+#define LLVM_C_ABI LLVM_ABI
+#define LLVM_CLASS_ABI LLVM_ABI
+#else
+#define LLVM_C_ABI
+#define LLVM_ABI
+#define LLVM_CLASS_ABI
+#define LLVM_TEMPLATE_ABI
+#define LLVM_EXPORT_TEMPLATE
+#endif
+#endif
+
#if defined(__GNUC__)
#define LLVM_PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality)
#else
>From aa6c3bf4c6fb3e0a2c26277c33bf4ba9d0cfd0f7 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Tue, 18 Jun 2024 14:34:13 +0100
Subject: [PATCH 08/25] Disable noisy 'needs to have dll-interface to be used
by clients' MSVC warning
This get spammed a lot for class fields with a templated type even if there private it seems.
We only selectively export classes with out of line members so this can be trigged a lot classes
that don't need exporting.
---
llvm/cmake/modules/HandleLLVMOptions.cmake | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 5ca580fbb59c5..46f51bb588fbe 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -754,6 +754,9 @@ if (MSVC)
# any code that uses the LLVM_ALIGNAS macro), so this is must be disabled to
# avoid unwanted alignment warnings.
-wd4324 # Suppress 'structure was padded due to __declspec(align())'
+ # This is triggered for every variable that is a template type of a class even
+ # if there private when the class is dllexport'ed
+ -wd4251 # Suppress 'needs to have dll-interface to be used by clients'
# Promoted warnings.
-w14062 # Promote 'enumerator in switch of enum is not handled' to level 1 warning.
>From 794afb20b854b894252c14e088f24845e4660a27 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Tue, 18 Jun 2024 14:35:03 +0100
Subject: [PATCH 09/25] Disable the MSVC warning C4275 non dll-interface class
used as base for dll-interface class
We only selectively put dll export on classes\structs who have out of line members
so this get triggered a lot for bases classes that don't need anything exported.
---
llvm/cmake/modules/HandleLLVMOptions.cmake | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 46f51bb588fbe..2da9dae343e4b 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -757,6 +757,9 @@ if (MSVC)
# This is triggered for every variable that is a template type of a class even
# if there private when the class is dllexport'ed
-wd4251 # Suppress 'needs to have dll-interface to be used by clients'
+ # We only putting dll export on classes with out of line members so this
+ # warning gets triggered a lot for bases we haven't exported'
+ -wd4275 # non dll-interface class used as base for dll-interface class
# Promoted warnings.
-w14062 # Promote 'enumerator in switch of enum is not handled' to level 1 warning.
>From d7817357716527d483822c55cd04011af6888495 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Mon, 17 Jun 2024 14:14:17 +0100
Subject: [PATCH 10/25] Replace LLVM_EXTERNAL_VISIBILITY with new export macros
---
llvm/include/llvm/CodeGen/MachineFunction.h | 2 +-
llvm/include/llvm/IR/Function.h | 4 ++--
llvm/include/llvm/IR/Module.h | 2 +-
llvm/include/llvm/Support/Compiler.h | 6 ------
4 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h
index 6e7292abeddbb..7952e60f37769 100644
--- a/llvm/include/llvm/CodeGen/MachineFunction.h
+++ b/llvm/include/llvm/CodeGen/MachineFunction.h
@@ -255,7 +255,7 @@ struct LandingPadInfo {
: LandingPadBlock(MBB) {}
};
-class LLVM_EXTERNAL_VISIBILITY MachineFunction {
+class LLVM_CLASS_ABI MachineFunction {
Function &F;
const LLVMTargetMachine &Target;
const TargetSubtargetInfo *STI;
diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h
index 5468cedb0815a..cfc168a9d166d 100644
--- a/llvm/include/llvm/IR/Function.h
+++ b/llvm/include/llvm/IR/Function.h
@@ -59,8 +59,8 @@ class User;
class BranchProbabilityInfo;
class BlockFrequencyInfo;
-class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject,
- public ilist_node<Function> {
+class LLVM_CLASS_ABI Function : public GlobalObject,
+ public ilist_node<Function> {
public:
using BasicBlockListType = SymbolTableList<BasicBlock>;
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 6135e15fd030f..f47398cd9d907 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -62,7 +62,7 @@ class VersionTuple;
/// constant references to global variables in the module. When a global
/// variable is destroyed, it should have no entries in the GlobalList.
/// The main container class for the LLVM Intermediate Representation.
-class LLVM_EXTERNAL_VISIBILITY Module {
+class LLVM_CLASS_ABI Module {
/// @name Types And Enumerations
/// @{
public:
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index 3eaff49b5e4ec..cea1b03dcc9ca 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -129,14 +129,8 @@
#if (!(defined(_WIN32) || defined(__CYGWIN__)) || \
(defined(__MINGW32__) && defined(__clang__)))
#define LLVM_LIBRARY_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
-#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS)
-#define LLVM_EXTERNAL_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
-#else
-#define LLVM_EXTERNAL_VISIBILITY
-#endif
#else
#define LLVM_LIBRARY_VISIBILITY
-#define LLVM_EXTERNAL_VISIBILITY
#endif
/// LLVM_ABI is the main export/visibility macro to mark something as explicitly
>From a03c5b19b721946df4eafb5c2c67ff1746062136 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Mon, 17 Jun 2024 05:48:20 +0100
Subject: [PATCH 11/25] Replace LLVM_EXTERNAL_VISIBILITY with LLVM_C_ABI for
X86 Target LLVMInitialize* functions
---
llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp | 2 +-
llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp | 2 +-
llvm/lib/Target/X86/MCA/X86CustomBehaviour.cpp | 2 +-
llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp | 2 +-
llvm/lib/Target/X86/TargetInfo/X86TargetInfo.cpp | 2 +-
llvm/lib/Target/X86/X86AsmPrinter.cpp | 2 +-
llvm/lib/Target/X86/X86TargetMachine.cpp | 2 +-
7 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
index c0f54b223877c..486ae17b8b76c 100644
--- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -4924,7 +4924,7 @@ bool X86AsmParser::parseDirectiveSEHPushFrame(SMLoc Loc) {
}
// Force static initialization.
-extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86AsmParser() {
+extern "C" LLVM_C_ABI void LLVMInitializeX86AsmParser() {
RegisterMCAsmParser<X86AsmParser> X(getTheX86_32Target());
RegisterMCAsmParser<X86AsmParser> Y(getTheX86_64Target());
}
diff --git a/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp b/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
index 6272e2d270f25..9a473784a8d40 100644
--- a/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
+++ b/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
@@ -2470,7 +2470,7 @@ static MCDisassembler *createX86Disassembler(const Target &T,
return new X86GenericDisassembler(STI, Ctx, std::move(MII));
}
-extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86Disassembler() {
+extern "C" LLVM_C_ABI void LLVMInitializeX86Disassembler() {
// Register the disassembler.
TargetRegistry::RegisterMCDisassembler(getTheX86_32Target(),
createX86Disassembler);
diff --git a/llvm/lib/Target/X86/MCA/X86CustomBehaviour.cpp b/llvm/lib/Target/X86/MCA/X86CustomBehaviour.cpp
index 84a3ee3ef27e0..28aceb0659325 100644
--- a/llvm/lib/Target/X86/MCA/X86CustomBehaviour.cpp
+++ b/llvm/lib/Target/X86/MCA/X86CustomBehaviour.cpp
@@ -56,7 +56,7 @@ static InstrPostProcess *createX86InstrPostProcess(const MCSubtargetInfo &STI,
/// Extern function to initialize the targets for the X86 backend
-extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86TargetMCA() {
+extern "C" LLVM_C_ABI void LLVMInitializeX86TargetMCA() {
TargetRegistry::RegisterInstrPostProcess(getTheX86_32Target(),
createX86InstrPostProcess);
TargetRegistry::RegisterInstrPostProcess(getTheX86_64Target(),
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
index ed4d0a45bd8f2..04adf9a787ef2 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
@@ -710,7 +710,7 @@ static MCInstrAnalysis *createX86MCInstrAnalysis(const MCInstrInfo *Info) {
}
// Force static initialization.
-extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86TargetMC() {
+extern "C" LLVM_C_ABI void LLVMInitializeX86TargetMC() {
for (Target *T : {&getTheX86_32Target(), &getTheX86_64Target()}) {
// Register the MC asm info.
RegisterMCAsmInfoFn X(*T, createX86MCAsmInfo);
diff --git a/llvm/lib/Target/X86/TargetInfo/X86TargetInfo.cpp b/llvm/lib/Target/X86/TargetInfo/X86TargetInfo.cpp
index 7490703251e9c..c8df3c29bb046 100644
--- a/llvm/lib/Target/X86/TargetInfo/X86TargetInfo.cpp
+++ b/llvm/lib/Target/X86/TargetInfo/X86TargetInfo.cpp
@@ -19,7 +19,7 @@ Target &llvm::getTheX86_64Target() {
return TheX86_64Target;
}
-extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86TargetInfo() {
+extern "C" LLVM_C_ABI void LLVMInitializeX86TargetInfo() {
RegisterTarget<Triple::x86, /*HasJIT=*/true> X(
getTheX86_32Target(), "x86", "32-bit X86: Pentium-Pro and above", "X86");
diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp
index 3395a13545e45..97d320b9a48d1 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp
@@ -1040,7 +1040,7 @@ void X86AsmPrinter::emitEndOfAsmFile(Module &M) {
//===----------------------------------------------------------------------===//
// Force static initialization.
-extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86AsmPrinter() {
+extern "C" LLVM_C_ABI void LLVMInitializeX86AsmPrinter() {
RegisterAsmPrinter<X86AsmPrinter> X(getTheX86_32Target());
RegisterAsmPrinter<X86AsmPrinter> Y(getTheX86_64Target());
}
diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp
index d4e642c7df9cf..a7966ec55bb43 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.cpp
+++ b/llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -65,7 +65,7 @@ static cl::opt<bool>
cl::desc("Enable the tile register allocation pass"),
cl::init(true), cl::Hidden);
-extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86Target() {
+extern "C" LLVM_C_ABI void LLVMInitializeX86Target() {
// Register the target.
RegisterTargetMachine<X86TargetMachine> X(getTheX86_32Target());
RegisterTargetMachine<X86TargetMachine> Y(getTheX86_64Target());
>From 31317352f2fe5001f9ac5967e5a6f746a134296c Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Sat, 22 Jun 2024 18:47:07 +0100
Subject: [PATCH 12/25] Remove LLVM_LIBRARY_VISIBILITY from public llvm headers
Replace LLVM_LIBRARY_VISIBILITY with LLVM_ABI_NOT_EXPORTED on InstCombiner
---
llvm/include/llvm/Transforms/InstCombine/InstCombiner.h | 2 +-
llvm/include/llvm/Transforms/Scalar/GVN.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
index 855d1aeddfaee..1d82b2cd50e07 100644
--- a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
+++ b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
@@ -44,7 +44,7 @@ class TargetTransformInfo;
///
/// This class provides both the logic to recursively visit instructions and
/// combine them.
-class LLVM_LIBRARY_VISIBILITY InstCombiner {
+class LLVM_ABI_NOT_EXPORTED InstCombiner {
/// Only used to call target specific intrinsic combining.
/// It must **NOT** be used for any other purpose, as InstCombine is a
/// target-independent canonicalization transform.
diff --git a/llvm/include/llvm/Transforms/Scalar/GVN.h b/llvm/include/llvm/Transforms/Scalar/GVN.h
index debe2ee799172..95d903c5b4565 100644
--- a/llvm/include/llvm/Transforms/Scalar/GVN.h
+++ b/llvm/include/llvm/Transforms/Scalar/GVN.h
@@ -56,7 +56,7 @@ class TargetLibraryInfo;
class Value;
/// A private "module" namespace for types and utilities used by GVN. These
/// are implementation details and should not be used by clients.
-namespace LLVM_LIBRARY_VISIBILITY gvn {
+namespace gvn {
struct AvailableValue;
struct AvailableValueInBlock;
>From bc2b76488de4d949fa2a9ce340a4b9dc09196d76 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Mon, 17 Jun 2024 16:54:41 +0100
Subject: [PATCH 13/25] Add LLVM_ALWAYS_EXPORT and use it for
__jit_debug_descriptor and __jit_debug_register_code in ExecutionEngine
---
llvm/include/llvm/Support/Compiler.h | 5 +++++
llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp | 4 ++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index cea1b03dcc9ca..307ab52b714ca 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -129,8 +129,13 @@
#if (!(defined(_WIN32) || defined(__CYGWIN__)) || \
(defined(__MINGW32__) && defined(__clang__)))
#define LLVM_LIBRARY_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
+#define LLVM_ALWAYS_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
+#elif defined(_WIN32)
+#define LLVM_ALWAYS_EXPORT __declspec(dllexport)
+#define LLVM_LIBRARY_VISIBILITY
#else
#define LLVM_LIBRARY_VISIBILITY
+#define LLVM_ALWAYS_EXPORT
#endif
/// LLVM_ABI is the main export/visibility macro to mark something as explicitly
diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp
index 7529d9cef67ed..8136407e4d5b2 100644
--- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp
@@ -26,13 +26,13 @@ extern "C" {
// We put information about the JITed function in this global, which the
// debugger reads. Make sure to specify the version statically, because the
// debugger checks the version before we can set it during runtime.
-LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
+LLVM_ALWAYS_EXPORT
struct jit_descriptor __jit_debug_descriptor = {JitDescriptorVersion, 0,
nullptr, nullptr};
// Debuggers that implement the GDB JIT interface put a special breakpoint in
// this function.
-LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
+LLVM_ALWAYS_EXPORT
LLVM_ATTRIBUTE_NOINLINE void __jit_debug_register_code() {
// The noinline and the asm prevent calls to this function from being
// optimized out.
>From d6d96f5d2ba76391346dda7ad251c7b9c09219ca Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Mon, 24 Jun 2024 21:10:15 +0100
Subject: [PATCH 14/25] Add LLVM_ABI_EXPORT macro that behaves like LLVM_ABI
but is always dllexpot on windows instead of switching to dllimport
Use LLVM_ABI_EXPORT on the declaration llvm plugin's entry point function
llvmGetPassPluginInfo thats exported by plugin built as shared libraries.
---
llvm/include/llvm/Passes/PassPlugin.h | 2 +-
llvm/include/llvm/Support/Compiler.h | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/Passes/PassPlugin.h b/llvm/include/llvm/Passes/PassPlugin.h
index 013b7a827c47d..43310d0b9f14a 100644
--- a/llvm/include/llvm/Passes/PassPlugin.h
+++ b/llvm/include/llvm/Passes/PassPlugin.h
@@ -107,7 +107,7 @@ class PassPlugin {
/// };
/// }
/// ```
-extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
+extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK LLVM_ABI_EXPORT
llvmGetPassPluginInfo();
#endif /* LLVM_PASSES_PASSPLUGIN_H */
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index 307ab52b714ca..285b8b1af367c 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -173,20 +173,24 @@
#define LLVM_TEMPLATE_ABI
#define LLVM_EXPORT_TEMPLATE
#endif
+#define LLVM_ABI_EXPORT __declspec(dllexport)
#elif defined(__ELF__)
#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
#define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
#define LLVM_EXPORT_TEMPLATE
+#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
#elif defined(__MACH__) || defined(__WASM__)
#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
#define LLVM_TEMPLATE_ABI
#define LLVM_EXPORT_TEMPLATE
+#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
#endif
#define LLVM_C_ABI LLVM_ABI
#define LLVM_CLASS_ABI LLVM_ABI
#else
#define LLVM_C_ABI
#define LLVM_ABI
+#define LLVM_ABI_EXPORT
#define LLVM_CLASS_ABI
#define LLVM_TEMPLATE_ABI
#define LLVM_EXPORT_TEMPLATE
>From 70f1363024c87d9c25256a39260e62aabdff22fe Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Fri, 21 Jun 2024 20:14:17 +0100
Subject: [PATCH 15/25] Add LLVM_C_ABI to all macro generated functions created
for Targets.def lists
---
llvm/include/llvm-c/Target.h | 57 ++++++++++++------------
llvm/include/llvm/Support/TargetSelect.h | 15 ++++---
2 files changed, 37 insertions(+), 35 deletions(-)
diff --git a/llvm/include/llvm-c/Target.h b/llvm/include/llvm-c/Target.h
index 518b46d55bc3c..c68eb17189d27 100644
--- a/llvm/include/llvm-c/Target.h
+++ b/llvm/include/llvm-c/Target.h
@@ -39,34 +39,35 @@ typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
/* Declare all of the target-initialization functions that are available. */
#define LLVM_TARGET(TargetName) \
- void LLVMInitialize##TargetName##TargetInfo(void);
+ LLVM_C_ABI void LLVMInitialize##TargetName##TargetInfo(void);
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
-#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
+#define LLVM_TARGET(TargetName) \
+ LLVM_C_ABI void LLVMInitialize##TargetName##Target(void);
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
#define LLVM_TARGET(TargetName) \
- void LLVMInitialize##TargetName##TargetMC(void);
+ LLVM_C_ABI void LLVMInitialize##TargetName##TargetMC(void);
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
/* Declare all of the available assembly printer initialization functions. */
#define LLVM_ASM_PRINTER(TargetName) \
- void LLVMInitialize##TargetName##AsmPrinter(void);
+ LLVM_C_ABI void LLVMInitialize##TargetName##AsmPrinter(void);
#include "llvm/Config/AsmPrinters.def"
#undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
/* Declare all of the available assembly parser initialization functions. */
#define LLVM_ASM_PARSER(TargetName) \
- void LLVMInitialize##TargetName##AsmParser(void);
+ LLVM_C_ABI void LLVMInitialize##TargetName##AsmParser(void);
#include "llvm/Config/AsmParsers.def"
#undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
/* Declare all of the available disassembler initialization functions. */
#define LLVM_DISASSEMBLER(TargetName) \
- void LLVMInitialize##TargetName##Disassembler(void);
+ LLVM_C_ABI void LLVMInitialize##TargetName##Disassembler(void);
#include "llvm/Config/Disassemblers.def"
#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
@@ -183,104 +184,104 @@ static inline LLVMBool LLVMInitializeNativeDisassembler(void) {
*
* @see Module::getDataLayout()
*/
-LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M);
+LLVM_C_ABI LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M);
/**
* Set the data layout for a module.
*
* @see Module::setDataLayout()
*/
-void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL);
+LLVM_C_ABI void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL);
/** Creates target data from a target layout string.
See the constructor llvm::DataLayout::DataLayout. */
-LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
+LLVM_C_ABI LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
/** Deallocates a TargetData.
See the destructor llvm::DataLayout::~DataLayout. */
-void LLVMDisposeTargetData(LLVMTargetDataRef TD);
+LLVM_C_ABI void LLVMDisposeTargetData(LLVMTargetDataRef TD);
/** Adds target library information to a pass manager. This does not take
ownership of the target library info.
See the method llvm::PassManagerBase::add. */
-void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
+LLVM_C_ABI void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
LLVMPassManagerRef PM);
/** Converts target data to a target layout string. The string must be disposed
with LLVMDisposeMessage.
See the constructor llvm::DataLayout::DataLayout. */
-char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD);
+LLVM_C_ABI char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD);
/** Returns the byte order of a target, either LLVMBigEndian or
LLVMLittleEndian.
See the method llvm::DataLayout::isLittleEndian. */
-enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD);
+LLVM_C_ABI enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD);
/** Returns the pointer size in bytes for a target.
See the method llvm::DataLayout::getPointerSize. */
-unsigned LLVMPointerSize(LLVMTargetDataRef TD);
+LLVM_C_ABI unsigned LLVMPointerSize(LLVMTargetDataRef TD);
/** Returns the pointer size in bytes for a target for a specified
address space.
See the method llvm::DataLayout::getPointerSize. */
-unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS);
+LLVM_C_ABI unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS);
/** Returns the integer type that is the same size as a pointer on a target.
See the method llvm::DataLayout::getIntPtrType. */
-LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD);
+LLVM_C_ABI LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD);
/** Returns the integer type that is the same size as a pointer on a target.
This version allows the address space to be specified.
See the method llvm::DataLayout::getIntPtrType. */
-LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS);
+LLVM_C_ABI LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS);
/** Returns the integer type that is the same size as a pointer on a target.
See the method llvm::DataLayout::getIntPtrType. */
-LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD);
+LLVM_C_ABI LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD);
/** Returns the integer type that is the same size as a pointer on a target.
This version allows the address space to be specified.
See the method llvm::DataLayout::getIntPtrType. */
-LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C, LLVMTargetDataRef TD,
+LLVM_C_ABI LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C, LLVMTargetDataRef TD,
unsigned AS);
/** Computes the size of a type in bytes for a target.
See the method llvm::DataLayout::getTypeSizeInBits. */
-unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty);
+LLVM_C_ABI unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the storage size of a type in bytes for a target.
See the method llvm::DataLayout::getTypeStoreSize. */
-unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
+LLVM_C_ABI unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the ABI size of a type in bytes for a target.
See the method llvm::DataLayout::getTypeAllocSize. */
-unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
+LLVM_C_ABI unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the ABI alignment of a type in bytes for a target.
See the method llvm::DataLayout::getTypeABISize. */
-unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
+LLVM_C_ABI unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the call frame alignment of a type in bytes for a target.
See the method llvm::DataLayout::getTypeABISize. */
-unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
+LLVM_C_ABI unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the preferred alignment of a type in bytes for a target.
See the method llvm::DataLayout::getTypeABISize. */
-unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
+LLVM_C_ABI unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the preferred alignment of a global variable in bytes for a target.
See the method llvm::DataLayout::getPreferredAlignment. */
-unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
+LLVM_C_ABI unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
LLVMValueRef GlobalVar);
/** Computes the structure element that contains the byte offset for a target.
See the method llvm::StructLayout::getElementContainingOffset. */
-unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
+LLVM_C_ABI unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
unsigned long long Offset);
/** Computes the byte offset of the indexed struct element for a target.
See the method llvm::StructLayout::getElementContainingOffset. */
-unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD,
+LLVM_C_ABI unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD,
LLVMTypeRef StructTy, unsigned Element);
/**
diff --git a/llvm/include/llvm/Support/TargetSelect.h b/llvm/include/llvm/Support/TargetSelect.h
index e57614cea758b..255b37be5ed90 100644
--- a/llvm/include/llvm/Support/TargetSelect.h
+++ b/llvm/include/llvm/Support/TargetSelect.h
@@ -16,34 +16,35 @@
#define LLVM_SUPPORT_TARGETSELECT_H
#include "llvm/Config/llvm-config.h"
+#include "llvm/Support/Compiler.h"
extern "C" {
// Declare all of the target-initialization functions that are available.
-#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetInfo();
+#define LLVM_TARGET(TargetName) LLVM_C_ABI void LLVMInitialize##TargetName##TargetInfo();
#include "llvm/Config/Targets.def"
-#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
+#define LLVM_TARGET(TargetName) LLVM_C_ABI void LLVMInitialize##TargetName##Target();
#include "llvm/Config/Targets.def"
// Declare all of the target-MC-initialization functions that are available.
-#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetMC();
+#define LLVM_TARGET(TargetName) LLVM_C_ABI void LLVMInitialize##TargetName##TargetMC();
#include "llvm/Config/Targets.def"
// Declare all of the available assembly printer initialization functions.
-#define LLVM_ASM_PRINTER(TargetName) void LLVMInitialize##TargetName##AsmPrinter();
+#define LLVM_ASM_PRINTER(TargetName) LLVM_C_ABI void LLVMInitialize##TargetName##AsmPrinter();
#include "llvm/Config/AsmPrinters.def"
// Declare all of the available assembly parser initialization functions.
-#define LLVM_ASM_PARSER(TargetName) void LLVMInitialize##TargetName##AsmParser();
+#define LLVM_ASM_PARSER(TargetName) LLVM_C_ABI void LLVMInitialize##TargetName##AsmParser();
#include "llvm/Config/AsmParsers.def"
// Declare all of the available disassembler initialization functions.
#define LLVM_DISASSEMBLER(TargetName) \
- void LLVMInitialize##TargetName##Disassembler();
+ LLVM_C_ABI void LLVMInitialize##TargetName##Disassembler();
#include "llvm/Config/Disassemblers.def"
// Declare all of the available TargetMCA initialization functions.
-#define LLVM_TARGETMCA(TargetName) void LLVMInitialize##TargetName##TargetMCA();
+#define LLVM_TARGETMCA(TargetName) LLVM_C_ABI void LLVMInitialize##TargetName##TargetMCA();
#include "llvm/Config/TargetMCAs.def"
}
>From 7c137459e3935726e154c8a4b1a6750cfd0bdfb6 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Mon, 24 Jun 2024 21:11:34 +0100
Subject: [PATCH 16/25] Fix building the LTO shared library on windows using
the wrong export macro by using LLVM_ABI_EXPORT
The functioned declared in llvm-c/lto.h need to declared with dll export when
building the lto shared library while the rest of the llvm API it uses needs to
be dllimport'ed when built with LLVM_BUILD_LLVM_DYLIB.
---
llvm/include/llvm-c/lto.h | 161 ++++++++++++++++++----------------
llvm/tools/lto/CMakeLists.txt | 4 +
2 files changed, 88 insertions(+), 77 deletions(-)
diff --git a/llvm/include/llvm-c/lto.h b/llvm/include/llvm-c/lto.h
index 5ceb02224d2bb..ba286e8e97ea3 100644
--- a/llvm/include/llvm-c/lto.h
+++ b/llvm/include/llvm-c/lto.h
@@ -16,8 +16,15 @@
#ifndef LLVM_C_LTO_H
#define LLVM_C_LTO_H
+#include "llvm/Support/Compiler.h"
#include "llvm-c/ExternC.h"
+#ifdef LLVM_BUILDING_LIBLTO
+#define LLVM_LIBLTO_ABI LLVM_ABI_EXPORT
+#else
+#define LLVM_LIBLTO_ABI LLVM_C_ABI
+#endif
+
#ifdef __cplusplus
#include <cstddef>
#else
@@ -107,7 +114,7 @@ LLVM_C_EXTERN_C_BEGIN
*
* \since prior to LTO_API_VERSION=3
*/
-extern const char*
+LLVM_LIBLTO_ABI extern const char*
lto_get_version(void);
/**
@@ -115,7 +122,7 @@ lto_get_version(void);
*
* \since prior to LTO_API_VERSION=3
*/
-extern const char*
+LLVM_LIBLTO_ABI extern const char*
lto_get_error_message(void);
/**
@@ -123,7 +130,7 @@ lto_get_error_message(void);
*
* \since prior to LTO_API_VERSION=3
*/
-extern lto_bool_t
+LLVM_LIBLTO_ABI extern lto_bool_t
lto_module_is_object_file(const char* path);
/**
@@ -131,7 +138,7 @@ lto_module_is_object_file(const char* path);
*
* \since prior to LTO_API_VERSION=3
*/
-extern lto_bool_t
+LLVM_LIBLTO_ABI extern lto_bool_t
lto_module_is_object_file_for_target(const char* path,
const char* target_triple_prefix);
@@ -141,7 +148,7 @@ lto_module_is_object_file_for_target(const char* path,
*
* \since LTO_API_VERSION=20
*/
-extern lto_bool_t
+LLVM_LIBLTO_ABI extern lto_bool_t
lto_module_has_objc_category(const void *mem, size_t length);
/**
@@ -149,7 +156,7 @@ lto_module_has_objc_category(const void *mem, size_t length);
*
* \since prior to LTO_API_VERSION=3
*/
-extern lto_bool_t lto_module_is_object_file_in_memory(const void *mem,
+LLVM_LIBLTO_ABI extern lto_bool_t lto_module_is_object_file_in_memory(const void *mem,
size_t length);
/**
@@ -157,7 +164,7 @@ extern lto_bool_t lto_module_is_object_file_in_memory(const void *mem,
*
* \since prior to LTO_API_VERSION=3
*/
-extern lto_bool_t
+LLVM_LIBLTO_ABI extern lto_bool_t
lto_module_is_object_file_in_memory_for_target(const void* mem, size_t length,
const char* target_triple_prefix);
@@ -167,7 +174,7 @@ lto_module_is_object_file_in_memory_for_target(const void* mem, size_t length,
*
* \since prior to LTO_API_VERSION=3
*/
-extern lto_module_t
+LLVM_LIBLTO_ABI extern lto_module_t
lto_module_create(const char* path);
/**
@@ -176,7 +183,7 @@ lto_module_create(const char* path);
*
* \since prior to LTO_API_VERSION=3
*/
-extern lto_module_t
+LLVM_LIBLTO_ABI extern lto_module_t
lto_module_create_from_memory(const void* mem, size_t length);
/**
@@ -185,7 +192,7 @@ lto_module_create_from_memory(const void* mem, size_t length);
*
* \since LTO_API_VERSION=9
*/
-extern lto_module_t
+LLVM_LIBLTO_ABI extern lto_module_t
lto_module_create_from_memory_with_path(const void* mem, size_t length,
const char *path);
@@ -200,7 +207,7 @@ lto_module_create_from_memory_with_path(const void* mem, size_t length,
*
* \since LTO_API_VERSION=11
*/
-extern lto_module_t
+LLVM_LIBLTO_ABI extern lto_module_t
lto_module_create_in_local_context(const void *mem, size_t length,
const char *path);
@@ -214,7 +221,7 @@ lto_module_create_in_local_context(const void *mem, size_t length,
*
* \since LTO_API_VERSION=11
*/
-extern lto_module_t
+LLVM_LIBLTO_ABI extern lto_module_t
lto_module_create_in_codegen_context(const void *mem, size_t length,
const char *path, lto_code_gen_t cg);
@@ -224,7 +231,7 @@ lto_module_create_in_codegen_context(const void *mem, size_t length,
*
* \since LTO_API_VERSION=5
*/
-extern lto_module_t
+LLVM_LIBLTO_ABI extern lto_module_t
lto_module_create_from_fd(int fd, const char *path, size_t file_size);
/**
@@ -233,7 +240,7 @@ lto_module_create_from_fd(int fd, const char *path, size_t file_size);
*
* \since LTO_API_VERSION=5
*/
-extern lto_module_t
+LLVM_LIBLTO_ABI extern lto_module_t
lto_module_create_from_fd_at_offset(int fd, const char *path, size_t file_size,
size_t map_size, off_t offset);
@@ -243,7 +250,7 @@ lto_module_create_from_fd_at_offset(int fd, const char *path, size_t file_size,
*
* \since prior to LTO_API_VERSION=3
*/
-extern void
+LLVM_LIBLTO_ABI extern void
lto_module_dispose(lto_module_t mod);
/**
@@ -251,7 +258,7 @@ lto_module_dispose(lto_module_t mod);
*
* \since prior to LTO_API_VERSION=3
*/
-extern const char*
+LLVM_LIBLTO_ABI extern const char*
lto_module_get_target_triple(lto_module_t mod);
/**
@@ -259,7 +266,7 @@ lto_module_get_target_triple(lto_module_t mod);
*
* \since LTO_API_VERSION=4
*/
-extern void
+LLVM_LIBLTO_ABI extern void
lto_module_set_target_triple(lto_module_t mod, const char *triple);
/**
@@ -267,7 +274,7 @@ lto_module_set_target_triple(lto_module_t mod, const char *triple);
*
* \since prior to LTO_API_VERSION=3
*/
-extern unsigned int
+LLVM_LIBLTO_ABI extern unsigned int
lto_module_get_num_symbols(lto_module_t mod);
/**
@@ -275,7 +282,7 @@ lto_module_get_num_symbols(lto_module_t mod);
*
* \since prior to LTO_API_VERSION=3
*/
-extern const char*
+LLVM_LIBLTO_ABI extern const char*
lto_module_get_symbol_name(lto_module_t mod, unsigned int index);
/**
@@ -283,7 +290,7 @@ lto_module_get_symbol_name(lto_module_t mod, unsigned int index);
*
* \since prior to LTO_API_VERSION=3
*/
-extern lto_symbol_attributes
+LLVM_LIBLTO_ABI extern lto_symbol_attributes
lto_module_get_symbol_attribute(lto_module_t mod, unsigned int index);
/**
@@ -294,7 +301,7 @@ lto_module_get_symbol_attribute(lto_module_t mod, unsigned int index);
*
* \since LTO_API_VERSION=16
*/
-extern const char*
+LLVM_LIBLTO_ABI extern const char*
lto_module_get_linkeropts(lto_module_t mod);
/**
@@ -308,7 +315,7 @@ lto_module_get_linkeropts(lto_module_t mod);
*
* \since LTO_API_VERSION=27
*/
-extern lto_bool_t lto_module_get_macho_cputype(lto_module_t mod,
+LLVM_LIBLTO_ABI extern lto_bool_t lto_module_get_macho_cputype(lto_module_t mod,
unsigned int *out_cputype,
unsigned int *out_cpusubtype);
@@ -321,7 +328,7 @@ extern lto_bool_t lto_module_get_macho_cputype(lto_module_t mod,
*
* \since LTO_API_VERSION=29
*/
-extern lto_bool_t lto_module_has_ctor_dtor(lto_module_t mod);
+LLVM_LIBLTO_ABI extern lto_bool_t lto_module_has_ctor_dtor(lto_module_t mod);
/**
* Diagnostic severity.
*
@@ -353,7 +360,7 @@ typedef void (*lto_diagnostic_handler_t)(
*
* \since LTO_API_VERSION=7
*/
-extern void lto_codegen_set_diagnostic_handler(lto_code_gen_t,
+LLVM_LIBLTO_ABI extern void lto_codegen_set_diagnostic_handler(lto_code_gen_t,
lto_diagnostic_handler_t,
void *);
@@ -366,7 +373,7 @@ extern void lto_codegen_set_diagnostic_handler(lto_code_gen_t,
*
* \since prior to LTO_API_VERSION=3
*/
-extern lto_code_gen_t
+LLVM_LIBLTO_ABI extern lto_code_gen_t
lto_codegen_create(void);
/**
@@ -378,7 +385,7 @@ lto_codegen_create(void);
*
* \since LTO_API_VERSION=11
*/
-extern lto_code_gen_t
+LLVM_LIBLTO_ABI extern lto_code_gen_t
lto_codegen_create_in_local_context(void);
/**
@@ -387,7 +394,7 @@ lto_codegen_create_in_local_context(void);
*
* \since prior to LTO_API_VERSION=3
*/
-extern void
+LLVM_LIBLTO_ABI extern void
lto_codegen_dispose(lto_code_gen_t);
/**
@@ -400,7 +407,7 @@ lto_codegen_dispose(lto_code_gen_t);
*
* \since prior to LTO_API_VERSION=3
*/
-extern lto_bool_t
+LLVM_LIBLTO_ABI extern lto_bool_t
lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod);
/**
@@ -411,7 +418,7 @@ lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod);
*
* \since LTO_API_VERSION=13
*/
-extern void
+LLVM_LIBLTO_ABI extern void
lto_codegen_set_module(lto_code_gen_t cg, lto_module_t mod);
/**
@@ -420,7 +427,7 @@ lto_codegen_set_module(lto_code_gen_t cg, lto_module_t mod);
*
* \since prior to LTO_API_VERSION=3
*/
-extern lto_bool_t
+LLVM_LIBLTO_ABI extern lto_bool_t
lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model);
/**
@@ -429,7 +436,7 @@ lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model);
*
* \since prior to LTO_API_VERSION=3
*/
-extern lto_bool_t
+LLVM_LIBLTO_ABI extern lto_bool_t
lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model);
/**
@@ -437,7 +444,7 @@ lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model);
*
* \since LTO_API_VERSION=4
*/
-extern void
+LLVM_LIBLTO_ABI extern void
lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu);
/**
@@ -446,7 +453,7 @@ lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu);
*
* \since LTO_API_VERSION=3
*/
-extern void
+LLVM_LIBLTO_ABI extern void
lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path);
/**
@@ -454,7 +461,7 @@ lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path);
*
* \since LTO_API_VERSION=4
*/
-extern void
+LLVM_LIBLTO_ABI extern void
lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args,
int nargs);
@@ -465,7 +472,7 @@ lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args,
*
* \since prior to LTO_API_VERSION=3
*/
-extern void
+LLVM_LIBLTO_ABI extern void
lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol);
/**
@@ -475,7 +482,7 @@ lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol);
*
* \since LTO_API_VERSION=5
*/
-extern lto_bool_t
+LLVM_LIBLTO_ABI extern lto_bool_t
lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path);
/**
@@ -490,7 +497,7 @@ lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path);
*
* \since prior to LTO_API_VERSION=3
*/
-extern const void*
+LLVM_LIBLTO_ABI extern const void*
lto_codegen_compile(lto_code_gen_t cg, size_t* length);
/**
@@ -502,7 +509,7 @@ lto_codegen_compile(lto_code_gen_t cg, size_t* length);
*
* \since LTO_API_VERSION=5
*/
-extern lto_bool_t
+LLVM_LIBLTO_ABI extern lto_bool_t
lto_codegen_compile_to_file(lto_code_gen_t cg, const char** name);
/**
@@ -510,7 +517,7 @@ lto_codegen_compile_to_file(lto_code_gen_t cg, const char** name);
*
* \since LTO_API_VERSION=12
*/
-extern lto_bool_t
+LLVM_LIBLTO_ABI extern lto_bool_t
lto_codegen_optimize(lto_code_gen_t cg);
/**
@@ -525,7 +532,7 @@ lto_codegen_optimize(lto_code_gen_t cg);
*
* \since LTO_API_VERSION=12
*/
-extern const void*
+LLVM_LIBLTO_ABI extern const void*
lto_codegen_compile_optimized(lto_code_gen_t cg, size_t* length);
/**
@@ -533,7 +540,7 @@ lto_codegen_compile_optimized(lto_code_gen_t cg, size_t* length);
*
* \since LTO_API_VERSION=12
*/
-extern unsigned int
+LLVM_LIBLTO_ABI extern unsigned int
lto_api_version(void);
/**
@@ -548,7 +555,7 @@ lto_api_version(void);
*
* \since LTO_API_VERSION=28
*/
-extern void lto_set_debug_options(const char *const *options, int number);
+LLVM_LIBLTO_ABI extern void lto_set_debug_options(const char *const *options, int number);
/**
* Sets options to help debug codegen bugs. Since parsing shud only happen once,
@@ -561,7 +568,7 @@ extern void lto_set_debug_options(const char *const *options, int number);
*
* \since prior to LTO_API_VERSION=3
*/
-extern void
+LLVM_LIBLTO_ABI extern void
lto_codegen_debug_options(lto_code_gen_t cg, const char *);
/**
@@ -570,7 +577,7 @@ lto_codegen_debug_options(lto_code_gen_t cg, const char *);
*
* \since prior to LTO_API_VERSION=26
*/
-extern void lto_codegen_debug_options_array(lto_code_gen_t cg,
+LLVM_LIBLTO_ABI extern void lto_codegen_debug_options_array(lto_code_gen_t cg,
const char *const *, int number);
/**
@@ -579,7 +586,7 @@ extern void lto_codegen_debug_options_array(lto_code_gen_t cg,
*
* \since LTO_API_VERSION=5
*/
-extern void
+LLVM_LIBLTO_ABI extern void
lto_initialize_disassembler(void);
/**
@@ -588,7 +595,7 @@ lto_initialize_disassembler(void);
*
* \since LTO_API_VERSION=14
*/
-extern void
+LLVM_LIBLTO_ABI extern void
lto_codegen_set_should_internalize(lto_code_gen_t cg,
lto_bool_t ShouldInternalize);
@@ -600,7 +607,7 @@ lto_codegen_set_should_internalize(lto_code_gen_t cg,
*
* \since LTO_API_VERSION=15
*/
-extern void
+LLVM_LIBLTO_ABI extern void
lto_codegen_set_should_embed_uselists(lto_code_gen_t cg,
lto_bool_t ShouldEmbedUselists);
@@ -615,7 +622,7 @@ typedef struct LLVMOpaqueLTOInput *lto_input_t;
*
* \since LTO_API_VERSION=24
*/
-extern lto_input_t lto_input_create(const void *buffer,
+LLVM_LIBLTO_ABI extern lto_input_t lto_input_create(const void *buffer,
size_t buffer_size,
const char *path);
@@ -625,7 +632,7 @@ extern lto_input_t lto_input_create(const void *buffer,
*
* \since LTO_API_VERSION=24
*/
-extern void lto_input_dispose(lto_input_t input);
+LLVM_LIBLTO_ABI extern void lto_input_dispose(lto_input_t input);
/**
* Returns the number of dependent library specifiers
@@ -633,7 +640,7 @@ extern void lto_input_dispose(lto_input_t input);
*
* \since LTO_API_VERSION=24
*/
-extern unsigned lto_input_get_num_dependent_libraries(lto_input_t input);
+LLVM_LIBLTO_ABI extern unsigned lto_input_get_num_dependent_libraries(lto_input_t input);
/**
* Returns the ith dependent library specifier
@@ -642,7 +649,7 @@ extern unsigned lto_input_get_num_dependent_libraries(lto_input_t input);
*
* \since LTO_API_VERSION=24
*/
-extern const char * lto_input_get_dependent_library(lto_input_t input,
+LLVM_LIBLTO_ABI extern const char * lto_input_get_dependent_library(lto_input_t input,
size_t index,
size_t *size);
@@ -652,7 +659,7 @@ extern const char * lto_input_get_dependent_library(lto_input_t input,
*
* \since prior to LTO_API_VERSION=25
*/
-extern const char *const *lto_runtime_lib_symbols_list(size_t *size);
+LLVM_LIBLTO_ABI extern const char *const *lto_runtime_lib_symbols_list(size_t *size);
/**
* @} // endgoup LLVMCLTO
@@ -684,7 +691,7 @@ typedef struct {
*
* \since LTO_API_VERSION=18
*/
-extern thinlto_code_gen_t thinlto_create_codegen(void);
+LLVM_LIBLTO_ABI extern thinlto_code_gen_t thinlto_create_codegen(void);
/**
* Frees the generator and all memory it internally allocated.
@@ -692,7 +699,7 @@ extern thinlto_code_gen_t thinlto_create_codegen(void);
*
* \since LTO_API_VERSION=18
*/
-extern void thinlto_codegen_dispose(thinlto_code_gen_t cg);
+LLVM_LIBLTO_ABI extern void thinlto_codegen_dispose(thinlto_code_gen_t cg);
/**
* Add a module to a ThinLTO code generator. Identifier has to be unique among
@@ -705,7 +712,7 @@ extern void thinlto_codegen_dispose(thinlto_code_gen_t cg);
*
* \since LTO_API_VERSION=18
*/
-extern void thinlto_codegen_add_module(thinlto_code_gen_t cg,
+LLVM_LIBLTO_ABI extern void thinlto_codegen_add_module(thinlto_code_gen_t cg,
const char *identifier, const char *data,
int length);
@@ -715,7 +722,7 @@ extern void thinlto_codegen_add_module(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=18
*/
-extern void thinlto_codegen_process(thinlto_code_gen_t cg);
+LLVM_LIBLTO_ABI extern void thinlto_codegen_process(thinlto_code_gen_t cg);
/**
* Returns the number of object files produced by the ThinLTO CodeGenerator.
@@ -726,7 +733,7 @@ extern void thinlto_codegen_process(thinlto_code_gen_t cg);
*
* \since LTO_API_VERSION=18
*/
-extern unsigned int thinlto_module_get_num_objects(thinlto_code_gen_t cg);
+LLVM_LIBLTO_ABI extern unsigned int thinlto_module_get_num_objects(thinlto_code_gen_t cg);
/**
* Returns a reference to the ith object file produced by the ThinLTO
@@ -737,7 +744,7 @@ extern unsigned int thinlto_module_get_num_objects(thinlto_code_gen_t cg);
*
* \since LTO_API_VERSION=18
*/
-extern LTOObjectBuffer thinlto_module_get_object(thinlto_code_gen_t cg,
+LLVM_LIBLTO_ABI extern LTOObjectBuffer thinlto_module_get_object(thinlto_code_gen_t cg,
unsigned int index);
/**
@@ -749,7 +756,7 @@ extern LTOObjectBuffer thinlto_module_get_object(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=21
*/
-unsigned int thinlto_module_get_num_object_files(thinlto_code_gen_t cg);
+LLVM_LIBLTO_ABI unsigned int thinlto_module_get_num_object_files(thinlto_code_gen_t cg);
/**
* Returns the path to the ith object file produced by the ThinLTO
@@ -760,7 +767,7 @@ unsigned int thinlto_module_get_num_object_files(thinlto_code_gen_t cg);
*
* \since LTO_API_VERSION=21
*/
-const char *thinlto_module_get_object_file(thinlto_code_gen_t cg,
+LLVM_LIBLTO_ABI const char *thinlto_module_get_object_file(thinlto_code_gen_t cg,
unsigned int index);
/**
@@ -769,7 +776,7 @@ const char *thinlto_module_get_object_file(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=18
*/
-extern lto_bool_t thinlto_codegen_set_pic_model(thinlto_code_gen_t cg,
+LLVM_LIBLTO_ABI extern lto_bool_t thinlto_codegen_set_pic_model(thinlto_code_gen_t cg,
lto_codegen_model);
/**
@@ -779,7 +786,7 @@ extern lto_bool_t thinlto_codegen_set_pic_model(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=18
*/
-extern void thinlto_codegen_set_savetemps_dir(thinlto_code_gen_t cg,
+LLVM_LIBLTO_ABI extern void thinlto_codegen_set_savetemps_dir(thinlto_code_gen_t cg,
const char *save_temps_dir);
/**
@@ -790,7 +797,7 @@ extern void thinlto_codegen_set_savetemps_dir(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=21
*/
-void thinlto_set_generated_objects_dir(thinlto_code_gen_t cg,
+LLVM_LIBLTO_ABI void thinlto_set_generated_objects_dir(thinlto_code_gen_t cg,
const char *save_temps_dir);
/**
@@ -798,7 +805,7 @@ void thinlto_set_generated_objects_dir(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=18
*/
-extern void thinlto_codegen_set_cpu(thinlto_code_gen_t cg, const char *cpu);
+LLVM_LIBLTO_ABI extern void thinlto_codegen_set_cpu(thinlto_code_gen_t cg, const char *cpu);
/**
* Disable CodeGen, only run the stages till codegen and stop. The output will
@@ -806,7 +813,7 @@ extern void thinlto_codegen_set_cpu(thinlto_code_gen_t cg, const char *cpu);
*
* \since LTO_API_VERSION=19
*/
-extern void thinlto_codegen_disable_codegen(thinlto_code_gen_t cg,
+LLVM_LIBLTO_ABI extern void thinlto_codegen_disable_codegen(thinlto_code_gen_t cg,
lto_bool_t disable);
/**
@@ -814,7 +821,7 @@ extern void thinlto_codegen_disable_codegen(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=19
*/
-extern void thinlto_codegen_set_codegen_only(thinlto_code_gen_t cg,
+LLVM_LIBLTO_ABI extern void thinlto_codegen_set_codegen_only(thinlto_code_gen_t cg,
lto_bool_t codegen_only);
/**
@@ -822,14 +829,14 @@ extern void thinlto_codegen_set_codegen_only(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=18
*/
-extern void thinlto_debug_options(const char *const *options, int number);
+LLVM_LIBLTO_ABI extern void thinlto_debug_options(const char *const *options, int number);
/**
* Test if a module has support for ThinLTO linking.
*
* \since LTO_API_VERSION=18
*/
-extern lto_bool_t lto_module_is_thinlto(lto_module_t mod);
+LLVM_LIBLTO_ABI extern lto_bool_t lto_module_is_thinlto(lto_module_t mod);
/**
* Adds a symbol to the list of global symbols that must exist in the final
@@ -839,7 +846,7 @@ extern lto_bool_t lto_module_is_thinlto(lto_module_t mod);
*
* \since LTO_API_VERSION=18
*/
-extern void thinlto_codegen_add_must_preserve_symbol(thinlto_code_gen_t cg,
+LLVM_LIBLTO_ABI extern void thinlto_codegen_add_must_preserve_symbol(thinlto_code_gen_t cg,
const char *name,
int length);
@@ -851,7 +858,7 @@ extern void thinlto_codegen_add_must_preserve_symbol(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=18
*/
-extern void thinlto_codegen_add_cross_referenced_symbol(thinlto_code_gen_t cg,
+LLVM_LIBLTO_ABI extern void thinlto_codegen_add_cross_referenced_symbol(thinlto_code_gen_t cg,
const char *name,
int length);
@@ -882,7 +889,7 @@ extern void thinlto_codegen_add_cross_referenced_symbol(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=18
*/
-extern void thinlto_codegen_set_cache_dir(thinlto_code_gen_t cg,
+LLVM_LIBLTO_ABI extern void thinlto_codegen_set_cache_dir(thinlto_code_gen_t cg,
const char *cache_dir);
/**
@@ -892,7 +899,7 @@ extern void thinlto_codegen_set_cache_dir(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=18
*/
-extern void thinlto_codegen_set_cache_pruning_interval(thinlto_code_gen_t cg,
+LLVM_LIBLTO_ABI extern void thinlto_codegen_set_cache_pruning_interval(thinlto_code_gen_t cg,
int interval);
/**
@@ -908,7 +915,7 @@ extern void thinlto_codegen_set_cache_pruning_interval(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=18
*/
-extern void thinlto_codegen_set_final_cache_size_relative_to_available_space(
+LLVM_LIBLTO_ABI extern void thinlto_codegen_set_final_cache_size_relative_to_available_space(
thinlto_code_gen_t cg, unsigned percentage);
/**
@@ -917,7 +924,7 @@ extern void thinlto_codegen_set_final_cache_size_relative_to_available_space(
*
* \since LTO_API_VERSION=18
*/
-extern void thinlto_codegen_set_cache_entry_expiration(thinlto_code_gen_t cg,
+LLVM_LIBLTO_ABI extern void thinlto_codegen_set_cache_entry_expiration(thinlto_code_gen_t cg,
unsigned expiration);
/**
@@ -928,7 +935,7 @@ extern void thinlto_codegen_set_cache_entry_expiration(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=22
*/
-extern void thinlto_codegen_set_cache_size_bytes(thinlto_code_gen_t cg,
+LLVM_LIBLTO_ABI extern void thinlto_codegen_set_cache_size_bytes(thinlto_code_gen_t cg,
unsigned max_size_bytes);
/**
@@ -937,7 +944,7 @@ extern void thinlto_codegen_set_cache_size_bytes(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=23
*/
-extern void
+LLVM_LIBLTO_ABI extern void
thinlto_codegen_set_cache_size_megabytes(thinlto_code_gen_t cg,
unsigned max_size_megabytes);
@@ -947,7 +954,7 @@ thinlto_codegen_set_cache_size_megabytes(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=22
*/
-extern void thinlto_codegen_set_cache_size_files(thinlto_code_gen_t cg,
+LLVM_LIBLTO_ABI extern void thinlto_codegen_set_cache_size_files(thinlto_code_gen_t cg,
unsigned max_size_files);
/**
diff --git a/llvm/tools/lto/CMakeLists.txt b/llvm/tools/lto/CMakeLists.txt
index 67f6d3af40e05..1983fc008c9ee 100644
--- a/llvm/tools/lto/CMakeLists.txt
+++ b/llvm/tools/lto/CMakeLists.txt
@@ -32,6 +32,10 @@ endif()
add_llvm_library(${LTO_LIBRARY_NAME} ${LTO_LIBRARY_TYPE} INSTALL_WITH_TOOLCHAIN
${SOURCES} DEPENDS intrinsics_gen)
+if (LLVM_BUILD_LLVM_DYLIB)
+ target_compile_definitions(${LTO_LIBRARY_NAME} PRIVATE LLVM_BUILDING_LIBLTO)
+endif()
+
install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/lto.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/llvm-c"
COMPONENT LTO)
>From ee1b6d53aa1c51703b71e20f72c8a4d9ccf4217b Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Mon, 24 Jun 2024 18:34:19 +0100
Subject: [PATCH 17/25] Add example usage of template export macros for
SmallVectorBase
---
llvm/include/llvm/ADT/SmallVector.h | 4 ++--
llvm/lib/Support/SmallVector.cpp | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index 09676d792dfeb..7443e77591f4f 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -1327,9 +1327,9 @@ template <typename Out, typename R> SmallVector<Out> to_vector_of(R &&Range) {
}
// Explicit instantiations
-extern template class llvm::SmallVectorBase<uint32_t>;
+extern template class LLVM_TEMPLATE_ABI llvm::SmallVectorBase<uint32_t>;
#if SIZE_MAX > UINT32_MAX
-extern template class llvm::SmallVectorBase<uint64_t>;
+extern template class LLVM_TEMPLATE_ABI llvm::SmallVectorBase<uint64_t>;
#endif
} // end namespace llvm
diff --git a/llvm/lib/Support/SmallVector.cpp b/llvm/lib/Support/SmallVector.cpp
index b6ce37842040b..6593dc31cb5e0 100644
--- a/llvm/lib/Support/SmallVector.cpp
+++ b/llvm/lib/Support/SmallVector.cpp
@@ -156,14 +156,14 @@ void SmallVectorBase<Size_T>::grow_pod(void *FirstEl, size_t MinSize,
this->set_allocation_range(NewElts, NewCapacity);
}
-template class llvm::SmallVectorBase<uint32_t>;
+template class LLVM_EXPORT_TEMPLATE llvm::SmallVectorBase<uint32_t>;
// Disable the uint64_t instantiation for 32-bit builds.
// Both uint32_t and uint64_t instantiations are needed for 64-bit builds.
// This instantiation will never be used in 32-bit builds, and will cause
// warnings when sizeof(Size_T) > sizeof(size_t).
#if SIZE_MAX > UINT32_MAX
-template class llvm::SmallVectorBase<uint64_t>;
+template class LLVM_EXPORT_TEMPLATE llvm::SmallVectorBase<uint64_t>;
// Assertions to ensure this #if stays in sync with SmallVectorSizeType.
static_assert(sizeof(SmallVectorSizeType<char>) == sizeof(uint64_t),
>From be598348da0cbc4ef1249ba4246712dc3327acff Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Sun, 23 Jun 2024 15:16:01 +0100
Subject: [PATCH 18/25] Add manual export macros for blake3 llvm-c API and work
around it not being created with llvm_add_library cmake target
The llvm-c header that would forward declare them with export macros is not included
by the source file so we have to manually annotate each function.
---
llvm/lib/Support/BLAKE3/CMakeLists.txt | 5 +++++
llvm/lib/Support/BLAKE3/blake3.c | 16 ++++++++--------
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/llvm/lib/Support/BLAKE3/CMakeLists.txt b/llvm/lib/Support/BLAKE3/CMakeLists.txt
index 51317b8048f76..9a253cd4fc236 100644
--- a/llvm/lib/Support/BLAKE3/CMakeLists.txt
+++ b/llvm/lib/Support/BLAKE3/CMakeLists.txt
@@ -81,3 +81,8 @@ endif()
add_library(LLVMSupportBlake3 OBJECT EXCLUDE_FROM_ALL ${LLVM_BLAKE3_FILES})
set_target_properties(LLVMSupportBlake3 PROPERTIES FOLDER "LLVM/Libraries")
llvm_update_compile_flags(LLVMSupportBlake3)
+
+# We have to manually set this because this library was not created with llvm_add_library
+if(LLVM_BUILD_LLVM_DYLIB)
+ target_compile_definitions(LLVMSupportBlake3 PRIVATE LLVM_ABI_EXPORTS)
+endif()
diff --git a/llvm/lib/Support/BLAKE3/blake3.c b/llvm/lib/Support/BLAKE3/blake3.c
index 23f0252602de2..a23dfce491b5c 100644
--- a/llvm/lib/Support/BLAKE3/blake3.c
+++ b/llvm/lib/Support/BLAKE3/blake3.c
@@ -12,7 +12,7 @@
#include "blake3_impl.h"
-const char *llvm_blake3_version(void) { return BLAKE3_VERSION_STRING; }
+LLVM_C_ABI const char *llvm_blake3_version(void) { return BLAKE3_VERSION_STRING; }
INLINE void chunk_state_init(blake3_chunk_state *self, const uint32_t key[8],
uint8_t flags) {
@@ -371,16 +371,16 @@ INLINE void hasher_init_base(blake3_hasher *self, const uint32_t key[8],
self->cv_stack_len = 0;
}
-void llvm_blake3_hasher_init(blake3_hasher *self) { hasher_init_base(self, IV, 0); }
+LLVM_C_ABI void llvm_blake3_hasher_init(blake3_hasher *self) { hasher_init_base(self, IV, 0); }
-void llvm_blake3_hasher_init_keyed(blake3_hasher *self,
+LLVM_C_ABI void llvm_blake3_hasher_init_keyed(blake3_hasher *self,
const uint8_t key[BLAKE3_KEY_LEN]) {
uint32_t key_words[8];
load_key_words(key, key_words);
hasher_init_base(self, key_words, KEYED_HASH);
}
-void llvm_blake3_hasher_init_derive_key_raw(blake3_hasher *self, const void *context,
+LLVM_C_ABI void llvm_blake3_hasher_init_derive_key_raw(blake3_hasher *self, const void *context,
size_t context_len) {
blake3_hasher context_hasher;
hasher_init_base(&context_hasher, IV, DERIVE_KEY_CONTEXT);
@@ -392,7 +392,7 @@ void llvm_blake3_hasher_init_derive_key_raw(blake3_hasher *self, const void *con
hasher_init_base(self, context_key_words, DERIVE_KEY_MATERIAL);
}
-void llvm_blake3_hasher_init_derive_key(blake3_hasher *self, const char *context) {
+LLVM_C_ABI void llvm_blake3_hasher_init_derive_key(blake3_hasher *self, const char *context) {
llvm_blake3_hasher_init_derive_key_raw(self, context, strlen(context));
}
@@ -457,7 +457,7 @@ INLINE void hasher_push_cv(blake3_hasher *self, uint8_t new_cv[BLAKE3_OUT_LEN],
self->cv_stack_len += 1;
}
-void llvm_blake3_hasher_update(blake3_hasher *self, const void *input,
+LLVM_C_ABI void llvm_blake3_hasher_update(blake3_hasher *self, const void *input,
size_t input_len) {
// Explicitly checking for zero avoids causing UB by passing a null pointer
// to memcpy. This comes up in practice with things like:
@@ -575,7 +575,7 @@ void llvm_blake3_hasher_finalize(const blake3_hasher *self, uint8_t *out,
#endif
}
-void llvm_blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek,
+LLVM_C_ABI void llvm_blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek,
uint8_t *out, size_t out_len) {
// Explicitly checking for zero avoids causing UB by passing a null pointer
// to memcpy. This comes up in practice with things like:
@@ -619,7 +619,7 @@ void llvm_blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek,
output_root_bytes(&output, seek, out, out_len);
}
-void llvm_blake3_hasher_reset(blake3_hasher *self) {
+LLVM_C_ABI void llvm_blake3_hasher_reset(blake3_hasher *self) {
chunk_state_reset(&self->chunk, self->key, 0);
self->cv_stack_len = 0;
}
>From 086d0c844017a5cb98552bdc0380e9250ea87cc6 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Mon, 24 Jun 2024 06:11:01 +0100
Subject: [PATCH 19/25] Stop dllexport instantiating ilist methods
getPrevNode/getNextNode that trigger compile errors in headers
The parent type used for the template a incomplete in the headers the template
is use. If the header for the parent was included we would end up with circular
header dependency.
If a a class method has a default template parameter then it will not be implicitly
instantiated by any dllexport'ed classes deriving from the class template its
contained in.
---
llvm/include/llvm/ADT/ilist_node.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/ADT/ilist_node.h b/llvm/include/llvm/ADT/ilist_node.h
index 3b6f0dcc7b5e9..3bd367954d74c 100644
--- a/llvm/include/llvm/ADT/ilist_node.h
+++ b/llvm/include/llvm/ADT/ilist_node.h
@@ -299,7 +299,7 @@ class ilist_node_with_parent : public ilist_node<NodeTy, Options...> {
/// @name Adjacent Node Accessors
/// @{
/// Get the previous node, or \c nullptr for the list head.
- NodeTy *getPrevNode() {
+ template<int = 0> NodeTy *getPrevNode() {
// Should be separated to a reused function, but then we couldn't use auto
// (and would need the type of the list).
const auto &List =
@@ -308,12 +308,12 @@ class ilist_node_with_parent : public ilist_node<NodeTy, Options...> {
}
/// Get the previous node, or \c nullptr for the list head.
- const NodeTy *getPrevNode() const {
+ template<int = 0> const NodeTy *getPrevNode() const {
return const_cast<ilist_node_with_parent *>(this)->getPrevNode();
}
/// Get the next node, or \c nullptr for the list tail.
- NodeTy *getNextNode() {
+ template<int = 0> NodeTy *getNextNode() {
// Should be separated to a reused function, but then we couldn't use auto
// (and would need the type of the list).
const auto &List =
@@ -322,7 +322,7 @@ class ilist_node_with_parent : public ilist_node<NodeTy, Options...> {
}
/// Get the next node, or \c nullptr for the list tail.
- const NodeTy *getNextNode() const {
+ template<int = 0> const NodeTy *getNextNode() const {
return const_cast<ilist_node_with_parent *>(this)->getNextNode();
}
/// @}
>From 6b1a8292d3935479427d1e3da5b685c9493fad12 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Mon, 24 Jun 2024 18:16:04 +0100
Subject: [PATCH 20/25] Fix linker errors from SDNode dump functions being
referenced by inline functions
The dump functions are only get compiled for debug builds or if
LLVM_ENABLE_DUMP is defined. The inline functions referencing them are not
normally instantiated from normal code, but will be by dllexport when building
for MSVC
---
llvm/include/llvm/CodeGen/SelectionDAGNodes.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
index 2f36c2e86b1c3..ed5474263db37 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
@@ -1080,6 +1080,7 @@ END_TWO_BYTE_PACK()
void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
unsigned depth = 100) const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Dump this node, for debugging.
void dump() const;
@@ -1109,6 +1110,7 @@ END_TWO_BYTE_PACK()
///
void dumprWithDepth(const SelectionDAG *G = nullptr,
unsigned depth = 100) const;
+#endif
/// Gather unique data for the node.
void Profile(FoldingSetNodeID &ID) const;
@@ -1235,6 +1237,7 @@ inline const DebugLoc &SDValue::getDebugLoc() const {
return Node->getDebugLoc();
}
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
inline void SDValue::dump() const {
return Node->dump();
}
@@ -1250,6 +1253,7 @@ inline void SDValue::dumpr() const {
inline void SDValue::dumpr(const SelectionDAG *G) const {
return Node->dumpr(G);
}
+#endif
// Define inline functions from the SDUse class.
>From 2adb373c5a344e9dd18b2af7fc556f1751ba64bc Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Sun, 7 Jul 2024 04:16:32 +0100
Subject: [PATCH 21/25] Update the export macro definitions to default to dll
import
If LLVM_BUILD_STATIC is defined the macros are a nop
---
llvm/cmake/modules/AddLLVM.cmake | 21 +++++++++++++-----
llvm/include/llvm/Support/Compiler.h | 27 ++++++++++++++---------
llvm/utils/TableGen/Basic/CMakeLists.txt | 2 +-
llvm/utils/TableGen/Common/CMakeLists.txt | 2 +-
4 files changed, 34 insertions(+), 18 deletions(-)
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index d5fc78a1a1c85..3bef92eb10cc2 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -606,6 +606,10 @@ function(llvm_add_library name)
endif()
endforeach()
endif()
+
+ if(ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
+ target_compile_definitions(${obj_name} PRIVATE LLVM_BUILD_STATIC)
+ endif()
endif()
if(ARG_SHARED AND ARG_STATIC)
@@ -647,11 +651,14 @@ function(llvm_add_library name)
## https://blog.llvm.org/2018/11/30-faster-windows-builds-with-clang-cl_14.html
if(LLVM_BUILD_LLVM_DYLIB AND NOT LLVM_DYLIB_EXPORT_INLNES AND MSVC AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
target_compile_options(${name} PUBLIC /Zc:dllexportInlines-)
+ if(TARGET ${obj_name})
+ target_compile_options(${obj_name} PUBLIC /Zc:dllexportInlines-)
+ endif()
endif()
if(ARG_COMPONENT_LIB)
set_target_properties(${name} PROPERTIES LLVM_COMPONENT TRUE)
- target_compile_definitions(${name} PRIVATE LLVM_ABI_EXPORTS)
+ target_compile_definitions(${name} PRIVATE LLVM_EXPORTS)
# When building shared objects for each target there are some internal APIs
# that are used across shared objects which we can't hide.
@@ -762,8 +769,10 @@ function(llvm_add_library name)
elseif (NOT ARG_COMPONENT_LIB)
if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
set(llvm_libs LLVM)
- target_compile_definitions(${name} PRIVATE LLVM_DLL_IMPORT)
else()
+ if(ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
+ target_compile_definitions(${name} PRIVATE LLVM_BUILD_STATIC)
+ endif()
llvm_map_components_to_libnames(llvm_libs
${ARG_LINK_COMPONENTS}
${LLVM_LINK_COMPONENTS}
@@ -1135,9 +1144,11 @@ macro(add_llvm_executable name)
llvm_codesign(${name} ENTITLEMENTS ${ARG_ENTITLEMENTS} BUNDLE_PATH ${ARG_BUNDLE_PATH})
- if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
- target_compile_definitions(${name} PRIVATE LLVM_DLL_IMPORT)
- if(MSVC AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
+ if (LLVM_BUILD_LLVM_DYLIB OR LLVM_ENABLE_PLUGINS OR LLVM_EXPORT_SYMBOLS_FOR_PLUGINS)
+ if(ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
+ target_compile_definitions(${name} PRIVATE LLVM_BUILD_STATIC)
+ elseif(NOT LLVM_DYLIB_EXPORT_INLNES AND MSVC AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
+ # This has to match how the libraries the executable is linked to are built or there be linker errors.
target_compile_options(${name} PRIVATE /Zc:dllexportInlines-)
endif()
endif()
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index 285b8b1af367c..6aa9a10aab9cf 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -159,19 +159,24 @@
// export macros added to them by the clang tool
#define LLVM_ABI_NOT_EXPORTED
#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS)
-#if defined(_WIN32)
-#if defined(LLVM_ABI_EXPORTS)
+// Some libraries like those for tablegen are linked in to tools that used
+// in the build so can't depend on the llvm shared library. If export macros
+// were left enabled when building these we would get duplicate or
+// missing symbol linker errors on windows.
+#if defined(LLVM_BUILD_STATIC)
+#define LLVM_ABI
+#define LLVM_TEMPLATE_ABI
+#define LLVM_EXPORT_TEMPLATE
+#define LLVM_ABI_EXPORT
+#elif defined(_WIN32)
+#if defined(LLVM_EXPORTS)
#define LLVM_ABI __declspec(dllexport)
#define LLVM_TEMPLATE_ABI
-#define LLVM_EXPORT_TEMPLATE LLVM_ABI
-#elif defined(LLVM_DLL_IMPORT)
+#define LLVM_EXPORT_TEMPLATE __declspec(dllexport)
+#else
#define LLVM_ABI __declspec(dllimport)
#define LLVM_TEMPLATE_ABI __declspec(dllimport)
#define LLVM_EXPORT_TEMPLATE
-#else
-#define LLVM_ABI
-#define LLVM_TEMPLATE_ABI
-#define LLVM_EXPORT_TEMPLATE
#endif
#define LLVM_ABI_EXPORT __declspec(dllexport)
#elif defined(__ELF__)
@@ -185,16 +190,16 @@
#define LLVM_EXPORT_TEMPLATE
#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
#endif
-#define LLVM_C_ABI LLVM_ABI
-#define LLVM_CLASS_ABI LLVM_ABI
#else
-#define LLVM_C_ABI
+#define LLVM_C_ABI
#define LLVM_ABI
#define LLVM_ABI_EXPORT
#define LLVM_CLASS_ABI
#define LLVM_TEMPLATE_ABI
#define LLVM_EXPORT_TEMPLATE
#endif
+#define LLVM_C_ABI LLVM_ABI
+#define LLVM_CLASS_ABI LLVM_ABI
#endif
#if defined(__GNUC__)
diff --git a/llvm/utils/TableGen/Basic/CMakeLists.txt b/llvm/utils/TableGen/Basic/CMakeLists.txt
index 09d79a01cae0a..41d737e8d418e 100644
--- a/llvm/utils/TableGen/Basic/CMakeLists.txt
+++ b/llvm/utils/TableGen/Basic/CMakeLists.txt
@@ -8,7 +8,7 @@ set(LLVM_LINK_COMPONENTS
TableGen
)
-add_llvm_library(LLVMTableGenBasic OBJECT EXCLUDE_FROM_ALL
+add_llvm_library(LLVMTableGenBasic OBJECT EXCLUDE_FROM_ALL DISABLE_LLVM_LINK_LLVM_DYLIB
CodeGenIntrinsics.cpp
SDNodeProperties.cpp
)
diff --git a/llvm/utils/TableGen/Common/CMakeLists.txt b/llvm/utils/TableGen/Common/CMakeLists.txt
index 13883aa8fa391..9d45dc1621143 100644
--- a/llvm/utils/TableGen/Common/CMakeLists.txt
+++ b/llvm/utils/TableGen/Common/CMakeLists.txt
@@ -10,7 +10,7 @@ set(LLVM_LINK_COMPONENTS
TableGen
)
-add_llvm_library(LLVMTableGenCommon STATIC OBJECT EXCLUDE_FROM_ALL
+add_llvm_library(LLVMTableGenCommon STATIC OBJECT EXCLUDE_FROM_ALL DISABLE_LLVM_LINK_LLVM_DYLIB
GlobalISel/CodeExpander.cpp
GlobalISel/CombinerUtils.cpp
GlobalISel/CXXPredicates.cpp
>From ee6c363846a1553c2f81595f63eb2e70b5b4aa36 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Sun, 7 Jul 2024 04:28:16 +0100
Subject: [PATCH 22/25] Fix spelling for LLVM_DYLIB_EXPORT_INLINES and make it
MSVC only
---
llvm/CMakeLists.txt | 2 +-
llvm/cmake/modules/AddLLVM.cmake | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 02ac5c8994e12..2d789e577108e 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -830,7 +830,7 @@ endif()
option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default})
if(MSVC)
- option(LLVM_DYLIB_EXPORT_INLNES "Force inline members of class to be dll exported when
+ option(LLVM_DYLIB_EXPORT_INLINES "Force inline members of class to be dll exported when
building with clang-cl so the libllvm dll is compatible with MSVC" OFF)
endif()
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 3bef92eb10cc2..177eaa062b87d 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -649,7 +649,7 @@ function(llvm_add_library name)
## class members from being dllexport'ed to reduce compile time.
## This will also keep us below the 64k exported symbol limit
## https://blog.llvm.org/2018/11/30-faster-windows-builds-with-clang-cl_14.html
- if(LLVM_BUILD_LLVM_DYLIB AND NOT LLVM_DYLIB_EXPORT_INLNES AND MSVC AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
+ if(LLVM_BUILD_LLVM_DYLIB AND NOT LLVM_DYLIB_EXPORT_INLINES AND MSVC AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
target_compile_options(${name} PUBLIC /Zc:dllexportInlines-)
if(TARGET ${obj_name})
target_compile_options(${obj_name} PUBLIC /Zc:dllexportInlines-)
@@ -1147,7 +1147,7 @@ macro(add_llvm_executable name)
if (LLVM_BUILD_LLVM_DYLIB OR LLVM_ENABLE_PLUGINS OR LLVM_EXPORT_SYMBOLS_FOR_PLUGINS)
if(ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
target_compile_definitions(${name} PRIVATE LLVM_BUILD_STATIC)
- elseif(NOT LLVM_DYLIB_EXPORT_INLNES AND MSVC AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
+ elseif(NOT LLVM_DYLIB_EXPORT_INLINES AND MSVC AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
# This has to match how the libraries the executable is linked to are built or there be linker errors.
target_compile_options(${name} PRIVATE /Zc:dllexportInlines-)
endif()
>From 57385cca4d7940f3ccffc80a913c84be70249bb7 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Thu, 11 Jul 2024 03:31:55 +0100
Subject: [PATCH 23/25] Revert the example code changes
---
llvm/include/llvm-c/Target.h | 57 +++----
llvm/include/llvm-c/lto.h | 161 +++++++++---------
llvm/include/llvm/ADT/SmallVector.h | 4 +-
llvm/include/llvm/ADT/ilist_node.h | 8 +-
llvm/include/llvm/CodeGen/MachineFunction.h | 2 +-
llvm/include/llvm/CodeGen/SelectionDAGNodes.h | 4 -
llvm/include/llvm/IR/Function.h | 4 +-
llvm/include/llvm/IR/Module.h | 2 +-
llvm/include/llvm/Passes/PassPlugin.h | 2 +-
llvm/include/llvm/Support/TargetSelect.h | 15 +-
.../Transforms/InstCombine/InstCombiner.h | 2 +-
llvm/include/llvm/Transforms/Scalar/GVN.h | 2 +-
.../Orc/TargetProcess/JITLoaderGDB.cpp | 4 +-
llvm/lib/Support/BLAKE3/CMakeLists.txt | 5 -
llvm/lib/Support/BLAKE3/blake3.c | 16 +-
llvm/lib/Support/SmallVector.cpp | 4 +-
.../lib/Target/X86/AsmParser/X86AsmParser.cpp | 2 +-
.../X86/Disassembler/X86Disassembler.cpp | 2 +-
.../lib/Target/X86/MCA/X86CustomBehaviour.cpp | 2 +-
.../X86/MCTargetDesc/X86MCTargetDesc.cpp | 2 +-
.../Target/X86/TargetInfo/X86TargetInfo.cpp | 2 +-
llvm/lib/Target/X86/X86AsmPrinter.cpp | 2 +-
llvm/lib/Target/X86/X86TargetMachine.cpp | 2 +-
llvm/tools/lto/CMakeLists.txt | 4 -
24 files changed, 144 insertions(+), 166 deletions(-)
diff --git a/llvm/include/llvm-c/Target.h b/llvm/include/llvm-c/Target.h
index c68eb17189d27..518b46d55bc3c 100644
--- a/llvm/include/llvm-c/Target.h
+++ b/llvm/include/llvm-c/Target.h
@@ -39,35 +39,34 @@ typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
/* Declare all of the target-initialization functions that are available. */
#define LLVM_TARGET(TargetName) \
- LLVM_C_ABI void LLVMInitialize##TargetName##TargetInfo(void);
+ void LLVMInitialize##TargetName##TargetInfo(void);
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
-#define LLVM_TARGET(TargetName) \
- LLVM_C_ABI void LLVMInitialize##TargetName##Target(void);
+#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
#define LLVM_TARGET(TargetName) \
- LLVM_C_ABI void LLVMInitialize##TargetName##TargetMC(void);
+ void LLVMInitialize##TargetName##TargetMC(void);
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
/* Declare all of the available assembly printer initialization functions. */
#define LLVM_ASM_PRINTER(TargetName) \
- LLVM_C_ABI void LLVMInitialize##TargetName##AsmPrinter(void);
+ void LLVMInitialize##TargetName##AsmPrinter(void);
#include "llvm/Config/AsmPrinters.def"
#undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
/* Declare all of the available assembly parser initialization functions. */
#define LLVM_ASM_PARSER(TargetName) \
- LLVM_C_ABI void LLVMInitialize##TargetName##AsmParser(void);
+ void LLVMInitialize##TargetName##AsmParser(void);
#include "llvm/Config/AsmParsers.def"
#undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
/* Declare all of the available disassembler initialization functions. */
#define LLVM_DISASSEMBLER(TargetName) \
- LLVM_C_ABI void LLVMInitialize##TargetName##Disassembler(void);
+ void LLVMInitialize##TargetName##Disassembler(void);
#include "llvm/Config/Disassemblers.def"
#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
@@ -184,104 +183,104 @@ static inline LLVMBool LLVMInitializeNativeDisassembler(void) {
*
* @see Module::getDataLayout()
*/
-LLVM_C_ABI LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M);
+LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M);
/**
* Set the data layout for a module.
*
* @see Module::setDataLayout()
*/
-LLVM_C_ABI void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL);
+void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL);
/** Creates target data from a target layout string.
See the constructor llvm::DataLayout::DataLayout. */
-LLVM_C_ABI LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
+LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
/** Deallocates a TargetData.
See the destructor llvm::DataLayout::~DataLayout. */
-LLVM_C_ABI void LLVMDisposeTargetData(LLVMTargetDataRef TD);
+void LLVMDisposeTargetData(LLVMTargetDataRef TD);
/** Adds target library information to a pass manager. This does not take
ownership of the target library info.
See the method llvm::PassManagerBase::add. */
-LLVM_C_ABI void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
+void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
LLVMPassManagerRef PM);
/** Converts target data to a target layout string. The string must be disposed
with LLVMDisposeMessage.
See the constructor llvm::DataLayout::DataLayout. */
-LLVM_C_ABI char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD);
+char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD);
/** Returns the byte order of a target, either LLVMBigEndian or
LLVMLittleEndian.
See the method llvm::DataLayout::isLittleEndian. */
-LLVM_C_ABI enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD);
+enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD);
/** Returns the pointer size in bytes for a target.
See the method llvm::DataLayout::getPointerSize. */
-LLVM_C_ABI unsigned LLVMPointerSize(LLVMTargetDataRef TD);
+unsigned LLVMPointerSize(LLVMTargetDataRef TD);
/** Returns the pointer size in bytes for a target for a specified
address space.
See the method llvm::DataLayout::getPointerSize. */
-LLVM_C_ABI unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS);
+unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS);
/** Returns the integer type that is the same size as a pointer on a target.
See the method llvm::DataLayout::getIntPtrType. */
-LLVM_C_ABI LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD);
+LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD);
/** Returns the integer type that is the same size as a pointer on a target.
This version allows the address space to be specified.
See the method llvm::DataLayout::getIntPtrType. */
-LLVM_C_ABI LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS);
+LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS);
/** Returns the integer type that is the same size as a pointer on a target.
See the method llvm::DataLayout::getIntPtrType. */
-LLVM_C_ABI LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD);
+LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD);
/** Returns the integer type that is the same size as a pointer on a target.
This version allows the address space to be specified.
See the method llvm::DataLayout::getIntPtrType. */
-LLVM_C_ABI LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C, LLVMTargetDataRef TD,
+LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C, LLVMTargetDataRef TD,
unsigned AS);
/** Computes the size of a type in bytes for a target.
See the method llvm::DataLayout::getTypeSizeInBits. */
-LLVM_C_ABI unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty);
+unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the storage size of a type in bytes for a target.
See the method llvm::DataLayout::getTypeStoreSize. */
-LLVM_C_ABI unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
+unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the ABI size of a type in bytes for a target.
See the method llvm::DataLayout::getTypeAllocSize. */
-LLVM_C_ABI unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
+unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the ABI alignment of a type in bytes for a target.
See the method llvm::DataLayout::getTypeABISize. */
-LLVM_C_ABI unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
+unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the call frame alignment of a type in bytes for a target.
See the method llvm::DataLayout::getTypeABISize. */
-LLVM_C_ABI unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
+unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the preferred alignment of a type in bytes for a target.
See the method llvm::DataLayout::getTypeABISize. */
-LLVM_C_ABI unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
+unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the preferred alignment of a global variable in bytes for a target.
See the method llvm::DataLayout::getPreferredAlignment. */
-LLVM_C_ABI unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
+unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
LLVMValueRef GlobalVar);
/** Computes the structure element that contains the byte offset for a target.
See the method llvm::StructLayout::getElementContainingOffset. */
-LLVM_C_ABI unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
+unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
unsigned long long Offset);
/** Computes the byte offset of the indexed struct element for a target.
See the method llvm::StructLayout::getElementContainingOffset. */
-LLVM_C_ABI unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD,
+unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD,
LLVMTypeRef StructTy, unsigned Element);
/**
diff --git a/llvm/include/llvm-c/lto.h b/llvm/include/llvm-c/lto.h
index ba286e8e97ea3..5ceb02224d2bb 100644
--- a/llvm/include/llvm-c/lto.h
+++ b/llvm/include/llvm-c/lto.h
@@ -16,15 +16,8 @@
#ifndef LLVM_C_LTO_H
#define LLVM_C_LTO_H
-#include "llvm/Support/Compiler.h"
#include "llvm-c/ExternC.h"
-#ifdef LLVM_BUILDING_LIBLTO
-#define LLVM_LIBLTO_ABI LLVM_ABI_EXPORT
-#else
-#define LLVM_LIBLTO_ABI LLVM_C_ABI
-#endif
-
#ifdef __cplusplus
#include <cstddef>
#else
@@ -114,7 +107,7 @@ LLVM_C_EXTERN_C_BEGIN
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern const char*
+extern const char*
lto_get_version(void);
/**
@@ -122,7 +115,7 @@ lto_get_version(void);
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern const char*
+extern const char*
lto_get_error_message(void);
/**
@@ -130,7 +123,7 @@ lto_get_error_message(void);
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern lto_bool_t
+extern lto_bool_t
lto_module_is_object_file(const char* path);
/**
@@ -138,7 +131,7 @@ lto_module_is_object_file(const char* path);
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern lto_bool_t
+extern lto_bool_t
lto_module_is_object_file_for_target(const char* path,
const char* target_triple_prefix);
@@ -148,7 +141,7 @@ lto_module_is_object_file_for_target(const char* path,
*
* \since LTO_API_VERSION=20
*/
-LLVM_LIBLTO_ABI extern lto_bool_t
+extern lto_bool_t
lto_module_has_objc_category(const void *mem, size_t length);
/**
@@ -156,7 +149,7 @@ lto_module_has_objc_category(const void *mem, size_t length);
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern lto_bool_t lto_module_is_object_file_in_memory(const void *mem,
+extern lto_bool_t lto_module_is_object_file_in_memory(const void *mem,
size_t length);
/**
@@ -164,7 +157,7 @@ LLVM_LIBLTO_ABI extern lto_bool_t lto_module_is_object_file_in_memory(const void
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern lto_bool_t
+extern lto_bool_t
lto_module_is_object_file_in_memory_for_target(const void* mem, size_t length,
const char* target_triple_prefix);
@@ -174,7 +167,7 @@ lto_module_is_object_file_in_memory_for_target(const void* mem, size_t length,
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern lto_module_t
+extern lto_module_t
lto_module_create(const char* path);
/**
@@ -183,7 +176,7 @@ lto_module_create(const char* path);
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern lto_module_t
+extern lto_module_t
lto_module_create_from_memory(const void* mem, size_t length);
/**
@@ -192,7 +185,7 @@ lto_module_create_from_memory(const void* mem, size_t length);
*
* \since LTO_API_VERSION=9
*/
-LLVM_LIBLTO_ABI extern lto_module_t
+extern lto_module_t
lto_module_create_from_memory_with_path(const void* mem, size_t length,
const char *path);
@@ -207,7 +200,7 @@ lto_module_create_from_memory_with_path(const void* mem, size_t length,
*
* \since LTO_API_VERSION=11
*/
-LLVM_LIBLTO_ABI extern lto_module_t
+extern lto_module_t
lto_module_create_in_local_context(const void *mem, size_t length,
const char *path);
@@ -221,7 +214,7 @@ lto_module_create_in_local_context(const void *mem, size_t length,
*
* \since LTO_API_VERSION=11
*/
-LLVM_LIBLTO_ABI extern lto_module_t
+extern lto_module_t
lto_module_create_in_codegen_context(const void *mem, size_t length,
const char *path, lto_code_gen_t cg);
@@ -231,7 +224,7 @@ lto_module_create_in_codegen_context(const void *mem, size_t length,
*
* \since LTO_API_VERSION=5
*/
-LLVM_LIBLTO_ABI extern lto_module_t
+extern lto_module_t
lto_module_create_from_fd(int fd, const char *path, size_t file_size);
/**
@@ -240,7 +233,7 @@ lto_module_create_from_fd(int fd, const char *path, size_t file_size);
*
* \since LTO_API_VERSION=5
*/
-LLVM_LIBLTO_ABI extern lto_module_t
+extern lto_module_t
lto_module_create_from_fd_at_offset(int fd, const char *path, size_t file_size,
size_t map_size, off_t offset);
@@ -250,7 +243,7 @@ lto_module_create_from_fd_at_offset(int fd, const char *path, size_t file_size,
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern void
+extern void
lto_module_dispose(lto_module_t mod);
/**
@@ -258,7 +251,7 @@ lto_module_dispose(lto_module_t mod);
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern const char*
+extern const char*
lto_module_get_target_triple(lto_module_t mod);
/**
@@ -266,7 +259,7 @@ lto_module_get_target_triple(lto_module_t mod);
*
* \since LTO_API_VERSION=4
*/
-LLVM_LIBLTO_ABI extern void
+extern void
lto_module_set_target_triple(lto_module_t mod, const char *triple);
/**
@@ -274,7 +267,7 @@ lto_module_set_target_triple(lto_module_t mod, const char *triple);
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern unsigned int
+extern unsigned int
lto_module_get_num_symbols(lto_module_t mod);
/**
@@ -282,7 +275,7 @@ lto_module_get_num_symbols(lto_module_t mod);
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern const char*
+extern const char*
lto_module_get_symbol_name(lto_module_t mod, unsigned int index);
/**
@@ -290,7 +283,7 @@ lto_module_get_symbol_name(lto_module_t mod, unsigned int index);
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern lto_symbol_attributes
+extern lto_symbol_attributes
lto_module_get_symbol_attribute(lto_module_t mod, unsigned int index);
/**
@@ -301,7 +294,7 @@ lto_module_get_symbol_attribute(lto_module_t mod, unsigned int index);
*
* \since LTO_API_VERSION=16
*/
-LLVM_LIBLTO_ABI extern const char*
+extern const char*
lto_module_get_linkeropts(lto_module_t mod);
/**
@@ -315,7 +308,7 @@ lto_module_get_linkeropts(lto_module_t mod);
*
* \since LTO_API_VERSION=27
*/
-LLVM_LIBLTO_ABI extern lto_bool_t lto_module_get_macho_cputype(lto_module_t mod,
+extern lto_bool_t lto_module_get_macho_cputype(lto_module_t mod,
unsigned int *out_cputype,
unsigned int *out_cpusubtype);
@@ -328,7 +321,7 @@ LLVM_LIBLTO_ABI extern lto_bool_t lto_module_get_macho_cputype(lto_module_t mod,
*
* \since LTO_API_VERSION=29
*/
-LLVM_LIBLTO_ABI extern lto_bool_t lto_module_has_ctor_dtor(lto_module_t mod);
+extern lto_bool_t lto_module_has_ctor_dtor(lto_module_t mod);
/**
* Diagnostic severity.
*
@@ -360,7 +353,7 @@ typedef void (*lto_diagnostic_handler_t)(
*
* \since LTO_API_VERSION=7
*/
-LLVM_LIBLTO_ABI extern void lto_codegen_set_diagnostic_handler(lto_code_gen_t,
+extern void lto_codegen_set_diagnostic_handler(lto_code_gen_t,
lto_diagnostic_handler_t,
void *);
@@ -373,7 +366,7 @@ LLVM_LIBLTO_ABI extern void lto_codegen_set_diagnostic_handler(lto_code_gen_t,
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern lto_code_gen_t
+extern lto_code_gen_t
lto_codegen_create(void);
/**
@@ -385,7 +378,7 @@ lto_codegen_create(void);
*
* \since LTO_API_VERSION=11
*/
-LLVM_LIBLTO_ABI extern lto_code_gen_t
+extern lto_code_gen_t
lto_codegen_create_in_local_context(void);
/**
@@ -394,7 +387,7 @@ lto_codegen_create_in_local_context(void);
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern void
+extern void
lto_codegen_dispose(lto_code_gen_t);
/**
@@ -407,7 +400,7 @@ lto_codegen_dispose(lto_code_gen_t);
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern lto_bool_t
+extern lto_bool_t
lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod);
/**
@@ -418,7 +411,7 @@ lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod);
*
* \since LTO_API_VERSION=13
*/
-LLVM_LIBLTO_ABI extern void
+extern void
lto_codegen_set_module(lto_code_gen_t cg, lto_module_t mod);
/**
@@ -427,7 +420,7 @@ lto_codegen_set_module(lto_code_gen_t cg, lto_module_t mod);
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern lto_bool_t
+extern lto_bool_t
lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model);
/**
@@ -436,7 +429,7 @@ lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model);
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern lto_bool_t
+extern lto_bool_t
lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model);
/**
@@ -444,7 +437,7 @@ lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model);
*
* \since LTO_API_VERSION=4
*/
-LLVM_LIBLTO_ABI extern void
+extern void
lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu);
/**
@@ -453,7 +446,7 @@ lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu);
*
* \since LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern void
+extern void
lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path);
/**
@@ -461,7 +454,7 @@ lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path);
*
* \since LTO_API_VERSION=4
*/
-LLVM_LIBLTO_ABI extern void
+extern void
lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args,
int nargs);
@@ -472,7 +465,7 @@ lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args,
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern void
+extern void
lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol);
/**
@@ -482,7 +475,7 @@ lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol);
*
* \since LTO_API_VERSION=5
*/
-LLVM_LIBLTO_ABI extern lto_bool_t
+extern lto_bool_t
lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path);
/**
@@ -497,7 +490,7 @@ lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path);
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern const void*
+extern const void*
lto_codegen_compile(lto_code_gen_t cg, size_t* length);
/**
@@ -509,7 +502,7 @@ lto_codegen_compile(lto_code_gen_t cg, size_t* length);
*
* \since LTO_API_VERSION=5
*/
-LLVM_LIBLTO_ABI extern lto_bool_t
+extern lto_bool_t
lto_codegen_compile_to_file(lto_code_gen_t cg, const char** name);
/**
@@ -517,7 +510,7 @@ lto_codegen_compile_to_file(lto_code_gen_t cg, const char** name);
*
* \since LTO_API_VERSION=12
*/
-LLVM_LIBLTO_ABI extern lto_bool_t
+extern lto_bool_t
lto_codegen_optimize(lto_code_gen_t cg);
/**
@@ -532,7 +525,7 @@ lto_codegen_optimize(lto_code_gen_t cg);
*
* \since LTO_API_VERSION=12
*/
-LLVM_LIBLTO_ABI extern const void*
+extern const void*
lto_codegen_compile_optimized(lto_code_gen_t cg, size_t* length);
/**
@@ -540,7 +533,7 @@ lto_codegen_compile_optimized(lto_code_gen_t cg, size_t* length);
*
* \since LTO_API_VERSION=12
*/
-LLVM_LIBLTO_ABI extern unsigned int
+extern unsigned int
lto_api_version(void);
/**
@@ -555,7 +548,7 @@ lto_api_version(void);
*
* \since LTO_API_VERSION=28
*/
-LLVM_LIBLTO_ABI extern void lto_set_debug_options(const char *const *options, int number);
+extern void lto_set_debug_options(const char *const *options, int number);
/**
* Sets options to help debug codegen bugs. Since parsing shud only happen once,
@@ -568,7 +561,7 @@ LLVM_LIBLTO_ABI extern void lto_set_debug_options(const char *const *options, in
*
* \since prior to LTO_API_VERSION=3
*/
-LLVM_LIBLTO_ABI extern void
+extern void
lto_codegen_debug_options(lto_code_gen_t cg, const char *);
/**
@@ -577,7 +570,7 @@ lto_codegen_debug_options(lto_code_gen_t cg, const char *);
*
* \since prior to LTO_API_VERSION=26
*/
-LLVM_LIBLTO_ABI extern void lto_codegen_debug_options_array(lto_code_gen_t cg,
+extern void lto_codegen_debug_options_array(lto_code_gen_t cg,
const char *const *, int number);
/**
@@ -586,7 +579,7 @@ LLVM_LIBLTO_ABI extern void lto_codegen_debug_options_array(lto_code_gen_t cg,
*
* \since LTO_API_VERSION=5
*/
-LLVM_LIBLTO_ABI extern void
+extern void
lto_initialize_disassembler(void);
/**
@@ -595,7 +588,7 @@ lto_initialize_disassembler(void);
*
* \since LTO_API_VERSION=14
*/
-LLVM_LIBLTO_ABI extern void
+extern void
lto_codegen_set_should_internalize(lto_code_gen_t cg,
lto_bool_t ShouldInternalize);
@@ -607,7 +600,7 @@ lto_codegen_set_should_internalize(lto_code_gen_t cg,
*
* \since LTO_API_VERSION=15
*/
-LLVM_LIBLTO_ABI extern void
+extern void
lto_codegen_set_should_embed_uselists(lto_code_gen_t cg,
lto_bool_t ShouldEmbedUselists);
@@ -622,7 +615,7 @@ typedef struct LLVMOpaqueLTOInput *lto_input_t;
*
* \since LTO_API_VERSION=24
*/
-LLVM_LIBLTO_ABI extern lto_input_t lto_input_create(const void *buffer,
+extern lto_input_t lto_input_create(const void *buffer,
size_t buffer_size,
const char *path);
@@ -632,7 +625,7 @@ LLVM_LIBLTO_ABI extern lto_input_t lto_input_create(const void *buffer,
*
* \since LTO_API_VERSION=24
*/
-LLVM_LIBLTO_ABI extern void lto_input_dispose(lto_input_t input);
+extern void lto_input_dispose(lto_input_t input);
/**
* Returns the number of dependent library specifiers
@@ -640,7 +633,7 @@ LLVM_LIBLTO_ABI extern void lto_input_dispose(lto_input_t input);
*
* \since LTO_API_VERSION=24
*/
-LLVM_LIBLTO_ABI extern unsigned lto_input_get_num_dependent_libraries(lto_input_t input);
+extern unsigned lto_input_get_num_dependent_libraries(lto_input_t input);
/**
* Returns the ith dependent library specifier
@@ -649,7 +642,7 @@ LLVM_LIBLTO_ABI extern unsigned lto_input_get_num_dependent_libraries(lto_input_
*
* \since LTO_API_VERSION=24
*/
-LLVM_LIBLTO_ABI extern const char * lto_input_get_dependent_library(lto_input_t input,
+extern const char * lto_input_get_dependent_library(lto_input_t input,
size_t index,
size_t *size);
@@ -659,7 +652,7 @@ LLVM_LIBLTO_ABI extern const char * lto_input_get_dependent_library(lto_input_t
*
* \since prior to LTO_API_VERSION=25
*/
-LLVM_LIBLTO_ABI extern const char *const *lto_runtime_lib_symbols_list(size_t *size);
+extern const char *const *lto_runtime_lib_symbols_list(size_t *size);
/**
* @} // endgoup LLVMCLTO
@@ -691,7 +684,7 @@ typedef struct {
*
* \since LTO_API_VERSION=18
*/
-LLVM_LIBLTO_ABI extern thinlto_code_gen_t thinlto_create_codegen(void);
+extern thinlto_code_gen_t thinlto_create_codegen(void);
/**
* Frees the generator and all memory it internally allocated.
@@ -699,7 +692,7 @@ LLVM_LIBLTO_ABI extern thinlto_code_gen_t thinlto_create_codegen(void);
*
* \since LTO_API_VERSION=18
*/
-LLVM_LIBLTO_ABI extern void thinlto_codegen_dispose(thinlto_code_gen_t cg);
+extern void thinlto_codegen_dispose(thinlto_code_gen_t cg);
/**
* Add a module to a ThinLTO code generator. Identifier has to be unique among
@@ -712,7 +705,7 @@ LLVM_LIBLTO_ABI extern void thinlto_codegen_dispose(thinlto_code_gen_t cg);
*
* \since LTO_API_VERSION=18
*/
-LLVM_LIBLTO_ABI extern void thinlto_codegen_add_module(thinlto_code_gen_t cg,
+extern void thinlto_codegen_add_module(thinlto_code_gen_t cg,
const char *identifier, const char *data,
int length);
@@ -722,7 +715,7 @@ LLVM_LIBLTO_ABI extern void thinlto_codegen_add_module(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=18
*/
-LLVM_LIBLTO_ABI extern void thinlto_codegen_process(thinlto_code_gen_t cg);
+extern void thinlto_codegen_process(thinlto_code_gen_t cg);
/**
* Returns the number of object files produced by the ThinLTO CodeGenerator.
@@ -733,7 +726,7 @@ LLVM_LIBLTO_ABI extern void thinlto_codegen_process(thinlto_code_gen_t cg);
*
* \since LTO_API_VERSION=18
*/
-LLVM_LIBLTO_ABI extern unsigned int thinlto_module_get_num_objects(thinlto_code_gen_t cg);
+extern unsigned int thinlto_module_get_num_objects(thinlto_code_gen_t cg);
/**
* Returns a reference to the ith object file produced by the ThinLTO
@@ -744,7 +737,7 @@ LLVM_LIBLTO_ABI extern unsigned int thinlto_module_get_num_objects(thinlto_code_
*
* \since LTO_API_VERSION=18
*/
-LLVM_LIBLTO_ABI extern LTOObjectBuffer thinlto_module_get_object(thinlto_code_gen_t cg,
+extern LTOObjectBuffer thinlto_module_get_object(thinlto_code_gen_t cg,
unsigned int index);
/**
@@ -756,7 +749,7 @@ LLVM_LIBLTO_ABI extern LTOObjectBuffer thinlto_module_get_object(thinlto_code_ge
*
* \since LTO_API_VERSION=21
*/
-LLVM_LIBLTO_ABI unsigned int thinlto_module_get_num_object_files(thinlto_code_gen_t cg);
+unsigned int thinlto_module_get_num_object_files(thinlto_code_gen_t cg);
/**
* Returns the path to the ith object file produced by the ThinLTO
@@ -767,7 +760,7 @@ LLVM_LIBLTO_ABI unsigned int thinlto_module_get_num_object_files(thinlto_code_ge
*
* \since LTO_API_VERSION=21
*/
-LLVM_LIBLTO_ABI const char *thinlto_module_get_object_file(thinlto_code_gen_t cg,
+const char *thinlto_module_get_object_file(thinlto_code_gen_t cg,
unsigned int index);
/**
@@ -776,7 +769,7 @@ LLVM_LIBLTO_ABI const char *thinlto_module_get_object_file(thinlto_code_gen_t cg
*
* \since LTO_API_VERSION=18
*/
-LLVM_LIBLTO_ABI extern lto_bool_t thinlto_codegen_set_pic_model(thinlto_code_gen_t cg,
+extern lto_bool_t thinlto_codegen_set_pic_model(thinlto_code_gen_t cg,
lto_codegen_model);
/**
@@ -786,7 +779,7 @@ LLVM_LIBLTO_ABI extern lto_bool_t thinlto_codegen_set_pic_model(thinlto_code_gen
*
* \since LTO_API_VERSION=18
*/
-LLVM_LIBLTO_ABI extern void thinlto_codegen_set_savetemps_dir(thinlto_code_gen_t cg,
+extern void thinlto_codegen_set_savetemps_dir(thinlto_code_gen_t cg,
const char *save_temps_dir);
/**
@@ -797,7 +790,7 @@ LLVM_LIBLTO_ABI extern void thinlto_codegen_set_savetemps_dir(thinlto_code_gen_t
*
* \since LTO_API_VERSION=21
*/
-LLVM_LIBLTO_ABI void thinlto_set_generated_objects_dir(thinlto_code_gen_t cg,
+void thinlto_set_generated_objects_dir(thinlto_code_gen_t cg,
const char *save_temps_dir);
/**
@@ -805,7 +798,7 @@ LLVM_LIBLTO_ABI void thinlto_set_generated_objects_dir(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=18
*/
-LLVM_LIBLTO_ABI extern void thinlto_codegen_set_cpu(thinlto_code_gen_t cg, const char *cpu);
+extern void thinlto_codegen_set_cpu(thinlto_code_gen_t cg, const char *cpu);
/**
* Disable CodeGen, only run the stages till codegen and stop. The output will
@@ -813,7 +806,7 @@ LLVM_LIBLTO_ABI extern void thinlto_codegen_set_cpu(thinlto_code_gen_t cg, const
*
* \since LTO_API_VERSION=19
*/
-LLVM_LIBLTO_ABI extern void thinlto_codegen_disable_codegen(thinlto_code_gen_t cg,
+extern void thinlto_codegen_disable_codegen(thinlto_code_gen_t cg,
lto_bool_t disable);
/**
@@ -821,7 +814,7 @@ LLVM_LIBLTO_ABI extern void thinlto_codegen_disable_codegen(thinlto_code_gen_t c
*
* \since LTO_API_VERSION=19
*/
-LLVM_LIBLTO_ABI extern void thinlto_codegen_set_codegen_only(thinlto_code_gen_t cg,
+extern void thinlto_codegen_set_codegen_only(thinlto_code_gen_t cg,
lto_bool_t codegen_only);
/**
@@ -829,14 +822,14 @@ LLVM_LIBLTO_ABI extern void thinlto_codegen_set_codegen_only(thinlto_code_gen_t
*
* \since LTO_API_VERSION=18
*/
-LLVM_LIBLTO_ABI extern void thinlto_debug_options(const char *const *options, int number);
+extern void thinlto_debug_options(const char *const *options, int number);
/**
* Test if a module has support for ThinLTO linking.
*
* \since LTO_API_VERSION=18
*/
-LLVM_LIBLTO_ABI extern lto_bool_t lto_module_is_thinlto(lto_module_t mod);
+extern lto_bool_t lto_module_is_thinlto(lto_module_t mod);
/**
* Adds a symbol to the list of global symbols that must exist in the final
@@ -846,7 +839,7 @@ LLVM_LIBLTO_ABI extern lto_bool_t lto_module_is_thinlto(lto_module_t mod);
*
* \since LTO_API_VERSION=18
*/
-LLVM_LIBLTO_ABI extern void thinlto_codegen_add_must_preserve_symbol(thinlto_code_gen_t cg,
+extern void thinlto_codegen_add_must_preserve_symbol(thinlto_code_gen_t cg,
const char *name,
int length);
@@ -858,7 +851,7 @@ LLVM_LIBLTO_ABI extern void thinlto_codegen_add_must_preserve_symbol(thinlto_cod
*
* \since LTO_API_VERSION=18
*/
-LLVM_LIBLTO_ABI extern void thinlto_codegen_add_cross_referenced_symbol(thinlto_code_gen_t cg,
+extern void thinlto_codegen_add_cross_referenced_symbol(thinlto_code_gen_t cg,
const char *name,
int length);
@@ -889,7 +882,7 @@ LLVM_LIBLTO_ABI extern void thinlto_codegen_add_cross_referenced_symbol(thinlto_
*
* \since LTO_API_VERSION=18
*/
-LLVM_LIBLTO_ABI extern void thinlto_codegen_set_cache_dir(thinlto_code_gen_t cg,
+extern void thinlto_codegen_set_cache_dir(thinlto_code_gen_t cg,
const char *cache_dir);
/**
@@ -899,7 +892,7 @@ LLVM_LIBLTO_ABI extern void thinlto_codegen_set_cache_dir(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=18
*/
-LLVM_LIBLTO_ABI extern void thinlto_codegen_set_cache_pruning_interval(thinlto_code_gen_t cg,
+extern void thinlto_codegen_set_cache_pruning_interval(thinlto_code_gen_t cg,
int interval);
/**
@@ -915,7 +908,7 @@ LLVM_LIBLTO_ABI extern void thinlto_codegen_set_cache_pruning_interval(thinlto_c
*
* \since LTO_API_VERSION=18
*/
-LLVM_LIBLTO_ABI extern void thinlto_codegen_set_final_cache_size_relative_to_available_space(
+extern void thinlto_codegen_set_final_cache_size_relative_to_available_space(
thinlto_code_gen_t cg, unsigned percentage);
/**
@@ -924,7 +917,7 @@ LLVM_LIBLTO_ABI extern void thinlto_codegen_set_final_cache_size_relative_to_ava
*
* \since LTO_API_VERSION=18
*/
-LLVM_LIBLTO_ABI extern void thinlto_codegen_set_cache_entry_expiration(thinlto_code_gen_t cg,
+extern void thinlto_codegen_set_cache_entry_expiration(thinlto_code_gen_t cg,
unsigned expiration);
/**
@@ -935,7 +928,7 @@ LLVM_LIBLTO_ABI extern void thinlto_codegen_set_cache_entry_expiration(thinlto_c
*
* \since LTO_API_VERSION=22
*/
-LLVM_LIBLTO_ABI extern void thinlto_codegen_set_cache_size_bytes(thinlto_code_gen_t cg,
+extern void thinlto_codegen_set_cache_size_bytes(thinlto_code_gen_t cg,
unsigned max_size_bytes);
/**
@@ -944,7 +937,7 @@ LLVM_LIBLTO_ABI extern void thinlto_codegen_set_cache_size_bytes(thinlto_code_ge
*
* \since LTO_API_VERSION=23
*/
-LLVM_LIBLTO_ABI extern void
+extern void
thinlto_codegen_set_cache_size_megabytes(thinlto_code_gen_t cg,
unsigned max_size_megabytes);
@@ -954,7 +947,7 @@ thinlto_codegen_set_cache_size_megabytes(thinlto_code_gen_t cg,
*
* \since LTO_API_VERSION=22
*/
-LLVM_LIBLTO_ABI extern void thinlto_codegen_set_cache_size_files(thinlto_code_gen_t cg,
+extern void thinlto_codegen_set_cache_size_files(thinlto_code_gen_t cg,
unsigned max_size_files);
/**
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index 7443e77591f4f..09676d792dfeb 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -1327,9 +1327,9 @@ template <typename Out, typename R> SmallVector<Out> to_vector_of(R &&Range) {
}
// Explicit instantiations
-extern template class LLVM_TEMPLATE_ABI llvm::SmallVectorBase<uint32_t>;
+extern template class llvm::SmallVectorBase<uint32_t>;
#if SIZE_MAX > UINT32_MAX
-extern template class LLVM_TEMPLATE_ABI llvm::SmallVectorBase<uint64_t>;
+extern template class llvm::SmallVectorBase<uint64_t>;
#endif
} // end namespace llvm
diff --git a/llvm/include/llvm/ADT/ilist_node.h b/llvm/include/llvm/ADT/ilist_node.h
index 3bd367954d74c..3b6f0dcc7b5e9 100644
--- a/llvm/include/llvm/ADT/ilist_node.h
+++ b/llvm/include/llvm/ADT/ilist_node.h
@@ -299,7 +299,7 @@ class ilist_node_with_parent : public ilist_node<NodeTy, Options...> {
/// @name Adjacent Node Accessors
/// @{
/// Get the previous node, or \c nullptr for the list head.
- template<int = 0> NodeTy *getPrevNode() {
+ NodeTy *getPrevNode() {
// Should be separated to a reused function, but then we couldn't use auto
// (and would need the type of the list).
const auto &List =
@@ -308,12 +308,12 @@ class ilist_node_with_parent : public ilist_node<NodeTy, Options...> {
}
/// Get the previous node, or \c nullptr for the list head.
- template<int = 0> const NodeTy *getPrevNode() const {
+ const NodeTy *getPrevNode() const {
return const_cast<ilist_node_with_parent *>(this)->getPrevNode();
}
/// Get the next node, or \c nullptr for the list tail.
- template<int = 0> NodeTy *getNextNode() {
+ NodeTy *getNextNode() {
// Should be separated to a reused function, but then we couldn't use auto
// (and would need the type of the list).
const auto &List =
@@ -322,7 +322,7 @@ class ilist_node_with_parent : public ilist_node<NodeTy, Options...> {
}
/// Get the next node, or \c nullptr for the list tail.
- template<int = 0> const NodeTy *getNextNode() const {
+ const NodeTy *getNextNode() const {
return const_cast<ilist_node_with_parent *>(this)->getNextNode();
}
/// @}
diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h
index 7952e60f37769..6e7292abeddbb 100644
--- a/llvm/include/llvm/CodeGen/MachineFunction.h
+++ b/llvm/include/llvm/CodeGen/MachineFunction.h
@@ -255,7 +255,7 @@ struct LandingPadInfo {
: LandingPadBlock(MBB) {}
};
-class LLVM_CLASS_ABI MachineFunction {
+class LLVM_EXTERNAL_VISIBILITY MachineFunction {
Function &F;
const LLVMTargetMachine &Target;
const TargetSubtargetInfo *STI;
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
index ed5474263db37..2f36c2e86b1c3 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
@@ -1080,7 +1080,6 @@ END_TWO_BYTE_PACK()
void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
unsigned depth = 100) const;
-#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Dump this node, for debugging.
void dump() const;
@@ -1110,7 +1109,6 @@ END_TWO_BYTE_PACK()
///
void dumprWithDepth(const SelectionDAG *G = nullptr,
unsigned depth = 100) const;
-#endif
/// Gather unique data for the node.
void Profile(FoldingSetNodeID &ID) const;
@@ -1237,7 +1235,6 @@ inline const DebugLoc &SDValue::getDebugLoc() const {
return Node->getDebugLoc();
}
-#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
inline void SDValue::dump() const {
return Node->dump();
}
@@ -1253,7 +1250,6 @@ inline void SDValue::dumpr() const {
inline void SDValue::dumpr(const SelectionDAG *G) const {
return Node->dumpr(G);
}
-#endif
// Define inline functions from the SDUse class.
diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h
index cfc168a9d166d..5468cedb0815a 100644
--- a/llvm/include/llvm/IR/Function.h
+++ b/llvm/include/llvm/IR/Function.h
@@ -59,8 +59,8 @@ class User;
class BranchProbabilityInfo;
class BlockFrequencyInfo;
-class LLVM_CLASS_ABI Function : public GlobalObject,
- public ilist_node<Function> {
+class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject,
+ public ilist_node<Function> {
public:
using BasicBlockListType = SymbolTableList<BasicBlock>;
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index f47398cd9d907..6135e15fd030f 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -62,7 +62,7 @@ class VersionTuple;
/// constant references to global variables in the module. When a global
/// variable is destroyed, it should have no entries in the GlobalList.
/// The main container class for the LLVM Intermediate Representation.
-class LLVM_CLASS_ABI Module {
+class LLVM_EXTERNAL_VISIBILITY Module {
/// @name Types And Enumerations
/// @{
public:
diff --git a/llvm/include/llvm/Passes/PassPlugin.h b/llvm/include/llvm/Passes/PassPlugin.h
index 43310d0b9f14a..013b7a827c47d 100644
--- a/llvm/include/llvm/Passes/PassPlugin.h
+++ b/llvm/include/llvm/Passes/PassPlugin.h
@@ -107,7 +107,7 @@ class PassPlugin {
/// };
/// }
/// ```
-extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK LLVM_ABI_EXPORT
+extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
llvmGetPassPluginInfo();
#endif /* LLVM_PASSES_PASSPLUGIN_H */
diff --git a/llvm/include/llvm/Support/TargetSelect.h b/llvm/include/llvm/Support/TargetSelect.h
index 255b37be5ed90..e57614cea758b 100644
--- a/llvm/include/llvm/Support/TargetSelect.h
+++ b/llvm/include/llvm/Support/TargetSelect.h
@@ -16,35 +16,34 @@
#define LLVM_SUPPORT_TARGETSELECT_H
#include "llvm/Config/llvm-config.h"
-#include "llvm/Support/Compiler.h"
extern "C" {
// Declare all of the target-initialization functions that are available.
-#define LLVM_TARGET(TargetName) LLVM_C_ABI void LLVMInitialize##TargetName##TargetInfo();
+#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetInfo();
#include "llvm/Config/Targets.def"
-#define LLVM_TARGET(TargetName) LLVM_C_ABI void LLVMInitialize##TargetName##Target();
+#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
#include "llvm/Config/Targets.def"
// Declare all of the target-MC-initialization functions that are available.
-#define LLVM_TARGET(TargetName) LLVM_C_ABI void LLVMInitialize##TargetName##TargetMC();
+#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetMC();
#include "llvm/Config/Targets.def"
// Declare all of the available assembly printer initialization functions.
-#define LLVM_ASM_PRINTER(TargetName) LLVM_C_ABI void LLVMInitialize##TargetName##AsmPrinter();
+#define LLVM_ASM_PRINTER(TargetName) void LLVMInitialize##TargetName##AsmPrinter();
#include "llvm/Config/AsmPrinters.def"
// Declare all of the available assembly parser initialization functions.
-#define LLVM_ASM_PARSER(TargetName) LLVM_C_ABI void LLVMInitialize##TargetName##AsmParser();
+#define LLVM_ASM_PARSER(TargetName) void LLVMInitialize##TargetName##AsmParser();
#include "llvm/Config/AsmParsers.def"
// Declare all of the available disassembler initialization functions.
#define LLVM_DISASSEMBLER(TargetName) \
- LLVM_C_ABI void LLVMInitialize##TargetName##Disassembler();
+ void LLVMInitialize##TargetName##Disassembler();
#include "llvm/Config/Disassemblers.def"
// Declare all of the available TargetMCA initialization functions.
-#define LLVM_TARGETMCA(TargetName) LLVM_C_ABI void LLVMInitialize##TargetName##TargetMCA();
+#define LLVM_TARGETMCA(TargetName) void LLVMInitialize##TargetName##TargetMCA();
#include "llvm/Config/TargetMCAs.def"
}
diff --git a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
index 1d82b2cd50e07..855d1aeddfaee 100644
--- a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
+++ b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
@@ -44,7 +44,7 @@ class TargetTransformInfo;
///
/// This class provides both the logic to recursively visit instructions and
/// combine them.
-class LLVM_ABI_NOT_EXPORTED InstCombiner {
+class LLVM_LIBRARY_VISIBILITY InstCombiner {
/// Only used to call target specific intrinsic combining.
/// It must **NOT** be used for any other purpose, as InstCombine is a
/// target-independent canonicalization transform.
diff --git a/llvm/include/llvm/Transforms/Scalar/GVN.h b/llvm/include/llvm/Transforms/Scalar/GVN.h
index 95d903c5b4565..debe2ee799172 100644
--- a/llvm/include/llvm/Transforms/Scalar/GVN.h
+++ b/llvm/include/llvm/Transforms/Scalar/GVN.h
@@ -56,7 +56,7 @@ class TargetLibraryInfo;
class Value;
/// A private "module" namespace for types and utilities used by GVN. These
/// are implementation details and should not be used by clients.
-namespace gvn {
+namespace LLVM_LIBRARY_VISIBILITY gvn {
struct AvailableValue;
struct AvailableValueInBlock;
diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp
index 8136407e4d5b2..7529d9cef67ed 100644
--- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp
@@ -26,13 +26,13 @@ extern "C" {
// We put information about the JITed function in this global, which the
// debugger reads. Make sure to specify the version statically, because the
// debugger checks the version before we can set it during runtime.
-LLVM_ALWAYS_EXPORT
+LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
struct jit_descriptor __jit_debug_descriptor = {JitDescriptorVersion, 0,
nullptr, nullptr};
// Debuggers that implement the GDB JIT interface put a special breakpoint in
// this function.
-LLVM_ALWAYS_EXPORT
+LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
LLVM_ATTRIBUTE_NOINLINE void __jit_debug_register_code() {
// The noinline and the asm prevent calls to this function from being
// optimized out.
diff --git a/llvm/lib/Support/BLAKE3/CMakeLists.txt b/llvm/lib/Support/BLAKE3/CMakeLists.txt
index 9a253cd4fc236..51317b8048f76 100644
--- a/llvm/lib/Support/BLAKE3/CMakeLists.txt
+++ b/llvm/lib/Support/BLAKE3/CMakeLists.txt
@@ -81,8 +81,3 @@ endif()
add_library(LLVMSupportBlake3 OBJECT EXCLUDE_FROM_ALL ${LLVM_BLAKE3_FILES})
set_target_properties(LLVMSupportBlake3 PROPERTIES FOLDER "LLVM/Libraries")
llvm_update_compile_flags(LLVMSupportBlake3)
-
-# We have to manually set this because this library was not created with llvm_add_library
-if(LLVM_BUILD_LLVM_DYLIB)
- target_compile_definitions(LLVMSupportBlake3 PRIVATE LLVM_ABI_EXPORTS)
-endif()
diff --git a/llvm/lib/Support/BLAKE3/blake3.c b/llvm/lib/Support/BLAKE3/blake3.c
index a23dfce491b5c..23f0252602de2 100644
--- a/llvm/lib/Support/BLAKE3/blake3.c
+++ b/llvm/lib/Support/BLAKE3/blake3.c
@@ -12,7 +12,7 @@
#include "blake3_impl.h"
-LLVM_C_ABI const char *llvm_blake3_version(void) { return BLAKE3_VERSION_STRING; }
+const char *llvm_blake3_version(void) { return BLAKE3_VERSION_STRING; }
INLINE void chunk_state_init(blake3_chunk_state *self, const uint32_t key[8],
uint8_t flags) {
@@ -371,16 +371,16 @@ INLINE void hasher_init_base(blake3_hasher *self, const uint32_t key[8],
self->cv_stack_len = 0;
}
-LLVM_C_ABI void llvm_blake3_hasher_init(blake3_hasher *self) { hasher_init_base(self, IV, 0); }
+void llvm_blake3_hasher_init(blake3_hasher *self) { hasher_init_base(self, IV, 0); }
-LLVM_C_ABI void llvm_blake3_hasher_init_keyed(blake3_hasher *self,
+void llvm_blake3_hasher_init_keyed(blake3_hasher *self,
const uint8_t key[BLAKE3_KEY_LEN]) {
uint32_t key_words[8];
load_key_words(key, key_words);
hasher_init_base(self, key_words, KEYED_HASH);
}
-LLVM_C_ABI void llvm_blake3_hasher_init_derive_key_raw(blake3_hasher *self, const void *context,
+void llvm_blake3_hasher_init_derive_key_raw(blake3_hasher *self, const void *context,
size_t context_len) {
blake3_hasher context_hasher;
hasher_init_base(&context_hasher, IV, DERIVE_KEY_CONTEXT);
@@ -392,7 +392,7 @@ LLVM_C_ABI void llvm_blake3_hasher_init_derive_key_raw(blake3_hasher *self, cons
hasher_init_base(self, context_key_words, DERIVE_KEY_MATERIAL);
}
-LLVM_C_ABI void llvm_blake3_hasher_init_derive_key(blake3_hasher *self, const char *context) {
+void llvm_blake3_hasher_init_derive_key(blake3_hasher *self, const char *context) {
llvm_blake3_hasher_init_derive_key_raw(self, context, strlen(context));
}
@@ -457,7 +457,7 @@ INLINE void hasher_push_cv(blake3_hasher *self, uint8_t new_cv[BLAKE3_OUT_LEN],
self->cv_stack_len += 1;
}
-LLVM_C_ABI void llvm_blake3_hasher_update(blake3_hasher *self, const void *input,
+void llvm_blake3_hasher_update(blake3_hasher *self, const void *input,
size_t input_len) {
// Explicitly checking for zero avoids causing UB by passing a null pointer
// to memcpy. This comes up in practice with things like:
@@ -575,7 +575,7 @@ void llvm_blake3_hasher_finalize(const blake3_hasher *self, uint8_t *out,
#endif
}
-LLVM_C_ABI void llvm_blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek,
+void llvm_blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek,
uint8_t *out, size_t out_len) {
// Explicitly checking for zero avoids causing UB by passing a null pointer
// to memcpy. This comes up in practice with things like:
@@ -619,7 +619,7 @@ LLVM_C_ABI void llvm_blake3_hasher_finalize_seek(const blake3_hasher *self, uint
output_root_bytes(&output, seek, out, out_len);
}
-LLVM_C_ABI void llvm_blake3_hasher_reset(blake3_hasher *self) {
+void llvm_blake3_hasher_reset(blake3_hasher *self) {
chunk_state_reset(&self->chunk, self->key, 0);
self->cv_stack_len = 0;
}
diff --git a/llvm/lib/Support/SmallVector.cpp b/llvm/lib/Support/SmallVector.cpp
index 6593dc31cb5e0..b6ce37842040b 100644
--- a/llvm/lib/Support/SmallVector.cpp
+++ b/llvm/lib/Support/SmallVector.cpp
@@ -156,14 +156,14 @@ void SmallVectorBase<Size_T>::grow_pod(void *FirstEl, size_t MinSize,
this->set_allocation_range(NewElts, NewCapacity);
}
-template class LLVM_EXPORT_TEMPLATE llvm::SmallVectorBase<uint32_t>;
+template class llvm::SmallVectorBase<uint32_t>;
// Disable the uint64_t instantiation for 32-bit builds.
// Both uint32_t and uint64_t instantiations are needed for 64-bit builds.
// This instantiation will never be used in 32-bit builds, and will cause
// warnings when sizeof(Size_T) > sizeof(size_t).
#if SIZE_MAX > UINT32_MAX
-template class LLVM_EXPORT_TEMPLATE llvm::SmallVectorBase<uint64_t>;
+template class llvm::SmallVectorBase<uint64_t>;
// Assertions to ensure this #if stays in sync with SmallVectorSizeType.
static_assert(sizeof(SmallVectorSizeType<char>) == sizeof(uint64_t),
diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
index 486ae17b8b76c..c0f54b223877c 100644
--- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -4924,7 +4924,7 @@ bool X86AsmParser::parseDirectiveSEHPushFrame(SMLoc Loc) {
}
// Force static initialization.
-extern "C" LLVM_C_ABI void LLVMInitializeX86AsmParser() {
+extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86AsmParser() {
RegisterMCAsmParser<X86AsmParser> X(getTheX86_32Target());
RegisterMCAsmParser<X86AsmParser> Y(getTheX86_64Target());
}
diff --git a/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp b/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
index 9a473784a8d40..6272e2d270f25 100644
--- a/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
+++ b/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
@@ -2470,7 +2470,7 @@ static MCDisassembler *createX86Disassembler(const Target &T,
return new X86GenericDisassembler(STI, Ctx, std::move(MII));
}
-extern "C" LLVM_C_ABI void LLVMInitializeX86Disassembler() {
+extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86Disassembler() {
// Register the disassembler.
TargetRegistry::RegisterMCDisassembler(getTheX86_32Target(),
createX86Disassembler);
diff --git a/llvm/lib/Target/X86/MCA/X86CustomBehaviour.cpp b/llvm/lib/Target/X86/MCA/X86CustomBehaviour.cpp
index 28aceb0659325..84a3ee3ef27e0 100644
--- a/llvm/lib/Target/X86/MCA/X86CustomBehaviour.cpp
+++ b/llvm/lib/Target/X86/MCA/X86CustomBehaviour.cpp
@@ -56,7 +56,7 @@ static InstrPostProcess *createX86InstrPostProcess(const MCSubtargetInfo &STI,
/// Extern function to initialize the targets for the X86 backend
-extern "C" LLVM_C_ABI void LLVMInitializeX86TargetMCA() {
+extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86TargetMCA() {
TargetRegistry::RegisterInstrPostProcess(getTheX86_32Target(),
createX86InstrPostProcess);
TargetRegistry::RegisterInstrPostProcess(getTheX86_64Target(),
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
index 04adf9a787ef2..ed4d0a45bd8f2 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
@@ -710,7 +710,7 @@ static MCInstrAnalysis *createX86MCInstrAnalysis(const MCInstrInfo *Info) {
}
// Force static initialization.
-extern "C" LLVM_C_ABI void LLVMInitializeX86TargetMC() {
+extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86TargetMC() {
for (Target *T : {&getTheX86_32Target(), &getTheX86_64Target()}) {
// Register the MC asm info.
RegisterMCAsmInfoFn X(*T, createX86MCAsmInfo);
diff --git a/llvm/lib/Target/X86/TargetInfo/X86TargetInfo.cpp b/llvm/lib/Target/X86/TargetInfo/X86TargetInfo.cpp
index c8df3c29bb046..7490703251e9c 100644
--- a/llvm/lib/Target/X86/TargetInfo/X86TargetInfo.cpp
+++ b/llvm/lib/Target/X86/TargetInfo/X86TargetInfo.cpp
@@ -19,7 +19,7 @@ Target &llvm::getTheX86_64Target() {
return TheX86_64Target;
}
-extern "C" LLVM_C_ABI void LLVMInitializeX86TargetInfo() {
+extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86TargetInfo() {
RegisterTarget<Triple::x86, /*HasJIT=*/true> X(
getTheX86_32Target(), "x86", "32-bit X86: Pentium-Pro and above", "X86");
diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp
index 97d320b9a48d1..3395a13545e45 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp
@@ -1040,7 +1040,7 @@ void X86AsmPrinter::emitEndOfAsmFile(Module &M) {
//===----------------------------------------------------------------------===//
// Force static initialization.
-extern "C" LLVM_C_ABI void LLVMInitializeX86AsmPrinter() {
+extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86AsmPrinter() {
RegisterAsmPrinter<X86AsmPrinter> X(getTheX86_32Target());
RegisterAsmPrinter<X86AsmPrinter> Y(getTheX86_64Target());
}
diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp
index a7966ec55bb43..d4e642c7df9cf 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.cpp
+++ b/llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -65,7 +65,7 @@ static cl::opt<bool>
cl::desc("Enable the tile register allocation pass"),
cl::init(true), cl::Hidden);
-extern "C" LLVM_C_ABI void LLVMInitializeX86Target() {
+extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86Target() {
// Register the target.
RegisterTargetMachine<X86TargetMachine> X(getTheX86_32Target());
RegisterTargetMachine<X86TargetMachine> Y(getTheX86_64Target());
diff --git a/llvm/tools/lto/CMakeLists.txt b/llvm/tools/lto/CMakeLists.txt
index 1983fc008c9ee..67f6d3af40e05 100644
--- a/llvm/tools/lto/CMakeLists.txt
+++ b/llvm/tools/lto/CMakeLists.txt
@@ -32,10 +32,6 @@ endif()
add_llvm_library(${LTO_LIBRARY_NAME} ${LTO_LIBRARY_TYPE} INSTALL_WITH_TOOLCHAIN
${SOURCES} DEPENDS intrinsics_gen)
-if (LLVM_BUILD_LLVM_DYLIB)
- target_compile_definitions(${LTO_LIBRARY_NAME} PRIVATE LLVM_BUILDING_LIBLTO)
-endif()
-
install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/lto.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/llvm-c"
COMPONENT LTO)
>From 3fa2755daf10c89b4f76b4828335d3d9a8ede4b0 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Thu, 11 Jul 2024 03:32:38 +0100
Subject: [PATCH 24/25] Revert Linux symbol visibility changes since they can't
go in until all of the API surface is annotated with export macros
---
llvm/cmake/modules/AddLLVM.cmake | 13 -------------
llvm/lib/Target/CMakeLists.txt | 11 +++++++++++
2 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 177eaa062b87d..03f8ddd251658 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -659,19 +659,6 @@ function(llvm_add_library name)
if(ARG_COMPONENT_LIB)
set_target_properties(${name} PROPERTIES LLVM_COMPONENT TRUE)
target_compile_definitions(${name} PRIVATE LLVM_EXPORTS)
-
- # When building shared objects for each target there are some internal APIs
- # that are used across shared objects which we can't hide.
- if (NOT BUILD_SHARED_LIBS AND NOT APPLE AND
- (NOT (WIN32 OR CYGWIN) OR (MINGW AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND
- NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX") AND
- NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET)
-
- set_target_properties(${name} PROPERTIES
- C_VISIBILITY_PRESET hidden
- CXX_VISIBILITY_PRESET hidden
- VISIBILITY_INLINES_HIDDEN YES)
- endif()
set_property(GLOBAL APPEND PROPERTY LLVM_COMPONENT_LIBS ${name})
endif()
diff --git a/llvm/lib/Target/CMakeLists.txt b/llvm/lib/Target/CMakeLists.txt
index 2a0edbe058984..2739233f9ccb3 100644
--- a/llvm/lib/Target/CMakeLists.txt
+++ b/llvm/lib/Target/CMakeLists.txt
@@ -20,6 +20,17 @@ add_llvm_component_library(LLVMTarget
TargetParser
)
+# When building shared objects for each target there are some internal APIs
+# that are used across shared objects which we can't hide.
+if (NOT BUILD_SHARED_LIBS AND NOT APPLE AND
+ (NOT (WIN32 OR CYGWIN) OR (MINGW AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND
+ NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX") AND
+ NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET)
+ # Set default visibility to hidden, so we don't export all the Target classes
+ # in libLLVM.so.
+ set(CMAKE_CXX_VISIBILITY_PRESET hidden)
+endif()
+
foreach(t ${LLVM_TARGETS_TO_BUILD})
message(STATUS "Targeting ${t}")
add_subdirectory(${t})
>From ba03cd68d9b1d0c4ebcbf831642c47d55b93aa2e Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Fri, 12 Jul 2024 22:00:52 +0100
Subject: [PATCH 25/25] Also enable export macros when only LLVM_ENABLE_PLUGINS
is set so symbols are exported from executables
---
llvm/include/llvm/Support/Compiler.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index 6aa9a10aab9cf..40f615dfe0e16 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -158,7 +158,8 @@
// 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
-#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS)
+#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS) || \
+ defined(LLVM_ENABLE_PLUGINS)
// Some libraries like those for tablegen are linked in to tools that used
// in the build so can't depend on the llvm shared library. If export macros
// were left enabled when building these we would get duplicate or
More information about the llvm-commits
mailing list