ARMv6z Build error 0n 1.10.0

Linux specific questions.
Post Reply
pidd
Posts: 31
Joined: Nov 11, 2022 16:27

ARMv6z Build error 0n 1.10.0

Post by pidd »

Using Raspberry Pi Zero 32-bit

If I build latest 1.10.0 freebasic using an old stw built version of freebasic it works fine (even using a very recent stw version at 1.10).

If I then build using the latest build I get "illegal instruction" error when running "fbc --version"

Takes 50 minutes to build on a Pi Zero :lol:

Everything works fine for Pi 4B 64 bit ARMv8-A
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: ARMv6z Build error 0n 1.10.0

Post by coderJeff »

Maybe the build options are changed somehow, either in the makefile, or fbc itself. Or Maybe stW overrides with v6?

Each version / build of fbc is calling gcc, as, ld to compile and link programs.
Maybe you can check what is being passed to each program
- verbose make: 'make V=1 ....'
- verbose fbc: 'fbc -v ...'

I believe fbc uses armv7 as default for 32-bit
I believe fbc uses armv8 as default for 64-bit

I build fbc on real pi3 (32-bit) & real pi4 (64-bit), then rebuild fbc again, and then run the full test-suite and it all passes for me.
pidd
Posts: 31
Joined: Nov 11, 2022 16:27

Re: ARMv6z Build error 0n 1.10.0

Post by pidd »

Yes, the same happened when I accidentally used a ARMv7 stw build so it is possibly defaulting to v7.

Its a long time since I've done anything low-ish level on the Pi zero's, they normally do a load of stats for fbc programs I'm developing, In a moment of madness I decided to build fbc on them the same as I do on the Pi4.

I might just stick to the stw builds, 50 minutes is a bit painful.

I'll see what the make verbose does, the fbc verbose shows nothing extra.
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: ARMv6z Build error 0n 1.10.0

Post by coderJeff »

pidd wrote: Feb 20, 2023 15:31 I'll see what the make verbose does, the fbc verbose shows nothing extra.
Example 'fbc -v a.bas':

Code: Select all

jeff@raspberrypi3:~ $ echo print > a.bas
jeff@raspberrypi3:~ $ fbc -v a.bas
FreeBASIC Compiler - Version 1.10.0 (2023-01-22), built for linux-arm (32bit)
Copyright (C) 2004-2023 The FreeBASIC development team.
target:       linux-arm, armv7-a, 32bit
backend:      gcc
compiling:    a.bas -o a.c (main module)
compiling C:  gcc -march=armv7-a -S -nostdlib -nostdinc -Wall -Wno-unused -Wno-main -Werror-implicit-function-declaration -O0 -fno-strict-aliasing -frounding-math -fno-math-errno -fwrapv -fno-exceptions -fno-asynchronous-unwind-tables -fno-unwind-tables -Wno-format "a.c" -o "a.asm"
assembling:   as --strip-local-absolute "a.asm" -o "a.o"
linking:      ld -m armelf_linux_eabi -o "a" -dynamic-linker /lib/ld-linux-armhf.so.3 -T "/usr/local/bin/../lib/freebasic/linux-arm/fbextra.x" -L "/usr/local/bin/../lib/freebasic/linux-arm" -L "." -L "/usr/lib/gcc/arm-linux-gnueabihf/10" "/usr/lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/crt1.o" "/usr/lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/crti.o" "/usr/lib/gcc/arm-linux-gnueabihf/10/crtbegin.o" "/usr/local/bin/../lib/freebasic/linux-arm/fbrt0.o" "a.o" "-(" -lfb -ltinfo -lm -ldl -lpthread -lgcc -lgcc_eh -lc "-)" "/usr/lib/gcc/arm-linux-gnueabihf/10/crtend.o" "/usr/lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/crtn.o"
To compile arm v6: pass 'fbc -arch armv6 ...' as compile option.
pidd
Posts: 31
Joined: Nov 11, 2022 16:27

Re: ARMv6z Build error 0n 1.10.0

Post by pidd »

Yes, thanks ...

Code: Select all

FreeBASIC Compiler - Version 1.10.0 (2023-02-20), built for linux-arm (32bit)
Copyright (C) 2004-2023 The FreeBASIC development team.
target:       linux-arm, armv7-a, 32bit
backend:      gcc
Whereas stw gives

Code: Select all

FreeBASIC Compiler - Version 1.10.0 (2022-06-24), built for linux-arm (32bit)
Copyright (C) 2004-2022 The FreeBASIC development team.
target:       linux-arm, armv6, 32bit
backend:      gcc
Just about to start it off with the arch armv6 option. Gettting myself a bit muddled with the stw, first build and second build versions .... I need some chocolate lol

I thought gcc/ar would just pick up system defaults - in my usual naive way
pidd
Posts: 31
Joined: Nov 11, 2022 16:27

Re: ARMv6z Build error 0n 1.10.0

Post by pidd »

Failed miserably, I tried ...

Code: Select all

