[llvm-branch-commits] [llvm] [libc] [flang] [clang-tools-extra] [compiler-rt] [clang] [OptTable] Make new lines in help text respect indentation (PR #74880)
https://github.com/jh7370 edited https://github.com/llvm/llvm-project/pull/74880 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [clang-tools-extra] [libc] [llvm] [flang] [clang] [OptTable] Make new lines in help text respect indentation (PR #74880)
@@ -1,16 +1,16 @@ ; RUN: llvm-cvtres /h > %t -; RUN: FileCheck -input-file=%t %s -check-prefix=HELP_TEST +; RUN: FileCheck -input-file=%t %s --strict-whitespace -check-prefix=HELP_TEST -; HELP_TEST: OVERVIEW: Resource Converter -; HELP_TEST-DAG: USAGE: llvm-cvtres [options] file... -; HELP_TEST-DAG: OPTIONS: -; HELP_TEST-NEXT: /{{DEFINE}}:symbol - Not implemented -; HELP_TEST-NEXT: /FOLDDUPS: - Not implemented -; HELP_TEST-NEXT: /HELP - Display available options +; HELP_TEST: OVERVIEW: Resource Converter +; HELP_TEST-DAG: USAGE: llvm-cvtres [options] file... +; HELP_TEST-DAG: OPTIONS: +; HELP_TEST-NEXT: /{{DEFINE}}:symbol - Not implemented jh7370 wrote: The formatting in this line looks wrong? It looks to me like there might be a bug here (possibly predating your PR). https://github.com/llvm/llvm-project/pull/74880 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [llvm] [clang-tools-extra] [clang] [compiler-rt] [libc] [OptTable] Make new lines in help text respect indentation (PR #74880)
https://github.com/jh7370 commented: > > Is the main functionality of this test actually tested in the current > > patch? It doesn't seem to be to me. > I don't fully understand your comment, I am working on getting some of the > test to be whitespace strict to specifically test the functionality. I just didn't see any testing like you've now added in OptionParsingTest.cpp that showed that the indentation was working correctly as desired. Taking a step back, I'm not sure the addition of the dash has anything to do with the main purpose of this PR, and I'm a little worried people will not spot that this PR is adding it. I personally have no issue with that part of the change, but I wonder if others wouldn't want it? https://github.com/llvm/llvm-project/pull/74880 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [libc] [clang-tools-extra] [compiler-rt] [clang] [llvm] [OptTable] Make new lines in help text respect indentation (PR #74880)
@@ -1,16 +1,16 @@ ; RUN: llvm-cvtres /h > %t -; RUN: FileCheck -input-file=%t %s -check-prefix=HELP_TEST +; RUN: FileCheck -input-file=%t %s --strict-whitespace -check-prefix=HELP_TEST -; HELP_TEST: OVERVIEW: Resource Converter -; HELP_TEST-DAG: USAGE: llvm-cvtres [options] file... -; HELP_TEST-DAG: OPTIONS: -; HELP_TEST-NEXT: /{{DEFINE}}:symbol - Not implemented -; HELP_TEST-NEXT: /FOLDDUPS: - Not implemented -; HELP_TEST-NEXT: /HELP - Display available options +; HELP_TEST: OVERVIEW: Resource Converter +; HELP_TEST-DAG: USAGE: llvm-cvtres [options] file... +; HELP_TEST-DAG: OPTIONS: +; HELP_TEST-NEXT: /{{DEFINE}}:symbol - Not implemented avillega wrote: This is a quirk of FileCheck. It thinks that `DEFINE` is a directive, so in order to match the `DEFINE` word it is necessary to make it a regex. FileCheck will ignore `{{}}` and that is why it doesn't look at the same indentation level as the rest of the options, but it is. https://github.com/llvm/llvm-project/pull/74880 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [llvm] [compiler-rt] [clang] [libc] [clang-tools-extra] [OptTable] Make new lines in help text respect indentation (PR #74880)
https://github.com/avillega edited https://github.com/llvm/llvm-project/pull/74880 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [compiler-rt] [clang-tools-extra] [flang] [libc] [OptTable] Make new lines in help text respect indentation (PR #74880)
MaskRay wrote: > Note the "-" at the beginning of the help text in the new version, > it was added to clearly separate the HelpText of the different > options. > Taking a step back, I'm not sure the addition of the dash has anything to do > with the main purpose of this PR, and I'm a little worried people will not > spot that this PR is adding it. I personally have no issue with that part of > the change, but I wonder if others wouldn't want it? I think `-` in `--help` messages is (very) uncommon. Many programs (`cat, node, gcc, as, 7z, ...`) don't use `-`. https://github.com/llvm/llvm-project/pull/74880 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [compiler-rt] [clang] [libc] [flang] [clang-tools-extra] [OptTable] Make new lines in help text respect indentation (PR #74880)
avillega wrote: > > Note the "-" at the beginning of the help text in the new version, > > it was added to clearly separate the HelpText of the different > > options. > > > Taking a step back, I'm not sure the addition of the dash has anything to > > do with the main purpose of this PR, and I'm a little worried people will > > not spot that this PR is adding it. I personally have no issue with that > > part of the change, but I wonder if others wouldn't want it? > > I think `-` in `--help` messages is (very) uncommon. Many programs (`cat, > node, gcc, as, 7z, ...`) don't use `-`. I will remove it. But I added it for two reasons: - I wanted a way to clearly spot the beginning of the help text of an option given that new lines will be indented at the same level as the first line of the help text, it is more difficult to clearly see the start and end of the help text for an specific option. - The help text generated by llvm::cl uses the `- ` to separate the help text of each option so I was trying to do something similar to what many llvm tools still do. https://github.com/llvm/llvm-project/pull/74880 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [compiler-rt] [lldb] [clang] [lld] [libc] [libcxx] [flang] [clang-tools-extra] [OptTable] Make new lines in help text respect indentation (PR #74880)
https://github.com/avillega updated https://github.com/llvm/llvm-project/pull/74880 >From 61fd524086abe13b6ed0a792a0e5ed29ba8fc692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Villegas?= Date: Tue, 12 Dec 2023 00:10:48 + Subject: [PATCH] Fix flang help tests. Created using spr 1.3.4 --- flang/test/Driver/driver-help-hidden.f90 | 226 ++-- flang/test/Driver/driver-help.f90| 434 +++ 2 files changed, 330 insertions(+), 330 deletions(-) diff --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90 index 9a11a7a571ffcc..ca114320d13d72 100644 --- a/flang/test/Driver/driver-help-hidden.f90 +++ b/flang/test/Driver/driver-help-hidden.f90 @@ -14,143 +14,143 @@ ! CHECK:USAGE: flang-new ! CHECK-EMPTY: ! CHECK-NEXT: DRIVER OPTIONS: -! CHECK-NEXT: --driver-mode= Set the driver mode to either 'gcc', 'g++', 'cpp', 'cl' or 'flang' +! CHECK-NEXT: --driver-mode= - Set the driver mode to either 'gcc', 'g++', 'cpp', 'cl' or 'flang' ! CHECK-EMPTY: ! CHECK-NEXT:OPTIONS: -! CHECK-NEXT: -###Print (but do not run) the commands to run for this compilation -! CHECK-NEXT: -ccc-print-phases Dump list of actions to perform -! CHECK-NEXT: -cppEnable predefined and command line preprocessor macros -! CHECK-NEXT: -c Only run preprocess, compile, and assemble steps -! CHECK-NEXT: -dumpmachineDisplay the compiler's target processor -! CHECK-NEXT: -dumpversionDisplay the version of the compiler -! CHECK-NEXT: -D = Define to (or 1 if omitted) -! CHECK-NEXT: -emit-llvm Use the LLVM representation for assembler and object files -! CHECK-NEXT: -E Only run the preprocessor +! CHECK-NEXT: -###- Print (but do not run) the commands to run for this compilation +! CHECK-NEXT: -ccc-print-phases - Dump list of actions to perform +! CHECK-NEXT: -cpp- Enable predefined and command line preprocessor macros +! CHECK-NEXT: -c - Only run preprocess, compile, and assemble steps +! CHECK-NEXT: -dumpmachine- Display the compiler's target processor +! CHECK-NEXT: -dumpversion- Display the version of the compiler +! CHECK-NEXT: -D = - Define to (or 1 if omitted) +! CHECK-NEXT: -emit-llvm - Use the LLVM representation for assembler and object files +! CHECK-NEXT: -E - Only run the preprocessor ! CHECK-NEXT: -falternative-parameter-statement -! CHECK-NEXT: Enable the old style PARAMETER statement -! CHECK-NEXT: -fapprox-func Allow certain math function calls to be replaced with an approximately equivalent calculation -! CHECK-NEXT: -fbackslash Specify that backslash in string introduces an escape character -! CHECK-NEXT: -fcolor-diagnostics Enable colors in diagnostics -! CHECK-NEXT: -fconvert= Set endian conversion of data for unformatted files -! CHECK-NEXT: -fdefault-double-8 Set the default double precision kind to an 8 byte wide type -! CHECK-NEXT: -fdefault-integer-8 Set the default integer and logical kind to an 8 byte wide type -! CHECK-NEXT: -fdefault-real-8Set the default real kind to an 8 byte wide type -! CHECK-NEXT: -ffast-math Allow aggressive, lossy floating-point optimizations -! CHECK-NEXT: -ffixed-formProcess source files in fixed form +! CHECK-NEXT: - Enable the old style PARAMETER statement +! CHECK-NEXT: -fapprox-func - Allow certain math function calls to be replaced with an approximately equivalent calculation +! CHECK-NEXT: -fbackslash - Specify that backslash in string introduces an escape character +! CHECK-NEXT: -fcolor-diagnostics - Enable colors in diagnostics +! CHECK-NEXT: -fconvert= - Set endian conversion of data for unformatted files +! CHECK-NEXT: -fdefault-double-8 - Set the default double precision kind to an 8 byte wide type +! CHECK-NEXT: -fdefault-integer-8 - Set the default integer and logical kind to an 8 byte wide type +! CHECK-NEXT: -fdefault-real-8- Set the default real kind to an 8 byte wide type +! CHECK-NEXT: -ffast-math - Allow aggressive, lossy floating-point optimizations +! CHECK-NEXT: -ffixed-form- Process source files in fixed form ! CHECK-NEXT: -ffixed-line-length= -! CHECK-NEXT: Use as character line width in fixed mode -! CHECK-NEXT: -ffp-contract= Form fused FP ops (e.g. FMAs) -! CHECK-NEXT: -ffree-form Process source files in free form -! CHECK-NEXT: -fhonor-infinities Specify that floating-point optimizations are not allowed that assume arguments and results are not +-inf. -! CHECK-NEXT: -fhonor-nansSpecify that floating-point optimizations are not allowed that assume arg
[llvm-branch-commits] [clang-tools-extra] [clang] [lld] [lldb] [llvm] [compiler-rt] [libc] [libcxx] [flang] [OptTable] Make new lines in help text respect indentation (PR #74880)
https://github.com/avillega updated https://github.com/llvm/llvm-project/pull/74880 >From 61fd524086abe13b6ed0a792a0e5ed29ba8fc692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Villegas?= Date: Tue, 12 Dec 2023 00:10:48 + Subject: [PATCH] Fix flang help tests. Created using spr 1.3.4 --- flang/test/Driver/driver-help-hidden.f90 | 226 ++-- flang/test/Driver/driver-help.f90| 434 +++ 2 files changed, 330 insertions(+), 330 deletions(-) diff --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90 index 9a11a7a571ffcc..ca114320d13d72 100644 --- a/flang/test/Driver/driver-help-hidden.f90 +++ b/flang/test/Driver/driver-help-hidden.f90 @@ -14,143 +14,143 @@ ! CHECK:USAGE: flang-new ! CHECK-EMPTY: ! CHECK-NEXT: DRIVER OPTIONS: -! CHECK-NEXT: --driver-mode= Set the driver mode to either 'gcc', 'g++', 'cpp', 'cl' or 'flang' +! CHECK-NEXT: --driver-mode= - Set the driver mode to either 'gcc', 'g++', 'cpp', 'cl' or 'flang' ! CHECK-EMPTY: ! CHECK-NEXT:OPTIONS: -! CHECK-NEXT: -###Print (but do not run) the commands to run for this compilation -! CHECK-NEXT: -ccc-print-phases Dump list of actions to perform -! CHECK-NEXT: -cppEnable predefined and command line preprocessor macros -! CHECK-NEXT: -c Only run preprocess, compile, and assemble steps -! CHECK-NEXT: -dumpmachineDisplay the compiler's target processor -! CHECK-NEXT: -dumpversionDisplay the version of the compiler -! CHECK-NEXT: -D = Define to (or 1 if omitted) -! CHECK-NEXT: -emit-llvm Use the LLVM representation for assembler and object files -! CHECK-NEXT: -E Only run the preprocessor +! CHECK-NEXT: -###- Print (but do not run) the commands to run for this compilation +! CHECK-NEXT: -ccc-print-phases - Dump list of actions to perform +! CHECK-NEXT: -cpp- Enable predefined and command line preprocessor macros +! CHECK-NEXT: -c - Only run preprocess, compile, and assemble steps +! CHECK-NEXT: -dumpmachine- Display the compiler's target processor +! CHECK-NEXT: -dumpversion- Display the version of the compiler +! CHECK-NEXT: -D = - Define to (or 1 if omitted) +! CHECK-NEXT: -emit-llvm - Use the LLVM representation for assembler and object files +! CHECK-NEXT: -E - Only run the preprocessor ! CHECK-NEXT: -falternative-parameter-statement -! CHECK-NEXT: Enable the old style PARAMETER statement -! CHECK-NEXT: -fapprox-func Allow certain math function calls to be replaced with an approximately equivalent calculation -! CHECK-NEXT: -fbackslash Specify that backslash in string introduces an escape character -! CHECK-NEXT: -fcolor-diagnostics Enable colors in diagnostics -! CHECK-NEXT: -fconvert= Set endian conversion of data for unformatted files -! CHECK-NEXT: -fdefault-double-8 Set the default double precision kind to an 8 byte wide type -! CHECK-NEXT: -fdefault-integer-8 Set the default integer and logical kind to an 8 byte wide type -! CHECK-NEXT: -fdefault-real-8Set the default real kind to an 8 byte wide type -! CHECK-NEXT: -ffast-math Allow aggressive, lossy floating-point optimizations -! CHECK-NEXT: -ffixed-formProcess source files in fixed form +! CHECK-NEXT: - Enable the old style PARAMETER statement +! CHECK-NEXT: -fapprox-func - Allow certain math function calls to be replaced with an approximately equivalent calculation +! CHECK-NEXT: -fbackslash - Specify that backslash in string introduces an escape character +! CHECK-NEXT: -fcolor-diagnostics - Enable colors in diagnostics +! CHECK-NEXT: -fconvert= - Set endian conversion of data for unformatted files +! CHECK-NEXT: -fdefault-double-8 - Set the default double precision kind to an 8 byte wide type +! CHECK-NEXT: -fdefault-integer-8 - Set the default integer and logical kind to an 8 byte wide type +! CHECK-NEXT: -fdefault-real-8- Set the default real kind to an 8 byte wide type +! CHECK-NEXT: -ffast-math - Allow aggressive, lossy floating-point optimizations +! CHECK-NEXT: -ffixed-form- Process source files in fixed form ! CHECK-NEXT: -ffixed-line-length= -! CHECK-NEXT: Use as character line width in fixed mode -! CHECK-NEXT: -ffp-contract= Form fused FP ops (e.g. FMAs) -! CHECK-NEXT: -ffree-form Process source files in free form -! CHECK-NEXT: -fhonor-infinities Specify that floating-point optimizations are not allowed that assume arguments and results are not +-inf. -! CHECK-NEXT: -fhonor-nansSpecify that floating-point optimizations are not allowed that assume arg
[llvm-branch-commits] [llvm] [compiler-rt] [lldb] [clang] [lld] [libc] [libcxx] [flang] [clang-tools-extra] [OptTable] Make new lines in help text respect indentation (PR #74880)
https://github.com/avillega edited https://github.com/llvm/llvm-project/pull/74880 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [LivePhysRegs] Add callee-saved regs from MFI in addLiveOutsNoPristines. (PR #73553)
efriedma-quic wrote: > After PEI the liveness of LR needs to be accurately reflected and tail calls > could (should?) always "use" LR. That would either prevent outlining or cause > the outliner to preserve LR across introduced calls. I'll elaborate on this a bit. I think long-term, the way we want to model this is that pre-PEI, LR is treated as if it were a callee-save register. (Nothing outside the prologue/epilogue should interact with the return address directly except for a few special cases like __builtin_return_address.) Then PEI marks the LR use on the relevant "return" instructions, and post-PEI it's not callee-save anymore. I think that correctly models the underlying weirdness: at a machine level, the return address is basically just an argument to the function, but it's special to PEI because of the interaction with the frame layout/exception handling/pop instructions/etc. Stuff before PEI doesn't need to be aware it's an argument, and stuff after PEI can just treat it as a normal register. > On the caller side, the call instruction clobbers LR, so it can't really be > considered live-out Correct, it's not really live-out. --- Short-term, can we make this fix a bit more targeted? The point of the "isRestored" bit is that it's supposed to avoid marking liveness when the function ends in a "pop pc". The relevant code is ARMFrameLowering::emitPopInst: it calls `Info.setRestored(false);` to do precisely this. But it's triggering in a case where it shouldn't. I think the problem is that the code isn't accounting for the possibility that there are other paths that return from the function. https://github.com/llvm/llvm-project/pull/73553 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [LivePhysRegs] Add callee-saved regs from MFI in addLiveOutsNoPristines. (PR #73553)
efriedma-quic wrote: Just looked at https://gist.github.com/fhahn/67937125b64440a8a414909c4a1b7973 ; that seems roughly appropriate. It's a little ugly to set the bit to false, then set it back to true, though; I'd rather just explicitly check whether all return instructions are LDMIA_RET/t2LDMIA_RET/tPOP_RET. https://github.com/llvm/llvm-project/pull/73553 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [test][sanitizer] Allow fork_threaded test on Msan, Tsan (PR #75260)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/75260 They already include workarounds. ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [test][sanitizer] Allow fork_threaded test on Msan, Tsan (PR #75260)
llvmbot wrote: @llvm/pr-subscribers-compiler-rt-sanitizer Author: Vitaly Buka (vitalybuka) Changes They already include workarounds. --- Full diff: https://github.com/llvm/llvm-project/pull/75260.diff 1 Files Affected: - (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp (+1-1) ``diff diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp index 2264c55816638..72a2f78a5a3e7 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp +++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp @@ -1,6 +1,6 @@ // RUN: %clangxx -O0 %s -o %t && %env_tool_opts=die_after_fork=0 %run %t -// UNSUPPORTED: * +// UNSUPPORTED: asan, lsan, hwasan // Forking in multithread environment is unsupported. However we already have // some workarounds, and will add more, so this is the test. `` https://github.com/llvm/llvm-project/pull/75260 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [test][sanitizer] Allow fork_threaded test on Msan, Tsan (PR #75260)
@@ -1,6 +1,6 @@ // RUN: %clangxx -O0 %s -o %t && %env_tool_opts=die_after_fork=0 %run %t -// UNSUPPORTED: * +// UNSUPPORTED: asan, lsan, hwasan thurstond wrote: This would also enable the test for ubsan, which is not mentioned in the title https://github.com/llvm/llvm-project/pull/75260 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [test][sanitizer] Allow fork_threaded test on Msan, Tsan (PR #75260)
https://github.com/thurstond approved this pull request. https://github.com/llvm/llvm-project/pull/75260 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [test][sanitizer] Allow fork_threaded test on Msan, Tsan (PR #75260)
https://github.com/thurstond edited https://github.com/llvm/llvm-project/pull/75260 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [hwasan] Add `__hwasan_get_tag_from_pointer` (PR #75267)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/75267 This simplifies handling tags by user code. Now code does not need to know bit size of tag and its position. ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [hwasan] Add `__hwasan_get_tag_from_pointer` (PR #75267)
llvmbot wrote: @llvm/pr-subscribers-compiler-rt-sanitizer Author: Vitaly Buka (vitalybuka) Changes This simplifies handling tags by user code. Now code does not need to know bit size of tag and its position. --- Full diff: https://github.com/llvm/llvm-project/pull/75267.diff 6 Files Affected: - (modified) compiler-rt/include/sanitizer/hwasan_interface.h (+4) - (modified) compiler-rt/lib/hwasan/hwasan.cpp (+2) - (modified) compiler-rt/lib/hwasan/hwasan.h (+3-3) - (modified) compiler-rt/lib/hwasan/hwasan_interface_internal.h (+3) - (added) compiler-rt/test/hwasan/TestCases/tag-ptr.cpp (+24) - (modified) compiler-rt/test/sanitizer_common/sanitizer_specific.h (+13) ``diff diff --git a/compiler-rt/include/sanitizer/hwasan_interface.h b/compiler-rt/include/sanitizer/hwasan_interface.h index abe310c0666948..407f488a24a617 100644 --- a/compiler-rt/include/sanitizer/hwasan_interface.h +++ b/compiler-rt/include/sanitizer/hwasan_interface.h @@ -44,6 +44,10 @@ void SANITIZER_CDECL __hwasan_tag_memory(const volatile void *p, void *SANITIZER_CDECL __hwasan_tag_pointer(const volatile void *p, unsigned char tag); +/// Get tag from the pointer. +unsigned char SANITIZER_CDECL +__hwasan_get_tag_from_pointer(const volatile void *p); + // Set memory tag from the current SP address to the given address to zero. // This is meant to annotate longjmp and other non-local jumps. // This function needs to know the (almost) exact destination frame address; diff --git a/compiler-rt/lib/hwasan/hwasan.cpp b/compiler-rt/lib/hwasan/hwasan.cpp index 2f6cb10caf1be6..52780becbdb264 100644 --- a/compiler-rt/lib/hwasan/hwasan.cpp +++ b/compiler-rt/lib/hwasan/hwasan.cpp @@ -678,6 +678,8 @@ uptr __hwasan_tag_pointer(uptr p, u8 tag) { return AddTagToPointer(p, tag); } +u8 __hwasan_get_tag_from_pointer(uptr p) { return GetTagFromPointer(p); } + void __hwasan_handle_longjmp(const void *sp_dst) { uptr dst = (uptr)sp_dst; // HWASan does not support tagged SP. diff --git a/compiler-rt/lib/hwasan/hwasan.h b/compiler-rt/lib/hwasan/hwasan.h index 37ef4822285110..df21375e81671f 100644 --- a/compiler-rt/lib/hwasan/hwasan.h +++ b/compiler-rt/lib/hwasan/hwasan.h @@ -104,9 +104,9 @@ static inline void *UntagPtr(const void *tagged_ptr) { } static inline uptr AddTagToPointer(uptr p, tag_t tag) { - return InTaggableRegion(p) - ? ((p & ~kAddressTagMask) | ((uptr)tag << kAddressTagShift)) - : p; + return InTaggableRegion(p) ? ((p & ~kAddressTagMask) | +((uptr)(tag & kTagMask) << kAddressTagShift)) + : p; } namespace __hwasan { diff --git a/compiler-rt/lib/hwasan/hwasan_interface_internal.h b/compiler-rt/lib/hwasan/hwasan_interface_internal.h index e7804cc4903343..8f2f77dad917d2 100644 --- a/compiler-rt/lib/hwasan/hwasan_interface_internal.h +++ b/compiler-rt/lib/hwasan/hwasan_interface_internal.h @@ -160,6 +160,9 @@ void __hwasan_tag_memory(uptr p, u8 tag, uptr sz); SANITIZER_INTERFACE_ATTRIBUTE uptr __hwasan_tag_pointer(uptr p, u8 tag); +SANITIZER_INTERFACE_ATTRIBUTE +u8 __hwasan_get_tag_from_pointer(uptr p); + SANITIZER_INTERFACE_ATTRIBUTE void __hwasan_tag_mismatch(uptr addr, u8 ts); diff --git a/compiler-rt/test/hwasan/TestCases/tag-ptr.cpp b/compiler-rt/test/hwasan/TestCases/tag-ptr.cpp new file mode 100644 index 00..2f00e7913bb155 --- /dev/null +++ b/compiler-rt/test/hwasan/TestCases/tag-ptr.cpp @@ -0,0 +1,24 @@ +// RUN: %clangxx_hwasan -O0 %s -o %t && %run %t + +#include +#include +#include +#include +#include + +int main() { + auto p = std::make_unique(); + std::set ptrs; + for (unsigned i = 0;; ++i) { +void *ptr = __hwasan_tag_pointer(p.get(), i); +if (!ptrs.insert(ptr).second) + break; +fprintf(stderr, "%p, %u, %u\n", ptr, i, __hwasan_get_tag_from_pointer(ptr)); +assert(__hwasan_get_tag_from_pointer(ptr) == i); + } +#ifdef __x86_64__ + assert(ptrs.size() == 8); +#else + assert(ptrs.size() == 256); +#endif +} diff --git a/compiler-rt/test/sanitizer_common/sanitizer_specific.h b/compiler-rt/test/sanitizer_common/sanitizer_specific.h index 963d91cb305f60..ceb7d72d12dd98 100644 --- a/compiler-rt/test/sanitizer_common/sanitizer_specific.h +++ b/compiler-rt/test/sanitizer_common/sanitizer_specific.h @@ -31,6 +31,19 @@ static void make_mem_good(void *p, size_t s) { static void make_mem_bad(void *p, size_t s) { __asan_poison_memory_region(p, s); } +#elif __has_feature(hwaddress_sanitizer) +# include +# include +static void check_mem_is_good(void *p, size_t s) { + if (__hwasan_test_shadow(p, s) != -1) +abort(); +} +static void make_mem_good(void *p, size_t s) { + __hwasan_tag_memory(p, __hwasan_get_tag_from_pointer(p), s); +} +static void make_mem_bad(void *p, size_t s) { + __hwasan_tag_memory(p, ~__hwasan_get_tag_from_pointer(p), s); +} #else static void check_mem_is_good(void *p, size_t s) {} static vo
[llvm-branch-commits] [compiler-rt] [hwasan] Add `__hwasan_get_tag_from_pointer` (PR #75267)
fmayer wrote: Confused by this change. Why is this needed in this CL? If this is one of the purposes of the change, mention in the commit message. https://github.com/llvm/llvm-project/pull/75267 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] [compiler-rt] [mlir] [llvm] [test][sanitizer] Allow fork_threaded test on Msan, Tsan (PR #75260)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75260 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [llvm] [compiler-rt] [lldb] [test][sanitizer] Allow fork_threaded test on Msan, Tsan (PR #75260)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75260 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] [llvm] [compiler-rt] [mlir] [hwasan] Add `__hwasan_get_tag_from_pointer` (PR #75267)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75267 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [mlir] [llvm] [lldb] [hwasan] Add `__hwasan_get_tag_from_pointer` (PR #75267)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75267 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] [llvm] [compiler-rt] [mlir] [test][sanitizer] Allow fork_threaded test on Msan, Tsan (PR #75260)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75260 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [mlir] [llvm] [lldb] [test][sanitizer] Allow fork_threaded test on Msan, Tsan (PR #75260)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75260 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [llvm] [compiler-rt] [lldb] [hwasan] Add `__hwasan_get_tag_from_pointer` (PR #75267)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75267 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] [compiler-rt] [mlir] [llvm] [hwasan] Add `__hwasan_get_tag_from_pointer` (PR #75267)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75267 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [llvm] [compiler-rt] [lldb] [test][sanitizer] Allow fork_threaded test on Msan, Tsan (PR #75260)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75260 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [mlir] [llvm] [lldb] [hwasan] Add `__hwasan_get_tag_from_pointer` (PR #75267)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75267 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] [llvm] [compiler-rt] [mlir] [test][sanitizer] Allow fork_threaded test on Msan, Tsan (PR #75260)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75260 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] [compiler-rt] [mlir] [llvm] [hwasan] Add `__hwasan_get_tag_from_pointer` (PR #75267)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75267 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lldb] [llvm] [mlir] [compiler-rt] [test][sanitizer] Allow fork_threaded test on Msan, Tsan (PR #75260)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75260 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [llvm] [lldb] [compiler-rt] [test][sanitizer] Allow fork_threaded test on Msan, Tsan (PR #75260)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75260 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [clang] [lldb] [compiler-rt] [llvm] [test][sanitizer] Allow fork_threaded test on Msan, Tsan (PR #75260)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75260 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [clang] [compiler-rt] [lldb] [llvm] [test][sanitizer] Allow fork_threaded test on Msan, Tsan (PR #75260)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75260 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [llvm] [clang] [lldb] [compiler-rt] [hwasan] Add `__hwasan_get_tag_from_pointer` (PR #75267)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75267 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [clang] [mlir] [lldb] [compiler-rt] [hwasan] Add `__hwasan_get_tag_from_pointer` (PR #75267)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75267 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [test][hwasan] Implement sanitizer_specific for HWASAN (PR #75280)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/75280 None ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [test][hwasan] Implement sanitizer_specific for HWASAN (PR #75280)
llvmbot wrote: @llvm/pr-subscribers-compiler-rt-sanitizer Author: Vitaly Buka (vitalybuka) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/75280.diff 1 Files Affected: - (modified) compiler-rt/test/sanitizer_common/sanitizer_specific.h (+13) ``diff diff --git a/compiler-rt/test/sanitizer_common/sanitizer_specific.h b/compiler-rt/test/sanitizer_common/sanitizer_specific.h index 898899f00e370..541af18a74979 100644 --- a/compiler-rt/test/sanitizer_common/sanitizer_specific.h +++ b/compiler-rt/test/sanitizer_common/sanitizer_specific.h @@ -31,6 +31,19 @@ static void make_mem_good(void *p, size_t s) { static void make_mem_bad(void *p, size_t s) { __asan_poison_memory_region(p, s); } +#elif __has_feature(hwaddress_sanitizer) +# include +# include +static void check_mem_is_good(void *p, size_t s) { + if (__hwasan_test_shadow(p, s) != -1) +abort(); +} +static void make_mem_good(void *p, size_t s) { + __hwasan_tag_memory(p, __hwasan_get_tag_from_pointer(p), s); +} +static void make_mem_bad(void *p, size_t s) { + __hwasan_tag_memory(p, ~__hwasan_get_tag_from_pointer(p), s); +} #else static void check_mem_is_good(void *p, size_t s) {} static void make_mem_good(void *p, size_t s) {} `` https://github.com/llvm/llvm-project/pull/75280 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clangd] check for synthesized symbols when tracking include locations (PR #75128)
mizvekov wrote: > Hi @mizvekov thanks for the fix, but I am not sure if this is at the right > level. The way you're bailing out currently prevents clangd from indexing all > implicit definitions, even if we have a hard-coded mapping for them (based on > the symbol name). > > Also the map you're preventing the insertion stores FileIDs as values, not > keys, hence it isn't the place firing assertion failures. Can you instead > move the logic to SymbolCollector::finish, which uses FileIDs to determine > includers for objective-c symbols? we should only perform that logic if > there's a valid FileID. I see. Though the situation you describe seems impossible at the present state of the implementation. For standard library stuff, we have hardcoded std::move and std::remove, implemented [here](https://github.com/llvm/llvm-project/blob/6d8fe3dc9a4f6225c4c84de578469efc50d7684d/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp#L117) but those require some sort of user provided declaration somewhere in code, which will have a valid source location, and we indeed unit test that. As an aside, I think in the above case we should honor the `-freestanding` flag, but currently we do not. For the builtin-which-requires-include case, that is unimplemented, with a FIXME note: https://github.com/llvm/llvm-project/blob/6d8fe3dc9a4f6225c4c84de578469efc50d7684d/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp#L177 I agree in principle to the change you suggested, even if presently non testable, but I still think it makes sense to skip inserting invalid FileIDs into the `IncludeFiles` map. https://github.com/llvm/llvm-project/pull/75128 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [llvm] [test][hwasan] Implement sanitizer_specific for HWASAN (PR #75280)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75280 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [llvm] [test][hwasan] Implement sanitizer_specific for HWASAN (PR #75280)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75280 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clangd] check for synthesized symbols when tracking include locations (PR #75128)
https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/75128 >From 3fb75008987c28c9d63d209f36caaced8b37c4a6 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Wed, 13 Dec 2023 01:44:16 -0300 Subject: [PATCH] [clangd] check for synthesized symbols when tracking include locations This fixes https://github.com/llvm/llvm-project/issues/75115 In C mode with MSVC compatibility, when the `assert` macro is defined, as a workaround, `static_assert` is implicitly defined as well, if not already so, in order to work around a broken `assert.h` implementation. This workaround was implemented in https://github.com/llvm/llvm-project/commit/8da090381d567d0ec555840f6b2a651d2997e4b3 A synthesized symbol does not occur in source code, and therefore should not have valid source location, but this was not checked when inserting this into a `symbol -> include file` map. The invalid FileID value is used for empty key representation in the include file hash table, so it's not valid to insert it. --- clang-tools-extra/clangd/index/SymbolCollector.cpp | 8 clang-tools-extra/clangd/test/GH75115.test | 11 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp index aac6676a995fed..5d995cdae6d665 100644 --- a/clang-tools-extra/clangd/index/SymbolCollector.cpp +++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -821,7 +821,8 @@ void SymbolCollector::setIncludeLocation(const Symbol &S, SourceLocation DefLoc, // Use the expansion location to get the #include header since this is // where the symbol is exposed. - IncludeFiles[S.ID] = SM.getDecomposedExpansionLoc(DefLoc).first; + if (FileID FID = SM.getDecomposedExpansionLoc(DefLoc).first; FID.isValid()) +IncludeFiles[S.ID] = FID; // We update providers for a symbol with each occurence, as SymbolCollector // might run while parsing, rather than at the end of a translation unit. @@ -893,16 +894,15 @@ void SymbolCollector::finish() { const Symbol *S = Symbols.find(SID); if (!S) continue; -assert(IncludeFiles.contains(SID)); -const auto FID = IncludeFiles.at(SID); +FileID FID = IncludeFiles.lookup(SID); // Determine if the FID is #include'd or #import'ed. Symbol::IncludeDirective Directives = Symbol::Invalid; auto CollectDirectives = shouldCollectIncludePath(S->SymInfo.Kind); if ((CollectDirectives & Symbol::Include) != 0) Directives |= Symbol::Include; // Only allow #import for symbols from ObjC-like files. -if ((CollectDirectives & Symbol::Import) != 0) { +if ((CollectDirectives & Symbol::Import) != 0 && FID.isValid()) { auto [It, Inserted] = FileToContainsImportsOrObjC.try_emplace(FID); if (Inserted) It->second = FilesWithObjCConstructs.contains(FID) || diff --git a/clang-tools-extra/clangd/test/GH75115.test b/clang-tools-extra/clangd/test/GH75115.test index 030392f1d69b30..dc86f5b9a6cee0 100644 --- a/clang-tools-extra/clangd/test/GH75115.test +++ b/clang-tools-extra/clangd/test/GH75115.test @@ -1,12 +1,15 @@ // RUN: rm -rf %t.dir && mkdir -p %t.dir // RUN: echo '[{"directory": "%/t.dir", "command": "clang --target=x86_64-pc-windows-msvc -x c GH75115.test", "file": "GH75115.test"}]' > %t.dir/compile_commands.json -// RUN: not --crash clangd -enable-config=0 --compile-commands-dir=%t.dir -check=%s 2>&1 | FileCheck -strict-whitespace %s - -// FIXME: Crashes +// RUN: clangd -enable-config=0 --compile-commands-dir=%t.dir -check=%s 2>&1 | FileCheck -strict-whitespace %s // CHECK: Building preamble... // CHECK-NEXT: Built preamble // CHECK-NEXT: Indexing headers... -// CHECK-NEXT: !KeyInfoT::isEqual(Val, EmptyKey) && !KeyInfoT::isEqual(Val, TombstoneKey) && "Empty/Tombstone value shouldn't be inserted into map!" +// CHECK-NEXT: Building AST... +// CHECK-NEXT: Indexing AST... +// CHECK-NEXT: Building inlay hints +// CHECK-NEXT: semantic highlighting +// CHECK-NEXT: Testing features at each token +// CHECK-NEXT: All checks completed, 0 errors #define assert ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [lsan] Install `pthread_atfork` (PR #75281)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/75281 This prevents deadlocks in forked process on essencial runtime components. ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [lsan] Install `pthread_atfork` (PR #75281)
llvmbot wrote: @llvm/pr-subscribers-compiler-rt-sanitizer Author: Vitaly Buka (vitalybuka) Changes This prevents deadlocks in forked process on essencial runtime components. --- Full diff: https://github.com/llvm/llvm-project/pull/75281.diff 7 Files Affected: - (modified) compiler-rt/lib/lsan/lsan.cpp (+1) - (modified) compiler-rt/lib/lsan/lsan.h (+1) - (modified) compiler-rt/lib/lsan/lsan_common.cpp (+3) - (modified) compiler-rt/lib/lsan/lsan_common.h (+4) - (modified) compiler-rt/lib/lsan/lsan_fuchsia.cpp (+1) - (modified) compiler-rt/lib/lsan/lsan_posix.cpp (+20) - (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp (+1-1) ``diff diff --git a/compiler-rt/lib/lsan/lsan.cpp b/compiler-rt/lib/lsan/lsan.cpp index 6b223603c6a79c..7a27b600f203f7 100644 --- a/compiler-rt/lib/lsan/lsan.cpp +++ b/compiler-rt/lib/lsan/lsan.cpp @@ -101,6 +101,7 @@ extern "C" void __lsan_init() { InstallDeadlySignalHandlers(LsanOnDeadlySignal); InitializeMainThread(); InstallAtExitCheckLeaks(); + InstallAtForkHandler(); InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir); diff --git a/compiler-rt/lib/lsan/lsan.h b/compiler-rt/lib/lsan/lsan.h index 757edec8e104f9..0074ad5308785c 100644 --- a/compiler-rt/lib/lsan/lsan.h +++ b/compiler-rt/lib/lsan/lsan.h @@ -40,6 +40,7 @@ void InitializeInterceptors(); void ReplaceSystemMalloc(); void LsanOnDeadlySignal(int signo, void *siginfo, void *context); void InstallAtExitCheckLeaks(); +void InstallAtForkHandler(); #define ENSURE_LSAN_INITED\ do {\ diff --git a/compiler-rt/lib/lsan/lsan_common.cpp b/compiler-rt/lib/lsan/lsan_common.cpp index 8b1af5b629fbce..e24839c984b346 100644 --- a/compiler-rt/lib/lsan/lsan_common.cpp +++ b/compiler-rt/lib/lsan/lsan_common.cpp @@ -42,6 +42,9 @@ namespace __lsan { // also to protect the global list of root regions. static Mutex global_mutex; +void LockGlobal() SANITIZER_ACQUIRE(global_mutex) { global_mutex.Lock(); } +void UnlockGlobal() SANITIZER_RELEASE(global_mutex) { global_mutex.Unlock(); } + Flags lsan_flags; void DisableCounterUnderflow() { diff --git a/compiler-rt/lib/lsan/lsan_common.h b/compiler-rt/lib/lsan/lsan_common.h index d3e768363e93b9..c598b62105873e 100644 --- a/compiler-rt/lib/lsan/lsan_common.h +++ b/compiler-rt/lib/lsan/lsan_common.h @@ -120,6 +120,10 @@ void GetRunningThreadsLocked(InternalMmapVector *threads); void LockAllocator(); void UnlockAllocator(); +// Lock/unlock global mutext. +void LockGlobal(); +void UnlockGlobal(); + // Returns the address range occupied by the global allocator object. void GetAllocatorGlobalRange(uptr *begin, uptr *end); // If p points into a chunk that has been allocated to the user, returns its diff --git a/compiler-rt/lib/lsan/lsan_fuchsia.cpp b/compiler-rt/lib/lsan/lsan_fuchsia.cpp index 4edac9757a9c49..ba59bc9b71e332 100644 --- a/compiler-rt/lib/lsan/lsan_fuchsia.cpp +++ b/compiler-rt/lib/lsan/lsan_fuchsia.cpp @@ -80,6 +80,7 @@ void GetAllThreadAllocatorCachesLocked(InternalMmapVector *caches) { // On Fuchsia, leak detection is done by a special hook after atexit hooks. // So this doesn't install any atexit hook like on other platforms. void InstallAtExitCheckLeaks() {} +void InstallAtForkHandler() {} // ASan defines this to check its `halt_on_error` flag. bool UseExitcodeOnLeak() { return true; } diff --git a/compiler-rt/lib/lsan/lsan_posix.cpp b/compiler-rt/lib/lsan/lsan_posix.cpp index d99e1cc0105ef7..7dc4254eb150a3 100644 --- a/compiler-rt/lib/lsan/lsan_posix.cpp +++ b/compiler-rt/lib/lsan/lsan_posix.cpp @@ -14,7 +14,11 @@ #include "sanitizer_common/sanitizer_platform.h" #if SANITIZER_POSIX + #include "lsan.h" + +#include + #include "lsan_allocator.h" #include "lsan_thread.h" #include "sanitizer_common/sanitizer_stacktrace.h" @@ -98,6 +102,22 @@ void InstallAtExitCheckLeaks() { Atexit(DoLeakCheck); } +void InstallAtForkHandler() { + auto before = []() { +LockGlobal(); +LockThreads(); +LockAllocator(); +StackDepotLockAll(); + }; + auto after = []() { +StackDepotUnlockAll(); +UnlockAllocator(); +UnlockThreads(); +UnlockGlobal(); + }; + pthread_atfork(before, after, after); +} + } // namespace __lsan #endif // SANITIZER_POSIX diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp index e2d67341846c74..833edbdb54bd93 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp +++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp @@ -1,6 +1,6 @@ // RUN: %clangxx -O0 %s -o %t && %env_tool_opts=die_after_fork=0 %run %t -// UNSUPPORTED: asan, lsan, hwasan +// UNSUPPORTED: asan, hwasan // Forking in multithread environment is unsupported. However we already have // some workarounds, and will add more, so this is the test. ``
[llvm-branch-commits] [compiler-rt] [lsan] Install `pthread_atfork` (PR #75281)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff b7c39068812f3417b41435961ece4171ed5bac4a d00d9f3d8e4b80eb8c7d24bf98bb65a8262a9730 -- compiler-rt/lib/lsan/lsan.cpp compiler-rt/lib/lsan/lsan.h compiler-rt/lib/lsan/lsan_common.cpp compiler-rt/lib/lsan/lsan_common.h compiler-rt/lib/lsan/lsan_fuchsia.cpp compiler-rt/lib/lsan/lsan_posix.cpp compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.cpp `` View the diff from clang-format here. ``diff diff --git a/compiler-rt/lib/lsan/lsan_posix.cpp b/compiler-rt/lib/lsan/lsan_posix.cpp index 7dc4254eb1..dbfd2c61a3 100644 --- a/compiler-rt/lib/lsan/lsan_posix.cpp +++ b/compiler-rt/lib/lsan/lsan_posix.cpp @@ -15,14 +15,13 @@ #if SANITIZER_POSIX -#include "lsan.h" +# include -#include - -#include "lsan_allocator.h" -#include "lsan_thread.h" -#include "sanitizer_common/sanitizer_stacktrace.h" -#include "sanitizer_common/sanitizer_tls_get_addr.h" +# include "lsan.h" +# include "lsan_allocator.h" +# include "lsan_thread.h" +# include "sanitizer_common/sanitizer_stacktrace.h" +# include "sanitizer_common/sanitizer_tls_get_addr.h" namespace __lsan { `` https://github.com/llvm/llvm-project/pull/75281 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [compiler-rt] [clang-tools-extra] [test][hwasan] Implement sanitizer_specific for HWASAN (PR #75280)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75280 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [compiler-rt] [clang-tools-extra] [test][hwasan] Implement sanitizer_specific for HWASAN (PR #75280)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75280 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [llvm] [clang-tools-extra] [lsan] Install `pthread_atfork` (PR #75281)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75281 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [compiler-rt] [clang-tools-extra] [lsan] Install `pthread_atfork` (PR #75281)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75281 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] 631d618 - Revert "[coroutines] Use DILocation from new storage for hoisted dbg.declare (#75104)"
Author: Matheus Izvekov Date: 2023-12-13T06:30:37+01:00 New Revision: 631d618a907ce59564147a0fb90c264806ef03de URL: https://github.com/llvm/llvm-project/commit/631d618a907ce59564147a0fb90c264806ef03de DIFF: https://github.com/llvm/llvm-project/commit/631d618a907ce59564147a0fb90c264806ef03de.diff LOG: Revert "[coroutines] Use DILocation from new storage for hoisted dbg.declare (#75104)" This reverts commit 31cf6df06febdf2483d224d2c9657497cac7d41f. Added: Modified: llvm/lib/Transforms/Coroutines/CoroFrame.cpp llvm/test/Transforms/Coroutines/coro-debug-frame-variable.ll Removed: diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp index 678d7fb3f5719..6b85de15947c2 100644 --- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp @@ -2891,11 +2891,9 @@ void coro::salvageDebugInfo( // dbg.declare does. if (isa(DVI)) { std::optional InsertPt; -if (auto *I = dyn_cast(Storage)) { +if (auto *I = dyn_cast(Storage)) InsertPt = I->getInsertionPointAfterDef(); - if (I->getDebugLoc()) -DVI->setDebugLoc(I->getDebugLoc()); -} else if (isa(Storage)) +else if (isa(Storage)) InsertPt = F->getEntryBlock().begin(); if (InsertPt) DVI->moveBefore(*(*InsertPt)->getParent(), *InsertPt); diff --git a/llvm/test/Transforms/Coroutines/coro-debug-frame-variable.ll b/llvm/test/Transforms/Coroutines/coro-debug-frame-variable.ll index 53995fb3498e5..37b4126ce3730 100644 --- a/llvm/test/Transforms/Coroutines/coro-debug-frame-variable.ll +++ b/llvm/test/Transforms/Coroutines/coro-debug-frame-variable.ll @@ -31,8 +31,8 @@ ; CHECK: entry: ; CHECK: %j = alloca i32, align 4 ; CHECK: call void @llvm.dbg.declare(metadata ptr %j, metadata ![[JVAR:[0-9]+]], metadata !DIExpression()), !dbg ![[JDBGLOC:[0-9]+]] -; CHECK: %[[MEMORY:.*]] = call ptr @new({{.+}}), !dbg ![[IDBGLOC:[0-9]+]] -; CHECK: call void @llvm.dbg.declare(metadata ptr %[[MEMORY]], metadata ![[XVAR:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 32)), !dbg ![[IDBGLOC]] +; CHECK: %[[MEMORY:.*]] = call ptr @new +; CHECK: call void @llvm.dbg.declare(metadata ptr %[[MEMORY]], metadata ![[XVAR:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 32)), !dbg ![[IDBGLOC:[0-9]+]] ; CHECK: call void @llvm.dbg.declare(metadata ptr %[[MEMORY]], metadata ![[IVAR:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 20)), !dbg ![[IDBGLOC]] ; CHECK: await.ready: ; @@ -48,20 +48,18 @@ ; CHECK: await.ready: ; ; CHECK-DAG: ![[IVAR]] = !DILocalVariable(name: "i" -; CHECK-DAG: ![[PROG_SCOPE:[0-9]+]] = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov" -; CHECK-DAG: ![[BLK_SCOPE:[0-9]+]] = distinct !DILexicalBlock(scope: ![[PROG_SCOPE]], file: !1, line: 23, column: 12) -; CHECK-DAG: ![[IDBGLOC]] = !DILocation(line: 23, column: 6, scope: ![[PROG_SCOPE]]) +; CHECK-DAG: ![[SCOPE:[0-9]+]] = distinct !DILexicalBlock(scope: !6, file: !1, line: 23, column: 12) +; CHECK-DAG: ![[IDBGLOC]] = !DILocation(line: 24, column: 7, scope: ![[SCOPE]]) ; CHECK-DAG: ![[XVAR]] = !DILocalVariable(name: "x" ; CHECK-DAG: ![[JVAR]] = !DILocalVariable(name: "j" -; CHECK-DAG: ![[JDBGLOC]] = !DILocation(line: 32, column: 7, scope: ![[BLK_SCOPE]]) +; CHECK-DAG: ![[JDBGLOC]] = !DILocation(line: 32, column: 7, scope: ![[SCOPE]]) ; CHECK-DAG: ![[XVAR_RESUME]] = !DILocalVariable(name: "x" -; CHECK-DAG: ![[RESUME_PROG_SCOPE:[0-9]+]] = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov" -; CHECK-DAG: ![[IDBGLOC_RESUME]] = !DILocation(line: 24, column: 7, scope: ![[RESUME_BLK_SCOPE:[0-9]+]]) -; CHECK-DAG: ![[RESUME_BLK_SCOPE]] = distinct !DILexicalBlock(scope: ![[RESUME_PROG_SCOPE]], file: !1, line: 23, column: 12) +; CHECK-DAG: ![[IDBGLOC_RESUME]] = !DILocation(line: 24, column: 7, scope: ![[RESUME_SCOPE:[0-9]+]]) +; CHECK-DAG: ![[RESUME_SCOPE]] = distinct !DILexicalBlock(scope: !22, file: !1, line: 23, column: 12) ; CHECK-DAG: ![[IVAR_RESUME]] = !DILocalVariable(name: "i" ; CHECK-DAG: ![[JVAR_RESUME]] = !DILocalVariable(name: "j" -; CHECK-DAG: ![[JDBGLOC_RESUME]] = !DILocation(line: 32, column: 7, scope: ![[RESUME_BLK_SCOPE]]) +; CHECK-DAG: ![[JDBGLOC_RESUME]] = !DILocation(line: 32, column: 7, scope: ![[RESUME_SCOPE]]) define void @f() presplitcoroutine !dbg !8 { entry: %__promise = alloca i8, align 8 @@ -73,13 +71,13 @@ entry: br i1 %alloc, label %coro.alloc, label %coro.init coro.alloc: ; preds = %entry - %size = call i64 @llvm.coro.size.i64(), !dbg !23 - %memory = call ptr @new(i64 %size), !dbg !23 - br label %coro.init, !dbg !23 + %size = call i64 @llvm.coro.size.i64() + %memory = call ptr @new(i64 %size) + br label %coro.init coro.init:; p
[llvm-branch-commits] [clang-tools-extra] [libcxx] [compiler-rt] [lld] [llvm] [test][hwasan] Implement sanitizer_specific for HWASAN (PR #75280)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75280 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [lld] [llvm] [libcxx] [clang-tools-extra] [test][hwasan] Implement sanitizer_specific for HWASAN (PR #75280)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75280 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [lld] [llvm] [libcxx] [clang-tools-extra] [lsan] Install `pthread_atfork` (PR #75281)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75281 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [libcxx] [compiler-rt] [lld] [llvm] [lsan] Install `pthread_atfork` (PR #75281)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75281 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [asan] Install `pthread_atfork` (PR #75290)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/75290 This prevents deadlocks in forked process if parent had more then one running threads. ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [hwasan] Improve support of forking with threads (PR #75291)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/75291 Lock Lsan and Thread related date at_fork. Clean shadow before thread starts, forked process may reuse already mapped stack of 'lost' parent thread for new threads. ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [asan] Install `pthread_atfork` (PR #75290)
llvmbot wrote: @llvm/pr-subscribers-compiler-rt-sanitizer Author: Vitaly Buka (vitalybuka) Changes This prevents deadlocks in forked process if parent had more then one running threads. --- Full diff: https://github.com/llvm/llvm-project/pull/75290.diff 6 Files Affected: - (modified) compiler-rt/lib/asan/asan_fuchsia.cpp (+2) - (modified) compiler-rt/lib/asan/asan_internal.h (+1) - (modified) compiler-rt/lib/asan/asan_posix.cpp (+24) - (modified) compiler-rt/lib/asan/asan_rtl.cpp (+2) - (modified) compiler-rt/lib/asan/asan_win.cpp (+2) - (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c (+1-1) ``diff diff --git a/compiler-rt/lib/asan/asan_fuchsia.cpp b/compiler-rt/lib/asan/asan_fuchsia.cpp index 2b15504123bee..12625e9d75833 100644 --- a/compiler-rt/lib/asan/asan_fuchsia.cpp +++ b/compiler-rt/lib/asan/asan_fuchsia.cpp @@ -240,6 +240,8 @@ void FlushUnneededASanShadowMemory(uptr p, uptr size) { // So this doesn't install any atexit hook like on other platforms. void InstallAtExitCheckLeaks() {} +void InstallAtForkHandler() {} + } // namespace __asan namespace __lsan { diff --git a/compiler-rt/lib/asan/asan_internal.h b/compiler-rt/lib/asan/asan_internal.h index 5b97e77882cd6..2944ebe213b5d 100644 --- a/compiler-rt/lib/asan/asan_internal.h +++ b/compiler-rt/lib/asan/asan_internal.h @@ -126,6 +126,7 @@ void *AsanDlSymNext(const char *sym); bool HandleDlopenInit(); void InstallAtExitCheckLeaks(); +void InstallAtForkHandler(); #define ASAN_ON_ERROR() \ if (&__asan_on_error) \ diff --git a/compiler-rt/lib/asan/asan_posix.cpp b/compiler-rt/lib/asan/asan_posix.cpp index e1f66641617cc..37fca8aea5151 100644 --- a/compiler-rt/lib/asan/asan_posix.cpp +++ b/compiler-rt/lib/asan/asan_posix.cpp @@ -148,6 +148,30 @@ void PlatformTSDDtor(void *tsd) { } #endif +void InstallAtForkHandler() { + auto before = []() { +if (CAN_SANITIZE_LEAKS) { + __lsan::LockGlobal(); +} +// `_lsan` functions defined regardless of `CAN_SANITIZE_LEAKS` and do the +// job. +__lsan::LockThreads(); +__lsan::LockAllocator(); +StackDepotLockAll(); + }; + auto after = []() { +StackDepotUnlockAll(); +// `_lsan` functions defined regardless of `CAN_SANITIZE_LEAKS` and do the +// job. +__lsan::UnlockAllocator(); +__lsan::UnlockThreads(); +if (CAN_SANITIZE_LEAKS) { + __lsan::UnlockGlobal(); +} + }; + pthread_atfork(before, after, after); +} + void InstallAtExitCheckLeaks() { if (CAN_SANITIZE_LEAKS) { if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit) { diff --git a/compiler-rt/lib/asan/asan_rtl.cpp b/compiler-rt/lib/asan/asan_rtl.cpp index b28f9f181239b..a61deed7382b0 100644 --- a/compiler-rt/lib/asan/asan_rtl.cpp +++ b/compiler-rt/lib/asan/asan_rtl.cpp @@ -493,6 +493,8 @@ static bool AsanInitInternal() { InstallAtExitCheckLeaks(); } + InstallAtForkHandler(); + #if CAN_SANITIZE_UB __ubsan::InitAsPlugin(); #endif diff --git a/compiler-rt/lib/asan/asan_win.cpp b/compiler-rt/lib/asan/asan_win.cpp index d5a30f471e2b0..f16ce677618e4 100644 --- a/compiler-rt/lib/asan/asan_win.cpp +++ b/compiler-rt/lib/asan/asan_win.cpp @@ -203,6 +203,8 @@ void InitializePlatformInterceptors() { void InstallAtExitCheckLeaks() {} +void InstallAtForkHandler() {} + void AsanApplyToGlobals(globals_op_fptr op, const void *needle) { UNIMPLEMENTED(); } diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c index 67d2993d11bf8..1a52702c5de8c 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c +++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c @@ -1,6 +1,6 @@ // RUN: %clang -O0 %s -o %t && %env_tool_opts=die_after_fork=0 %run %t -// UNSUPPORTED: asan, hwasan +// UNSUPPORTED: hwasan // Forking in multithread environment is unsupported. However we already have // some workarounds, and will add more, so this is the test. `` https://github.com/llvm/llvm-project/pull/75290 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [hwasan] Improve support of forking with threads (PR #75291)
llvmbot wrote: @llvm/pr-subscribers-compiler-rt-sanitizer Author: Vitaly Buka (vitalybuka) Changes Lock Lsan and Thread related date at_fork. Clean shadow before thread starts, forked process may reuse already mapped stack of 'lost' parent thread for new threads. --- Full diff: https://github.com/llvm/llvm-project/pull/75291.diff 3 Files Affected: - (modified) compiler-rt/lib/hwasan/hwasan_linux.cpp (+14-2) - (modified) compiler-rt/lib/hwasan/hwasan_thread.cpp (+1) - (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c (+4-2) ``diff diff --git a/compiler-rt/lib/hwasan/hwasan_linux.cpp b/compiler-rt/lib/hwasan/hwasan_linux.cpp index f01fa42764134..e0db24b9519f7 100644 --- a/compiler-rt/lib/hwasan/hwasan_linux.cpp +++ b/compiler-rt/lib/hwasan/hwasan_linux.cpp @@ -523,12 +523,24 @@ uptr TagMemoryAligned(uptr p, uptr size, tag_t tag) { void HwasanInstallAtForkHandler() { auto before = []() { -HwasanAllocatorLock(); +if (CAN_SANITIZE_LEAKS) { + __lsan::LockGlobal(); +} +// `_lsan` functions defined regardless of `CAN_SANITIZE_LEAKS` and do the +// job. +__lsan::LockThreads(); +__lsan::LockAllocator(); StackDepotLockAll(); }; auto after = []() { StackDepotUnlockAll(); -HwasanAllocatorUnlock(); +// `_lsan` functions defined regardless of `CAN_SANITIZE_LEAKS` and do the +// job. +__lsan::UnlockAllocator(); +__lsan::UnlockThreads(); +if (CAN_SANITIZE_LEAKS) { + __lsan::UnlockGlobal(); +} }; pthread_atfork(before, after, after); } diff --git a/compiler-rt/lib/hwasan/hwasan_thread.cpp b/compiler-rt/lib/hwasan/hwasan_thread.cpp index ce36547580e6e..3e14a718513d7 100644 --- a/compiler-rt/lib/hwasan/hwasan_thread.cpp +++ b/compiler-rt/lib/hwasan/hwasan_thread.cpp @@ -68,6 +68,7 @@ void Thread::Init(uptr stack_buffer_start, uptr stack_buffer_size, } Print("Creating : "); } + ClearShadowForThreadStackAndTLS(); } void Thread::InitStackRingBuffer(uptr stack_buffer_start, diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c index 1a52702c5de8c..f27859f815ff9 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c +++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c @@ -1,7 +1,5 @@ // RUN: %clang -O0 %s -o %t && %env_tool_opts=die_after_fork=0 %run %t -// UNSUPPORTED: hwasan - // Forking in multithread environment is unsupported. However we already have // some workarounds, and will add more, so this is the test. // The test try to check two things: @@ -58,6 +56,10 @@ NOSAN static void *inchild(void *arg) { } int main(void) { +#if __has_feature(hwaddress_sanitizer) + __hwasan_enable_allocator_tagging(); +#endif + pid_t pid; pthread_barrier_init(&bar, NULL, 2); `` https://github.com/llvm/llvm-project/pull/75291 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits