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 501f66b commit 8f57d2a
Show file tree
Hide file tree
Showing 29 changed files with 69 additions and 85 deletions.
3 changes: 1 addition & 2 deletions test/arch-x86_64-note2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ EOF

./mold -o $t/exe $t/a.o $t/b.o $t/c.o $t/d.o

readelf --segments $t/exe > $t/log
grep -Fq '01 .note.a .note.c .note.b' $t/log
readelf --segments $t/exe | grep -Fq '01 .note.a .note.c .note.b'
2 changes: 1 addition & 1 deletion test/arch-x86_64-warn-execstack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ cat <<EOF | $CC -o $t/b.o -c -xc -
int main() {}
EOF

$GCC -B. -o $t/exe $t/a.o $t/b.o 2>&1 | grep -Eq 'may cause a segmentation fault|requires executable stack'
$GCC -B. -o $t/exe $t/a.o $t/b.o |& grep -Eq 'may cause a segmentation fault|requires executable stack'
2 changes: 1 addition & 1 deletion test/bno-symbolic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# GCC produces buggy code for this test case on s390x.
# https://sourceware.org/bugzilla/show_bug.cgi?id=29655
[ $MACHINE = s390x ] && $CC -v 2>&1 | grep -E '^gcc version 1[0-5]\.' && skip
[ $MACHINE = s390x ] && $CC -v |& grep -E '^gcc version 1[0-5]\.' && skip

cat <<EOF | $CC -c -fPIC -o$t/a.o -xc -
int foo = 4;
Expand Down
2 changes: 1 addition & 1 deletion test/canonical-plt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# GCC produces buggy code for this test case on s390x.
# https://sourceware.org/bugzilla/show_bug.cgi?id=29655
[ $MACHINE = s390x ] && $CC -v 2>&1 | grep -E '^gcc version 1[0-5]\.' && skip
[ $MACHINE = s390x ] && $CC -v |& grep -E '^gcc version 1[0-5]\.' && skip

