Description
Hello all,
I would like to know the general opinions on merging the avr-rust fork into Rust proper.
The fork itself has became a lot more stable with less bugs in the recent months. It has also started attracting a number of people interested in using it.
You can find one of the more interesting projects using avr-rust on GitHub.
Blockers
LLVM 5.0
Rust is currently on LLVM 4.0, which contains a working AVR backend, but there have been many bugfixes since then. We would need to wait for LLVM 5.0 to be supported (nearly finished: #43370) before we get a version of the AVR backend that has a few important bugs fixed.
This is no longer a blocker. Upstream Rust is at LLVM 6.0 as of 2018-02-20.
Questions
Cherry-picking fixes
If AVR support was built into mainline, we'd need to be able to cherry-pick patches into Rust's LLVM fork. I don't imagine this would be much of a problem, as we already cherry-pick a number of important fixes into there.
All of the bugfixes cherry-picked into the avr-rust repository have already been upstreamed into LLVM trunk, which would continue to be the case if we merged the fork, as I am not a fan of the LLVM fork diverging too far from trunk.
Cherry-picking is necessary because of LLVM's 6-month release cycle.
Current issues in the AVR backend
There aren't any known bugs in the avr-rust/rust repository - all of the known bugs are issues in the AVR LLVM backend; here are some of the more interesting/impactful ones.
libcore
cannot be compiled without modification
There is a milestone set up to track what bugs need to be fixed in order to get libcore
compiling successfully without modification.
This hasn't been much of a problem for users so far, as xargo will transparently compile libcore
on the fly when needed, and we can override libcore in Xargo.toml
.
I am unsure what the Rust team thinks of merging a target which can't use the stock libcore.
Any operations on function pointers other than 'call' access RAM, not program memory (avr-rust#68)
This is a symptom of AVR being the very first in-tree LLVM backend for a Harvard architecture. LLVM currently assumes that all functions reside in "the generic address space", which corresponds to RAM. Because of this, if you attempt to load/store through a function pointer, it will access RAM instead of the program memory.
Good news is that I have pending upstream LLVM patches to fix it (D37052, D37053, D37054, D37057).
32-bit shifts generate calls to a compiler-rt
routine that doesn't exist (avr-llvm/llvm#163)
Because there aren't many (if any) targets that don't support 32-bit shifts natively, libgcc
and compiler-rt
do not have 32-bit versions of shift routine, even though LLVM still happily generates a call to it.
This causes an undefined symbol error whilst linking. This will only happen if you actually write code or use code that performs 32-bit shifts, as the linker is quite good at removing all dead code.
Note that I've had one user hit the missing shift bug due to compiling in release mode, which promoted a multiplication to a shift as an "optimisation".
Actual changes to merge
You can find all AVR-specific differences by looking at this diff.
Note that over half of that diff is just the README and Travis CI configuration - the actual code being upstreamed is very small; just some glue code to enable the AVR backend and a target specification.
This diff also conditionally disables parts of libcore
for AVR - these fixes would not upstreamed, and are not strictly required as downstream users can use Xargo to compile a minified libcore
for AVR).