Skip to content

Commit

Permalink
Add lots of quotes to shell scripts
Browse files Browse the repository at this point in the history
This makes it possible to build and test mold in a path that contains
whitespace characters - with the notable exception of the tests where
`LD_PRELOAD` is used. That's because `LD_PRELOAD` unconditionally treats
any whitespace as separator, regardless of quoting.

The following ShellCheck warnings are eliminated by this commit:
* SC2046: Quote this to prevent word splitting.
* SC2086: Double quote to prevent globbing and word splitting.

Signed-off-by: Christoph Erhardt <[email protected]>
  • Loading branch information
sicherha committed Dec 29, 2021
1 parent 1c6c8c3 commit 0dcc910
Show file tree
Hide file tree
Showing 221 changed files with 2,474 additions and 2,474 deletions.
2 changes: 1 addition & 1 deletion build-static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ fi

docker run -it --rm "${docker_args[@]}" \
mold-build-ubuntu20 \
make -C /mold -j$(nproc) EXTRA_LDFLAGS="$EXTRA_LDFLAGS" "$@"
make -C /mold -j"$(nproc)" EXTRA_LDFLAGS="$EXTRA_LDFLAGS" "$@"
24 changes: 12 additions & 12 deletions test/elf/aarch64-hello-static.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/bin/bash
export LANG=
set -e
cd $(dirname $0)
cd "$(dirname "$0")"
mold=`pwd`/../../mold
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh $0)
mkdir -p $t
echo -n "Testing $(basename -s .sh "$0") ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh "$0")
mkdir -p "$t"

[ $(uname -m) = x86_64 ] || { echo skipped; exit; }
[ "$(uname -m)" = x86_64 ] || { echo skipped; exit; }

echo 'int main() {}' | aarch64-linux-gnu-gcc -o $t/exe -xc - >& /dev/null \
echo 'int main() {}' | aarch64-linux-gnu-gcc -o "$t"/exe -xc - >& /dev/null \
|| { echo skipped; exit; }

cat <<EOF | aarch64-linux-gnu-gcc -o $t/a.o -c -g -xc -
cat <<EOF | aarch64-linux-gnu-gcc -o "$t"/a.o -c -g -xc -
#include <stdio.h>
int main() {
Expand All @@ -21,12 +21,12 @@ int main() {
}
EOF

aarch64-linux-gnu-gcc -B`dirname $mold` -o $t/exe $t/a.o -static
aarch64-linux-gnu-gcc -B"`dirname "$mold"`" -o "$t"/exe "$t"/a.o -static

readelf -p .comment $t/exe | grep -qw mold
readelf -p .comment "$t"/exe | grep -qw mold

readelf -a $t/exe > $t/log
grep -Pq 'Machine:\s+AArch64' $t/log
qemu-aarch64 -L /usr/aarch64-linux-gnu $t/exe | grep -q 'Hello world'
readelf -a "$t"/exe > "$t"/log
grep -Pq 'Machine:\s+AArch64' "$t"/log
qemu-aarch64 -L /usr/aarch64-linux-gnu "$t"/exe | grep -q 'Hello world'

echo OK
18 changes: 9 additions & 9 deletions test/elf/allow-multiple-definition.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/bin/bash
export LANG=
set -e
cd $(dirname $0)
cd "$(dirname "$0")"
mold=`pwd`/../../mold
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh $0)
mkdir -p $t
echo -n "Testing $(basename -s .sh "$0") ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh "$0")
mkdir -p "$t"

echo 'int main() { return 0; }' > $t/a.c
echo 'int main() { return 0; }' > $t/b.c
echo 'int main() { return 0; }' > "$t"/a.c
echo 'int main() { return 0; }' > "$t"/b.c

! clang -fuse-ld=$mold -o $t/exe $t/a.c $t/b.c 2> /dev/null || false
clang -fuse-ld=$mold -o $t/exe $t/a.c $t/b.c -Wl,-allow-multiple-definition
clang -fuse-ld=$mold -o $t/exe $t/a.c $t/b.c -Wl,-z,muldefs
! clang -fuse-ld="$mold" -o "$t"/exe "$t"/a.c "$t"/b.c 2> /dev/null || false
clang -fuse-ld="$mold" -o "$t"/exe "$t"/a.c "$t"/b.c -Wl,-allow-multiple-definition
clang -fuse-ld="$mold" -o "$t"/exe "$t"/a.c "$t"/b.c -Wl,-z,muldefs

