This is an archive of the discontinued LLVM Phabricator instance.

[lldb/dyld-posix] Avoid reading the module list in inconsistent states
ClosedPublic

Authored by labath on Jun 21 2022, 5:25 AM.

Details

Summary

New glibc versions (since 2.34 or including this
https://github.com/bminor/glibc/commit/ed3ce71f5c64c5f07cbde0ef03554ea8950d8f2c
patch) trigger the rendezvous breakpoint after they have already added
some modules to the list. This did not play well with our dynamic
loader plugin which was doing a diff of the the reported modules in the
before (RT_ADD) and after (RT_CONSISTENT) states. Specifically, it
caused us to miss some of the modules.

While I think the old behavior makes more sense, I don't think that lldb
is doing the right thing either, as the documentation states that we
should not be expecting a consistent view in the RT_ADD (and RT_DELETE)
states.

Therefore, this patch changes the lldb algorithm to compare the module
list against the previous consistent snapshot. This fixes the previous
issue, and I believe it is more correct in general. It also reduces the
number of times we are fetching the module info, which should speed up
the debugging of processes with many shared libraries.

The change in RefreshModules ensures we don't broadcast the loaded
notification for the dynamic loader (ld.so) module more than once.

Diff Detail

Event Timeline

labath created this revision.Jun 21 2022, 5:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2022, 5:25 AM
labath requested review of this revision.Jun 21 2022, 5:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2022, 5:25 AM

@emrekultursay: Mainly added you in case you want to try this out on android.

lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
425

@mgorny: I suspect this workaround may no longer be needed.

(This was breaking several shared library tests, most notably TestLoadUnload)

Mainly added you in case you want to try this out on android.

Thanks. I tested this on a few Android API levels, and it looks good to me.

lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
441

Use this variable below, instead of calling lock() again?

labath updated this revision to Diff 439277.Jun 23 2022, 1:47 AM

reuse the module pointer

labath marked an inline comment as done.Jun 23 2022, 1:47 AM
labath added inline comments.
lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
441

Yes. In fact, that's why I created that variable in the first place. :)

labath marked an inline comment as done.Jun 28 2022, 7:18 AM

@mgorny, ping. Do you maybe want to try this out on freebsd?

mgorny accepted this revision.Jun 30 2022, 9:38 AM

The patch itself looks good, however the workaround seems still required on FreeBSD.

lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
425

Well, unless I've done it wrong, removing it causes a lot of test regressions.

This revision is now accepted and ready to land.Jun 30 2022, 9:38 AM
labath marked an inline comment as done.Jun 30 2022, 11:01 PM
labath added inline comments.
lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
425

That is unfortunate, but thanks for checking it out. I still suspect there is some way we could tweak the code to make this unnecessary (IIUC, the main problem here was the lack of an "add" notification but this patch essentially makes lldb ignore all add notifications), but it needs more investigation.

This revision was automatically updated to reflect the committed changes.
labath marked an inline comment as done.