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 313d36a
Show file tree
Hide file tree
Showing 188 changed files with 393 additions and 355 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)
4 changes: 2 additions & 2 deletions test/arch-aarch64-variant-pcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ foo:
EOF

$CC -B. -shared -o $t/b.so $t/a.o
readelf -W --dyn-syms $t/b.so | grep foo | grep -q '[VARIANT_PCS]'
$READELF -W --dyn-syms $t/b.so | grep foo | grep -q '[VARIANT_PCS]'

cat <<EOF | $CC -c -o $t/c.o -xc -
void foo();
int main() { foo(); }
EOF

$CC -B. -o $t/exe $t/c.o $t/b.so
readelf -W --dynamic $t/exe | grep -q AARCH64_VARIANT_PCS
$READELF -W --dynamic $t/exe | grep -q AARCH64_VARIANT_PCS
6 changes: 3 additions & 3 deletions test/arch-riscv64-attributes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void foo() {}
EOF

# The compiler might not create .riscv.attributes
readelf --sections $t/a.o | grep -Fq .riscv.attributes || skip
$READELF --sections $t/a.o | grep -Fq .riscv.attributes || skip

cat <<EOF | $CC -march=rv64imafd_xtheadba2p0 -o $t/b.o -c -xc -
void bar() {}
Expand All @@ -17,7 +17,7 @@ void _start() {}
EOF

$CC -B. -nostdlib -o $t/exe $t/a.o $t/c.o
readelf -A $t/exe | grep -q '_xtheadba1p5"'
$READELF -A $t/exe | grep -q '_xtheadba1p5"'

$CC -B. -nostdlib -o $t/exe $t/a.o $t/b.o $t/c.o
readelf -A $t/exe | grep -q '_xtheadba2p0"'
$READELF -A $t/exe | grep -q '_xtheadba2p0"'
2 changes: 1 addition & 1 deletion test/arch-riscv64-attributes2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ $STRIP --remove-section=.riscv.attributes $t/a.o

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

