From cd05cdaa57da4953e65d306503ce7134151fb16e Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Thu, 4 Aug 2022 11:40:58 +0200 Subject: [PATCH] Thunks: Make GL guest thunks implicitly load libX11.so Steam's gameoverlayrenderer.so relies on libX11 symbols to be available without actually loading that library directly. This works on an unthunked system since libGL.so depends on libGLX.so, which in turn pulls in libX11.so at load-time. Adding a fake libX11 dependency to the libGL-guest thunks reproduces this behavior. --- ThunkLibs/GuestLibs/CMakeLists.txt | 4 ++++ ThunkLibs/libGL/libGL_Guest.cpp | 4 ++++ ThunkLibs/libX11/libX11_NativeGuest.cpp | 7 +++++++ 3 files changed, 15 insertions(+) create mode 100644 ThunkLibs/libX11/libX11_NativeGuest.cpp diff --git a/ThunkLibs/GuestLibs/CMakeLists.txt b/ThunkLibs/GuestLibs/CMakeLists.txt index ce37d95c8..f6c9f8e80 100644 --- a/ThunkLibs/GuestLibs/CMakeLists.txt +++ b/ThunkLibs/GuestLibs/CMakeLists.txt @@ -91,6 +91,10 @@ add_guest_lib(EGL) generate(libGL ${CMAKE_CURRENT_SOURCE_DIR}/../libGL/libGL_interface.cpp thunks function_packs function_packs_public symbol_list) add_guest_lib(GL) +# libGL must pull in libX11.so, so generate a placeholder libX11.so to link against +add_library(X11 SHARED ../libX11/libX11_NativeGuest.cpp) +target_link_libraries(GL-guest PRIVATE X11) + # disabled for now, headers are platform specific # find_package(SDL2 REQUIRED) # generate(libSDL2 thunks function_packs function_packs_public) diff --git a/ThunkLibs/libGL/libGL_Guest.cpp b/ThunkLibs/libGL/libGL_Guest.cpp index 05fe827f3..01024b5ee 100644 --- a/ThunkLibs/libGL/libGL_Guest.cpp +++ b/ThunkLibs/libGL/libGL_Guest.cpp @@ -65,4 +65,8 @@ extern "C" { } } +// libGL.so must pull in libX11.so as a dependency. Referencing some libX11 +// symbol here prevents the linker from optimizing away the unused dependency +auto implicit_libx11_dependency = XSetErrorHandler; + LOAD_LIB(libGL) diff --git a/ThunkLibs/libX11/libX11_NativeGuest.cpp b/ThunkLibs/libX11/libX11_NativeGuest.cpp new file mode 100644 index 000000000..a1a958a2d --- /dev/null +++ b/ThunkLibs/libX11/libX11_NativeGuest.cpp @@ -0,0 +1,7 @@ +// This file only exists to create a placeholder library to link against for +// libraries that are supposed to implicitly load libX11. At runtime, the guest +// linker will select the library from the RootFS instead, which is then +// replaced by libX11-guest.so. + +// Define some symbol so that the linker doesn't consider this library unused +extern "C" void XSetErrorHandler() {}