Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore native armv7 support for NetBSD 10.0 #13146

Open
VoxSciurorum opened this issue May 4, 2024 · 7 comments
Open

Restore native armv7 support for NetBSD 10.0 #13146

VoxSciurorum opened this issue May 4, 2024 · 7 comments
Assignees

Comments

@VoxSciurorum
Copy link

The 4.14 branch configure script does not enable native compiler support for armv7 on NetBSD 10.0. The patch below enables the native compiler. All expected tests pass except testyield.ml which also fails with the bytecode compiler. See issue #12415.

diff --git a/configure.ac b/configure.ac
index 892af53fad..d25df8eef1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1042,6 +1042,7 @@ AS_IF([test x"$supports_shared_libraries" = 'xtrue'],
     [[i[3456]86-*-haiku*]], [natdynlink=true],
     [arm*-*-linux*], [natdynlink=true],
     [arm*-*-freebsd*], [natdynlink=true],
+    [arm*-*-netbsd*], [natdynlink=true],
     [earm*-*-netbsd*], [natdynlink=true],
     [aarch64-*-linux*], [natdynlink=true],
     [aarch64-*-freebsd*], [natdynlink=true],
@@ -1118,6 +1119,8 @@ AS_CASE([$host],
     [arch=arm; model=armv6; system=netbsd],
   [earmv7*-*-netbsd*],
     [arch=arm; model=armv7; system=netbsd],
+  [armv7*-*-netbsd*],
+    [arch=arm; model=armv7; system=netbsd],
   [armv5te*-*-linux-*eabi],
     [arch=arm; model=armv5te; system=linux_eabi],
   [armv5*-*-linux-*eabi],

uname -a reports

NetBSD palmarum 10.0 NetBSD 10.0 (GENERIC) #0: Thu Mar 28 08:33:33 UTC 2024  [email protected]:/usr/src/sys/arch/evbarm/compile/GENERIC evbarm
@tmcgilchrist
Copy link
Contributor

I don't have physical hardware to try this out so I've used QEMU emulating a cortex-a15, roughly following these instructions on macOS ARM64.

qemu-system-arm -M virt -cpu cortex-a15 -smp 4 -m 2g \
      -drive if=none,file=armv7.img,id=hd0 -device virtio-blk-device,drive=hd0 \
      -netdev type=user,id=net0 -device virtio-net-device,netdev=net0,mac=00:11:22:33:44:55 \
      -bios QEMU_EFI.fd -nographic -vga virtio

I made the changes to configure.ac as you have here. However I ran into three issues:

  1. Error in sak.c with char used as array subscript
$ gmake
gmake -C runtime sak
gmake[1]: Entering directory '/home/tsmc/ocaml-4.14/runtime'
gcc -c -O2 -fno-strict-aliasing -fwrapv -pthread -Wall -Wdeclaration-after-statement -Werror -fno-common -fexcess-precision=standard -g  -D_FILE_OFFSET_BITS=64 -DCAML_NAME_SPACE  -DCAMLDLLIMPORT=  -o sak.o sak.c
In file included from /usr/include/ctype.h:100,
                 from sak.c:29:
sak.c: In function 'add_stdlib_prefix':
sak.c:126:26: error: array subscript has type 'char' [-Werror=char-subscripts]
  126 |       *name = toupper_os(*name);
      |                          ^
sak.c:126:15: note: in expansion of macro 'toupper_os'
  126 |       *name = toupper_os(*name);
      |               ^~~~~~~~~~
cc1: all warnings being treated as errors
gmake[1]: *** [Makefile:260: sak.o] Error 1
gmake[1]: Leaving directory '/home/tsmc/ocaml-4.14/runtime'
gmake: *** [Makefile:785: runtime/sak] Error 2

Ignoring that with CFLAGS of -Wno-error gets to the second issue.

  1. Selected processor does not support `cbz r1,1f' in ARM mode
$ gmake
...
gmake[3]: Entering directory '/home/tsmc/ocaml-4.14/runtime'
/usr/pkg/gcc13/bin/gcc -c -DSYS_unknown -I../runtime -DMODEL_default -o arm.o arm.S || \
{ echo "If your assembler produced syntax errors, it is probably";\
          echo "unhappy with the preprocessor. Check your assembler, or";\
          echo "try producing arm.o by hand.";\
          exit 2; }
arm.S: Assembler messages:
arm.S:333: Error: selected processor does not support `cbz r1,1f' in ARM mode
arm.S:363: Error: selected processor does not support `cbz r1,1f' in ARM mode
If your assembler produced syntax errors, it is probably
unhappy with the preprocessor. Check your assembler, or
try producing arm.o by hand.

Which is used in runtime/arm.S. Not sure why the feature detection on NetBSD fails, that instruction should be available on a cortex-a15 using thumb encoding. This is what NetBSD knows about the processor:

armv7# cpuctl identify 0
cpu0: isa features: Swap, Bitcount, Bitfield, CmpBranch, Coproc=0, Debug
cpu0: isa features: Divde=2, Endian, Except, Except_AR, Extend=2, IfThen
cpu0: isa features: Immediate, Interwork=3, Jazelle, LoadStore, MemHint=4
cpu0: isa features: MultAccessInt=0, Mult=2, MultS=3, MultU=2, PSR_AR
cpu0: isa features: Reversal=2, Saturate, SIMD=3, SVC, SynchPrim=2, TabBranch
cpu0: isa features: ThumbCopy, TrueNOP, ThumbEE_Extn, Unpriv=2, WithShifts=4
cpu0: isa features: Writeback, SMC, Barrier, SynchPrim_frac, PSR_M, SWP
cpu0: memory model: VMSA-Support=5, Outermost-Shareability=1
cpu0: memory model: Shareability-Levels=1, Auxiliary-Registers=2
cpu0: memory model: Innermost-Shareability=1, Branch-Predictor=2
cpu0: memory model: Unified-TLB=4, Mem-Barrier=2, WFI-Stall=1
cpu0: memory model: Cache-Maintenance-MVA=1, Cache-Maintenance-Set/Way=1
cpu0: memory model: BP-Maintenance=2, Maintenance-Broadcast=2
cpu0: memory model: Coherent-Tablewalk=1, Cached-Memory-Size=2
cpu0: processor features: ThumbEE=1, Jazelle=3, Thumb=1, ARM=1, Programmer=1
cpu0: processor features: Security=0, M-profile=0, Virtualization=0
cpu0: processor features: Generic-Timer=1
cpu0: media and VFP features: ASIMD-Registers=2, Single-Precision=2
cpu0: media and VFP features: Double-Precision=2, Divide=1, Square-Root=1
cpu0: media and VFP features: VFP-Rounding-Modes=1, Flush-To-Zero=1
cpu0: media and VFP features: Default-NaN=1, ASIMD-Load/Store=1
cpu0: media and VFP features: ASIMD-Integer=1, ASIMD-SPFP=1, ASIMD-HPFP=1
cpu0: media and VFP features: VFP-HPFP=1, ASIMD-FMAC=1
armv7# uname -a
NetBSD armv7 10.0 NetBSD 10.0 (GENERIC) #0: Thu Mar 28 08:33:33 UTC 2024  [email protected]:/usr/src/sys/arch/evbarm/compile/GENERIC evbarm

If I replace that section of code to output the older style cmp / beq instructions as per armv6 above everything compiles.

  1. At this point running the test suite yields 4 failing tests.
List of unexpected errors:
    tests/lib-dynlink-pr4839/'test.ml' with 1.2.2.17 (ocamlopt.byte) 
    tests/lib-dynlink-pr4839/'test.ml' with 1.2.2.5 (ocamlopt.byte) 
    tests/lib-systhreads/'testyield.ml' with 1.1.1 (bytecode) 
    tests/lib-dynlink-pr4839/'test.ml' with 1.2.2.11 (ocamlopt.byte) 

Summary:
  2519 tests passed
   43 tests skipped
  414 tests failed
  161 tests not started (parent test skipped or failed)
    4 unexpected errors
  3141 tests considered

Can you provide more details on the physical hardware being used? And try replicating this using a checkout of https://github.com/ocaml/ocaml/tree/4.14

@VoxSciurorum
Copy link
Author

The sak.c compile error is fixed in 284244a and f54b3ac. The fix needs to be backported to support recent NetBSD in 4.14.

I am running on an Allwinner A83T, 8 Cortex A-7 cores. These should be ISA compatible with A-15 because some systems put both in the same SOC. If I assemble "cbz r1,1f" I get the same error as you. I will try to figure out why we are seeing different code generation.

@VoxSciurorum
Copy link
Author

My system (hardware, NetBSD 10) assembles arm.S with defines -DSYS_netbsd -DMODEL_armv7. Your system (qemu, NetBSD 9) uses -DSYS_unknown -DMODEL_default. I will try with qemu tomorrow to see why there is a difference.

@VoxSciurorum
Copy link
Author

Running NetBSD 9.4 under qemu I find the expected variables in Makefile.config

ARCH=arm
MODEL=armv7
TARGET=armv7-unknown-netbsdelf9.4-eabihf
HOST=armv7-unknown-netbsdelf9.4-eabihf
SYSTEM=netbsd

The compile command gcc -c -DSYS_netbsd -I../runtime -DMODEL_armv7 -o arm.o arm.S does not report an error. There is no difference in MODEL or SYSTEM between A7 and A15 emulated CPU.

I regenerated configure with autoconf 2.71. The original in git was generated with autoconf 2.69. My base git hash is fdffa5c.

@tmcgilchrist
Copy link
Contributor

tmcgilchrist commented May 12, 2024

With a bit more testing over the weekend I can get the right variables in Makefile.config.

ARCH=arm
MODEL=armv7
TARGET=armv7-unknown-netbsdelf10.0-eabihf
HOST=armv7-unknown-netbsdelf10.0-eabihf
SYSTEM=netbsd

My changes are on https://github.com/tmcgilchrist/ocaml/tree/netbsd-arm-fixes. Running make tests I get the expected sys threads error plus the dynlink errors as before. Fixed the dynlink tests, caused by a misconfigured NetBSD user on my side, apologies for the noise.

The assembler error is no longer present and was likely due to my error with configuration.

@VoxSciurorum
Copy link
Author

I tested the branch netbsd-arm-fixes on NetBSD 10.0 with real hardware and got the expected results – native code passes tests except testyield.ml which also fails with the bytecode compiler.

@shindere
Copy link
Contributor

shindere commented May 29, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants