You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wrong code generated for Android ARM with optimisations #22776
There appears to be a case that looks like optimisations resulting in bad code to be generated for Android ARM. This issue demonstrates the problem in the context where I ran into it, using the byteorder library.
Test environment
Host OS: OSX 10.9.5
Android SDK
Android NDK (Revision 10d) with standalone toolchain according to the wiki.
Android Emulator: ARM (armeabi-v7a), Android 5.0.1 (API level 21)
rustc 1.0.0-dev (built 2015-02-23), configured for cross-compilation to the arm-linux-androideabi target.
The following is the output for the relevant functions (write_u16, write_u32 and write_u64) of compiling byteorder using --emit=llvm-ir with and without the above patch.
Just another update: Reproduced with Rust Beta2 and a newer version of byteorder (which accidentally but thankfully reintroduced the issue but is now patched again, so there is a recent commit that compiles with the latest rustc). Specifically:
I think the problem here is (the old) byteorder: .as_ptr only returns a pointer that is valid for as long as the slice it is called on, and the slice in the original code only lasts until the end of its let statement. Thus, the original code actually had a use-after-free bug.
I'm closing since I don't think this is a bug in Rust, and thanks to @romanb for diagnosing and even fixing the problem in byteorder!
There appears to be a case that looks like optimisations resulting in bad code to be generated for Android ARM. This issue demonstrates the problem in the context where I ran into it, using the byteorder library.
Test environment
arm-linux-androideabitarget.Steps to reproduce
Clone byteorder. Checkout commit
d9259c15a4b18de37d765aebbe5034f282772b84.Create main.rs:
Build
Run on emulator
Output
Expected:
Actual (sample):
Workarounds
There seem to be two ways to work around the problem:
Apply the following patch to
byteorderTurn off optimizations (
opt-level).Further Details
The following is the output for the relevant functions (
write_u16,write_u32andwrite_u64) of compilingbyteorderusing--emit=llvm-irwith and without the above patch.Without the patch: https://gist.github.com/romanb/2ff2ebb474c87103e631
With the patch: https://gist.github.com/romanb/d419ba4882d9c489c494