From ea27702addaf51979db073e697c08fefaa619e44 Mon Sep 17 00:00:00 2001 From: Rainer Orth Date: Mon, 2 Jun 2025 14:42:17 +0200 Subject: [PATCH] [OpenMP] Don't use libproc on Solaris `openmp` currently doesn't compile on 32-bit Solaris: ``` FAILED: projects/openmp/runtime/src/CMakeFiles/omp.dir/z_Linux_util.cpp.o [...] In file included from openmp/runtime/src/z_Linux_util.cpp:78: In file included from /usr/include/libproc.h:25: In file included from /usr/include/gelf.h:10: /usr/include/libelf.h:22:2: error: "large files are not supported by libelf" 22 | #error "large files are not supported by libelf" | ^ In file included from openmp/runtime/src/z_Linux_util.cpp:78: /usr/include/libproc.h:42:2: error: "Cannot use libproc in the large file compilation environment" 42 | #error "Cannot use libproc in the large file compilation environment" | ^ ``` Looking closer, there's no point in using `Pgrab` (the only interface from ``) at all: the resulting `ps_prochandle_t *` isn't used in the remainder of the code and the original PR #82930 gives no indication why it is deemed necessary/useful. While at it, this patch switches to use `/proc/self/xmap`, matching `compiler-rt`'s `sanitizer_procmaps_solaris.cpp`, and makes some minor formatting fixes. Tested on `sparc-sun-solaris2.11`, `sparcv9-sun-solaris2.11`, `i386-pc-solaris2.11`, and `amd64-pc-solaris2.11`. --- openmp/runtime/cmake/LibompHandleFlags.cmake | 3 -- openmp/runtime/src/z_Linux_util.cpp | 30 +++++++------------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/openmp/runtime/cmake/LibompHandleFlags.cmake b/openmp/runtime/cmake/LibompHandleFlags.cmake index cb7e488652230..470f94ee90cbf 100644 --- a/openmp/runtime/cmake/LibompHandleFlags.cmake +++ b/openmp/runtime/cmake/LibompHandleFlags.cmake @@ -149,9 +149,6 @@ function(libomp_get_libflags libflags) endif() elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|NetBSD|SunOS") libomp_append(libflags_local -lm) - if (${CMAKE_SYSTEM_NAME} STREQUAL "SunOS") - libomp_append(libflags_local "-lproc") - endif() endif() set(libflags_local ${libflags_local} ${LIBOMP_LIBFLAGS}) libomp_setup_flags(libflags_local) diff --git a/openmp/runtime/src/z_Linux_util.cpp b/openmp/runtime/src/z_Linux_util.cpp index 3b82b45e24405..368c0b6e872cc 100644 --- a/openmp/runtime/src/z_Linux_util.cpp +++ b/openmp/runtime/src/z_Linux_util.cpp @@ -75,7 +75,6 @@ #include #endif #elif KMP_OS_SOLARIS -#include #include #include #include @@ -2232,43 +2231,34 @@ int __kmp_is_address_mapped(void *addr) { kvm_close(fd); #elif KMP_OS_SOLARIS - prmap_t *cur, *map; + prxmap_t *cur, *map; void *buf; uintptr_t uaddr; ssize_t rd; - int err; - int file; - + int fd; pid_t pid = getpid(); - struct ps_prochandle *fd = Pgrab(pid, PGRAB_RDONLY, &err); - ; - - if (!fd) { - return 0; - } - - char *name = __kmp_str_format("/proc/%d/map", pid); - size_t sz = (1 << 20); - file = open(name, O_RDONLY); - if (file == -1) { + char *name = __kmp_str_format("/proc/%d/xmap", pid); + fd = open(name, O_RDONLY); + if (fd == -1) { KMP_INTERNAL_FREE(name); return 0; } + size_t sz = (1 << 20); buf = KMP_INTERNAL_MALLOC(sz); - while (sz > 0 && (rd = pread(file, buf, sz, 0)) == sz) { + while (sz > 0 && (rd = pread(fd, buf, sz, 0)) == sz) { void *newbuf; sz <<= 1; newbuf = KMP_INTERNAL_REALLOC(buf, sz); buf = newbuf; } - map = reinterpret_cast(buf); + map = reinterpret_cast(buf); uaddr = reinterpret_cast(addr); for (cur = map; rd > 0; cur++, rd = -sizeof(*map)) { - if ((uaddr >= cur->pr_vaddr) && (uaddr < cur->pr_vaddr)) { + if (uaddr >= cur->pr_vaddr && uaddr < cur->pr_vaddr) { if ((cur->pr_mflags & MA_READ) != 0 && (cur->pr_mflags & MA_WRITE) != 0) { found = 1; break; @@ -2277,7 +2267,7 @@ int __kmp_is_address_mapped(void *addr) { } KMP_INTERNAL_FREE(map); - close(file); + close(fd); KMP_INTERNAL_FREE(name); #elif KMP_OS_DARWIN