hanchenye-llvm-project/openmp/tools/archer
RitanyaB 378b0ac179 SIGSEGV in ompt_tsan_dependences with for-ordered
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.

Reviewed By: protze.joachim

Differential Revision: https://reviews.llvm.org/D115328
2022-01-03 11:23:57 -06:00
..
tests [OpenMP][Tools][NFC] Make an Archer test more robust 2021-10-15 17:32:05 +02:00
CMakeLists.txt
README.md [OpenMP][Tools] Cleanup memory pool used in Archer 2021-06-09 13:36:19 +02:00
ompt-tsan.cpp SIGSEGV in ompt_tsan_dependences with for-ordered 2022-01-03 11:23:57 -06:00

README.md

License

Archer is distributed under the terms of the Apache License.

Please see LICENSE.txt for usage terms.

LLNL-CODE-773957

Introduction

Archer is an OMPT tool which annotates OpenMP synchronization semantics for data race detection. This avoids false alerts in data race detection. Archer is automatically loaded for OpenMP applications which are compiled with ThreadSanitizer option.

Build Archer within Clang/LLVM

This distribution of Archer is automatically built with the OpenMP runtime and automatically loaded by the OpenMP runtime.

Usage

How to compile

To use archer, compile the application with the extra flag -fsanitize=thread:

clang -O3 -g -fopenmp -fsanitize=thread app.c
clang++ -O3 -g -fopenmp -fsanitize=thread app.cpp

To compile Fortran applications, compile with gfortran, link with clang:

gfortran -g -c -fopenmp -fsanitize=thread app.f
clang -fopenmp -fsanitize=thread app.o -lgfortran

Runtime Flags

TSan runtime flags are passed via TSAN_OPTIONS environment variable, we highly recommend the following option to avoid false alerts for the OpenMP or MPI runtime implementation:

export TSAN_OPTIONS="ignore_noninstrumented_modules=1"

Runtime flags are passed via ARCHER_OPTIONS environment variable, different flags are separated by spaces, e.g.:

ARCHER_OPTIONS="flush_shadow=1" ./myprogram
Flag Name Default value Description
flush_shadow 0 Flush shadow memory at the end of an outer OpenMP parallel region. Our experiments show that this can reduce memory overhead by ~30% and runtime overhead by ~10%. This flag is useful for large OpenMP applications that typically require large amounts of memory, causing out-of-memory exceptions when checked by Archer.
print_max_rss 0 Print the RSS memory peak at the end of the execution.
ignore_serial 0 Turn off tracking and analysis of memory accesses in the sequential part of an OpenMP program. (Only effective when OpenMP runtime is initialized. In doubt, insert omp_get_max_threads() as first statement in main!)
report_data_leak 0 Report leaking OMPT data for execution under Archer. Used for testing and debugging Archer if errors occur.
verbose 0 Print startup information.
enable 1 Use Archer runtime library during execution.

Example

Let us take the program below and follow the steps to compile and check the program for data races.

Suppose our program is called myprogram.c:

 1  #include <stdio.h>
 2
 3  #define N 1000
 4
 5  int main (int argc, char **argv)
 6  {
 7    int a[N];
 8
 9  #pragma omp parallel for
10    for (int i = 0; i < N - 1; i++) {
11      a[i] = a[i + 1];
12    }
13  }

We compile the program as follow:

clang -fsanitize=thread -fopenmp -g myprogram.c -o myprogram

Now we can run the program with the following commands:

export OMP_NUM_THREADS=2
./myprogram

Archer will output a report in case it finds data races. In our case the report will look as follow:

==================
WARNING: ThreadSanitizer: data race (pid=13641)
  Read of size 4 at 0x7fff79a01170 by main thread:
    #0 .omp_outlined. myprogram.c:11:12 (myprogram+0x00000049b5a2)
    #1 __kmp_invoke_microtask <null> (libomp.so+0x000000077842)
    #2 __libc_start_main /build/glibc-t3gR2i/glibc-2.23/csu/../csu/libc-start.c:291 (libc.so.6+0x00000002082f)

  Previous write of size 4 at 0x7fff79a01170 by thread T1:
    #0 .omp_outlined. myprogram.c:11:10 (myprogram+0x00000049b5d6)
    #1 __kmp_invoke_microtask <null> (libomp.so+0x000000077842)

  Location is stack of main thread.

  Thread T1 (tid=13643, running) created by main thread at:
    #0 pthread_create tsan_interceptors.cc:902:3 (myprogram+0x00000043db75)
    #1 __kmp_create_worker <null> (libomp.so+0x00000006c364)
    #2 __libc_start_main /build/glibc-t3gR2i/glibc-2.23/csu/../csu/libc-start.c:291 (libc.so.6+0x00000002082f)

SUMMARY: ThreadSanitizer: data race myprogram.c:11:12 in .omp_outlined.
==================
ThreadSanitizer: reported 1 warnings

Contacts and Support