Building Blender on linux using glibc >= 2.34 raises linking errors from the USD library

Disclaimer : this is not a request for help, but rather a helpful reference for the people that might encounter the same problem. I’ve asked the question/discovered the solution in blender’s chat, but this is to provide a searchable and more permanent forum post for the few that might encounter this error.

While building Blender on my system (Arch linux, GCC v11.x, glibc v2.35) using the provided pre-compiled libraries, some linking errors appear at the end in the form of :

<Blender lib folder>/lib/linux_centos7_x86_64/usd/lib/libusd_usd_m.a(mallocHook.cpp.o):mallocHook.cpp:function usdBlender__pxrReserved__::ArchMallocHook::Initialize(void* (*)(unsigned long, void const*), void* (*)(void*, unsigned long, void const*), void* (*)(unsigned long, unsigned long, void const*), void (*)(void*, void const*), std::string*): error: undefined reference to '__malloc_hook'
<Blender lib folder>/linux_centos7_x86_64/usd/lib/libusd_usd_m.a(mallocHook.cpp.o):mallocHook.cpp:function usdBlender__pxrReserved__::ArchMallocHook::Initialize(void* (*)(unsigned long, void const*), void* (*)(void*, unsigned long, void const*), void* (*)(unsigned long, unsigned long, void const*), void (*)(void*, void const*), std::string*): error: undefined reference to '__malloc_hook'
<Blender lib folder>/linux_centos7_x86_64/usd/lib/libusd_usd_m.a(mallocHook.cpp.o):mallocHook.cpp:function usdBlender__pxrReserved__::ArchMallocHook::Initialize(void* (*)(unsigned long, void const*), void* (*)(void*, unsigned long, void const*), void* (*)(unsigned long, unsigned long, void const*), void (*)(void*, void const*), std::string*): error: undefined reference to '__realloc_hook'
<Blender lib folder>/linux_centos7_x86_64/usd/lib/libusd_usd_m.a(mallocHook.cpp.o):mallocHook.cpp:function usdBlender__pxrReserved__::ArchMallocHook::Initialize(void* (*)(unsigned long, void const*), void* (*)(void*, unsigned long, void const*), void* (*)(unsigned long, unsigned long, void const*), void (*)(void*, void const*), std::string*): error: undefined reference to '__realloc_hook'
<Blender lib folder>/linux_centos7_x86_64/usd/lib/libusd_usd_m.a(mallocHook.cpp.o):mallocHook.cpp:function usdBlender__pxrReserved__::ArchMallocHook::Initialize(void* (*)(unsigned long, void const*), void* (*)(void*, unsigned long, void const*), void* (*)(unsigned long, unsigned long, void const*), void (*)(void*, void const*), std::string*): error: undefined reference to '__memalign_hook'
<Blender lib folder>/linux_centos7_x86_64/usd/lib/libusd_usd_m.a(mallocHook.cpp.o):mallocHook.cpp:function usdBlender__pxrReserved__::ArchMallocHook::Initialize(void* (*)(unsigned long, void const*), void* (*)(void*, unsigned long, void const*), void* (*)(unsigned long, unsigned long, void const*), void (*)(void*, void const*), std::string*): error: undefined reference to '__memalign_hook'
<Blender lib folder>/linux_centos7_x86_64/usd/lib/libusd_usd_m.a(mallocHook.cpp.o):mallocHook.cpp:function usdBlender__pxrReserved__::ArchMallocHook::Initialize(void* (*)(unsigned long, void const*), void* (*)(void*, unsigned long, void const*), void* (*)(unsigned long, unsigned long, void const*), void (*)(void*, void const*), std::string*): error: undefined reference to '__free_hook'
<Blender lib folder>/linux_centos7_x86_64/usd/lib/libusd_usd_m.a(mallocHook.cpp.o):mallocHook.cpp:function usdBlender__pxrReserved__::ArchMallocHook::Initialize(void* (*)(unsigned long, void const*), void* (*)(void*, unsigned long, void const*), void* (*)(unsigned long, unsigned long, void const*), void (*)(void*, void const*), std::string*): error: undefined reference to '__free_hook'
<Blender lib folder>/linux_centos7_x86_64/usd/lib/libusd_usd_m.a(mallocHook.cpp.o):mallocHook.cpp:function usdBlender__pxrReserved__::ArchMallocHook::Initialize(void* (*)(unsigned long, void const*), void* (*)(void*, unsigned long, void const*), void* (*)(unsigned long, unsigned long, void const*), void (*)(void*, void const*), std::string*): error: undefined reference to '__malloc_hook'
<Blender lib folder>/linux_centos7_x86_64/usd/lib/libusd_usd_m.a(mallocHook.cpp.o):mallocHook.cpp:function usdBlender__pxrReserved__::ArchMallocHook::Initialize(void* (*)(unsigned long, void const*), void* (*)(void*, unsigned long, void const*), void* (*)(unsigned long, unsigned long, void const*), void (*)(void*, void const*), std::string*): error: undefined reference to '__realloc_hook'
<Blender lib folder>/linux_centos7_x86_64/usd/lib/libusd_usd_m.a(mallocHook.cpp.o):mallocHook.cpp:function usdBlender__pxrReserved__::ArchMallocHook::Initialize(void* (*)(unsigned long, void const*), void* (*)(void*, unsigned long, void const*), void* (*)(unsigned long, unsigned long, void const*), void (*)(void*, void const*), std::string*): error: undefined reference to '__memalign_hook'
<Blender lib folder>/linux_centos7_x86_64/usd/lib/libusd_usd_m.a(mallocHook.cpp.o):mallocHook.cpp:function usdBlender__pxrReserved__::ArchMallocHook::Initialize(void* (*)(unsigned long, void const*), void* (*)(void*, unsigned long, void const*), void* (*)(unsigned long, unsigned long, void const*), void (*)(void*, void const*), std::string*): error: undefined reference to '__free_hook'

