-
-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip a test if LD_PRELOAD doesn't work
- Loading branch information
Showing
1 changed file
with
33 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,52 @@ | ||
#!/bin/bash | ||
. $(dirname $0)/common.inc | ||
|
||
cat <<EOF | $CC -B. -fPIC -shared -o $t/a.so -xassembler - | ||
# LD_PRELOAD may not work in some environments, so try to test it | ||
# with the default linker first | ||
cat <<EOF | $CC -fPIC -shared -o $t/a.so -xc - | ||
int foo() { return 3; } | ||
EOF | ||
|
||
cat <<EOF | $CC -fPIC -shared -o $t/b.so -xc - | ||
int foo() { return 5; } | ||
EOF | ||
|
||
cat <<EOF | $CC -fPIC -c -o $t/c.o -xc - | ||
#include <stdio.h> | ||
int foo(); | ||
int main() { printf("foo=%d\n", foo()); } | ||
EOF | ||
|
||
$CC -o $t/exe1 -pie $t/c.o $t/a.so | ||
$QEMU $t/exe1 | grep -q 'foo=3' | ||
LD_PRELOAD=$t/b.so $QEMU $t/exe1 | grep -q 'foo=5' || skip | ||
|
||
# If LD_PRELOAD works, continue | ||
cat <<EOF | $CC -B. -fPIC -shared -o $t/d.so -xassembler - | ||
.globl foo | ||
foo = 3; | ||
EOF | ||
|
||
cat <<EOF | $CC -B. -fPIC -shared -o $t/b.so -xassembler - | ||
cat <<EOF | $CC -B. -fPIC -shared -o $t/e.so -xassembler - | ||
.globl foo | ||
foo = 5; | ||
EOF | ||
|
||
cat <<EOF | $CC -fPIC -c -o $t/c.o -xc - | ||
cat <<EOF | $CC -fPIC -c -o $t/f.o -xc - | ||
#include <stdio.h> | ||
extern char foo; | ||
int main() { printf("foo=%p\n", &foo); } | ||
EOF | ||
|
||
# This test fails with older glibc | ||
$CC -B. -o $t/exe1 -pie $t/c.o $t/a.so 2> /dev/null || skip | ||
$QEMU $t/exe1 | grep -q 'foo=0x3' || skip | ||
LD_PRELOAD=$t/b.so $QEMU $t/exe1 | grep -q 'foo=0x5' | ||
|
||
$CC -B. -o $t/exe2 -pie $t/c.o $t/a.so | ||
$QEMU $t/exe2 | grep -q 'foo=0x3' | ||
LD_PRELOAD=$t/b.so $QEMU $t/exe2 | grep -q 'foo=0x5' | ||
$CC -B. -o $t/exe2 -pie $t/f.o $t/d.so 2> /dev/null || skip | ||
$QEMU $t/exe2 | grep -q 'foo=0x3' || skip | ||
LD_PRELOAD=$t/e.so $QEMU $t/exe2 | grep -q 'foo=0x5' | ||
|
||
$CC -B. -o $t/exe3 -no-pie $t/c.o $t/a.so | ||
$CC -B. -o $t/exe3 -pie $t/f.o $t/d.so | ||
$QEMU $t/exe3 | grep -q 'foo=0x3' | ||
LD_PRELOAD=$t/b.so $QEMU $t/exe3 | grep -q 'foo=0x5' | ||
LD_PRELOAD=$t/e.so $QEMU $t/exe3 | grep -q 'foo=0x5' | ||
|
||
$CC -B. -o $t/exe4 -no-pie $t/f.o $t/d.so | ||
$QEMU $t/exe4 | grep -q 'foo=0x3' | ||
LD_PRELOAD=$t/e.so $QEMU $t/exe4 | grep -q 'foo=0x5' |