[compiler-rt] r295318 - [tsan] Provide external tags (object types) via debugging API

Kuba Mracek via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 20 07:43:03 PST 2017


Thanks, I will look into this.

Kuba

> On 20 Feb 2017, at 07:40, Diana Picus via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> 
> Hi Kuba,
> 
> I reverted this because it was flaky on AArch64:
> 
> ******************** TEST 'ThreadSanitizer-aarch64 ::
> debug_external.cc' FAILED ********************
> Script:
> --
> /home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/./bin/clang
> --driver-mode=g++ -fsanitize=thread -Wall  -gline-tables-only
> -I/home/buildslave/buildslave/clang-cmake-aarch64-42vma/llvm/projects/compiler-rt/test/tsan/../
> -std=c++11 -I/home/buildslave/buildslave/clang-cmake-aarch64-42vma/llvm/projects/compiler-rt/test/tsan/../
> -O1 /home/buildslave/buildslave/clang-cmake-aarch64-42vma/llvm/projects/compiler-rt/test/tsan/debug_external.cc
> -o /home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/projects/compiler-rt/test/tsan/AARCH64Config/Output/debug_external.cc.tmp
> /home/buildslave/buildslave/clang-cmake-aarch64-42vma/llvm/projects/compiler-rt/test/tsan/deflake.bash
> /home/buildslave/buildslave/clang-cmake-aarch64-42vma/stage1/projects/compiler-rt/test/tsan/AARCH64Config/Output/debug_external.cc.tmp
> 2>&1 | FileCheck
> /home/buildslave/buildslave/clang-cmake-aarch64-42vma/llvm/projects/compiler-rt/test/tsan/debug_external.cc
> --
> Exit Code: 2
> 
> Command Output (stderr):
> --
> FileCheck error: '-' is empty.
> FileCheck command line:  FileCheck
> /home/buildslave/buildslave/clang-cmake-aarch64-42vma/llvm/projects/compiler-rt/test/tsan/debug_external.cc
> 
> --
> 
> ********************
> 
> See e.g. http://lab.llvm.org:8011/builders/clang-cmake-aarch64-42vma/builds/4813.
> It also failed in builds 4789, 4783, 4777, 4753 etc.
> 
> Can you try to fix this and recommit?
> 
> Thanks,
> Diana
> 
> On 16 February 2017 at 15:02, Kuba Mracek via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
>> Author: kuba.brecka
>> Date: Thu Feb 16 08:02:32 2017
>> New Revision: 295318
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=295318&view=rev
>> Log:
>> [tsan] Provide external tags (object types) via debugging API
>> 
>> In D28836, we added a way to tag heap objects and thus provide object types into report. This patch exposes this information into the debugging API.
>> 
>> Differential Revision: https://reviews.llvm.org/D30023
>> 
>> 
>> Added:
>>    compiler-rt/trunk/test/tsan/debug_external.cc
>> Modified:
>>    compiler-rt/trunk/lib/tsan/rtl/tsan_debugging.cc
>>    compiler-rt/trunk/lib/tsan/rtl/tsan_interface.h
>> 
>> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_debugging.cc
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_debugging.cc?rev=295318&r1=295317&r2=295318&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/tsan/rtl/tsan_debugging.cc (original)
>> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_debugging.cc Thu Feb 16 08:02:32 2017
>> @@ -128,6 +128,16 @@ int __tsan_get_report_loc(void *report,
>> }
>> 
>> SANITIZER_INTERFACE_ATTRIBUTE
>> +int __tsan_get_report_loc_object_type(void *report, uptr idx,
>> +                                      const char **object_type) {
>> +  const ReportDesc *rep = (ReportDesc *)report;
>> +  CHECK_LT(idx, rep->locs.Size());
>> +  ReportLocation *loc = rep->locs[idx];
>> +  *object_type = GetObjectTypeFromTag(loc->external_tag);
>> +  return 1;
>> +}
>> +
>> +SANITIZER_INTERFACE_ATTRIBUTE
>> int __tsan_get_report_mutex(void *report, uptr idx, uptr *mutex_id, void **addr,
>>                             int *destroyed, void **trace, uptr trace_size) {
>>   const ReportDesc *rep = (ReportDesc *)report;
>> 
>> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interface.h
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interface.h?rev=295318&r1=295317&r2=295318&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/tsan/rtl/tsan_interface.h (original)
>> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_interface.h Thu Feb 16 08:02:32 2017
>> @@ -132,6 +132,10 @@ int __tsan_get_report_loc(void *report,
>>                           int *fd, int *suppressable, void **trace,
>>                           uptr trace_size);
>> 
>> +SANITIZER_INTERFACE_ATTRIBUTE
>> +int __tsan_get_report_loc_object_type(void *report, uptr idx,
>> +                                      const char **object_type);
>> +
>> // Returns information about mutexes included in the report.
>> SANITIZER_INTERFACE_ATTRIBUTE
>> int __tsan_get_report_mutex(void *report, uptr idx, uptr *mutex_id, void **addr,
>> 
>> Added: compiler-rt/trunk/test/tsan/debug_external.cc
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/debug_external.cc?rev=295318&view=auto
>> ==============================================================================
>> --- compiler-rt/trunk/test/tsan/debug_external.cc (added)
>> +++ compiler-rt/trunk/test/tsan/debug_external.cc Thu Feb 16 08:02:32 2017
>> @@ -0,0 +1,61 @@
>> +// RUN: %clangxx_tsan -O1 %s -o %t
>> +// RUN: %deflake %run %t 2>&1 | FileCheck %s
>> +
>> +#include <pthread.h>
>> +#include <stdio.h>
>> +#include <stdlib.h>
>> +#include <string.h>
>> +
>> +extern "C" {
>> +void __tsan_on_report(void *report);
>> +int __tsan_get_report_loc(void *report, unsigned long idx, const char **type,
>> +                          void **addr, void **start,
>> +                          unsigned long *size, int *tid, int *fd,
>> +                          int *suppressable, void **trace,
>> +                          unsigned long trace_size);
>> +int __tsan_get_report_loc_object_type(void *report, unsigned long idx,
>> +                                      const char **object_type);
>> +void *__tsan_external_register_tag(const char *object_type);
>> +void __tsan_external_assign_tag(void *addr, void *tag);
>> +}
>> +
>> +void *Thread(void *arg) {
>> +  *((long *)arg) = 42;
>> +  return NULL;
>> +}
>> +
>> +int main() {
>> +  void *tag = __tsan_external_register_tag("MyObject");
>> +  long *obj = (long *)malloc(sizeof(long));
>> +  fprintf(stderr, "obj = %p\n", obj);
>> +  // CHECK: obj = [[ADDR:0x[0-9a-f]+]]
>> +  __tsan_external_assign_tag(obj, tag);
>> +
>> +  pthread_t t;
>> +  pthread_create(&t, 0, Thread, obj);
>> +  *obj = 41;
>> +  pthread_join(t, 0);
>> +  fprintf(stderr, "Done.\n");
>> +  return 0;
>> +}
>> +
>> +void __tsan_on_report(void *report) {
>> +  const char *type;
>> +  void *addr;
>> +  void *start;
>> +  unsigned long size;
>> +  int tid, fd, suppressable;
>> +  void *trace[16] = {0};
>> +  __tsan_get_report_loc(report, 0, &type, &addr, &start, &size, &tid, &fd,
>> +                        &suppressable, trace, 16);
>> +  fprintf(stderr, "type = %s, start = %p, size = %ld\n", type, start, size);
>> +  // CHECK: type = heap, start = [[ADDR]], size = 8
>> +
>> +  const char *object_type;
>> +  __tsan_get_report_loc_object_type(report, 0, &object_type);
>> +  fprintf(stderr, "object_type = %s\n", object_type);
>> +  // CHECK: object_type = MyObject
>> +}
>> +
>> +// CHECK: Done.
>> +// CHECK: ThreadSanitizer: reported 1 warnings
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list