This is due to the deprecation [1] of the internal memory hooks [2] from GCC in glibc v2.34. Since the VFX reference platform [3] (used for building the pre-compiled libraries) requires that the version of glibc used be at most 2.17 (which still includes those symbols).

There is an issue [4] in the USD library GitHub’s page referencing this error, which also references a pull request [5] for USD to remove those symbols from its codebase, but it has not been accepted yet.

To solve the problem, either build a ‘Lite’ version of Blender (make lite BUILD_DIR=PATH) which does not include libUSD if you can, or use GCC v9.3.1 like indicated in [2].

Links :
[1] The GNU C Library version 2.34 is now available
[2] Hooks for Malloc (The GNU C Library)
[3] https://vfxplatform.com/
[4] USD uses deprecated malloc hooks removed in glibc 2.34 · Issue #1592 · PixarAnimationStudios/USD · GitHub
[5] Allow building against recent glibc with no malloc hooks (>= 2.34) by charlesfleche · Pull Request #1830 · PixarAnimationStudios/USD · GitHub

4 Likes

Thanks for that post, just faced that issue today while trying to update install_deps script for Blender 3.4…

Raised the topic on ⚓ T99618 Library changes for Blender 3.4

Committed a fix as rB16af35054dc7, will probably also be backported to 3.3 LTS.

1 Like

Hi, after the commit 16af35054dc7 I was unable to compile blender… I compile blender every day following the guide with pre-compiled libraries method, but now it’s returning an error right at the end of the compile process:

/usr/bin/ld.gold: error: ../../lib/libbf_intern_libc_compat.a(libc_compat.c.o): multiple definition of '__free_hook'
/usr/bin/ld.gold: /home/evercgart/blender-git/lib/linux_centos7_x86_64/jemalloc/lib/libjemalloc.a(jemalloc.o): previous definition here
/usr/bin/ld.gold: error: ../../lib/libbf_intern_libc_compat.a(libc_compat.c.o): multiple definition of '__memalign_hook'
/usr/bin/ld.gold: /home/evercgart/blender-git/lib/linux_centos7_x86_64/jemalloc/lib/libjemalloc.a(jemalloc.o): previous definition here
/usr/bin/ld.gold: error: ../../lib/libbf_intern_libc_compat.a(libc_compat.c.o): multiple definition of '__realloc_hook'
/usr/bin/ld.gold: /home/evercgart/blender-git/lib/linux_centos7_x86_64/jemalloc/lib/libjemalloc.a(jemalloc.o): previous definition here
/usr/bin/ld.gold: error: ../../lib/libbf_intern_libc_compat.a(libc_compat.c.o): multiple definition of '__malloc_hook'
/usr/bin/ld.gold: /home/evercgart/blender-git/lib/linux_centos7_x86_64/jemalloc/lib/libjemalloc.a(jemalloc.o): previous definition here
collect2: error: ld returned 1 exit status
make[3]: *** [source/creator/CMakeFiles/blender.dir/build.make:578: bin/blender] Error 1
make[2]: *** [CMakeFiles/Makefile2:7519: source/creator/CMakeFiles/blender.dir/all] Error 2
make[1]: *** [Makefile:166: all] Error 2
make: *** [GNUmakefile:353: all] Error 2

Can anyone help? I don’t know how to solve it.

Quoting @mont29 from chat today:

workaround currently is to not build with jemalloc (at least, not the one from our svn libs)
Sybren will work on ‘proper’ fix tomorrow

1 Like

Thank you!!!
I was able to discover a way to rewind to a commit before and now I have the build running. I will wait until tomorrow.

https://developer.blender.org/rBcca416cfe6c21ee9d0feb9d87995e505604b491e

Fingers crossed…

EDIT: And it works! :slight_smile:

1 Like