[libcxx-commits] [PATCH] D131292: [libunwind][AIX] Save/restore errno before/after system calls dlopen/dlsym/dlclose

Xing Xue via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Aug 5 13:50:00 PDT 2022


xingxue created this revision.
xingxue added reviewers: MaskRay, compnerd, cebowleratibm, hubert.reinterpretcast.
xingxue added a project: LLVM.
Herald added subscribers: libcxx-commits, StephenFan.
Herald added projects: libunwind, All.
Herald added a reviewer: libunwind.
xingxue requested review of this revision.
Herald added a subscriber: llvm-commits.

libunwind on AIX calls `dlopen()/dlsym()/dlclose()` to dynamically load `libc++abi` and get the personality for state table EH when it is running against the legacy `xlcang++` compiler genereated applications. `dlopen()/dlsym()/dlclose()` set `errno` to 0 when they are successful, which clobbers the value in `errno` from the user code. This patch saves and restores `errno` before and after these calls.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131292

Files:
  libunwind/src/UnwindCursor.hpp


Index: libunwind/src/UnwindCursor.hpp
===================================================================
--- libunwind/src/UnwindCursor.hpp
+++ libunwind/src/UnwindCursor.hpp
@@ -2106,6 +2106,7 @@
           // using dlopen().
           const char libcxxabi[] = "libc++abi.a(libc++abi.so.1)";
           void *libHandle;
+          int saveErrno = errno;
           libHandle = dlopen(libcxxabi, RTLD_MEMBER | RTLD_NOW);
           if (libHandle == NULL) {
             _LIBUNWIND_TRACE_UNWINDING("dlopen() failed with errno=%d\n",
@@ -2119,6 +2120,7 @@
             assert(0 && "dlsym() failed");
           }
           dlclose(libHandle);
+          errno = saveErrno;
         }
       }
       xlcPersonalityV0InitLock.unlock();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131292.450371.patch
Type: text/x-patch
Size: 736 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220805/a65ae487/attachment.bin>


More information about the libcxx-commits mailing list