-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
riscv64: Fix underflow in call relocation handling #5951
riscv64: Fix underflow in call relocation handling #5951
Conversation
Are you sure this is correct and not a case where two functions end up more than the max relocation distance away by chance? We don't handle that case correctly right now. See #4000. |
I don't think so, I gave this a pretty good run in the fuzzer (~24h) with these changes and it stopped complaining. It also fixed the same bug that was previously reported by the fuzzer. Also, could that happen with 4-5 functions in the test case? I'll try to get it again, but I think that was how many there were. |
If those functions don't fit in a single page and you are very unlucky, yes it can happen. |
@elliottt and I just spent a while puzzling over this. We believe that something like this PR is necessary for correctness, and that switching to The point of this calculation is that Trevor had a suggestion I really liked: Do all the intermediate arithmetic for Since One thing that confused us, if you want to add a comment into this PR: Unlike the ABI documentation linked in this code, I also thought about defining |
I've left the fuzzer running since yesterday on riscv64 (took about 18hours!) to try and find this again since I lost the original case. Testcase
Fuzzer inputBase64:
On this commit: 8bb183f Again, this doesn't seem to reproduce via the regular CLIF test case, only via the fuzzer. But when compiling it comes out as I'll look into making those changes tommorow. Just wanted to make sure it wasn't the issue @bjorn3 was mentioning above! |
If it fits in a single page then it is likely not the issue I was talking about. Or does the fuzzer call finalize_definitions in between two function compilations? That would force them to end up in separately allocated pages. |
No, we define and declare all of them (inc trampolines), and call |
41260be
to
2e170f8
Compare
Yes, but also we need it without the left shifts to calculate lo12, and at that point there was a bunch of shifting going on which seemed even more confusing. I've added that remark as a comment though. Could you double check if the comments match what you expected? |
You've covered almost everything that confused me. Thanks! The remaining bit is that |
Under some test case layouts the call relocation panicking with an underflow. Use `wrapping_sub` to signal that this is expected. The fuzzer took a while to generate such a test case. And I can't introduce it as a regression test because when running via the regular clif-util run tests the layout is different and the test case passes! I think this is because in the fuzzer we only add one trampoline, while in clif-util we build trampolines for each funcion in the file. Co-Authored-By: Jamey Sharp <[email protected]>
2e170f8
to
186e81e
Compare
👋 Hey,
Under some test case layouts the call relocation was panicking with an underflow. Use
wrapping_sub
to signal that this is expected.The fuzzer took a while to generate such a test case. And I can't introduce it as a regression test because when running via the regular clif-util run tests the layout is different and the test case passes!
I think this is because in the fuzzer we only add one trampoline, while in clif-util we build trampolines for each function in the file.