This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Create a temp file in /tmp if /dev/shm is not accessible
ClosedPublic

Authored by tianshilei1992 on Jan 19 2023, 9:18 PM.

Details

Summary

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.

Diff Detail

Event Timeline

tianshilei1992 created this revision.Jan 19 2023, 9:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2023, 9:18 PM
tianshilei1992 requested review of this revision.Jan 19 2023, 9:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2023, 9:18 PM
tianshilei1992 edited the summary of this revision. (Show Details)Jan 19 2023, 9:19 PM
tianshilei1992 edited the summary of this revision. (Show Details)

ping

openmp/runtime/src/kmp_runtime.cpp
27

Hmm, this should be removed. No idea where it comes from.

jdoerfert accepted this revision.Jan 24 2023, 2:37 PM

LG

openmp/runtime/src/kmp_runtime.cpp
6789–6801

start the comment in this line, not the line above

6918

KMP_DEBUG_ASSERT(temp_reg_status_file_name);

This revision is now accepted and ready to land.Jan 24 2023, 2:37 PM
tianshilei1992 marked 2 inline comments as done.

fix comments

sthibaul added inline comments.
openmp/runtime/src/kmp_runtime.cpp
6920

This is very obviously wrong (mixing fopen and O_RDONLY), and doesn't build:

/<<PKGBUILDDIR>>/openmp/runtime/src/kmp_runtime.cpp:6920:16: error: no matching function for call to 'fopen'
    FILE *tf = fopen(temp_reg_status_file_name, O_RDONLY);
               ^~~~~
/usr/include/stdio.h:270:26: note: candidate function not viable: no known conversion from 'int' to 'const char *__restrict' for 2nd argumen
extern FILE *__REDIRECT (fopen, (const char *__restrict __filename,

Actually, why using fopen at all? Rather use

fd1 = open(temp_reg_status_file_name, O_RDONLY);
if (fd1 == -1) {
  // give it up now
  return;
}

?

tianshilei1992 added inline comments.Feb 22 2023, 3:22 PM
openmp/runtime/src/kmp_runtime.cpp
6920

Thanks for pointing that out. I should have caught that. I'll fix it right now.