Skip to content

Conversation

@tambry
Copy link
Contributor

@tambry tambry commented Oct 14, 2025

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: #110555

@tambry tambry added cmake Build system in general and CMake in particular compiler-rt labels Oct 14, 2025
@tambry tambry self-assigned this Oct 14, 2025
@tambry tambry force-pushed the default_source_easier branch from 0eac16e to 2bb42d3 Compare October 14, 2025 12:12
@tambry tambry requested a review from mstorsjo October 14, 2025 12:13
@llvmbot llvmbot added the PGO Profile Guided Optimizations label Oct 14, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 14, 2025

@llvm/pr-subscribers-pgo

Author: Raul Tambre (tambry)

Changes

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: #110555


Full diff: https://github.com/llvm/llvm-project/pull/163377.diff

2 Files Affected:

  • (modified) compiler-rt/cmake/Modules/AddCompilerRT.cmake (+1-6)
  • (modified) compiler-rt/lib/profile/CMakeLists.txt (+6-4)
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..4753bdb35e003 100644
--- a/compiler-rt/lib/profile/CMakeLists.txt
+++ b/compiler-rt/lib/profile/CMakeLists.txt
@@ -135,6 +135,10 @@ if(COMPILER_RT_TARGET_HAS_UNAME)
      -DCOMPILER_RT_HAS_UNAME=1)
 endif()
 
+if(OS_NAME MATCHES "Linux")
+  list(APPEND EXTRA_FLAGS "-D_DEFAULT_SOURCE")
+endif()
+
 if(MSVC)
   # profile historically has only been supported with the static runtime
   # on windows
@@ -162,8 +166,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 +174,5 @@ else()
     CFLAGS ${EXTRA_FLAGS}
     SOURCES ${PROFILE_SOURCES}
     ADDITIONAL_HEADERS ${PROFILE_HEADERS}
-    PARENT_TARGET profile
-    EXTENSIONS ON)
+    PARENT_TARGET profile)
 endif()

@mstorsjo
Copy link
Member

Can you add to the commit message/PR description, what parts of the code needs this to be defined?

@tambry tambry force-pushed the default_source_easier branch from 2bb42d3 to 0b35bc1 Compare October 21, 2025 11:59
…sions

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: llvm#110555
@tambry tambry force-pushed the default_source_easier branch from 0b35bc1 to 1bfcfad Compare October 21, 2025 11:59
@tambry
Copy link
Contributor Author

tambry commented Oct 21, 2025

@mstorsjo Changed over to explicit defines in the applicable files with comments for the functions its needed for.

@mstorsjo
Copy link
Member

@mstorsjo Changed over to explicit defines in the applicable files with comments for the functions its needed for.

This looks great, thanks! Are we sure that this is only needed on __linux__ targets and nowhere else?

@tambry
Copy link
Contributor Author

tambry commented Oct 21, 2025

@mstorsjo As far as I can tell _DEFAULT_SOURCE seems rather glibc and musl specific, which both are Linux-only.
On FreeBSD these are enabled by default as these are mostly extensions originating from BSDs anyway. I expect the same to be true for other BSDs.
For more exotic systems (e.g. Sun/Solaris) I think _XOPEN_SOURCE might be required but it's hard to verify. So I'd leave those up to others to discover.

@mstorsjo
Copy link
Member

@mstorsjo As far as I can tell _DEFAULT_SOURCE seems rather glibc and musl specific, which both are Linux-only. On FreeBSD these are enabled by default as these are mostly extensions originating from BSDs anyway. I expect the same to be true for other BSDs. For more exotic systems (e.g. Sun/Solaris) I think _XOPEN_SOURCE might be required but it's hard to verify. So I'd leave those up to others to discover.

Ok, fair enough.

Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tambry tambry merged commit 88d303e into llvm:main Oct 21, 2025
10 checks passed
@tambry tambry deleted the default_source_easier branch October 21, 2025 13:06
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 21, 2025

LLVM Buildbot has detected a new failure on builder sanitizer-x86_64-linux-android running on sanitizer-buildbot-android while building compiler-rt at step 2 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/186/builds/13348

