[Bf-blender-cvs] [6143b3ab382] blender-v3.3-release: Fix compilation on Linux, glibc 2.34, and CentOS libraries

Sergey Sharybin noreply at git.blender.org
Wed Sep 21 14:27:10 CEST 2022


Commit: 6143b3ab3824316a94f2c0a8cc8f48e81371a03f
Author: Sergey Sharybin
Date:   Tue Sep 13 10:34:41 2022 +0200
Branches: blender-v3.3-release
https://developer.blender.org/rB6143b3ab3824316a94f2c0a8cc8f48e81371a03f

Fix compilation on Linux, glibc 2.34, and CentOS libraries

A continuation of previous fix for malloc hooks which got removed
from the new glibc library.

The pre-compiled jemalloc has definitions which interpose hooks
in glibc leading to linking errors with multiple hook definitions.

A simple fix is to skip doing the workaround when using jemalloc
from pre-compiled libraries.

This will likely be revisited in the future, but for now it is
important to fix compilation errors for developers.

===================================================================

M	build_files/cmake/platform/platform_unix.cmake
M	intern/libc_compat/CMakeLists.txt
M	intern/libc_compat/libc_compat.c

===================================================================

diff --git a/build_files/cmake/platform/platform_unix.cmake b/build_files/cmake/platform/platform_unix.cmake
index f6e233a0c86..7a427c4fd25 100644
--- a/build_files/cmake/platform/platform_unix.cmake
+++ b/build_files/cmake/platform/platform_unix.cmake
@@ -16,9 +16,16 @@ if(NOT DEFINED LIBDIR)
   # Choose the best suitable libraries.
   if(EXISTS ${LIBDIR_NATIVE_ABI})
     set(LIBDIR ${LIBDIR_NATIVE_ABI})
+    set(WITH_LIBC_MALLOC_HOOK_WORKAROUND True)
   elseif(EXISTS ${LIBDIR_CENTOS7_ABI})
     set(LIBDIR ${LIBDIR_CENTOS7_ABI})
     set(WITH_CXX11_ABI OFF)
+    if(WITH_MEM_JEMALLOC)
+      # jemalloc provides malloc hooks.
+      set(WITH_LIBC_MALLOC_HOOK_WORKAROUND False)
+    else()
+      set(WITH_LIBC_MALLOC_HOOK_WORKAROUND True)
+    endif()
 
     if(CMAKE_COMPILER_IS_GNUCC AND
        CMAKE_C_COMPILER_VERSION VERSION_LESS 9.3)
diff --git a/intern/libc_compat/CMakeLists.txt b/intern/libc_compat/CMakeLists.txt
index c318b3a303b..298d6f49bd9 100644
--- a/intern/libc_compat/CMakeLists.txt
+++ b/intern/libc_compat/CMakeLists.txt
@@ -18,3 +18,9 @@ set(LIB
 add_c_flag(-ffast-math)
 
 blender_add_lib(bf_intern_libc_compat "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
+
+if(WITH_LIBC_MALLOC_HOOK_WORKAROUND)
+  target_compile_definitions(bf_intern_libc_compat
+    PRIVATE WITH_LIBC_MALLOC_HOOK_WORKAROUND
+  )
+endif()
diff --git a/intern/libc_compat/libc_compat.c b/intern/libc_compat/libc_compat.c
index 97e3f518c58..79efb1c009b 100644
--- a/intern/libc_compat/libc_compat.c
+++ b/intern/libc_compat/libc_compat.c
@@ -116,7 +116,7 @@ float __powf_finite(float x, float y)
 
 #    endif /* __GLIBC_PREREQ(2, 31) */
 
-#    if __GLIBC_PREREQ(2, 34)
+#    if __GLIBC_PREREQ(2, 34) && defined(WITH_LIBC_MALLOC_HOOK_WORKAROUND)
 
 extern void *(*__malloc_hook)(size_t __size, const void *);
 extern void *(*__realloc_hook)(void *__ptr, size_t __size, const void *);



More information about the Bf-blender-cvs mailing list