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/tst-auxobj-dlopen.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 elf/tst-auxobj-dlopen.c (limited to 'elf/tst-auxobj-dlopen.c') diff --git a/elf/tst-auxobj-dlopen.c b/elf/tst-auxobj-dlopen.c new file mode 100644 index 0000000..cb54aba --- /dev/null +++ b/elf/tst-auxobj-dlopen.c @@ -0,0 +1,47 @@ +/* Test for BZ#16272, dlopen'ing an auxiliary filter object. + Ensure that symbols from the resolve correctly. + + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +static int do_test (void) +{ + void *lib = xdlopen ("tst-filterobj-aux.so", RTLD_LAZY); + char *(*fn)(void) = xdlsym (lib, "get_text"); + const char* text = fn (); + + printf ("%s\n", text); + + /* Verify the text matches what we expect from the filtee */ + TEST_COMPARE_STRING (text, "Hello from filtee (PASS)"); + + fn = xdlsym (lib, "get_text2"); + text = fn (); + + printf ("%s\n", text); + + /* Verify the text matches what we expect from the auxiliary object */ + TEST_COMPARE_STRING (text, "Hello from auxiliary filter object (PASS)"); + + return 0; +} + +#include -- cgit v1.1