Commit 723acab2 authored by Simon McVittie's avatar Simon McVittie

capture-libs: Don't capture results of path-match if they are other ABIs

On Red Hat-derived OSs, /usr/lib/dri contains 32-bit drivers (with
their 64-bit equivalents in /usr/lib64/dri), but on Arch Linux-derived
OSs it contains 64-bit drivers (with their 32-bit equivalents in
/usr/lib32/dri). As a result, we have to run both
i386-linux-gnu-capsule-capture-libs and
x86_64-linux-gnu-capsule-capture-libs against
if-exists:path-match:/usr/lib/dri/*.so, ignoring anything we find that
is of the other word-size.
Signed-off-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
parent 95d7d222
......@@ -405,7 +405,7 @@ $(testmeta_DATA): tests/%.test: tests/% Makefile
echo "[Test]"; \
echo "Type=session"; \
echo "Output=TAP"; \
echo "Exec=$(insttestsdir)/tests/$*$$maybe_tap"; \
echo "Exec=env CAPSULE_TESTS_GNU_HOST=$(host) $(insttestsdir)/tests/$*$$maybe_tap"; \
) > $@.tmp && mv $@.tmp $@
if ENABLE_SHARED
......
......@@ -307,6 +307,65 @@ SKIP: {
"--resolve-ld.so=$host should print ".abs_path($ld_so));
};
SKIP: {
my $multiarch;
my $other_multiarch;
# For simplicity, we only consider this case on x86.
skip "$ENV{CAPSULE_TESTS_GNU_HOST} not x86_64 or i386", 1
unless $ENV{CAPSULE_TESTS_GNU_HOST} =~ m/^(x86_64|i.86)-/;
if ($ENV{CAPSULE_TESTS_GNU_HOST} =~ m/^x86_64-/) {
$other_multiarch = 'i386-linux-gnu';
}
else {
$other_multiarch = 'x86_64-linux-gnu';
}
skip "$other_multiarch libjpeg.so.62 not available", 1
unless -e "/usr/lib/$other_multiarch/libjpeg.so.62";
# Normally, the wrong ABI is an error...
ok(! system('rm', '-fr', $libdir));
mkdir($libdir);
$result = run_verbose([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",
"path:/usr/lib/$other_multiarch/libjpeg.so.62"],
'>&2');
ok(! $result, 'library of wrong ABI yields an error');
ok(! -e "$libdir/libjpeg.so.62");
# ... but when we're dealing with a glob match, other ABIs are silently
# ignored.
ok(! system('rm', '-fr', $libdir));
mkdir($libdir);
$result = run_verbose([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",
"path-match:/usr/lib/$other_multiarch/libjpeg.so.62"],
'>&2');
ok($result, 'library of wrong ABI ignored when using path-match');
ok(! -e "$libdir/libjpeg.so.62");
# We can also ignore this case explicitly.
ok(! system('rm', '-fr', $libdir));
mkdir($libdir);
$result = run_verbose([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",
"if-same-abi:path:/usr/lib/$other_multiarch/libjpeg.so.62"],
'>&2');
ok($result, 'library of wrong ABI ignored when using if-same-abi');
ok(! -e "$libdir/libjpeg.so.62");
};
done_testing;
# vim:set sw=4 sts=4 et:
......@@ -244,6 +244,9 @@ static void usage (int code)
"\ttheir dependencies\n" );
fprintf( fh, "if-exists:PATTERN\n"
"\tCapture PATTERN, but don't fail if nothing matches\n" );
fprintf( fh, "if-same-abi:PATTERN\n"
"\tCapture PATTERN, but don't fail if it points to a\n"
"\tlibrary with mismatched word size or architecture\n" );
fprintf( fh, "even-if-older:PATTERN\n"
"\tCapture PATTERN, even if the version in CONTAINER\n"
"\tappears newer\n" );
......@@ -256,7 +259,7 @@ static void usage (int code)
"\tand capture the result\n" );
fprintf( fh, "path-match:GLOB\n"
"\tResolve GLOB as though chrooted into PROVIDER\n"
"\tand capture the result\n" );
"\tand capture any results that are of the right ABI\n" );
fprintf( fh, "an absolute path with no '?', '*', '['\n"
"\tSame as path:PATTERN\n" );
fprintf( fh, "a glob pattern starting with '/'\n"
......@@ -275,6 +278,7 @@ typedef enum
CAPTURE_FLAG_IF_EXISTS = (1 << 1),
CAPTURE_FLAG_LIBRARY_ITSELF = ( 1 << 2 ),
CAPTURE_FLAG_DEPENDENCIES = ( 1 << 3 ),
CAPTURE_FLAG_IF_SAME_ABI = ( 1 << 4 ),
} capture_flags;
static bool
......@@ -325,12 +329,17 @@ capture_one( const char *soname, capture_flags flags,
_capsule_clear( &local_message );
return true;
}
else
if( ( flags & CAPTURE_FLAG_IF_SAME_ABI ) && local_code == ENOEXEC )
{
_capsule_propagate_error( code, message, local_code,
_capsule_steal_pointer( &local_message ) );
return false;
DEBUG( DEBUG_TOOL, "%s is a different ABI: %s", soname, local_message );
_capsule_clear( &local_message );
return true;
}
_capsule_propagate_error( code, message, local_code,
_capsule_steal_pointer( &local_message ) );
return false;
}
if( !ld_libs_find_dependencies( &provider, code, message ) )
......@@ -676,7 +685,8 @@ capture_path_match( const char *pattern, capture_flags flags,
}
if( !capture_one( path + strlen( option_provider ),
flags, code, message ) )
flags | CAPTURE_FLAG_IF_SAME_ABI,
code, message ) )
{
ret = false;
break;
......@@ -776,6 +786,13 @@ capture_pattern( const char *pattern, capture_flags flags,
code, message );
}
if( strstarts( pattern, "if-same-abi:" ) )
{
return capture_pattern( pattern + strlen( "if-same-abi:" ),
flags | CAPTURE_FLAG_IF_SAME_ABI,
code, message );
}
if( strstarts( pattern, "even-if-older:" ) )
{
return capture_pattern( pattern + strlen( "even-if-older:" ),
......
Markdown is supported
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