2021-03-02 14:24:31 +03:00
|
|
|
#!/bin/bash
|
2022-03-09 03:01:04 +03:00
|
|
|
export LC_ALL=C
|
2021-03-02 14:24:31 +03:00
|
|
|
set -e
|
2022-05-11 11:46:19 +03:00
|
|
|
CC="${TEST_CC:-cc}"
|
|
|
|
CXX="${TEST_CXX:-c++}"
|
|
|
|
GCC="${TEST_GCC:-gcc}"
|
|
|
|
GXX="${TEST_GXX:-g++}"
|
2022-04-02 11:12:14 +03:00
|
|
|
MACHINE="${MACHINE:-$(uname -m)}"
|
2022-01-24 04:21:08 +03:00
|
|
|
testname=$(basename "$0" .sh)
|
2021-12-30 05:11:06 +03:00
|
|
|
echo -n "Testing $testname ... "
|
2022-07-18 10:25:13 +03:00
|
|
|
t=out/test/elf/$MACHINE/$testname
|
2022-01-07 12:06:53 +03:00
|
|
|
mkdir -p $t
|
2021-03-02 14:24:31 +03:00
|
|
|
|
2022-01-07 12:06:53 +03:00
|
|
|
cat <<EOF | $CC -c -fPIC -o$t/a.o -xc -
|
2021-03-02 15:47:19 +03:00
|
|
|
int foo = 4;
|
2022-09-10 10:26:24 +03:00
|
|
|
int get_foo() { return foo; }
|
2021-03-02 14:24:31 +03:00
|
|
|
EOF
|
|
|
|
|
2022-01-07 12:06:53 +03:00
|
|
|
$CC -B. -shared -fPIC -o $t/b.so $t/a.o -Wl,-Bsymbolic
|
2021-07-19 18:21:12 +03:00
|
|
|
|
2022-01-07 12:06:53 +03:00
|
|
|
cat <<EOF | $CC -c -o $t/c.o -xc - -fno-PIE
|
2021-03-02 14:24:31 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2022-09-10 10:26:24 +03:00
|
|
|
int foo = 3;
|
2021-03-02 15:47:19 +03:00
|
|
|
int get_foo();
|
2021-03-02 14:24:31 +03:00
|
|
|
|
|
|
|
int main() {
|
2022-09-10 10:26:24 +03:00
|
|
|
printf("%d %d\n", foo, get_foo());
|
2021-03-02 14:24:31 +03:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
2022-01-07 12:06:53 +03:00
|
|
|
$CC -B. -no-pie -o $t/exe $t/c.o $t/b.so
|
2022-09-10 10:26:24 +03:00
|
|
|
$QEMU $t/exe | grep -q '3 4'
|
2021-03-02 14:24:31 +03:00
|
|
|
|
|
|
|
echo OK
|