From cfd16c04f8316270b67c73775a5885d6bc4dc4e2 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 29 Jul 2022 17:31:52 +0200 Subject: Build: hide all symbols except a few required ones on Linux Instead of specifying which symbols to hide, we hide all and make a few visible. Some users may be relying on calling internal Blender functions, but Windows is already hiding all of them and this is just not supported. Fixes T99900: crash with some third-party Python libraries since OneAPI Ref T76442 Differential Revision: https://developer.blender.org/D14971 --- build_files/cmake/platform/platform_apple.cmake | 3 +- build_files/cmake/platform/platform_unix.cmake | 3 +- source/creator/CMakeLists.txt | 6 +- source/creator/blender.map | 173 ------------------------ source/creator/osx_locals.map | 71 ---------- source/creator/symbols_apple.map | 71 ++++++++++ source/creator/symbols_unix.map | 44 ++++++ 7 files changed, 121 insertions(+), 250 deletions(-) delete mode 100644 source/creator/blender.map delete mode 100644 source/creator/osx_locals.map create mode 100644 source/creator/symbols_apple.map create mode 100644 source/creator/symbols_unix.map diff --git a/build_files/cmake/platform/platform_apple.cmake b/build_files/cmake/platform/platform_apple.cmake index 3c77a28d55f..f84be3c5238 100644 --- a/build_files/cmake/platform/platform_apple.cmake +++ b/build_files/cmake/platform/platform_apple.cmake @@ -470,8 +470,9 @@ string(APPEND CMAKE_CXX_FLAGS " -ftemplate-depth=1024") # Avoid conflicts with Luxrender, and other plug-ins that may use the same # libraries as Blender with a different version or build options. +set(PLATFORM_SYMBOLS_MAP ${CMAKE_SOURCE_DIR}/source/creator/symbols_apple.map) string(APPEND PLATFORM_LINKFLAGS - " -Wl,-unexported_symbols_list,'${CMAKE_SOURCE_DIR}/source/creator/osx_locals.map'" + " -Wl,-unexported_symbols_list,'${PLATFORM_SYMBOLS_MAP}'" ) string(APPEND CMAKE_CXX_FLAGS " -stdlib=libc++") diff --git a/build_files/cmake/platform/platform_unix.cmake b/build_files/cmake/platform/platform_unix.cmake index d22cf437e59..f6e233a0c86 100644 --- a/build_files/cmake/platform/platform_unix.cmake +++ b/build_files/cmake/platform/platform_unix.cmake @@ -888,8 +888,9 @@ unset(_IS_LINKER_DEFAULT) # Avoid conflicts with Mesa llvmpipe, Luxrender, and other plug-ins that may # use the same libraries as Blender with a different version or build options. +set(PLATFORM_SYMBOLS_MAP ${CMAKE_SOURCE_DIR}/source/creator/symbols_unix.map) set(PLATFORM_LINKFLAGS - "${PLATFORM_LINKFLAGS} -Wl,--version-script='${CMAKE_SOURCE_DIR}/source/creator/blender.map'" + "${PLATFORM_LINKFLAGS} -Wl,--version-script='${PLATFORM_SYMBOLS_MAP}'" ) # Don't use position independent executable for portable install since file diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 278cd4362c3..11f48a72908 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -1216,10 +1216,8 @@ unset(LIB) setup_platform_linker_flags(blender) setup_platform_linker_libs(blender) -if(APPLE) - set_target_properties(blender PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/osx_locals.map) -elseif(UNIX) - set_target_properties(blender PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/blender.map) +if(DEFINED PLATFORM_SYMBOLS_MAP) + set_target_properties(blender PROPERTIES LINK_DEPENDS ${PLATFORM_SYMBOLS_MAP}) endif() # ----------------------------------------------------------------------------- diff --git a/source/creator/blender.map b/source/creator/blender.map deleted file mode 100644 index 500892a20f3..00000000000 --- a/source/creator/blender.map +++ /dev/null @@ -1,173 +0,0 @@ - -/* on Linux we exclude LLVM symbols, they conflict with Mesa llvmpipe - * we also keep boost's symbols local, since some python modules could - * be using boost as well (mainly that's for lux render) - */ - -{ -global: - *; - *_boost*; -local: - __once_proxy; - _ZSt11__once_call; - _ZSt15__once_callable; - al*; - *Alembic*; - av*; - blosc*; - *boost*; - *ceres*; - *cineon*; - *clang*; - *COLLADA*; - cu*; - *default_error_condition*; - *dpx*; - *embree*; - ff_*; - fftw*; - FLAC*; - FT_*; - *GeneratedSaxParser*; - *google*; - gsm*; - Gsm*; - html*; - id3tag*; - *Iex*; - *Ilm*; - *Imath*; - *Imf*; - jack_*; - jpeg_*; - jsimd**; - lame_*; - *llvm*; - *LLVM*; - *MathML*; - *mkldnn*; - nvrtc*; - oc_*; - ogg*; - *oidn*; - *OpenColorIO*; - *OpenImageIO*; - *OpenSubdiv*; - *openvdb*; - opj_*; - opus_*; - *OSL*; - *pathYy*; - png_*; - *SDL*; - *squish*; - *tbb*; - *textFileFormatYy*; - *TIFF*; - *tinyformat*; - *usdBlender*; - vorbis*; - vp8*; - vp9*; - vpx*; - x264_*; - xml*; - xvid*; - *YAML*; - - /* LLVM symbols not in the LLVM namespace that can conflict with LLVM usage - * in OpenGL and OpenCL drivers. - * - * These are found by doing a Blender build with and without OSL, and - * comparing the output of nm -gD ./bin/blender to find symbols. */ - AlwaysSpillBase; - AsmMacroMaxNestingDepth; - AttributorRun; - CheckBFIUnknownBlockQueries; - *cloneBitwiseIVUser*; - *computeHostNumHardwareThread*; - *computeHostNumPhysicalCores*; - decodeInstruction; - DisableBasicAA; - DisablePreInliner; - DisableWholeProgramVisibility; - EnableCHR; - EnableConstraintElimination; - EnableGVNHoist; - EnableGVNSink; - EnableHotColdSplit; - EnableIPRA; - EnableIROutliner; - EnableKnowledgeRetention; - EnableLoopFlatten; - EnableMatrix; - EnableOrderFileInstrumentation; - EnablePGSO; - EnableUnrollAndJam; - EnableVPlanNativePath; - EnableVPlanPredication; - ExtraVectorizerPasses; - FlattenedProfileUsed; - ForcePGSO; - ForceStackAlign; - ForceSummaryEdgesCold; - FSEC; - *getExtendedOperandRecurrence*; - *getWideRecurrence*; - InlinerFunctionImportStats; - *IROutlinerLegacyPass*; - __jit_debug_descriptor; - __jit_debug_register_code; - _Jv_RegisterClasses; - *LiveDebugValues*; - *LoopInterchangeLegacyPass*; - MachineRegionInfoPassID; - MaxDevirtIterations; - MaxRegistersForGCPointers; - MemOPOptMemcmpBcmp; - MemOPSizeLarge; - MemOPSizeRange; - MISchedPostRA; - ModuleSummaryDotFile; - __morestack; - Name; - NumNamedVarArgParams; - PGOViewCounts; - PGSOColdCodeOnly; - PGSOColdCodeOnlyForInstrPGO; - PGSOColdCodeOnlyForPartialSamplePGO; - PGSOColdCodeOnlyForSamplePGO; - PgsoCutoffInstrProf; - PgsoCutoffSampleProf; - PGSOLargeWorkingSetSizeOnly; - PreInlineThreshold; - PrintBlockFreqFuncName; - PrintBranchProbFuncName; - ProfileLikelyProb; - RunNewGVN; - RunPartialInlining; - RunSLPVectorization; - ScalePartialSampleProfileWorkingSetSize; - *ScopedAliasMetadataDeepCloner*; - ShouldPreserveAllAttributes; - SkipFunctionNames; - StartAfterOptName; - StartBeforeOptName; - StaticLikelyProb; - StopAfterOptName; - StopBeforeOptName; - UseContextLessSummary; - UseDbgAddr; - UseLEB128Directives; - UseRegistersForDeoptValues; - UseRegistersForGCPointersInLandingPad; - ViewBlockFreqFuncName; - ViewBlockLayoutWithBFI; - ViewHotFreqPercent; - WholeProgramVisibility; - *widenLoopCompare*; - *widenWithVariant*; - WriteRelBFToSummary; - X86CompilationCallback*; -}; diff --git a/source/creator/osx_locals.map b/source/creator/osx_locals.map deleted file mode 100644 index 5619f151bd2..00000000000 --- a/source/creator/osx_locals.map +++ /dev/null @@ -1,71 +0,0 @@ -## The symbols will be treated as if they were marked as __private_extern__ -## (aka visibility=hidden) and will not be global in the output file -al* -*Alembic* -av* -blosc* -*boost* -*ceres* -*cineon* -*clang* -*COLLADA* -cu* -decodeInstruction -*default_error_condition* -*dpx* -*embree* -ff_* -fftw* -FLAC* -ForceStackAlign -FT_* -*GeneratedSaxParser* -*google* -gsm* -Gsm* -html* -id3tag* -*Iex* -*Ilm* -*Imath* -*Imf* -jack_* -jpeg_* -jsimd** -_Jv_RegisterClasses -lame_* -*llvm* -*LLVM* -*MathML* -*mkldnn* -Name -NumNamedVarArgParams -nvrtc* -oc_* -ogg* -*oidn* -*OpenColorIO* -*OpenImageIO* -*OpenSubdiv* -*openvdb* -opj_* -opus_* -*OSL* -*pathYy* -png_* -*SDL* -*squish* -*tbb* -*textFileFormatYy* -*TIFF* -*tinyformat* -*usdBlender* -vorbis* -vp8* -vp9* -vpx* -x264_* -X86CompilationCallback* -xml* -xvid* -*YAML* diff --git a/source/creator/symbols_apple.map b/source/creator/symbols_apple.map new file mode 100644 index 00000000000..5619f151bd2 --- /dev/null +++ b/source/creator/symbols_apple.map @@ -0,0 +1,71 @@ +## The symbols will be treated as if they were marked as __private_extern__ +## (aka visibility=hidden) and will not be global in the output file +al* +*Alembic* +av* +blosc* +*boost* +*ceres* +*cineon* +*clang* +*COLLADA* +cu* +decodeInstruction +*default_error_condition* +*dpx* +*embree* +ff_* +fftw* +FLAC* +ForceStackAlign +FT_* +*GeneratedSaxParser* +*google* +gsm* +Gsm* +html* +id3tag* +*Iex* +*Ilm* +*Imath* +*Imf* +jack_* +jpeg_* +jsimd** +_Jv_RegisterClasses +lame_* +*llvm* +*LLVM* +*MathML* +*mkldnn* +Name +NumNamedVarArgParams +nvrtc* +oc_* +ogg* +*oidn* +*OpenColorIO* +*OpenImageIO* +*OpenSubdiv* +*openvdb* +opj_* +opus_* +*OSL* +*pathYy* +png_* +*SDL* +*squish* +*tbb* +*textFileFormatYy* +*TIFF* +*tinyformat* +*usdBlender* +vorbis* +vp8* +vp9* +vpx* +x264_* +X86CompilationCallback* +xml* +xvid* +*YAML* diff --git a/source/creator/symbols_unix.map b/source/creator/symbols_unix.map new file mode 100644 index 00000000000..673c402022d --- /dev/null +++ b/source/creator/symbols_unix.map @@ -0,0 +1,44 @@ +/* Hide all symbols except a few required ones. + * + * Otherwise LLVM symbols conflict with Mesa llvm pipe, boost symbols conflict + * with Luxrender, etc. */ +{ +global: + /* Essential symbols for the program to start and exit. */ + _bss_start; + __end; + _fini; + _init; + /* Needed for Python modules to work. */ + Py*; + _Py*; + /* Needed for sanitizers. Based on: + * llvm/compiler-rt/lib/sanitizer_common/scripts/gen_dynamic_list.py. */ + __asan*; + __lsan*; + __tsan*; + __ubsan*; + __sanitizer*; + __Znw*; + __Zna*; + __Zdl*; + __Zda*; + aligned_alloc; + aligned_free; + calloc*; + free; + mallinfo; + malloc*; + mallopt; + memalign; + memcpy; + posix_memalign; + pthread_*; + pvalloc; + realloc*; + realpath; + sched_*; + valloc; +local: + *; +}; -- cgit v1.2.3