-
Notifications
You must be signed in to change notification settings - Fork 157
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
Fix downstream errors due to inline assembly #63
Conversation
Even though this crate is intended for ARM Cortex-M microcontrollers, its code must be compilable on other platforms, for example when running unit tests in a downstream crate. This could lead to compile or link errors, due to inline assembly that was invalid on the host platform. Those errors wouldn't show up when compiling this crate, as inline assembly within functions marked as `#[inline(always)]` bypasses validation, unless the function is used.[1] This commit fixes the issue, by only compiling inline assembly when running on ARM. In some cases, some replacement code had to be added, to make the compiler happy. [1]: rust-lang/rust#36718
@japaric Have you had a chance to take a look at this? I'm currently forced to override cortex-m in my downstream library, as I wouldn't be able to have a CI build otherwise. |
I also had some problems with tests recently caused by inline assembly, so I like this change |
Thanks for the PR, @hannobraun. I'm not 100% sure this is the layer where this "problem" should be "fixed". For starters I don't think these functions are a problem at all. If you are testing your code on Now, perhaps you are testing some other function that uses these low level functions that directly Or, perhaps the problem here is that your unit tests are not using these functions at all but |
Thank you for your reply, @japaric. I am not calling these functions from my test code. That would be wrong for all the reasons you outlined. The compiler/linker errors are triggered by simply compiling the code on x86_64, as might be necessary when trying to run To be more clear about what's happening, I think if everything was working correctly, cortex-m itself should not compile on anything but ARM, as the ARM-specific assembly should trigger compiler errors. It does compile, however, because the ARM assembly is not validated because the functions are As soon as a crate depending on cortex-m contains calls to one of the functions that contain ARM assembly, running So to summarize, this is definitely a problem in cortex-m, and it needs to be fixed in cortex-m. The only reason this isn't extremely obvious, is because the problem is masked by rust-lang/rust#36718. However, I do agree with you that |
Thanks. While you are at it could you also update the |
Yes, no problem. I noticed you added the v0.4.0 milestone. Are you in any hurry there? If so, let me know. I'm already in holiday mode and won't be back in the office until early January, but I can sneak this in without too much trouble, if you want to release before then. |
Well, I'd love to get the ecosystem bump done sooner than later since it seems that more interested people are popping out right now (probably due to the holidays) but I'm also (supposed to be) in holiday mode so I can only make so much progress on a daily basis. So every bit of help is welcome! |
map asm! ops to unimplemented! on non ARM targets closes #63 cc @hannobraun
Great work over the last few days! Nice to see this much progress. Sorry I couldn't be more helpful so far. |
don't over-constrain the .data section
Even though this crate is intended for ARM Cortex-M microcontrollers,
its code must be compilable on other platforms, for example when running
unit tests in a downstream crate.
This could lead to compile or link errors, due to inline assembly that
was invalid on the host platform. Those errors wouldn't show up when
compiling this crate, as inline assembly within functions marked as
#[inline(always)]
bypasses validation, unless the function is used.1This commit fixes the issue, by only compiling inline assembly when
running on ARM. In some cases, some replacement code had to be added, to
make the compiler happy.