This is an archive of the discontinued LLVM Phabricator instance.

Problem with realpath interceptor
Needs RevisionPublic

Authored by jakubjelinek on Aug 10 2021, 5:24 AM.

Details

Summary

tsan in some cases (e.g. after fork from multithreaded program, which arguably is problematic) increments ignore_interceptors and in that case runs just the intercepted functions and not their wrappers.
For realpath the interceptor handles the resolved_path == nullptr case though and so when ignore_interceptors is non-zero, realpath (".", nullptr) will fail instead of succeeding.
This patch uses instead the COMMON_INTERCEPT_FUNCTION_GLIBC_VER_MIN macro to use realpath@@GLIBC_2.3 whenever possible (if not, then it is likely a glibc architecture
with more recent oldest symbol version than 2.3, for which any realpath in glibc will DTRT, or unsupported glibc older than 2.3), which never supported NULL as second argument.

Diff Detail

Event Timeline

jakubjelinek requested review of this revision.Aug 10 2021, 5:24 AM
jakubjelinek created this revision.
Herald added a subscriber: Restricted Project. · View Herald TranscriptAug 10 2021, 5:24 AM
dvyukov accepted this revision.Aug 10 2021, 7:07 AM

Hi Jakub,
I don't remember if you have commit access or not. Do you want me to land this?

This revision is now accepted and ready to land.Aug 10 2021, 7:07 AM

I don't remember if you have commit access or not. Do you want me to land this?

I don't have access. So yes, please commit this.

This revision was landed with ongoing or failed builds.Aug 10 2021, 7:29 AM
This revision was automatically updated to reflect the committed changes.

git commit --amend --author='name <email>' can be used for proper attribution in the future.

git commit --amend --author='name <email>' can be used for proper attribution in the future.

I used arc. I assumed it will do the right thing. It even asked about landing a patch by a different author.
Also I don't even see the email provided anywhere...

git commit --amend --author='name <email>' can be used for proper attribution in the future.

I used arc. I assumed it will do the right thing. It even asked about landing a patch by a different author.

arc patch D107819 does the right thing if the Differential was uploaded via arc diff 'HEAD^'.
It seems it isn't, so the author name/email are not tracked.

Also I don't even see the email provided anywhere...

I assume that you know Jakub's email... otherwise you may ask for the information:)

git commit --amend --author='name <email>' can be used for proper attribution in the future.

I used arc. I assumed it will do the right thing. It even asked about landing a patch by a different author.

arc patch D107819 does the right thing if the Differential was uploaded via arc diff 'HEAD^'.
It seems it isn't, so the author name/email are not tracked.

Also I don't even see the email provided anywhere...

I assume that you know Jakub's email... otherwise you may ask for the information:)

Thanks, will use in future.

vitalybuka reopened this revision.Aug 25 2021, 2:00 PM
vitalybuka added a reviewer: vitalybuka.
vitalybuka added a subscriber: vitalybuka.

I had to revert the patch because it breaks interceptor on some environments. I'll investigate the issue.

If TSAN issue is important to you, probably moving WRAP(malloc) workaround before COMMON_INTERCEPTOR_ENTER will fix it. I will accept the patch if are willing to try.
Could you also try to build some regression test for the TSAN issue?

This revision is now accepted and ready to land.Aug 25 2021, 2:00 PM
vitalybuka requested changes to this revision.Aug 25 2021, 2:01 PM
This revision now requires changes to proceed.Aug 25 2021, 2:01 PM

What kind of problems are you talking about? Is it that some non-glibc system wants also the NULL resolved_path handling and doesn't have it in the libc?
To be precise, the patch would work fine if only the INIT_REALPATH macro is changed to the COMMON_INTERCEPT_FUNCTION_GLIBC_VER_MIN macro, but no reordering will help,
the problem is that tsan disables the wrappers altogether at some points and then it only calls the original function. And it is crucial that the original function is the right one.

What kind of problems are you talking about? Is it that some non-glibc system wants also the NULL resolved_path handling and doesn't have it in the libc?

It's GLIBC, it has all functions, but COMMON_INTERCEPT_FUNCTION_GLIBC_VER_MIN fallbacks to the old one. Patch works without fallback, but it will break non-glibc cases.
E.g. it will work COMMON_INTERCEPT_FUNCTION_VER which does not fallback

Also fallback it's quite recent thing D96348