tinygo-org / tinygo

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

tinygo build cache sometimes stale #3281

Open hollowaykeanho opened 1 year ago

hollowaykeanho commented 1 year ago

Hi team! Is the following a bug?

While developing a TinyGo friendly standard library, I encountered these errors when attempting to re-use standard library's math package, which was marked usable and tested in the documentation (see screenshot below):

screenshot-2022-11-10-09-20-52

tinygo:ld.lld: error: undefined symbol: log
>>> referenced by log.go:81 (/home/u0/Documents/zoralab/Hestia/.monteurFS/bin/golang/src/math/log.go:81)
>>>               /home/u0/.cache/tinygo/thinlto/llvmcache-7AEE18076F98FE7D131EDF8E8D934891C3E6B0C2:(hestia/hestiaSTRING.Test_S64_ParseFLOAT64$1)

tinygo:ld.lld: error: undefined symbol: floor
>>> referenced by floor.go:14 (/home/u0/Documents/zoralab/Hestia/.monteurFS/bin/golang/src/math/floor.go:14)
>>>               /home/u0/.cache/tinygo/thinlto/llvmcache-7AEE18076F98FE7D131EDF8E8D934891C3E6B0C2:(hestia/hestiaSTRING.Test_S64_ParseFLOAT64$1)
failed to run tool: ld.lld

Issue is not seen on standard Go compiler.

Site-note: No worries. I'm planning to adopt+modify standard library math package into my library that is friendly to TinyGo and Rust. The only disruption is schedule.

hollowaykeanho commented 1 year ago

Issue confirmed caused by https://github.com/tinygo-org/tinygo/issues/3282 as TinyGo cannot see the assembly codes. Question answered. Further clarifications is in ticket 3282.

aykevl commented 1 year ago

Which target is this? Because the math package should be supported on all platforms (except AVR but that one has bigger problems).

hollowaykeanho commented 1 year ago

amd64. Command issued was tinygo test . inside a string processing package.


EDIT:

By the way, don't pressure yourself. I just managed to developed the function successfully here: https://github.com/ZORALab/Hestia/commit/6f9f26c76c938f297f74e2ac0ef9a330f32fbd24

Still working on (and pathfinding) multi-arch package structuring for the repository. At the moment, I'm developing the Rust's Format/ Go's Sprintf function without reflection here: https://github.com/ZORALab/Hestia/tree/experimental/hestiaGO/hestiaSTRING

As far as from my side, it's considered completed and tested working. I just want to make sure both TinyGo and Go moving in the same direction. For what I know, embedded has a lot of asm codes (easier to develop as well). Already querying from Std team Go: https://groups.google.com/g/golang-nuts/c/_anP6F0iPDM

Cheers!

aykevl commented 1 year ago

Can you try running tinygo test math? It passes for me. Also, please share tinygo version.

hollowaykeanho commented 1 year ago

Failed on my side:

u0:hestiaSTRING$ tinygo test math
tinygo:ld.lld: error: undefined symbol: log
>>> referenced by log.go:81 (/home/u0/Documents/zoralab/Hestia/.monteurFS/bin/golang/src/math/log.go:81)
>>>               /home/u0/.cache/tinygo/thinlto/llvmcache-2CEFCC256783054285B8EA72C5BF6AB1E037B087:(math.Acosh)
>>> referenced by log.go:81 (/home/u0/Documents/zoralab/Hestia/.monteurFS/bin/golang/src/math/log.go:81)
>>>               /home/u0/.cache/tinygo/thinlto/llvmcache-2CEFCC256783054285B8EA72C5BF6AB1E037B087:(math.Acosh)
>>> referenced by log.go:81 (/home/u0/Documents/zoralab/Hestia/.monteurFS/bin/golang/src/math/log.go:81)
>>>               /home/u0/.cache/tinygo/thinlto/llvmcache-2CEFCC256783054285B8EA72C5BF6AB1E037B087:(math.Asinh)
>>> referenced 17 more times

tinygo:ld.lld: error: undefined symbol: exp
>>> referenced by exp.go:16 (/home/u0/Documents/zoralab/Hestia/.monteurFS/bin/golang/src/math/exp.go:16)
>>>               /home/u0/.cache/tinygo/thinlto/llvmcache-2CEFCC256783054285B8EA72C5BF6AB1E037B087:(math.Erf)
>>> referenced by exp.go:16 (/home/u0/Documents/zoralab/Hestia/.monteurFS/bin/golang/src/math/exp.go:16)
>>>               /home/u0/.cache/tinygo/thinlto/llvmcache-2CEFCC256783054285B8EA72C5BF6AB1E037B087:(math.Erf)
>>> referenced by exp.go:16 (/home/u0/Documents/zoralab/Hestia/.monteurFS/bin/golang/src/math/exp.go:16)
>>>               /home/u0/.cache/tinygo/thinlto/llvmcache-2CEFCC256783054285B8EA72C5BF6AB1E037B087:(math.Exp)
>>> referenced 9 more times

