diff --git a/cmake/QtPlatformTargetHelpers.cmake b/cmake/QtPlatformTargetHelpers.cmake index e9f40d0565..47cffc8040 100644 --- a/cmake/QtPlatformTargetHelpers.cmake +++ b/cmake/QtPlatformTargetHelpers.cmake @@ -42,7 +42,8 @@ function(qt_internal_setup_public_platform_target) target_link_options(Platform INTERFACE "${libc_link_option}") endif() if (QT_FEATURE_no_extern_direct_access) - target_compile_options(Platform INTERFACE "-mno-direct-extern-access") + target_compile_options(Platform INTERFACE "$<$:-mno-direct-extern-access>") + target_compile_options(Platform INTERFACE "$<$:-fno-direct-access-external-data>") endif() qt_set_msvc_cplusplus_options(Platform INTERFACE) diff --git a/config.tests/direct_extern_access/CMakeLists.txt b/config.tests/direct_extern_access/CMakeLists.txt index 50a35f1d02..7c82348751 100644 --- a/config.tests/direct_extern_access/CMakeLists.txt +++ b/config.tests/direct_extern_access/CMakeLists.txt @@ -5,5 +5,9 @@ project(direct_extern_access LANGUAGES CXX) add_library(no_extern_access_lib SHARED lib.cpp) add_executable(no_extern_access_main main.cpp) -target_compile_options(no_extern_access_lib PUBLIC "-mno-direct-extern-access") + +target_compile_options(no_extern_access_lib PRIVATE "-Werror") +target_compile_options(no_extern_access_lib PUBLIC "$<$:-mno-direct-extern-access>") +target_compile_options(no_extern_access_lib PUBLIC "$<$:-fno-direct-access-external-data>") + target_link_libraries(no_extern_access_main no_extern_access_lib) diff --git a/config.tests/direct_extern_access/lib.cpp b/config.tests/direct_extern_access/lib.cpp index 6cbc85571f..cf3b18bb38 100644 --- a/config.tests/direct_extern_access/lib.cpp +++ b/config.tests/direct_extern_access/lib.cpp @@ -6,5 +6,6 @@ #define BUILD #include "lib.h" +void *S::ptr = nullptr; S::~S() { } -void S::f() { } +void *S::f() { return ptr; } diff --git a/config.tests/direct_extern_access/lib.h b/config.tests/direct_extern_access/lib.h index d35b52f135..1a9c3c5533 100644 --- a/config.tests/direct_extern_access/lib.h +++ b/config.tests/direct_extern_access/lib.h @@ -12,5 +12,6 @@ struct LIB_API S { virtual ~S(); - virtual void f(); + virtual void *f(); + static void *ptr; }; diff --git a/mkspecs/features/unix/mno_extern_direct_access.prf b/mkspecs/features/unix/mno_extern_direct_access.prf index 816e28bb43..2b7b3c8539 100644 --- a/mkspecs/features/unix/mno_extern_direct_access.prf +++ b/mkspecs/features/unix/mno_extern_direct_access.prf @@ -1,2 +1,7 @@ -QMAKE_CFLAGS += -mno-direct-extern-access -QMAKE_CXXFLAGS += -mno-direct-extern-access +clang { + QMAKE_CFLAGS += -fno-direct-access-external-data + QMAKE_CXXFLAGS += -fno-direct-access-external-data +} else { + QMAKE_CFLAGS += -mno-direct-extern-access + QMAKE_CXXFLAGS += -mno-direct-extern-access +}