Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Feb 8, 2025
1 parent 8f57d2a commit 0619541
Show file tree
Hide file tree
Showing 24 changed files with 34 additions and 42 deletions.
3 changes: 1 addition & 2 deletions test/arch-arm-range-extension-thunk.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash
. $(dirname $0)/common.inc

echo 'int main() {}' | $CC -c -o /dev/null -xc - -O0 -mthumb >& /dev/null \
|| skip
echo 'int main() {}' | $CC -c -o /dev/null -xc - -O0 -mthumb >& /dev/null || skip

cat <<EOF > $t/a.c
#include <stdio.h>
Expand Down
3 changes: 1 addition & 2 deletions test/arch-arm-tlsdesc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

is_musl && skip

echo 'int main() {}' | $GCC -c -o /dev/null -xc - -O0 -mthumb >& /dev/null \
|| skip
echo 'int main() {}' | $GCC -c -o /dev/null -xc - -O0 -mthumb >& /dev/null || skip

cat <<EOF > $t/a.c
extern _Thread_local int foo;
Expand Down
2 changes: 1 addition & 1 deletion test/arch-x86_64-gnu-linkonce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ EOF

$CC -B. -o $t/exe $t/a.o $t/b.o $t/c.o
$OBJDUMP -d $t/exe >& /dev/null || skip
$OBJDUMP -d $t/exe | grep -A1 '<__x86.get_pc_thunk.bx>:' | \
$OBJDUMP -d $t/exe | grep -A1 '<__x86.get_pc_thunk.bx>:' |
grep -Fq 'puts$plt'
3 changes: 1 addition & 2 deletions test/arch-x86_64-incompatible-libs.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash
. $(dirname $0)/common.inc

echo 'int main() {}' | $CC -m32 -o $t/exe -xc - >& /dev/null \
|| skip
echo 'int main() {}' | $CC -m32 -o $t/exe -xc - >& /dev/null || skip

cat <<EOF | $CC -m32 -c -o $t/a.o -xc -
char hello[] = "Hello world";
Expand Down
8 changes: 3 additions & 5 deletions test/arch-x86_64-incompatible-libs2.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash
. $(dirname $0)/common.inc

echo 'int main() {}' | $CC -m32 -o $t/exe -xc - >& /dev/null \
|| skip
echo 'int main() {}' | $CC -m32 -o $t/exe -xc - >& /dev/null || skip

cat <<EOF | $CC -m32 -c -o $t/a.o -xc -
char hello[] = "Hello world";
Expand Down Expand Up @@ -31,8 +30,7 @@ EOF
mkdir -p $t/script
echo 'GROUP(libfoo.so)' > $t/script/libfoo.so

$CC -B. -o $t/exe -L$t/lib32 -L$t/lib64 -lfoo $t/e.o -Wl,-rpath $t/lib64 \
>& $t/log
$CC -B. -o $t/exe -L$t/lib32 -L$t/lib64 -lfoo $t/e.o -Wl,-rpath $t/lib64 |&
grep -q 'lib32/libfoo.so: skipping incompatible file'

grep -q 'lib32/libfoo.so: skipping incompatible file' $t/log
$QEMU $t/exe | grep -q 'Hello world'
3 changes: 1 addition & 2 deletions test/arch-x86_64-incompatible-obj.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash
. $(dirname $0)/common.inc

echo 'int main() {}' | $CC -m32 -o $t/exe -xc - >& /dev/null \
|| skip
echo 'int main() {}' | $CC -m32 -o $t/exe -xc - >& /dev/null || skip

cat <<EOF | $CC -c -o $t/a.o -m64 -xc -
int main() {}
Expand Down
2 changes: 1 addition & 1 deletion test/arch-x86_64-note-property2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ readelf -n $t/exe1 | grep -q 'x86 ISA used: x86-64-baseline, x86-64-v2, x86-64-v

./mold -nostdlib -o $t/exe2 $t/a.o $t/b.o $t/c.o
readelf -n $t/exe2 | not grep -q 'x86 feature: SHSTK'
readelf -n $t/exe2 | grep -q 'x86 ISA needed: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4' || false
readelf -n $t/exe2 | grep -q 'x86 ISA needed: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4'
readelf -n $t/exe2 | not grep -q 'x86 ISA used: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4'