echo OK
22 changes: 11 additions & 11 deletions test/elf/ar-alignment.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#!/bin/bash
export LANG=
set -e
cd $(dirname $0)
cd "$(dirname "$0")"
mold=`pwd`/../../mold
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh $0)
mkdir -p $t
echo -n "Testing $(basename -s .sh "$0") ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh "$0")
mkdir -p "$t"

cat <<EOF | cc -o $t/a.o -c -xc -
cat <<EOF | cc -o "$t"/a.o -c -xc -
int two() { return 2; }
EOF

head -c 1 /dev/zero >> $t/a.o
head -c 1 /dev/zero >> "$t"/a.o

cat <<EOF | cc -o $t/b.o -c -xc -
cat <<EOF | cc -o "$t"/b.o -c -xc -
int three() { return 3; }
EOF

cat <<EOF | cc -o $t/c.o -c -xc -
cat <<EOF | cc -o "$t"/c.o -c -xc -
#include <stdio.h>
int two();
Expand All @@ -28,9 +28,9 @@ int main() {
}
EOF

rm -f $t/d.a
ar rcs $t/d.a $t/a.o $t/b.o
rm -f "$t"/d.a
ar rcs "$t"/d.a "$t"/a.o "$t"/b.o

clang -fuse-ld=$mold -o $t/exe $t/c.o $t/d.a
clang -fuse-ld="$mold" -o "$t"/exe "$t"/c.o "$t"/d.a

echo OK
30 changes: 15 additions & 15 deletions test/elf/as-needed-weak.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
#!/bin/bash
export LANG=
set -e
cd $(dirname $0)
cd "$(dirname "$0")"
mold=`pwd`/../../mold
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh $0)
mkdir -p $t
echo -n "Testing $(basename -s .sh "$0") ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh "$0")
mkdir -p "$t"

cat <<EOF | cc -fPIC -o $t/a.o -c -xc -
cat <<EOF | cc -fPIC -o "$t"/a.o -c -xc -
__attribute__((weak)) int fn1();
int main() {
fn1();
}
EOF

cat <<EOF | cc -o $t/b.so -shared -fPIC -Wl,-soname,libfoo.so -xc -
cat <<EOF | cc -o "$t"/b.so -shared -fPIC -Wl,-soname,libfoo.so -xc -
int fn1() { return 42; }
EOF

cat <<EOF | cc -o $t/c.so -shared -fPIC -Wl,-soname,libbar.so -xc -
cat <<EOF | cc -o "$t"/c.so -shared -fPIC -Wl,-soname,libbar.so -xc -
int fn2() { return 42; }
EOF

clang -fuse-ld=$mold -o $t/exe $t/a.o $t/b.so $t/c.so
clang -fuse-ld="$mold" -o "$t"/exe "$t"/a.o "$t"/b.so "$t"/c.so

readelf --dynamic $t/exe > $t/readelf
fgrep -q 'Shared library: [libfoo.so]' $t/readelf
fgrep -q 'Shared library: [libbar.so]' $t/readelf
readelf --dynamic "$t"/exe > "$t"/readelf
fgrep -q 'Shared library: [libfoo.so]' "$t"/readelf
fgrep -q 'Shared library: [libbar.so]' "$t"/readelf

clang -fuse-ld=$mold -o $t/exe $t/a.o -Wl,-as-needed $t/b.so $t/c.so
clang -fuse-ld="$mold" -o "$t"/exe "$t"/a.o -Wl,-as-needed "$t"/b.so "$t"/c.so

readelf --dynamic $t/exe > $t/readelf
! fgrep -q 'Shared library: [libfoo.so]' $t/readelf || false
! fgrep -q 'Shared library: [libbar.so]' $t/readelf || false
readelf --dynamic "$t"/exe > "$t"/readelf
! fgrep -q 'Shared library: [libfoo.so]' "$t"/readelf || false
! fgrep -q 'Shared library: [libbar.so]' "$t"/readelf || false

