Skip to content

Commit ba4f140

Browse files
authored
[OpenMP] Don't use libproc on Solaris (#142379)
`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 `<libproc.h>`) 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`.
1 parent 370d017 commit ba4f140

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

openmp/runtime/cmake/LibompHandleFlags.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ function(libomp_get_libflags libflags)
149149
endif()
150150
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|NetBSD|SunOS")
151151
libomp_append(libflags_local -lm)
152-
if (${CMAKE_SYSTEM_NAME} STREQUAL "SunOS")
153-
libomp_append(libflags_local "-lproc")
154-
endif()
155152
endif()
156153
set(libflags_local ${libflags_local} ${LIBOMP_LIBFLAGS})
157154
libomp_setup_flags(libflags_local)

openmp/runtime/src/z_Linux_util.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
#include <pthread_np.h>
7676
#endif
7777
#elif KMP_OS_SOLARIS
78-
#include <libproc.h>
7978
#include <procfs.h>
8079
#include <thread.h>
8180
#include <sys/loadavg.h>
@@ -2232,43 +2231,34 @@ int __kmp_is_address_mapped(void *addr) {
22322231

22332232
kvm_close(fd);
22342233
#elif KMP_OS_SOLARIS
2235-
prmap_t *cur, *map;
2234+
prxmap_t *cur, *map;
22362235
void *buf;
22372236
uintptr_t uaddr;
22382237
ssize_t rd;
2239-
int err;
2240-
int file;
2241-
2238+
int fd;
22422239
pid_t pid = getpid();
2243-
struct ps_prochandle *fd = Pgrab(pid, PGRAB_RDONLY, &err);
2244-
;
2245-
2246-
if (!fd) {
2247-
return 0;
2248-
}
2249-
2250-
char *name = __kmp_str_format("/proc/%d/map", pid);
2251-
size_t sz = (1 << 20);
2252-
file = open(name, O_RDONLY);
2253-
if (file == -1) {
2240+
char *name = __kmp_str_format("/proc/%d/xmap", pid);
2241+
fd = open(name, O_RDONLY);
2242+
if (fd == -1) {
22542243
KMP_INTERNAL_FREE(name);
22552244
return 0;
22562245
}
22572246

2247+
size_t sz = (1 << 20);
22582248
buf = KMP_INTERNAL_MALLOC(sz);
22592249

2260-
while (sz > 0 && (rd = pread(file, buf, sz, 0)) == sz) {
2250+
while (sz > 0 && (rd = pread(fd, buf, sz, 0)) == sz) {
22612251
void *newbuf;
22622252
sz <<= 1;
22632253
newbuf = KMP_INTERNAL_REALLOC(buf, sz);
22642254
buf = newbuf;
22652255
}
22662256

2267-
map = reinterpret_cast<prmap_t *>(buf);
2257+
map = reinterpret_cast<prxmap_t *>(buf);
22682258
uaddr = reinterpret_cast<uintptr_t>(addr);
22692259

22702260
for (cur = map; rd > 0; cur++, rd = -sizeof(*map)) {
2271-
if ((uaddr >= cur->pr_vaddr) && (uaddr < cur->pr_vaddr)) {
2261+
if (uaddr >= cur->pr_vaddr && uaddr < cur->pr_vaddr) {
22722262
if ((cur->pr_mflags & MA_READ) != 0 && (cur->pr_mflags & MA_WRITE) != 0) {
22732263
found = 1;
22742264
break;
@@ -2277,7 +2267,7 @@ int __kmp_is_address_mapped(void *addr) {
22772267
}
22782268

22792269
KMP_INTERNAL_FREE(map);
2280-
close(file);
2270+
close(fd);
22812271
KMP_INTERNAL_FREE(name);
22822272
#elif KMP_OS_DARWIN
22832273

0 commit comments

Comments
 (0)