From eb447b7b4bd6177f876ba9420ad9e048c27bae91 Mon Sep 17 00:00:00 2001 From: David Kilroy Date: Wed, 12 Feb 2020 14:28:15 -0300 Subject: elf: Allow dlopen of filter object to work [BZ #16272] There are two fixes that are needed to be able to dlopen filter objects. First _dl_map_object_deps cannot assume that map will be at the beginning of l_searchlist.r_list[], as filtees are inserted before map. Secondly dl_open_worker needs to ensure that filtees get relocated. In _dl_map_object_deps: * avoiding removing relocation dependencies of map by setting l_reserved to 0 and otherwise processing the rest of the search list. * ensure that map remains at the beginning of l_initfini - the list of things that need initialisation (and destruction). Do this by splitting the copy up. This may not be required, but matches the initialization order without dlopen. Modify dl_open_worker to relocate the objects in new->l_inifini. new->l_initfini is constructed in _dl_map_object_deps, and lists the objects that need initialization and destruction. Originally the list of objects in new->l_next are relocated. All of these objects should also be included in new->l_initfini (both lists are populated with dependencies in _dl_map_object_deps). We can't use new->l_prev to pick up filtees, as during a recursive dlopen from an interposed malloc call, l->prev can contain objects that are not ready for relocation. Add tests to verify that symbols resolve to the filtee implementation when auxiliary and filter objects are used, both as a normal link and when dlopen'd. Tested by running the testsuite on x86_64. --- elf/Makefile | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'elf/Makefile') diff --git a/elf/Makefile b/elf/Makefile index 632a4d8b0f..dfd43fb39b 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -201,7 +201,8 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \ tst-unwind-ctor tst-unwind-main tst-audit13 \ tst-sonamemove-link tst-sonamemove-dlopen tst-dlopen-tlsmodid \ tst-dlopen-self tst-auditmany tst-initfinilazyfail tst-dlopenfail \ - tst-dlopenfail-2 + tst-dlopenfail-2 \ + tst-filterobj tst-filterobj-dlopen tst-auxobj tst-auxobj-dlopen # reldep9 tests-internal += loadtest unload unload2 circleload1 \ neededtest neededtest2 neededtest3 neededtest4 \ @@ -312,7 +313,8 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \ tst-auditmanymod7 tst-auditmanymod8 tst-auditmanymod9 \ tst-initlazyfailmod tst-finilazyfailmod \ tst-dlopenfailmod1 tst-dlopenfaillinkmod tst-dlopenfailmod2 \ - tst-dlopenfailmod3 tst-ldconfig-ld-mod + tst-dlopenfailmod3 tst-ldconfig-ld-mod \ + tst-filterobj-flt tst-filterobj-aux tst-filterobj-filtee # Most modules build with _ISOMAC defined, but those filtered out # depend on internal headers. modules-names-tests = $(filter-out ifuncmod% tst-libc_dlvsym-dso tst-tlsmod%,\ @@ -1699,3 +1701,15 @@ LDFLAGS-tst-dlopen-nodelete-reloc-mod17.so = -Wl,--no-as-needed $(objpfx)tst-ldconfig-ld_so_conf-update.out: $(objpfx)tst-ldconfig-ld-mod.so $(objpfx)tst-ldconfig-ld_so_conf-update: $(libdl) + +LDFLAGS-tst-filterobj-flt.so = -Wl,--filter=$(objpfx)tst-filterobj-filtee.so +$(objpfx)tst-filterobj: $(objpfx)tst-filterobj-flt.so +$(objpfx)tst-filterobj-dlopen: $(libdl) +$(objpfx)tst-filterobj.out: $(objpfx)tst-filterobj-filtee.so +$(objpfx)tst-filterobj-dlopen.out: $(objpfx)tst-filterobj-filtee.so + +LDFLAGS-tst-filterobj-aux.so = -Wl,--auxiliary=$(objpfx)tst-filterobj-filtee.so +$(objpfx)tst-auxobj: $(objpfx)tst-filterobj-aux.so +$(objpfx)tst-auxobj-dlopen: $(libdl) +$(objpfx)tst-auxobj.out: $(objpfx)tst-filterobj-filtee.so +$(objpfx)tst-auxobj-dlopen.out: $(objpfx)tst-filterobj-filtee.so -- cgit 1.4.1