From eecebb0ff4864cfcd2efa53d889dea2dc9dfe3da Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Fri, 22 Nov 2024 22:55:22 +0100 Subject: [PATCH 1/3] Only define _XOPEN_SOURCE in configurecompiler.cmake (for consistency) --- eng/native/configurecompiler.cmake | 4 +++- src/coreclr/nativeaot/CMakeLists.txt | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index d949e9ce89b58..d7e93c51a302e 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -301,7 +301,9 @@ elseif(CLR_CMAKE_HOST_SUNOS) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector") add_definitions(-D__EXTENSIONS__ -D_XPG4_2 -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT) -elseif(CLR_CMAKE_HOST_OSX AND NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS) +elseif(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS) + add_definitions(-D_XOPEN_SOURCE) +elseif(CLR_CMAKE_HOST_OSX) add_definitions(-D_XOPEN_SOURCE) # the new linker in Xcode 15 (ld_new/ld_prime) deprecated the -bind_at_load flag for macOS which causes a warning diff --git a/src/coreclr/nativeaot/CMakeLists.txt b/src/coreclr/nativeaot/CMakeLists.txt index 74ee982ab9805..20deb87a60bb1 100644 --- a/src/coreclr/nativeaot/CMakeLists.txt +++ b/src/coreclr/nativeaot/CMakeLists.txt @@ -20,7 +20,6 @@ if(CLR_CMAKE_HOST_UNIX) add_compile_options(-nostdlib) if(CLR_CMAKE_TARGET_APPLE) - add_definitions(-D_XOPEN_SOURCE) add_definitions(-DFEATURE_OBJCMARSHAL) endif(CLR_CMAKE_TARGET_APPLE) From eb2e3a888f0f70cb266cf6da45c6aa63a45af063 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sat, 23 Nov 2024 10:18:29 +0100 Subject: [PATCH 2/3] Apply _DARWIN_C_SOURCE universally for all Apple platforms --- src/native/libs/System.Native/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/libs/System.Native/CMakeLists.txt b/src/native/libs/System.Native/CMakeLists.txt index ea059b923e057..3231e02683551 100644 --- a/src/native/libs/System.Native/CMakeLists.txt +++ b/src/native/libs/System.Native/CMakeLists.txt @@ -4,7 +4,7 @@ if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CM add_definitions(-DHAS_CONSOLE_SIGNALS) endif () -if (CLR_CMAKE_TARGET_OSX) +if (CLR_CMAKE_TARGET_APPLE) add_definitions(-D_DARWIN_C_SOURCE) endif () From 19bd01774edbf31d6ffa465687830e9880277366 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sat, 23 Nov 2024 10:23:43 +0100 Subject: [PATCH 3/3] Consolidate --- eng/native/configurecompiler.cmake | 21 +++++++++++--------- src/native/libs/System.Native/CMakeLists.txt | 4 ---- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index d7e93c51a302e..924b661c8dfde 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -301,16 +301,19 @@ elseif(CLR_CMAKE_HOST_SUNOS) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector") add_definitions(-D__EXTENSIONS__ -D_XPG4_2 -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT) -elseif(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS) +elseif(CLR_CMAKE_HOST_APPLE) + # enable support for X/Open and POSIX APIs, like the header file add_definitions(-D_XOPEN_SOURCE) -elseif(CLR_CMAKE_HOST_OSX) - add_definitions(-D_XOPEN_SOURCE) - - # the new linker in Xcode 15 (ld_new/ld_prime) deprecated the -bind_at_load flag for macOS which causes a warning - # that fails the build since we build with -Werror. Only pass the flag if we need it, i.e. older linkers. - check_linker_flag(C "-Wl,-bind_at_load,-fatal_warnings" LINKER_SUPPORTS_BIND_AT_LOAD_FLAG) - if(LINKER_SUPPORTS_BIND_AT_LOAD_FLAG) - add_linker_flag("-Wl,-bind_at_load") + # enable support for Darwin extension APIs, like pthread_getthreadid_np + add_definitions(-D_DARWIN_C_SOURCE) + + if(CLR_CMAKE_HOST_OSX) + # the new linker in Xcode 15 (ld_new/ld_prime) deprecated the -bind_at_load flag for macOS which causes a warning + # that fails the build since we build with -Werror. Only pass the flag if we need it, i.e. older linkers. + check_linker_flag(C "-Wl,-bind_at_load,-fatal_warnings" LINKER_SUPPORTS_BIND_AT_LOAD_FLAG) + if(LINKER_SUPPORTS_BIND_AT_LOAD_FLAG) + add_linker_flag("-Wl,-bind_at_load") + endif() endif() elseif(CLR_CMAKE_HOST_HAIKU) add_compile_options($<$:-Wa,--noexecstack>) diff --git a/src/native/libs/System.Native/CMakeLists.txt b/src/native/libs/System.Native/CMakeLists.txt index 3231e02683551..7712f25560202 100644 --- a/src/native/libs/System.Native/CMakeLists.txt +++ b/src/native/libs/System.Native/CMakeLists.txt @@ -4,10 +4,6 @@ if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CM add_definitions(-DHAS_CONSOLE_SIGNALS) endif () -if (CLR_CMAKE_TARGET_APPLE) - add_definitions(-D_DARWIN_C_SOURCE) -endif () - set(NATIVE_SOURCES pal_errno.c pal_interfaceaddresses.c