Here is the relevant piece of the build log for the reference
Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
[       OK ] AddressSanitizer.AtoiAndFriendsOOBTest (2301 ms)
[ RUN      ] AddressSanitizer.HasFeatureAddressSanitizerTest
[       OK ] AddressSanitizer.HasFeatureAddressSanitizerTest (0 ms)
[ RUN      ] AddressSanitizer.CallocReturnsZeroMem
[       OK ] AddressSanitizer.CallocReturnsZeroMem (9 ms)
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN      ] AddressSanitizer.IgnoreTest
[       OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN      ] AddressSanitizer.SignalTest
[       OK ] AddressSanitizer.SignalTest (185 ms)
[ RUN      ] AddressSanitizer.ReallocTest
[       OK ] AddressSanitizer.ReallocTest (28 ms)
[ RUN      ] AddressSanitizer.WrongFreeTest
[       OK ] AddressSanitizer.WrongFreeTest (113 ms)
[ RUN      ] AddressSanitizer.LongJmpTest
[       OK ] AddressSanitizer.LongJmpTest (0 ms)
[ RUN      ] AddressSanitizer.ThreadStackReuseTest
[       OK ] AddressSanitizer.ThreadStackReuseTest (10 ms)
[ DISABLED ] AddressSanitizer.DISABLED_MemIntrinsicUnalignedAccessTest
[ DISABLED ] AddressSanitizer.DISABLED_LargeFunctionSymbolizeTest
[ DISABLED ] AddressSanitizer.DISABLED_MallocFreeUnwindAndSymbolizeTest
[ RUN      ] AddressSanitizer.UseThenFreeThenUseTest
[       OK ] AddressSanitizer.UseThenFreeThenUseTest (133 ms)
[ RUN      ] AddressSanitizer.FileNameInGlobalReportTest
[       OK ] AddressSanitizer.FileNameInGlobalReportTest (120 ms)
[ DISABLED ] AddressSanitizer.DISABLED_StressStackReuseAndExceptionsTest
[ RUN      ] AddressSanitizer.MlockTest
[       OK ] AddressSanitizer.MlockTest (0 ms)
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadedTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowIn
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowLeft
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowRight
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFHigh
[ DISABLED ] AddressSanitizer.DISABLED_DemoOOM
[ DISABLED ] AddressSanitizer.DISABLED_DemoDoubleFreeTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoNullDerefTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoFunctionStaticTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoTooMuchMemoryTest
[ RUN      ] AddressSanitizer.LongDoubleNegativeTest
[       OK ] AddressSanitizer.LongDoubleNegativeTest (0 ms)
[----------] 19 tests from AddressSanitizer (27685 ms total)

[----------] Global test environment tear-down
[==========] 22 tests from 2 test suites ran. (27692 ms total)
[  PASSED  ] 22 tests.

  YOU HAVE 1 DISABLED TEST

Step 34 (run instrumented asan tests [aarch64/bluejay-userdebug/TQ3A.230805.001]) failure: run instrumented asan tests [aarch64/bluejay-userdebug/TQ3A.230805.001] (failure)
...
[ RUN      ] AddressSanitizer.HasFeatureAddressSanitizerTest
[       OK ] AddressSanitizer.HasFeatureAddressSanitizerTest (0 ms)
[ RUN      ] AddressSanitizer.CallocReturnsZeroMem
[       OK ] AddressSanitizer.CallocReturnsZeroMem (9 ms)
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN      ] AddressSanitizer.IgnoreTest
[       OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN      ] AddressSanitizer.SignalTest
[       OK ] AddressSanitizer.SignalTest (185 ms)
[ RUN      ] AddressSanitizer.ReallocTest
[       OK ] AddressSanitizer.ReallocTest (28 ms)
[ RUN      ] AddressSanitizer.WrongFreeTest
[       OK ] AddressSanitizer.WrongFreeTest (113 ms)
[ RUN      ] AddressSanitizer.LongJmpTest
[       OK ] AddressSanitizer.LongJmpTest (0 ms)
[ RUN      ] AddressSanitizer.ThreadStackReuseTest
[       OK ] AddressSanitizer.ThreadStackReuseTest (10 ms)
[ DISABLED ] AddressSanitizer.DISABLED_MemIntrinsicUnalignedAccessTest
[ DISABLED ] AddressSanitizer.DISABLED_LargeFunctionSymbolizeTest
[ DISABLED ] AddressSanitizer.DISABLED_MallocFreeUnwindAndSymbolizeTest
[ RUN      ] AddressSanitizer.UseThenFreeThenUseTest
[       OK ] AddressSanitizer.UseThenFreeThenUseTest (133 ms)
[ RUN      ] AddressSanitizer.FileNameInGlobalReportTest
[       OK ] AddressSanitizer.FileNameInGlobalReportTest (120 ms)
[ DISABLED ] AddressSanitizer.DISABLED_StressStackReuseAndExceptionsTest
[ RUN      ] AddressSanitizer.MlockTest
[       OK ] AddressSanitizer.MlockTest (0 ms)
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadedTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowIn
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowLeft
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowRight
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFHigh
[ DISABLED ] AddressSanitizer.DISABLED_DemoOOM
[ DISABLED ] AddressSanitizer.DISABLED_DemoDoubleFreeTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoNullDerefTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoFunctionStaticTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoTooMuchMemoryTest
[ RUN      ] AddressSanitizer.LongDoubleNegativeTest
[       OK ] AddressSanitizer.LongDoubleNegativeTest (0 ms)
[----------] 19 tests from AddressSanitizer (27685 ms total)

