This is an archive of the discontinued LLVM Phabricator instance.

[libunwind][AIX] Save/restore errno before/after system calls dlopen/dlsym/dlclose
ClosedPublic

Authored by xingxue on Aug 5 2022, 1:49 PM.

Details

Summary

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.

Diff Detail

Event Timeline

xingxue created this revision.Aug 5 2022, 1:49 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 5 2022, 1:49 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
xingxue requested review of this revision.Aug 5 2022, 1:49 PM
xingxue edited the summary of this revision. (Show Details)Aug 5 2022, 3:11 PM

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.

compnerd requested changes to this revision.Aug 8 2022, 8:49 AM
This revision now requires changes to proceed.Aug 8 2022, 8:49 AM

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.

xingxue updated this revision to Diff 450845.Aug 8 2022, 10:05 AM

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.

compnerd accepted this revision.Aug 8 2022, 1:21 PM

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.

This revision is now accepted and ready to land.Aug 8 2022, 1:21 PM