Skip to content

[LoongArch][sanitizer] Fix SC_ADDRERR_{RD,WR} missing in the musl environment #108557

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 2 commits into from
Sep 14, 2024

Conversation

heiher
Copy link
Member

@heiher heiher commented Sep 13, 2024

Fixes #108550

@heiher
Copy link
Member Author

heiher commented Sep 13, 2024

cc @xen0n @xry111

@llvmbot
Copy link
Member

llvmbot commented Sep 13, 2024

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

Author: hev (heiher)

Changes

Fixes #108550


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

1 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp (+12)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 16d06c69a38f32..f4a2f46c6ea022 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -2018,6 +2018,18 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
     return Unknown;
   return esr & ESR_ELx_WNR ? Write : Read;
 #  elif defined(__loongarch__)
+     // In the musl environment, the Linux kernel uapi sigcontext.h is not
+     // included in signal.h. To avoid missing the SC_ADDRERR_{RD,WR} macros,
+     // copy them here. The LoongArch Linux kernel uapi is already stable,
+     // so there's no need to worry about the value changing.
+#    ifndef SC_ADDRERR_RD
+       // Address error was due to memory load
+#      define SC_ADDRERR_RD		(1 << 30)
+#    endif
+#    ifndef SC_ADDRERR_WR
+       // Address error was due to memory store
+#      define SC_ADDRERR_WR		(1 << 31)
+#    endif
   u32 flags = ucontext->uc_mcontext.__flags;
   if (flags & SC_ADDRERR_RD)
     return SignalContext::Read;

Copy link

github-actions bot commented Sep 13, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@SixWeining SixWeining left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@heiher heiher merged commit 1825cf2 into llvm:main Sep 14, 2024
7 checks passed
@heiher heiher deleted the issue-108550 branch September 14, 2024 03:19
@heiher heiher added this to the LLVM 19.X Release milestone Sep 18, 2024
@heiher
Copy link
Member Author

heiher commented Sep 18, 2024

/cherry-pick 1825cf2

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Sep 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 18, 2024

/pull-request #109110

tru pushed a commit to llvmbot/llvm-project that referenced this pull request Sep 24, 2024
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.

[LoongArch] 'SC_ADDRERR_Z{RD,WR}' was not declared in the musl environment
3 participants