This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Avoid duplicate vdso modules when opening core files
ClosedPublic

Authored by labath on Mar 29 2022, 8:35 AM.

Details

Summary

When opening core files (and also in some other situations) we could end
up with two vdso modules. This could happen because the vdso module is
very special, and over the years, we have accumulated various ways to
load it.

In D10800, we added one mechanism for loading it, which took the form of
a generic load-from-memory capability. Unfortunately loading an elf file
from memory is not possible (because the loader never loads the entire
file), and our attempts to do so were causing crashes. So, in D34352, we
partially reverted D10800 and implemented a custom mechanism specific to
the vdso.

Unfortunately, enough of D10800 remained such that, under the right
circumstances, it could end up loading a second (non-functional) copy of
the vdso module. This happened when the process plugin did not support
the extended MemoryRegionInfo query (added in D22219, to workaround a
different bug), which meant that the loader plugin was not able to
recognise that the linux-vdso.so.1 module (this is how the loader calls
it) is in fact the same as the [vdso] module (the name used in
/proc/$PID/maps) we loaded before. This typically happened in a core
file, as they don't store this kind of information.

This patch fixes the issue by completing the revert of D10800 -- the
memory loading code is removed completely. It also reduces the scope of
the hackaround introduced in D22219 -- it isn't completely sound and is
only relevant for fairly old (but still supported) versions of android.

I added the memory loading logic to the wasm dynamic loader, which has
since appeared and is relying on this feature (it even has a test). As
far as I can tell loading wasm modules from memory is possible and
reliable. MachO memory loading is not affected by this patch, as it uses
a completely different code path.

Since the scenarios/patches I described came without test cases, I have
created two new gdb-client tests cases for them. They're not
particularly readable, but right now, this is the best way we can
simulate the behavior (bugs) of a particular dynamic linker.

Diff Detail

Event Timeline

labath created this revision.Mar 29 2022, 8:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2022, 8:35 AM
labath requested review of this revision.Mar 29 2022, 8:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2022, 8:35 AM
Herald added a subscriber: aheejin. · View Herald Transcript
mgorny accepted this revision.Apr 4 2022, 1:36 PM

Well, I don't see anything wrong with it and it doesn't seem to cause any regressions on FreeBSD. I wouldn't call myself an expert on this though.

This revision is now accepted and ready to land.Apr 4 2022, 1:36 PM
clayborg accepted this revision.Apr 4 2022, 2:35 PM

We have seen this issue as well in linux, so thanks for fixing it. I never did any of the work on the posix dyld loader so I had been avoiding trying to fix this.

This revision was automatically updated to reflect the committed changes.