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

Code following very small functions can trampled by jumps #9

Open
ftilde opened this issue Nov 11, 2018 · 3 comments
Open

Code following very small functions can trampled by jumps #9

ftilde opened this issue Nov 11, 2018 · 3 comments

Comments

@ftilde
Copy link
Contributor

ftilde commented Nov 11, 2018

This is very much a duplicate of #3, but it seems like you had problems consistently reproducing the problem in tests. I put together a proof of concept which (at least on my machines) consistently shows the described problem here.

Unfortunately, I'm not sure how to turn this into a unit test as it relies on turning on size optimization (opt-level = "s") and requires the functions to be defined in another crate in order to avoid inlining. If you can think of a way to turn this into a test or just want to use the code for debugging purposes, feel free to do so!

@mehcode
Copy link
Owner

mehcode commented Nov 11, 2018

Would #[inline(never)] help?

Of course if this bug requires optimizations of any kind to manifest I'm going to say it's out of scope of this crate. I wouldn't say no to a PR fixing it but I'm not going to actively work to fix it.

@ftilde
Copy link
Contributor Author

ftilde commented Nov 12, 2018

In my testing found I found that rustc/llvm (quite annoyingly) still inlines #[inline(never)] functions (at least) when turning on size optimization. (The functions in the other library are actually still marked with that, also I haven't tested they are inlined if the annotations are removed.)

Of course if this bug requires optimizations of any kind to manifest I'm going to say it's out of scope of this crate.

I would suspect that optimizations are not required to trigger this bug, but they seem to be able to trigger it reliably. I don't think (but also don't actually know if) there is a guarantee that small functions are padded with nops if no optimizations are enabled (like it is currently the case).

I wouldn't say no to a PR fixing it but I'm not going to actively work to fix it.

No worries. I just had fun putting this proof of concept together after reading the announcement on reddit and thought it might be useful if someone wants to implement a fix.

@mehcode
Copy link
Owner

mehcode commented Nov 13, 2018

I would accept a PR that adds the test under a feature flag like limitations or flaky or something. It's good to document what we can't do after all.

In my testing found I found that rustc/llvm (quite annoyingly) still inlines #[inline(never)] [...]

Just tested this when making my tests pass in --release mode. #[inline(never)] annotations are ignored if the functions are declared in the same module. Just put them in a new mod { ... } block.

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