From d5b316d315d5c4ace691c1f364013e39372e2ce6 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Fri, 29 Sep 2023 12:48:15 +0100 Subject: [PATCH] reduce the amount of symbols exposed by the library Gbp-Pq: Name visibility-hidden.patch --- CMakeLists.txt | 3 +++ include/LLVMSPIRVLib.h | 8 ++++++++ include/LLVMSPIRVOpts.h | 4 ++++ lib/SPIRV/libSPIRV/SPIRVModule.cpp | 2 ++ lib/SPIRV/libSPIRV/SPIRVStream.cpp | 1 + 5 files changed, 18 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08980f2..439e28d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,6 +117,9 @@ if(NOT SPIRV_TOOLS_FOUND) "--spirv-tools-dis support.") endif(NOT SPIRV_TOOLS_FOUND) +add_compile_options(-fvisibility=hidden) +add_compile_options($<$:-fvisibility-inlines-hidden>) + add_subdirectory(lib/SPIRV) add_subdirectory(tools/llvm-spirv) if(LLVM_SPIRV_INCLUDE_TESTS) diff --git a/include/LLVMSPIRVLib.h b/include/LLVMSPIRVLib.h index 7102385..0517326 100644 --- a/include/LLVMSPIRVLib.h +++ b/include/LLVMSPIRVLib.h @@ -46,6 +46,8 @@ #include #include +#pragma GCC visibility push(default) + namespace llvm { // Pass initialization functions need to be declared before inclusion of // PassSupport.h. @@ -68,8 +70,12 @@ class ModulePass; class FunctionPass; } // namespace llvm +#pragma GCC visibility pop + #include "llvm/IR/Module.h" +#pragma GCC visibility push(default) + namespace SPIRV { class SPIRVModule; @@ -229,4 +235,6 @@ FunctionPass *createSPIRVLowerBitCastToNonStandardTypeLegacy( } // namespace llvm +#pragma GCC visibility pop + #endif // SPIRV_H diff --git a/include/LLVMSPIRVOpts.h b/include/LLVMSPIRVOpts.h index 8c73b64..e009958 100644 --- a/include/LLVMSPIRVOpts.h +++ b/include/LLVMSPIRVOpts.h @@ -48,6 +48,8 @@ #include #include +#pragma GCC visibility push(default) + namespace llvm { class IntrinsicInst; } // namespace llvm @@ -225,4 +227,6 @@ private: } // namespace SPIRV +#pragma GCC visibility pop + #endif // SPIRV_LLVMSPIRVOPTS_H diff --git a/lib/SPIRV/libSPIRV/SPIRVModule.cpp b/lib/SPIRV/libSPIRV/SPIRVModule.cpp index b5c14cb..243e116 100644 --- a/lib/SPIRV/libSPIRV/SPIRVModule.cpp +++ b/lib/SPIRV/libSPIRV/SPIRVModule.cpp @@ -2137,6 +2137,7 @@ bool isSpirvBinary(const std::string &Img) { #ifdef _SPIRV_SUPPORT_TEXT_FMT +__attribute__ ((visibility ("default"))) bool convertSpirv(std::istream &IS, std::ostream &OS, std::string &ErrMsg, bool FromText, bool ToText) { auto SaveOpt = SPIRVUseTextFormat; @@ -2173,6 +2174,7 @@ bool isSpirvText(const std::string &Img) { return Magic == MagicNumber; } +__attribute__ ((visibility ("default"))) bool convertSpirv(std::string &Input, std::string &Out, std::string &ErrMsg, bool ToText) { auto FromText = isSpirvText(Input); diff --git a/lib/SPIRV/libSPIRV/SPIRVStream.cpp b/lib/SPIRV/libSPIRV/SPIRVStream.cpp index 8a9e0a4..496dc0c 100644 --- a/lib/SPIRV/libSPIRV/SPIRVStream.cpp +++ b/lib/SPIRV/libSPIRV/SPIRVStream.cpp @@ -81,6 +81,7 @@ static void readQuotedString(std::istream &IS, std::string &Str) { } #ifdef _SPIRV_SUPPORT_TEXT_FMT +__attribute__ ((visibility ("default"))) bool SPIRVUseTextFormat = false; #endif -- 2.30.2