[Openmp-commits] [PATCH] D115328: SIGSEGV in ompt_tsan_dependences with for-ordered

Ritanya via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Dec 8 03:33:29 PST 2021


RitanyaB created this revision.
RitanyaB added reviewers: dreachem, protze.joachim.
Herald added a subscriber: pengfei.
RitanyaB requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.

Segmentation fault in ompt_tsan_dependences function due to an unchecked NULL pointer dereference is as follows:

  ThreadSanitizer:DEADLYSIGNAL
  	==140865==ERROR: ThreadSanitizer: SEGV on unknown address 0x000000000050 (pc 0x7f217c2d3652 bp 0x7ffe8cfc7e00 sp 0x7ffe8cfc7d90 T140865)
  	==140865==The signal is caused by a READ memory access.
  	==140865==Hint: address points to the zero page.
  	/usr/bin/addr2line: DWARF error: could not find variable specification at offset 1012a
  	/usr/bin/addr2line: DWARF error: could not find variable specification at offset 133b5
  	/usr/bin/addr2line: DWARF error: could not find variable specification at offset 1371a
  	/usr/bin/addr2line: DWARF error: could not find variable specification at offset 13a58
  	#0 ompt_tsan_dependences(ompt_data_t*, ompt_dependence_t const*, int) /ptmp/bhararit/llvm-project/openmp/tools/archer/ompt-tsan.cpp:1004 (libarcher.so+0x15652)
  	#1 __kmpc_doacross_post /ptmp/bhararit/llvm-project/openmp/runtime/src/kmp_csupport.cpp:4280 (libomp.so+0x74d98)
  	#2 .omp_outlined. for_ordered_01.c:? (for_ordered_01.exe+0x5186cb)
  	#3 __kmp_invoke_microtask /ptmp/bhararit/llvm-project/openmp/runtime/src/z_Linux_asm.S:1166 (libomp.so+0x14e592)
  	#4 __kmp_invoke_task_func /ptmp/bhararit/llvm-project/openmp/runtime/src/kmp_runtime.cpp:7556 (libomp.so+0x909ad)
  	#5 __kmp_fork_call /ptmp/bhararit/llvm-project/openmp/runtime/src/kmp_runtime.cpp:2284 (libomp.so+0x8461a)
  	#6 __kmpc_fork_call /ptmp/bhararit/llvm-project/openmp/runtime/src/kmp_csupport.cpp:308 (libomp.so+0x6db55)
  	#7 main ??:? (for_ordered_01.exe+0x51828f)
  	#8 __libc_start_main ??:? (libc.so.6+0x24349)
  	#9 _start /home/abuild/rpmbuild/BUILD/glibc-2.26/csu/../sysdeps/x86_64/start.S:120 (for_ordered_01.exe+0x4214e9)
  	
  	ThreadSanitizer can not provide additional info.
  	SUMMARY: ThreadSanitizer: SEGV /ptmp/bhararit/llvm-project/openmp/tools/archer/ompt-tsan.cpp:1004 in ompt_tsan_dependences(ompt_data_t*, ompt_dependence_t const*, int)
  	==140865==ABORTING

To reproduce the error, use the following openmp code snippet:

  /* initialise  testMatrixInt Matrix, cols, r and c */
  	  #pragma omp parallel private(r,c) shared(testMatrixInt)
  	    {
  	      #pragma omp for ordered(2)
  	      for (r=1; r < rows; r++) {
  	        for (c=1; c < cols; c++) {
  	          #pragma omp ordered depend(sink:r-1, c+1) depend(sink:r-1,c-1)
  	          testMatrixInt[r][c] = (testMatrixInt[r-1][c] + testMatrixInt[r-1][c-1]) % cols ;
  	          #pragma omp ordered depend (source)
  	        }
  	      }
  	    }

Compilation:

  clang -g -stdlib=libc++ -fsanitize=thread -fopenmp -larcher test_case.c 

It seems like the changes introduced by the commit https://reviews.llvm.org/D114005 causes this particular SEGV while using Archer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115328

Files:
  openmp/tools/archer/ompt-tsan.cpp


Index: openmp/tools/archer/ompt-tsan.cpp
===================================================================
--- openmp/tools/archer/ompt-tsan.cpp
+++ openmp/tools/archer/ompt-tsan.cpp
@@ -1001,20 +1001,22 @@
   if (ndeps > 0) {
     // Copy the data to use it in task_switch and task_end.
     TaskData *Data = ToTaskData(task_data);
-    if (!Data->Parent->DependencyMap)
+    if (Data->Parent != nullptr && !Data->Parent->DependencyMap)
       Data->Parent->DependencyMap =
           new std::unordered_map<void *, DependencyData *>();
     Data->Dependencies =
         (TaskDependency *)malloc(sizeof(TaskDependency) * ndeps);
     Data->DependencyCount = ndeps;
     for (int i = 0; i < ndeps; i++) {
-      auto ret = Data->Parent->DependencyMap->insert(
-          std::make_pair(deps[i].variable.ptr, nullptr));
-      if (ret.second) {
-        ret.first->second = DependencyData::New();
+      if (Data->Parent != nullptr) {
+        auto ret = Data->Parent->DependencyMap->insert(
+            std::make_pair(deps[i].variable.ptr, nullptr));
+        if (ret.second) {
+          ret.first->second = DependencyData::New();
+        }
+        new ((void *)(Data->Dependencies + i))
+            TaskDependency(ret.first->second, deps[i].dependence_type);
       }
-      new ((void *)(Data->Dependencies + i))
-          TaskDependency(ret.first->second, deps[i].dependence_type);
     }
 
     // This callback is executed before this task is first started.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115328.392698.patch
Type: text/x-patch
Size: 1472 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20211208/d06bd114/attachment.bin>


More information about the Openmp-commits mailing list