cat <<EOF | $CC -o $t/a.so -fPIC -shared -xc -
void *foo() {
Expand Down
8 changes: 4 additions & 4 deletions test/cmdline.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
. $(dirname $0)/common.inc

{ ./mold -zfoo || true; } 2>&1 | grep -q 'unknown command line option: -zfoo'
{ ./mold -z foo || true; } 2>&1 | grep -q 'unknown command line option: -z foo'
{ ./mold -abcdefg || true; } 2>&1 | grep -q 'unknown command line option: -abcdefg'
{ ./mold --abcdefg || true; } 2>&1 | grep -q 'unknown command line option: --abcdefg'
not ./mold -zfoo |& grep -q 'unknown command line option: -zfoo'
not ./mold -z foo |& grep -q 'unknown command line option: -z foo'
not ./mold -abcdefg |& grep -q 'unknown command line option: -abcdefg'
not ./mold --abcdefg |& grep -q 'unknown command line option: --abcdefg'
8 changes: 4 additions & 4 deletions test/color-diagnostics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int foo();
int main() { foo(); }
EOF

not ./mold -o $t/exe $t/a.o --color-diagnostics 2>&1 | not grep -q $'\033'
not ./mold -o $t/exe $t/a.o --color-diagnostics=always 2>&1 | grep -q $'\033'
not ./mold -o $t/exe $t/a.o --color-diagnostics=never 2>&1 | not grep -q $'\033'
not ./mold -o $t/exe $t/a.o --color-diagnostics=auto 2>&1 | not grep -q $'\033'
not ./mold -o $t/exe $t/a.o --color-diagnostics |& not grep -q $'\033'
not ./mold -o $t/exe $t/a.o --color-diagnostics=always |& grep -q $'\033'
not ./mold -o $t/exe $t/a.o --color-diagnostics=never |& not grep -q $'\033'
not ./mold -o $t/exe $t/a.o --color-diagnostics=auto |& not grep -q $'\033'
2 changes: 1 addition & 1 deletion test/common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ test_cxxflags() {
}

is_musl() {
ldd --version 2>&1 | grep -q musl
ldd --version |& grep -q musl
}

supports_ifunc() {
Expand Down
16 changes: 8 additions & 8 deletions test/demangle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ int main() {
}
EOF

not $CC -B. -o $t/exe $t/a.o -Wl,-no-demangle 2> $t/log
grep -q 'undefined symbol: _Z3fooii$' $t/log
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 2> $t/log
grep -Eq 'undefined symbol: foo\(int, int\)$' $t/log
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 2> $t/log
grep -Eq 'undefined symbol: foo\(int, int\)$' $t/log
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 -
extern int Pi;
Expand All @@ -24,5 +24,5 @@ int main() {
}
EOF

not $CC -B. -o $t/exe $t/b.o -Wl,-demangle 2> $t/log
grep -q 'undefined symbol: Pi$' $t/log
not $CC -B. -o $t/exe $t/b.o -Wl,-demangle |& \
grep -q 'undefined symbol: Pi$'
15 changes: 3 additions & 12 deletions test/dynamic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@ echo '.globl main; main:' | $CC -o $t/a.o -c -x assembler -

$CC -B. -o $t/exe $t/a.o

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

readelf -W --dyn-syms --use-dynamic $t/exe > $t/log2
grep -Eq 'FUNC\s+GLOBAL\s+DEFAULT.*UND\s+__libc_start' $t/log2

cat <<EOF | $CC -c -fPIC -o $t/b.o -xc -
#include <stdio.h>
int main() {
printf("Hello world\n");
}
EOF
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/empty-arg.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
. $(dirname $0)/common.inc

not ./mold -m elf_x86_64 '' 2>&1 | grep -q 'cannot open :'
not ./mold -m elf_x86_64 '' |& grep -q 'cannot open :'
3 changes: 1 addition & 2 deletions test/exclude-libs2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ int foo() {
EOF

$CC -B. -shared -o $t/d.so $t/c.o $t/b.a -Wl,-exclude-libs=b.a
readelf --dyn-syms $t/d.so > $t/log
grep -Fq foo $t/log
readelf --dyn-syms $t/d.so | grep -Fq foo
3 changes: 1 addition & 2 deletions test/exclude-libs3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ void foo() { bar(); }
EOF

$CC -B. -shared -o $t/d.so $t/c.o $t/b.a -Wl,-exclude-libs=ALL
readelf --dyn-syms $t/d.so > $t/log
grep -Fq foo $t/log
readelf --dyn-syms $t/d.so | grep -Fq foo
2 changes: 1 addition & 1 deletion test/linker-script-error.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ EOF

echo 'VERSION { ver_x /*' > $t/b.script

not $CC -B. -o $t/exe $t/a.o $t/b.script 2>&1 | grep -q 'unclosed comment'
not $CC -B. -o $t/exe $t/a.o $t/b.script |& grep -q 'unclosed comment'
2 changes: 1 addition & 1 deletion test/lto-gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int main() {
}
EOF

$GCC -B. -o $t/exe2 $t/b.o --verbose 2>&1 | grep -q -- -fwpa
$GCC -B. -o $t/exe2 $t/b.o --verbose |& grep -q -- -fwpa

# Test FAT objects if -fno-use-linker-plugin is used

Expand Down
5 changes: 2 additions & 3 deletions test/nocopyreloc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +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 2> $t/log

grep -q 'recompile with -fPIC' $t/log
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/physical-image-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[ $MACHINE = ppc64 ] && skip

# BusyBox's grep can't handle capture groups (e.g. \1, \2 ...)
grep --version 2>&1 | grep BusyBox && skip
grep --version |& grep BusyBox && skip

cat <<EOF | $CC -o $t/a.o -c -xc -
#include <stdio.h>
Expand Down
4 changes: 2 additions & 2 deletions test/relocatable-debug-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ EOF

# It looks like objdump prints out a warning message for
# object files compiled with Clang.
$OBJDUMP --dwarf=info $t/a.o $t/b.o 2>&1 | grep -q 'Warning: DIE at offset' && skip
$OBJDUMP --dwarf=info $t/a.o $t/b.o |& grep -q 'Warning: DIE at offset' && skip

./mold --relocatable -o $t/c.o $t/a.o $t/b.o

$CC -B. -o $t/exe $t/c.o
$QEMU $t/exe | grep -q 'Hello world'

$OBJDUMP --dwarf=info $t/c.o > /dev/null 2>&1 | not grep -q Warning
$OBJDUMP --dwarf=info $t/c.o > /dev/null |& not grep -q Warning
9 changes: 3 additions & 6 deletions test/relro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ EOF

$CC -B. -o $t/exe1 $t/a.o -Wl,-z,relro,-z,lazy
$QEMU $t/exe1 | grep -q 'Hello world'
readelf --segments -W $t/exe1 > $t/log1
grep -q 'GNU_RELRO ' $t/log1
readelf --segments -W $t/exe1 | grep -q 'GNU_RELRO '

$CC -B. -o $t/exe2 $t/a.o -Wl,-z,relro,-z,now
$QEMU $t/exe2 | grep -q 'Hello world'
readelf --segments -W $t/exe2 > $t/log2
grep -q 'GNU_RELRO ' $t/log2
readelf --segments -W $t/exe2 | grep -q 'GNU_RELRO '

$CC -B. -o $t/exe3 $t/a.o -Wl,-z,norelro
$QEMU $t/exe3 | grep -q 'Hello world'
readelf --segments -W $t/exe3 > $t/log3
not grep -q 'GNU_RELRO ' $t/log3
readelf --segments -W $t/exe3 | not grep -q 'GNU_RELRO '
4 changes: 2 additions & 2 deletions test/run-clang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ EOF

LD_PRELOAD=`pwd`/mold-wrapper.so MOLD_PATH=`pwd`/mold \
clang -no-pie -o $t/exe $t/a.o -fuse-ld=/usr/bin/ld
readelf -p .comment $t/exe > $t/log
grep -q mold $t/log

readelf -p .comment $t/exe | grep -q mold
6 changes: 3 additions & 3 deletions test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ EOF

LD_PRELOAD=`pwd`/mold-wrapper.so MOLD_PATH=`pwd`/mold \
$CC -o $t/exe $t/a.o -B/usr/bin
readelf -p .comment $t/exe > $t/log
grep -q mold $t/log

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

./mold -run env | grep -q '^MOLD_PATH=.*/mold$'

Expand All @@ -44,7 +44,7 @@ EOF
chmod 755 $t/sh

./mold -run $t/sh ld --version | grep -q mold
./mold -run $t/sh foo.ld --version >& /dev/null | grep -q mold && false
./mold -run $t/sh foo.ld --version |& not grep -q mold

./mold -run $t/sh $t/ld --version | grep -q mold
./mold -run $t/sh $t/ld.lld --version | grep -q mold
Expand Down
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 2>&1 | \
not $CC -B. -o $t/exe3 $t/a.o -Wl,--section-align=.foo=3 |& \
grep -q 'must be a power of 2'
16 changes: 8 additions & 8 deletions test/unresolved-symbols.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ int foo();
int main() { foo(); }
EOF

not $CC -B. -o $t/exe $t/a.o 2>&1 | grep -q 'undefined.*foo'
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 2>&1 \
| grep -q 'undefined.*foo'
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

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 2>&1 | grep -q 'undefined.*foo'
-Wl,--warn-unresolved-symbols |& grep -q 'undefined.*foo'

$CC -B. -o $t/exe $t/a.o -Wl,-unresolved-symbols=ignore-in-object-files 2>&1 \
| not grep -q 'undefined.*foo'
$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 2>&1 \
| grep -q 'undefined.*foo'
not $CC -B. -o $t/exe $t/a.o -Wl,-unresolved-symbols=ignore-in-shared-libs |& \
grep -q 'undefined.*foo'
6 changes: 3 additions & 3 deletions test/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ int main() {
EOF

rm -f $t/exe
$CC -B. -Wl,--version -o $t/exe1 $t/a.o 2>&1 | grep -q mold
$CC -B. -Wl,--version -o $t/exe1 $t/a.o |& grep -q mold
not [ -f $t/exe1 ]

$CC -B. -Wl,-v -o $t/exe2 $t/a.o 2>&1 | grep -q mold
$CC -B. -Wl,-v -o $t/exe2 $t/a.o |& grep -q mold
$QEMU $t/exe2 | grep -q 'Hello world'

not ./mold --v 2>&1 | grep -q 'unknown command line option:'
not ./mold --v |& grep -q 'unknown command line option:'
2 changes: 1 addition & 1 deletion test/warn-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ int main() {
EOF

$CC -B. -o $t/exe $t/a.o $t/b.o | not grep -Fq 'multiple common symbols'
$CC -B. -o $t/exe $t/a.o $t/b.o -Wl,-warn-common 2>&1 | grep -Fq 'multiple common symbols'
$CC -B. -o $t/exe $t/a.o $t/b.o -Wl,-warn-common |& grep -Fq 'multiple common symbols'
8 changes: 4 additions & 4 deletions test/warn-unresolved-symbols.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ int main() {
}
EOF

not $CC -B. -o $t/exe $t/a.o 2>&1 | grep -q 'undefined symbol:.*foo'
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 2>&1 \
| grep -q 'undefined symbol:.*foo'
$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 \
-Wl,--error-unresolved-symbols 2>&1 | grep -q 'undefined symbol:.*foo'
-Wl,--error-unresolved-symbols |& grep -q 'undefined symbol:.*foo'
2 changes: 1 addition & 1 deletion test/weak-undef2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ int foo();
int bar() { return foo(); }
EOF

not $CC -B. -o $t/exe $t/a.o $t/b.o 2>&1 | grep -q 'undefined symbol: foo'
not $CC -B. -o $t/exe $t/a.o $t/b.o |& grep -q 'undefined symbol: foo'
12 changes: 6 additions & 6 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 2> $t/log
grep -q 'undefined symbol:.* foo' $t/log
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 2> $t/log
grep -q 'undefined symbol:.* foo' $t/log
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 2> $t/log
grep -q 'undefined symbol:.* foo$' $t/log
$CC -B. -shared -o $t/c.so $t/a.o -Wl,-z,defs -Wl,--warn-unresolved-symbols |& \
grep -q 'undefined symbol:.* foo$'
2 changes: 1 addition & 1 deletion test/z-sectionheader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ EOF
$CC -B. -o $t/exe $t/a.o -Wl,-z,nosectionheader
$QEMU $t/exe | grep -q 'Hello world'

readelf -h $t/exe 2>&1 | grep -Eq 'Size of section headers:\s+0 '
readelf -h $t/exe |& grep -Eq 'Size of section headers:\s+0 '
4 changes: 2 additions & 2 deletions test/z-unknown.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
. $(dirname $0)/common.inc

./mold -z no-such-opt 2>&1 | grep -q 'unknown command line option: -z no-such-opt'
./mold -zno-such-opt 2>&1 | grep -q 'unknown command line option: -zno-such-opt'
./mold -z no-such-opt |& grep -q 'unknown command line option: -z no-such-opt'
./mold -zno-such-opt |& grep -q 'unknown command line option: -zno-such-opt'

0 comments on commit 8f57d2a

Please sign in to comment.