From 27c7678f124ebf5b1c8f777f94f51e9b73f32be8 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Mon, 2 Sep 2024 13:53:23 +0900 Subject: [PATCH] Add a FreeBSD tester --- .github/workflows/ci.yml | 16 ++++++++++++++++ install-build-deps.sh | 2 +- test/arch-x86_64-tls-module-base.sh | 2 ++ test/arch-x86_64-warn-execstack.sh | 2 +- test/as-needed.sh | 12 ++++++------ test/common.inc | 14 ++++++++++++-- test/defsym-lto.sh | 3 +-- test/dynamic.sh | 2 +- test/lto-archive.sh | 4 +--- test/lto-archive2.sh | 2 +- test/lto-dso.sh | 3 +-- test/lto-gcc.sh | 2 +- test/lto-llvm.sh | 2 +- test/lto-nostdlib.sh | 2 ++ test/lto-version-script.sh | 2 ++ test/many-sections2.sh | 2 +- test/mold-wrapper.sh | 2 +- test/range-extension-thunk3.sh | 6 +++--- test/run.sh | 2 +- test/section-order.sh | 1 + test/symbol-version-lto.sh | 2 ++ test/thin-archive.sh | 2 +- test/warn-once.sh | 2 +- test/whole-archive.sh | 18 +++++++++--------- test/wrap-lto.sh | 2 ++ 25 files changed, 71 insertions(+), 38 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3dfc1fdf44..16e27facc9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -156,3 +156,19 @@ jobs: cd build cmake -GNinja -DMOLD_USE_MIMALLOC=OFF -DMOLD_USE_SYSTEM_TBB=ON .. cmake --build . -j $(nproc) + + build-freebsd: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Build and test + uses: vmactions/freebsd-vm@v1 + with: + usesh: true + run: | + ./install-build-deps.sh + mkdir build + cd build + cmake .. + cmake --build . -j$(nproc) + ctest -j$(nproc) diff --git a/install-build-deps.sh b/install-build-deps.sh index 126a6e7b69..4ef3bac1da 100755 --- a/install-build-deps.sh +++ b/install-build-deps.sh @@ -45,7 +45,7 @@ almalinux-*) ;; freebsd-*) pkg update - pkg install -y cmake bash + pkg install -y cmake bash binutils gcc ;; *) echo "Error: don't know anything about build dependencies on $ID-$VERSION_ID" diff --git a/test/arch-x86_64-tls-module-base.sh b/test/arch-x86_64-tls-module-base.sh index 211d2a5a2f..830f0297f4 100755 --- a/test/arch-x86_64-tls-module-base.sh +++ b/test/arch-x86_64-tls-module-base.sh @@ -1,6 +1,8 @@ #!/bin/bash . $(dirname $0)/common.inc +supports_tlsdesc || skip + cat <&1 | grep -q 'may cause a segmentation fault' +$GCC -B. -o $t/exe $t/a.o $t/b.o 2>&1 | grep -Eq 'may cause a segmentation fault|requires executable stack' diff --git a/test/as-needed.sh b/test/as-needed.sh index b0389c2762..6d5448c8a5 100755 --- a/test/as-needed.sh +++ b/test/as-needed.sh @@ -18,12 +18,12 @@ EOF $CC -B. -o $t/exe $t/a.o -Wl,--no-as-needed $t/b.so $t/c.so -readelf --dynamic $t/exe > $t/readelf -grep -Fq 'Shared library: [libfoo.so]' $t/readelf -grep -Fq 'Shared library: [libbar.so]' $t/readelf +readelf --dynamic $t/exe > $t/log +grep -Fq 'Shared library: [libfoo.so]' $t/log +grep -Fq 'Shared library: [libbar.so]' $t/log $CC -B. -o $t/exe $t/a.o -Wl,--as-needed $t/b.so $t/c.so -readelf --dynamic $t/exe > $t/readelf -grep -Fq 'Shared library: [libfoo.so]' $t/readelf -! grep -Fq 'Shared library: [libbar.so]' $t/readelf || false +readelf --dynamic $t/exe > $t/log +grep -Fq 'Shared library: [libfoo.so]' $t/log +! grep -Fq 'Shared library: [libbar.so]' $t/log || false diff --git a/test/common.inc b/test/common.inc index e2b0cd600b..d7a987f957 100644 --- a/test/common.inc +++ b/test/common.inc @@ -6,6 +6,7 @@ export LC_ALL=C canonical_name() { case $1 in i?86) echo i686 ;; + amd64) echo x86_64 ;; arm*) echo arm ;; powerpc) echo ppc ;; powerpc64) echo ppc64 ;; @@ -65,13 +66,19 @@ aarch64 | loongarch*) tlsdesc_opt=-mtls-dialect=desc ;; esac +# We want to use GNU's binutils even on BSDs. `pkg install binutils` +# installs GNU binutils under /usr/local/bin. +if [ "$(uname)" = FreeBSD ]; then + export PATH="/usr/local/bin:$PATH" +fi + # Common functions test_cflags() { - echo 'int main() {}' | $CC "$@" -o /dev/null -xc - >& /dev/null + echo 'int main() {}' | $CC -B. "$@" -o /dev/null -xc - >& /dev/null } test_cxxflags() { - echo 'int main() {}' | $CXX "$@" -o /dev/null -xc++ - >& /dev/null + echo 'int main() {}' | $CXX -B. "$@" -o /dev/null -xc++ - >& /dev/null } is_musl() { @@ -88,6 +95,9 @@ supports_tlsdesc() { # musl's tlsdesc on arm32 seems to be broken [ $MACHINE = arm ] && is_musl && return 1 + # FreeBSD's loader doesn't support TLSDESC relocs in an executable + [ "$(uname)" = FreeBSD ] && return 1 + [ "$tlsdesc_opt" != '' ] } diff --git a/test/defsym-lto.sh b/test/defsym-lto.sh index 3848384b30..d60b83df6b 100755 --- a/test/defsym-lto.sh +++ b/test/defsym-lto.sh @@ -1,8 +1,7 @@ #!/bin/bash . $(dirname $0)/common.inc -echo 'int main() {}' | $CC -flto -o /dev/null -xc - >& /dev/null \ - || skip +test_cflags -flto || skip cat < diff --git a/test/dynamic.sh b/test/dynamic.sh index ce207c6a3b..2b9576c2ae 100755 --- a/test/dynamic.sh +++ b/test/dynamic.sh @@ -9,7 +9,7 @@ readelf --dynamic $t/exe > $t/log grep -Eq 'Shared library:.*\blibc\b' $t/log readelf -W --dyn-syms --use-dynamic $t/exe > $t/log2 -grep -Eq 'FUNC\s+GLOBAL\s+DEFAULT.*UND\s+__libc_start_main' $t/log2 +grep -Eq 'FUNC\s+GLOBAL\s+DEFAULT.*UND\s+__libc_start' $t/log2 cat < diff --git a/test/lto-archive.sh b/test/lto-archive.sh index 88ce90f0a4..3938a9b2b9 100755 --- a/test/lto-archive.sh +++ b/test/lto-archive.sh @@ -2,9 +2,7 @@ . $(dirname $0)/common.inc [ "$CC" = cc ] || skip - -echo 'int main() {}' | $CC -flto -o /dev/null -xc - >& /dev/null \ - || skip +test_cflags -flto || skip cat < diff --git a/test/lto-archive2.sh b/test/lto-archive2.sh index 4357294182..8a63b9d74f 100755 --- a/test/lto-archive2.sh +++ b/test/lto-archive2.sh @@ -1,7 +1,7 @@ #!/bin/bash . $(dirname $0)/common.inc -echo 'int main() {}' | $CC -flto=auto -o /dev/null -xc - >& /dev/null || skip +test_cflags -flto=auto || skip echo | $CC -o $t/a.o -c -flto=auto -xc - diff --git a/test/lto-dso.sh b/test/lto-dso.sh index 5fe3c4d57f..61c27794fd 100755 --- a/test/lto-dso.sh +++ b/test/lto-dso.sh @@ -1,8 +1,7 @@ #!/bin/bash . $(dirname $0)/common.inc -echo 'int main() {}' | $CC -flto -o /dev/null -xc - >& /dev/null \ - || skip +test_cflags -flto || skip cat <& /dev/null \ +echo 'int main() {}' | $GCC -B. -flto -o /dev/null -xc - >& /dev/null \ || skip cat <& /dev/null \ +echo 'int main() {}' | clang -B. -flto -o /dev/null -xc - >& /dev/null \ || skip cat < $t/a.s -seq 1 100000 | sed 's/.*/.section .data.\0,"aw"\n.globl x\0\nx\0: .word 0\n/g' >> $t/a.s +seq 1 100000 | sed 's/.*/.section .data.&,"aw"\n.globl x&\nx&: .word 0\n/g' >> $t/a.s $CC -c -xassembler -o $t/a.o $t/a.s ./mold --relocatable -o $t/b.o $t/a.o diff --git a/test/mold-wrapper.sh b/test/mold-wrapper.sh index 2bd0bb99e7..4748c8d74c 100755 --- a/test/mold-wrapper.sh +++ b/test/mold-wrapper.sh @@ -8,7 +8,7 @@ ldd mold-wrapper.so | grep -q libasan && skip nm mold | grep -q '__[at]san_init' && skip cat <<'EOF' > $t/a.sh -#!/bin/bash +#!/usr/bin/env bash echo "$0" "$@" $FOO EOF diff --git a/test/range-extension-thunk3.sh b/test/range-extension-thunk3.sh index bb45e594fe..5174727183 100755 --- a/test/range-extension-thunk3.sh +++ b/test/range-extension-thunk3.sh @@ -4,12 +4,12 @@ [ $MACHINE = alpha ] && skip [ $MACHINE = sh4 ] && skip -seq 1 10000 | sed 's/.*/void func\0() {}/' > $t/a.c +seq 1 10000 | sed 's/.*/void func&() {}/' > $t/a.c $CC -B. -o $t/b.so -shared $t/a.c -seq 1 10000 | sed 's/.*/void func\0();/' > $t/c.c +seq 1 10000 | sed 's/.*/void func&();/' > $t/c.c echo 'int main() {' >> $t/c.c -seq 1 10000 | sed 's/.*/func\0();/' >> $t/c.c +seq 1 10000 | sed 's/.*/func&();/' >> $t/c.c echo '}' >> $t/c.c $CC -c -o $t/d.o $t/c.c diff --git a/test/run.sh b/test/run.sh index b103fd07b1..e62576362c 100755 --- a/test/run.sh +++ b/test/run.sh @@ -16,7 +16,7 @@ int main() { EOF LD_PRELOAD=`pwd`/mold-wrapper.so MOLD_PATH=`pwd`/mold \ - $GCC -o $t/exe $t/a.o -B/usr/bin + $CC -o $t/exe $t/a.o -B/usr/bin readelf -p .comment $t/exe > $t/log grep -q mold $t/log diff --git a/test/section-order.sh b/test/section-order.sh index fb856ed86d..989089cd4d 100755 --- a/test/section-order.sh +++ b/test/section-order.sh @@ -3,6 +3,7 @@ # qemu crashes if the ELF header is not mapped to memory on_qemu && skip +[ "$(uname)" = FreeBSD ] && skip cat < diff --git a/test/symbol-version-lto.sh b/test/symbol-version-lto.sh index f8b3f2eb82..de02e456df 100755 --- a/test/symbol-version-lto.sh +++ b/test/symbol-version-lto.sh @@ -1,6 +1,8 @@ #!/bin/bash . $(dirname $0)/common.inc +test_cflags -flto || skip + cat < $t/log grep -Eq 'thin-archive/d.a\(.*long-long-long-filename.o\)' $t/log -grep -Eq 'thin-archive/d.a\(.*/b.o\)' $t/log +grep -Eq 'thin-archive/d.a\((.*/)?b.o\)' $t/log grep -Fq thin-archive/d.o $t/log $QEMU $t/exe | grep -q 15 diff --git a/test/warn-once.sh b/test/warn-once.sh index 44ab16a3ff..852fe0e287 100755 --- a/test/warn-once.sh +++ b/test/warn-once.sh @@ -14,4 +14,4 @@ EOF $CC -B. -o $t/exe $t/a.o $t/b.o -Wl,--warn-unresolved-symbols,--warn-once >& $t/log -[ "$(grep 'undefined symbol:.* foo$' $t/log | wc -l)" = 1 ] +[ $(grep 'undefined symbol:.* foo$' $t/log | wc -l) = 1 ] diff --git a/test/whole-archive.sh b/test/whole-archive.sh index de5da115ae..721acf37c7 100755 --- a/test/whole-archive.sh +++ b/test/whole-archive.sh @@ -14,19 +14,19 @@ ar cr $t/d.a $t/b.o $t/c.o $CC -B. -nostdlib -o $t/exe $t/a.o $t/d.a -readelf --symbols $t/exe > $t/readelf -! grep -q fn1 $t/readelf || false -! grep -q fn2 $t/readelf || false +readelf --symbols $t/exe > $t/log +! grep -q fn1 $t/log || false +! grep -q fn2 $t/log || false $CC -B. -nostdlib -o $t/exe $t/a.o -Wl,--whole-archive $t/d.a -readelf --symbols $t/exe > $t/readelf -grep -q fn1 $t/readelf -grep -q fn2 $t/readelf +readelf --symbols $t/exe > $t/log +grep -q fn1 $t/log +grep -q fn2 $t/log $CC -B. -nostdlib -o $t/exe $t/a.o -Wl,--whole-archive \ -Wl,--no-whole-archive $t/d.a -readelf --symbols $t/exe > $t/readelf -! grep -q fn1 $t/readelf || false -! grep -q fn2 $t/readelf || false +readelf --symbols $t/exe > $t/log +! grep -q fn1 $t/log || false +! grep -q fn2 $t/log || false diff --git a/test/wrap-lto.sh b/test/wrap-lto.sh index 1e26af8ce8..0e2fb52bce 100755 --- a/test/wrap-lto.sh +++ b/test/wrap-lto.sh @@ -1,6 +1,8 @@ #!/bin/bash . $(dirname $0)/common.inc +test_cflags -flto || skip + cat <