1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-22 18:40:59 +03:00
mold/test/copyrel-relro.sh

31 lines
716 B
Bash
Raw Normal View History

2021-02-28 17:19:29 +03:00
#!/bin/bash
set -e
2021-03-01 10:28:16 +03:00
cd $(dirname $0)
2021-02-28 17:19:29 +03:00
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/tmp/$(basename -s .sh $0)
mkdir -p $t
cat <<EOF | cc -o $t/a.o -c -xc -fno-PIE -
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 -
const char readonly[100] = "abc";
char readwrite[100] = "abc";
EOF
clang -fuse-ld=`pwd`/../mold $t/a.o $t/b.so -o $t/exe
readelf -a $t/exe > $t/log
2021-03-13 15:29:02 +03:00
fgrep -q '[21] .dynbss.rel.ro' $t/log
fgrep -q '[24] .dynbss' $t/log
fgrep -q '00000000002021e0 100 OBJECT GLOBAL DEFAULT 21 readonly' $t/log
fgrep -q '0000000000203040 100 OBJECT GLOBAL DEFAULT 24 readwrite' $t/log
2021-02-28 17:19:29 +03:00
echo OK