[compiler-rt] 88d303e - [cmake][compiler-rt] Define _DEFAULT_SOURCE instead of enabling extensions (#163377)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 21 06:06:01 PDT 2025
Author: Raul Tambre
Date: 2025-10-21T16:05:57+03:00
New Revision: 88d303e6d42a17a5b1789f6f4b3a1b4ee98b5bf7
URL: https://github.com/llvm/llvm-project/commit/88d303e6d42a17a5b1789f6f4b3a1b4ee98b5bf7
DIFF: https://github.com/llvm/llvm-project/commit/88d303e6d42a17a5b1789f6f4b3a1b4ee98b5bf7.diff
LOG: [cmake][compiler-rt] Define _DEFAULT_SOURCE instead of enabling extensions (#163377)
GNU extensions are a bit of a hammer approach to enabling access to POSIX extensions.
Instead we can define _DEFAULT_SOURCE ourselves where necessary, which is what the extensions
mechanism does.
See: #110555
Added:
Modified:
compiler-rt/cmake/Modules/AddCompilerRT.cmake
compiler-rt/lib/profile/CMakeLists.txt
compiler-rt/lib/profile/GCDAProfiling.c
compiler-rt/lib/profile/InstrProfilingFile.c
compiler-rt/lib/profile/InstrProfilingUtil.c
Removed:
################################################################################
diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index fb2aee8e42ee2..d658b7009e859 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -162,7 +162,6 @@ endmacro()
# OBJECT_LIBS <object libraries to use as sources>
# PARENT_TARGET <convenience parent target>
# ADDITIONAL_HEADERS <header files>
-# EXTENSIONS <boolean>
# C_STANDARD <version>
# CXX_STANDARD <version>)
function(add_compiler_rt_runtime name type)
@@ -174,7 +173,7 @@ function(add_compiler_rt_runtime name type)
cmake_parse_arguments(LIB
""
"PARENT_TARGET;C_STANDARD;CXX_STANDARD"
- "OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS"
+ "OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS"
${ARGN})
set(libnames)
# Until we support this some other way, build compiler-rt runtime without LTO
@@ -445,10 +444,6 @@ 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 ac1451c8ceed1..a6402f80b890a 100644
--- a/compiler-rt/lib/profile/CMakeLists.txt
+++ b/compiler-rt/lib/profile/CMakeLists.txt
@@ -162,8 +162,7 @@ if(APPLE)
CFLAGS ${EXTRA_FLAGS}
SOURCES ${PROFILE_SOURCES}
ADDITIONAL_HEADERS ${PROFILE_HEADERS}
- PARENT_TARGET profile
- EXTENSIONS ON)
+ PARENT_TARGET profile)
else()
add_compiler_rt_runtime(clang_rt.profile
STATIC
@@ -171,6 +170,5 @@ else()
CFLAGS ${EXTRA_FLAGS}
SOURCES ${PROFILE_SOURCES}
ADDITIONAL_HEADERS ${PROFILE_HEADERS}
- PARENT_TARGET profile
- EXTENSIONS ON)
+ PARENT_TARGET profile)
endif()
diff --git a/compiler-rt/lib/profile/GCDAProfiling.c b/compiler-rt/lib/profile/GCDAProfiling.c
index ac01805e70adc..523ade5eafc15 100644
--- a/compiler-rt/lib/profile/GCDAProfiling.c
+++ b/compiler-rt/lib/profile/GCDAProfiling.c
@@ -21,6 +21,11 @@
#if !defined(__Fuchsia__)
+#if defined(__linux__)
+// For fdopen()
+#define _DEFAULT_SOURCE
+#endif
+
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c
index 354f21b786151..71127b05aafb8 100644
--- a/compiler-rt/lib/profile/InstrProfilingFile.c
+++ b/compiler-rt/lib/profile/InstrProfilingFile.c
@@ -8,6 +8,11 @@
#if !defined(__Fuchsia__)
+#if defined(__linux__)
+// For fileno(), ftruncate(), getpagesize(), setenv()
+#define _DEFAULT_SOURCE
+#endif
+
#include <assert.h>
#include <errno.h>
#include <stdio.h>
diff --git a/compiler-rt/lib/profile/InstrProfilingUtil.c b/compiler-rt/lib/profile/InstrProfilingUtil.c
index 0fae91cfb8950..a9d9df813764b 100644
--- a/compiler-rt/lib/profile/InstrProfilingUtil.c
+++ b/compiler-rt/lib/profile/InstrProfilingUtil.c
@@ -12,6 +12,11 @@
#include <windows.h>
#include "WindowsMMap.h"
#else
+#if defined(__linux__)
+// For fdopen(), fileno(), getpagesize(), madvise()
+#define _DEFAULT_SOURCE
+#endif
+
#include <errno.h>
#include <fcntl.h>
#include <sys/file.h>
More information about the llvm-commits
mailing list