ladybird/Userland/Libraries/LibELF
Rodrigo Tobar 4b091a7cc2 LibELF: Fix dynamic linking of dlopen()-ed libs
Consider the situation where two shared libraries libA and libB, both
depending (as in having a NEEDED dtag) on libC. libA is first
dlopen()-ed, which produces libC to be mapped and linked. When libB is
dlopen()-ed the DynamicLinker would re-map and re-link libC though,
causing any previous references to its old location to be invalid. And
if libA's PLT has been patched to point to libC's symbols, then any
further invocations to libA will cause the code to jump to a virtual
address that isn't mapped anymore, therefore causing a crash. This
situation was reported in #10014, although the setup was more convolved
in the ticket.

This commit fixes the issue by distinguishing between a main program
loading being performed by Loader.so, and a dlopen() call. The main
difference between these two cases is that in the former the
s_globals_objects maps is always empty, while in the latter it might
already contain dependencies for the library being dlopen()-ed. Hence,
when collecting dependencies to map and link, dlopen() should skip those
that are present in the global map to avoid the issue described above.

With this patch the original issue seen in #10014 is gone, with all
python3 modules (so far) loading correctly.

A unit test reproducing a simplified issue is also included in this
commit. The unit test includes the building of two dynamic libraries A
and B with both depending on libline.so (and B also depending on A); the
test then dlopen()s libA, invokes one its function, then does the same
with libB.
2021-10-06 12:33:21 +02:00
..
Arch CMake: Let Meta/serenity.sh run aarch64 make it past cmake 2021-08-28 14:43:07 +01:00
AuxiliaryVector.h LibELF: Use StringView to carry temporary strings in auxiliary vector 2021-09-07 13:53:14 +02:00
CMakeLists.txt LibELF+LibTest: Fix serenity_install_sources() paths 2021-03-15 09:06:10 +01:00
Core.h Everywhere: Core dump => Coredump 2021-08-23 00:02:09 +02:00
DynamicLinker.cpp LibELF: Fix dynamic linking of dlopen()-ed libs 2021-10-06 12:33:21 +02:00
DynamicLinker.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
DynamicLoader.cpp LibELF: Name non-executable map regions ".rodata" instead of ".text" 2021-09-04 20:30:56 +02:00
DynamicLoader.h LibELF: Swap the arguments for negative_offset_from_tls_block_end 2021-07-04 01:07:28 +02:00
DynamicObject.cpp LibELF: Indicate value of unimplemented dtag 2021-09-26 12:45:55 +02:00
DynamicObject.h LibELF+readelf: Remove duplicated dtag->string map 2021-09-26 12:45:55 +02:00
Hashes.h AK+Userland: Use akaster@serenityos.org for my copyright headers 2021-05-30 14:35:34 +01:00
Image.cpp LibELF+Utilities: Avoid truncating 64-bit values 2021-07-22 08:57:01 +02:00
Image.h LibELF: Use default instead of an empty constructor/destructor 2021-09-16 17:17:13 +02:00
Relocation.cpp LibELF: Fix unaligned writes in the relocation code 2021-07-27 13:15:16 +02:00
Relocation.h DynamicLoader+LibELF: Move self-relocation code into a separate file 2021-07-27 13:15:16 +02:00
Validation.cpp LibELF: Allow (but ignore) PT_LOAD headers with zero size 2021-08-31 16:46:16 +02:00
Validation.h Kernel+LibELF: Add support for validating and loading ELF64 executables 2021-06-28 22:29:28 +02:00