Skip to content

Commit 64b3be0

Browse files
committed
[cmake][compiler-rt] Define _DEFAULT_SOURCE instead of enabling extensions
GNU extensions are a bit of a hammer approach to enabling access to POSIX extensions. Instead we can define _DEFAULT_SOURCE ourselves, which is what the extensions mechanism does. See: llvm#110555
1 parent 0ebcc97 commit 64b3be0

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

compiler-rt/cmake/Modules/AddCompilerRT.cmake

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ endmacro()
162162
# OBJECT_LIBS <object libraries to use as sources>
163163
# PARENT_TARGET <convenience parent target>
164164
# ADDITIONAL_HEADERS <header files>
165-
# EXTENSIONS <boolean>
166165
# C_STANDARD <version>
167166
# CXX_STANDARD <version>)
168167
function(add_compiler_rt_runtime name type)
@@ -174,7 +173,7 @@ function(add_compiler_rt_runtime name type)
174173
cmake_parse_arguments(LIB
175174
""
176175
"PARENT_TARGET;C_STANDARD;CXX_STANDARD"
177-
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS"
176+
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS"
178177
${ARGN})
179178
set(libnames)
180179
# Until we support this some other way, build compiler-rt runtime without LTO
@@ -445,10 +444,6 @@ function(add_compiler_rt_runtime name type)
445444
if(type STREQUAL "SHARED")
446445
rt_externalize_debuginfo(${libname})
447446
endif()
448-
449-
if(DEFINED LIB_EXTENSIONS)
450-
set_target_properties(${libname} PROPERTIES C_EXTENSIONS ${LIB_EXTENSIONS})
451-
endif()
452447
endforeach()
453448
if(LIB_PARENT_TARGET)
454449
add_dependencies(${LIB_PARENT_TARGET} ${libnames})

compiler-rt/lib/profile/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ if(COMPILER_RT_TARGET_HAS_UNAME)
135135
-DCOMPILER_RT_HAS_UNAME=1)
136136
endif()
137137

138+
if(OS_NAME MATCHES "Linux")
139+
list(APPEND EXTRA_FLAGS "-D_DEFAULT_SOURCE")
140+
endif()
141+
138142
if(MSVC)
139143
# profile historically has only been supported with the static runtime
140144
# on windows
@@ -162,15 +166,13 @@ if(APPLE)
162166
CFLAGS ${EXTRA_FLAGS}
163167
SOURCES ${PROFILE_SOURCES}
164168
ADDITIONAL_HEADERS ${PROFILE_HEADERS}
165-
PARENT_TARGET profile
166-
EXTENSIONS ON)
169+
PARENT_TARGET profile)
167170
else()
168171
add_compiler_rt_runtime(clang_rt.profile
169172
STATIC
170173
ARCHS ${PROFILE_SUPPORTED_ARCH}
171174
CFLAGS ${EXTRA_FLAGS}
172175
SOURCES ${PROFILE_SOURCES}
173176
ADDITIONAL_HEADERS ${PROFILE_HEADERS}
174-
PARENT_TARGET profile
175-
EXTENSIONS ON)
177+
PARENT_TARGET profile)
176178
endif()

compiler-rt/lib/profile/GCDAProfiling.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121

2222
#if !defined(__Fuchsia__)
2323

24+
#if defined(__linux__)
25+
// For fdopen()
26+
#define _DEFAULT_SOURCE
27+
#endif
28+
2429
#include <errno.h>
2530
#include <fcntl.h>
2631
#include <stdint.h>

compiler-rt/lib/profile/InstrProfilingFile.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
#if !defined(__Fuchsia__)
1010

11+
#if defined(__linux__)
12+
// For fileno(), ftruncate(), getpagesize(), setenv()
13+
#define _DEFAULT_SOURCE
14+
#endif
15+
1116
#include <assert.h>
1217
#include <errno.h>
1318
#include <stdio.h>

compiler-rt/lib/profile/InstrProfilingUtil.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
#include <windows.h>
1313
#include "WindowsMMap.h"
1414
#else
15+
#if defined(__linux__)
16+
// For fdopen(), fileno(), getpagesize(), madvise()
17+
#define _DEFAULT_SOURCE
18+
#endif
19+
1520
#include <errno.h>
1621
#include <fcntl.h>
1722
#include <sys/file.h>

0 commit comments

Comments
 (0)