esp-rs / rust

Rust for the xtensa architecture. Built in targets for the ESP32 and ESP8266
https://www.rust-lang.org
Other
743 stars 39 forks source link

Add a custom lowering of vaarg for xtensa. #201

Closed plietar closed 1 year ago

plietar commented 1 year ago

LLVM does not include an implementation of the va_arg instruction for Xtensa. From what I understand, this is a conscious decision and instead language frontends are encouraged to implement it themselves. The rationale seems to be that loading values correctly requires language and ABI-specific knowledge that LLVM lacks.

This is true of most architectures, and rustc already provides implementation for a number of them. This commit extends the support to include Xtensa.

See https://lists.llvm.org/pipermail/llvm-dev/2017-August/116337.html for some discussion on the topic.

Unfortunately there does not seem to be a reference document for the semantics of the va_list and va_arg on Xtensa. The most reliable source is the GCC implementation, which this commit tries to follow. Clang also provides its own compatible implementation.

This was tested for all the types that rustc allows in variadics, including larger types such as u64 and f64. I am also able to run the esp-wifi examples with formatted logs from the wifi stack.

Fixes #177

MabezDev commented 1 year ago

Thank you so much for taking the time to fix this! I have to admit I was completely stumped with this issue so I really appreciate the time you spent finding and fixing the problem. I compiled this and ran a few examples, including esp-wifi with wifi-logs enabled and everything has worked perfectly.

I've added your commit (keeping you as the author) to a new release branch, 1.73.0.1. We will begin producing builds for this branch soon.