2021-03-02 14:24:31 +03:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
cd $(dirname $0)
|
|
|
|
echo -n "Testing $(basename -s .sh $0) ... "
|
|
|
|
t=$(pwd)/tmp/$(basename -s .sh $0)
|
|
|
|
mkdir -p $t
|
|
|
|
|
|
|
|
cat <<EOF | cc -shared -fPIC -o $t/a.so -xc - -Wl,-Bsymbolic
|
2021-03-02 15:47:19 +03:00
|
|
|
int foo = 4;
|
|
|
|
|
|
|
|
int get_foo() {
|
2021-03-02 14:24:31 +03:00
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *bar() {
|
|
|
|
return bar;
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
2021-03-02 15:47:19 +03:00
|
|
|
cat <<EOF | cc -c -o $t/b.o -xc - -fno-PIE
|
2021-03-02 14:24:31 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2021-03-02 15:47:19 +03:00
|
|
|
extern int foo;
|
|
|
|
int get_foo();
|
2021-03-02 14:24:31 +03:00
|
|
|
void *bar();
|
|
|
|
|
|
|
|
int main() {
|
2021-03-02 15:47:19 +03:00
|
|
|
foo = 3;
|
|
|
|
printf("%d %d %d\n", foo, get_foo(), bar == bar());
|
2021-03-02 14:24:31 +03:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
2021-03-04 08:09:56 +03:00
|
|
|
clang -fuse-ld=`pwd`/../mold -no-pie -o $t/exe $t/b.o $t/a.so
|
2021-03-02 15:47:19 +03:00
|
|
|
$t/exe | grep -q '3 4 0'
|
2021-03-02 14:24:31 +03:00
|
|
|
|
|
|
|
echo OK
|