diff --git a/CMakeLists.txt b/CMakeLists.txt
index 30d960cb07..dbc303dc4c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -77,9 +77,29 @@ endif()
 FetchContent_MakeAvailable(SwiftFoundationICU SwiftFoundation)
 
 include(CheckLinkerFlag)
+include(CheckSymbolExists)
 
 check_linker_flag(C "LINKER:--build-id=sha1" LINKER_SUPPORTS_BUILD_ID)
 
+# Detect if the system libc defines symbols for these functions.
+# If it is not availble, swift-corelibs-foundation has its own implementations
+# that will be used. If it is available, it should not redefine them.
+# Note: SwiftPM does not have the ability to introspect the contents of the SDK
+#       and therefore will always include these functions in the build and will
+#       cause build failures on platforms that define these functions.
+check_symbol_exists("strlcat" "string.h" HAVE_STRLCAT)
+check_symbol_exists("strlcpy" "string.h" HAVE_STRLCPY)
+check_symbol_exists("issetugid" "unistd.h" HAVE_ISSETUGID)
+add_compile_definitions(
+  $<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_STRLCAT}>>:HAVE_STRLCAT>
+  $<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_STRLCPY}>>:HAVE_STRLCPY>
+  $<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_ISSETUGID}>>:HAVE_ISSETUGID>)
+
+if(CMAKE_SYSTEM_NAME STREQUAL Linux)
+  check_symbol_exists(sched_getaffinity "sched.h" HAVE_SCHED_GETAFFINITY)
+  add_compile_definitions($<$<COMPILE_LANGUAGE:C>:HAVE_SCHED_GETAFFINITY>)
+endif()
+
 # Precompute module triple for installation
 if(NOT SwiftFoundation_MODULE_TRIPLE)
     set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info)
@@ -93,6 +113,7 @@ if(NOT SwiftFoundation_MODULE_TRIPLE)
 endif()
 
 # System dependencies
+find_package(LibRT)
 find_package(dispatch CONFIG)
 if(NOT dispatch_FOUND)
     if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
diff --git a/Sources/Foundation/Port.swift b/Sources/Foundation/Port.swift
index c1f78c14a4..c4ed8282bf 100644
--- a/Sources/Foundation/Port.swift
+++ b/Sources/Foundation/Port.swift
@@ -113,6 +113,12 @@ fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM.rawValue)
 fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP)
 #endif
 
+#if canImport(Musl)
+import Musl
+fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM)
+fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP)
+#endif
+
 #if canImport(Glibc) && os(Android) || os(OpenBSD)
 import Glibc
 fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM)
diff --git a/cmake/modules/FindLibRT.cmake b/cmake/modules/FindLibRT.cmake
index 0a9f0d80e5..caee828517 100644
--- a/cmake/modules/FindLibRT.cmake
+++ b/cmake/modules/FindLibRT.cmake
@@ -4,7 +4,7 @@
 #
 # Find librt library and headers.
 #
-# The mdoule defines the following variables:
+# The module defines the following variables:
 #
 # ::
 #