readelf -W --segments --sections $t/exe > $t/log
$READELF -W --segments --sections $t/exe > $t/log
! grep -F .riscv.attributes $t/log || false
! grep -F RISCV_ATTR $t/log || false
6 changes: 3 additions & 3 deletions test/arch-riscv64-global-pointer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ int main() {
EOF

$CC -B. -o $t/exe1 $t/a.o -fno-PIE
readelf -W --dyn-syms $t/exe1 | grep -Fq '__global_pointer$'
$READELF -W --dyn-syms $t/exe1 | grep -Fq '__global_pointer$'

$CC -B. -o $t/exe2 $t/a.o -fPIE
readelf -W --dyn-syms $t/exe2 | grep -Fq '__global_pointer$'
$READELF -W --dyn-syms $t/exe2 | grep -Fq '__global_pointer$'

cat <<EOF | $CC -o $t/b.o -c -xc - -fPIC
#include <stdio.h>
Expand All @@ -22,5 +22,5 @@ int hello() {
EOF

$CC -B. -o $t/c.so $t/b.o -shared
readelf -W --dyn-syms $t/c.so > $t/log1
$READELF -W --dyn-syms $t/c.so > $t/log1
! grep -Fq '__global_pointer$' $t/log1 || false
2 changes: 1 addition & 1 deletion test/arch-x86_64-empty-mergeable-section.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ EOF
$CC -B. -o $t/exe $t/a.o $t/b.o $t/c.o
$t/exe

readelf -SW $t/exe > $t/log
$READELF -SW $t/exe > $t/log
grep -q '.rodata.str1.1 .* AMS ' $t/log
! grep -q '.rodata.str1.1 .* AM ' $t/log || false
2 changes: 1 addition & 1 deletion test/arch-x86_64-emulation-deduction.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ void _start() {}
EOF

./mold -o $t/exe $t/a.o
readelf --file-header $t/exe | grep -qi x86-64
$READELF --file-header $t/exe | grep -qi x86-64
4 changes: 2 additions & 2 deletions test/arch-x86_64-execstack-if-needed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ main:
EOF

$CC -B. -o $t/exe $t/a.o >& /dev/null
readelf --segments -W $t/exe | grep -q 'GNU_STACK.* RW '
$READELF --segments -W $t/exe | grep -q 'GNU_STACK.* RW '

$CC -B. -o $t/exe $t/a.o -Wl,-z,execstack-if-needed
readelf --segments -W $t/exe | grep -q 'GNU_STACK.* RWE '
$READELF --segments -W $t/exe | grep -q 'GNU_STACK.* RWE '
10 changes: 5 additions & 5 deletions test/arch-x86_64-isa-level.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ int main() {}
EOF

$CC -B. -o $t/exe2 $t/a.o -Wl,-z,x86-64-v2
readelf -n $t/exe2 | grep -Fq 'Unknown note type: (0x00000005)' && skip
readelf -n $t/exe2 | grep -Fq 'procesor-specific type 0xc0008002' && skip
readelf -n $t/exe2 | grep -q 'x86 ISA needed: .*x86-64-v2'
$READELF -n $t/exe2 | grep -Fq 'Unknown note type: (0x00000005)' && skip
$READELF -n $t/exe2 | grep -Fq 'procesor-specific type 0xc0008002' && skip
$READELF -n $t/exe2 | grep -q 'x86 ISA needed: .*x86-64-v2'

$CC -B. -o $t/exe3 $t/a.o -Wl,-z,x86-64-v3
readelf -n $t/exe3 | grep -q 'x86 ISA needed: .*x86-64-v3'
$READELF -n $t/exe3 | grep -q 'x86 ISA needed: .*x86-64-v3'

$CC -B. -o $t/exe4 $t/a.o -Wl,-z,x86-64-v4
readelf -n $t/exe4 | grep -q 'x86 ISA needed: .*x86-64-v4'
$READELF -n $t/exe4 | grep -q 'x86 ISA needed: .*x86-64-v4'
4 changes: 2 additions & 2 deletions test/arch-x86_64-mergeable-strings-nonalloc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ EOF

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

readelf -x .foo $t/exe | grep -Fq '03000000 00000000 ffffffff ffffffff'
readelf -x .bar $t/exe | grep -Fq 'xyz.abc.'
$READELF -x .foo $t/exe | grep -Fq '03000000 00000000 ffffffff ffffffff'
$READELF -x .bar $t/exe | grep -Fq 'xyz.abc.'
2 changes: 1 addition & 1 deletion test/arch-x86_64-mergeable-strings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ EOF
$CC -B. -static -o $t/exe $t/a.o
$QEMU $t/exe | grep -q 'Hello world'

readelf -sW $t/exe | grep -Eq '[0-9] foo$'
$READELF -sW $t/exe | grep -Eq '[0-9] foo$'
4 changes: 2 additions & 2 deletions test/arch-x86_64-note-property.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void _start() {}
EOF

./mold -o $t/exe $t/a.o
readelf -n $t/exe | grep -q 'x86 feature: IBT'
$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
! $READELF -n $t/exe | grep -q 'x86 feature: IBT' || false
20 changes: 10 additions & 10 deletions test/arch-x86_64-note-property2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ nm mold | grep -q '__tsan_init' && skip
test_cflags -Xassembler -mx86-used-note=no && CFLAGS="-Xassembler -mx86-used-note=no" || CFLAGS=""

# This test requires the new ISA constants defined in Binutils 2.36
readelf -v | grep -q -E "GNU readelf .+ (2\.3[6-9]|2\.[4-9]|[3-9])" || skip
$READELF -v | grep -q -E "GNU $READELF .+ (2\.3[6-9]|2\.[4-9]|[3-9])" || skip

cat <<EOF | $CC $CFLAGS -c -o $t/a.o -xassembler-with-cpp -
#define NT_GNU_PROPERTY_TYPE_0 5
Expand Down Expand Up @@ -68,16 +68,16 @@ cat <<EOF | $CC $CFLAGS -c -o $t/c.o -xassembler-with-cpp -
EOF

./mold -nostdlib -o $t/exe1 $t/a.o $t/b.o
readelf -n $t/exe1 | grep -q 'x86 feature: SHSTK'
readelf -n $t/exe1 | grep -q 'x86 ISA needed: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4'
readelf -n $t/exe1 | grep -q 'x86 ISA used: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4'
$READELF -n $t/exe1 | grep -q 'x86 feature: SHSTK'
$READELF -n $t/exe1 | grep -q 'x86 ISA needed: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4'
$READELF -n $t/exe1 | grep -q 'x86 ISA used: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4'

./mold -nostdlib -o $t/exe2 $t/a.o $t/b.o $t/c.o
! readelf -n $t/exe2 | grep -q 'x86 feature: SHSTK' || false
readelf -n $t/exe2 | grep -q 'x86 ISA needed: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4' || false
! readelf -n $t/exe2 | grep -q 'x86 ISA used: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4'
! $READELF -n $t/exe2 | grep -q 'x86 feature: SHSTK' || false
$READELF -n $t/exe2 | grep -q 'x86 ISA needed: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4' || false
! $READELF -n $t/exe2 | grep -q 'x86 ISA used: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4'

./mold --relocatable -o $t/d.o $t/a.o $t/b.o
readelf -n $t/d.o | grep -q 'x86 feature: SHSTK'
readelf -n $t/d.o | grep -q 'x86 ISA needed: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4'
readelf -n $t/d.o | grep -q 'x86 ISA used: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4'
$READELF -n $t/d.o | grep -q 'x86 feature: SHSTK'
$READELF -n $t/d.o | grep -q 'x86 ISA needed: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4'
$READELF -n $t/d.o | grep -q 'x86 ISA used: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4'
4 changes: 2 additions & 2 deletions test/arch-x86_64-note.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ _start:
EOF

./mold -static -o $t/exe $t/a.o
readelf -W --sections $t/exe > $t/log
$READELF -W --sections $t/exe > $t/log

grep -Eq '.note.bar\s+NOTE.+000008 00 A 0 0 4' $t/log
grep -Eq '.note.baz\s+NOTE.+000008 00 A 0 0 8' $t/log
grep -Eq '.note.nonalloc\s+NOTE.+000008 00 0 0 1' $t/log

readelf --segments $t/exe > $t/log
$READELF --segments $t/exe > $t/log
grep -Fq '01 .note.bar .note.baz .note.foo' $t/log
! grep -q 'NOTE.*0x0000000000000000 0x0000000000000000' $t/log || false
2 changes: 1 addition & 1 deletion test/arch-x86_64-note2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ EOF

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

readelf --segments $t/exe > $t/log
$READELF --segments $t/exe > $t/log
grep -Fq '01 .note.a .note.b .note.c' $t/log
4 changes: 2 additions & 2 deletions test/arch-x86_64-plt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ EOF

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

readelf --sections $t/exe | grep -Fq '.got'
readelf --sections $t/exe | grep -Fq '.got.plt'
$READELF --sections $t/exe | grep -Fq '.got'
$READELF --sections $t/exe | grep -Fq '.got.plt'

$QEMU $t/exe | grep -q 'Hello world'
2 changes: 1 addition & 1 deletion test/arch-x86_64-reloc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ EOF

$CC -c -o $t/f.o $t/f.s
$CC -B. -o $t/exe $t/f.o
readelf -x .foo -x .bar $t/exe > $t/log
$READELF -x .foo -x .bar $t/exe > $t/log

grep -Fq '0x00000010 00000000 00000000 10000000 00000000' $t/log
grep -Fq '0x00000010 18000000 00000000' $t/log
22 changes: 11 additions & 11 deletions test/arch-x86_64-section-name.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ EOF

./mold -o $t/exe $t/a.o -z keep-text-section-prefix

readelf -p .text.hot $t/exe | grep -Fq '.text.hot .text.hot.foo'
readelf -p .text.unknown $t/exe | grep -Fq '.text.unknown .text.unknown.foo'
readelf -p .text.unlikely $t/exe | grep -Fq '.text.unlikely .text.unlikely.foo'
readelf -p .text.startup $t/exe | grep -Fq '.text.startup .text.startup.foo'
readelf -p .text.exit $t/exe | grep -Fq '.text.exit .text.exit.foo'
readelf -p .text $t/exe | grep -Fq '.text .text.foo'
readelf -p .data.rel.ro $t/exe | grep -Fq '.data.rel.ro .data.rel.ro.foo'
readelf -p .data $t/exe | grep -Fq '.data .data.foo'
readelf -p .rodata $t/exe | grep -Fq '.rodata .rodata.foo'
$READELF -p .text.hot $t/exe | grep -Fq '.text.hot .text.hot.foo'
$READELF -p .text.unknown $t/exe | grep -Fq '.text.unknown .text.unknown.foo'
$READELF -p .text.unlikely $t/exe | grep -Fq '.text.unlikely .text.unlikely.foo'
$READELF -p .text.startup $t/exe | grep -Fq '.text.startup .text.startup.foo'
$READELF -p .text.exit $t/exe | grep -Fq '.text.exit .text.exit.foo'
$READELF -p .text $t/exe | grep -Fq '.text .text.foo'
$READELF -p .data.rel.ro $t/exe | grep -Fq '.data.rel.ro .data.rel.ro.foo'
$READELF -p .data $t/exe | grep -Fq '.data .data.foo'
$READELF -p .rodata $t/exe | grep -Fq '.rodata .rodata.foo'

./mold -o $t/exe $t/a.o
! readelf --sections $t/exe | grep -Fq .text.hot || false
! $READELF --sections $t/exe | grep -Fq .text.hot || false

./mold -o $t/exe $t/a.o -z nokeep-text-section-prefix
! readelf --sections $t/exe | grep -Fq .text.hot || false
! $READELF --sections $t/exe | grep -Fq .text.hot || false
2 changes: 1 addition & 1 deletion test/arch-x86_64-tbss-only.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ EOF
$CC -B. -o $t/exe $t/a.o
$QEMU $t/exe

readelf -W --segments $t/exe | grep -Eq 'TLS +0x000([^ ][^ ][^ ]) 0x[^ ]+\1 '
$READELF -W --segments $t/exe | grep -Eq 'TLS +0x000([^ ][^ ][^ ]) 0x[^ ]+\1 '
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
6 changes: 3 additions & 3 deletions test/arch-x86_64-unique.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ EOF

$CC -B. -o $t/exe $t/a.o -nostdlib -Wl,-unique='*foo*'

readelf -x .data.foo.1 $t/exe | grep -q ab
readelf -x .data.foo.2 $t/exe | grep -q c
readelf -x .data $t/exe | grep -q de
$READELF -x .data.foo.1 $t/exe | grep -q ab
$READELF -x .data.foo.2 $t/exe | grep -q c
$READELF -x .data $t/exe | grep -q de
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'
4 changes: 2 additions & 2 deletions test/arch-x86_64-z-ibt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ main:
EOF

$CC -B. -o $t/exe $t/a.o
readelf --notes $t/exe > $t/log
$READELF --notes $t/exe > $t/log
! grep -qw SHSTK $t/log

$CC -B. -o $t/exe $t/a.o -Wl,-z,ibt
readelf --notes $t/exe | grep -qw IBT
$READELF --notes $t/exe | grep -qw IBT
4 changes: 2 additions & 2 deletions test/arch-x86_64-z-shstk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ main:
EOF

$CC -B. -o $t/exe $t/a.o
readelf --notes $t/exe > $t/log
$READELF --notes $t/exe > $t/log
! grep -qw SHSTK $t/log

$CC -B. -o $t/exe $t/a.o -Wl,-z,shstk
readelf --notes $t/exe | grep -qw SHSTK
$READELF --notes $t/exe | grep -qw SHSTK
4 changes: 2 additions & 2 deletions test/arch-x86_64-z-text.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ EOF
$CC -B. -pie -o $t/exe $t/a.o $t/b.o
$QEMU $t/exe | grep -q 3

readelf --dynamic $t/exe | grep -Fq '(TEXTREL)'
readelf --dynamic $t/exe | grep -q '\(FLAGS\).*TEXTREL'
$READELF --dynamic $t/exe | grep -Fq '(TEXTREL)'
$READELF --dynamic $t/exe | grep -q '\(FLAGS\).*TEXTREL'
2 changes: 1 addition & 1 deletion test/as-needed-dso.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ int main() { fn2(); }
EOF

$CC -B. -o $t/exe $t/a.o -L$t -Wl,--as-needed -lbar -lfoo
readelf -W --dynamic $t/exe > $t/log2
$READELF -W --dynamic $t/exe > $t/log2
grep -q libbar $t/log2
grep -q libfoo $t/log2
2 changes: 1 addition & 1 deletion test/as-needed-dso2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ $CC -B. -shared -o $t/libfoo.so $t/a.o
$CC -B. -shared -o $t/libbar.so $t/b.o
$CC -B. -o $t/exe $t/c.o -L$t -Wl,--as-needed -lfoo -lbar

readelf --dynamic $t/exe > $t/log
$READELF --dynamic $t/exe > $t/log
! grep libfoo.so $t/log || false
grep -q libbar.so $t/log
4 changes: 2 additions & 2 deletions test/as-needed-weak.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ EOF

$CC -B. -o $t/exe1 $t/a.o -Wl,-no-as-needed -L$t -lbar -lfoo

readelf --dynamic $t/exe1 > $t/log1
$READELF --dynamic $t/exe1 > $t/log1
grep -Fq 'Shared library: [libfoo.so]' $t/log1
grep -Fq 'Shared library: [libbar.so]' $t/log1

$CC -B. -o $t/exe2 $t/a.o -Wl,-as-needed -L$t -lbar -lfoo

readelf --dynamic $t/exe2 > $t/log2
$READELF --dynamic $t/exe2 > $t/log2
grep -Fq 'Shared library: [libfoo.so]' $t/log2
! grep -Fq 'Shared library: [libbar.so]' $t/log2 || false
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
2 changes: 1 addition & 1 deletion test/auxiliary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ EOF

./mold -o $t/b.so $t/a.o -auxiliary foo -f bar -shared

readelf --dynamic $t/b.so > $t/log
$READELF --dynamic $t/b.so > $t/log
grep -Fq 'Auxiliary library: [foo]' $t/log
grep -Fq 'Auxiliary library: [bar]' $t/log
Loading

0 comments on commit 313d36a

Please sign in to comment.