From 7aeebfd91857b18e5335edf00728d3c71339835f Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Tue, 15 Apr 2025 17:07:27 -0700 Subject: [PATCH 1/5] [llvm] use __attribute__ for export visibility macros --- llvm/include/llvm/Support/Compiler.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h index d265d864228ca..7b490d7db4dcf 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -199,15 +199,15 @@ #define LLVM_ABI_EXPORT __declspec(dllexport) #elif defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \ defined(__MVS__) -#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT -#define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT +#define LLVM_ABI __attribute__((visibility("default"))) +#define LLVM_TEMPLATE_ABI __attribute__((visibility("default"))) #define LLVM_EXPORT_TEMPLATE -#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT +#define LLVM_ABI_EXPORT __attribute__((visibility("default"))) #elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__) -#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT +#define LLVM_ABI __attribute__((visibility("default"))) #define LLVM_TEMPLATE_ABI #define LLVM_EXPORT_TEMPLATE -#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT +#define LLVM_ABI_EXPORT __attribute__((visibility("default"))) #endif #else #define LLVM_ABI From c57be05d0a7613f91837fd124108bb6819d252f4 Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Tue, 15 Apr 2025 17:07:54 -0700 Subject: [PATCH 2/5] [llvm] do not define LLVM_TEMPLATE_ABI for GCC builds --- llvm/include/llvm/Support/Compiler.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h index 7b490d7db4dcf..fd103ea72e55c 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -200,7 +200,12 @@ #elif defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \ defined(__MVS__) #define LLVM_ABI __attribute__((visibility("default"))) +#if defined(__GNUC__) && !defined(__clang__) +// GCC produces warnings on visibility attributes applied to templates. +#define LLVM_TEMPLATE_ABI +#else #define LLVM_TEMPLATE_ABI __attribute__((visibility("default"))) +#endif #define LLVM_EXPORT_TEMPLATE #define LLVM_ABI_EXPORT __attribute__((visibility("default"))) #elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__) From 3d62cf05b5ac87c3a2cd4560b67c7155bb6b83ae Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Wed, 16 Apr 2025 09:15:22 -0700 Subject: [PATCH 3/5] [llvm] check for visibility attribute --- llvm/include/llvm/Support/Compiler.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h index fd103ea72e55c..5dfac827e615c 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -197,8 +197,8 @@ #define LLVM_EXPORT_TEMPLATE #endif #define LLVM_ABI_EXPORT __declspec(dllexport) -#elif defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \ - defined(__MVS__) +#elif (defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \ + defined(__MVS__)) && __has_attribute(visibililty) #define LLVM_ABI __attribute__((visibility("default"))) #if defined(__GNUC__) && !defined(__clang__) // GCC produces warnings on visibility attributes applied to templates. @@ -208,11 +208,17 @@ #endif #define LLVM_EXPORT_TEMPLATE #define LLVM_ABI_EXPORT __attribute__((visibility("default"))) -#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__) +#elif (defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__)) && \ + __has_attribute(visibility) #define LLVM_ABI __attribute__((visibility("default"))) #define LLVM_TEMPLATE_ABI #define LLVM_EXPORT_TEMPLATE #define LLVM_ABI_EXPORT __attribute__((visibility("default"))) +#else +#define LLVM_ABI +#define LLVM_TEMPLATE_ABI +#define LLVM_EXPORT_TEMPLATE +#define LLVM_ABI_EXPORT #endif #else #define LLVM_ABI From 74ed68fcb6cfc3b804ce21b79c35282edb484278 Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Wed, 16 Apr 2025 10:33:48 -0700 Subject: [PATCH 4/5] [llvm] additional comments --- llvm/include/llvm/Support/Compiler.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h index 5dfac827e615c..d24d78a5b3c1d 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -199,9 +199,12 @@ #define LLVM_ABI_EXPORT __declspec(dllexport) #elif (defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \ defined(__MVS__)) && __has_attribute(visibililty) +// Use __attribute__((visibility(""))) syntax for visibility rather than +// [[gnu::visibility("")]] because compilers are more permissive with its +// placement. #define LLVM_ABI __attribute__((visibility("default"))) #if defined(__GNUC__) && !defined(__clang__) -// GCC produces warnings on visibility attributes applied to templates. +// GCC produces warnings on visibility attributes applied to some templates. #define LLVM_TEMPLATE_ABI #else #define LLVM_TEMPLATE_ABI __attribute__((visibility("default"))) From 294ea13c1cb94c01765145f2082374febec95c32 Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Wed, 16 Apr 2025 11:33:55 -0700 Subject: [PATCH 5/5] clang format --- 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 d24d78a5b3c1d..baa5fb5c6b97b 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -198,7 +198,8 @@ #endif #define LLVM_ABI_EXPORT __declspec(dllexport) #elif (defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \ - defined(__MVS__)) && __has_attribute(visibililty) + defined(__MVS__)) && \ + __has_attribute(visibililty) // Use __attribute__((visibility(""))) syntax for visibility rather than // [[gnu::visibility("")]] because compilers are more permissive with its // placement.