Skip to content

Commit

Permalink
Add patch for backtracing support for armv7, enable backtracing in st…
Browse files Browse the repository at this point in the history
…dlib build
  • Loading branch information
xtremekforever committed Feb 26, 2025
1 parent 712cc2b commit c8d7459
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build-swift-stdlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ LIBS="-latomic" cmake -S $SWIFT_SRCDIR -B $SWIFT_BUILDDIR -G Ninja \
-DSWIFT_BUILD_REMOTE_MIRROR=ON \
-DSWIFT_BUILD_SOURCEKIT=ON \
-DSWIFT_BUILD_STDLIB_EXTRA_TOOLCHAIN_CONTENT=ON \
-DSWIFT_ENABLE_SOURCEKIT_TESTS=OFF \
-DSWIFT_ENABLE_BACKTRACING=ON \
-DSWIFT_INCLUDE_DOCS=OFF \
-DSWIFT_INCLUDE_TOOLS=OFF \
-DSWIFT_INCLUDE_TESTS=OFF \
Expand Down
3 changes: 2 additions & 1 deletion fetch-sources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ fi
--skip-repository zlib \

# Apply patches
echo "Apply CXX interop patch"
echo "Apply Swift patches"
patch -d . -p1 <$SRC_ROOT/patches/0001-Swift-fix-find-libstdc++-for-cxx-interop.patch
patch -d . -p1 <$SRC_ROOT/patches/0003-Add-fixes-to-correct-backtracing-compilation-for-arm.patch

# Only applies to Swift 5.9
if [[ $SWIFT_VERSION == *"5.9"* ]]; then
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
From 2dd33c1200664fef2dc034966323307c8057f7cb Mon Sep 17 00:00:00 2001
From: "Jesse L. Zamora" <[email protected]>
Date: Tue, 25 Feb 2025 17:54:51 -0500
Subject: [PATCH] Add fixes to correct backtracing compilation for armv7

---
stdlib/public/Backtracing/Context.swift | 7 ++++---
stdlib/public/runtime/CrashHandlerLinux.cpp | 2 +-
stdlib/public/runtime/Float16Support.cpp | 2 +-
3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/stdlib/public/Backtracing/Context.swift b/stdlib/public/Backtracing/Context.swift
index bfb015e6d96..92e36d13e27 100644
--- a/stdlib/public/Backtracing/Context.swift
+++ b/stdlib/public/Backtracing/Context.swift
@@ -865,10 +865,11 @@ extension arm_gprs {

#if os(Linux) && arch(arm)
init(with mctx: mcontext_t) {
+ var mctxCopy = mctx
withUnsafeMutablePointer(to: &gprs._r) {
- $0.withMemoryRebound(to: UInt32.self, capacity: 16) {
- withUnsafePointer(to: &mctx.arm_r0) {
- $0.withMemoryRebound(to: UInt32.self, capacity: 16) {
+ $0.withMemoryRebound(to: UInt32.self, capacity: 16) { to in
+ withUnsafePointer(to: &mctxCopy.arm_r0) {
+ $0.withMemoryRebound(to: UInt32.self, capacity: 16) { from in
for n in 0..<16 {
to[n] = from[n]
}
diff --git a/stdlib/public/runtime/CrashHandlerLinux.cpp b/stdlib/public/runtime/CrashHandlerLinux.cpp
index 1c188374bc5..7baeb365c77 100644
--- a/stdlib/public/runtime/CrashHandlerLinux.cpp
+++ b/stdlib/public/runtime/CrashHandlerLinux.cpp
@@ -251,7 +251,7 @@ handle_fatal_signal(int signum,
#elif defined(__arm64__) || defined(__aarch64__)
pc = (void *)(ctx->uc_mcontext.pc);
#elif defined(__arm__)
-#if defined(__ANDROID__)
+#if defined(__ANDROID__) || defined(__linux__)
pc = (void *)(ctx->uc_mcontext.arm_pc);
#else
pc = (void *)(ctx->uc_mcontext.gprs[15]);
diff --git a/stdlib/public/runtime/Float16Support.cpp b/stdlib/public/runtime/Float16Support.cpp
index fa259559e45..0c887272164 100644
--- a/stdlib/public/runtime/Float16Support.cpp
+++ b/stdlib/public/runtime/Float16Support.cpp
@@ -31,7 +31,7 @@
// Android NDK <r21 do not provide `__aeabi_d2h` in the compiler runtime,
// provide shims in that case.
#if (defined(__ANDROID__) && defined(__ARM_ARCH_7A__) && defined(__ARM_EABI__)) || \
- ((defined(__i386__) || defined(__i686__) || defined(__x86_64__)) && !defined(__APPLE__))
+ ((defined(__i386__) || defined(__i686__) || defined(__x86_64__) || defined(__arm__)) && !defined(__APPLE__))

#include "swift/shims/Visibility.h"

--
2.43.0

0 comments on commit c8d7459

Please sign in to comment.