[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
Tue Jun 25 06:05:26 PDT 2024
https://github.com/fsfod created https://github.com/llvm/llvm-project/pull/96630
These are some of the main build and some code changes/fixes I've had to do to get just llvm building as a shared library on windows without having to force export all symbols and filter them with a python script and Linux with the default symbol visibility set to hidden. Some of the cmake and code changes are based on @tstellar's earlier PR https://github.com/llvm/llvm-project/pull/67502, in my full branch most of my changes based on top of the commits from that PR.
I have managed to get both Windows building using clang-cl, MSVC is at-least able to build libllvm, but I still have to solve some linker errors when building some of the tools. Linux also builds without issue, but has two test failures that might just be from bad commit tip i choose as a branch base. My full branch is here https://github.com/fsfod/llvm-project/tree/llvm-exported-api and with all the auto generated export macros.
I'm posting to get some feedback if I'm going the wrong direction on anything or if there is better way to do something. @vgvassilev @compnerd @tstellar
>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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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.
More information about the llvm-commits
mailing list