wolfpld / tracy

Frame profiler
https://tracy.nereid.pl/
Other
8.61k stars 592 forks source link

Android UE5: dlopen failed due to TLS model in tracy_rpmalloc.cpp #779

Open natepaynefb opened 2 months ago

natepaynefb commented 2 months ago

Hi. Thanks for the great profiler! I'm trying to use it in a UE5 project built for Android and deployed onto a Meta Queset VR headset. It crashes immediately with an error of the form:

java.lang.UnsatisfiedLinkError: dlopen failed: TLS symbol "(null)" in dlopened "<path>/libtracy.so" referenced from "<path>/libtracy.so" using IE access model

The dynamic linker is trying to handle the following variable from tracy_rpmalloc.cpp:

static _Thread_local heap_t* _memory_thread_heap TLS_MODEL;

where TLS_MODEL is defined as:

define TLS_MODEL __attribute__((tls_model("initial-exec")))

I can work around this problem by removing the tls_model attribute. Doing so fixes the crash and does not cause any other problems that I have been able to observe. However, I don't feel confident about this fix because I don't know why the specific TLS model was used in the first place.

I also tried compiling with linker flag -fvisibility=hidden. I was hoping that would hide the variable from the dynamic linker entirely, but it did not.

What would you suggest? Would the following revision to tracy_rpmalloc.cpp cause any problems that you are aware of?

#    if !defined(__HAIKU__) && !defined(__ANDROID__)
#      define TLS_MODEL __attribute__((tls_model("initial-exec")))
#    else
#      define TLS_MODEL
#    endif

In case it matters, here are the other defines used when building Tracy:

         -DTRACY_ENABLE=1,
        -DTRACY_FIBERS=1,
        -DTRACY_ON_DEMAND=1,
        -DTRACY_DELAYED_INIT=1,
        -DTRACY_MANUAL_LIFETIME=1,
        -DTRACY_EXPORTS=1,

Thanks for your help.

wolfpld commented 2 months ago

It would be best to ask about this in rpmalloc: https://github.com/mjansson/rpmalloc