Illegal operations on a Raspberry Pi Zero W (ARMv6)
Describe the bug Using a Raspberry pi zero (armv6) most commands will fail with "Illegal instruction" and terminate.
To Reproduce
- Running latest pyarmor from pip using the trial version on a Raspberry Pi Zero W running Raspbian 10 (buster) and python 3.7.3
- Commands used obfuscate, pack, download, hdinfo and -v
- Manually downloading armv6.0 and replacing the .3 version works Output from trying to obfuscate main.py
pyarmor -d obfuscate main.py
DEBUG PyArmor installation path: /home/pi/.local/lib/python3.7/site-packages/pyarmor
DEBUG PyArmor home path: /home/pi/.pyarmor
DEBUG Native platform is linux.armv6
DEBUG Search dynamic library in the path: /home/pi/.local/lib/python3.7/site-packages/pyarmor/platforms
DEBUG Search dynamic library in the path: /home/pi/.pyarmor/platforms
DEBUG Found available dynamic library linux/armv6/3
Illegal instruction
Additional context Tested on a Windows machine and had no problem running the pack option with our .spec file
I seems there is something wrong with linux.armv6.3, I'll check it.
Since linux.armv6.0 works, now use it by exporting environment variable PYARMOR_PLATFORM=linux.armv6.0
I rebuild linux.armv6.3, it may fix this issue, it has been packaged into the dev version
https://pyarmor.readthedocs.io/en/latest/change-logs.html#dev-version
For trial version, after v6.6.2, the latest extra platforms are not available to download.
I have uploaded the temporary one to https://pyarmor.dashingsoft.com/downloads/temp/_pytrasnform.so
Download it, then save it to /home/pi/.local/lib/python3.7/site-packages/pyarmor/platforms/linux/armv6
I'm afraid it didn't work. We tested it on 2 Pi Zeros following your instructions and we still got "Illegal instruction"
First make sure it's the latest one is loaded, run pyarmor -d obfuscate foo.py, the output log will print which _pytrasnfrom.so is loaded.
And check this file by ldd
ldd /home/pi/.local/lib/python3.7/site-packages/pyarmor/platforms/linux/armv6/_pytransform.so
What's the output of uname -a?
Obfuscate output :
pi@raspberrypi:~/PerkinElmer/Source $ pyarmor -d obfuscate main.py
DEBUG PyArmor installation path: /home/pi/.local/lib/python3.7/site-packages/pyarmor
DEBUG PyArmor home path: /home/pi/.pyarmor
DEBUG Native platform is linux.armv6
DEBUG Search dynamic library in the path: /home/pi/.local/lib/python3.7/site-packages/pyarmor/platforms
Illegal instruction
ldd output:
pi@raspberrypi:~/PerkinElmer/Source $ ldd /home/pi/.local/lib/python3.7/site-packages/pyarmor/platforms/linux/armv6/_pytransform.so
/usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so => /usr/lib/arm-linux-gnueabihf/libarmmem-v6l.so (0xb6d69000)
libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6c02000)
/lib/ld-linux-armhf.so.3 (0xb6f94000)
uname:
pi@raspberrypi:~/PerkinElmer/Source $ uname -a
Linux raspberrypi 5.10.20+ #1404 Thu Mar 4 19:36:44 GMT 2021 armv6l GNU/Linux
@shedstrom I uploaded 2 apps to print some debug information https://pyarmor.dashingsoft.com/downloads/temp/foo-arm-mode https://pyarmor.dashingsoft.com/downloads/temp/foo-thumb-mode
Could you test them in Pi zero? check them work or not.
Here is the output from both:
pi@raspberrypi:~ $ ./foo-arm-mode
carmor_set_key_iv at 0x0x91fc
Illegal instruction
pi@raspberrypi:~ $ ./foo-thumb-mode
carmor_set_key_iv at 0x0x91fc
Illegal instruction
How about these 2 files, they're compiled by another cross-compile tool? https://pyarmor.dashingsoft.com/downloads/temp/foo2a https://pyarmor.dashingsoft.com/downloads/temp/foo2t
Output:
pi@raspberrypi:~ $ ./foo2t
carmor_set_key_iv at 0x0x11000
Illegal instruction
pi@raspberrypi:~ $ ./foo2a
carmor_set_key_iv at 0x0x11000
Illegal instruction
What's COLLECT_GCC_OPTIONS in this platform? This is what I used to build dynamic library
$ echo "" > a.c
$ toolchain/bin/arm-buildroot-linux-gnueabihf-gcc --verbose -shared a.c
...
COLLECT_GCC_OPTIONS='-v' '-shared' '-mcpu=arm1176jzf-s' '-mfloat-abi=hard' '-mfpu=vfp' '-mabi=aapcs-linux' '-marm' '-mtls-dialect=gnu' '-march=armv6kz+fp'
This is what I get:
COLLECT_GCC_OPTIONS='-v' '-shared' '-mfloat-abi=hard' '-mfpu=vfp' '-mtls-dialect=gnu' '-marm' '-march=armv6+fp'
Does this work? https://pyarmor.dashingsoft.com/downloads/temp/foo-armv6
It's built with extra cflags -march=armv6, not the default -march=armv6kz
If it works, also try this new linux.armv6.3
https://pyarmor.dashingsoft.com/downloads/temp/_pytrasnform.so
Download it, then save it to /home/pi/.local/lib/python3.7/site-packages/pyarmor/platforms/linux/armv6
Does this work? https://pyarmor.dashingsoft.com/downloads/temp/foo-armv6
I'm afraid that it did not work
It's a little difficult to fix it, because I can't reproduce this issue by qemu, the test app foo works in my test vm qemu-system-arm -M raspi0 with linux kernel 4.2.0 built as bcm2835_defconfig
So the current solution is linux.armv6.0
Okay, will update my scripts to use armv6.0.
Do you think its possible for you to test on a qemu with a kernel that is 5.x?
I think it could not help for this issue.
I rebuild
linux.armv6.3, it may fix this issue, it has been packaged into the dev version https://pyarmor.readthedocs.io/en/latest/change-logs.html#dev-version
I seems there is something wrong with
linux.armv6.3, I'll check it.Since
linux.armv6.0works, now use it by exporting environment variablePYARMOR_PLATFORM=linux.armv6.0
after exporting env variable as linux.armv6.0 i am getting [error 21] is a directory