Commit ca69ae4d authored by Simon McVittie's avatar Simon McVittie
Browse files

Add capture-libs tool



Signed-off-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
parent 2a469628
......@@ -31,6 +31,7 @@ Makefile
shim/*.so.c
shim/*.so.symbols
shim/*.so.map
/capsule-capture-libs
/capsule-elf-dump
print-libstubs
capsule-symbols
......
......@@ -26,7 +26,7 @@ AM_LDFLAGS = $(WARN_LDFLAGS)
static_docs = Building Debugging Limitations Quick-Start Capsules
# installable items:
bin_PROGRAMS = capsule-symbols capsule-version
bin_PROGRAMS = capsule-capture-libs capsule-symbols capsule-version
dist_bin_SCRIPTS = data/capsule-init-project
lib_LTLIBRARIES = libcapsule.la
pkgconfigdir = $(libdir)/pkgconfig
......@@ -52,8 +52,10 @@ install-exec-hook:
cd $(DESTDIR)$(bindir) && ln -f capsule-symbols $(HOST_PREFIX)capsule-symbols
cd $(DESTDIR)$(bindir) && ln -f capsule-version $(HOST_PREFIX)capsule-version
cd $(DESTDIR)$(bindir) && ln -f capsule-elf-dump $(HOST_PREFIX)capsule-elf-dump
cd $(DESTDIR)$(bindir) && ln -f capsule-capture-libs $(HOST_PREFIX)capsule-capture-libs
uninstall-hook:
cd $(DESTDIR)$(bindir) && rm -f $(HOST_PREFIX)capsule-capture-libs
cd $(DESTDIR)$(bindir) && rm -f $(HOST_PREFIX)capsule-elf-dump
cd $(DESTDIR)$(bindir) && rm -f $(HOST_PREFIX)capsule-symbols
cd $(DESTDIR)$(bindir) && rm -f $(HOST_PREFIX)capsule-version
......@@ -82,6 +84,9 @@ capsule_elf_dump_LDADD = utils/libutils.la -ldl
# instantiations of dump.o for elf-dump and libcapsule
capsule_elf_dump_CFLAGS = $(AM_CFLAGS)
capsule_capture_libs_SOURCES = utils/capture-libs.c
capsule_capture_libs_LDADD = utils/libld.la
# now the rules for building our installables:
capsule_symbols_SOURCES = utils/print-libstubs.c
capsule_symbols_LDADD = utils/libld.la
......@@ -282,7 +287,8 @@ PL_LOG_DRIVER = $(LOG_DRIVER)
PL_LOG_COMPILER = $(PERL)
T_LOG_DRIVER = $(LOG_DRIVER)
T_LOG_COMPILER = $(SHELL) $(top_srcdir)/tests/glib-tap.sh
AM_TESTS_ENVIRONMENT = export CAPSULE_CFLAGS="-I$(abs_top_srcdir) -I$(abs_top_builddir)"; \
AM_TESTS_ENVIRONMENT = export CAPSULE_CAPTURE_LIBS_TOOL="$(abs_builddir)/capsule-capture-libs"; \
export CAPSULE_CFLAGS="-I$(abs_top_srcdir) -I$(abs_top_builddir)"; \
export CAPSULE_LIBS="$(abs_top_builddir)/libcapsule.la"; \
export CAPSULE_SYMBOLS_TOOL="$(abs_builddir)/capsule-symbols";\
export CAPSULE_TESTS_UNINSTALLED=1; \
......@@ -311,7 +317,8 @@ endif
tests_utils_t_SOURCES = tests/utils.c
tests_utils_t_LDADD = utils/libutils.la $(GLIB_LIBS)
test_scripts = tests/gl-shim.pl \
test_scripts = tests/capture-libs.pl \
tests/gl-shim.pl \
tests/init-project.pl \
tests/notgl.pl \
tests/symbols.pl \
......
makeinc=@abs_top_srcdir@/data
CAPSULE_CAPTURE_LIBS_TOOL=@abs_top_builddir@/capsule-capture-libs
CAPSULE_INIT_PROJECT_TOOL=@abs_top_srcdir@/data/capsule-init-project
CAPSULE_MKSTUBLIB_TOOL=@abs_top_srcdir@/data/capsule-mkstublib
CAPSULE_SYMBOLS_TOOL=@abs_top_builddir@/capsule-symbols
......
......@@ -6,6 +6,7 @@ libexecdir=@libexecdir@
datarootdir=@datarootdir@
datadir=@datarootdir@
makeinc=@datadir@/libcapsule
CAPSULE_CAPTURE_LIBS_TOOL=@bindir@/@HOST_PREFIX@capsule-capture-libs
CAPSULE_INIT_PROJECT_TOOL=@bindir@/capsule-init-project
CAPSULE_MKSTUBLIB_TOOL=@bindir@/@HOST_PREFIX@capsule-mkstublib
CAPSULE_SYMBOLS_TOOL=@bindir@/@HOST_PREFIX@capsule-symbols
......
usr/bin/*-capsule-capture-libs
usr/bin/*-capsule-elf-dump
usr/bin/*-capsule-mkstublib
usr/bin/*-capsule-symbols
......
......@@ -62,6 +62,7 @@ override_dh_install:
find debian/tmp/usr/lib/libcapsule/installed-tests -name '*.la' -print -delete
# Only keep the architecture-qualified version, delete the unprefixed
# version, so we can be Multi-Arch: same
rm -f debian/tmp/usr/bin/capsule-capture-libs
rm -f debian/tmp/usr/bin/capsule-elf-dump
rm -f debian/tmp/usr/bin/capsule-symbols
rm -f debian/tmp/usr/bin/capsule-version
......
......@@ -35,6 +35,7 @@ our @EXPORT = qw(
run_verbose
skip_all_unless_bwrap
skip_all_unless_nm
$CAPSULE_CAPTURE_LIBS_TOOL
$CAPSULE_INIT_PROJECT_TOOL
$CAPSULE_SYMBOLS_TOOL
$CAPSULE_VERSION_TOOL
......@@ -65,6 +66,19 @@ The B<pkg-config>(1) utility.
our $PKG_CONFIG = $ENV{PKG_CONFIG};
$PKG_CONFIG = 'pkg-config' unless length $PKG_CONFIG;
=item $CAPSULE_CAPTURE_LIBS_TOOL
The B<capsule-capture-libs>(1) development tool.
=cut
our $CAPSULE_CAPTURE_LIBS_TOOL = $ENV{CAPSULE_CAPTURE_LIBS_TOOL};
if (! length $CAPSULE_CAPTURE_LIBS_TOOL) {
$CAPSULE_CAPTURE_LIBS_TOOL = `$PKG_CONFIG --variable=CAPSULE_CAPTURE_LIBS_TOOL libcapsule-tools`;
chomp $CAPSULE_CAPTURE_LIBS_TOOL;
}
=item $CAPSULE_INIT_PROJECT_TOOL
The B<capsule-init-project>(1) development tool.
......
#!/usr/bin/perl
# 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/>.
use autodie;
use warnings;
use strict;
use Cwd qw(abs_path);
use File::Temp qw();
use IPC::Run qw(run);
use Test::More;
use FindBin;
use lib $FindBin::Bin;
use CapsuleTest;
skip_all_unless_bwrap;
my $LIBDIR = qr{/(?:usr/)?lib(?:32|64|x32)?(?:/\w+-linux-gnu\w*)?};
my $test_tempdir = File::Temp->newdir();
diag "Working directory: $test_tempdir";
my $host = "${test_tempdir}/host";
mkdir($host);
my $libdir = "${test_tempdir}/libdir";
ok(! system('rm', '-fr', $libdir));
mkdir($libdir);
run_ok([$CAPSULE_CAPTURE_LIBS_TOOL, 'libc.so.6'], '>&2',
init => sub { chdir $libdir or die $!; });
ok(-e "$libdir/libc.so.6", 'libc.so.6 was captured');
like(readlink "$libdir/libc.so.6", qr{^$LIBDIR/libc\.so\.6$},
'$libdir/libc.so.6 is a symlink to the real libc.so.6');
my $libc = abs_path("$libdir/libc.so.6");
ok(-e "$libdir/libBrokenLocale.so.1", 'related libraries were captured');
ok(-e "$libdir/libm.so.6", 'related libraries were captured');
ok(-e "$libdir/libpthread.so.0", 'related libraries were captured');
ok(-e "$libdir/libmemusage.so", 'related libraries were captured');
like(readlink "$libdir/libm.so.6", qr{^$LIBDIR/libm\.so\.6$},
'libm is a symlink to the right place');
my @libc_family;
{
opendir(my $dir_iter, $libdir);
@libc_family = sort grep { $_ ne '.' and $_ ne '..' } readdir $dir_iter;
closedir $dir_iter;
foreach my $symlink (@libc_family) {
diag "- $symlink -> ".readlink("$libdir/$symlink");
}
}
ok(! system('rm', '-fr', $libdir));
mkdir($libdir);
run_ok([$CAPSULE_CAPTURE_LIBS_TOOL, '--link-target=/run/host',
"--dest=$libdir", 'libc.so.6'], '>&2');
{
opendir(my $dir_iter, $libdir);
my @links = sort grep { $_ ne '.' and $_ ne '..' } readdir $dir_iter;
foreach my $symlink (@links) {
diag "- $symlink -> ".readlink("$libdir/$symlink");
}
closedir $dir_iter;
is_deeply(\@links, \@libc_family,
'the same libraries are captured when using --link-target');
}
like(readlink "$libdir/libc.so.6", qr{^/run/host\Q$libc\E$},
'$libdir/libc.so.6 is a symlink to /run/host + realpath of libc.so.6');
ok(! system('rm', '-fr', $libdir));
mkdir($libdir);
run_ok([qw(bwrap --ro-bind / / --ro-bind /), $host,
'--bind', $libdir, $libdir,
qw(--dev-bind /dev /dev),
$CAPSULE_CAPTURE_LIBS_TOOL,
"--dest=$libdir",
"--provider=$host", 'libc.so.6'], '>&2');
{
opendir(my $dir_iter, $libdir);
my @links = sort grep { $_ ne '.' and $_ ne '..' } readdir $dir_iter;
foreach my $symlink (@links) {
diag "- $symlink -> ".readlink("$libdir/$symlink");
}
closedir $dir_iter;
is_deeply(\@links, \@libc_family,
'the same libraries are captured when using $host');
}
like(readlink "$libdir/libc.so.6", qr{^\Q$host\E\Q$libc\E$},
'$libdir/libc.so.6 is a symlink to $host + realpath of libc.so.6');
ok(! system('rm', '-fr', $libdir));
mkdir($libdir);
run_ok([qw(bwrap --ro-bind / / --ro-bind /), $host,
'--bind', $libdir, $libdir,
qw(--dev-bind /dev /dev),
$CAPSULE_CAPTURE_LIBS_TOOL, '--link-target=/run/host',
"--dest=$libdir",
"--provider=$host", 'libc.so.6'], '>&2');
{
opendir(my $dir_iter, $libdir);
my @links = sort grep { $_ ne '.' and $_ ne '..' } readdir $dir_iter;
foreach my $symlink (@links) {
diag "- $symlink -> ".readlink("$libdir/$symlink");
}
closedir $dir_iter;
is_deeply(\@links, \@libc_family,
'the same libraries are captured when using $host and --link-target');
}
like(readlink "$libdir/libc.so.6", qr{^/run/host\Q$libc\E$},
'$libdir/libc.so.6 is a symlink to /run/host + realpath of libc.so.6');
ok(! system('rm', '-fr', $libdir));
mkdir($libdir);
run_ok([qw(bwrap --ro-bind / / --ro-bind /), $host,
'--bind', $libdir, $libdir,
qw(--dev-bind /dev /dev),
$CAPSULE_CAPTURE_LIBS_TOOL, '--link-target=/',
"--dest=$libdir", "--provider=$host", 'libjp*g.so.6*'], '>&2');
{
opendir(my $dir_iter, $libdir);
foreach my $symlink (readdir $dir_iter) {
next if $symlink eq '.' || $symlink eq '..';
diag "- $symlink -> ".readlink("$libdir/$symlink");
}
closedir $dir_iter;
}
like(readlink "$libdir/libjpeg.so.62", qr{^$LIBDIR/libjpeg\.so\.62(?:[0-9.]+)$},
'$libdir/libjpeg.so.62 is a symlink to /run/host + realpath of libjpeg-6b');
SKIP: {
skip "not on Linux? Good luck!", 1 unless $^O eq 'linux';
my $stdout;
my $ld_so;
run_ok([$CAPSULE_CAPTURE_LIBS_TOOL, '--print-ld.so'], '>', \$ld_so);
chomp $ld_so;
diag "ld.so is $ld_so";
run_ok([$CAPSULE_CAPTURE_LIBS_TOOL, '--resolve-ld.so=/'], '>', \$stdout);
is($stdout, abs_path($ld_so)."\n",
'--resolve-ld.so=/ should print '.abs_path($ld_so));
run_ok([qw(bwrap --ro-bind / / --ro-bind /), $host,
$CAPSULE_CAPTURE_LIBS_TOOL, "--resolve-ld.so=$host"],
'>', \$stdout);
is($stdout, abs_path($ld_so)."\n",
"--resolve-ld.so=$host should print ".abs_path($ld_so));
};
done_testing;
# vim:set sw=4 sts=4 et:
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment