1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-04 16:48:04 +03:00
mold/test/macho/weak-def-dylib.sh
2022-06-26 17:21:26 +08:00

44 lines
787 B
Bash
Executable File

#!/bin/bash
export LC_ALL=C
set -e
CC="${CC:-cc}"
CXX="${CXX:-c++}"
GCC="${GCC:-gcc}"
GXX="${GXX:-g++}"
OBJDUMP="${OBJDUMP:-objdump}"
MACHINE="${MACHINE:-$(uname -m)}"
testname=$(basename "$0" .sh)
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
t=out/test/macho/$testname
mkdir -p $t
cat <<EOF | $CC -c -o $t/a.o -xc -
int foo() __attribute__((weak));
int foo() {
return 3;
}
EOF
clang --ld-path=./ld64 -shared -o $t/b.dylib $t/a.o
cat <<EOF | $CC -c -o $t/c.o -xc -
#include <stdio.h>
int foo() __attribute((weak));
int main() {
printf("%d\n", foo ? foo() : 42);
}
EOF
clang --ld-path=./ld64 -o $t/exe $t/b.dylib $t/c.o
$t/exe | grep -q '^3$'
clang -c -o $t/d.o -xc /dev/null
clang --ld-path=./ld64 -shared -o $t/b.dylib $t/d.o
$t/exe | grep -q '^42$'
echo OK