arduino/arduino101load

`bsdthread_register` / `segmentation fault` error when release build executed on modern macOS

per1234 opened this issue ยท 5 comments

Describe the problem

The binaries provided as release assets in this repository fail with a bsdthread_register or segmentation fault error when used on a machine running a recent version of macOS.

This is apparently caused by the vintage version of Go used to generate the build:

https://github.com/golang/go/wiki/MacOS12BSDThreadRegisterIssue

To reproduce

Download the binary from the release asset and attempt to execute it on a machine running a recent version of macOS.

% sw_vers
ProductName:            macOS
ProductVersion:         13.2
BuildVersion:           22D49

% mkdir /tmp/arduino101load-demo

% cd /tmp/arduino101load-demo

% curl --location --output arduino101load-2.0.1-darwin_amd64.tar.bz2 https://github.com/facchinm/arduino101load/releases/download/2.0.1/arduino101load-2.0.1-darwin_amd64.tar.bz2
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 1033k  100 1033k    0     0   517k      0  0:00:01  0:00:01 --:--:--  989k

% tar -xf arduino101load-2.0.1-darwin_amd64.tar.bz2

% bin/arduino101load --help
zsh: segmentation fault  bin/arduino101load --help

๐Ÿ› The valid invocation errored.

Expected behavior

Builds are available for the users of modern macOS machines.

Proposed solution

Convert the project to a Go module and build with a recent version of Go.

The produced binary works as expected:

% git clone --depth 1 https://github.com/facchinm/arduino101load
Cloning into 'arduino101load'...
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 18 (delta 2), reused 12 (delta 1), pack-reused 0
Receiving objects: 100% (18/18), 198.18 KiB | 622.00 KiB/s, done.
Resolving deltas: 100% (2/2), done.

% cd arduino101load

% go version
go version go1.19.5 darwin/amd64

% go mod init github.com/facchinm/arduino101load
go: creating new go.mod: module github.com/facchinm/arduino101load
go: to add module requirements and sums:
        go mod tidy

% go mod tidy
go: finding module for package github.com/mattn/go-shellwords
go: downloading github.com/mattn/go-shellwords v1.0.12
go: found github.com/mattn/go-shellwords in github.com/mattn/go-shellwords v1.0.12

% go build

% ./arduino101load --help
Usage of ./arduino101load:
  -bin string
        Location of sketch binary
  -ble_fw_pos int
        BLE FW ID offset
  -ble_fw_str string
        BLE FW ID string
  -c    Copy bin_file to bin_save
  -core string
        Firmware location
  -dfu string
        Location of dfu-util binaries
  -f    Force firmware update
  -from string
        Original file location
  -port string
        Upload serial port
  -q    Show quiet logging (default true)
  -rtos_fw_pos int
        RTOS FW ID offset
  -rtos_fw_str string
        RTOS FW ID string
  -to string
        Save file location
  -v    Show verbose logging

For the sake of simplicity, the above was done on the macOS machine, but the binary produced by cross compiling per the instructions in the readme works just as well, so there is no difficulty in producing the builds.

Additional context

The above demo was on an Apple Silicon-based Mac machine running the Rosetta 2 interpreter because that is the only machine I have access to, but the same problem also occur on an x86 Mac, as reported by users of the Arduino 101 board:

On the x86 machine, the error message is a bit more verbose:

/Users/x-user/Library/Arduino15/packages/Intel/tools/arduino101load/2.0.1/arduino101load -c "-from=\"/private/var/folders/dl/cdjfr_wx1lv48vd5mzr4klj80000gp/T/arduino-sketch-5CEDF04D633012E523AC2E5C948FE18F/Blink.ino.elf\"" "-to=\"/private/var/folders/dl/cdjfr_wx1lv48vd5mzr4klj80000gp/T/arduino-sketch-5CEDF04D633012E523AC2E5C948FE18F/../arduino101_sketch.debug.elf\""

runtime stack:
runtime.throw(0x1122f8, 0x21)
	/ssd/go/src/runtime/panic.go:566 +0x95 fp=0x7ff7bfeff5c0 sp=0x7ff7bfeff5a0
runtime.goenvs()
	/ssd/go/src/runtime/os_darwin.go:88 +0xa0 fp=0x7ff7bfeff5f0 sp=0x7ff7bfeff5c0
runtime.schedinit()
	/ssd/go/src/runtime/proc.go:450 +0x9c fp=0x7ff7bfeff630 sp=0x7ff7bfeff5f0
runtime.rt0_go(0x7ff7bfeff660, 0x4, 0x7ff7bfeff660, 0x1000, 0x4, 0x7ff7bfeff810, 0x7ff7bfeff86c, 0x7ff7bfeff86f, 0x7ff7bfeff8ee, 0x0, ...)
	/ssd/go/src/runtime/asm_amd64.s:145 +0x14f fp=0x7ff7bfeff638 sp=0x7ff7bfeff630

exit status 2

Compilation error: exit status 2}

I think we should be moving this repo under arduino umbrella (I forgot it was still here ๐Ÿ˜… ) and kindly asking @MatteoPologruto to perform the builds in the "modern" way.

Hi @facchinm, we'll do that, but after the repo is moved under the Arduino org. Could you please take care of this?

Activities

  • Move under arduino
  • Put in place the Release CI
  • Make a release using a recent version of go
  • Publish it on the index
  • Publish new core

Probably a release of the core is not required because we do not specify the version of the tool in the core's platform.txt
But we do in the index https://github.com/bcmi-labs/package_index/blob/master/package_index.json#L13816

Moved to arduino org

Resolved by #4 and the 2.3.0 release. Thanks to everyone who helped make this happen!