From 946f15efb76fffda37b77f7d194d679b904305b1 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 27 Jul 2023 21:31:44 -0700 Subject: [PATCH] CMake/ELF: hide all Standard Library symbols We've had issues in the past where Standard Library constructs either with or without a Qt type mangled in the middle get exported from our ABI and thus get marked with the Qt version numbers. For example, I can see in our libraries: 517: 000000000010e608 24 OBJECT GLOBAL DEFAULT 22 typeinfo for std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>@@Qt_6 615: 00000000000eb2a0 47 OBJECT GLOBAL DEFAULT 17 typeinfo name for std::_Mutex_base<(__gnu_cxx::_Lock_policy)2>@@Qt_6 706: 000000000010e5f8 16 OBJECT GLOBAL DEFAULT 22 typeinfo for std::_Mutex_base<(__gnu_cxx::_Lock_policy)2>@@Qt_6 750: 00000000000ed5f0 16 OBJECT GLOBAL DEFAULT 17 std::_Sp_make_shared_tag::_S_ti()::__tag@@Qt_6 754: 00000000000da408 1 OBJECT GLOBAL DEFAULT 17 std::piecewise_construct@@Qt_6 This causes user content to break when an update to Qt stops exporting such symbols, either because of code changes or because of changes to the compiler and its optimizer. In fact, this commit will cause that, for the symbols above. But this will no longer be random-looking. [ChangeLog][Important ABI Changes] On ELF-based platforms (e.g., Linux, FreeBSD), the linking process has been updated to exclude Standard Library symbols from getting the "Qt_6" ELF version. This solves the problem of applications and libraries breaking arbitrarily after Qt updates, but will cause such breakages right now. Content built with older versions of Qt may need to be relinked. Change-Id: I5acc02341c5940499682fffd1775edce0021ce6d Reviewed-by: Volker Hilsheimer Reviewed-by: Alexandru Croitor --- cmake/QtFlagHandlingHelpers.cmake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmake/QtFlagHandlingHelpers.cmake b/cmake/QtFlagHandlingHelpers.cmake index 6784232ca9c..04fb8552694 100644 --- a/cmake/QtFlagHandlingHelpers.cmake +++ b/cmake/QtFlagHandlingHelpers.cmake @@ -23,7 +23,10 @@ function(qt_internal_add_linker_version_script target) endif() if(TEST_ld_version_script) - set(contents "Qt_${PROJECT_VERSION_MAJOR}_PRIVATE_API {\n qt_private_api_tag*;\n") + set(contents "NonQt { local:\n") + string(APPEND contents " _ZT?S*;\n") # {typeinfo {,name},vtable,VTT} for std:: + string(APPEND contents " extern \"C++\" { std::*; };\n") + string(APPEND contents "};\nQt_${PROJECT_VERSION_MAJOR}_PRIVATE_API { qt_private_api_tag*;\n") if(arg_PRIVATE_HEADERS) foreach(ph ${arg_PRIVATE_HEADERS}) string(APPEND contents " @FILE:${ph}@\n")