echo OK
30 changes: 15 additions & 15 deletions test/elf/as-needed.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
#!/bin/bash
export LANG=
set -e
cd $(dirname $0)
cd "$(dirname "$0")"
mold=`pwd`/../../mold
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh $0)
mkdir -p $t
echo -n "Testing $(basename -s .sh "$0") ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh "$0")
mkdir -p "$t"

cat <<EOF | cc -o $t/a.o -c -xc -
cat <<EOF | cc -o "$t"/a.o -c -xc -
void fn1();
int main() {
fn1();
}
EOF

cat <<EOF | cc -o $t/b.so -shared -fPIC -Wl,-soname,libfoo.so -xc -
cat <<EOF | cc -o "$t"/b.so -shared -fPIC -Wl,-soname,libfoo.so -xc -
int fn1() { return 42; }
EOF

cat <<EOF | cc -o $t/c.so -shared -fPIC -Wl,-soname,libbar.so -xc -
cat <<EOF | cc -o "$t"/c.so -shared -fPIC -Wl,-soname,libbar.so -xc -
int fn2() { return 42; }
EOF

clang -fuse-ld=$mold -o $t/exe $t/a.o $t/b.so $t/c.so
clang -fuse-ld="$mold" -o "$t"/exe "$t"/a.o "$t"/b.so "$t"/c.so

readelf --dynamic $t/exe > $t/readelf
fgrep -q 'Shared library: [libfoo.so]' $t/readelf
fgrep -q 'Shared library: [libbar.so]' $t/readelf
readelf --dynamic "$t"/exe > "$t"/readelf
fgrep -q 'Shared library: [libfoo.so]' "$t"/readelf
fgrep -q 'Shared library: [libbar.so]' "$t"/readelf

clang -fuse-ld=$mold -o $t/exe $t/a.o -Wl,--as-needed $t/b.so $t/c.so
clang -fuse-ld="$mold" -o "$t"/exe "$t"/a.o -Wl,--as-needed "$t"/b.so "$t"/c.so

readelf --dynamic $t/exe > $t/readelf
fgrep -q 'Shared library: [libfoo.so]' $t/readelf
! fgrep -q 'Shared library: [libbar.so]' $t/readelf || false
readelf --dynamic "$t"/exe > "$t"/readelf
fgrep -q 'Shared library: [libfoo.so]' "$t"/readelf
! fgrep -q 'Shared library: [libbar.so]' "$t"/readelf || false

echo OK
28 changes: 14 additions & 14 deletions test/elf/as-needed2.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
#!/bin/bash
export LANG=
set -e
cd $(dirname $0)
cd "$(dirname "$0")"
mold=`pwd`/../../mold
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh $0)
mkdir -p $t
echo -n "Testing $(basename -s .sh "$0") ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh "$0")
mkdir -p "$t"

cat <<EOF | cc -shared -fPIC -o $t/a.so -xc -
cat <<EOF | cc -shared -fPIC -o "$t"/a.so -xc -
int foo() { return 3; }
EOF

cat <<EOF | cc -shared -fPIC -o $t/b.so -xc -
cat <<EOF | cc -shared -fPIC -o "$t"/b.so -xc -
int bar() { return 3; }
EOF

cat <<EOF | cc -shared -fPIC -o $t/c.so -xc -
cat <<EOF | cc -shared -fPIC -o "$t"/c.so -xc -
int foo();
int baz() { return foo(); }
EOF

cat <<EOF | cc -c -o $t/d.o -xc -
cat <<EOF | cc -c -o "$t"/d.o -xc -
#include <stdio.h>
int baz();
int main() {
printf("%d\n", baz());
}
EOF

clang -fuse-ld=$mold -o $t/exe $t/d.o -Wl,--as-needed \
$t/c.so $t/b.so $t/a.so
clang -fuse-ld="$mold" -o "$t"/exe "$t"/d.o -Wl,--as-needed \
"$t"/c.so "$t"/b.so "$t"/a.so

