Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help needed in debugging AVR compilation errors #19

Closed
deadprogram opened this issue Sep 22, 2018 · 6 comments
Closed

Help needed in debugging AVR compilation errors #19

deadprogram opened this issue Sep 22, 2018 · 6 comments

Comments

@deadprogram
Copy link
Member

I am working on the I2C interface for the AVR. The WIP branch is located here:

hybridgroup@f3c8e28

My problem is that the compile works with the code I just committed, but if I uncomment this line https://github.com/hybridgroup/tinygo/blob/feature/avr-i2c/src/examples/i2clcd/i2clcd.go#L52 in my sample, the compile fails with:

$ make flash-i2clcd TARGET=arduino                                                                                     
./build/tgo build -target arduino -size=short -o build/i2clcd.elf examples/i2clcd
ROLW unimplemented
UNREACHABLE executed at /home/ron/.gvm/pkgsets/go1.11/global/src/github.com/aykevl/llvm/lib/Target/AVR/AVRExpandPseudo$
nsts.cpp:1316!
SIGABRT: abort
PC=0x7f7ec3df0428 m=4 sigcode=18446744073709551610

If I uncomment the following line instead https://github.com/hybridgroup/tinygo/blob/feature/avr-i2c/src/examples/i2clcd/i2clcd.go#L53

I get this error:

$ make flash-i2clcd TARGET=arduino
go build -o build/tgo -i .
./build/tgo build -target arduino -size=short -o build/i2clcd.elf examples/i2clcd
tgo: /home/ron/.gvm/pkgsets/go1.11/global/src/github.com/aykevl/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:9
039: void llvm::SelectionDAGISel::LowerArguments(const llvm::Function&): Assertion `InVals.size() == Ins.size() && "Low
erFormalArguments didn't emit the correct number of values!"' failed.
SIGABRT: abort
PC=0x7f633a6f8428 m=5 sigcode=18446744073709551610

Perhaps this has to do with not yet implemented features on AVR?

@aykevl
Copy link
Member

aykevl commented Sep 22, 2018

I have seen the second error more often. It is due to a limitation in the AVR backend (it cannot deal with struct parameters, and []byte is really a {ptr, len, cap} struct). See #20 for details. A temporary (ugly) workaround is to make the inliner more likely to run by increasing the value of the third parameter to Optmize(opt, size, inliner) in main.go.

I haven't seen the first error before but it also looks like an unimplemented feature.

@deadprogram
Copy link
Member Author

Boosted Optimize() 3 param as you suggested. the value 300 compiles (both errors go away) but does not execute as desired.

You are probably not surprised. Digging here to figure out more.

@aykevl
Copy link
Member

aykevl commented Sep 23, 2018

You could try again now. The second problem is probably fixed with fdfa810. The first problem should really be fixed in upstream LLVM, but might also be fixed as a side effect (who knows).

A trick that might fix the first problem (again, a dirty workaround) is to sleep the same time everywhere. The optimizer will recognize the pattern and do the expensive int64 calculation at compile time.

@aykevl
Copy link
Member

aykevl commented Sep 23, 2018

Ah now I see. The trouble with the second uncommented line might be related to the memory allocator, which I have never tested on AVR (as it wasn't able to run any significant programs).

@deadprogram
Copy link
Member Author

You were correct that changing all of the calls to time.Sleep() to use the same value let the compiler run without errors and without changing the value of the inliner param to Optimize(). That is probably not a practical long-term solution, of course.

The latest version of master lets the compiler run using various different time values like my original code, with the inline param set to the lower value 50.

@deadprogram
Copy link
Member Author

The latest version of master now is able to run the AVR I2C code with no change to the Optimize() function. I am going to close this issue as the original problem has been addressed. Thank you!

ZauberNerd pushed a commit to ZauberNerd/tinygo that referenced this issue Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants