1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-26 21:20:46 +03:00
mold/test/elf/weak-undef4.sh
Yang Liu 9ce963b480 Add an another weak undef test
This test ensures that mold does not extract archive members to resolve
undefined weak symbols.

Signed-off-by: Yang Liu <liuyang22@iscas.ac.cn>
2023-02-11 14:51:30 +08:00

38 lines
587 B
Bash
Executable File

#!/bin/bash
. $(dirname $0)/common.inc
cat <<EOF | $CC -c -o $t/a.o -xc -
#include <stdio.h>
__attribute__((weak)) int foo();
int bar();
int main() {
bar();
printf("%d\n", foo ? foo() : -1);
}
EOF
cat <<EOF | $CC -c -o $t/b.o -xc -
#include <stdio.h>
__attribute__((weak)) int foo();
int main() {
printf("%d\n", foo ? foo() : -1);
}
EOF
cat <<EOF | $CC -fcommon -xc -c -o $t/c.o -
int foo() { return 2; }
void bar() {}
EOF
ar rcs $t/d.a $t/c.o
$CC -B. -o $t/exe1 $t/a.o $t/d.a
$CC -B. -o $t/exe2 $t/b.o $t/d.a
$QEMU $t/exe1 | grep -q '^2$'
$QEMU $t/exe2 | grep -q '^-1$'