diff --git a/package/swift/extra-patches/004-MIPS.patch b/package/swift/extra-patches/004-MIPS.patch new file mode 100644 index 0000000..8cc3594 --- /dev/null +++ b/package/swift/extra-patches/004-MIPS.patch @@ -0,0 +1,189 @@ +diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake +index 3e918719e3e..ce5358fa7a0 100644 +--- a/cmake/modules/AddSwift.cmake ++++ b/cmake/modules/AddSwift.cmake +@@ -335,7 +335,7 @@ function(_add_host_variant_c_compile_flags target) + # The LLVM backend is built with these defines on most 32-bit platforms, + # llvm/llvm-project@66395c9, which can cause incompatibilities with the Swift + # frontend if not built the same way. +- if("${SWIFT_HOST_VARIANT_ARCH}" MATCHES "armv6|armv7|i686" AND ++ if("${SWIFT_HOST_VARIANT_ARCH}" MATCHES "mips|mipsel|armv6|armv7|i686" AND + NOT (SWIFT_HOST_VARIANT_SDK STREQUAL ANDROID AND SWIFT_ANDROID_API_LEVEL LESS 24)) + target_compile_definitions(${target} PRIVATE + $<$:_LARGEFILE_SOURCE _FILE_OFFSET_BITS=64>) +@@ -349,7 +349,7 @@ function(_add_host_variant_link_flags target) + target_link_libraries(${target} PRIVATE + pthread + dl) +- if("${SWIFT_HOST_VARIANT_ARCH}" MATCHES "armv5|armv6|armv7|i686") ++ if("${SWIFT_HOST_VARIANT_ARCH}" MATCHES "mips|mipsel|armv5|armv6|armv7|i686") + target_link_libraries(${target} PRIVATE atomic) + endif() + elseif(SWIFT_HOST_VARIANT_SDK STREQUAL FREEBSD) +diff --git a/cmake/modules/AddSwiftUnittests.cmake b/cmake/modules/AddSwiftUnittests.cmake +index 9dff9f77a2e..f1cd0961882 100644 +--- a/cmake/modules/AddSwiftUnittests.cmake ++++ b/cmake/modules/AddSwiftUnittests.cmake +@@ -37,7 +37,7 @@ function(add_swift_unittest test_dirname) + if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") + target_compile_options(${test_dirname} PRIVATE + -march=core2) +- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "armv5|armv6|armv7|i686") ++ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "mips|mipsel|armv5|armv6|armv7|i686") + set_property(TARGET "${test_dirname}" APPEND PROPERTY LINK_LIBRARIES + "atomic") + endif() +diff --git a/cmake/modules/SwiftConfigureSDK.cmake b/cmake/modules/SwiftConfigureSDK.cmake +index fbcea509552..f4c0632e87a 100644 +--- a/cmake/modules/SwiftConfigureSDK.cmake ++++ b/cmake/modules/SwiftConfigureSDK.cmake +@@ -364,7 +364,7 @@ macro(configure_sdk_unix name architectures) + set(SWIFT_SDK_LINUX_ARCH_${arch}_TRIPLE "${arch}-unknown-linux-gnueabi") + elseif(arch MATCHES "(armv6|armv7)") + set(SWIFT_SDK_LINUX_ARCH_${arch}_TRIPLE "${arch}-unknown-linux-gnueabihf") +- elseif(arch MATCHES "(aarch64|i686|powerpc|powerpc64|powerpc64le|s390x|x86_64|riscv64)") ++ elseif(arch MATCHES "(aarch64|i686|powerpc|powerpc64|powerpc64le|s390x|x86_64|riscv64|mips|mipsel|mips64|mips64el)") + set(SWIFT_SDK_LINUX_ARCH_${arch}_TRIPLE "${arch}-unknown-linux-gnu") + else() + message(FATAL_ERROR "unknown arch for ${prefix}: ${arch}") +diff --git a/cmake/modules/SwiftSetIfArchBitness.cmake b/cmake/modules/SwiftSetIfArchBitness.cmake +index 9038302669e..8844312a2bf 100644 +--- a/cmake/modules/SwiftSetIfArchBitness.cmake ++++ b/cmake/modules/SwiftSetIfArchBitness.cmake +@@ -10,6 +10,8 @@ function(set_if_arch_bitness var_name) + "${SIA_ARCH}" STREQUAL "i686" OR + "${SIA_ARCH}" STREQUAL "x86" OR + "${SIA_ARCH}" STREQUAL "armv5" OR ++ "${SIA_ARCH}" STREQUAL "mips" OR ++ "${SIA_ARCH}" STREQUAL "mipsel" OR + "${SIA_ARCH}" STREQUAL "armv6" OR + "${SIA_ARCH}" STREQUAL "armv7" OR + "${SIA_ARCH}" STREQUAL "armv7k" OR +@@ -25,6 +27,8 @@ function(set_if_arch_bitness var_name) + "${SIA_ARCH}" STREQUAL "aarch64" OR + "${SIA_ARCH}" STREQUAL "powerpc64" OR + "${SIA_ARCH}" STREQUAL "powerpc64le" OR ++ "${SIA_ARCH}" STREQUAL "mips64" OR ++ "${SIA_ARCH}" STREQUAL "mips64el" OR + "${SIA_ARCH}" STREQUAL "s390x" OR + "${SIA_ARCH}" STREQUAL "riscv64") + set("${var_name}" "${SIA_CASE_64_BIT}" PARENT_SCOPE) +diff --git a/lib/Basic/LangOptions.cpp b/lib/Basic/LangOptions.cpp +index 86a887a4eef..30e5d72bba0 100644 +--- a/lib/Basic/LangOptions.cpp ++++ b/lib/Basic/LangOptions.cpp +@@ -74,6 +74,10 @@ static const SupportedConditionalValue SupportedConditionalCompilationArches[] = + "powerpc", + "powerpc64", + "powerpc64le", ++ "mips", ++ "mipsel", ++ "mips64", ++ "mips64el", + "s390x", + "wasm32", + "riscv64", +@@ -357,6 +361,18 @@ std::pair LangOptions::setTarget(llvm::Triple triple) { + case llvm::Triple::ArchType::ppc64le: + addPlatformConditionValue(PlatformConditionKind::Arch, "powerpc64le"); + break; ++ case llvm::Triple::ArchType::mips: ++ addPlatformConditionValue(PlatformConditionKind::Arch, "mips"); ++ break; ++ case llvm::Triple::ArchType::mipsel: ++ addPlatformConditionValue(PlatformConditionKind::Arch, "mipsel"); ++ break; ++ case llvm::Triple::ArchType::mips64: ++ addPlatformConditionValue(PlatformConditionKind::Arch, "mips64"); ++ break; ++ case llvm::Triple::ArchType::mips64el: ++ addPlatformConditionValue(PlatformConditionKind::Arch, "mips64el"); ++ break; + case llvm::Triple::ArchType::x86: + addPlatformConditionValue(PlatformConditionKind::Arch, "i386"); + break; +diff --git a/stdlib/public/core/AtomicInt.swift.gyb b/stdlib/public/core/AtomicInt.swift.gyb +index e367a62cc52..91147a40a1d 100644 +--- a/stdlib/public/core/AtomicInt.swift.gyb ++++ b/stdlib/public/core/AtomicInt.swift.gyb +@@ -65,10 +65,10 @@ internal func _swift_stdlib_atomicCompareExchangeStrongInt( + object target: UnsafeMutablePointer, + expected: UnsafeMutablePointer, + desired: Int) -> Bool { +-#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) || arch(powerpc) ++#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) || arch(mips) || arch(mipsel) || arch(powerpc) + let (oldValue, won) = Builtin.cmpxchg_seqcst_seqcst_Int32( + target._rawValue, expected.pointee._value, desired._value) +-#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) || arch(riscv64) ++#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) || arch(riscv64) || arch(mips64) || arch(mips64el) + let (oldValue, won) = Builtin.cmpxchg_seqcst_seqcst_Int64( + target._rawValue, expected.pointee._value, desired._value) + #endif +@@ -82,22 +82,22 @@ internal func _swift_stdlib_atomicCompareExchangeStrongInt( + public // Existing uses outside stdlib + func _swift_stdlib_atomicLoadInt( + object target: UnsafeMutablePointer) -> Int { +-#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) || arch(powerpc) ++#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) || arch(mips) || arch(mipsel) || arch(powerpc) + let value = Builtin.atomicload_seqcst_Int32(target._rawValue) + return Int(value) +-#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) || arch(riscv64) ++#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) || arch(riscv64) || arch(mips64) || arch(mips64el) + let value = Builtin.atomicload_seqcst_Int64(target._rawValue) + return Int(value) + #endif + + @usableFromInline // used by SwiftPrivate._stdlib_AtomicInt + internal func _swift_stdlib_atomicStoreInt( + object target: UnsafeMutablePointer, + desired: Int) { +-#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) || arch(powerpc) ++#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) || arch(mips) || arch(mipsel) || arch(powerpc) + Builtin.atomicstore_seqcst_Int32(target._rawValue, desired._value) +-#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) || arch(riscv64) ++#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) || arch(riscv64) || arch(mips64) || arch(mips64el) + Builtin.atomicstore_seqcst_Int64(target._rawValue, desired._value) + #endif + } +@@ -111,11 +111,11 @@ func _swift_stdlib_atomicFetch${operation}Int( + object target: UnsafeMutablePointer, + operand: Int) -> Int { + let rawTarget = UnsafeMutableRawPointer(target) +-#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) || arch(powerpc) ++#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) || arch(mips) || arch(mipsel) || arch(powerpc) + let value = _swift_stdlib_atomicFetch${operation}Int32( + object: rawTarget.assumingMemoryBound(to: Int32.self), + operand: Int32(operand)) +-#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) || arch(riscv64) ++#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) || arch(riscv64) || arch(mips64) || arch(mips64el) + let value = _swift_stdlib_atomicFetch${operation}Int64( + object: rawTarget.assumingMemoryBound(to: Int64.self), + operand: Int64(operand)) +diff --git a/stdlib/public/core/Builtin.swift b/stdlib/public/core/Builtin.swift +index c651fb30f3f..7986ed91a79 100644 +--- a/stdlib/public/core/Builtin.swift ++++ b/stdlib/public/core/Builtin.swift +@@ -397,8 +397,7 @@ internal var _objectPointerLowSpareBitShift: UInt { + } + } + +-#if arch(i386) || arch(arm) || arch(wasm32) || arch(powerpc) || arch(powerpc64) || arch( +- powerpc64le) || arch(s390x) || arch(arm64_32) ++#if arch(i386) || arch(arm) || arch(wasm32) || arch(powerpc) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) || arch(arm64_32) || arch(mips) || arch(mipsel) || arch(mips64) || arch(mips64el) + @inlinable + internal var _objectPointerIsObjCBit: UInt { + @inline(__always) get { return 0x0000_0002 } +diff --git a/stdlib/public/stubs/MathStubs.cpp b/stdlib/public/stubs/MathStubs.cpp +index fbab170b2aa..b15c72f927c 100644 +--- a/stdlib/public/stubs/MathStubs.cpp ++++ b/stdlib/public/stubs/MathStubs.cpp +@@ -113,7 +113,8 @@ __muloti4(ti_int a, ti_int b, int* overflow) + // lowered to instructions as though MSVC had generated. There does not seem to + // be a MSVC provided multiply with overflow detection that I can see, but this + // avoids an unnecessary dependency on compiler-rt for a single function. +-#if (defined(__linux__) && (defined(__arm__) || defined(__i386__) || defined(__powerpc__))) || defined(_WIN32) ++ ++#if (defined(__linux__) && (defined(__arm__) || defined(__i386__) || defined(__powerpc__) || (defined(__mips__) && !defined(__LP64__)))) || defined(_WIN32) + + // Similar to above, but with mulodi4. Perhaps this is + // something that shouldn't be done, and is a bandaid over