2021-03-02 14:24:31 +03:00
|
|
|
#!/bin/bash
|
2022-10-06 05:37:16 +03:00
|
|
|
. $(dirname $0)/common.inc
|
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'
|