1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-04 08:37:28 +03:00
mold/test/elf/x86_64_warn-textrel.sh
Rui Ueyama 930964ab38 [ELF] Do not run target-specific tests on unintended targets
This commit reduces the number of tests that are invoked only to
print out the "skipped" message.
2022-10-01 10:29:40 +08:00

37 lines
805 B
Bash
Executable File

#!/bin/bash
export LC_ALL=C
set -e
CC="${TEST_CC:-cc}"
CXX="${TEST_CXX:-c++}"
GCC="${TEST_GCC:-gcc}"
GXX="${TEST_GXX:-g++}"
MACHINE="${MACHINE:-$(uname -m)}"
testname=$(basename "$0" .sh)
echo -n "Testing $testname ... "
t=out/test/elf/$MACHINE/$testname
mkdir -p $t
# Skip if libc is musl
ldd --help 2>&1 | grep -q musl && { echo skipped; exit; }
# Skip if target is not x86-64
[ $MACHINE = x86_64 ] || { echo skipped; exit; }
cat <<'EOF' | $CC -c -o $t/a.o -x assembler -
.globl fn
fn:
movabs main, %rax
ret
EOF
cat <<EOF | $CC -c -o $t/b.o -fPIC -xc -
void fn();
int main() { fn(); }
EOF
$CC -B. -o $t/exe $t/a.o $t/b.o -pie -Wl,-warn-textrel >& $t/log
grep -q 'relocation against symbol `main'\'' in read-only section' $t/log
grep -q 'creating a DT_TEXTREL in an output file' $t/log
echo OK