Skip to content
Snippets Groups Projects
Commit a2905311 authored by Simon McVittie's avatar Simon McVittie
Browse files

Stop allowing dlopen() as seen outside the capsule to be non-default


We cannot allow non-default implementations of it, because which
capsule would get to choose the implementation?

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent f27a1196
No related branches found
No related tags found
1 merge request!311Build capsule-capture-libs from a bundled copy of libcapsule
...@@ -56,7 +56,6 @@ uninstall-hook: ...@@ -56,7 +56,6 @@ uninstall-hook:
# Headers to be included by shim libraries # Headers to be included by shim libraries
nobase_include_HEADERS += capsule/capsule-shim.h \ nobase_include_HEADERS += capsule/capsule-shim.h \
capsule/_ext_dlopen.h \
capsule/_int_dlopen.h capsule/_int_dlopen.h
# demo program - keep this hanging around as it's a useful PoC # demo program - keep this hanging around as it's a useful PoC
...@@ -244,7 +243,6 @@ tests/shim/%.c: tests/shim/%.excluded tests/shim/%.shared tests/shim/%.symbols d ...@@ -244,7 +243,6 @@ tests/shim/%.c: tests/shim/%.excluded tests/shim/%.shared tests/shim/%.symbols d
PKG_CONFIG_PATH=$(abs_builddir)/data \ PKG_CONFIG_PATH=$(abs_builddir)/data \
V=$V \ V=$V \
$(top_srcdir)/data/capsule-mkstublib \ $(top_srcdir)/data/capsule-mkstublib \
--ext-dlopen \
--symbols-from=$(srcdir)/tests/shim/$*.symbols \ --symbols-from=$(srcdir)/tests/shim/$*.symbols \
--no-update-symbols \ --no-update-symbols \
--runtime-tree=/host \ --runtime-tree=/host \
......
// Copyright © 2017 Collabora Ltd
//
// This file is part of libcapsule.
//
// libcapsule 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.
//
// libcapsule 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 libcapsule. If not, see <http://www.gnu.org/licenses/>.
// Standard implementation of _ext_dlopen(), the implementation used
// when a library outside the capsule calls dlopen(). To override this
// implementation, copy this file to shim/capsule/_ext_dlopen.h in
// your shim library and modify as needed.
static void *_ext_dlopen (const char *filename, int flag)
{
return capsule_external_dlopen( filename, flag );
}
...@@ -34,8 +34,6 @@ Usage: $me [OPTIONS] TARGET EXCLUDES EXPORTS OUTPUT [DSO-VERSION [TREE]]" ...@@ -34,8 +34,6 @@ Usage: $me [OPTIONS] TARGET EXCLUDES EXPORTS OUTPUT [DSO-VERSION [TREE]]"
Use replacement capsule-symbols(1) Use replacement capsule-symbols(1)
--symbols-from=PATH Use symbols from this file --symbols-from=PATH Use symbols from this file
[default: \${OUTPUT%.c}.symbols] [default: \${OUTPUT%.c}.symbols]
--[no-]ext-dlopen Do or don't override dlopen() for
callers outside the capsule [default: don't]
--[no-]update-symbols Do or don't update symbols list if EXPORTS --[no-]update-symbols Do or don't update symbols list if EXPORTS
is newer than it [default: do] is newer than it [default: do]
--search-tree=PATH Find libraries to be proxied in this --search-tree=PATH Find libraries to be proxied in this
...@@ -66,11 +64,10 @@ EOF ...@@ -66,11 +64,10 @@ EOF
exit "${1:-0}" exit "${1:-0}"
} }
ext_dlopen=
update_symbols= update_symbols=
getopt_temp="$(getopt -o 'h' \ getopt_temp="$(getopt -o 'h' \
-l 'capsule-symbols-tool:,ext-dlopen,no-ext-dlopen,search-tree:,runtime-tree:,symbols-from:,update-symbols,no-update-symbols,help' \ -l 'capsule-symbols-tool:,search-tree:,runtime-tree:,symbols-from:,update-symbols,no-update-symbols,help' \
-n "$me" -- "$@")" -n "$me" -- "$@")"
eval set -- "$getopt_temp" eval set -- "$getopt_temp"
...@@ -83,18 +80,6 @@ do ...@@ -83,18 +80,6 @@ do
continue; continue;
;; ;;
(--ext-dlopen)
ext_dlopen=yes;
shift;
continue;
;;
(--no-ext-dlopen)
ext_dlopen=;
shift;
continue;
;;
(--runtime-tree) (--runtime-tree)
runtime_tree="$2" runtime_tree="$2"
shift 2; shift 2;
...@@ -248,21 +233,6 @@ static const char soname[] = "$proxied_dso"; ...@@ -248,21 +233,6 @@ static const char soname[] = "$proxied_dso";
// _int_dlopen() from libcapsule or a locally overridden version // _int_dlopen() from libcapsule or a locally overridden version
#include "capsule/_int_dlopen.h" #include "capsule/_int_dlopen.h"
EOF
if [ -n "$ext_dlopen" ]
then
echo '// _ext_dlopen() from libcapsule or a locally overridden version'
echo '#include "capsule/_ext_dlopen.h"'
echo '#define HAVE_EXT_DLOPEN'
else
echo '// Disabled by capsule-mkstublib --no-ext-dlopen'
echo '//#include "capsule/_ext_dlopen.h"'
echo '//#define HAVE_EXT_DLOPEN'
fi
cat - <<EOF
// should we exclude libpthread here? // should we exclude libpthread here?
// in any case, these are DSOs we do _not_ want to isolate // in any case, these are DSOs we do _not_ want to isolate
static const char *exclude[] = static const char *exclude[] =
...@@ -310,19 +280,6 @@ static const char *invalid_dl_reloc_targets[] = ...@@ -310,19 +280,6 @@ static const char *invalid_dl_reloc_targets[] =
NULL NULL
}; };
#ifdef HAVE_EXT_DLOPEN
static capsule_item _external_dl_relocs[] =
{
{ "dlopen",
(capsule_addr) _ext_dlopen ,
(capsule_addr) _ext_dlopen },
{ NULL }
};
#define EXT_DLOPEN_WRAPPERS _external_dl_relocs
#else
#define EXT_DLOPEN_WRAPPERS capsule_external_dl_relocs
#endif
// make sure this symbol has global visibility so // make sure this symbol has global visibility so
// that the libcapsule initialisation can find it // that the libcapsule initialisation can find it
__attribute__ ((visibility("default"))) __attribute__ ((visibility("default")))
...@@ -334,7 +291,7 @@ capsule_metadata capsule_meta = ...@@ -334,7 +291,7 @@ capsule_metadata capsule_meta =
.exclude = exclude, .exclude = exclude,
.export = valid_dlsym_sources, .export = valid_dlsym_sources,
.nowrap = invalid_dl_reloc_targets, .nowrap = invalid_dl_reloc_targets,
.dl_wrappers = EXT_DLOPEN_WRAPPERS, .dl_wrappers = capsule_external_dl_relocs,
}; };
// ------------------------------------------------------------- // -------------------------------------------------------------
...@@ -407,7 +364,7 @@ static void __attribute__ ((constructor)) _capsule_init (void) ...@@ -407,7 +364,7 @@ static void __attribute__ ((constructor)) _capsule_init (void)
if( rloc != 0 ) // relocation failed. we're dead. if( rloc != 0 ) // relocation failed. we're dead.
abort(); abort();
rloc = capsule_relocate_except( cap, EXT_DLOPEN_WRAPPERS, rloc = capsule_relocate_except( cap, capsule_external_dl_relocs,
&invalid_dl_reloc_targets[0], &invalid_dl_reloc_targets[0],
&capsule_error ); &capsule_error );
if( rloc != 0 ) // we may survive this depending on how dlopen is used if( rloc != 0 ) // we may survive this depending on how dlopen is used
......
...@@ -9,7 +9,7 @@ AM_CFLAGS += $(CAPSULE_CFLAGS) ...@@ -9,7 +9,7 @@ AM_CFLAGS += $(CAPSULE_CFLAGS)
CAPSULE_SONAMES := @TARGET@ CAPSULE_SONAMES := @TARGET@
CAPSULE_VERSION_@AMTARGET@ := @VER@ CAPSULE_VERSION_@AMTARGET@ := @VER@
#AM_CAPSULE_MKSTUBLIB_FLAGS := --ext-dlopen AM_CAPSULE_MKSTUBLIB_FLAGS :=
lib_LTLIBRARIES = lib@LIB@.la lib_LTLIBRARIES = lib@LIB@.la
......
...@@ -21,15 +21,7 @@ The generated library will have the same name as the main proxy target ...@@ -21,15 +21,7 @@ The generated library will have the same name as the main proxy target
(@TARGET@). You can control the exact version number (cf libfoo.x.y.z) (@TARGET@). You can control the exact version number (cf libfoo.x.y.z)
by setting CAPSULE_VERSION_@AMTARGET@ in Makefile.am by setting CAPSULE_VERSION_@AMTARGET@ in Makefile.am
To make the generated library override dlopen() for callers outside the If libcapsule's standard implementation of dlopen() for callers inside
capsule, pass --ext-dlopen to capsule-mkstublib by setting the the capsule is not suitable, copy capsule/_int_dlopen.h from
AM_CAPSULE_MKSTUBLIB_FLAGS variable in Makefile.am. libcapsule's development files into shim/capsule/, modify it as
necessary, and add it to EXTRA_DIST in Makefile.am.
If libcapsule's standard implementations of that function
is not suitable, copy capsule/_ext_dlopen.h from libcapsule's
development files into shim/capsule/, modify it as necessary,
and add it to EXTRA_DIST in Makefile.am.
Similarly, if libcapsule's standard implementation of dlopen() for
callers inside the capsule is not suitable, copy and modify
capsule/_int_dlopen.h.
...@@ -175,30 +175,6 @@ shim/capsule/_int_dlopen.h ...@@ -175,30 +175,6 @@ shim/capsule/_int_dlopen.h
} }
----------------------------------------------------------------------------
shim/capsule/_ext_dlopen.h
This file is not created or used by default. It can be enabled by
adding --ext-dlopen to AM_CAPSULE_MKSTUBLIB_FLAGS in Makefile.am.
The _ext_dlopen wrapper is installed in _most_ libraries outside the
capsule (notably not in the shim itself, libcapsule.so, libc.so and
a few other core libraries). It is responsible for triggering the
capsule's manual symbol relocation when a library outside the capsule
is dlopen()ed.
If this is enabled by --ext-dlopen but the file is not present,
a default implementation provided by libcapsule is used.
See libcapsule's <capsule/_ext_dlopen.h> for that implementation.
To use a custom implementation, create the file and implement a
function with the same signature:
static void *_ext_dlopen (const char *filename, int flags)
{
}
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
That's it - you should be ready to: That's it - you should be ready to:
......
...@@ -186,21 +186,6 @@ License along with libcapsule. If not, see <http://www.gnu.org/licenses/>. ...@@ -186,21 +186,6 @@ License along with libcapsule. If not, see <http://www.gnu.org/licenses/>.
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>--[no-]ext-dlopen</option></term>
<listitem>
<para>
Do or don't provide an explicit override for dlopen(3)
calls made outside the capsule in the generated
source.
</para>
<para>
[There is always an implicit override - this just
exposes the implementation for easy modification]
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><option>--[no]-update-symbols</option></term> <term><option>--[no]-update-symbols</option></term>
<listitem> <listitem>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment