|
Packit Service |
6bec0b |
/* Test interactions of dlopen, NODELETE, and relocations.
|
|
Packit Service |
6bec0b |
Copyright (C) 2019 Free Software Foundation, Inc.
|
|
Packit Service |
6bec0b |
This file is part of the GNU C Library.
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
6bec0b |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
6bec0b |
License as published by the Free Software Foundation; either
|
|
Packit Service |
6bec0b |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
6bec0b |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
6bec0b |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
6bec0b |
Lesser General Public License for more details.
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
6bec0b |
License along with the GNU C Library; if not, see
|
|
Packit Service |
6bec0b |
<https://www.gnu.org/licenses/>. */
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
/* This test exercises NODELETE propagation due to data relocations
|
|
Packit Service |
6bec0b |
and unique symbols, and the interaction with already-loaded
|
|
Packit Service |
6bec0b |
objects. Some test objects are written in C++, to produce unique
|
|
Packit Service |
6bec0b |
symbol definitions.
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
First test: Global scope variant, data relocation as the NODELETE
|
|
Packit Service |
6bec0b |
trigger. mod1 is loaded first with a separate dlopen call.
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
mod2 ---(may_finalize_mod1 relocation dependency)---> mod1
|
|
Packit Service |
6bec0b |
(NODELETE) (marked as NODELETE)
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
Second test: Local scope variant, data relocation. mod3 is loaded
|
|
Packit Service |
6bec0b |
first, then mod5.
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
mod5 ---(DT_NEEDED)---> mod4 ---(DT_NEEDED)---> mod3
|
|
Packit Service |
6bec0b |
(NODELETE) (not NODELETE) ^
|
|
Packit Service |
6bec0b |
\ / (marked as
|
|
Packit Service |
6bec0b |
`--(may_finalize_mod3 relocation dependency)--/ NODELETE)
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
Third test: Shared local scope with unique symbol. mod6 is loaded
|
|
Packit Service |
6bec0b |
first, then mod7. No explicit dependencies between the two
|
|
Packit Service |
6bec0b |
objects, so first object has to be opened with RTLD_GLOBAL.
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
mod7 ---(unique symbol)---> mod6
|
|
Packit Service |
6bec0b |
(marked as NODELETE)
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
Forth test: Non-shared scopes with unique symbol. mod8 and mod10
|
|
Packit Service |
6bec0b |
are loaded from the main program. mod8 loads mod9 from an ELF
|
|
Packit Service |
6bec0b |
constructor, mod10 loads mod11. There are no DT_NEEDED
|
|
Packit Service |
6bec0b |
dependencies. mod9 is promoted to the global scope form the main
|
|
Packit Service |
6bec0b |
program. The unique symbol dependency is:
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
mod9 ---(unique symbol)---> mod11
|
|
Packit Service |
6bec0b |
(marked as NODELETE)
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
Fifth test: Shared local scope with unique symbol, like test 3, but
|
|
Packit Service |
6bec0b |
this time, there is also a DT_NEEDED dependency (so no RTLD_GLOBAL
|
|
Packit Service |
6bec0b |
needed):
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
DT_NEEDED
|
|
Packit Service |
6bec0b |
mod13 ---(unique symbol)---> mod12
|
|
Packit Service |
6bec0b |
(marked as NODELETE)
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
Sixth test: NODELETE status is retained after relocation failure
|
|
Packit Service |
6bec0b |
with unique symbol dependency. The object graph ensures that the
|
|
Packit Service |
6bec0b |
unique symbol binding is processed before the dlopen failure.
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
DT_NEEDED
|
|
Packit Service |
6bec0b |
mod17 --(DT_NEEDED)--> mod15 --(unique symbol)--> mod14
|
|
Packit Service |
6bec0b |
\ ^ (RTLD_NODELETE)
|
|
Packit Service |
6bec0b |
\ (DT_NEEDED)
|
|
Packit Service |
6bec0b |
\ |
|
|
Packit Service |
6bec0b |
`---(DT_NEEDED)--> mod16
|
|
Packit Service |
6bec0b |
(fails to relocate)
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
mod14 is loaded first, and the loading mod17 is attempted.
|
|
Packit Service |
6bec0b |
mod14 must remain NODELETE after opening mod17 failed. */
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
#include <stdio.h>
|
|
Packit Service |
6bec0b |
#include <string.h>
|
|
Packit Service |
6bec0b |
#include <stdbool.h>
|
|
Packit Service |
6bec0b |
#include <support/check.h>
|
|
Packit Service |
6bec0b |
#include <support/xdlfcn.h>
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
static int
|
|
Packit Service |
6bec0b |
do_test (void)
|
|
Packit Service |
6bec0b |
{
|
|
Packit Service |
6bec0b |
/* First case: global scope, regular data symbol. Open the object
|
|
Packit Service |
6bec0b |
which is not NODELETE initially. */
|
|
Packit Service |
6bec0b |
void *mod1 = xdlopen ("tst-dlopen-nodelete-reloc-mod1.so",
|
|
Packit Service |
6bec0b |
RTLD_NOW | RTLD_GLOBAL);
|
|
Packit Service |
6bec0b |
/* This is used to indicate that the ELF destructor may be
|
|
Packit Service |
6bec0b |
called. */
|
|
Packit Service |
6bec0b |
bool *may_finalize_mod1 = xdlsym (mod1, "may_finalize_mod1");
|
|
Packit Service |
6bec0b |
/* Open the NODELETE object. */
|
|
Packit Service |
6bec0b |
void *mod2 = xdlopen ("tst-dlopen-nodelete-reloc-mod2.so", RTLD_NOW);
|
|
Packit Service |
6bec0b |
/* This has no effect because the DSO is directly marked as
|
|
Packit Service |
6bec0b |
NODELETE. */
|
|
Packit Service |
6bec0b |
xdlclose (mod2);
|
|
Packit Service |
6bec0b |
/* This has no effect because the DSO has been indirectly marked as
|
|
Packit Service |
6bec0b |
NODELETE due to a relocation dependency. */
|
|
Packit Service |
6bec0b |
xdlclose (mod1);
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
/* Second case: local scope, regular data symbol. Open the object
|
|
Packit Service |
6bec0b |
which is not NODELETE initially. */
|
|
Packit Service |
6bec0b |
void *mod3 = xdlopen ("tst-dlopen-nodelete-reloc-mod3.so", RTLD_NOW);
|
|
Packit Service |
6bec0b |
bool *may_finalize_mod3 = xdlsym (mod3, "may_finalize_mod3");
|
|
Packit Service |
6bec0b |
/* Open the NODELETE object. */
|
|
Packit Service |
6bec0b |
void *mod5 = xdlopen ("tst-dlopen-nodelete-reloc-mod5.so", RTLD_NOW);
|
|
Packit Service |
6bec0b |
/* Again those have no effect because of NODELETE. */
|
|
Packit Service |
6bec0b |
xdlclose (mod5);
|
|
Packit Service |
6bec0b |
xdlclose (mod3);
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
/* Third case: Unique symbol. */
|
|
Packit Service |
6bec0b |
void *mod6 = xdlopen ("tst-dlopen-nodelete-reloc-mod6.so",
|
|
Packit Service |
6bec0b |
RTLD_NOW | RTLD_GLOBAL);
|
|
Packit Service |
6bec0b |
bool *may_finalize_mod6 = xdlsym (mod6, "may_finalize_mod6");
|
|
Packit Service |
6bec0b |
void *mod7 = xdlopen ("tst-dlopen-nodelete-reloc-mod7.so", RTLD_NOW);
|
|
Packit Service |
6bec0b |
bool *may_finalize_mod7 = xdlsym (mod7, "may_finalize_mod7");
|
|
Packit Service |
6bec0b |
/* This should not have any effect because of the unique symbol and
|
|
Packit Service |
6bec0b |
the resulting NODELETE status. */
|
|
Packit Service |
6bec0b |
xdlclose (mod6);
|
|
Packit Service |
6bec0b |
/* mod7 is not NODELETE and can be closed. */
|
|
Packit Service |
6bec0b |
*may_finalize_mod7 = true;
|
|
Packit Service |
6bec0b |
xdlclose (mod7);
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
/* Fourth case: Unique symbol, indirect loading. */
|
|
Packit Service |
6bec0b |
void *mod8 = xdlopen ("tst-dlopen-nodelete-reloc-mod8.so", RTLD_NOW);
|
|
Packit Service |
6bec0b |
/* Also promote to global scope. */
|
|
Packit Service |
6bec0b |
void *mod9 = xdlopen ("tst-dlopen-nodelete-reloc-mod9.so",
|
|
Packit Service |
6bec0b |
RTLD_NOW | RTLD_NOLOAD | RTLD_GLOBAL);
|
|
Packit Service |
6bec0b |
bool *may_finalize_mod9 = xdlsym (mod9, "may_finalize_mod9");
|
|
Packit Service |
6bec0b |
xdlclose (mod9); /* Drop mod9 reference. */
|
|
Packit Service |
6bec0b |
void *mod10 = xdlopen ("tst-dlopen-nodelete-reloc-mod10.so", RTLD_NOW);
|
|
Packit Service |
6bec0b |
void *mod11 = xdlopen ("tst-dlopen-nodelete-reloc-mod11.so",
|
|
Packit Service |
6bec0b |
RTLD_NOW | RTLD_NOLOAD);
|
|
Packit Service |
6bec0b |
bool *may_finalize_mod11 = xdlsym (mod11, "may_finalize_mod11");
|
|
Packit Service |
6bec0b |
xdlclose (mod11); /* Drop mod11 reference. */
|
|
Packit Service |
6bec0b |
/* mod11 is not NODELETE and can be closed. */
|
|
Packit Service |
6bec0b |
*may_finalize_mod11 = true;
|
|
Packit Service |
6bec0b |
/* Trigger closing of mod11, too. */
|
|
Packit Service |
6bec0b |
xdlclose (mod10);
|
|
Packit Service |
6bec0b |
/* Does not trigger closing of mod9. */
|
|
Packit Service |
6bec0b |
xdlclose (mod8);
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
/* Fifth case: Unique symbol, with DT_NEEDED dependency. */
|
|
Packit Service |
6bec0b |
void *mod12 = xdlopen ("tst-dlopen-nodelete-reloc-mod12.so", RTLD_NOW);
|
|
Packit Service |
6bec0b |
bool *may_finalize_mod12 = xdlsym (mod12, "may_finalize_mod12");
|
|
Packit Service |
6bec0b |
void *mod13 = xdlopen ("tst-dlopen-nodelete-reloc-mod13.so", RTLD_NOW);
|
|
Packit Service |
6bec0b |
bool *may_finalize_mod13 = xdlsym (mod13, "may_finalize_mod13");
|
|
Packit Service |
6bec0b |
/* This should not have any effect because of the unique symbol. */
|
|
Packit Service |
6bec0b |
xdlclose (mod12);
|
|
Packit Service |
6bec0b |
/* mod13 is not NODELETE and can be closed. */
|
|
Packit Service |
6bec0b |
*may_finalize_mod13 = true;
|
|
Packit Service |
6bec0b |
xdlclose (mod13);
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
/* Sixth case: Unique symbol binding must not cause loss of NODELETE
|
|
Packit Service |
6bec0b |
status. */
|
|
Packit Service |
6bec0b |
void *mod14 = xdlopen ("tst-dlopen-nodelete-reloc-mod14.so",
|
|
Packit Service |
6bec0b |
RTLD_NOW | RTLD_NODELETE);
|
|
Packit Service |
6bec0b |
bool *may_finalize_mod14 = xdlsym (mod14, "may_finalize_mod14");
|
|
Packit Service |
6bec0b |
TEST_VERIFY (dlopen ("tst-dlopen-nodelete-reloc-mod17.so", RTLD_NOW)
|
|
Packit Service |
6bec0b |
== NULL);
|
|
Packit Service |
6bec0b |
const char *message = dlerror ();
|
|
Packit Service |
6bec0b |
printf ("info: test 6 message: %s\n", message);
|
|
Packit Service |
6bec0b |
/* This must not close the object, it must still be NODELETE. */
|
|
Packit Service |
6bec0b |
xdlclose (mod14);
|
|
Packit Service |
6bec0b |
xdlopen ("tst-dlopen-nodelete-reloc-mod14.so", RTLD_NOW | RTLD_NOLOAD);
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
/* Prepare for process exit. Destructors for NODELETE objects will
|
|
Packit Service |
6bec0b |
be invoked. */
|
|
Packit Service |
6bec0b |
*may_finalize_mod1 = true;
|
|
Packit Service |
6bec0b |
*may_finalize_mod3 = true;
|
|
Packit Service |
6bec0b |
*may_finalize_mod6 = true;
|
|
Packit Service |
6bec0b |
*may_finalize_mod9 = true;
|
|
Packit Service |
6bec0b |
*may_finalize_mod12 = true;
|
|
Packit Service |
6bec0b |
*may_finalize_mod14 = true;
|
|
Packit Service |
6bec0b |
return 0;
|
|
Packit Service |
6bec0b |
}
|
|
Packit Service |
6bec0b |
|
|
Packit Service |
6bec0b |
#include <support/test-driver.c>
|