libjemalloc.so.2: cannot allocate memory in static TLS block
Description:
I'm getting the following error when trying to run usdzip from usd-24.05-2 on x86_64
$ usdzip --help Traceback (most recent call last): File "/usr/bin/usdzip", line 31, in from pxr import Ar, Sdf, Tf, Usd, UsdUtils File "/usr/lib/python3.12/site-packages/pxr/Ar/init.py", line 24, in from pxr import Tf File "/usr/lib/python3.12/site-packages/pxr/Tf/init.py", line 178, in PreparePythonModule() File "/usr/lib/python3.12/site-packages/pxr/Tf/init.py", line 103, in PreparePythonModule module = importlib.import_module( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/importlib/init.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ImportError: /usr/lib/libjemalloc.so.2: cannot allocate memory in static TLS block
ChatGPT suggested using LD_PRELOAD, which at least lets me run the application.
LD_PRELOAD=/usr/lib/libjemalloc.so.2 usdzip --help
This is the full output:
The error "ImportError: /usr/lib/libjemalloc.so.2: cannot allocate
memory in static TLS block" typically occurs when a shared library (like
libjemalloc.so.2
) cannot allocate memory for Thread-Local Storage
(TLS). This is often due to the fact that the library was not compiled
with the -fPIC
(Position Independent Code) flag, which is necessary
for shared libraries in certain environments.
To resolve this issue, you can try the following steps:
-
Preload the Library: Preloading
libjemalloc
can sometimes resolve the issue. You can do this by setting theLD_PRELOAD
environment variable:export LD_PRELOAD=/usr/lib/libjemalloc.so.2
Add this line to your shell configuration file (e.g.,
~/.bashrc
,~/.zshrc
) to make it persistent. -
Use a Different Version of the Library: The problem might be specific to the version of
libjemalloc
you are using. Try using a different version or reinstallinglibjemalloc
.sudo apt-get install --reinstall libjemalloc2
-
Recompile the Library with
-fPIC
: If you have control over the compilation oflibjemalloc
, ensure it is compiled with the-fPIC
flag. This ensures that the library can be used in a position-independent way, which is necessary for certain environments../configure CFLAGS="-fPIC" make sudo make install
-
Check for Conflicting Libraries: Ensure that there are no conflicting versions of
libjemalloc
on your system. Sometimes, multiple versions can cause issues. You can check the loaded libraries usingldd
:ldd /path/to/your/executable
-
Use an Alternative Memory Allocator: If
libjemalloc
is not strictly required, consider using an alternative memory allocator. You can unsetlibjemalloc
by ensuring it is not preloaded or linked. -
Consult System Logs: System logs may provide additional insights into what might be causing the issue. Check logs using:
dmesg | grep jemalloc
If these steps do not resolve the issue, please provide more context about the environment in which you are encountering this error (e.g., the specific application, operating system, and any relevant configuration).
Steps to reproduce:
$ usdzip --help