Skip to content

Commit

Permalink
Add a FreeBSD tester
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Sep 2, 2024
1 parent 8e010c2 commit 27c7678
Show file tree
Hide file tree
Showing 25 changed files with 71 additions and 38 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion install-build-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions test/arch-x86_64-tls-module-base.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
. $(dirname $0)/common.inc

supports_tlsdesc || skip

cat <<EOF | $CC -fPIC -o $t/a.o -c -xassembler -
.globl get_foo
.type get_foo, @function
Expand Down
2 changes: 1 addition & 1 deletion test/arch-x86_64-warn-execstack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ cat <<EOF | $CC -o $t/b.o -c -xc -
int main() {}
EOF

$GCC -B. -o $t/exe $t/a.o $t/b.o 2>&1 | grep -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'
12 changes: 6 additions & 6 deletions test/as-needed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 12 additions & 2 deletions test/common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;;
Expand Down Expand Up @@ -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() {
Expand All @@ -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" != '' ]
}

Expand Down
3 changes: 1 addition & 2 deletions test/defsym-lto.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash
. $(dirname $0)/common.inc

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

cat <<EOF | $CC -flto -fPIC -o $t/a.o -c -xc -
#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion test/dynamic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF | $CC -c -fPIC -o $t/b.o -xc -
#include <stdio.h>
Expand Down
4 changes: 1 addition & 3 deletions test/lto-archive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF | $CC -o $t/a.o -c -flto -xc -
#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion test/lto-archive2.sh
Original file line number Diff line number Diff line change
@@ -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 -

Expand Down
3 changes: 1 addition & 2 deletions test/lto-dso.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash
. $(dirname $0)/common.inc

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

cat <<EOF | $CC -flto -c -fPIC -o $t/a.o -xc -
void foo() {}
Expand Down
2 changes: 1 addition & 1 deletion test/lto-gcc.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
. $(dirname $0)/common.inc

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

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

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

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

cat <<EOF | clang -flto -c -o $t/a.o -xc -
Expand Down
2 changes: 2 additions & 0 deletions test/lto-nostdlib.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
. $(dirname $0)/common.inc

test_cflags -flto || skip

cat <<EOF | $CC -flto -c -o $t/a.o -xc -
void _start() {}
EOF
Expand Down
2 changes: 2 additions & 0 deletions test/lto-version-script.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
. $(dirname $0)/common.inc

test_cflags -flto || skip

cat <<EOF | $CC -flto -c -fPIC -o $t/a.o -xc -
void foo() {}
void bar() {}
Expand Down
2 changes: 1 addition & 1 deletion test/many-sections2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
nm mold | grep -q '__tsan_init' && skip

echo 'foo = 0x1000' > $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
Expand Down
2 changes: 1 addition & 1 deletion test/mold-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions test/range-extension-thunk3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions test/section-order.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# qemu crashes if the ELF header is not mapped to memory
on_qemu && skip
[ "$(uname)" = FreeBSD ] && skip

cat <<EOF | $CC -o $t/a.o -c -xc -fno-PIC $flags -
#include <stdio.h>
Expand Down
2 changes: 2 additions & 0 deletions test/symbol-version-lto.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
. $(dirname $0)/common.inc

test_cflags -flto || skip

cat <<EOF | $CC -fPIC -c -o $t/a.o -xc - -flto
void foo_1() {}
__asm__(".symver foo_1, foo@@VER1");
Expand Down
2 changes: 1 addition & 1 deletion test/thin-archive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ rm -f $t/d.a
$CC -B. -Wl,--trace -o $t/exe $t/d.o $t/d.a > $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
2 changes: 1 addition & 1 deletion test/warn-once.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
18 changes: 9 additions & 9 deletions test/whole-archive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions test/wrap-lto.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
. $(dirname $0)/common.inc

test_cflags -flto || skip

cat <<EOF | $CC -fPIC -shared -o $t/a.so -xc -
#include <stdio.h>
Expand Down

0 comments on commit 27c7678

Please sign in to comment.