Fix attempt to use -mno-direct-extern-access with Clang

Clang has the option, but spells it differently.

Fixes: QTBUG-105002
Change-Id: I36b24183fbd041179f2ffffd170217e82ff6d14d
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
(cherry picked from commit 78ef9e9d14f170c410c2fb52f5aada8421ed8f07)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Thiago Macieira 2022-07-15 12:38:18 -07:00 committed by Qt Cherry-pick Bot
parent d8e584c7a6
commit dd4875b54c
5 changed files with 18 additions and 6 deletions

View File

@ -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 "$<$<CXX_COMPILER_ID:GNU>:-mno-direct-extern-access>")
target_compile_options(Platform INTERFACE "$<$<CXX_COMPILER_ID:Clang>:-fno-direct-access-external-data>")
endif()
qt_set_msvc_cplusplus_options(Platform INTERFACE)

View File

@ -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 "$<$<CXX_COMPILER_ID:GNU>:-mno-direct-extern-access>")
target_compile_options(no_extern_access_lib PUBLIC "$<$<CXX_COMPILER_ID:Clang>:-fno-direct-access-external-data>")
target_link_libraries(no_extern_access_main no_extern_access_lib)

View File

@ -6,5 +6,6 @@
#define BUILD
#include "lib.h"
void *S::ptr = nullptr;
S::~S() { }
void S::f() { }
void *S::f() { return ptr; }

View File

@ -12,5 +12,6 @@
struct LIB_API S
{
virtual ~S();
virtual void f();
virtual void *f();
static void *ptr;
};

View File

@ -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
}