-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[llvm] revisions to LLVM_ABI
export macro definitions
#144598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andrurogerz
wants to merge
4
commits into
llvm:main
Choose a base branch
from
andrurogerz:llvm-abi-annotation-revisions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2b8ec5d
[llvm] simplify export annotation control
andrurogerz d385dc2
[llvm] remove LLVM_ABI_FRIEND in favor of LLVM_ABI
andrurogerz e5c8e4e
[llvm] remove LLVM_ABI_FRIEND documentation
andrurogerz 15fcc40
[llvm] always define LLVM_ABI using __attribute__
andrurogerz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -171,11 +171,6 @@ | |||||
/// for both functions and classes. On windows its turned in to dllimport for | ||||||
/// library consumers, for other platforms its a default visibility attribute. | ||||||
/// | ||||||
/// LLVM_ABI_FRIEND is for annotating friend function declarations when the | ||||||
/// target function's original declaration is annotated with LLVM_ABI. This | ||||||
/// macro matches the LLVM_ABI macro on Windows, on other platforms it does | ||||||
/// nothing. | ||||||
/// | ||||||
/// 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 | ||||||
|
@@ -184,19 +179,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) || \ | ||||||
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 | ||||||
// missing symbol linker errors on windows. | ||||||
#if defined(LLVM_BUILD_STATIC) | ||||||
#define LLVM_ABI | ||||||
#define LLVM_ABI_FRIEND | ||||||
#define LLVM_TEMPLATE_ABI | ||||||
#define LLVM_EXPORT_TEMPLATE | ||||||
#define LLVM_ABI_EXPORT | ||||||
#elif defined(_WIN32) && !defined(__MINGW32__) | ||||||
#if defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS) && !defined(LLVM_BUILD_STATIC) | ||||||
#if defined(_WIN32) && !defined(__MINGW32__) | ||||||
#if defined(LLVM_EXPORTS) | ||||||
#define LLVM_ABI __declspec(dllexport) | ||||||
#define LLVM_TEMPLATE_ABI | ||||||
|
@@ -206,25 +190,24 @@ | |||||
#define LLVM_TEMPLATE_ABI __declspec(dllimport) | ||||||
#define LLVM_EXPORT_TEMPLATE | ||||||
#endif | ||||||
#define LLVM_ABI_FRIEND LLVM_ABI | ||||||
#define LLVM_ABI_EXPORT __declspec(dllexport) | ||||||
#elif defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \ | ||||||
#elif __has_attribute(visibility) | ||||||
#if defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \ | ||||||
defined(__MVS__) || defined(__CYGWIN__) | ||||||
#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT | ||||||
#define LLVM_ABI_FRIEND | ||||||
#define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT | ||||||
#define LLVM_ABI __attribute__((visibility("default"))) | ||||||
compnerd marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
#define LLVM_TEMPLATE_ABI LLVM_ABI | ||||||
#define LLVM_EXPORT_TEMPLATE | ||||||
#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT | ||||||
#define LLVM_ABI_EXPORTL LLVM_ABI | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo
Suggested change
|
||||||
#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__) | ||||||
#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT | ||||||
#define LLVM_ABI_FRIEND | ||||||
#define LLVM_ABI __attribute__((visibility("default"))) | ||||||
compnerd marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
#define LLVM_TEMPLATE_ABI | ||||||
#define LLVM_EXPORT_TEMPLATE | ||||||
#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT | ||||||
#define LLVM_ABI_EXPORT LLVM_ABI | ||||||
#endif | ||||||
#else | ||||||
#endif | ||||||
#endif | ||||||
#if !defined(LLVM_ABI) | ||||||
#define LLVM_ABI | ||||||
#define LLVM_ABI_FRIEND | ||||||
#define LLVM_TEMPLATE_ABI | ||||||
#define LLVM_EXPORT_TEMPLATE | ||||||
#define LLVM_ABI_EXPORT | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that at some point we will want to make
LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS
always true and remove that from the conditional check here?LLVM_BUILD_STATIC
should be able to control the behaviour as needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@compnerd I haven't figured out a way of gating these macros with a single preprocessor definition. Here is my thinking:
#define
that gets emitted tollvm-config.h
(via a#cmakedefine
) so that it will be present when LLVM clients are built. This is so clients will pick-up the__declspec(dllimport)
annotation when building on Windows. I addedLLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS
for this purpose, and I expect to add two similar definitions for the llvm-c and Demangle libraries.llvm-config.h
when building some tools/utils (e.g.tablegen
) that prefer to statically link against LLVM. This was already working withLLVM_BUILD_STATIC
.Do you have a suggestion to achieve this with a single define?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The headers are associated with a build, that build can only be used one way (static or dynamic). We should record that into
llvm-config.h
via the#cmakedefine LLVM_BUILD_STATIC
. Then when ready to enable the attributes by default:LLVM_EXPORTS
would be defined by the build system (normally, CMake would define this for you ifBUILD_SHARED_LIBS
is set and you are building theLLVM
library).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just don't see a way to eliminate support for
llvm_add_library
'sDISABLE_LLVM_LINK_LLVM_DYLIB
argument, which is what dynamically definesLLVM_BUILD_STATIC
at build time in the few cases it is needed. See AddLLVM.cmake.Here's why I believe we need to have a second variable as a dynamic override to the one in
llvm-config.h
:__declspec(dllimport)
annotations on symbol declarationsIs there a better way to solve this? Generate a second llvm-config.h for this purpose maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be building the library a second time if the configuration is different.