[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
https://github.com/cjappl edited https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
dougsonos wrote: > Looking for weighing in on any of the code as it stands now, or the naming > question posed by MaskRay > [here](https://discourse.llvm.org/t/rfc-nolock-and-noalloc-attributes/76837/75), > so far there seems to be support for rtsan over radsan :) +1 for rtsan https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
cjappl wrote: Ping @yln @vitalybuka @Sirraide @AaronBallman @zygoloid @compnerd @petrhosek @isanbard @MaskRay https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
cjappl wrote: Weekly ping of reviewers @yln @vitalybuka @Sirraide @AaronBallman @zygoloid @compnerd @petrhosek @isanbard Looking for weighing in on any of the code as it stands now, or the naming question posed by MaskRay [here](https://discourse.llvm.org/t/rfc-nolock-and-noalloc-attributes/76837/75), so far there seems to be support for rtsan over radsan :) https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
MaskRay wrote: https://discourse.llvm.org/t/rfc-nolock-and-noalloc-attributes/76837/75 contains a discussion about the subproject name. Do you have opinions? @llvm/pr-subscribers-sanitizer @compnerd @petrhosek @isanbard https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
@@ -1382,6 +1382,10 @@ collectSanitizerRuntimes(const ToolChain , const ArgList , StaticRuntimes.push_back("asan_cxx"); } + if (!SanArgs.needsSharedRt() && SanArgs.needsRadsanRt()) { +StaticRuntimes.push_back("radsan"); + } cjappl wrote: Ok, if I can summarize the important bits in my own words: Different platforms have different defaults they use for the sanitizers, some (Darwin, for example) use shared, others (clang on Linux) use static. A user can specify and override the default with the flags `-[shared|static]-libsan`. To support the most possible configurations, do you think we should add back in the ability to link the shared library in this file? In Darwin.cpp we already show the ability to link the shared runtime, so it seemingly would be as simple as adding in a: ``` if (SanArgs.needsRadsanRt()) SharedRuntimes.push_back("radsan"); ``` To the block above. Any advice? https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
@@ -0,0 +1,106 @@ +//===--- radsan_context.cpp - Realtime Sanitizer --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +//===--===// + +#include + +#include + +#include +#include + +#include +#include +#include +#include + +using namespace __sanitizer; + +namespace detail { + +static pthread_key_t Key; cjappl wrote: I pushed the change for all non-lambda variable names, happy to change the lambdas too based on your feedback. https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
@@ -0,0 +1,106 @@ +//===--- radsan_context.cpp - Realtime Sanitizer --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +//===--===// + +#include + +#include + +#include +#include + +#include +#include +#include +#include + +using namespace __sanitizer; + +namespace detail { + +static pthread_key_t Key; cjappl wrote: No apology necessary! Happy to do this right the first time. Does this also apply to lambdas? ``` auto Func = []() { vec.push_back(0.4f); }; ``` Should this become: ``` auto func = []() { vec.push_back(0.4f); }; ``` Or remain "function case"? https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
@@ -0,0 +1,106 @@ +//===--- radsan_context.cpp - Realtime Sanitizer --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +//===--===// + +#include + +#include + +#include +#include + +#include +#include +#include +#include + +using namespace __sanitizer; + +namespace detail { + +static pthread_key_t Key; MaskRay wrote: Yes, `variable_name` and `FunctionName`.. Sorry if this change may take a while. asan/hwasan/lsan are good examples to follow. https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
@@ -0,0 +1,106 @@ +//===--- radsan_context.cpp - Realtime Sanitizer --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +//===--===// + +#include + +#include + +#include +#include + +#include +#include +#include +#include + +using namespace __sanitizer; + +namespace detail { + +static pthread_key_t Key; cjappl wrote: Great thanks!! Before I go through and edit these, `snake_case` is preferred for variables in all contexts? Really appreciate the review. Pushing up most of your requested changes now. https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
@@ -0,0 +1,71 @@ +# -*- Python -*- + +import os + +# Setup config name. +config.name = "RADSAN" + config.name_suffix + +# Setup source root. +config.test_source_root = os.path.dirname(__file__) cjappl wrote: Yes, the lit tests may be placed directly in `compiler-rt/test/radsan/` and they run as intended. Just checked on our branch that has them implemented. https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
@@ -0,0 +1,71 @@ +# -*- Python -*- + +import os + +# Setup config name. +config.name = "RADSAN" + config.name_suffix + +# Setup source root. +config.test_source_root = os.path.dirname(__file__) MaskRay wrote: `msan`, `lsan`, `gwp_asan` places lit tests directly under the directory, while some use `TestCases/`. Avoiding `TestCases` is preferred. Is the lit set up to avoid `TestCases`? https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
@@ -0,0 +1,413 @@ +//===--- radsan_interceptors.cpp - Realtime Sanitizer --*- C++ +//-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +//===--===// + +#include "radsan/radsan_interceptors.h" + +#include "sanitizer_common/sanitizer_platform.h" +#include "sanitizer_common/sanitizer_platform_interceptors.h" + +#include "interception/interception.h" +#include "radsan/radsan_context.h" + +#if !SANITIZER_LINUX && !SANITIZER_APPLE +#error Sorry, radsan does not yet support this platform +#endif + +#if SANITIZER_APPLE +#include +#include +#endif + +#if SANITIZER_INTERCEPT_MEMALIGN || SANITIZER_INTERCEPT_PVALLOC +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +using namespace __sanitizer; + +namespace radsan { +void ExpectNotRealtime(const char *InterceptedFunctionName) { + GetContextForThisThread().ExpectNotRealtime(InterceptedFunctionName); +} +} // namespace radsan + +/* MaskRay wrote: Avoid `/*` in C++ files https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
@@ -0,0 +1,38 @@ +//===--- radsan_context.h - Realtime Sanitizer --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +//===--===// + +#pragma once + +namespace radsan { MaskRay wrote: `__radsan` to avoid conflicts with user programs https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
@@ -0,0 +1,52 @@ +//===--- radsan_stack.cpp - Realtime Sanitizer --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +//===--===// + +#include +#include + +using namespace __sanitizer; + +// We must define our own implementation of this method for our runtime. +// This one is just copied from UBSan. + +namespace __sanitizer { +void BufferedStackTrace::UnwindImpl(uptr pc, uptr bp, void *context, +bool request_fast, u32 max_depth) { + uptr top = 0; + uptr bottom = 0; + GetThreadStackTopAndBottom(false, , ); + bool fast = StackTrace::WillUseFastUnwind(request_fast); + Unwind(max_depth, pc, bp, context, top, bottom, fast); +} +} // namespace __sanitizer + +namespace { +void SetGlobalStackTraceFormat() { + SetCommonFlagsDefaults(); + CommonFlags cf; + cf.CopyFrom(*common_flags()); + cf.stack_trace_format = "DEFAULT"; + cf.external_symbolizer_path = GetEnv("RADSAN_SYMBOLIZER_PATH"); + OverrideCommonFlags(cf); +} +} // namespace + +namespace radsan { +void PrintStackTrace() { MaskRay wrote: https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions `void radsan::PrintStackTrace` https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
@@ -0,0 +1,106 @@ +//===--- radsan_context.cpp - Realtime Sanitizer --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +//===--===// + +#include + +#include + +#include +#include + +#include +#include +#include +#include + +using namespace __sanitizer; + +namespace detail { + +static pthread_key_t Key; MaskRay wrote: Avoid `VariableName` in new compiler-rt code. Use the recommended `variable_name` like asan/hwasan/lsan. Some new compiler-rt subprojects used `Variable` as cargo culting llvm/ and clang/, which is a pity (you can also read https://llvm.org/docs/Proposals/VariableNames.html for more history) https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
@@ -0,0 +1,50 @@ +//===--- radsan.h - Realtime Sanitizer --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +//===--===// + +#pragma once + +#include "sanitizer_common/sanitizer_internal_defs.h" + +extern "C" { + +/** Initialise radsan interceptors. + + A call to this method is added to the preinit array on Linux systems. +*/ +SANITIZER_INTERFACE_ATTRIBUTE void radsan_init(); + +/** Enter real-time context. + + When in a real-time context, RADSan interceptors will error if realtime + violations are detected. Calls to this method are injected at the code + generation stage when RADSan is enabled. +*/ +SANITIZER_INTERFACE_ATTRIBUTE void radsan_realtime_enter(); MaskRay wrote: Use `__*` names to avoid conflicts with user code. Use `//`. If there are user APIs, define them at `include/sanitizer/*_interface.h` https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
@@ -0,0 +1,52 @@ +//===--- radsan_stack.cpp - Realtime Sanitizer --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +//===--===// + +#include +#include + +using namespace __sanitizer; + +// We must define our own implementation of this method for our runtime. +// This one is just copied from UBSan. + +namespace __sanitizer { +void BufferedStackTrace::UnwindImpl(uptr pc, uptr bp, void *context, +bool request_fast, u32 max_depth) { + uptr top = 0; + uptr bottom = 0; + GetThreadStackTopAndBottom(false, , ); + bool fast = StackTrace::WillUseFastUnwind(request_fast); + Unwind(max_depth, pc, bp, context, top, bottom, fast); +} +} // namespace __sanitizer + +namespace { +void SetGlobalStackTraceFormat() { MaskRay wrote: https://llvm.org/docs/CodingStandards.html#anonymous-namespaces https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
@@ -0,0 +1,71 @@ +# -*- Python -*- MaskRay wrote: Delete Some older `lit.cfg.py` files might use this because previously they were named `lit.cfg` https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
@@ -1382,6 +1382,10 @@ collectSanitizerRuntimes(const ToolChain , const ArgList , StaticRuntimes.push_back("asan_cxx"); } + if (!SanArgs.needsSharedRt() && SanArgs.needsRadsanRt()) { +StaticRuntimes.push_back("radsan"); + } MaskRay wrote: I have some notes at https://maskray.me/blog/2023-01-08-all-about-sanitizer-interceptors#static-runtime Nit: we omit braces in this single-line statement case https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
https://github.com/cjappl edited https://github.com/llvm/llvm-project/pull/92460 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits