2021-03-01 17:33:53 +03:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
cd $(dirname $0)
|
2021-09-08 13:11:48 +03:00
|
|
|
mold=`pwd`/../../mold
|
2021-03-01 17:33:53 +03:00
|
|
|
echo -n "Testing $(basename -s .sh $0) ... "
|
2021-10-12 12:32:20 +03:00
|
|
|
t=$(pwd)/../../out/test/elf/$(basename -s .sh $0)
|
2021-03-01 17:33:53 +03:00
|
|
|
mkdir -p $t
|
|
|
|
|
|
|
|
cat <<EOF | cc -o $t/a.so -fPIC -shared -xc -
|
|
|
|
void *foo() {
|
|
|
|
return foo;
|
|
|
|
}
|
2021-11-18 14:23:57 +03:00
|
|
|
|
|
|
|
void *bar() {
|
|
|
|
return bar;
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat <<EOF | cc -o $t/b.o -c -xc - -fPIC
|
|
|
|
void *bar();
|
|
|
|
|
|
|
|
void *baz() {
|
|
|
|
return bar;
|
|
|
|
}
|
2021-03-01 17:33:53 +03:00
|
|
|
EOF
|
|
|
|
|
2021-11-18 14:23:57 +03:00
|
|
|
cat <<EOF | cc -o $t/c.o -c -xc - -fno-PIC
|
2021-03-01 17:33:53 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
void *foo();
|
2021-11-18 14:23:57 +03:00
|
|
|
void *bar();
|
|
|
|
void *baz();
|
2021-03-01 17:33:53 +03:00
|
|
|
|
|
|
|
int main() {
|
2021-11-18 14:23:57 +03:00
|
|
|
printf("%d %d %d\n", foo == foo(), bar == bar(), bar == baz());
|
2021-03-01 17:33:53 +03:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
2021-11-18 14:23:57 +03:00
|
|
|
clang -fuse-ld=$mold -no-pie -o $t/exe $t/a.so $t/b.o $t/c.o
|
|
|
|
$t/exe | grep -q '^1 1 1$'
|
2021-03-01 17:33:53 +03:00
|
|
|
|
|
|
|
echo OK
|