make -B TARGET_CPU=armv6

but of course make install used the old linux-arm directory instead of the linux-armv6 directory. I guess I could copy them in manually but piecemeal fixes have a habit of biting.

Why is fighting systems and tools always ten times more difficult than writing programs.
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: ARMv6z Build error 0n 1.10.0

Post by coderJeff »

pidd wrote: Feb 20, 2023 20:46

Code: Select all

make -B TARGET_CPU=armv6
Is this an old makefile or some other version of fbc's makefile? 'TARGET_CPU' is not an option in fbc's current makefile.
arm arch targets were added in 2014 with armv7a as the default and armv7a has been the default on fbc/master since fbc version 1.00. If your fbc defaults to armv6 then it is older or has been patched.

The issue with the build tools and armv7a versus armv6 is that it is really two different targets and can be considered a kind of cross compilation. So depending on the versions of build tools you are running, the system you are running on, and the target desired will affect the understanding and success.

When fbc is being used to compile, then need to tell fbc to target '-arch arm6' because default is '-arch armv7a'
When gcc is being used to compile (i.e. makefile to build run time libraries), then need to tell gcc to target '-march=armv6' because gcc on the system may target armv7a by default.

I can help you with the makefile arguments to force a particular target, but will be helpful to know what you are starting with, what system you are building on, and where you want to run the resulting programs.
pidd
Posts: 31
Joined: Nov 11, 2022 16:27

Re: ARMv6z Build error 0n 1.10.0

Post by pidd »

I am aware that stw said he was considering updating his build system and that he'd had major problems with some of the cross-compiling in the past. I was hoping to build the armv6 independently in case he doesn't continue. FBC reports as "linux-arm, armv6, 32bit" on stw's builds for the Pi Zero. Its been so easy on the Pi4, I didn't anticipate any problems with the Pi Zero's

Things are further complicated with the Pi Zero because Raspberry use armhf as the target to compile everything, but the Pi Zero isn't an armhf and its not armel either. The Pi Zero even updates from debian's armhf repositories yet armhf is arm7 and the Pi zero is armv6. I can't understand that.

I'm not sure where I got TARGET_CPU from now, whatever I used definitely compiled and produced the Linux-armv6 directory. Perhaps I actually used TARGET_ARCH, my memory isn't very good, I vaguely remember getting the command line wrong the first time and making a quick change which obviously wasn't impaled sufficiently in my memory banks.

As I compiling on the Pi Zero, gcc does default to the correct device.

TBH I've deleted most of what I was doing because I had got in a mess, so I've just installed the stw builds again for the moment. I've got a silly amount of personal stuff going on at the moment and I need to wait until I can get more focused.

Thanks very much for your offer of help, I'll probably get back to you in a month or two.
St_W
Posts: 1619
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: ARMv6z Build error 0n 1.10.0

Post by St_W »

Hi, if you were wondering about the ARMv6 default in my "linux-armv6-rpi" builds from https://users.freebasic-portal.de/stw/b ... armv6-rpi/ they indeed use a single-line patch for fb.bi as explained in the introduction post back then viewtopic.php?p=205446#p205446.

As the original Raspberry Pi hardware is only capable of the ARMv6 instruction set I patched the following line to use ARMv6 by default in that build:
https://github.com/freebasic/fbc/blob/m ... fb.bi#L412

Code: Select all

sed -i 's/const\s\+FB_DEFAULT_CPUTYPE_ARM\s*=.*/const FB_DEFAULT_CPUTYPE_ARM = FB_CPUTYPE_ARMV6/i' src/compiler/fb.bi
According to https://en.wikipedia.org/wiki/Raspberry ... ifications the original Pi Zero models also use the ARMv6 instruction set, so you either need to pass `-arch armv6` to fbc or patch fb.bi as I did to get a working binary for that platform.
pidd
Posts: 31
Joined: Nov 11, 2022 16:27

Re: ARMv6z Build error 0n 1.10.0

Post by pidd »

St_W wrote: Mar 14, 2023 16:23 Hi, if you were wondering about the ARMv6 default in my "linux-armv6-rpi" builds from https://users.freebasic-portal.de/stw/b ... armv6-rpi/ they indeed use a single-line patch for fb.bi as explained in the introduction post back then viewtopic.php?p=205446#p205446.

As the original Raspberry Pi hardware is only capable of the ARMv6 instruction set I patched the following line to use ARMv6 by default in that build:
https://github.com/freebasic/fbc/blob/m ... fb.bi#L412

Code: Select all

sed -i 's/const\s\+FB_DEFAULT_CPUTYPE_ARM\s*=.*/const FB_DEFAULT_CPUTYPE_ARM = FB_CPUTYPE_ARMV6/i' src/compiler/fb.bi
According to https://en.wikipedia.org/wiki/Raspberry ... ifications the original Pi Zero models also use the ARMv6 instruction set, so you either need to pass `-arch armv6` to fbc or patch fb.bi as I did to get a working binary for that platform.
Thanks for that info!
Post Reply