readelf --dynamic $t/exe > $t/log
grep -q /a.so $t/log
grep -q /c.so $t/log
! grep -q /b.so $t/log || false
readelf --dynamic "$t"/exe > "$t"/log
grep -q /a.so "$t"/log
grep -q /c.so "$t"/log
! grep -q /b.so "$t"/log || false

echo OK
18 changes: 9 additions & 9 deletions test/elf/auxiliary.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#!/bin/bash
export LANG=
set -e
cd $(dirname $0)
cd "$(dirname "$0")"
mold=`pwd`/../../mold
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh $0)
mkdir -p $t
echo -n "Testing $(basename -s .sh "$0") ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh "$0")
mkdir -p "$t"

cat <<EOF | cc -o $t/a.o -c -x assembler -
cat <<EOF | cc -o "$t"/a.o -c -x assembler -
.text
.globl _start
_start:
nop
EOF

$mold -o $t/b.so $t/a.o -auxiliary foo -f bar -shared
"$mold" -o "$t"/b.so "$t"/a.o -auxiliary foo -f bar -shared

readelf --dynamic $t/b.so > $t/log
fgrep -q 'Auxiliary library: [foo]' $t/log
fgrep -q 'Auxiliary library: [bar]' $t/log
readelf --dynamic "$t"/b.so > "$t"/log
fgrep -q 'Auxiliary library: [foo]' "$t"/log
fgrep -q 'Auxiliary library: [bar]' "$t"/log

echo OK
20 changes: 10 additions & 10 deletions test/elf/basic.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/bin/bash
export LANG=
set -e
cd $(dirname $0)
cd "$(dirname "$0")"
mold=`pwd`/../../mold
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh $0)
mkdir -p $t
echo -n "Testing $(basename -s .sh "$0") ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh "$0")
mkdir -p "$t"

[ $(uname -m) = x86_64 ] || { echo skipped; exit; }
[ "$(uname -m)" = x86_64 ] || { echo skipped; exit; }

echo '.globl _start; _start: jmp loop' | cc -o $t/a.o -c -x assembler -
echo '.globl loop; loop: jmp loop' | cc -o $t/b.o -c -x assembler -
$mold -static -o $t/exe $t/a.o $t/b.o
objdump -d $t/exe > /dev/null
file $t/exe | grep -q ELF
echo '.globl _start; _start: jmp loop' | cc -o "$t"/a.o -c -x assembler -
echo '.globl loop; loop: jmp loop' | cc -o "$t"/b.o -c -x assembler -
"$mold" -static -o "$t"/exe "$t"/a.o "$t"/b.o
objdump -d "$t"/exe > /dev/null
file "$t"/exe | grep -q ELF

echo OK
18 changes: 9 additions & 9 deletions test/elf/bno-symbolic.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash
export LANG=
set -e
cd $(dirname $0)
cd "$(dirname "$0")"
mold=`pwd`/../../mold
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh $0)
mkdir -p $t
echo -n "Testing $(basename -s .sh "$0") ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh "$0")
mkdir -p "$t"

cat <<EOF | cc -c -fPIC -o$t/a.o -xc -
cat <<EOF | cc -c -fPIC -o"$t"/a.o -xc -
int foo = 4;
int get_foo() {
Expand All @@ -19,9 +19,9 @@ void *bar() {
}
EOF

clang -fuse-ld=$mold -shared -fPIC -o $t/b.so $t/a.o -Wl,-Bsymbolic -Wl,-Bno-symbolic
clang -fuse-ld="$mold" -shared -fPIC -o "$t"/b.so "$t"/a.o -Wl,-Bsymbolic -Wl,-Bno-symbolic

cat <<EOF | cc -c -o $t/c.o -xc - -fno-PIE
cat <<EOF | cc -c -o "$t"/c.o -xc - -fno-PIE
#include <stdio.h>
extern int foo;
Expand All @@ -34,7 +34,7 @@ int main() {
}
EOF

clang -fuse-ld=$mold -no-pie -o $t/exe $t/c.o $t/b.so
$t/exe | grep -q '3 3 1'
clang -fuse-ld="$mold" -no-pie -o "$t"/exe "$t"/c.o "$t"/b.so
"$t"/exe | grep -q '3 3 1'

echo OK
Loading

0 comments on commit 0dcc910

Please sign in to comment.