1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-15 14:36:25 +03:00
mold/test/wrap.sh

51 lines
757 B
Bash
Raw Normal View History

2021-05-21 19:12:24 +03:00
#!/bin/bash
set -e
cd $(dirname $0)
2021-07-21 08:49:02 +03:00
mold=`pwd`/../mold
2021-05-21 19:12:24 +03:00
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/tmp/$(basename -s .sh $0)
mkdir -p $t
cat <<EOF | clang -c -o $t/a.o -xc -
#include <stdio.h>
void foo() {
printf("foo\n");
}
EOF
cat <<EOF | clang -c -o $t/b.o -xc -
#include <stdio.h>
void foo();
void __wrap_foo() {
printf("wrap_foo\n");
}
int main() {
foo();
}
EOF
cat <<EOF | clang -c -o $t/c.o -xc -
#include <stdio.h>
void __real_foo();
int main() {
__real_foo();
}
EOF
clang -fuse-ld=$mold -o $t/exe $t/a.o $t/b.o
2021-05-21 19:12:24 +03:00
$t/exe | grep -q '^foo$'
clang -fuse-ld=$mold -o $t/exe $t/a.o $t/b.o -Wl,-wrap,foo
2021-05-21 19:12:24 +03:00
$t/exe | grep -q '^wrap_foo$'
clang -fuse-ld=$mold -o $t/exe $t/a.o $t/c.o -Wl,-wrap,foo
2021-05-21 19:12:24 +03:00
$t/exe | grep -q '^foo$'
echo OK