[compiler-rt] r271046 - [sanitizers] introduce __sanitizer_set_report_fd so that we can re-route the sanitizer logging to another fd from inside the process

Mehdi Amini via llvm-commits llvm-commits at lists.llvm.org
Tue May 31 13:16:56 PDT 2016


Committed in r271323.

I wonder what is the rational for the discrepancy between Darwin and Linux?

-- 
Mehdi

> On May 31, 2016, at 1:11 PM, Kostya Serebryany <kcc at google.com> wrote:
> 
> Ah, I think this is caused by different defaults. 
> On linux by default asan dies with _exit and on Mac it dies with abort()
> This difference was introduced by Kuba after a long resistance from my side :)
> The fix should be pretty simple: add abort_on_error=0 to %tool_options in the test. 
> Could you please check if this helps on Mac? 
> If so, feel free to submit. 
> 
> Thanks! 
> --kcc
> 
> 
> On Tue, May 31, 2016 at 1:01 PM, Mehdi Amini <mehdi.amini at apple.com <mailto:mehdi.amini at apple.com>> wrote:
> Hi Kostya,
> 
> We see a bot failure with the test case you added below: http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-globalisel_check/2068/console <http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-globalisel_check/2068/console>
> 
> After investigating, it seems that they trigger an ASAN failure, which is returning a negative error code. The `not` command tool interprets it as a crash, and you need to pass the --crash option to it.
> 
> Don't you observe this on your setup? I wonder why they are passing?
> 
> --
> Mehdi
> 
> 
> 
> 
> > On May 27, 2016, at 2:23 PM, Kostya Serebryany via llvm-commits <llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>> wrote:
> >
> > Author: kcc
> > Date: Fri May 27 16:23:05 2016
> > New Revision: 271046
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=271046&view=rev <http://llvm.org/viewvc/llvm-project?rev=271046&view=rev>
> > Log:
> > [sanitizers] introduce __sanitizer_set_report_fd so that we can re-route the sanitizer logging to another fd from inside the process
> >
> > Added:
> >    compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc
> > Modified:
> >    compiler-rt/trunk/include/sanitizer/common_interface_defs.h
> >    compiler-rt/trunk/lib/asan/asan_posix.cc
> >    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
> >
> > Modified: compiler-rt/trunk/include/sanitizer/common_interface_defs.h
> > URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/common_interface_defs.h?rev=271046&r1=271045&r2=271046&view=diff <http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/common_interface_defs.h?rev=271046&r1=271045&r2=271046&view=diff>
> > ==============================================================================
> > --- compiler-rt/trunk/include/sanitizer/common_interface_defs.h (original)
> > +++ compiler-rt/trunk/include/sanitizer/common_interface_defs.h Fri May 27 16:23:05 2016
> > @@ -41,6 +41,9 @@ extern "C" {
> >
> >   // Tell the tools to write their reports to "path.<pid>" instead of stderr.
> >   void __sanitizer_set_report_path(const char *path);
> > +  // Tell the tools to write their reports to the provided file descriptor
> > +  // (casted to void *).
> > +  void __sanitizer_set_report_fd(void *fd);
> >
> >   // Notify the tools that the sandbox is going to be turned on. The reserved
> >   // parameter will be used in the future to hold a structure with functions
> >
> > Modified: compiler-rt/trunk/lib/asan/asan_posix.cc
> > URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_posix.cc?rev=271046&r1=271045&r2=271046&view=diff <http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_posix.cc?rev=271046&r1=271045&r2=271046&view=diff>
> > ==============================================================================
> > --- compiler-rt/trunk/lib/asan/asan_posix.cc (original)
> > +++ compiler-rt/trunk/lib/asan/asan_posix.cc Fri May 27 16:23:05 2016
> > @@ -36,8 +36,9 @@ namespace __asan {
> > void AsanOnDeadlySignal(int signo, void *siginfo, void *context) {
> >   ScopedDeadlySignal signal_scope(GetCurrentThread());
> >   int code = (int)((siginfo_t*)siginfo)->si_code;
> > -  // Write the first message using the bullet-proof write.
> > -  if (18 != internal_write(2, "ASAN:DEADLYSIGNAL\n", 18)) Die();
> > +  // Write the first message using fd=2, just in case.
> > +  // It may actually fail to write in case stderr is closed.
> > +  internal_write(2, "ASAN:DEADLYSIGNAL\n", 18);
> >   SignalContext sig = SignalContext::Create(siginfo, context);
> >
> >   // Access at a reasonable offset above SP, or slightly below it (to account
> >
> > Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
> > URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=271046&r1=271045&r2=271046&view=diff <http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=271046&r1=271045&r2=271046&view=diff>
> > ==============================================================================
> > --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc (original)
> > +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc Fri May 27 16:23:05 2016
> > @@ -496,6 +496,11 @@ void __sanitizer_set_report_path(const c
> >   report_file.SetReportPath(path);
> > }
> >
> > +void __sanitizer_set_report_fd(void *fd) {
> > +  report_file.fd = reinterpret_cast<uptr>(fd);
> > +  report_file.fd_pid = internal_getpid();
> > +}
> > +
> > void __sanitizer_report_error_summary(const char *error_summary) {
> >   Printf("%s\n", error_summary);
> > }
> >
> > Added: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc
> > URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc?rev=271046&view=auto <http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc?rev=271046&view=auto>
> > ==============================================================================
> > --- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc (added)
> > +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc Fri May 27 16:23:05 2016
> > @@ -0,0 +1,37 @@
> > +// Test __sanitizer_set_report_fd:
> > +// RUN: %clangxx -O2 %s -o %t
> > +// RUN: not %run %t 2>&1   | FileCheck %s
> > +// RUN: not %run %t stdout | FileCheck %s
> > +// RUN: not %run %t %t-out && FileCheck < %t-out %s
> > +
> > +// REQUIRES: stable-runtime
> > +// FIXME: implement SEGV handler in other sanitizers, not just asan.
> > +// XFAIL: msan
> > +// XFAIL: lsan
> > +// XFAIL: tsan
> > +
> > +#include <sanitizer/common_interface_defs.h>
> > +#include <stdio.h>
> > +#include <string.h>
> > +#include <stdlib.h>
> > +#include <sys/types.h>
> > +#include <sys/stat.h>
> > +#include <fcntl.h>
> > +#include <assert.h>
> > +
> > +volatile int *null = 0;
> > +
> > +int main(int argc, char **argv) {
> > +  if (argc == 2) {
> > +    if (!strcmp(argv[1], "stdout")) {
> > +      __sanitizer_set_report_fd(reinterpret_cast<void*>(1));
> > +    } else {
> > +      int fd = open(argv[1], O_CREAT | O_WRONLY | O_TRUNC, S_IRWXU);
> > +      assert(fd > 0);
> > +      __sanitizer_set_report_fd(reinterpret_cast<void*>(fd));
> > +    }
> > +  }
> > +  *null = 0;
> > +}
> > +
> > +// CHECK: ERROR: {{.*}} SEGV on unknown address
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits>
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160531/f4eb9d9a/attachment.html>


More information about the llvm-commits mailing list