rui314 / mold

Mold: A Modern Linker 🦠
MIT License
14.2k stars 468 forks source link

2 tests fail on RiscV #1291

Closed ausil closed 3 months ago

ausil commented 3 months ago

When building mold for riscv on Fedora 40 the test suite fails on 2 tests. I am not sure of the best way to debug them further

99% tests passed, 2 tests failed out of 338

Total Test time (real) = 103.65 sec

The following tests did not run:
     56 - riscv64-discard (Skipped)
     58 - riscv64-dt-init (Skipped)
     76 - riscv64-exception-multiple-ehframe (Skipped)
     90 - riscv64-gdb-index-compress-output (Skipped)
     91 - riscv64-gdb-index-dwarf2 (Skipped)
     92 - riscv64-gdb-index-dwarf3 (Skipped)
     93 - riscv64-gdb-index-dwarf4 (Skipped)
     94 - riscv64-gdb-index-dwarf5 (Skipped)
     95 - riscv64-gdb-index-dwarf64 (Skipped)
     97 - riscv64-gdb-index-split-dwarf (Skipped)
    151 - riscv64-lto-llvm (Skipped)
    266 - riscv64-tlsdesc-dlopen (Skipped)
    267 - riscv64-tlsdesc-import (Skipped)
    268 - riscv64-tlsdesc-initial-exec (Skipped)
    269 - riscv64-tlsdesc-local-dynamic (Skipped)
    270 - riscv64-tlsdesc-static (Skipped)
    271 - riscv64-tlsdesc (Skipped)

The following tests FAILED:
    122 - riscv64-ifunc-static-pie (Failed)
    225 - riscv64-static-pie (Failed)
Errors while running CTest
rui314 commented 3 months ago

I cannot debug it myself because Fedora doesn't provide a Docker image for riscv64.

Can you run the failing tests as bash -x test/elf/static-pie.sh and bash -x test/elf/ifunc-static-pie.sh and copy-n-paste the output?

ausil commented 3 months ago

running the tests alone they pass okay, but as part of the rpm build they fail

The following tests FAILED:
    122 - riscv64-ifunc-static-pie (Failed)
    225 - riscv64-static-pie (Failed)
Errors while running CTest
error: Bad exit status from /var/tmp/rpm-tmp.aoysuV (%check)

RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.aoysuV (%check) 
[mockbuild@a460513229fd4580ab9226e651e0bfbe ~]$ cd /builddir/build/BUILD/mold-2.32.0/
[mockbuild@a460513229fd4580ab9226e651e0bfbe mold-2.32.0]$ bash -x test/elf/static-pie.sh
++ dirname test/elf/static-pie.sh
+ . test/elf/common.inc
++ export LC_ALL=C
++ LC_ALL=C
++ '[' -z '' ']'
++++ uname -m
+++ canonical_name riscv64
+++ case $1 in
+++ echo riscv64
++ MACHINE=riscv64
++ '[' -z '' ']'
++ TESTDIR=out/test/elf/riscv64
++ CC=cc
++ CXX=c++
++ GCC=gcc
++ GXX=g++
++ OBJDUMP=objdump
++ OBJCOPY=objcopy
++ STRIP=strip
++ QEMU=
++ '[' riscv64 = x86_64 -o riscv64 = i686 -o riscv64 = arm ']'
++ '[' riscv64 = aarch64 ']'
++ trap 'on_error $LINENO' ERR
++ trap on_exit EXIT
+++ basename test/elf/static-pie.sh .sh
++ testname=static-pie
++ echo -n 'Testing static-pie ... '
Testing static-pie ... ++ t=out/test/elf/riscv64/static-pie
++ mkdir -p out/test/elf/riscv64/static-pie
+ test_cflags -static-pie
+ echo 'int main() {}'
+ cc -static-pie -o /dev/null -xc -
+ cat
+ cc -o out/test/elf/riscv64/static-pie/a.o -c -xc - -fPIE
+ cc -B. -o out/test/elf/riscv64/static-pie/exe1 out/test/elf/riscv64/static-pie/a.o -static-pie
+ out/test/elf/riscv64/static-pie/exe1
+ grep -q 'Hello world'
+ cc -B. -o out/test/elf/riscv64/static-pie/exe2 out/test/elf/riscv64/static-pie/a.o -static-pie -Wl,--no-relax
+ out/test/elf/riscv64/static-pie/exe2
+ grep -q 'Hello world'
+ on_exit
+ echo OK
OK
+ exit 0
[mockbuild@a460513229fd4580ab9226e651e0bfbe mold-2.32.0]$ bash -x test/elf/ifunc-static-pie.sh
++ dirname test/elf/ifunc-static-pie.sh
+ . test/elf/common.inc
++ export LC_ALL=C
++ LC_ALL=C
++ '[' -z '' ']'
++++ uname -m
+++ canonical_name riscv64
+++ case $1 in
+++ echo riscv64
++ MACHINE=riscv64
++ '[' -z '' ']'
++ TESTDIR=out/test/elf/riscv64
++ CC=cc
++ CXX=c++
++ GCC=gcc
++ GXX=g++
++ OBJDUMP=objdump
++ OBJCOPY=objcopy
++ STRIP=strip
++ QEMU=
++ '[' riscv64 = x86_64 -o riscv64 = i686 -o riscv64 = arm ']'
++ '[' riscv64 = aarch64 ']'
++ trap 'on_error $LINENO' ERR
++ trap on_exit EXIT
+++ basename test/elf/ifunc-static-pie.sh .sh
++ testname=ifunc-static-pie
++ echo -n 'Testing ifunc-static-pie ... '
Testing ifunc-static-pie ... ++ t=out/test/elf/riscv64/ifunc-static-pie
++ mkdir -p out/test/elf/riscv64/ifunc-static-pie
+ test_cflags -static-pie
+ echo 'int main() {}'
+ cc -static-pie -o /dev/null -xc -
+ supports_ifunc
+ is_musl
+ ldd --version
+ grep -q musl
+ echo 'void x() __attribute__((ifunc("y"))); void *y() { return 0; }'
+ cc -c -o /dev/null -xc -
+ cat
+ cc -o out/test/elf/riscv64/ifunc-static-pie/a.o -c -xc - -fPIC
+ cc -B. -o out/test/elf/riscv64/ifunc-static-pie/exe2 out/test/elf/riscv64/ifunc-static-pie/a.o -static-pie
+ out/test/elf/riscv64/ifunc-static-pie/exe2
+ grep -q 'Hello world'
+ on_exit
+ echo OK
OK
+ exit 0
rui314 commented 3 months ago

ctest runs the scripts just like you manually did, so it is odd that the scripts failed only for the rpm build. I'm not familiar with the RPM packaging system. Can you debug a little bit to see which command in the scripts failed?

ausil commented 3 months ago

rpmbuild output the full failure

125/338 Test #122: riscv64-ifunc-static-pie ....................***Failed    3.05 sec
++ dirname /builddir/build/BUILD/mold-2.32.0/test/elf/ifunc-static-pie.sh
+ . /builddir/build/BUILD/mold-2.32.0/test/elf/common.inc
++ export LC_ALL=C
++ LC_ALL=C
++ '[' -z riscv64 ']'
++ '[' -z '' ']'
++ TESTDIR=out/test/elf/riscv64
++ CC=cc
++ CXX=c++
++ GCC=gcc
++ GXX=g++
++ OBJDUMP=objdump
++ OBJCOPY=objcopy
++ STRIP=strip
++ QEMU=
++ '[' riscv64 = x86_64 -o riscv64 = i686 -o riscv64 = arm ']'
++ '[' riscv64 = aarch64 ']'
++ trap 'on_error $LINENO' ERR
++ trap on_exit EXIT
+++ basename /builddir/build/BUILD/mold-2.32.0/test/elf/ifunc-static-pie.sh .sh
++ testname=ifunc-static-pie
++ echo -n 'Testing ifunc-static-pie ... '
Testing ifunc-static-pie ... ++ t=out/test/elf/riscv64/ifunc-static-pie
++ mkdir -p out/test/elf/riscv64/ifunc-static-pie
+ test_cflags -static-pie
+ echo 'int main() {}'
+ cc -static-pie -o /dev/null -xc -
+ supports_ifunc
+ is_musl
+ ldd --version
+ grep -q musl
+ echo 'void x() __attribute__((ifunc("y"))); void *y() { return 0; }'
+ cc -c -o /dev/null -xc -
+ cat
+ cc -o out/test/elf/riscv64/ifunc-static-pie/a.o -c -xc - -fPIC
+ cc -B. -o out/test/elf/riscv64/ifunc-static-pie/exe2 out/test/elf/riscv64/ifunc-static-pie/a.o -static-pie
+ out/test/elf/riscv64/ifunc-static-pie/exe2
+ grep -q 'Hello world'
++ on_error 27
++ code=1
++ echo 'command failed: 27: grep -q '\''Hello world'\'''
command failed: 27: grep -q 'Hello world'
++ trap - EXIT
++ exit 1

231/338 Test #225: riscv64-static-pie ..........................***Failed    2.81 sec
++ dirname /builddir/build/BUILD/mold-2.32.0/test/elf/static-pie.sh
+ . /builddir/build/BUILD/mold-2.32.0/test/elf/common.inc
++ export LC_ALL=C
++ LC_ALL=C
++ '[' -z riscv64 ']'
++ '[' -z '' ']'
++ TESTDIR=out/test/elf/riscv64
++ CC=cc
++ CXX=c++
++ GCC=gcc
++ GXX=g++
++ OBJDUMP=objdump
++ OBJCOPY=objcopy
++ STRIP=strip
++ QEMU=
++ '[' riscv64 = x86_64 -o riscv64 = i686 -o riscv64 = arm ']'
++ '[' riscv64 = aarch64 ']'
++ trap 'on_error $LINENO' ERR
++ trap on_exit EXIT
+++ basename /builddir/build/BUILD/mold-2.32.0/test/elf/static-pie.sh .sh
++ testname=static-pie
++ echo -n 'Testing static-pie ... '
Testing static-pie ... ++ t=out/test/elf/riscv64/static-pie
++ mkdir -p out/test/elf/riscv64/static-pie
+ test_cflags -static-pie
+ echo 'int main() {}'
+ cc -static-pie -o /dev/null -xc -
+ cat
+ cc -o out/test/elf/riscv64/static-pie/a.o -c -xc - -fPIE
+ cc -B. -o out/test/elf/riscv64/static-pie/exe1 out/test/elf/riscv64/static-pie/a.o -static-pie
+ out/test/elf/riscv64/static-pie/exe1
+ grep -q 'Hello world'
++ on_error 14
++ code=1
++ echo 'command failed: 14: grep -q '\''Hello world'\'''
command failed: 14: grep -q 'Hello world'
++ trap - EXIT
++ exit 1
ausil commented 3 months ago

the rpmbuild puts its output in a slightly different location. The binaries segfault from those two tests

[mockbuild@a460513229fd4580ab9226e651e0bfbe mold-2.32.0]$  redhat-linux-build/out/test/elf/riscv64/static-pie/exe1 
Segmentation fault (core dumped)
[mockbuild@a460513229fd4580ab9226e651e0bfbe mold-2.32.0]$  redhat-linux-build/out/test/elf/riscv64/ifunc-static-pie/exe2 
Segmentation fault (core dumped)
ausil commented 3 months ago

http://fedora.riscv.rocks:3000/davidlt/-/packages/container/fedora-generic/40 has info on getting a fedora container image