[OpenMP] Create a temp file in /tmp if /dev/shm is not accessible
authorShilei Tian <i@tianshilei.me>
Wed, 25 Jan 2023 02:45:32 +0000 (21:45 -0500)
committerShilei Tian <i@tianshilei.me>
Wed, 25 Jan 2023 02:45:38 +0000 (21:45 -0500)
commitdafebd5b5a08dde25f5f52f65cac54bd6ec0ecde
treee3d4594689e22ef0e2719e3b1c125506c4600c22
parent56313f65cce71366fdc659d1d08e0eeaa5d40b63
[OpenMP] Create a temp file in /tmp if /dev/shm is not accessible

When `libomp` is initialized, it creates a temp file in `/dev/shm` to store
registration flag. Some systems, like Android, don't have `/dev/shm`, then this
feature is disabled by the macro `KMP_USE_SHM`, though most Linux distributions
have that. However, some customized distribution, such as the one reported in
https://github.com/llvm/llvm-project/issues/53955, doesn't support it either.
It causes a core dump. In this patch, if it is the case, we will try to create a
temporary file in `/tmp`, and if it still doesn't make it, then we error out.
Note that we don't consider in this patch if the temporary directory has been
set to `TMPDIR` in this patch. If `/tmp` is not accessible, we error out.

Fix #53955.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D142175
openmp/runtime/src/kmp_runtime.cpp