Skip to content

Commit 653642d

Browse files
authored
Add a SWIFT_STDLIB_HAS_DARWIN_ASL config flag to allow removing asl_log() usage in freestanding build (#39584)
1 parent 75b57ea commit 653642d

File tree

7 files changed

+26
-3
lines changed

7 files changed

+26
-3
lines changed

stdlib/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ else()
6262
set(SWIFT_STDLIB_SUPPORTS_BACKTRACE_REPORTING_default TRUE)
6363
endif()
6464

65+
if("${SWIFT_HOST_VARIANT_SDK}" IN_LIST SWIFT_DARWIN_PLATFORMS)
66+
set(SWIFT_STDLIB_HAS_ASL_default TRUE)
67+
else()
68+
set(SWIFT_STDLIB_HAS_ASL_default FALSE)
69+
endif()
70+
6571
#
6672
# User-configurable options for the standard library.
6773
#
@@ -97,6 +103,10 @@ option(SWIFT_STDLIB_HAS_DARWIN_LIBMALLOC
97103
"Build stdlib assuming the Darwin build of stdlib can use extended libmalloc APIs"
98104
TRUE)
99105

106+
option(SWIFT_STDLIB_HAS_ASL
107+
"Build stdlib assuming we can use the asl_log API."
108+
"${SWIFT_STDLIB_HAS_ASL_default}")
109+
100110
option(SWIFT_STDLIB_HAS_STDIN
101111
"Build stdlib assuming the platform supports stdin and getline API."
102112
TRUE)

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ function(_add_target_variant_c_compile_flags)
335335
list(APPEND result "-DSWIFT_STDLIB_HAS_DARWIN_LIBMALLOC=0")
336336
endif()
337337

338+
if(SWIFT_STDLIB_HAS_ASL)
339+
list(APPEND result "-DSWIFT_STDLIB_HAS_ASL")
340+
endif()
341+
338342
if(SWIFT_STDLIB_HAS_STDIN)
339343
list(APPEND result "-DSWIFT_STDLIB_HAS_STDIN")
340344
endif()

stdlib/public/LLVMSupport/ErrorHandling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void error(const char *fmt, ...) {
4141
vsnprintf(buffer, sizeof(buffer), fmt, argp);
4242
va_end(argp);
4343

44-
#if defined(__APPLE__)
44+
#if SWIFT_STDLIB_HAS_ASL
4545
asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", buffer);
4646
#elif defined(__ANDROID__)
4747
__android_log_print(ANDROID_LOG_FATAL, "SwiftRuntime", "%s", buffer);

stdlib/public/runtime/Errors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ reportNow(uint32_t flags, const char *message)
314314
#else
315315
write(STDERR_FILENO, message, strlen(message));
316316
#endif
317-
#if defined(__APPLE__)
317+
#if SWIFT_STDLIB_HAS_ASL
318318
asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", message);
319319
#elif defined(__ANDROID__)
320320
__android_log_print(ANDROID_LOG_FATAL, "SwiftRuntime", "%s", message);

utils/build-presets.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,6 +2466,7 @@ swift-enable-reflection=0
24662466
swift-stdlib-has-dladdr=0
24672467
swift-stdlib-supports-backtrace-reporting=0
24682468
swift-stdlib-has-darwin-libmalloc=0
2469+
swift-stdlib-has-asl=0
24692470
swift-stdlib-has-stdin=0
24702471
swift-runtime-static-image-inspection=1
24712472
swift-stdlib-single-threaded-runtime=1

utils/build-script-impl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ KNOWN_SETTINGS=(
213213
swift-stdlib-os-versioning "1" "whether to build stdlib with availability based on OS versions (Darwin only)"
214214
swift-stdlib-stable-abi "" "should stdlib be built with stable ABI, if not set defaults to true on Darwin, false otherwise"
215215
swift-stdlib-has-darwin-libmalloc "1" "whether the Darwin build of stdlib can use extended libmalloc APIs"
216+
swift-stdlib-has-asl "" "whether the stdlib can use the asl_log API, defaults to true on Darwin, false otherwise"
216217
swift-stdlib-has-stdin "1" "whether to build stdlib assuming the platform supports stdin and getline API"
217218
swift-stdlib-lto "" "enable LLVM LTO on the stdlib, valid values are empty string (no LTO), 'full' and 'thin'"
218219
swift-disable-dead-stripping "0" "turns off Darwin-specific dead stripping for Swift host tools"
@@ -2111,6 +2112,13 @@ for host in "${ALL_HOSTS[@]}"; do
21112112
)
21122113
fi
21132114

2115+
if [[ "${SWIFT_STDLIB_HAS_ASL}" ]] ; then
2116+
cmake_options=(
2117+
"${cmake_options[@]}"
2118+
-DSWIFT_STDLIB_HAS_ASL:BOOL=$(true_false "${SWIFT_STDLIB_HAS_ASL}")
2119+
)
2120+
fi
2121+
21142122
if [ "${SWIFT_INSTALL_COMPONENTS}" ] ; then
21152123
cmake_options=(
21162124
"${cmake_options[@]}"

utils/check_freestanding_dependencies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
] + icu_dependencies + cxx_dependencies + math_dependencies
6161
vendor_apple_specific_dependencies = [
6262
"__NSGetArgc", "__NSGetArgv", "___stack_chk_fail", "___stack_chk_guard",
63-
"_asl_log", "_getsectiondata", "__dyld_register_func_for_add_image",
63+
"_getsectiondata", "__dyld_register_func_for_add_image",
6464
]
6565
################################################################################
6666

0 commit comments

Comments
 (0)