./mold --relocatable -o $t/d.o $t/a.o $t/b.o
Expand Down
2 changes: 1 addition & 1 deletion test/common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ supports_tlsdesc() {
# TLSDESC may not be supported on old systems. Compile a DSO with
# it to see if it is actually supported.
echo '_Thread_local int x; int y() { return x; }' |
$CC -shared -fPIC -xc -o $t/tlsdesc.so $tlsdesc_opt - 2> /dev/null || \
$CC -shared -fPIC -xc -o $t/tlsdesc.so $tlsdesc_opt - 2> /dev/null ||
return 1
echo 'int y(); int main() { y(); }' | $CC -xc -c -o $t/tlsdesc.o -
$CC -o $t/tlsdesc $t/tlsdesc.o $t/tlsdesc.so
Expand Down
2 changes: 1 addition & 1 deletion test/defsym2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ void foo() {}
EOF

$CC -B. -o $t/b.so -shared -Wl,-defsym=bar=foo $t/a.o
nm -D $t/b.so | grep -q 'bar' || false
nm -D $t/b.so | grep -q 'bar'
8 changes: 4 additions & 4 deletions test/demangle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ int main() {
}
EOF

not $CC -B. -o $t/exe $t/a.o -Wl,-no-demangle |& \
not $CC -B. -o $t/exe $t/a.o -Wl,-no-demangle |&
grep -q 'undefined symbol: _Z3fooii$'

not $CC -B. -o $t/exe $t/a.o -Wl,-demangle |& \
not $CC -B. -o $t/exe $t/a.o -Wl,-demangle |&
grep -Eq 'undefined symbol: foo\(int, int\)$'

not $CC -B. -o $t/exe $t/a.o |& \
not $CC -B. -o $t/exe $t/a.o |&
grep -Eq 'undefined symbol: foo\(int, int\)$'

cat <<EOF | $CC -c -o $t/b.o -xc -
Expand All @@ -24,5 +24,5 @@ int main() {
}
EOF

not $CC -B. -o $t/exe $t/b.o -Wl,-demangle |& \
not $CC -B. -o $t/exe $t/b.o -Wl,-demangle |&
grep -q 'undefined symbol: Pi$'
2 changes: 1 addition & 1 deletion test/dynamic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ $CC -B. -o $t/exe $t/a.o

readelf --dynamic $t/exe | grep -Eq 'Shared library:.*\blibc\b'

readelf -W --dyn-syms --use-dynamic $t/exe | \
readelf -W --dyn-syms --use-dynamic $t/exe |
grep -Eq 'FUNC\s+GLOBAL\s+DEFAULT.*UND\s+__libc_start'
2 changes: 1 addition & 1 deletion test/glibc-2.22-bug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ int main() {
EOF

$CC -B. -o $t/b.so -shared $t/a.o
readelf -W --sections $t/b.so | grep -E -A1 '\.rela?\.dyn' | \
readelf -W --sections $t/b.so | grep -E -A1 '\.rela?\.dyn' |
grep -Eq '\.rela?\.plt'
3 changes: 1 addition & 2 deletions test/lto-gcc.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash
. $(dirname $0)/common.inc

echo 'int main() {}' | $GCC -B. -flto -o /dev/null -xc - >& /dev/null \
|| skip
echo 'int main() {}' | $GCC -B. -flto -o /dev/null -xc - >& /dev/null || skip

cat <<EOF | $GCC -flto -c -o $t/a.o -xc -
#include <stdio.h>
Expand Down
3 changes: 1 addition & 2 deletions test/lto-llvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

[ $MACHINE = $(uname -m) ] || skip

echo 'int main() {}' | clang -B. -flto -o /dev/null -xc - >& /dev/null \
|| skip
echo 'int main() {}' | clang -B. -flto -o /dev/null -xc - >& /dev/null || skip

cat <<EOF | clang -flto -c -o $t/a.o -xc -
#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion test/many-sections.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
. $(dirname $0)/common.inc

seq 1 100000 | sed 's/.*/.section .data.\0,"aw"\n.word 0\n/g' | \
seq 1 100000 | sed 's/.*/.section .data.\0,"aw"\n.word 0\n/g' |
$CC -c -xassembler -o $t/a.o -

cat <<'EOF' | $CC -c -xc -o $t/b.o -
Expand Down
2 changes: 1 addition & 1 deletion test/nocopyreloc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ EOF
$CC -B. -no-pie -o $t/exe $t/a.so $t/b.o
$QEMU $t/exe | grep -q '3 5'

not $CC -B. -o $t/exe $t/a.so $t/b.o -no-pie -Wl,-z,nocopyreloc |& \
not $CC -B. -o $t/exe $t/a.so $t/b.o -no-pie -Wl,-z,nocopyreloc |&
grep -q 'recompile with -fPIC'
2 changes: 1 addition & 1 deletion test/relocatable-many-sections.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# OneTBB isn't tsan-clean
nm mold | grep -q '__tsan_init' && skip

seq 1 80000 | sed 's/.*/.section .data.\0,"aw"\n.word 0\n/g' | \
seq 1 80000 | sed 's/.*/.section .data.\0,"aw"\n.word 0\n/g' |
$CC -c -xassembler -o $t/a.o -

cat <<'EOF' | $CC -c -xc -o $t/b.o -
Expand Down
4 changes: 2 additions & 2 deletions test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ chmod 755 $t/ld $t/ld.lld $t/ld.gold $t/foo.ld
./mold -run $t/ld --version | grep -q mold
./mold -run $t/ld.lld --version | grep -q mold
./mold -run $t/ld.gold --version | grep -q mold
./mold -run $t/foo.ld --version | grep -q mold && false
./mold -run $t/foo.ld --version | not grep -q mold

cat <<'EOF' > $t/sh
#!/bin/sh
Expand All @@ -49,4 +49,4 @@ chmod 755 $t/sh
./mold -run $t/sh $t/ld --version | grep -q mold
./mold -run $t/sh $t/ld.lld --version | grep -q mold
./mold -run $t/sh $t/ld.gold --version | grep -q mold
./mold -run $t/sh $t/foo.ld --version | grep -q mold && false
./mold -run $t/sh $t/foo.ld --version | not grep -q mold
2 changes: 1 addition & 1 deletion test/section-align.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ readelf -WS $t/exe1 | grep -q '\.foo.* 8192$'
$CC -B. -o $t/exe2 $t/a.o -Wl,--section-align=.foo=256
readelf -WS $t/exe2 | grep -q '\.foo.* 256$'

not $CC -B. -o $t/exe3 $t/a.o -Wl,--section-align=.foo=3 |& \
not $CC -B. -o $t/exe3 $t/a.o -Wl,--section-align=.foo=3 |&
grep -q 'must be a power of 2'
2 changes: 1 addition & 1 deletion test/shuffle-sections-seed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ EOF

# Create a lot of sections to lower the probability that
# we get the identical output as a result of shuffling.
for i in `seq 1 1000`; do echo "void fn$i() {}"; done | \
for i in `seq 1 1000`; do echo "void fn$i() {}"; done |
$CC -o $t/b.o -ffunction-sections -c -xc -

$CC -B. -o $t/exe1 $t/a.o $t/b.o
Expand Down
2 changes: 1 addition & 1 deletion test/shuffle-sections.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ EOF

# Create a lot of sections to lower the probability that
# we get the identical output as a result of shuffling.
for i in `seq 1 1000`; do echo "void fn$i() {}"; done | \
for i in `seq 1 1000`; do echo "void fn$i() {}"; done |
$CC -o $t/b.o -ffunction-sections -c -xc -

$CC -B. -o $t/exe1 $t/a.o $t/b.o
Expand Down
6 changes: 3 additions & 3 deletions test/unresolved-symbols.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ EOF

not $CC -B. -o $t/exe $t/a.o |& grep -q 'undefined.*foo'

not $CC -B. -o $t/exe $t/a.o -Wl,-unresolved-symbols=report-all |& \
not $CC -B. -o $t/exe $t/a.o -Wl,-unresolved-symbols=report-all |&
grep -q 'undefined.*foo'

$CC -B. -o $t/exe $t/a.o -Wl,-unresolved-symbols=ignore-all
Expand All @@ -18,8 +18,8 @@ readelf --dyn-syms $t/exe | not grep -w foo
$CC -B. -o $t/exe $t/a.o -Wl,-unresolved-symbols=report-all \
-Wl,--warn-unresolved-symbols |& grep -q 'undefined.*foo'

$CC -B. -o $t/exe $t/a.o -Wl,-unresolved-symbols=ignore-in-object-files |& \
$CC -B. -o $t/exe $t/a.o -Wl,-unresolved-symbols=ignore-in-object-files |&
not grep -q 'undefined.*foo'

not $CC -B. -o $t/exe $t/a.o -Wl,-unresolved-symbols=ignore-in-shared-libs |& \
not $CC -B. -o $t/exe $t/a.o -Wl,-unresolved-symbols=ignore-in-shared-libs |&
grep -q 'undefined.*foo'
2 changes: 1 addition & 1 deletion test/warn-unresolved-symbols.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ EOF

not $CC -B. -o $t/exe $t/a.o |& grep -q 'undefined symbol:.*foo'

$CC -B. -o $t/exe $t/a.o -Wl,-warn-unresolved-symbols |& \
$CC -B. -o $t/exe $t/a.o -Wl,-warn-unresolved-symbols |&
grep -q 'undefined symbol:.*foo'

not $CC -B. -o $t/exe $t/a.o -Wl,-warn-unresolved-symbols \
Expand Down
6 changes: 3 additions & 3 deletions test/z-defs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ EOF
$CC -B. -shared -o $t/b.so $t/a.o
$CC -B. -shared -o $t/b.so $t/a.o -Wl,-z,undefs

not $CC -B. -shared -o $t/b.so $t/a.o -Wl,-z,defs |& \
not $CC -B. -shared -o $t/b.so $t/a.o -Wl,-z,defs |&
grep -q 'undefined symbol:.* foo'

not $CC -B. -shared -o $t/b.so $t/a.o -Wl,-no-undefined |& \
not $CC -B. -shared -o $t/b.so $t/a.o -Wl,-no-undefined |&
grep -q 'undefined symbol:.* foo'

$CC -B. -shared -o $t/c.so $t/a.o -Wl,-z,defs -Wl,--warn-unresolved-symbols |& \
$CC -B. -shared -o $t/c.so $t/a.o -Wl,-z,defs -Wl,--warn-unresolved-symbols |&
grep -q 'undefined symbol:.* foo$'

0 comments on commit 0619541

Please sign in to comment.