From 9cc6d6e9a96bda923ff7e7bb7394dfb4d2319b07 Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Mon, 14 Oct 2024 15:07:11 +0300 Subject: [PATCH] [compiler-rt] Explicitly enable C extensions for profile (#110555) The profiling code requires GNU extensions as it uses functions such as getpagesize(), fdopen(), etc. The problem manifests when the compiler is built to not default to the extensions mode, e.g. custom config with -std=c2x. CMake didn't support this scenario very well, but it's been fixed by CMP0128. Set the policy to NEW as we now conform to it. --- compiler-rt/CMakeLists.txt | 5 +++++ compiler-rt/cmake/Modules/AddCompilerRT.cmake | 9 +++++++-- compiler-rt/lib/profile/CMakeLists.txt | 6 ++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt index deb6994f48185..1c24b520da985 100644 --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -12,6 +12,11 @@ endif() include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake NO_POLICY_SCOPE) +# TODO(CMake 3.22): remove +if(POLICY CMP0128) + cmake_policy(SET CMP0128 NEW) +endif() + # Check if compiler-rt is built as a standalone project. if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD) project(CompilerRT C CXX ASM) diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake index 6962b733733a6..e3d81d241b105 100644 --- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake +++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake @@ -161,7 +161,8 @@ endmacro() # LINK_LIBS (only for shared library) # OBJECT_LIBS # PARENT_TARGET -# ADDITIONAL_HEADERS
) +# ADDITIONAL_HEADERS
+# EXTENSIONS ) function(add_compiler_rt_runtime name type) if(NOT type MATCHES "^(OBJECT|STATIC|SHARED|MODULE)$") message(FATAL_ERROR @@ -171,7 +172,7 @@ function(add_compiler_rt_runtime name type) cmake_parse_arguments(LIB "" "PARENT_TARGET" - "OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS" + "OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS" ${ARGN}) set(libnames) # Until we support this some other way, build compiler-rt runtime without LTO @@ -435,6 +436,10 @@ function(add_compiler_rt_runtime name type) if(type STREQUAL "SHARED") rt_externalize_debuginfo(${libname}) endif() + + if(DEFINED LIB_EXTENSIONS) + set_target_properties(${libname} PROPERTIES C_EXTENSIONS ${LIB_EXTENSIONS}) + endif() endforeach() if(LIB_PARENT_TARGET) add_dependencies(${LIB_PARENT_TARGET} ${libnames}) diff --git a/compiler-rt/lib/profile/CMakeLists.txt b/compiler-rt/lib/profile/CMakeLists.txt index ef23492514898..2617841296720 100644 --- a/compiler-rt/lib/profile/CMakeLists.txt +++ b/compiler-rt/lib/profile/CMakeLists.txt @@ -138,7 +138,8 @@ if(APPLE) CFLAGS ${EXTRA_FLAGS} SOURCES ${PROFILE_SOURCES} ADDITIONAL_HEADERS ${PROFILE_HEADERS} - PARENT_TARGET profile) + PARENT_TARGET profile + EXTENSIONS ON) else() add_compiler_rt_runtime(clang_rt.profile STATIC @@ -146,5 +147,6 @@ else() CFLAGS ${EXTRA_FLAGS} SOURCES ${PROFILE_SOURCES} ADDITIONAL_HEADERS ${PROFILE_HEADERS} - PARENT_TARGET profile) + PARENT_TARGET profile + EXTENSIONS ON) endif()