Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The swift-corelibs-foundation build is broken in glibc 2.38+ on the main branch. #5012

Open
bc-lee opened this issue Jul 17, 2024 · 0 comments · May be fixed by #5013
Open

The swift-corelibs-foundation build is broken in glibc 2.38+ on the main branch. #5012

bc-lee opened this issue Jul 17, 2024 · 0 comments · May be fixed by #5013

Comments

@bc-lee
Copy link

bc-lee commented Jul 17, 2024

swift-corelibs-foundation uses strlcpy and strlcat functions, which are originally from BSD and not available in glibc. However, glibc 2.38 added these functions as an extension, so swift-corelibs-foundation includes a CMake check for these functions and uses them from glibc if available; otherwise, it provides its own implementation like this:

#if !TARGET_OS_MAC
#if !HAVE_STRLCPY
CF_INLINE size_t
strlcpy(char * dst, const char * src, size_t maxlen) {
    // omitting the implementation
}
#endif

See 8d1a679 and 48076cb for more details.

However, when the new CMakeFiles were added in c772413, this check wasn't added to the new CMakeLists.txt, so the build fails when glibc 2.38+ is used.

For example, see my build log at https://download.copr.fedorainfracloud.org/results/leebc/swift-lang-main/fedora-40-x86_64/07741791-swift-lang/builder-live.log.gz. The build failed with:

Details
[472/573][ 82%][102.959s] /builddir/build/BUILD/swift-source/build/buildbot_linux/llvm-linux-x86_64/bin/clang  -I/builddir/build/BUILD/swift-source/swift-corelibs-foundation/Sources/CoreFoundation/include -I/builddir/build/BUILD/swift-source/swift-corelibs-foundation/Sources/CoreFoundation/internalInclude -I/builddir/build/BUILD/swift-source/swift-foundation-icu/icuSources/include -isystem /builddir/build/BUILD/swift-source/build/buildbot_linux/libdispatch-linux-x86_64 -isystem /builddir/build/BUILD/swift-source/swift-corelibs-libdispatch -isystem /builddir/build/BUILD/swift-source/swift-corelibs-libdispatch/src -isystem /builddir/build/BUILD/swift-source/build/buildbot_linux/libdispatch-linux-x86_64/src -isystem /builddir/build/BUILD/swift-source/swift-corelibs-libdispatch/src/BlocksRuntime -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -O3 -DNDEBUG -fPIC -DDEPLOYMENT_RUNTIME_SWIFT -DCF_BUILDING_CF -DDEPLOYMENT_ENABLE_LIBDISPATCH -DHAVE_STRUCT_TIMESPEC -DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS -Wno-shorten-64-to-32 -Wno-deprecated-declarations -Wno-unreachable-code -Wno-conditional-uninitialized -Wno-unused-variable -Wno-unused-function -Wno-microsoft-enum-forward-reference -Wno-int-conversion -fblocks -fconstant-cfstrings -fdollars-in-identifiers -fno-common -fcf-runtime-abi=swift -fexceptions -D_GNU_SOURCE -I/usr/lib/swift -Winvalid-pch -fpch-instantiate-templates -Xclang -emit-pch -Xclang -include -Xclang /builddir/build/BUILD/swift-source/build/buildbot_linux/foundation-linux-x86_64/Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h -x c-header -MD -MT Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.pch -MF Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.pch.d -o Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.pch -c /builddir/build/BUILD/swift-source/build/buildbot_linux/foundation-linux-x86_64/Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.c
FAILED: Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.pch
/builddir/build/BUILD/swift-source/build/buildbot_linux/llvm-linux-x86_64/bin/clang  -I/builddir/build/BUILD/swift-source/swift-corelibs-foundation/Sources/CoreFoundation/include -I/builddir/build/BUILD/swift-source/swift-corelibs-foundation/Sources/CoreFoundation/internalInclude -I/builddir/build/BUILD/swift-source/swift-foundation-icu/icuSources/include -isystem /builddir/build/BUILD/swift-source/build/buildbot_linux/libdispatch-linux-x86_64 -isystem /builddir/build/BUILD/swift-source/swift-corelibs-libdispatch -isystem /builddir/build/BUILD/swift-source/swift-corelibs-libdispatch/src -isystem /builddir/build/BUILD/swift-source/build/buildbot_linux/libdispatch-linux-x86_64/src -isystem /builddir/build/BUILD/swift-source/swift-corelibs-libdispatch/src/BlocksRuntime -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -O3 -DNDEBUG -fPIC -DDEPLOYMENT_RUNTIME_SWIFT -DCF_BUILDING_CF -DDEPLOYMENT_ENABLE_LIBDISPATCH -DHAVE_STRUCT_TIMESPEC -DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS -Wno-shorten-64-to-32 -Wno-deprecated-declarations -Wno-unreachable-code -Wno-conditional-uninitialized -Wno-unused-variable -Wno-unused-function -Wno-microsoft-enum-forward-reference -Wno-int-conversion -fblocks -fconstant-cfstrings -fdollars-in-identifiers -fno-common -fcf-runtime-abi=swift -fexceptions -D_GNU_SOURCE -I/usr/lib/swift -Winvalid-pch -fpch-instantiate-templates -Xclang -emit-pch -Xclang -include -Xclang /builddir/build/BUILD/swift-source/build/buildbot_linux/foundation-linux-x86_64/Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h -x c-header -MD -MT Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.pch -MF Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.pch.d -o Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.pch -c /builddir/build/BUILD/swift-source/build/buildbot_linux/foundation-linux-x86_64/Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.c
In file included from <built-in>:1:
In file included from /builddir/build/BUILD/swift-source/build/buildbot_linux/foundation-linux-x86_64/Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h:4:
/builddir/build/BUILD/swift-source/swift-corelibs-foundation/Sources/CoreFoundation/internalInclude/CoreFoundation_Prefix.h:205:1: error: static declaration of 'strlcpy' follows non-static declaration
205 | strlcpy(char * dst, const char * src, size_t maxlen) {
    | ^
/usr/include/string.h:506:15: note: previous declaration is here
506 | extern size_t strlcpy (char *__restrict __dest,
    |               ^
In file included from <built-in>:1:
In file included from /builddir/build/BUILD/swift-source/build/buildbot_linux/foundation-linux-x86_64/Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h:4:
/builddir/build/BUILD/swift-source/swift-corelibs-foundation/Sources/CoreFoundation/internalInclude/CoreFoundation_Prefix.h:219:1: error: static declaration of 'strlcat' follows non-static declaration
219 | strlcat(char * dst, const char * src, size_t maxlen) {
    | ^
/usr/include/string.h:512:15: note: previous declaration is here
512 | extern size_t strlcat (char *__restrict __dest,
    |               ^
2 errors generated.

We should add the check for strlcpy and strlcat functions in the new CMakeLists.txt as well.

bc-lee added a commit to bc-lee/swift-corelibs-foundation that referenced this issue Jul 17, 2024
These checks are required because glibc 2.38+ added strlcat and strlcpy
functions. swift-corelibs-foundation should use these functions if
they are available.

The checks originally existed in commit 8d1a679,
but were not added to the new CMakeLists.txt in commit c772413.

Fixes swiftlang#5012
bc-lee added a commit to bc-lee/swift-corelibs-foundation that referenced this issue Jul 19, 2024
…itions.

While checking whether the system provides the `strlcat` and `strlcpy`
functions, using an autoconf-style check to determine their availability
does not seem to be a good idea. This is because the code is also
used with SwiftPM, which does not have a similar feature test.
Instead, we should directly check the availability of these functions
in the system.

Given that `strlcpy` and `strlcat` are not standard C functions,
we should check whether the system is macOS, Linux with Bionic or
Musl libc, or glibc version 2.38 or later. This patch adds the necessary
checks in the header file so that SwiftPM can use these checks as well.

Fixes swiftlang#5012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant