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 <marc.mutz@qt.io>
This commit is contained in:
Thiago Macieira 2025-01-23 14:43:10 -08:00
parent facf2c1770
commit 014e77801f

View File

@ -1317,9 +1317,14 @@ static_assert(!std::is_convertible_v<std::nullptr_t, bool>,
#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