1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-10 19:26:38 +03:00

Use relative paths in tests

This commit is contained in:
Rui Ueyama 2022-01-07 18:06:53 +09:00
parent 4324cb2998
commit e7decd2c77
225 changed files with 2002 additions and 2003 deletions

View File

@ -7,15 +7,15 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
[ "$(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() {
@ -24,12 +24,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

View File

@ -7,14 +7,14 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
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
! $CC -B. -o "$t"/exe "$t"/a.c "$t"/b.c 2> /dev/null || false
$CC -B. -o "$t"/exe "$t"/a.c "$t"/b.c -Wl,-allow-multiple-definition
$CC -B. -o "$t"/exe "$t"/a.c "$t"/b.c -Wl,-z,muldefs
! $CC -B. -o $t/exe $t/a.c $t/b.c 2> /dev/null || false
$CC -B. -o $t/exe $t/a.c $t/b.c -Wl,-allow-multiple-definition
$CC -B. -o $t/exe $t/a.c $t/b.c -Wl,-z,muldefs
echo OK

View File

@ -7,20 +7,20 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
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();
@ -31,9 +31,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
$CC -B. -o "$t"/exe "$t"/c.o "$t"/d.a
$CC -B. -o $t/exe $t/c.o $t/d.a
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
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() {
@ -18,24 +18,24 @@ int main() {
}
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
$CC -B. -o "$t"/exe "$t"/a.o -Wl,-no-as-needed "$t"/b.so "$t"/c.so
$CC -B. -o $t/exe $t/a.o -Wl,-no-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
readelf --dynamic $t/exe > $t/readelf
fgrep -q 'Shared library: [libfoo.so]' $t/readelf
fgrep -q 'Shared library: [libbar.so]' $t/readelf
$CC -B. -o "$t"/exe "$t"/a.o -Wl,-as-needed "$t"/b.so "$t"/c.so
$CC -B. -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

View File

@ -7,34 +7,34 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
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
$CC -B. -o "$t"/exe "$t"/a.o -Wl,--no-as-needed "$t"/b.so "$t"/c.so
$CC -B. -o $t/exe $t/a.o -Wl,--no-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
readelf --dynamic $t/exe > $t/readelf
fgrep -q 'Shared library: [libfoo.so]' $t/readelf
fgrep -q 'Shared library: [libbar.so]' $t/readelf
$CC -B. -o "$t"/exe "$t"/a.o -Wl,--as-needed "$t"/b.so "$t"/c.so
$CC -B. -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

View File

@ -7,23 +7,23 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
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() {
@ -31,12 +31,12 @@ int main() {
}
EOF
$CC -B. -o "$t"/exe "$t"/d.o -Wl,--as-needed \
"$t"/c.so "$t"/b.so "$t"/a.so
$CC -B. -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

View File

@ -7,20 +7,20 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
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

View File

@ -7,15 +7,15 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
[ "$(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

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
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() {
@ -22,9 +22,9 @@ void *bar() {
}
EOF
$CC -B. -shared -fPIC -o "$t"/b.so "$t"/a.o -Wl,-Bsymbolic -Wl,-Bno-symbolic
$CC -B. -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;
@ -37,7 +37,7 @@ int main() {
}
EOF
$CC -B. -no-pie -o "$t"/exe "$t"/c.o "$t"/b.so
"$t"/exe | grep -q '3 3 1'
$CC -B. -no-pie -o $t/exe $t/c.o $t/b.so
$t/exe | grep -q '3 3 1'
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -c -o "$t"/a.o -fPIC -xc -
cat <<EOF | $CC -c -o $t/a.o -fPIC -xc -
int foo = 4;
int get_foo() {
@ -22,9 +22,9 @@ void *bar() {
}
EOF
$CC -B. -shared -o "$t"/b.so "$t"/a.o -Wl,-Bsymbolic-functions
$CC -B. -shared -o $t/b.so $t/a.o -Wl,-Bsymbolic-functions
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;
@ -37,7 +37,7 @@ int main() {
}
EOF
$CC -B. -no-pie -o "$t"/exe "$t"/c.o "$t"/b.so
"$t"/exe | grep -q '3 3 0'
$CC -B. -no-pie -o $t/exe $t/c.o $t/b.so
$t/exe | grep -q '3 3 0'
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
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() {
@ -22,9 +22,9 @@ void *bar() {
}
EOF
$CC -B. -shared -fPIC -o "$t"/b.so "$t"/a.o -Wl,-Bsymbolic
$CC -B. -shared -fPIC -o $t/b.so $t/a.o -Wl,-Bsymbolic
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;
@ -37,7 +37,7 @@ int main() {
}
EOF
$CC -B. -no-pie -o "$t"/exe "$t"/c.o "$t"/b.so
"$t"/exe | grep -q '3 4 0'
$CC -B. -no-pie -o $t/exe $t/c.o $t/b.so
$t/exe | grep -q '3 4 0'
echo OK

View File

@ -7,21 +7,21 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
# Verify that mold does not crash if no object file is included
# in the output. The resulting executable doesn't contain any
# meaningful code or data, so this is an edge case, though.
cat <<EOF | $CC -x assembler -c -o "$t"/a.o -
cat <<EOF | $CC -x assembler -c -o $t/a.o -
.globl foo
foo:
EOF
rm -f "$t"/a.a
ar rcs "$t"/a.a "$t"/a.o
rm -f $t/a.a
ar rcs $t/a.a $t/a.o
"$mold" -o "$t"/exe "$t"/a.a
"$mold" -o $t/exe $t/a.a
echo OK

View File

@ -7,28 +7,28 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
echo 'int main() { return 0; }' > "$t"/a.c
echo 'int main() { return 0; }' > $t/a.c
$CC -B. -o "$t"/exe "$t"/a.c -Wl,-build-id
readelf -n "$t"/exe | grep -qv 'GNU.*0x00000010.*NT_GNU_BUILD_ID'
$CC -B. -o $t/exe $t/a.c -Wl,-build-id
readelf -n $t/exe | grep -qv 'GNU.*0x00000010.*NT_GNU_BUILD_ID'
$CC -B. -o "$t"/exe "$t"/a.c -Wl,-build-id=uuid
readelf -nW "$t"/exe |
$CC -B. -o $t/exe $t/a.c -Wl,-build-id=uuid
readelf -nW $t/exe |
grep -Pq 'GNU.*0x00000010.*NT_GNU_BUILD_ID.*Build ID: ............4...[89abcdef]'
$CC -B. -o "$t"/exe "$t"/a.c -Wl,-build-id=md5
readelf -n "$t"/exe | grep -q 'GNU.*0x00000010.*NT_GNU_BUILD_ID'
$CC -B. -o $t/exe $t/a.c -Wl,-build-id=md5
readelf -n $t/exe | grep -q 'GNU.*0x00000010.*NT_GNU_BUILD_ID'
$CC -B. -o "$t"/exe "$t"/a.c -Wl,-build-id=sha1
readelf -n "$t"/exe | grep -q 'GNU.*0x00000014.*NT_GNU_BUILD_ID'
$CC -B. -o $t/exe $t/a.c -Wl,-build-id=sha1
readelf -n $t/exe | grep -q 'GNU.*0x00000014.*NT_GNU_BUILD_ID'
$CC -B. -o "$t"/exe "$t"/a.c -Wl,-build-id=sha256
readelf -n "$t"/exe | grep -q 'GNU.*0x00000020.*NT_GNU_BUILD_ID'
$CC -B. -o $t/exe $t/a.c -Wl,-build-id=sha256
readelf -n $t/exe | grep -q 'GNU.*0x00000020.*NT_GNU_BUILD_ID'
$CC -B. -o "$t"/exe "$t"/a.c -Wl,-build-id=0xdeadbeef
readelf -n "$t"/exe | grep -q 'Build ID: deadbeef'
$CC -B. -o $t/exe $t/a.c -Wl,-build-id=0xdeadbeef
readelf -n $t/exe | grep -q 'Build ID: deadbeef'
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.so -fPIC -shared -xc -
cat <<EOF | $CC -o $t/a.so -fPIC -shared -xc -
void *foo() {
return foo;
}
@ -20,7 +20,7 @@ void *bar() {
}
EOF
cat <<EOF | $CC -o "$t"/b.o -c -xc - -fPIC
cat <<EOF | $CC -o $t/b.o -c -xc - -fPIC
void *bar();
void *baz() {
@ -28,7 +28,7 @@ void *baz() {
}
EOF
cat <<EOF | $CC -o "$t"/c.o -c -xc - -fno-PIC
cat <<EOF | $CC -o $t/c.o -c -xc - -fno-PIC
#include <stdio.h>
void *foo();
@ -40,7 +40,7 @@ int main() {
}
EOF
$CC -B. -no-pie -o "$t"/exe "$t"/a.so "$t"/b.o "$t"/c.o
"$t"/exe | grep -q '^1 1 1$'
$CC -B. -no-pie -o $t/exe $t/a.so $t/b.o $t/c.o
$t/exe | grep -q '^1 1 1$'
echo OK

View File

@ -7,8 +7,8 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
(! "$mold" -zfoo) 2>&1 | grep -q 'unknown command line option: -zfoo'
(! "$mold" -z foo) 2>&1 | grep -q 'unknown command line option: -z foo'

View File

@ -7,24 +7,24 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -o $t/a.o -c -xc -
int foo();
int main() { foo(); }
EOF
! "$mold" -o "$t"/exe "$t"/a.o --color-diagnostics 2> "$t"/log
grep -Pq '\e' "$t"/log
! "$mold" -o $t/exe $t/a.o --color-diagnostics 2> $t/log
grep -Pq '\e' $t/log
! "$mold" -o "$t"/exe "$t"/a.o --color-diagnostics=always 2> "$t"/log
grep -Pq '\e' "$t"/log
! "$mold" -o $t/exe $t/a.o --color-diagnostics=always 2> $t/log
grep -Pq '\e' $t/log
! "$mold" -o "$t"/exe "$t"/a.o --color-diagnostics=never 2> "$t"/log
! grep -Pq '\e' "$t"/log || false
! "$mold" -o $t/exe $t/a.o --color-diagnostics=never 2> $t/log
! grep -Pq '\e' $t/log || false
! "$mold" -o "$t"/exe "$t"/a.o --color-diagnostics=auto 2> "$t"/log
! grep -Pq '\e' "$t"/log || false
! "$mold" -o $t/exe $t/a.o --color-diagnostics=auto 2> $t/log
! grep -Pq '\e' $t/log || false
echo OK

View File

@ -7,14 +7,14 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -c -o "$t"/a.o -xc -
cat <<EOF | $CC -c -o $t/a.o -xc -
int main() {}
EOF
$CC -B. -o "$t"/exe "$t"/a.o
readelf -p .comment "$t"/exe | grep -q 'mold'
$CC -B. -o $t/exe $t/a.o
readelf -p .comment $t/exe | grep -q 'mold'
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -fcommon -xc -c -o "$t"/a.o -
cat <<EOF | $CC -fcommon -xc -c -o $t/a.o -
#include <stdio.h>
int foo;
@ -22,30 +22,30 @@ int main() {
}
EOF
cat <<EOF | $CC -fcommon -xc -c -o "$t"/b.o -
cat <<EOF | $CC -fcommon -xc -c -o $t/b.o -
int foo = 5;
EOF
cat <<EOF | $CC -fcommon -xc -c -o "$t"/c.o -
cat <<EOF | $CC -fcommon -xc -c -o $t/c.o -
int bar;
int two() { return 2; }
EOF
rm -f "$t"/d.a
ar rcs "$t"/d.a "$t"/b.o "$t"/c.o
rm -f $t/d.a
ar rcs $t/d.a $t/b.o $t/c.o
$CC -B. -o "$t"/exe "$t"/a.o "$t"/d.a
"$t"/exe | grep -q '5 0 -1'
$CC -B. -o $t/exe $t/a.o $t/d.a
$t/exe | grep -q '5 0 -1'
cat <<EOF | $CC -fcommon -xc -c -o "$t"/e.o -
cat <<EOF | $CC -fcommon -xc -c -o $t/e.o -
int bar = 0;
int two() { return 2; }
EOF
rm -f "$t"/e.a
ar rcs "$t"/e.a "$t"/b.o "$t"/e.o
rm -f $t/e.a
ar rcs $t/e.a $t/b.o $t/e.o
$CC -B. -o "$t"/exe "$t"/a.o "$t"/e.a
"$t"/exe | grep -q '5 0 2'
$CC -B. -o $t/exe $t/a.o $t/e.a
$t/exe | grep -q '5 0 2'
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -fcommon -xc -c -o "$t"/a.o -
cat <<EOF | $CC -fcommon -xc -c -o $t/a.o -
#include <stdio.h>
int bar;
@ -20,23 +20,23 @@ int main() {
}
EOF
cat <<EOF | $CC -fcommon -xc -c -o "$t"/b.o -
cat <<EOF | $CC -fcommon -xc -c -o $t/b.o -
int foo;
EOF
rm -f "$t"/c.a
ar rcs "$t"/c.a "$t"/b.o
rm -f $t/c.a
ar rcs $t/c.a $t/b.o
cat <<EOF | $CC -fcommon -xc -c -o "$t"/d.o -
cat <<EOF | $CC -fcommon -xc -c -o $t/d.o -
int foo;
int bar = 5;
int get_foo() { return foo; }
EOF
rm -f "$t"/e.a
ar rcs "$t"/e.a "$t"/d.o
rm -f $t/e.a
ar rcs $t/e.a $t/d.o
$CC -B. -o "$t"/exe "$t"/a.o "$t"/c.a "$t"/e.a
"$t"/exe | grep -q 5
$CC -B. -o $t/exe $t/a.o $t/c.a $t/e.a
$t/exe | grep -q 5
echo OK

View File

@ -7,16 +7,16 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -fcommon -xc -c -o "$t"/a.o -
cat <<EOF | $CC -fcommon -xc -c -o $t/a.o -
int foo;
int bar;
int baz = 42;
EOF
cat <<EOF | $CC -fcommon -xc -c -o "$t"/b.o -
cat <<EOF | $CC -fcommon -xc -c -o $t/b.o -
#include <stdio.h>
int foo;
@ -28,10 +28,10 @@ int main() {
}
EOF
$CC -B. -o "$t"/exe "$t"/a.o "$t"/b.o
"$t"/exe | grep -q '0 5 42'
$CC -B. -o $t/exe $t/a.o $t/b.o
$t/exe | grep -q '0 5 42'
readelf --sections "$t"/exe > "$t"/log
grep -q '.common .*NOBITS' "$t"/log
readelf --sections $t/exe > $t/log
grep -q '.common .*NOBITS' $t/log
echo OK

View File

@ -7,12 +7,12 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
which dwarfdump >& /dev/null || { echo skipped; exit; }
cat <<EOF | $CC -c -g -o "$t"/a.o -xc -
cat <<EOF | $CC -c -g -o $t/a.o -xc -
#include <stdio.h>
int main() {
@ -21,14 +21,14 @@ int main() {
}
EOF
$CC -B. -o "$t"/exe "$t"/a.o -Wl,--compress-debug-sections=zlib
dwarfdump "$t"/exe > "$t"/log
fgrep -q '.debug_info SHF_COMPRESSED' "$t"/log
fgrep -q '.debug_str SHF_COMPRESSED' "$t"/log
$CC -B. -o $t/exe $t/a.o -Wl,--compress-debug-sections=zlib
dwarfdump $t/exe > $t/log
fgrep -q '.debug_info SHF_COMPRESSED' $t/log
fgrep -q '.debug_str SHF_COMPRESSED' $t/log
$CC -B. -o "$t"/exe "$t"/a.o -Wl,--compress-debug-sections=zlib-gnu
dwarfdump "$t"/exe > "$t"/log
fgrep -q .zdebug_info "$t"/log
fgrep -q .zdebug_str "$t"/log
$CC -B. -o $t/exe $t/a.o -Wl,--compress-debug-sections=zlib-gnu
dwarfdump $t/exe > $t/log
fgrep -q .zdebug_info $t/log
fgrep -q .zdebug_str $t/log
echo OK

View File

@ -7,25 +7,25 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
which dwarfdump >& /dev/null || { echo skipped; exit; }
cat <<EOF | g++ -c -o "$t"/a.o -g -gz=zlib-gnu -xc++ -
cat <<EOF | g++ -c -o $t/a.o -g -gz=zlib-gnu -xc++ -
int main() {
return 0;
}
EOF
cat <<EOF | g++ -c -o "$t"/b.o -g -gz=zlib -xc++ -
cat <<EOF | g++ -c -o $t/b.o -g -gz=zlib -xc++ -
int foo() {
return 0;
}
EOF
$CC -B. -o "$t"/exe "$t"/a.o "$t"/b.o
dwarfdump "$t"/exe > /dev/null
readelf --sections "$t"/exe | fgrep -q .debug_info
$CC -B. -o $t/exe $t/a.o $t/b.o
dwarfdump $t/exe > /dev/null
readelf --sections $t/exe | fgrep -q .debug_info
echo ' OK'

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -xc -fno-PIE -
cat <<EOF | $CC -o $t/a.o -c -xc -fno-PIE -
extern int foo;
int main() {
@ -18,11 +18,11 @@ int main() {
}
EOF
cat <<EOF | $CC -shared -o "$t"/b.so -xc -
cat <<EOF | $CC -shared -o $t/b.so -xc -
__attribute__((visibility("protected"))) int foo;
EOF
! $CC -B. "$t"/a.o "$t"/b.so -o "$t"/exe >& "$t"/log || false
fgrep -q 'cannot make copy relocation for protected symbol' "$t"/log
! $CC -B. $t/a.o $t/b.so -o $t/exe >& $t/log || false
fgrep -q 'cannot make copy relocation for protected symbol' $t/log
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -xc -fno-PIE -
cat <<EOF | $CC -o $t/a.o -c -xc -fno-PIE -
extern const char readonly[100];
extern char readwrite[100];
@ -19,15 +19,15 @@ int main() {
}
EOF
cat <<EOF | $CC -shared -o "$t"/b.so -xc -
cat <<EOF | $CC -shared -o $t/b.so -xc -
const char readonly[100] = "abc";
char readwrite[100] = "abc";
EOF
$CC -B. "$t"/a.o "$t"/b.so -o "$t"/exe
readelf -a "$t"/exe > "$t"/log
$CC -B. $t/a.o $t/b.so -o $t/exe
readelf -a $t/exe > $t/log
grep -Pqz '(?s)\[(\d+)\] .dynbss.rel.ro .* \1 readonly' "$t"/log
grep -Pqz '(?s)\[(\d+)\] .dynbss .* \1 readwrite' "$t"/log
grep -Pqz '(?s)\[(\d+)\] .dynbss.rel.ro .* \1 readonly' $t/log
grep -Pqz '(?s)\[(\d+)\] .dynbss .* \1 readwrite' $t/log
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -fno-PIC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -fno-PIC -o $t/a.o -c -xc -
#include <stdio.h>
extern int foo;
@ -22,19 +22,19 @@ int main() {
}
EOF
cat <<EOF | $CC -fno-PIC -o "$t"/b.o -c -xc -
cat <<EOF | $CC -fno-PIC -o $t/b.o -c -xc -
extern int bar;
int *get_bar() { return &bar; }
EOF
cat <<EOF | $CC -fPIC -o "$t"/c.o -c -xc -
cat <<EOF | $CC -fPIC -o $t/c.o -c -xc -
int foo = 42;
extern int bar __attribute__((alias("foo")));
extern int baz __attribute__((alias("foo")));
EOF
$CC -B. -shared -o "$t"/c.so "$t"/c.o
$CC -B. -no-pie -o "$t"/exe "$t"/a.o "$t"/b.o "$t"/c.so
"$t"/exe | grep -q '42 42 1'
$CC -B. -shared -o $t/c.so $t/c.o
$CC -B. -no-pie -o $t/exe $t/a.o $t/b.o $t/c.so
$t/exe | grep -q '42 42 1'
echo OK

View File

@ -7,18 +7,18 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -o $t/a.o -c -xc -
void foo() {}
EOF
$CC -B. -o "$t"/b.so -shared "$t"/a.o -Wl,-default-symver
readelf --dyn-syms "$t"/b.so | grep -q ' foo@@b\.so$'
$CC -B. -o $t/b.so -shared $t/a.o -Wl,-default-symver
readelf --dyn-syms $t/b.so | grep -q ' foo@@b\.so$'
$CC -B. -o "$t"/b.so -shared "$t"/a.o \
$CC -B. -o $t/b.so -shared $t/a.o \
-Wl,--soname=bar -Wl,-default-symver
readelf --dyn-syms "$t"/b.so | grep -q ' foo@@bar$'
readelf --dyn-syms $t/b.so | grep -q ' foo@@bar$'
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -fPIC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -fPIC -o $t/a.o -c -xc -
#include <stdio.h>
extern char foo;
extern char bar;
@ -25,9 +25,9 @@ int main() {
}
EOF
$CC -B. -o "$t"/exe "$t"/a.o -pie -Wl,-defsym=foo=16 \
$CC -B. -o $t/exe $t/a.o -pie -Wl,-defsym=foo=16 \
-Wl,-defsym=bar=0x2000 -Wl,-defsym=baz=print
"$t"/exe | grep -q '^Hello 0x10 0x2000$'
$t/exe | grep -q '^Hello 0x10 0x2000$'
echo OK

View File

@ -7,33 +7,33 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -c -o "$t"/a.o -xc++ -
cat <<EOF | $CC -c -o $t/a.o -xc++ -
int foo(int, int);
int main() {
foo(3, 4);
}
EOF
! $CC -B. -o "$t"/exe "$t"/a.o -Wl,-no-demangle 2> "$t"/log || false
grep -q 'undefined symbol: .*: _Z3fooii' "$t"/log
! $CC -B. -o $t/exe $t/a.o -Wl,-no-demangle 2> $t/log || false
grep -q 'undefined symbol: .*: _Z3fooii' $t/log
! $CC -B. -o "$t"/exe "$t"/a.o -Wl,-demangle 2> "$t"/log || false
grep -Pq 'undefined symbol: .*: foo\(int, int\)' "$t"/log
! $CC -B. -o $t/exe $t/a.o -Wl,-demangle 2> $t/log || false
grep -Pq 'undefined symbol: .*: foo\(int, int\)' $t/log
! $CC -B. -o "$t"/exe "$t"/a.o 2> "$t"/log || false
grep -Pq 'undefined symbol: .*: foo\(int, int\)' "$t"/log
! $CC -B. -o $t/exe $t/a.o 2> $t/log || false
grep -Pq 'undefined symbol: .*: foo\(int, int\)' $t/log
cat <<EOF | $CC -c -o "$t"/b.o -xc -
cat <<EOF | $CC -c -o $t/b.o -xc -
extern int Pi;
int main() {
return Pi;
}
EOF
! $CC -B. -o "$t"/exe "$t"/b.o -Wl,-demangle 2> "$t"/log || false
grep -q 'undefined symbol: .*: Pi' "$t"/log
! $CC -B. -o $t/exe $t/b.o -Wl,-demangle 2> $t/log || false
grep -q 'undefined symbol: .*: Pi' $t/log
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -x assembler -Wa,-L -
cat <<EOF | $CC -o $t/a.o -c -x assembler -Wa,-L -
.text
.globl _start
_start:
@ -21,28 +21,28 @@ foo:
nop
EOF
"$mold" -o "$t"/exe "$t"/a.o
readelf --symbols "$t"/exe > "$t"/log
fgrep -q _start "$t"/log
fgrep -q foo "$t"/log
fgrep -q .Lbar "$t"/log
"$mold" -o $t/exe $t/a.o
readelf --symbols $t/exe > $t/log
fgrep -q _start $t/log
fgrep -q foo $t/log
fgrep -q .Lbar $t/log
"$mold" -o "$t"/exe "$t"/a.o --discard-locals
readelf --symbols "$t"/exe > "$t"/log
fgrep -q _start "$t"/log
fgrep -q foo "$t"/log
! fgrep -q .Lbar "$t"/log || false
"$mold" -o $t/exe $t/a.o --discard-locals
readelf --symbols $t/exe > $t/log
fgrep -q _start $t/log
fgrep -q foo $t/log
! fgrep -q .Lbar $t/log || false
"$mold" -o "$t"/exe "$t"/a.o --discard-all
readelf --symbols "$t"/exe > "$t"/log
fgrep -q _start "$t"/log
! fgrep -q foo "$t"/log || false
! fgrep -q .Lbar "$t"/log || false
"$mold" -o $t/exe $t/a.o --discard-all
readelf --symbols $t/exe > $t/log
fgrep -q _start $t/log
! fgrep -q foo $t/log || false
! fgrep -q .Lbar $t/log || false
"$mold" -o "$t"/exe "$t"/a.o --strip-all
readelf --symbols "$t"/exe > "$t"/log
! fgrep -q _start "$t"/log || false
! fgrep -q foo "$t"/log || false
! fgrep -q .Lbar "$t"/log || false
"$mold" -o $t/exe $t/a.o --strip-all
readelf --symbols $t/exe > $t/log
! fgrep -q _start $t/log || false
! fgrep -q foo $t/log || false
! fgrep -q .Lbar $t/log || false
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -c -o "$t"/a.o -x assembler -
cat <<EOF | $CC -c -o $t/a.o -x assembler -
.globl main, init, fini
main:
ret
@ -20,18 +20,18 @@ fini:
ret
EOF
$CC -B. -o "$t"/exe "$t"/a.o
readelf -a "$t"/exe > "$t"/log
$CC -B. -o $t/exe $t/a.o
readelf -a $t/exe > $t/log
grep -Pqz '(?s)\(INIT\)\s+0x([0-9a-f]+)\b.*\1\s+0 \w+\s+GLOBAL \w+\s+\d+ _init\b' "$t"/log
grep -Pqz '(?s)\(INIT\)\s+0x([0-9a-f]+)\b.*\1\s+0 \w+\s+GLOBAL \w+\s+\d+ _init\b' $t/log
grep -Pqz '(?s)\(FINI\)\s+0x([0-9a-f]+)\b.*\1\s+0 \w+\s+GLOBAL \w+\s+\d+ _fini\b' "$t"/log
grep -Pqz '(?s)\(FINI\)\s+0x([0-9a-f]+)\b.*\1\s+0 \w+\s+GLOBAL \w+\s+\d+ _fini\b' $t/log
$CC -B. -o "$t"/exe "$t"/a.o -Wl,-init,init -Wl,-fini,fini
readelf -a "$t"/exe > "$t"/log
$CC -B. -o $t/exe $t/a.o -Wl,-init,init -Wl,-fini,fini
readelf -a $t/exe > $t/log
grep -Pqz '(?s)\(INIT\)\s+0x([0-9a-f]+)\b.*\1\s+0 NOTYPE GLOBAL DEFAULT\s+\d+ init\b' "$t"/log
grep -Pqz '(?s)\(INIT\)\s+0x([0-9a-f]+)\b.*\1\s+0 NOTYPE GLOBAL DEFAULT\s+\d+ init\b' $t/log
grep -Pqz '(?s)\(FINI\)\s+0x([0-9a-f]+)\b.*\1\s+0 NOTYPE GLOBAL DEFAULT\s+\d+ fini\b' "$t"/log
grep -Pqz '(?s)\(FINI\)\s+0x([0-9a-f]+)\b.*\1\s+0 NOTYPE GLOBAL DEFAULT\s+\d+ fini\b' $t/log
echo OK

View File

@ -7,31 +7,31 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -c -o "$t"/a.o -xc -
cat <<EOF | $CC -c -o $t/a.o -xc -
void foo() {}
EOF
$CC -B. -shared -o "$t"/libfoo.so "$t"/a.o -Wl,--soname,libfoo
$CC -B. -shared -o "$t"/libbar.so "$t"/a.o
$CC -B. -shared -o $t/libfoo.so $t/a.o -Wl,--soname,libfoo
$CC -B. -shared -o $t/libbar.so $t/a.o
cat <<EOF | $CC -c -o "$t"/b.o -xc -
cat <<EOF | $CC -c -o $t/b.o -xc -
void foo();
int main() { foo(); }
EOF
$CC -B. -o "$t"/exe "$t"/b.o "$t"/libfoo.so
readelf --dynamic "$t"/exe | fgrep -q 'Shared library: [libfoo]'
$CC -B. -o $t/exe $t/b.o $t/libfoo.so
readelf --dynamic $t/exe | fgrep -q 'Shared library: [libfoo]'
$CC -B. -o "$t"/exe "$t"/b.o -L "$t" -lfoo
readelf --dynamic "$t"/exe | fgrep -q 'Shared library: [libfoo]'
$CC -B. -o $t/exe $t/b.o -L $t -lfoo
readelf --dynamic $t/exe | fgrep -q 'Shared library: [libfoo]'
$CC -B. -o "$t"/exe "$t"/b.o "$t"/libbar.so
readelf --dynamic "$t"/exe | grep -Pq 'Shared library: \[.*dt-needed/libbar\.so\]'
$CC -B. -o $t/exe $t/b.o $t/libbar.so
readelf --dynamic $t/exe | grep -Pq 'Shared library: \[.*dt-needed/libbar\.so\]'
$CC -B. -o "$t"/exe "$t"/b.o -L"$t" -lbar
readelf --dynamic "$t"/exe | fgrep -q 'Shared library: [libbar.so]'
$CC -B. -o $t/exe $t/b.o -L$t -lbar
readelf --dynamic $t/exe | fgrep -q 'Shared library: [libbar.so]'
echo OK

View File

@ -7,17 +7,17 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
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 main
main:
nop
EOF
! "$mold" -o "$t"/exe "$t"/a.o "$t"/a.o 2> "$t"/log || false
grep -q 'duplicate symbol: .*\.o: .*\.o: main' "$t"/log
! "$mold" -o $t/exe $t/a.o $t/a.o 2> $t/log || false
grep -q 'duplicate symbol: .*\.o: .*\.o: main' $t/log
echo OK

View File

@ -7,25 +7,25 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -c -o "$t"/a.o -x assembler -
cat <<EOF | $CC -c -o $t/a.o -x assembler -
.globl _start
_start:
ret
EOF
"$mold" -o "$t"/exe "$t"/a.o
"$mold" -o $t/exe $t/a.o
readelf --sections "$t"/exe > "$t"/log
! fgrep .interp "$t"/log || false
readelf --sections $t/exe > $t/log
! fgrep .interp $t/log || false
readelf --dynamic "$t"/exe > "$t"/log
readelf --dynamic $t/exe > $t/log
"$mold" -o "$t"/exe "$t"/a.o --dynamic-linker=/foo/bar
"$mold" -o $t/exe $t/a.o --dynamic-linker=/foo/bar
readelf --sections "$t"/exe > "$t"/log
fgrep -q .interp "$t"/log
readelf --sections $t/exe > $t/log
fgrep -q .interp $t/log
echo OK

View File

@ -7,29 +7,29 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -o $t/a.o -c -xc -
void foo() {}
void bar() {}
int main() {}
EOF
$CC -B. -o "$t"/exe "$t"/a.o
$CC -B. -o $t/exe $t/a.o
readelf --dyn-syms "$t"/exe > "$t"/log
! grep -q ' foo$' "$t"/log || false
! grep -q ' bar$' "$t"/log || false
readelf --dyn-syms $t/exe > $t/log
! grep -q ' foo$' $t/log || false
! grep -q ' bar$' $t/log || false
cat <<EOF > "$t"/dyn
cat <<EOF > $t/dyn
{ foo; bar; };
EOF
$CC -B. -o "$t"/exe "$t"/a.o -Wl,-dynamic-list="$t"/dyn
$CC -B. -o $t/exe $t/a.o -Wl,-dynamic-list=$t/dyn
readelf --dyn-syms "$t"/exe > "$t"/log
grep -q ' foo$' "$t"/log
grep -q ' bar$' "$t"/log
readelf --dyn-syms $t/exe > $t/log
grep -q ' foo$' $t/log
grep -q ' bar$' $t/log
echo OK

View File

@ -7,34 +7,34 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -o $t/a.o -c -xc -
void foo(int x) {}
void bar(int x) {}
EOF
cat <<EOF | $CXX -o "$t"/b.o -c -xc++ -
cat <<EOF | $CXX -o $t/b.o -c -xc++ -
void baz(int x) {}
int main() {}
EOF
$CXX -B. -o "$t"/exe "$t"/a.o "$t"/b.o
$CXX -B. -o $t/exe $t/a.o $t/b.o
readelf --dyn-syms "$t"/exe > "$t"/log
! grep -q ' foo$' "$t"/log || false
! grep -q ' bar$' "$t"/log || false
readelf --dyn-syms $t/exe > $t/log
! grep -q ' foo$' $t/log || false
! grep -q ' bar$' $t/log || false
cat <<EOF > "$t"/dyn
cat <<EOF > $t/dyn
{ foo; extern "C++" { "baz(int)"; }; };
EOF
$CC -B. -o "$t"/exe "$t"/a.o "$t"/b.o -Wl,-dynamic-list="$t"/dyn
$CC -B. -o $t/exe $t/a.o $t/b.o -Wl,-dynamic-list=$t/dyn
readelf --dyn-syms "$t"/exe > "$t"/log
grep -q ' foo$' "$t"/log
! grep -q ' bar$' "$t"/log || false
grep -q ' _Z3bazi$' "$t"/log
readelf --dyn-syms $t/exe > $t/log
grep -q ' foo$' $t/log
! grep -q ' bar$' $t/log || false
grep -q ' _Z3bazi$' $t/log
echo OK

View File

@ -7,20 +7,20 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
echo '.globl main; main:' | $CC -o "$t"/a.o -c -x assembler -
echo '.globl main; main:' | $CC -o $t/a.o -c -x assembler -
$CC -B. -o "$t"/exe "$t"/a.o
$CC -B. -o $t/exe $t/a.o
readelf --dynamic "$t"/exe > "$t"/log
grep -Pq 'Shared library:.*\blibc.so\b' "$t"/log
readelf --dynamic $t/exe > $t/log
grep -Pq 'Shared library:.*\blibc.so\b' $t/log
readelf -W --dyn-syms --use-dynamic "$t"/exe > "$t"/log2
grep -Pq 'FUNC\s+GLOBAL\s+DEFAULT\s+UND\s+__libc_start_main' "$t"/log2
readelf -W --dyn-syms --use-dynamic $t/exe > $t/log2
grep -Pq 'FUNC\s+GLOBAL\s+DEFAULT\s+UND\s+__libc_start_main' $t/log2
cat <<EOF | $CC -c -fPIC -o "$t"/b.o -xc -
cat <<EOF | $CC -c -fPIC -o $t/b.o -xc -
#include <stdio.h>
int main() {
@ -28,8 +28,8 @@ int main() {
}
EOF
$CC -B. -o "$t"/exe -pie "$t"/b.o
count=$(readelf -W --relocs "$t"/exe | grep -P 'R_[\w\d_]+_RELATIVE' | wc -l)
readelf -W --dynamic "$t"/exe | grep -q "RELACOUNT.*\b$count\b"
$CC -B. -o $t/exe -pie $t/b.o
count=$(readelf -W --relocs $t/exe | grep -P 'R_[\w\d_]+_RELATIVE' | wc -l)
readelf -W --dynamic $t/exe | grep -q "RELACOUNT.*\b$count\b"
echo OK

View File

@ -7,20 +7,20 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -o $t/a.o -c -xc -
#include <stdio.h>
int main() {
printf("Hello world\n");
}
EOF
rm -f "$t"/b.script
touch "$t"/b.script
rm -f $t/b.script
touch $t/b.script
$CC -B. -o "$t"/exe "$t"/a.o -Wl,--version-script,"$t"/b.script
"$t"/exe | grep -q 'Hello world'
$CC -B. -o $t/exe $t/a.o -Wl,--version-script,$t/b.script
$t/exe | grep -q 'Hello world'
echo OK

View File

@ -7,12 +7,12 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
rm -f $t/a.o
touch $t/a.o
! $CC -B. -o "$t"/exe "$t"/a.o &> $t/log || false
! $CC -B. -o $t/exe $t/a.o &> $t/log || false
grep -q 'unknown file type: EMPTY' $t/log
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -fPIC -c -o "$t"/a.o -xc -
cat <<EOF | $CC -fPIC -c -o $t/a.o -xc -
void foo1() {}
void foo2() {}
@ -18,9 +18,9 @@ __asm__(".symver foo1, bar1@");
__asm__(".symver foo2, bar2@@");
EOF
$CC -B. -shared -o "$t"/b.so "$t"/a.o
$CC -B. -shared -o $t/b.so $t/a.o
readelf --dyn-syms "$t"/b.so | grep -q 'bar1$'
readelf --dyn-syms "$t"/b.so | grep -q 'bar2$'
readelf --dyn-syms $t/b.so | grep -q 'bar1$'
readelf --dyn-syms $t/b.so | grep -q 'bar2$'
echo OK

View File

@ -7,17 +7,17 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
# Skip if target is not x86-64
[ "$(uname -m)" = x86_64 ] || { echo skipped; exit; }
cat <<EOF | $CC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -o $t/a.o -c -xc -
void _start() {}
EOF
"$mold" -o "$t"/exe "$t"/a.o
readelf --file-header "$t"/exe | grep -qi x86-64
"$mold" -o $t/exe $t/a.o
readelf --file-header $t/exe | grep -qi x86-64
echo OK

View File

@ -7,8 +7,8 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
case "$(uname -m)" in
i386 | i686 | x86_64)
@ -23,7 +23,7 @@ aarch64)
;;
esac
cat <<EOF | $CC -o "$t"/a.o -c -x assembler -
cat <<EOF | $CC -o $t/a.o -c -x assembler -
.globl foo, bar
foo:
.quad 0
@ -31,16 +31,16 @@ bar:
.quad 0
EOF
"$mold" -e foo -static -o "$t"/exe "$t"/a.o
readelf -e "$t"/exe > "$t"/log
grep -q "Entry point address:.*$base" "$t"/log
"$mold" -e foo -static -o $t/exe $t/a.o
readelf -e $t/exe > $t/log
grep -q "Entry point address:.*$base" $t/log
"$mold" -e bar -static -o "$t"/exe "$t"/a.o
readelf -e "$t"/exe > "$t"/log
grep -q "$(printf 'Entry point address:.*0x%x' $((base + 8)))" "$t"/log
"$mold" -e bar -static -o $t/exe $t/a.o
readelf -e $t/exe > $t/log
grep -q "$(printf 'Entry point address:.*0x%x' $((base + 8)))" $t/log
"$mold" -static -o "$t"/exe "$t"/a.o
readelf -e "$t"/exe > "$t"/log
grep -q "Entry point address:.*$base" "$t"/log
"$mold" -static -o $t/exe $t/a.o
readelf -e $t/exe > $t/log
grep -q "Entry point address:.*$base" $t/log
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF > "$t"/a.cc
cat <<EOF > $t/a.cc
int main() {
try {
throw 0;
@ -21,22 +21,22 @@ int main() {
}
EOF
$CXX -B. -o "$t"/exe "$t"/a.cc -static
"$t"/exe
$CXX -B. -o $t/exe $t/a.cc -static
$t/exe
$CXX -B. -o "$t"/exe "$t"/a.cc
"$t"/exe
$CXX -B. -o $t/exe $t/a.cc
$t/exe
$CXX -B. -o "$t"/exe "$t"/a.cc -Wl,--gc-sections
"$t"/exe
$CXX -B. -o $t/exe $t/a.cc -Wl,--gc-sections
$t/exe
$CXX -B. -o "$t"/exe "$t"/a.cc -static -Wl,--gc-sections
"$t"/exe
$CXX -B. -o $t/exe $t/a.cc -static -Wl,--gc-sections
$t/exe
$CXX -B. -o "$t"/exe "$t"/a.cc -mcmodel=large
"$t"/exe
$CXX -B. -o $t/exe $t/a.cc -mcmodel=large
$t/exe
$CXX -B. -o "$t"/exe "$t"/a.cc -static -mcmodel=large
"$t"/exe
$CXX -B. -o $t/exe $t/a.cc -static -mcmodel=large
$t/exe
echo OK

View File

@ -7,28 +7,28 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -fPIC -xc -c -o "$t"/a.o -
cat <<EOF | $CC -fPIC -xc -c -o $t/a.o -
int foo() {
return 3;
}
EOF
cat <<EOF | $CC -fPIC -xc -c -o "$t"/b.o -
cat <<EOF | $CC -fPIC -xc -c -o $t/b.o -
int bar() {
return 5;
}
EOF
rm -f "$t"/c.a
ar crs "$t"/c.a "$t"/a.o
rm -f $t/c.a
ar crs $t/c.a $t/a.o
rm -f "$t"/d.a
ar crs "$t"/d.a "$t"/b.o
rm -f $t/d.a
ar crs $t/d.a $t/b.o
cat <<EOF | $CC -fPIC -xc -c -o "$t"/e.o -
cat <<EOF | $CC -fPIC -xc -c -o $t/e.o -
int foo();
int bar();
@ -39,28 +39,28 @@ int baz() {
}
EOF
$CC -B. -shared -o "$t"/f.so "$t"/e.o "$t"/c.a "$t"/d.a
readelf --dyn-syms "$t"/f.so > "$t"/log
fgrep -q foo "$t"/log
fgrep -q bar "$t"/log
fgrep -q baz "$t"/log
$CC -B. -shared -o $t/f.so $t/e.o $t/c.a $t/d.a
readelf --dyn-syms $t/f.so > $t/log
fgrep -q foo $t/log
fgrep -q bar $t/log
fgrep -q baz $t/log
$CC -B. -shared -o "$t"/f.so "$t"/e.o "$t"/c.a "$t"/d.a -Wl,-exclude-libs=c.a
readelf --dyn-syms "$t"/f.so > "$t"/log
! fgrep -q foo "$t"/log || false
fgrep -q bar "$t"/log
fgrep -q baz "$t"/log
$CC -B. -shared -o $t/f.so $t/e.o $t/c.a $t/d.a -Wl,-exclude-libs=c.a
readelf --dyn-syms $t/f.so > $t/log
! fgrep -q foo $t/log || false
fgrep -q bar $t/log
fgrep -q baz $t/log
$CC -B. -shared -o "$t"/f.so "$t"/e.o "$t"/c.a "$t"/d.a -Wl,-exclude-libs=c.a -Wl,-exclude-libs=d.a
readelf --dyn-syms "$t"/f.so > "$t"/log
! fgrep -q foo "$t"/log || false
! fgrep -q bar "$t"/log || false
fgrep -q baz "$t"/log
$CC -B. -shared -o $t/f.so $t/e.o $t/c.a $t/d.a -Wl,-exclude-libs=c.a -Wl,-exclude-libs=d.a
readelf --dyn-syms $t/f.so > $t/log
! fgrep -q foo $t/log || false
! fgrep -q bar $t/log || false
fgrep -q baz $t/log
$CC -B. -shared -o "$t"/f.so "$t"/e.o "$t"/c.a "$t"/d.a -Wl,-exclude-libs=ALL
readelf --dyn-syms "$t"/f.so > "$t"/log
! fgrep -q foo "$t"/log || false
! fgrep -q bar "$t"/log || false
fgrep -q baz "$t"/log
$CC -B. -shared -o $t/f.so $t/e.o $t/c.a $t/d.a -Wl,-exclude-libs=ALL
readelf --dyn-syms $t/f.so > $t/log
! fgrep -q foo $t/log || false
! fgrep -q bar $t/log || false
fgrep -q baz $t/log
echo OK

View File

@ -7,26 +7,26 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -x assembler -c -o "$t"/a.o -
cat <<EOF | $CC -x assembler -c -o $t/a.o -
.globl foo
foo:
ret
EOF
rm -f "$t"/b.a
ar crs "$t"/b.a "$t"/a.o
rm -f $t/b.a
ar crs $t/b.a $t/a.o
cat <<EOF | $CC -xc -c -o "$t"/c.o -
cat <<EOF | $CC -xc -c -o $t/c.o -
int foo() {
return 3;
}
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
fgrep -q foo "$t"/log
$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
fgrep -q foo $t/log
echo OK

View File

@ -7,24 +7,24 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -xc -c -o "$t"/a.o -
cat <<EOF | $CC -xc -c -o $t/a.o -
void foo();
void bar() { foo(); }
EOF
rm -f "$t"/b.a
ar crs "$t"/b.a "$t"/a.o
rm -f $t/b.a
ar crs $t/b.a $t/a.o
cat <<EOF | $CC -xc -c -o "$t"/c.o -
cat <<EOF | $CC -xc -c -o $t/c.o -
void bar();
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
fgrep -q foo "$t"/log
$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
fgrep -q foo $t/log
echo OK

View File

@ -7,24 +7,24 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -c -xc -o "$t"/a.o -
cat <<EOF | $CC -c -xc -o $t/a.o -
int main() {}
EOF
$CC -B. -o "$t"/exe "$t"/a.o -Wl,-z,execstack
readelf --segments -W "$t"/exe > "$t"/log
grep -q 'GNU_STACK.* RWE ' "$t"/log
$CC -B. -o $t/exe $t/a.o -Wl,-z,execstack
readelf --segments -W $t/exe > $t/log
grep -q 'GNU_STACK.* RWE ' $t/log
$CC -B. -o "$t"/exe "$t"/a.o -Wl,-z,execstack \
$CC -B. -o $t/exe $t/a.o -Wl,-z,execstack \
-Wl,-z,noexecstack
readelf --segments -W "$t"/exe > "$t"/log
grep -q 'GNU_STACK.* RW ' "$t"/log
readelf --segments -W $t/exe > $t/log
grep -q 'GNU_STACK.* RW ' $t/log
$CC -B. -o "$t"/exe "$t"/a.o
readelf --segments -W "$t"/exe > "$t"/log
grep -q 'GNU_STACK.* RW ' "$t"/log
$CC -B. -o $t/exe $t/a.o
readelf --segments -W $t/exe > $t/log
grep -q 'GNU_STACK.* RW ' $t/log
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
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 foo
.hidden foo
@ -24,11 +24,11 @@ _start:
nop
EOF
$CC -shared -fPIC -o "$t"/b.so -xc /dev/null
"$mold" -o "$t"/exe "$t"/a.o "$t"/b.so --export-dynamic
$CC -shared -fPIC -o $t/b.so -xc /dev/null
"$mold" -o $t/exe $t/a.o $t/b.so --export-dynamic
readelf --dyn-syms "$t"/exe > "$t"/log
fgrep -q 'NOTYPE GLOBAL DEFAULT 6 bar' "$t"/log
fgrep -q 'NOTYPE GLOBAL DEFAULT 6 _start' "$t"/log
readelf --dyn-syms $t/exe > $t/log
fgrep -q 'NOTYPE GLOBAL DEFAULT 6 bar' $t/log
fgrep -q 'NOTYPE GLOBAL DEFAULT 6 _start' $t/log
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -o $t/a.o -c -xc -
void expfn1() {}
void expfn2() {}
void foo();
@ -22,7 +22,7 @@ int main() {
}
EOF
cat <<EOF | $CC -shared -o "$t"/b.so -xc -
cat <<EOF | $CC -shared -o $t/b.so -xc -
void expfn1();
void expfn2() {}
@ -31,8 +31,8 @@ void foo() {
}
EOF
$CC -B. -o "$t"/exe "$t"/a.o "$t"/b.so
readelf --dyn-syms "$t"/exe | grep -q expfn2
readelf --dyn-syms "$t"/exe | grep -q expfn1
$CC -B. -o $t/exe $t/a.o $t/b.so
readelf --dyn-syms $t/exe | grep -q expfn2
readelf --dyn-syms $t/exe | grep -q expfn1
echo OK

View File

@ -7,14 +7,14 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -fcommon -xc -c -o "$t"/a.o -
cat <<EOF | $CC -fcommon -xc -c -o $t/a.o -
int foo;
EOF
cat <<EOF | $CC -fcommon -xc -c -o "$t"/b.o -
cat <<EOF | $CC -fcommon -xc -c -o $t/b.o -
int foo;
int main() {
@ -22,10 +22,10 @@ int main() {
}
EOF
$CC -B. -o "$t"/exe "$t"/a.o "$t"/b.o \
$CC -B. -o $t/exe $t/a.o $t/b.o \
-Wl,-warn-common 2> /dev/null
! $CC -B. -o "$t"/exe "$t"/a.o "$t"/b.o \
! $CC -B. -o $t/exe $t/a.o $t/b.o \
-Wl,-warn-common -Wl,-fatal-warnings 2> /dev/null || false
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -o $t/a.o -c -xc -
#include <stdio.h>
__attribute__((aligned(512)))
@ -24,13 +24,13 @@ int main() {
}
EOF
$CC -B. -static -Wl,--filler,0xfe -o "$t"/exe1 "$t"/a.o
sed -i -e 's/--filler 0xfe/--filler 0x00/' "$t"/exe1
hexdump -C "$t"/exe1 > "$t"/txt1
$CC -B. -static -Wl,--filler,0xfe -o $t/exe1 $t/a.o
sed -i -e 's/--filler 0xfe/--filler 0x00/' $t/exe1
hexdump -C $t/exe1 > $t/txt1
$CC -B. -static -Wl,--filler,0x00 -o "$t"/exe2 "$t"/a.o
hexdump -C "$t"/exe2 > "$t"/txt2
$CC -B. -static -Wl,--filler,0x00 -o $t/exe2 $t/a.o
hexdump -C $t/exe2 > $t/txt2
diff -q "$t"/txt1 "$t"/txt2
diff -q $t/txt1 $t/txt2
echo OK

View File

@ -7,20 +7,20 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
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 --filter foo -F bar -shared
"$mold" -o $t/b.so $t/a.o --filter foo -F bar -shared
readelf --dynamic "$t"/b.so > "$t"/log
fgrep -q 'Filter library: [foo]' "$t"/log
fgrep -q 'Filter library: [bar]' "$t"/log
readelf --dynamic $t/b.so > $t/log
fgrep -q 'Filter library: [foo]' $t/log
fgrep -q 'Filter library: [bar]' $t/log
echo OK

View File

@ -7,14 +7,14 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -shared -o "$t"/a.so -xc -
cat <<EOF | $CC -shared -o $t/a.so -xc -
void fn() {}
EOF
cat <<EOF | $CC -o "$t"/b.o -c -xc -fno-PIC -
cat <<EOF | $CC -o $t/b.o -c -xc -fno-PIC -
#include <stdio.h>
typedef void Func();
@ -27,7 +27,7 @@ int main() {
}
EOF
$CC -B. -o "$t"/exe -no-pie "$t"/b.o "$t"/a.so
"$t"/exe | grep -q 1
$CC -B. -o $t/exe -no-pie $t/b.o $t/a.so
$t/exe | grep -q 1
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF > "$t"/a.cc
cat <<EOF > $t/a.cc
#include <stdio.h>
int two() { return 2; }
@ -31,30 +31,30 @@ int main() {
}
EOF
$CXX -B. -o "$t"/exe1 "$t"/a.cc -ffunction-sections -fdata-sections
$CXX -B. -o $t/exe1 $t/a.cc -ffunction-sections -fdata-sections
readelf --symbols "$t"/exe1 > "$t"/log.1
grep -qv live_fn1 "$t"/log.1
grep -qv live_fn2 "$t"/log.1
grep -qv dead_fn1 "$t"/log.1
grep -qv dead_fn2 "$t"/log.1
grep -qv live_var1 "$t"/log.1
grep -qv live_var2 "$t"/log.1
grep -qv dead_var1 "$t"/log.1
grep -qv dead_var2 "$t"/log.1
"$t"/exe1 | grep -q '1 2'
readelf --symbols $t/exe1 > $t/log.1
grep -qv live_fn1 $t/log.1
grep -qv live_fn2 $t/log.1
grep -qv dead_fn1 $t/log.1
grep -qv dead_fn2 $t/log.1
grep -qv live_var1 $t/log.1
grep -qv live_var2 $t/log.1
grep -qv dead_var1 $t/log.1
grep -qv dead_var2 $t/log.1
$t/exe1 | grep -q '1 2'
$CXX -B. -o "$t"/exe2 "$t"/a.cc -ffunction-sections -fdata-sections -Wl,-gc-sections
$CXX -B. -o $t/exe2 $t/a.cc -ffunction-sections -fdata-sections -Wl,-gc-sections
readelf --symbols "$t"/exe2 > "$t"/log.2
grep -q live_fn1 "$t"/log.2
grep -q live_fn2 "$t"/log.2
grep -qv dead_fn1 "$t"/log.2
grep -qv dead_fn2 "$t"/log.2
grep -q live_var1 "$t"/log.2
grep -q live_var2 "$t"/log.2
grep -qv dead_var1 "$t"/log.2
grep -qv dead_var2 "$t"/log.2
"$t"/exe2 | grep -q '1 2'
readelf --symbols $t/exe2 > $t/log.2
grep -q live_fn1 $t/log.2
grep -q live_fn2 $t/log.2
grep -qv dead_fn1 $t/log.2
grep -qv dead_fn2 $t/log.2
grep -q live_var1 $t/log.2
grep -q live_var2 $t/log.2
grep -qv dead_var1 $t/log.2
grep -qv dead_var2 $t/log.2
$t/exe2 | grep -q '1 2'
echo OK

View File

@ -7,21 +7,21 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
# glibc 2.22 or prior have a bug that ld-linux.so.2 crashes on dlopen()
# if .rela.dyn and .rela.plt are not contiguous in a given DSO.
# This test verifies that these sections are contiguous in mold's output.
cat <<EOF | $CC -o "$t"/a.o -fPIC -c -xc -
cat <<EOF | $CC -o $t/a.o -fPIC -c -xc -
#include <stdio.h>
int main() {
printf("Hello world\n");
}
EOF
$CC -B. -o "$t"/b.so -shared "$t"/a.o
readelf -W --sections "$t"/b.so | fgrep -A1 .rela.dyn | fgrep -q .rela.plt
$CC -B. -o $t/b.so -shared $t/a.o
readelf -W --sections $t/b.so | fgrep -A1 .rela.dyn | fgrep -q .rela.plt
echo OK

View File

@ -7,15 +7,15 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -c -o "$t"/a.o -xc -
cat <<EOF | $CC -c -o $t/a.o -xc -
void foo() {}
void bar() {}
static void baz() {}
EOF
$CC -B. -o "$t"/b.so "$t"/a.o -Wl,-hash-style=gnu -shared
$CC -B. -o $t/b.so $t/a.o -Wl,-hash-style=gnu -shared
echo OK

View File

@ -7,24 +7,24 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | gcc -c -o "$t"/a.o -xc -
cat <<EOF | gcc -c -o $t/a.o -xc -
void foo() {}
__attribute__((section(".gnu.warning.foo")))
static const char foo_warning[] = "warning message";
EOF
cat <<EOF | $CC -c -o "$t"/b.o -xc -
cat <<EOF | $CC -c -o $t/b.o -xc -
void foo();
int main() { foo(); }
EOF
# Make sure that we do not copy .gnu.warning.* sections.
$CC -B. -o "$t"/exe "$t"/a.o "$t"/b.o
! readelf --sections "$t"/exe | fgrep -q .gnu.warning || false
$CC -B. -o $t/exe $t/a.o $t/b.o
! readelf --sections $t/exe | fgrep -q .gnu.warning || false
echo OK

View File

@ -7,17 +7,17 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -o $t/a.o -c -xc -
#include <stdio.h>
int main() {
printf("Hello world\n");
}
EOF
$CC -B. -o "$t"/exe "$t"/a.o
"$t"/exe | grep -q 'Hello world'
$CC -B. -o $t/exe $t/a.o
$t/exe | grep -q 'Hello world'
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -o $t/a.o -c -xc -
#include <stdio.h>
int main() {
@ -18,7 +18,7 @@ int main() {
}
EOF
$CC -B. -o "$t"/exe "$t"/a.o -static
"$t"/exe | grep -q 'Hello world'
$CC -B. -o $t/exe $t/a.o -static
$t/exe | grep -q 'Hello world'
echo OK

View File

@ -7,8 +7,8 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
"$mold" --help | grep -q Usage

View File

@ -7,13 +7,13 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
echo 'int main() {}' | $CC -m32 -o "$t"/exe -xc - >& /dev/null \
echo 'int main() {}' | $CC -m32 -o $t/exe -xc - >& /dev/null \
|| { echo skipped; exit; }
cat <<EOF | $CC -m32 -o "$t"/a.o -c -xc -
cat <<EOF | $CC -m32 -o $t/a.o -c -xc -
#include <stdio.h>
int main() {
@ -22,7 +22,7 @@ int main() {
}
EOF
$CC -B. -m32 -o "$t"/exe "$t"/a.o
"$t"/exe | grep -q 'Hello world'
$CC -B. -m32 -o $t/exe $t/a.o
$t/exe | grep -q 'Hello world'
echo OK

View File

@ -7,13 +7,13 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
echo 'int main() {}' | $CC -m32 -o "$t"/exe -xc - >& /dev/null \
echo 'int main() {}' | $CC -m32 -o $t/exe -xc - >& /dev/null \
|| { echo skipped; exit; }
cat <<EOF | $CC -m32 -o "$t"/a.o -c -xc -
cat <<EOF | $CC -m32 -o $t/a.o -c -xc -
#include <stdio.h>
int main() {
@ -22,7 +22,7 @@ int main() {
}
EOF
$CC -m32 -o "$t"/exe "$t"/a.o -static
"$t"/exe | grep -q 'Hello world'
$CC -m32 -o $t/exe $t/a.o -static
$t/exe | grep -q 'Hello world'
echo OK

View File

@ -7,15 +7,15 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
[ "$(uname -m)" = x86_64 ] || { echo skipped; exit; }
echo 'int main() {}' | $CC -m32 -o /dev/null -xc - >& /dev/null \
|| { echo skipped; exit; }
cat <<'EOF' | $CC -o "$t"/a.o -c -x assembler -m32 -
cat <<'EOF' | $CC -o $t/a.o -c -x assembler -m32 -
.text
.globl main
main:
@ -35,7 +35,7 @@ main:
.string "foo world\n"
EOF
$CC -B. -m32 -static -o "$t"/exe "$t"/a.o
"$t"/exe | grep -q 'Hello world'
$CC -B. -m32 -static -o $t/exe $t/a.o
$t/exe | grep -q 'Hello world'
echo OK

View File

@ -7,13 +7,13 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
echo 'int main() {}' | $CC -m32 -o "$t"/exe -xc - >& /dev/null \
echo 'int main() {}' | $CC -m32 -o $t/exe -xc - >& /dev/null \
|| { echo skipped; exit; }
cat <<EOF | $CC -fPIC -c -o "$t"/a.o -xc - -m32
cat <<EOF | $CC -fPIC -c -o $t/a.o -xc - -m32
int foo = 5;
void set_foo(int x) { foo = x; }
int get_foo() { return foo; }
@ -23,9 +23,9 @@ void set_bar(int x) { bar = x; }
int get_bar() { return bar; }
EOF
$CC -B. -o "$t"/b.so -shared "$t"/a.o -m32
$CC -B. -o $t/b.so -shared $t/a.o -m32
cat <<EOF > "$t"/c.c
cat <<EOF > $t/c.c
#include <stdio.h>
int get_foo();
@ -38,16 +38,16 @@ int main() {
}
EOF
$CC -c -o "$t"/d.o "$t"/c.c -fno-PIC -m32
$CC -B. -o "$t"/exe "$t"/d.o "$t"/b.so -m32 -no-pie
"$t"/exe | grep -q '5 7 2'
$CC -c -o $t/d.o $t/c.c -fno-PIC -m32
$CC -B. -o $t/exe $t/d.o $t/b.so -m32 -no-pie
$t/exe | grep -q '5 7 2'
$CC -c -o "$t"/e.o "$t"/c.c -fPIE -m32
$CC -B. -o "$t"/exe "$t"/e.o "$t"/b.so -m32 -pie
"$t"/exe | grep -q '5 7 2'
$CC -c -o $t/e.o $t/c.c -fPIE -m32
$CC -B. -o $t/exe $t/e.o $t/b.so -m32 -pie
$t/exe | grep -q '5 7 2'
$CC -c -o "$t"/f.o "$t"/c.c -fPIC -m32
$CC -B. -o "$t"/exe "$t"/f.o "$t"/b.so -m32 -pie
"$t"/exe | grep -q '5 7 2'
$CC -c -o $t/f.o $t/c.c -fPIC -m32
$CC -B. -o $t/exe $t/f.o $t/b.so -m32 -pie
$t/exe | grep -q '5 7 2'
echo OK

View File

@ -7,13 +7,13 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
echo 'int main() {}' | $CC -m32 -o "$t"/exe -xc - >& /dev/null \
echo 'int main() {}' | $CC -m32 -o $t/exe -xc - >& /dev/null \
|| { echo skipped; exit; }
cat <<EOF | $CC -fPIC -c -o "$t"/a.o -xc - -m32
cat <<EOF | $CC -fPIC -c -o $t/a.o -xc - -m32
#include <stdio.h>
static _Thread_local int x1 = 1;
@ -31,26 +31,26 @@ int main() {
}
EOF
cat <<EOF | $CC -fPIC -c -o "$t"/b.o -xc - -m32
cat <<EOF | $CC -fPIC -c -o $t/b.o -xc - -m32
_Thread_local int x3 = 3;
static _Thread_local int x5 = 5;
int get_x5() { return x5; }
EOF
cat <<EOF | $CC -fPIC -c -o "$t"/c.o -xc - -m32
cat <<EOF | $CC -fPIC -c -o $t/c.o -xc - -m32
_Thread_local int x4 = 4;
static _Thread_local int x6 = 6;
int get_x6() { return x6; }
EOF
$CC -B. -shared -o "$t"/d.so "$t"/b.o -m32
$CC -B. -shared -o "$t"/e.so "$t"/c.o -Wl,--no-relax -m32
$CC -B. -shared -o $t/d.so $t/b.o -m32
$CC -B. -shared -o $t/e.so $t/c.o -Wl,--no-relax -m32
$CC -B. -o "$t"/exe "$t"/a.o "$t"/d.so "$t"/e.so -m32
"$t"/exe | grep -q '1 2 3 4 5 6'
$CC -B. -o $t/exe $t/a.o $t/d.so $t/e.so -m32
$t/exe | grep -q '1 2 3 4 5 6'
$CC -B. -o "$t"/exe "$t"/a.o "$t"/d.so "$t"/e.so -Wl,-no-relax -m32
"$t"/exe | grep -q '1 2 3 4 5 6'
$CC -B. -o $t/exe $t/a.o $t/d.so $t/e.so -Wl,-no-relax -m32
$t/exe | grep -q '1 2 3 4 5 6'
echo OK

View File

@ -7,13 +7,13 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
echo 'int main() {}' | $CC -m32 -o "$t"/exe -xc - >& /dev/null \
echo 'int main() {}' | $CC -m32 -o $t/exe -xc - >& /dev/null \
|| { echo skipped; exit; }
cat <<EOF | $CC -ftls-model=local-dynamic -fPIC -c -o "$t"/a.o -xc - -m32
cat <<EOF | $CC -ftls-model=local-dynamic -fPIC -c -o $t/a.o -xc - -m32
#include <stdio.h>
extern _Thread_local int foo;
@ -30,14 +30,14 @@ int main() {
}
EOF
cat <<EOF | $CC -ftls-model=local-dynamic -fPIC -c -o "$t"/b.o -xc - -m32
cat <<EOF | $CC -ftls-model=local-dynamic -fPIC -c -o $t/b.o -xc - -m32
_Thread_local int foo = 3;
EOF
$CC -B. -o "$t"/exe "$t"/a.o "$t"/b.o -m32
"$t"/exe | grep -q '3 5 3 5'
$CC -B. -o $t/exe $t/a.o $t/b.o -m32
$t/exe | grep -q '3 5 3 5'
$CC -B. -o "$t"/exe "$t"/a.o "$t"/b.o -Wl,-no-relax -m32
"$t"/exe | grep -q '3 5 3 5'
$CC -B. -o $t/exe $t/a.o $t/b.o -Wl,-no-relax -m32
$t/exe | grep -q '3 5 3 5'
echo OK

View File

@ -7,13 +7,13 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
echo 'int main() {}' | $CC -m32 -o "$t"/exe -xc - >& /dev/null \
echo 'int main() {}' | $CC -m32 -o $t/exe -xc - >& /dev/null \
|| { echo skipped; exit; }
cat <<EOF | gcc -fPIC -mtls-dialect=gnu2 -c -o "$t"/a.o -xc - -m32
cat <<EOF | gcc -fPIC -mtls-dialect=gnu2 -c -o $t/a.o -xc - -m32
extern _Thread_local int foo;
int get_foo() {
@ -21,7 +21,7 @@ int get_foo() {
}
EOF
cat <<EOF | $CC -fPIC -c -o "$t"/b.o -xc - -m32
cat <<EOF | $CC -fPIC -c -o $t/b.o -xc - -m32
#include <stdio.h>
_Thread_local int foo;
@ -35,18 +35,18 @@ int main() {
}
EOF
$CC -B. -o "$t"/exe "$t"/a.o "$t"/b.o -m32
"$t"/exe | grep -q 42
$CC -B. -o $t/exe $t/a.o $t/b.o -m32
$t/exe | grep -q 42
$CC -B. -shared -o "$t"/c.so "$t"/a.o -m32
$CC -B. -o "$t"/exe "$t"/b.o "$t"/c.so -m32
"$t"/exe | grep -q 42
$CC -B. -shared -o $t/c.so $t/a.o -m32
$CC -B. -o $t/exe $t/b.o $t/c.so -m32
$t/exe | grep -q 42
$CC -B. -o "$t"/exe "$t"/a.o "$t"/b.o -Wl,-no-relax -m32
"$t"/exe | grep -q 42
$CC -B. -o $t/exe $t/a.o $t/b.o -Wl,-no-relax -m32
$t/exe | grep -q 42
$CC -B. -shared -o "$t"/c.so "$t"/a.o -Wl,-no-relax -m32
$CC -B. -o "$t"/exe "$t"/b.o "$t"/c.so -Wl,-no-relax -m32
"$t"/exe | grep -q 42
$CC -B. -shared -o $t/c.so $t/a.o -Wl,-no-relax -m32
$CC -B. -o $t/exe $t/b.o $t/c.so -Wl,-no-relax -m32
$t/exe | grep -q 42
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -c -o "$t"/a.o -ffunction-sections -fdata-sections -xc -
cat <<EOF | $CC -c -o $t/a.o -ffunction-sections -fdata-sections -xc -
#include <stdio.h>
int bar() {
@ -36,7 +36,7 @@ int main() {
}
EOF
$CC -B. -o "$t"/exe "$t"/a.o -Wl,-icf=all
"$t"/exe | grep -q '1 0'
$CC -B. -o $t/exe $t/a.o -Wl,-icf=all
$t/exe | grep -q '1 0'
echo OK

View File

@ -7,14 +7,14 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
# Skip if libc is musl because musl does not support GNU FUNC
echo 'int main() {}' | $CC -o "$t"/exe -xc -
ldd "$t"/exe | grep -q ld-musl && { echo OK; exit; }
echo 'int main() {}' | $CC -o $t/exe -xc -
ldd $t/exe | grep -q ld-musl && { echo OK; exit; }
cat <<EOF | $CC -fPIC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -fPIC -o $t/a.o -c -xc -
void foobar(void);
int main() {
@ -22,7 +22,7 @@ int main() {
}
EOF
cat <<EOF | $CC -fPIC -shared -o "$t"/b.so -xc -
cat <<EOF | $CC -fPIC -shared -o $t/b.so -xc -
#include <stdio.h>
__attribute__((ifunc("resolve_foobar")))
@ -39,7 +39,7 @@ static Func *resolve_foobar(void) {
}
EOF
$CC -B. -o "$t"/exe "$t"/a.o "$t"/b.so
"$t"/exe | grep -q 'Hello world'
$CC -B. -o $t/exe $t/a.o $t/b.so
$t/exe | grep -q 'Hello world'
echo OK

View File

@ -7,14 +7,14 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
# Skip if libc is musl because musl does not support GNU FUNC
echo 'int main() {}' | $CC -o "$t"/exe -xc -
ldd "$t"/exe | grep -q ld-musl && { echo OK; exit; }
echo 'int main() {}' | $CC -o $t/exe -xc -
ldd $t/exe | grep -q ld-musl && { echo OK; exit; }
cat <<EOF | $CC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -o $t/a.o -c -xc -
#include <stdio.h>
__attribute__((ifunc("resolve_foobar")))
@ -35,7 +35,7 @@ int main() {
}
EOF
$CC -B. -o "$t"/exe "$t"/a.o
"$t"/exe | grep -q 'Hello world'
$CC -B. -o $t/exe $t/a.o
$t/exe | grep -q 'Hello world'
echo OK

View File

@ -7,14 +7,14 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
# Skip if libc is musl because musl does not support GNU FUNC
echo 'int main() {}' | $CC -o "$t"/exe -xc -
ldd "$t"/exe | grep -q ld-musl && { echo OK; exit; }
echo 'int main() {}' | $CC -o $t/exe -xc -
ldd $t/exe | grep -q ld-musl && { echo OK; exit; }
cat <<EOF | $CC -c -fPIC -o "$t"/a.o -xc -
cat <<EOF | $CC -c -fPIC -o $t/a.o -xc -
#include <stdio.h>
__attribute__((ifunc("resolve_foobar")))
@ -31,7 +31,7 @@ Func *resolve_foobar(void) {
}
EOF
$CC -B. -shared -o "$t"/b.so "$t"/a.o
readelf --dyn-syms "$t"/b.so | grep -Pq '(IFUNC|<OS specific>: 10)\s+GLOBAL DEFAULT \d+ foobar'
$CC -B. -shared -o $t/b.so $t/a.o
readelf --dyn-syms $t/b.so | grep -Pq '(IFUNC|<OS specific>: 10)\s+GLOBAL DEFAULT \d+ foobar'
echo OK

View File

@ -7,14 +7,14 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
# Skip if libc is musl because musl does not support GNU FUNC
echo 'int main() {}' | $CC -o "$t"/exe -xc -
ldd "$t"/exe | grep -q ld-musl && { echo OK; exit; }
echo 'int main() {}' | $CC -o $t/exe -xc -
ldd $t/exe | grep -q ld-musl && { echo OK; exit; }
cat <<EOF | $CC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -o $t/a.o -c -xc -
#include <stdio.h>
void foo() __attribute__((ifunc("resolve_foo")));
@ -33,7 +33,7 @@ int main() {
}
EOF
$CC -B. -o "$t"/exe "$t"/a.o -static
"$t"/exe | grep -q 'Hello world'
$CC -B. -o $t/exe $t/a.o -static
$t/exe | grep -q 'Hello world'
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -o $t/a.o -c -xc -
#include <stdio.h>
int main() {
@ -19,8 +19,8 @@ int main() {
}
EOF
$CC -B. -no-pie -o "$t"/exe "$t"/a.o -Wl,--image-base=0x8000000
"$t"/exe | grep -q 'Hello world'
readelf -W --sections "$t"/exe | grep -Pq '.interp\s+PROGBITS\s+0000000008000...\b'
$CC -B. -no-pie -o $t/exe $t/a.o -Wl,--image-base=0x8000000
$t/exe | grep -q 'Hello world'
readelf -W --sections $t/exe | grep -Pq '.interp\s+PROGBITS\s+0000000008000...\b'
echo OK

View File

@ -7,29 +7,29 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
echo 'int main() {}' | $CC -m32 -o "$t"/exe -xc - >& /dev/null \
echo 'int main() {}' | $CC -m32 -o $t/exe -xc - >& /dev/null \
|| { echo skipped; exit; }
cat <<EOF | $CC -m32 -c -o "$t"/a.o -xc -
cat <<EOF | $CC -m32 -c -o $t/a.o -xc -
char hello[] = "Hello world";
EOF
mkdir -p "$t"/lib32
ar crs "$t"/lib32/libfoo.a "$t"/a.o
$CC -m32 -shared -o "$t"/lib32/libfoo.so "$t"/a.o
mkdir -p $t/lib32
ar crs $t/lib32/libfoo.a $t/a.o
$CC -m32 -shared -o $t/lib32/libfoo.so $t/a.o
cat <<EOF | $CC -c -o "$t"/d.o -xc -
cat <<EOF | $CC -c -o $t/d.o -xc -
char hello[] = "Hello world";
EOF
mkdir -p "$t"/lib64
ar crs "$t"/lib64/libfoo.a "$t"/d.o
$CC -shared -o "$t"/lib64/libfoo.so "$t"/d.o
mkdir -p $t/lib64
ar crs $t/lib64/libfoo.a $t/d.o
$CC -shared -o $t/lib64/libfoo.so $t/d.o
cat <<EOF | $CC -c -o "$t"/e.o -xc -
cat <<EOF | $CC -c -o $t/e.o -xc -
#include <stdio.h>
extern char hello[];
@ -39,15 +39,15 @@ int main() {
}
EOF
mkdir -p "$t"/script
echo 'OUTPUT_FORMAT(elf32-i386)' > "$t"/script/libfoo.so
mkdir -p $t/script
echo 'OUTPUT_FORMAT(elf32-i386)' > $t/script/libfoo.so
$CC -B. -o "$t"/exe -L"$t"/script -L"$t"/lib32 -L"$t"/lib64 \
"$t"/e.o -lfoo -Wl,-rpath "$t"/lib64 >& "$t"/log
$CC -B. -o $t/exe -L$t/script -L$t/lib32 -L$t/lib64 \
$t/e.o -lfoo -Wl,-rpath $t/lib64 >& $t/log
grep -q 'script/libfoo.so: skipping incompatible file' "$t"/log
grep -q 'lib32/libfoo.so: skipping incompatible file' "$t"/log
grep -q 'lib32/libfoo.a: skipping incompatible file' "$t"/log
"$t"/exe | grep -q 'Hello world'
grep -q 'script/libfoo.so: skipping incompatible file' $t/log
grep -q 'lib32/libfoo.so: skipping incompatible file' $t/log
grep -q 'lib32/libfoo.a: skipping incompatible file' $t/log
$t/exe | grep -q 'Hello world'
echo OK

View File

@ -7,55 +7,55 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<'EOF' | $CC -c -o "$t"/a.o -xc -
cat <<'EOF' | $CC -c -o $t/a.o -xc -
#include <stdio.h>
__attribute__((constructor(10000))) void init4() { printf("1"); }
EOF
cat <<'EOF' | $CC -c -o "$t"/b.o -xc -
cat <<'EOF' | $CC -c -o $t/b.o -xc -
#include <stdio.h>
__attribute__((constructor(1000))) void init3() { printf("2"); }
EOF
cat <<'EOF' | $CC -c -o "$t"/c.o -xc -
cat <<'EOF' | $CC -c -o $t/c.o -xc -
#include <stdio.h>
__attribute__((constructor)) void init1() { printf("3"); }
EOF
cat <<'EOF' | $CC -c -o "$t"/d.o -xc -
cat <<'EOF' | $CC -c -o $t/d.o -xc -
#include <stdio.h>
__attribute__((constructor)) void init2() { printf("4"); }
EOF
cat <<'EOF' | $CC -c -o "$t"/e.o -xc -
cat <<'EOF' | $CC -c -o $t/e.o -xc -
#include <stdio.h>
__attribute__((destructor(10000))) void fini4() { printf("5"); }
EOF
cat <<'EOF' | $CC -c -o "$t"/f.o -xc -
cat <<'EOF' | $CC -c -o $t/f.o -xc -
#include <stdio.h>
__attribute__((destructor(1000))) void fini3() { printf("6"); }
EOF
cat <<'EOF' | $CC -c -o "$t"/g.o -xc -
cat <<'EOF' | $CC -c -o $t/g.o -xc -
#include <stdio.h>
__attribute__((destructor)) void fini1() { printf("7"); }
EOF
cat <<'EOF' | $CC -c -o "$t"/h.o -xc -
cat <<'EOF' | $CC -c -o $t/h.o -xc -
#include <stdio.h>
__attribute__((destructor)) void fini2() { printf("8"); }
EOF
cat <<EOF | $CC -c -o "$t"/i.o -xc -
cat <<EOF | $CC -c -o $t/i.o -xc -
int main() {}
EOF
$CC -B. -o "$t"/exe "$t"/a.o "$t"/b.o "$t"/c.o "$t"/d.o \
"$t"/e.o "$t"/f.o "$t"/g.o "$t"/h.o "$t"/i.o
"$t"/exe | grep -q '21348756'
$CC -B. -o $t/exe $t/a.o $t/b.o $t/c.o $t/d.o \
$t/e.o $t/f.o $t/g.o $t/h.o $t/i.o
$t/exe | grep -q '21348756'
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -c -o "$t"/a.o -x assembler -
cat <<EOF | $CC -c -o $t/a.o -x assembler -
.globl init1, init2, fini1, fini2
.section .init_array,"aw",@init_array
@ -30,7 +30,7 @@ cat <<EOF | $CC -c -o "$t"/a.o -x assembler -
.quad fini2
EOF
cat <<EOF | $CC -c -o "$t"/b.o -xc -
cat <<EOF | $CC -c -o $t/b.o -xc -
#include <stdio.h>
void init1() { printf("init1 "); }
@ -43,7 +43,7 @@ int main() {
}
EOF
$CC -B. -o "$t"/exe "$t"/a.o "$t"/b.o
"$t"/exe | grep -q 'init1 init2 fini2 fini1'
$CC -B. -o $t/exe $t/a.o $t/b.o
$t/exe | grep -q 'init1 init2 fini2 fini1'
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -c -fPIC -o "$t"/a.o -xc -
cat <<EOF | $CC -c -fPIC -o $t/a.o -xc -
#include <stdio.h>
void foo() {
@ -18,7 +18,7 @@ void foo() {
}
EOF
$CC -B. -shared -o "$t"/b.so "$t"/a.o -Wl,-z,initfirst
readelf --dynamic "$t"/b.so | grep -q 'Flags: INITFIRST'
$CC -B. -shared -o $t/b.so $t/a.o -Wl,-z,initfirst
readelf --dynamic $t/b.so | grep -q 'Flags: INITFIRST'
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -c -fPIC -o "$t"/a.o -xc -
cat <<EOF | $CC -c -fPIC -o $t/a.o -xc -
#include <stdio.h>
void foo() {
@ -18,7 +18,7 @@ void foo() {
}
EOF
$CC -B. -shared -o "$t"/b.so "$t"/a.o -Wl,-z,interpose
readelf --dynamic "$t"/b.so | grep -q 'Flags: INTERPOSE'
$CC -B. -shared -o $t/b.so $t/a.o -Wl,-z,interpose
readelf --dynamic $t/b.so | grep -q 'Flags: INTERPOSE'
echo OK

View File

@ -7,15 +7,15 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
echo 'int main() {}' | $CC -c -o "$t"/a.o -xc -
echo 'int main() {}' | $CC -c -o $t/a.o -xc -
echo 'VER1 { foo[12; };' > "$t"/b.ver
echo 'VER1 { foo[12; };' > $t/b.ver
! $CC -B. -shared -o "$t"/c.so -Wl,-version-script,"$t"/b.ver \
"$t"/a.o >& "$t"/log || false
grep -q 'invalid version pattern' "$t"/log
! $CC -B. -shared -o $t/c.so -Wl,-version-script,$t/b.ver \
$t/a.o >& $t/log || false
grep -q 'invalid version pattern' $t/log
echo OK

View File

@ -7,29 +7,29 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -fPIC -c -o "$t"/a.o -xc -
cat <<EOF | $CC -fPIC -c -o $t/a.o -xc -
void foo() {}
EOF
$CC -B. -shared -o "$t"/libfoo.so "$t"/a.o
ar crs "$t"/libfoo.a "$t"/a.o
$CC -B. -shared -o $t/libfoo.so $t/a.o
ar crs $t/libfoo.a $t/a.o
cat <<EOF | $CC -c -o "$t"/b.o -xc -
cat <<EOF | $CC -c -o $t/b.o -xc -
void foo();
int main() {
foo();
}
EOF
$CC -B. -o "$t"/exe "$t"/b.o -Wl,--as-needed \
"$t"/libfoo.so "$t"/libfoo.a
ldd "$t"/exe | grep -q libfoo
$CC -B. -o $t/exe $t/b.o -Wl,--as-needed \
$t/libfoo.so $t/libfoo.a
ldd $t/exe | grep -q libfoo
$CC -B. -o "$t"/exe "$t"/b.o -Wl,--as-needed \
"$t"/libfoo.a "$t"/libfoo.so
! ldd "$t"/exe | grep -q libfoo || false
$CC -B. -o $t/exe $t/b.o -Wl,--as-needed \
$t/libfoo.a $t/libfoo.so
! ldd $t/exe | grep -q libfoo || false
echo OK

View File

@ -7,27 +7,27 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -o $t/a.o -c -xc -
#include <stdio.h>
int main() {
printf("Hello world\n");
}
EOF
cat <<EOF > "$t"/script
cat <<EOF > $t/script
GROUP("$t/a.o")
EOF
$CC -B. -o "$t"/exe "$t"/script
"$t"/exe | grep -q 'Hello world'
$CC -B. -o $t/exe $t/script
$t/exe | grep -q 'Hello world'
$CC -B. -o "$t"/exe -Wl,-T,"$t"/script
"$t"/exe | grep -q 'Hello world'
$CC -B. -o $t/exe -Wl,-T,$t/script
$t/exe | grep -q 'Hello world'
$CC -B. -o "$t"/exe -Wl,--script,"$t"/script
"$t"/exe | grep -q 'Hello world'
$CC -B. -o $t/exe -Wl,--script,$t/script
$t/exe | grep -q 'Hello world'
echo OK

View File

@ -7,21 +7,21 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -o $t/a.o -c -xc -
int main() {}
EOF
mkdir -p "$t"/foo/bar
rm -f "$t"/foo/bar/libfoo.a
ar rcs "$t"/foo/bar/libfoo.a "$t"/a.o
mkdir -p $t/foo/bar
rm -f $t/foo/bar/libfoo.a
ar rcs $t/foo/bar/libfoo.a $t/a.o
cat <<EOF > "$t"/b.script
cat <<EOF > $t/b.script
INPUT(-lfoo)
EOF
$CC -o "$t"/exe -L"$t"/foo/bar "$t"/b.script
$CC -o $t/exe -L$t/foo/bar $t/b.script
echo OK

View File

@ -7,19 +7,19 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
mkdir -p "$t"/foo
mkdir -p $t/foo
cat <<EOF | $CC -o "$t"/foo/a.o -c -xc -
cat <<EOF | $CC -o $t/foo/a.o -c -xc -
int main() {}
EOF
cat <<EOF > "$t"/b.script
cat <<EOF > $t/b.script
INPUT(a.o)
EOF
$CC -o "$t"/exe -L"$t"/foo "$t"/b.script
$CC -o $t/exe -L$t/foo $t/b.script
echo OK

View File

@ -7,12 +7,12 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
echo 'VERSION { ver_x { global: *; }; };' > "$t"/a.script
echo 'VERSION { ver_x { global: *; }; };' > $t/a.script
cat <<EOF > "$t"/b.s
cat <<EOF > $t/b.s
.globl foo, bar, baz
foo:
nop
@ -22,9 +22,9 @@ baz:
nop
EOF
$CC -B. -shared -o "$t"/c.so "$t"/a.script "$t"/b.s
readelf --version-info "$t"/c.so > "$t"/log
$CC -B. -shared -o $t/c.so $t/a.script $t/b.s
readelf --version-info $t/c.so > $t/log
fgrep -q 'Rev: 1 Flags: none Index: 2 Cnt: 1 Name: ver_x' "$t"/log
fgrep -q 'Rev: 1 Flags: none Index: 2 Cnt: 1 Name: ver_x' $t/log
echo OK

View File

@ -7,20 +7,20 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
which ld.bfd >& /dev/null || { echo skipped; exit 0; }
cat <<EOF | gcc -flto -c -o "$t"/a.o -xc -
cat <<EOF | gcc -flto -c -o $t/a.o -xc -
#include <stdio.h>
int main() {
printf("Hello world\n");
}
EOF
gcc -B"$(pwd)" -o "$t"/exe "$t"/a.o >& "$t"/log
grep -q 'falling back' "$t"/log
"$t"/exe | grep -q 'Hello world'
gcc -B"$(pwd)" -o $t/exe $t/a.o >& $t/log
grep -q 'falling back' $t/log
$t/exe | grep -q 'Hello world'
echo OK

View File

@ -7,20 +7,20 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
which ld.lld >& /dev/null || { echo skipped; exit 0; }
cat <<EOF | $CC -flto -c -o "$t"/a.o -xc -
cat <<EOF | $CC -flto -c -o $t/a.o -xc -
#include <stdio.h>
int main() {
printf("Hello world\n");
}
EOF
$CC -B. -o "$t"/exe "$t"/a.o &> "$t"/log
grep -q 'falling back' "$t"/log
"$t"/exe | grep -q 'Hello world'
$CC -B. -o $t/exe $t/a.o &> $t/log
grep -q 'falling back' $t/log
$t/exe | grep -q 'Hello world'
echo OK

View File

@ -7,14 +7,14 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
seq 1 65500 | sed 's/.*/.section .text.\0, "ax",@progbits/' > "$t"/a.s
seq 1 65500 | sed 's/.*/.section .text.\0, "ax",@progbits/' > $t/a.s
$CC -c -o "$t"/a.o "$t"/a.s
$CC -c -o $t/a.o $t/a.s
cat <<'EOF' | $CC -c -xc -o "$t"/b.o -
cat <<'EOF' | $CC -c -xc -o $t/b.o -
#include <stdio.h>
int main() {
@ -23,7 +23,7 @@ int main() {
}
EOF
$CC -B. -o "$t"/exe "$t"/a.o "$t"/b.o
"$t"/exe | grep -q Hello
$CC -B. -o $t/exe $t/a.o $t/b.o
$t/exe | grep -q Hello
echo OK

View File

@ -7,13 +7,13 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
# Skip if target is not x86-64
[ "$(uname -m)" = x86_64 ] || { echo skipped; exit; }
cat <<'EOF' | $CC -o "$t"/a.o -c -x assembler -
cat <<'EOF' | $CC -o $t/a.o -c -x assembler -
.text
.globl main
main:
@ -35,7 +35,7 @@ main:
.string "foo world\n"
EOF
$CC -B. -static -o "$t"/exe "$t"/a.o
"$t"/exe | grep -q 'Hello world'
$CC -B. -static -o $t/exe $t/a.o
$t/exe | grep -q 'Hello world'
echo OK

View File

@ -7,16 +7,16 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
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, foo
_start:
nop
EOF
"$mold" -o "$t"/exe "$t"/a.o
"$mold" -o $t/exe $t/a.o
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -o $t/a.o -c -xc -
int foo();
int main() {
@ -18,7 +18,7 @@ int main() {
}
EOF
! "$mold" -o "$t"/exe "$t"/a.o 2> "$t"/log || false
grep -q 'undefined symbol: .*\.o: foo' "$t"/log
! "$mold" -o $t/exe $t/a.o 2> $t/log || false
grep -q 'undefined symbol: .*\.o: foo' $t/log
echo OK

View File

@ -7,19 +7,19 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
ldd "$mold"-wrapper.so | grep -q libasan && { echo skipped; exit; }
cat <<'EOF' > "$t"/a.sh
cat <<'EOF' > $t/a.sh
#!/bin/bash
echo "$0" "$@"
EOF
chmod 755 "$t"/a.sh
chmod 755 $t/a.sh
cat <<'EOF' | $CC -xc -o "$t"/exe -
cat <<'EOF' | $CC -xc -o $t/exe -
#define _GNU_SOURCE 1
#include <assert.h>
@ -72,11 +72,11 @@ int main(int argc, char **argv) {
}
EOF
LD_PRELOAD=$mold-wrapper.so MOLD_PATH=$t/a.sh "$t"/exe execl | grep -q 'a.sh execl'
LD_PRELOAD=$mold-wrapper.so MOLD_PATH=$t/a.sh "$t"/exe execlp | grep -q 'a.sh execlp'
LD_PRELOAD=$mold-wrapper.so MOLD_PATH=$t/a.sh "$t"/exe execle | grep -q 'a.sh execle'
LD_PRELOAD=$mold-wrapper.so MOLD_PATH=$t/a.sh "$t"/exe execv | grep -q 'a.sh execv'
LD_PRELOAD=$mold-wrapper.so MOLD_PATH=$t/a.sh "$t"/exe execvp | grep -q 'a.sh execvp'
LD_PRELOAD=$mold-wrapper.so MOLD_PATH=$t/a.sh "$t"/exe execvpe | grep -q 'a.sh execvpe'
LD_PRELOAD=$mold-wrapper.so MOLD_PATH=$t/a.sh $t/exe execl | grep -q 'a.sh execl'
LD_PRELOAD=$mold-wrapper.so MOLD_PATH=$t/a.sh $t/exe execlp | grep -q 'a.sh execlp'
LD_PRELOAD=$mold-wrapper.so MOLD_PATH=$t/a.sh $t/exe execle | grep -q 'a.sh execle'
LD_PRELOAD=$mold-wrapper.so MOLD_PATH=$t/a.sh $t/exe execv | grep -q 'a.sh execv'
LD_PRELOAD=$mold-wrapper.so MOLD_PATH=$t/a.sh $t/exe execvp | grep -q 'a.sh execvp'
LD_PRELOAD=$mold-wrapper.so MOLD_PATH=$t/a.sh $t/exe execvpe | grep -q 'a.sh execvpe'
echo OK

View File

@ -7,16 +7,16 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
ldd "$mold"-wrapper.so | grep -q libasan && { echo skipped; exit; }
rm -rf "$t"
mkdir -p "$t"/bin "$t"/lib/mold
cp "$mold" "$t"/bin
cp "$mold"-wrapper.so "$t"/bin
rm -rf $t
mkdir -p $t/bin $t/lib/mold
cp "$mold" $t/bin
cp "$mold"-wrapper.so $t/bin
"$t"/bin/mold -run bash -c 'echo $LD_PRELOAD' | grep -q '/bin/mold-wrapper.so'
$t/bin/mold -run bash -c 'echo $LD_PRELOAD' | grep -q '/bin/mold-wrapper.so'
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -xc -
cat <<EOF | $CC -o $t/a.o -c -xc -
#include <stdio.h>
int main() {
@ -19,7 +19,7 @@ int main() {
}
EOF
$CC -B. -o "$t"/exe "$t"/a.o -Wl,-no-quick-exit
"$t"/exe | grep -q 'Hello world'
$CC -B. -o $t/exe $t/a.o -Wl,-no-quick-exit
$t/exe | grep -q 'Hello world'
echo OK

View File

@ -7,15 +7,15 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -shared -o "$t"/a.so -xc -
cat <<EOF | $CC -shared -o $t/a.so -xc -
int foo = 3;
int bar = 5;
EOF
cat <<EOF | $CC -fno-PIC -c -o "$t"/b.o -xc -
cat <<EOF | $CC -fno-PIC -c -o $t/b.o -xc -
#include <stdio.h>
extern int foo;
@ -27,12 +27,12 @@ int main() {
}
EOF
$CC -B. -no-pie -o "$t"/exe "$t"/a.so "$t"/b.o
"$t"/exe | grep -q '3 5'
$CC -B. -no-pie -o $t/exe $t/a.so $t/b.o
$t/exe | grep -q '3 5'
! $CC -B. -o "$t"/exe "$t"/a.so "$t"/b.o \
-Wl,-z,nocopyreloc 2> "$t"/log || false
! $CC -B. -o $t/exe $t/a.so $t/b.o \
-Wl,-z,nocopyreloc 2> $t/log || false
grep -q 'recompile with -fPIC' "$t"/log
grep -q 'recompile with -fPIC' $t/log
echo OK

View File

@ -7,24 +7,24 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
# Skip if target is not x86-64
[ "$(uname -m)" = x86_64 ] || { echo skipped; exit; }
cat <<EOF | $CC -fcf-protection=branch -c -o "$t"/a.o -xc -
cat <<EOF | $CC -fcf-protection=branch -c -o $t/a.o -xc -
void _start() {}
EOF
cat <<EOF | $CC -fcf-protection=none -c -o "$t"/b.o -xc -
cat <<EOF | $CC -fcf-protection=none -c -o $t/b.o -xc -
void _start() {}
EOF
"$mold" -o "$t"/exe "$t"/a.o
readelf -n "$t"/exe | grep -q 'x86 feature: IBT'
"$mold" -o $t/exe $t/a.o
readelf -n $t/exe | grep -q 'x86 feature: IBT'
"$mold" -o "$t"/exe "$t"/b.o
! readelf -n "$t"/exe | grep -q 'x86 feature: IBT' || false
"$mold" -o $t/exe $t/b.o
! readelf -n $t/exe | grep -q 'x86 feature: IBT' || false
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
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:
@ -33,16 +33,16 @@ _start:
.quad 42
EOF
"$mold" -static -o "$t"/exe "$t"/a.o
readelf -W --sections "$t"/exe > "$t"/log
"$mold" -static -o $t/exe $t/a.o
readelf -W --sections $t/exe > $t/log
grep -Pq '.note.bar\s+NOTE.+000008 00 A 0 0 4' "$t"/log
grep -Pq '.note.baz\s+NOTE.+000008 00 A 0 0 8' "$t"/log
grep -Pq '.note.nonalloc\s+NOTE.+000008 00 0 0 1' "$t"/log
grep -Pq '.note.bar\s+NOTE.+000008 00 A 0 0 4' $t/log
grep -Pq '.note.baz\s+NOTE.+000008 00 A 0 0 8' $t/log
grep -Pq '.note.nonalloc\s+NOTE.+000008 00 0 0 1' $t/log
readelf --segments "$t"/exe > "$t"/log
fgrep -q '01 .note.bar' "$t"/log
fgrep -q '02 .note.baz .note.foo' "$t"/log
! grep -q 'NOTE.*0x0000000000000000 0x0000000000000000' "$t"/log || false
readelf --segments $t/exe > $t/log
fgrep -q '01 .note.bar' $t/log
fgrep -q '02 .note.baz .note.foo' $t/log
! grep -q 'NOTE.*0x0000000000000000 0x0000000000000000' $t/log || false
echo OK

View File

@ -7,35 +7,35 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -x assembler -
cat <<EOF | $CC -o $t/a.o -c -x assembler -
.section .note.a, "a", @note
.p2align 3
.quad 42
EOF
cat <<EOF | $CC -o "$t"/b.o -c -x assembler -
cat <<EOF | $CC -o $t/b.o -c -x assembler -
.section .note.b, "a", @note
.p2align 2
.quad 42
EOF
cat <<EOF | $CC -o "$t"/c.o -c -x assembler -
cat <<EOF | $CC -o $t/c.o -c -x assembler -
.section .note.c, "a", @note
.p2align 3
.quad 42
EOF
cat <<EOF | $CC -o "$t"/d.o -c -xc -
cat <<EOF | $CC -o $t/d.o -c -xc -
int main() {}
EOF
"$mold" -static -o "$t"/exe "$t"/a.o "$t"/b.o "$t"/c.o "$t"/d.o
"$mold" -static -o $t/exe $t/a.o $t/b.o $t/c.o $t/d.o
readelf --segments "$t"/exe > "$t"/log
fgrep -q '01 .note.b' "$t"/log
fgrep -q '02 .note.a .note.c' "$t"/log
readelf --segments $t/exe > $t/log
fgrep -q '01 .note.b' $t/log
fgrep -q '02 .note.a .note.c' $t/log
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -c -fPIC -o "$t"/a.o -xc -
cat <<EOF | $CC -c -fPIC -o $t/a.o -xc -
#include <stdio.h>
void foo() {
@ -18,11 +18,11 @@ void foo() {
}
EOF
$CC -B. -shared -o "$t"/b.so "$t"/a.o -Wl,-z,now
readelf --dynamic "$t"/b.so | grep -q 'Flags: NOW'
$CC -B. -shared -o $t/b.so $t/a.o -Wl,-z,now
readelf --dynamic $t/b.so | grep -q 'Flags: NOW'
$CC -B. -shared -o "$t"/b.so "$t"/a.o -Wl,-z,now,-z,lazy
readelf --dynamic "$t"/b.so > "$t"/log
! grep -q 'Flags: NOW' "$t"/log || false
$CC -B. -shared -o $t/b.so $t/a.o -Wl,-z,now,-z,lazy
readelf --dynamic $t/b.so > $t/log
! grep -q 'Flags: NOW' $t/log || false
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -c -o "$t"/a.o -xc -
cat <<EOF | $CC -c -o $t/a.o -xc -
#include <stdio.h>
int main() {
@ -19,6 +19,6 @@ int main() {
}
EOF
$CC -B. "$t"/a.o -o "$t"/exe -static -Wl,--omagic
$CC -B. $t/a.o -o $t/exe -static -Wl,--omagic
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o "$t"/a.o -c -xc -fPIE -
cat <<EOF | $CC -o $t/a.o -c -xc -fPIE -
#include <stdio.h>
int main() {
@ -19,8 +19,8 @@ int main() {
}
EOF
$CC -B. -pie -o "$t"/exe "$t"/a.o
readelf --file-header "$t"/exe | grep -q -E '(Shared object file|Position-Independent Executable file)'
"$t"/exe | grep -q 'Hello world'
$CC -B. -pie -o $t/exe $t/a.o
readelf --file-header $t/exe | grep -q -E '(Shared object file|Position-Independent Executable file)'
$t/exe | grep -q 'Hello world'
echo OK

View File

@ -7,10 +7,10 @@ testname=$(basename -s .sh "$0")
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t="$(pwd)/out/test/elf/$testname"
mkdir -p "$t"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -fPIC -c -o "$t"/a.o -xc -
cat <<EOF | $CC -fPIC -c -o $t/a.o -xc -
#include <stdio.h>
void world() {
@ -27,9 +27,9 @@ void hello() {
}
EOF
$CC -B. -shared -o "$t"/b.so "$t"/a.o
$CC -B. -shared -o $t/b.so $t/a.o
cat <<EOF | $CC -c -o "$t"/c.o -xc -
cat <<EOF | $CC -c -o $t/c.o -xc -
#include <stdio.h>
void world() {
@ -43,7 +43,7 @@ int main() {
}
EOF
$CC -B. -o "$t"/exe -Wl,-rpath="$t" "$t"/c.o "$t"/b.so
"$t"/exe | grep -q 'Hello WORLD'
$CC -B. -o $t/exe -Wl,-rpath=$t $t/c.o $t/b.so
$t/exe | grep -q 'Hello WORLD'
echo OK

Some files were not shown because too many files have changed in this diff Show More