From 014e77801fa4b99cdb03330ccce1e212ac13a0af Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 23 Jan 2025 14:43:10 -0800 Subject: [PATCH] Fix detection of -fPIE code for QT_CONFIG(reduce_relocations) Amends commit 19b7f854a274812d9c95fc7aaf134a12530c105f, which removed the __PIE__ check because of the GCC version check that was alongside. GCC and Clang define both __PIE__ and __PIC__ for -fPIE, so checking for __PIC__'s presence isn't enough. Drive-by amend the no-PIC #error message to also suggest -DFEATURE_no_direct_extern_access=ON, which is more modern and produces better code for executables too. Because of that, I've also changed the reduce_relocations option to the CMake one, as there is no configure- style equivalent for the modern option. Pick-to: 6.9 6.8 6.5 Fixes: QTBUG-133101 Change-Id: I957b264eaee360fd964afffd60617964b26fe934 Reviewed-by: Marc Mutz --- src/corelib/global/qcompilerdetection.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 137756aefc7..333c6454d5a 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -1317,9 +1317,14 @@ static_assert(!std::is_convertible_v, #if defined(QT_BOOTSTRAPPED) || defined(QT_USE_PROTECTED_VISIBILITY) || !defined(__ELF__) || defined(__PIC__) // this is fine +#elif defined(__PIE__) +# error "-fPIE is not sufficient if Qt was configured with the -DFEATURE_reduce_relocations=ON "\ + "CMake option. Compile your code with -fPIC and without -fPIE or compile Qt with "\ + "-DFEATURE_no_direct_extern_access=ON." #elif defined(QT_REDUCE_RELOCATIONS) -# error "You must build your code with position independent code if Qt was configured with -reduce-relocations. "\ - "Compile your code with -fPIC (and not with -fPIE)." +# error "You must build your code with position independent code if Qt was configured with the "\ + "-DFEATURE_reduce_relocations=ON CMake option. Compile your code with -fPIC and "\ + "without -fPIE or compile Qt with -DFEATURE_no_direct_extern_access=ON." #endif #ifdef Q_PROCESSOR_X86_32