tinygo:ld.lld: error: undefined symbol: exp2
>>> referenced by exp.go:142 (/home/u0/Documents/zoralab/Hestia/.monteurFS/bin/golang/src/math/exp.go:142)
>>>               /home/u0/.cache/tinygo/thinlto/llvmcache-2CEFCC256783054285B8EA72C5BF6AB1E037B087:(math.Exp2)

tinygo:ld.lld: error: undefined symbol: floor
>>> referenced by floor.go:14 (/home/u0/Documents/zoralab/Hestia/.monteurFS/bin/golang/src/math/floor.go:14)
>>>               /home/u0/.cache/tinygo/thinlto/llvmcache-2CEFCC256783054285B8EA72C5BF6AB1E037B087:(math.Gamma)
>>> referenced by floor.go:14 (/home/u0/Documents/zoralab/Hestia/.monteurFS/bin/golang/src/math/floor.go:14)
>>>               /home/u0/.cache/tinygo/thinlto/llvmcache-2CEFCC256783054285B8EA72C5BF6AB1E037B087:(math.Lgamma)
>>> referenced by floor.go:14 (/home/u0/Documents/zoralab/Hestia/.monteurFS/bin/golang/src/math/floor.go:14)
>>>               /home/u0/.cache/tinygo/thinlto/llvmcache-2CEFCC256783054285B8EA72C5BF6AB1E037B087:(math_test.TestFloor)
>>> referenced 1 more times

tinygo:ld.lld: error: undefined symbol: ceil
>>> referenced by floor.go:43 (/home/u0/Documents/zoralab/Hestia/.monteurFS/bin/golang/src/math/floor.go:43)
>>>               /home/u0/.cache/tinygo/thinlto/llvmcache-2CEFCC256783054285B8EA72C5BF6AB1E037B087:(math_test.TestCeil)
>>> referenced by floor.go:43 (/home/u0/Documents/zoralab/Hestia/.monteurFS/bin/golang/src/math/floor.go:43)
>>>               /home/u0/.cache/tinygo/thinlto/llvmcache-2CEFCC256783054285B8EA72C5BF6AB1E037B087:(math_test.TestCeil)

tinygo:ld.lld: error: undefined symbol: trunc
>>> referenced by floor.go:61 (/home/u0/Documents/zoralab/Hestia/.monteurFS/bin/golang/src/math/floor.go:61)
>>>               /home/u0/.cache/tinygo/thinlto/llvmcache-2CEFCC256783054285B8EA72C5BF6AB1E037B087:(math_test.TestTrunc)
>>> referenced by floor.go:61 (/home/u0/Documents/zoralab/Hestia/.monteurFS/bin/golang/src/math/floor.go:61)
>>>               /home/u0/.cache/tinygo/thinlto/llvmcache-2CEFCC256783054285B8EA72C5BF6AB1E037B087:(math_test.TestTrunc)
failed to run tool: ld.lld
error: failed to link /tmp/tinygo2492987438/main: exit status 1
FAIL
u0:hestiaSTRING$ 

Yeap, all above failure because tinygo can't see the .s assembly source codes.


Version:

u0:hestiaSTRING$ tinygo version
tinygo version 0.26.0 linux/amd64 (using go version go1.19.1 and LLVM version 14.0.0)
soypat commented 1 year ago

I'm also getting an error running tinygo test math on dev:

