Skip to content

Commit 9cc6d6e

Browse files
authored
[compiler-rt] Explicitly enable C extensions for profile (llvm#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.
1 parent c978f0f commit 9cc6d6e

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

compiler-rt/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ endif()
1212
include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
1313
NO_POLICY_SCOPE)
1414

15+
# TODO(CMake 3.22): remove
16+
if(POLICY CMP0128)
17+
cmake_policy(SET CMP0128 NEW)
18+
endif()
19+
1520
# Check if compiler-rt is built as a standalone project.
1621
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD)
1722
project(CompilerRT C CXX ASM)

compiler-rt/cmake/Modules/AddCompilerRT.cmake

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ endmacro()
161161
# LINK_LIBS <linked libraries> (only for shared library)
162162
# OBJECT_LIBS <object libraries to use as sources>
163163
# PARENT_TARGET <convenience parent target>
164-
# ADDITIONAL_HEADERS <header files>)
164+
# ADDITIONAL_HEADERS <header files>
165+
# EXTENSIONS <boolean>)
165166
function(add_compiler_rt_runtime name type)
166167
if(NOT type MATCHES "^(OBJECT|STATIC|SHARED|MODULE)$")
167168
message(FATAL_ERROR
@@ -171,7 +172,7 @@ function(add_compiler_rt_runtime name type)
171172
cmake_parse_arguments(LIB
172173
""
173174
"PARENT_TARGET"
174-
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS"
175+
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS"
175176
${ARGN})
176177
set(libnames)
177178
# Until we support this some other way, build compiler-rt runtime without LTO
@@ -435,6 +436,10 @@ function(add_compiler_rt_runtime name type)
435436
if(type STREQUAL "SHARED")
436437
rt_externalize_debuginfo(${libname})
437438
endif()
439+
440+
if(DEFINED LIB_EXTENSIONS)
441+
set_target_properties(${libname} PROPERTIES C_EXTENSIONS ${LIB_EXTENSIONS})
442+
endif()
438443
endforeach()
439444
if(LIB_PARENT_TARGET)
440445
add_dependencies(${LIB_PARENT_TARGET} ${libnames})

compiler-rt/lib/profile/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,15 @@ if(APPLE)
138138
CFLAGS ${EXTRA_FLAGS}
139139
SOURCES ${PROFILE_SOURCES}
140140
ADDITIONAL_HEADERS ${PROFILE_HEADERS}
141-
PARENT_TARGET profile)
141+
PARENT_TARGET profile
142+
EXTENSIONS ON)
142143
else()
143144
add_compiler_rt_runtime(clang_rt.profile
144145
STATIC
145146
ARCHS ${PROFILE_SUPPORTED_ARCH}
146147
CFLAGS ${EXTRA_FLAGS}
147148
SOURCES ${PROFILE_SOURCES}
148149
ADDITIONAL_HEADERS ${PROFILE_HEADERS}
149-
PARENT_TARGET profile)
150+
PARENT_TARGET profile
151+
EXTENSIONS ON)
150152
endif()

0 commit comments

Comments
 (0)