-
Notifications
You must be signed in to change notification settings - Fork 39
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
Allow using sanitizer runtimes on RISC-V #564
Open
arichardson
wants to merge
9
commits into
CTSRD-CHERI:dev
Choose a base branch
from
arichardson:riscv-purecap-compiler-rt
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+251
−100
Open
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a7421e8
[CHERI-RISC-V] Add baseline test for conflicting sanitizer library names
arichardson 09d7ac6
[compiler-rt][cmake] Correctly set architecture for purecap
arichardson 9a1a63a
[compiler-rt] Unbreak the MIPS purecap build
arichardson d4dda34
[sanitizer] Fix build on FreeBSD RISC-V
arichardson 6880e5d
[compiler-rt] Allow building the builtins for RISC-V purecap
arichardson 418cc82
sanitizer_linux_libcdep.cpp: reduce diff to upstream
arichardson 16ac532
[compiler-rt] Fix a few -Wcheri-provenance warnings
arichardson de6704f
[compiler-rt] Fix purecap RISC-V build
arichardson f5ac08e
[CHERI-RISC-V] Use suffixed sanitizer libraries for purecap
arichardson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// RUN: %riscv64_cheri_clang --sysroot=%S/Inputs/basic_cheribsd_libXXc_tree \ | ||
// RUN: -fsanitize=undefined %s -### 2>&1 | FileCheck --check-prefixes=UBSAN,UBSAN-RISCV64 %s | ||
// RUN: %riscv64_cheri_purecap_clang --sysroot=%S/Inputs/basic_cheribsd_libXXc_tree \ | ||
// RUN: -fsanitize=undefined %s -### 2>&1 | FileCheck --check-prefixes=UBSAN,UBSAN-PURECAP-RISCV64 %s | ||
// RUN: %riscv32_cheri_clang --sysroot=%S/Inputs/basic_cheribsd_libXXc_tree \ | ||
// RUN: -fsanitize=undefined %s -### 2>&1 | FileCheck --check-prefixes=UBSAN,UBSAN-RISCV32 %s | ||
// RUN: %riscv32_cheri_purecap_clang --sysroot=%S/Inputs/basic_cheribsd_libXXc_tree \ | ||
// RUN: -fsanitize=undefined %s -### 2>&1 | FileCheck --check-prefixes=UBSAN,UBSAN-PURECAP-RISCV32 %s | ||
// RUN: %cheri_clang --sysroot=%S/Inputs/basic_cheribsd_libXXc_tree \ | ||
// RUN: -fsanitize=undefined %s -### 2>&1 | FileCheck --check-prefixes=UBSAN,UBSAN-MIPS64 %s | ||
// RUN: %cheri_purecap_clang --sysroot=%S/Inputs/basic_cheribsd_libXXc_tree \ | ||
// RUN: -fsanitize=undefined %s -### 2>&1 | FileCheck --check-prefixes=UBSAN,UBSAN-PURECAP-MIPS64 %s | ||
|
||
// UBSAN: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" "-isysroot" | ||
// UBSAN-SAME: "-fsanitize=alignment,array-bounds, | ||
// UBSAN-SAME: "-fsanitize-recover=alignment,array-bounds, | ||
// UBSAN-NEXT: "/usr/bin/ld" | ||
// UBSAN-RISCV64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_standalone-riscv64.a" | ||
// UBSAN-PURECAP-RISCV64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_standalone-riscv64.a" | ||
// UBSAN-RISCV32-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_standalone-riscv32.a" | ||
// UBSAN-PURECAP-RISCV32-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_standalone-riscv32.a" | ||
// UBSAN-MIPS64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_standalone-mips64.a" | ||
// UBSAN-PURECAP-MIPS64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_standalone-mips64c128.a" | ||
|
||
// RUN: %riscv64_cheri_clang --sysroot=%S/Inputs/basic_cheribsd_libXXc_tree \ | ||
// RUN: -fsanitize=undefined -fsanitize-minimal-runtime %s -### 2>&1 | FileCheck --check-prefixes=UBSAN-MINIMAL,UBSAN-MINIMAL-RISCV64 %s | ||
// RUN: %riscv64_cheri_purecap_clang --sysroot=%S/Inputs/basic_cheribsd_libXXc_tree \ | ||
// RUN: -fsanitize=undefined -fsanitize-minimal-runtime %s -### 2>&1 | FileCheck --check-prefixes=UBSAN-MINIMAL,UBSAN-MINIMAL-PURECAP-RISCV64 %s | ||
// RUN: %riscv32_cheri_clang --sysroot=%S/Inputs/basic_cheribsd_libXXc_tree \ | ||
// RUN: -fsanitize=undefined -fsanitize-minimal-runtime %s -### 2>&1 | FileCheck --check-prefixes=UBSAN-MINIMAL,UBSAN-MINIMAL-RISCV32 %s | ||
// RUN: %riscv32_cheri_purecap_clang --sysroot=%S/Inputs/basic_cheribsd_libXXc_tree \ | ||
// RUN: -fsanitize=undefined -fsanitize-minimal-runtime %s -### 2>&1 | FileCheck --check-prefixes=UBSAN-MINIMAL,UBSAN-MINIMAL-PURECAP-RISCV32 %s | ||
// RUN: %cheri_clang --sysroot=%S/Inputs/basic_cheribsd_libXXc_tree \ | ||
// RUN: -fsanitize=undefined -fsanitize-minimal-runtime %s -### 2>&1 | FileCheck --check-prefixes=UBSAN-MINIMAL,UBSAN-MINIMAL-MIPS64 %s | ||
// RUN: %cheri_purecap_clang --sysroot=%S/Inputs/basic_cheribsd_libXXc_tree \ | ||
// RUN: -fsanitize=undefined -fsanitize-minimal-runtime %s -### 2>&1 | FileCheck --check-prefixes=UBSAN-MINIMAL,UBSAN-MINIMAL-PURECAP-MIPS64 %s | ||
|
||
// UBSAN-MINIMAL: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" "-isysroot" | ||
// UBSAN-MINIMAL-SAME: "-fsanitize=alignment,array-bounds, | ||
// UBSAN-MINIMAL-SAME: "-fsanitize-recover=alignment,array-bounds, | ||
// UBSAN-MINIMAL-NEXT: "/usr/bin/ld" | ||
// UBSAN-MINIMAL-RISCV64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_minimal-riscv64.a" | ||
// UBSAN-MINIMAL-PURECAP-RISCV64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_minimal-riscv64.a" | ||
// UBSAN-MINIMAL-RISCV32-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_minimal-riscv32.a" | ||
// UBSAN-MINIMAL-PURECAP-RISCV32-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_minimal-riscv32.a" | ||
// UBSAN-MINIMAL-MIPS64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_minimal-mips64.a" | ||
// UBSAN-MINIMAL-PURECAP-MIPS64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_minimal-mips64c128.a" | ||
|
||
// FIXME: fsanitize=fuzzer is not accepted for RISC-V | ||
// RUN: %cheri_clang --sysroot=%S/Inputs/basic_cheribsd_libXXc_tree \ | ||
// RUN: -fsanitize=fuzzer %s -### 2>&1 | FileCheck --check-prefixes=FUZZER,FUZZER-MIPS64 %s | ||
// RUN: %cheri_purecap_clang --sysroot=%S/Inputs/basic_cheribsd_libXXc_tree \ | ||
// RUN: -fsanitize=fuzzer %s -### 2>&1 | FileCheck --check-prefixes=FUZZER,FUZZER-PURECAP-MIPS64 %s | ||
|
||
|
||
// FUZZER: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" "-isysroot" | ||
// FUZZER-SAME: "-fsanitize-coverage | ||
// FUZZER-SAME: "-fsanitize=fuzzer,fuzzer-no-link" | ||
// FUZZER: "/usr/bin/ld" | ||
// FUZZER-MIPS64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.fuzzer-mips64.a" | ||
// FUZZER-MIPS64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_standalone-mips64.a" | ||
// FUZZER-PURECAP-MIPS64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.fuzzer-mips64c128.a" | ||
// FUZZER-PURECAP-MIPS64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_standalone-mips64c128.a" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,7 +167,7 @@ namespace __sanitizer { | |
#if !SANITIZER_S390 | ||
uptr internal_mmap(void *addr, usize length, int prot, int flags, int fd, | ||
u64 offset) { | ||
#ifdef __CHERI_PURE_CAPABILITY__ | ||
#if SANITIZER_FREEBSD && defined(__CHERI_PURE_CAPABILITY__) | ||
return (uptr)mmap(addr, length, prot, flags, fd, offset); | ||
#elif SANITIZER_FREEBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS | ||
return internal_syscall(SYSCALL(mmap), (uptr)addr, length, prot, flags, fd, | ||
|
@@ -193,11 +193,11 @@ uptr internal_mremap(void *old_address, usize old_size, usize new_size, int flag | |
} | ||
#endif | ||
|
||
int internal_mprotect(void *addr, uptr length, int prot) { | ||
int internal_mprotect(void *addr, usize length, int prot) { | ||
return internal_syscall(SYSCALL(mprotect), (uptr)addr, length, prot); | ||
} | ||
|
||
int internal_madvise(uptr addr, uptr length, int advice) { | ||
int internal_madvise(uptr addr, usize length, int advice) { | ||
return internal_syscall(SYSCALL(madvise), addr, length, advice); | ||
} | ||
|
||
|
@@ -1854,7 +1854,11 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const { | |
uint32_t op_code; | ||
|
||
# if SANITIZER_FREEBSD | ||
# ifdef __CHERI_PURE_CAPABILITY__ | ||
exception_source = (uint32_t *)ucontext->uc_mcontext.mc_cheriframe.cf_pcc; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Grr split register files |
||
# else | ||
exception_source = (uint32_t *)(uptr)ucontext->uc_mcontext.mc_pc; | ||
# endif | ||
# else | ||
exception_source = (uint32_t *)ucontext->uc_mcontext.pc; | ||
# endif | ||
|
@@ -2133,9 +2137,15 @@ static void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) { | |
#elif defined(__mips__) | ||
# if SANITIZER_FREEBSD | ||
ucontext_t *ucontext = (ucontext_t*)context; | ||
# ifdef __CHERI_PURE_CAPABILITY__ | ||
*pc = (uptr)ucontext->uc_mcontext.mc_cheriframe.cf_pcc; | ||
*bp = (uptr)ucontext->uc_mcontext.mc_cheriframe.cf_c24; | ||
*sp = (uptr)ucontext->uc_mcontext.mc_cheriframe.cf_csp; | ||
# else | ||
*pc = ucontext->uc_mcontext.mc_pc; | ||
*bp = ucontext->uc_mcontext.mc_regs[30]; | ||
*sp = ucontext->uc_mcontext.mc_regs[29]; | ||
# endif | ||
# else | ||
ucontext_t *ucontext = (ucontext_t*)context; | ||
*pc = ucontext->uc_mcontext.pc; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's wrong with internal_syscall? It returns uptr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason that didn't work, I really can't remember why. Will need to try again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it predates making length a usize, so the varargs nature of syscall(2) broke it?