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() sets errno to 0 when it is successful, which clobbers the value in errno from the user code. This seems to be an AIX bug that it should not set errno to 0 according to POSIX. We will open a bug report to AIX but in the mean time there won't be time line when AIX will have a fix and even AIX does fix it, it won't help earlier AIX releases in the field. This patch saves and restores errno before and after these calls so that user code can work as expected.
Details
- Reviewers
MaskRay compnerd cebowleratibm hubert.reinterpretcast - Group Reviewers
Restricted Project - Commits
- rGcc8edbea7a5f: [libunwind][AIX] Save/restore errno before/after system calls…
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
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.
errno for other platforms should be untouched anyway... _LIBUNWIND_SUPPORT_TBTAB_UNWIND is only true (AFAIK) for AIX.
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.
Thanks for adding the comment! I think that being part of the traceback table support should be sufficiently isolated and that the additional conditional would be superfluous.