1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-04 16:48:04 +03:00
mold/test/elf/copyrel-relro.sh

34 lines
683 B
Bash
Raw Normal View History

2021-02-28 17:19:29 +03:00
#!/bin/bash
export LANG=
2021-02-28 17:19:29 +03:00
set -e
CC="${CC:-cc}"
CXX="${CXX:-c++}"
testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
2022-01-07 12:06:53 +03:00
t=out/test/elf/$testname
mkdir -p $t
2021-02-28 17:19:29 +03:00
2022-01-07 12:06:53 +03:00
cat <<EOF | $CC -o $t/a.o -c -xc -fno-PIE -
2021-02-28 17:19:29 +03:00
extern const char readonly[100];
extern char readwrite[100];
int main() {
return readonly[0] + readwrite[0];
}
EOF
2022-01-18 07:10:34 +03:00
cat <<EOF | $CC -fPIC -shared -o $t/b.so -xc -
2021-02-28 17:19:29 +03:00
const char readonly[100] = "abc";
char readwrite[100] = "abc";
EOF
2022-01-07 12:06:53 +03:00
$CC -B. $t/a.o $t/b.so -o $t/exe
readelf -a $t/exe > $t/log
2021-02-28 17:19:29 +03:00
2022-01-07 12:06:53 +03:00
grep -Pqz '(?s)\[(\d+)\] .dynbss.rel.ro .* \1 readonly' $t/log
grep -Pqz '(?s)\[(\d+)\] .dynbss .* \1 readwrite' $t/log
2021-02-28 17:19:29 +03:00
echo OK