Skip to content

Draft: Die RTLD_GLOBAL

Emil Velikov requested to merge xexaxo/mesa:die-RTLD_GLOBAL into main

As you may know, our current use of dlopen(driver_handle, RTLD_GLOBAL) has been somewhat of a nuisance since it promotes all the symbols of the driver as well as its dependencies into the global namespace.

Thus resulting in symbol collision, which brings all sorts of fun behaviour.

Additionally, to allow sharing of the winsys (et al) for gallium drivers we used the linker specific dynamic-lists. Thus again and again we had to export the required API.

With this MR, I'm introducing an internal library /usr/lib/mesa-tls/mesa_tls.so which is the only one dlopen'd with RTLD_GLOBAL. The library allows for sharing the required state and has zero dependencies. As a result:

  • there is no pollution of the global namespace
  • we consistently share state across APIs, with 5 lines of code
  • no more linker magic (dynamic-lists) and linker file changes

I'm not 100% set of the naming of the library and API, but the functionality is all there.

This has been briefly tested and I would welcome people to check it against their favourite workload.

/cc @mareko @bnieuwenhuizen @imirkin @robclark @robh @hakzsam @kusma @issor.oruam @tpalli

@bnieuwenhuizen this effectively shares ac_init_llvm_once across radeonsi and radv, as mentioned earlier \o/

Notes:

  • Last two patches are straight from Erik's MR !4683 (closed)
  • Use of dlmopen in Mesa is out of the question for the moment due to this glibc bug
  • Android.mk for the library is missing - @issor.oruam @tpalli can you add one and test? Alternatively we can preserve the original code for Android and use the new one otherwise.

Merge request reports