2021-03-02 14:24:31 +03:00
|
|
|
#!/bin/bash
|
2021-12-17 14:05:14 +03:00
|
|
|
export LANG=
|
2021-03-02 14:24:31 +03:00
|
|
|
set -e
|
2021-12-22 13:38:00 +03:00
|
|
|
cd "$(dirname "$0")"
|
2021-09-08 13:11:48 +03:00
|
|
|
mold=`pwd`/../../mold
|
2021-12-22 13:38:00 +03:00
|
|
|
echo -n "Testing $(basename -s .sh "$0") ... "
|
|
|
|
t=$(pwd)/../../out/test/elf/$(basename -s .sh "$0")
|
|
|
|
mkdir -p "$t"
|
2021-03-02 14:24:31 +03:00
|
|
|
|
2021-12-22 13:38:00 +03:00
|
|
|
cat <<EOF | cc -c -fPIC -o"$t"/a.o -xc -
|
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-12-22 13:38:00 +03:00
|
|
|
clang -fuse-ld="$mold" -shared -fPIC -o "$t"/b.so "$t"/a.o -Wl,-Bsymbolic
|
2021-07-19 18:21:12 +03:00
|
|
|
|
2021-12-22 13:38:00 +03:00
|
|
|
cat <<EOF | cc -c -o "$t"/c.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-12-22 13:38:00 +03:00
|
|
|
clang -fuse-ld="$mold" -no-pie -o "$t"/exe "$t"/c.o "$t"/b.so
|
|
|
|
"$t"/exe | grep -q '3 4 0'
|
2021-03-02 14:24:31 +03:00
|
|
|
|
|
|
|
echo OK
|