[----------] Global test environment tear-down
[==========] 22 tests from 2 test suites ran. (27692 ms total)
[  PASSED  ] 22 tests.

  YOU HAVE 1 DISABLED TEST
program finished with exit code 0
elapsedTime=2319.700800

@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 22, 2025

LLVM Buildbot has detected a new failure on builder clang-ppc64le-linux-multistage running on ppc64le-clang-multistage-test while building compiler-rt at step 5 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/76/builds/13263

Here is the relevant piece of the build log for the reference
Step 5 (ninja check 1) failure: 1200 seconds without output running [b'ninja', b'check-all'], attempting to kill
...
PASS: SanitizerCommon-ubsan-powerpc64le-Linux :: Linux/signal_segv_handler.cpp (103111 of 103127)
PASS: SanitizerCommon-msan-powerpc64le-Linux :: Linux/signal_segv_handler.cpp (103112 of 103127)
PASS: SanitizerCommon-lsan-powerpc64le-Linux :: Linux/signal_segv_handler.cpp (103113 of 103127)
PASS: mlgo-utils :: corpus/extract_ir_script.test (103114 of 103127)
PASS: SanitizerCommon-tsan-powerpc64le-Linux :: Linux/signal_segv_handler.cpp (103115 of 103127)
PASS: SanitizerCommon-asan-powerpc64le-Linux :: Linux/signal_segv_handler.cpp (103116 of 103127)
PASS: LLVM :: tools/llvm-readobj/ELF/AMDGPU/elf-headers.test (103117 of 103127)
PASS: LLVM :: tools/llvm-objdump/ELF/AMDGPU/subtarget.ll (103118 of 103127)
PASS: lit :: shtest-define.py (103119 of 103127)
PASS: LLVM :: tools/llvm-readobj/ELF/note-core.test (103120 of 103127)
command timed out: 1200 seconds without output running [b'ninja', b'check-all'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=7606.132008
Step 11 (ninja check 2) failure: 1200 seconds without output running [b'ninja', b'check-all'], attempting to kill
...
[1268/1277] Linking CXX executable tools/clang/tools/extra/clangd/unittests/ClangdTests
[1269/1277] Building CXX object tools/clang/unittests/Format/CMakeFiles/FormatTests.dir/FormatTest.cpp.o
[1270/1277] Building CXX object tools/clang/unittests/CMakeFiles/AllClangUnitTests.dir/ASTMatchers/ASTMatchersNarrowingTest.cpp.o
[1271/1277] Linking CXX executable tools/clang/unittests/Format/FormatTests
[1272/1277] Building CXX object tools/clang/unittests/CMakeFiles/AllClangUnitTests.dir/AST/ASTImporterTest.cpp.o
[1273/1277] Building CXX object unittests/ADT/CMakeFiles/ADTTests.dir/SmallVectorTest.cpp.o
[1274/1277] Linking CXX executable unittests/ADT/ADTTests
[1275/1277] Building CXX object tools/clang/unittests/CMakeFiles/AllClangUnitTests.dir/ASTMatchers/ASTMatchersTraversalTest.cpp.o
[1276/1277] Linking CXX executable tools/clang/unittests/AllClangUnitTests
[1276/1277] Running all regression tests
command timed out: 1200 seconds without output running [b'ninja', b'check-all'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1933.301277

Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Oct 29, 2025
…sions (llvm#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: llvm#110555
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
…sions (llvm#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: llvm#110555
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmake Build system in general and CMake in particular compiler-rt PGO Profile Guided Optimizations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants