Skip to content

[compiler-rt] Support building runtimes for Windows on arm32 #101462

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

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

mstorsjo
Copy link
Member

@mstorsjo mstorsjo commented Aug 1, 2024

In these environments, the architecture name is armv7; recognize that and enable the relevant runtimes.

Fix building the sanitizer_common library for this target, by using the right registers for the architecture - this is similar to what 0c39113 did for aarch64.

(Still, address sanitizer doesn't support hooking functions at runtime on armv7 or aarch64 - but other runtimes such as ubsan do work.)

In these environments, the architecture name is armv7; recognize
that and enable the relevant runtimes.

Fix building the sanitizer_common library for this target, by using
the right registers for the architecture - this is similar to what
0c39113 did for aarch64.

(Still, address sanitizer doesn't support hooking functions
at runtime on armv7 or aarch64 - but other runtimes such as ubsan
do work.)
@llvmbot
Copy link
Member

llvmbot commented Aug 1, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Martin Storsjö (mstorsjo)

Changes

In these environments, the architecture name is armv7; recognize that and enable the relevant runtimes.

Fix building the sanitizer_common library for this target, by using the right registers for the architecture - this is similar to what 0c39113 did for aarch64.

(Still, address sanitizer doesn't support hooking functions at runtime on armv7 or aarch64 - but other runtimes such as ubsan do work.)


Full diff: https://github.com/llvm/llvm-project/pull/101462.diff

3 Files Affected:

  • (modified) compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake (+4)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_unwind_win.cpp (+7)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_win.cpp (+5)
diff --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index 29e5beb6182ba..37ad48bef818a 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -24,6 +24,10 @@ if(APPLE)
   set(X86_64 x86_64 x86_64h)
 endif()
 
+if(WIN32)
+  set(ARM32 ${ARM32} armv7)
+endif()
+
 set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64} ${RISCV64}
     ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9}
     ${HEXAGON} ${LOONGARCH64})
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_unwind_win.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_unwind_win.cpp
index afcd01dae0b7a..6fc18396ca63b 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_unwind_win.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_unwind_win.cpp
@@ -70,10 +70,17 @@ void BufferedStackTrace::UnwindSlow(uptr pc, void *context, u32 max_depth) {
   stack_frame.AddrStack.Offset = ctx.Rsp;
 #      endif
 #    else
+#      if SANITIZER_ARM
+  int machine_type = IMAGE_FILE_MACHINE_ARM;
+  stack_frame.AddrPC.Offset = ctx.Pc;
+  stack_frame.AddrFrame.Offset = ctx.R11;
+  stack_frame.AddrStack.Offset = ctx.Sp;
+#      else
   int machine_type = IMAGE_FILE_MACHINE_I386;
   stack_frame.AddrPC.Offset = ctx.Eip;
   stack_frame.AddrFrame.Offset = ctx.Ebp;
   stack_frame.AddrStack.Offset = ctx.Esp;
+#      endif
 #    endif
   stack_frame.AddrPC.Mode = AddrModeFlat;
   stack_frame.AddrFrame.Mode = AddrModeFlat;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
index 995f00eddc38a..8a80d54751364 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
@@ -992,8 +992,13 @@ void SignalContext::InitPcSpBp() {
   sp = (uptr)context_record->Rsp;
 #    endif
 #  else
+#    if SANITIZER_ARM
+  bp = (uptr)context_record->R11;
+  sp = (uptr)context_record->Sp;
+#    else
   bp = (uptr)context_record->Ebp;
   sp = (uptr)context_record->Esp;
+#    endif
 #  endif
 }
 

@mstorsjo
Copy link
Member Author

mstorsjo commented Aug 3, 2024

Ping @vitalybuka, does this seem reasonable?

@mstorsjo mstorsjo merged commit 5ea9dd8 into llvm:main Aug 8, 2024
9 checks passed
@mstorsjo mstorsjo deleted the sanitizers-arm branch August 8, 2024 10:51
@mstorsjo mstorsjo added this to the LLVM 19.X Release milestone Aug 29, 2024
@mstorsjo
Copy link
Member Author

/cherry-pick 5ea9dd8

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Aug 29, 2024
…1462)

In these environments, the architecture name is armv7; recognize that
and enable the relevant runtimes.

Fix building the sanitizer_common library for this target, by using the
right registers for the architecture - this is similar to what
0c39113 did for aarch64.

(Still, address sanitizer doesn't support hooking functions at runtime
on armv7 or aarch64 - but other runtimes such as ubsan do work.)

(cherry picked from commit 5ea9dd8)
@llvmbot
Copy link
Member

llvmbot commented Aug 29, 2024

/pull-request #106518

tru pushed a commit to llvmbot/llvm-project that referenced this pull request Sep 3, 2024
…1462)

In these environments, the architecture name is armv7; recognize that
and enable the relevant runtimes.

Fix building the sanitizer_common library for this target, by using the
right registers for the architecture - this is similar to what
0c39113 did for aarch64.

(Still, address sanitizer doesn't support hooking functions at runtime
on armv7 or aarch64 - but other runtimes such as ubsan do work.)

(cherry picked from commit 5ea9dd8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

3 participants