tinygo-org / tinygo

Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
https://tinygo.org
Other
15.45k stars 911 forks source link

Build Error on Ubuntu #2685

Closed charles-d-burton closed 2 years ago

charles-d-burton commented 2 years ago

Installed using the .deb package for ubuntu. I'm getting the following permissions error, it's easy enough to fix, just posting this here because I think the .deb needs the permissions updated

❯ tinygo build -target pico -o test.u2f
tinygo:ld.lld: error: cannot open /usr/local/lib/tinygo/pkg/thumbv6m-unknown-unknown-eabi-cortex-m0plus/compiler-rt/lib.a: Permission denied
tinygo:ld.lld: error: cannot open /usr/local/lib/tinygo/pkg/thumbv6m-unknown-unknown-eabi-cortex-m0plus/picolibc/lib.a: Permission denied
failed to run tool: ld.lld
error: failed to link /tmp/tinygo157798778/main: exit status 1
❯ tinygo version
tinygo version 0.22.0 linux/amd64 (using go version go1.17.7 and LLVM version 13.0.0)

The permissions on those files are set to read by root onlY

❯ ls -l /usr/local/lib/tinygo/pkg/thumbv6m-unknown-unknown-eabi-cortex-m0plus/picolibc/lib.a
-rw------- 1 root root 705066 Jan 25 19:00 /usr/local/lib/tinygo/pkg/thumbv6m-unknown-unknown-eabi-cortex-m0plus/picolibc/lib.a
charles-d-burton commented 2 years ago

I fixed it locally with the following command

❯ sudo find /usr/local/lib/tinygo/pkg/ -type f | sudo xargs chmod 644
❯ tinygo build -target pico -o test.u2f
dankegel commented 2 years ago

Confirming present in 0.21 and 0.22 (but not in 0.20, which didn't contain those files):

$ wget https://github.com/tinygo-org/tinygo/releases/download/v0.22.0/tinygo_0.22.0_amd64.deb
$ ar x tinygo_0.22.0_amd64.deb 
$ tar tvf data.tar.gz | grep ".-----"
-rw------- 0/0          401872 2021-11-18 05:31 ./usr/local/lib/tinygo/pkg/armv6m-unknown-unknown-eabi/compiler-rt/lib.a
drwx------ 0/0               0 2021-11-18 05:31 ./usr/local/lib/tinygo/pkg/armv6m-unknown-unknown-eabi/picolibc/include/
-rw------- 0/0          764890 2021-11-18 05:31 ./usr/local/lib/tinygo/pkg/armv6m-unknown-unknown-eabi/picolibc/lib.a
-rw------- 0/0          387320 2021-11-18 05:31 ./usr/local/lib/tinygo/pkg/armv7em-unknown-unknown-eabi/compiler-rt/lib.a
drwx------ 0/0               0 2021-11-18 05:31 ./usr/local/lib/tinygo/pkg/armv7em-unknown-unknown-eabi/picolibc/include/
-rw------- 0/0          744574 2021-11-18 05:31 ./usr/local/lib/tinygo/pkg/armv7em-unknown-unknown-eabi/picolibc/lib.a
-rw------- 0/0          387376 2021-11-18 05:31 ./usr/local/lib/tinygo/pkg/armv7m-unknown-unknown-eabi/compiler-rt/lib.a
drwx------ 0/0               0 2021-11-18 05:31 ./usr/local/lib/tinygo/pkg/armv7m-unknown-unknown-eabi/picolibc/include/
-rw------- 0/0          744050 2021-11-18 05:31 ./usr/local/lib/tinygo/pkg/armv7m-unknown-unknown-eabi/picolibc/lib.a
dankegel commented 2 years ago

Fun fact: mac ar cannot deal with those debs because they mistakenly have a slash after the filenames. Might be an fpm issue...

dankegel commented 2 years ago

Looks like original sin is committed by tinygo itself?

$ umask
0002
$ strace -o slog -e trace=file -f ./build/tinygo build-library -target=cortex-m4     -o build/release/tinygo/pkg/thumbv7em-unknown-unknown-eabi-cortex-m4/picolibc    picolibc
...
88138 mkdirat(AT_FDCWD, "build/release/tinygo/pkg/thumbv7em-unknown-unknown-eabi-cortex-m4/picolibc", 0775) = 0
...
88138 mkdirat(AT_FDCWD, "build/release/tinygo/pkg/thumbv7em-unknown-unknown-eabi-cortex-m4/picolibc/include", 0700) = 0

Somehow "tinygo build-library" is using the wrong permissions when creating that include directory?

aykevl commented 2 years ago

So it appears that the underlying cause is that we use os.TempFile files which are created with very restricted permissions and we simply copy those files with the same permissions. I think we should loosen up those permissions a bit.