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

Xing Xue via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 8 10:05:25 PDT 2022


xingxue updated this revision to Diff 450845.
xingxue added a comment.

> I'm not opposed to the change, but I wonder if we should consider placing this in an #if defined(_AIX) guard. This would avoid touching errno on other platforms, which would likely > be a TLS access. It would also make it more obvious that this is a workaround for AIX. At the very least, I think that we should add some comments to explain the issue so that it is > obvious at the site rather than having to go through the change log.

Thanks for your comments, Saleem! I've added comments to describe the workaround.  As to guarding the workaround with `#if defined(_AIX)`, I thought the code block containing the workaround is guarded by `#if defined(_LIBUNWIND_SUPPORT_TBTAB_UNWIND)`, which is only enabled on AIX so it won't affect other platforms. If you think it is better to use `#if defined(_AIX)` to highlight it is for AIX only, I can do that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131292/new/

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,11 @@
           // using dlopen().
           const char libcxxabi[] = "libc++abi.a(libc++abi.so.1)";
           void *libHandle;
+          // The AIX dlopen() sets errno to 0 when it is successful, which
+          // clobbers the value of errno from the user code. This is an AIX
+          // bug because according POSIX it should not set errno to 0. To
+          // workaround before AIX fixes the bug, errno is saved and restored.
+          int saveErrno = errno;
           libHandle = dlopen(libcxxabi, RTLD_MEMBER | RTLD_NOW);
           if (libHandle == NULL) {
             _LIBUNWIND_TRACE_UNWINDING("dlopen() failed with errno=%d\n",
@@ -2119,6 +2124,7 @@
             assert(0 && "dlsym() failed");
           }
           dlclose(libHandle);
+          errno = saveErrno;
         }
       }
       xlcPersonalityV0InitLock.unlock();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131292.450845.patch
Type: text/x-patch
Size: 1045 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220808/85054bdd/attachment.bin>


More information about the llvm-commits mailing list