```shell $ tinygo version tinygo version 0.27.0-dev linux/amd64 (using go version go1.19 and LLVM version $ tinygo test -c math ld.lld-14: error: undefined symbol: log >>> referenced by log.go:81 (/usr/local/go/src/math/log.go:81) >>> /home/pato/.cache/tinygo/thinlto/llvmcache-68652BC5248C68C90C92EDDE09430B640DBCEE46:(math.Acosh) >>> referenced by log.go:81 (/usr/local/go/src/math/log.go:81) >>> /home/pato/.cache/tinygo/thinlto/llvmcache-68652BC5248C68C90C92EDDE09430B640DBCEE46:(math.Acosh) >>> referenced by log.go:81 (/usr/local/go/src/math/log.go:81) >>> /home/pato/.cache/tinygo/thinlto/llvmcache-68652BC5248C68C90C92EDDE09430B640DBCEE46:(math.Asinh) >>> referenced 17 more times ld.lld-14: error: undefined symbol: exp >>> referenced by exp.go:16 (/usr/local/go/src/math/exp.go:16) >>> /home/pato/.cache/tinygo/thinlto/llvmcache-68652BC5248C68C90C92EDDE09430B640DBCEE46:(math.Erf) >>> referenced by exp.go:16 (/usr/local/go/src/math/exp.go:16) >>> /home/pato/.cache/tinygo/thinlto/llvmcache-68652BC5248C68C90C92EDDE09430B640DBCEE46:(math.Erf) >>> referenced by exp.go:16 (/usr/local/go/src/math/exp.go:16) >>> /home/pato/.cache/tinygo/thinlto/llvmcache-68652BC5248C68C90C92EDDE09430B640DBCEE46:(math.Exp) >>> referenced 9 more times ld.lld-14: error: undefined symbol: exp2 >>> referenced by exp.go:142 (/usr/local/go/src/math/exp.go:142) >>> /home/pato/.cache/tinygo/thinlto/llvmcache-68652BC5248C68C90C92EDDE09430B640DBCEE46:(math.Exp2) ld.lld-14: error: undefined symbol: floor >>> referenced by floor.go:14 (/usr/local/go/src/math/floor.go:14) >>> /home/pato/.cache/tinygo/thinlto/llvmcache-68652BC5248C68C90C92EDDE09430B640DBCEE46:(math.Gamma) >>> referenced by floor.go:14 (/usr/local/go/src/math/floor.go:14) >>> /home/pato/.cache/tinygo/thinlto/llvmcache-68652BC5248C68C90C92EDDE09430B640DBCEE46:(math.Lgamma) >>> referenced by floor.go:14 (/usr/local/go/src/math/floor.go:14) >>> /home/pato/.cache/tinygo/thinlto/llvmcache-68652BC5248C68C90C92EDDE09430B640DBCEE46:(math_test.TestFloor) >>> referenced 1 more times ld.lld-14: error: undefined symbol: ceil >>> referenced by floor.go:43 (/usr/local/go/src/math/floor.go:43) >>> /home/pato/.cache/tinygo/thinlto/llvmcache-68652BC5248C68C90C92EDDE09430B640DBCEE46:(math_test.TestCeil) >>> referenced by floor.go:43 (/usr/local/go/src/math/floor.go:43) >>> /home/pato/.cache/tinygo/thinlto/llvmcache-68652BC5248C68C90C92EDDE09430B640DBCEE46:(math_test.TestCeil) ld.lld-14: error: undefined symbol: trunc >>> referenced by floor.go:61 (/usr/local/go/src/math/floor.go:61) >>> /home/pato/.cache/tinygo/thinlto/llvmcache-68652BC5248C68C90C92EDDE09430B640DBCEE46:(math_test.TestTrunc) >>> referenced by floor.go:61 (/usr/local/go/src/math/floor.go:61) >>> /home/pato/.cache/tinygo/thinlto/llvmcache-68652BC5248C68C90C92EDDE09430B640DBCEE46:(math_test.TestTrunc) error: failed to link /tmp/tinygo225708749/main: exit status 1 ```

Strangely, the following commands seem to work:

$ GOOS=darwin tinygo test -c math
$ GOOS=windows tinygo test -c math
ld.lld-14: warning: duplicate /export option: hypot
ld.lld-14: warning: duplicate /export option: nextafter
aykevl commented 1 year ago

Yeap, all above failure because tinygo can't see the .s assembly source codes.

Again, this is not the problem. It works fine on my side and in CI.

One thing you could try is running tinygo clean. It might be that you have an old cache.

Other than that, you will need to provide some more steps to reproduce. How did you install TinyGo? What Linux distro are you on? Did you build from source or download the release tarball, or even install it from the distro package manager?

soypat commented 1 year ago

tinygo clean did it for me :)

I'll leave my installation steps for posterity: I followed the build-from-source steps shown on the site as of today. Since I am on linux mint I had to additionally do sudo apt install build-essential for a cpp compiler and stuff. I also ran make llvm-source. And with that I had a working tinygo installation.

aykevl commented 1 year ago

tinygo clean did it for me :)

Great! Then it's probably indeed just an old cache. (This is still technically a bug in TinyGo as it shouldn't use a stale cache, but it's not related to assembly files).

hollowaykeanho commented 1 year ago

Noted. Should I retitle to reflect the latest finding?