'GOARCH=arm64 GOOS=linux go build examples/record.go' fails
doesnotexist opened this issue · comments
I'm running into an issue with the example/record.go, which works fine if I build it with GOARCH=arm but fails if I build with GOARCH=arm64. Specifically it fails at this ioctl: https://github.com/thinkski/go-v4l2/blob/master/examples/record.go#L43
Unfortunately I want to use some other native cgo modules (for example https://github.com/gen2brain/malgo) whose symbols will not resolve if I use GOARCH=arm only if I use GOARCH=arm64, so currently this library and the others are incompatible to use together. Any idea why this is failing?
I did use this library recently in arm64 altough I went back to arm since it has better compatibility on the Raspberry Pi. I didn't run into this issue, however I suspect the error has to do with diffrent u_long/u_longlong definitions. I recently adapted a diffrent library to switch appropriatly which is rather easy,
Unfortunatly I feel like this library is not maintained as there were no commits the last 2 years. However if possible I would like to help you out.
Could you post your error message?
Thanks. I've got a WIP patch to fix the issue. The issue is due to different width of types like you mentioned. As a result the hardcoded ioctl request values are incorrect for arm64. For example, for 32 bit arm the hardcoded constant VIDIOC_S_FMT = 0xc0cc5605 is correct but incorrect for arm64 where the correct value is 0xc0d05605. The difference is the 0xCC and 0xD0 is the sizeof(struct v4l2_format).
This surprised me since it seemed such values would be the same across binaries running against the same kernel, and I'm running raspian with aarch64 (arm64) kernel, but it turns out there is a 32-bit compatibility translation for syscalls on a 64-bit kernel. https://github.com/torvalds/linux/blob/master/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
Applying this patch works for my simplified examples/record.go :
https://gist.github.com/doesnotexist/45e90067639d844cda83b3ff734d926e
Will turn into a PR once I figure out how to define constants based on GOOS/GOARCH combination
You can just put the definition in different files with build tags and name them the same.
Also I dont know if your PR will be viewed 😅
I should really turn on notifications so I catch threads like this earlier. Regardless, thank you for the PR -- glad you figured it out.