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

32 lines
686 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
testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
2021-02-28 17:19:29 +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
cat <<EOF | cc -shared -o "$t"/b.so -xc -
2021-02-28 17:19:29 +03:00
const char readonly[100] = "abc";
char readwrite[100] = "abc";
EOF
clang -fuse-ld="$mold" "$t"/a.o "$t"/b.so -o "$t"/exe
readelf -a "$t"/exe > "$t"/log
2021-02-28 17:19:29 +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