-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[BOLT] Avoid reference updates for non-JT symbol operands #88838
Conversation
pass validate-memrefs wrongly update the correct reference to the jump table reference, which leads to a different execution result. (a.out is compiled from jt-symbol-disambiguation-4.s attached in this PR)
a.out
a.out-opt
|
01deba3
to
696f3a7
Compare
Thank you for the fix. How did you discover the problem? |
Hi @maksfb , I found this problem in an internal testsuite built with clang/llvm toolchain. I did some investigation and saw that some SCEV-based optimizations like loop-reduce and slsr in LLVM can generate this kind of pattern. LLVM IR log:
in this case, llvm optimize after removing PHI
Then we have
|
Thanks for the context. It's interesting how you hit a corner case where the pass does the exact opposite of what it's supposed to do. I.e it fetches a symbol at Instead of verifying if the symbol
This way, we are also making sure the symbol will not collide with other symbols registered at the same address. Then you'll also have to adjust the way the new object is created and used:
|
@linsinan1995, does the above make sense to you? |
Add a check to skip updating references for operands that do not directly refer to jump table symbols but fall within a jump table's address range to prevent unintended modifications.
696f3a7
to
999bddf
Compare
@maksfb sorry for the delay. Thank you for your suggestions. The changes have been made accordingly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks again!
@maksfb , One thing I am not very sure about is the like
Although the code is not directly generated by the compiler, we may need more checks for such addresses overlapping cases in BOLT. at least more warnings in the future? |
Yes, you are correct. We planned to add data flow analysis to disambiguate such cases. |
# REQUIRES: system-linux | ||
|
||
|
||
# RUN: %clang -no-pie %s -o %t.exe -Wl,-q |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test fails on my AArch64-linux machine.
It seems that something is missing on this clang command line to tell it explicitly to target x86? In some of the other tests in this directory, it seems that might be done indirectly by adding %cflags to the clang command line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted.
…8838)" This reverts commit 9d5411f. Breaks aarch64 buildbot: https://lab.llvm.org/buildbot/#/builders/221/builds/22130
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address the issues with the test.
# REQUIRES: system-linux | ||
|
||
|
||
# RUN: %clang -no-pie %s -o %t.exe -Wl,-q |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use llvm-mc + lld for assembly tests (check bolt/test/X86 for examples).
|
||
# RUN: %clang -no-pie %s -o %t.exe -Wl,-q | ||
|
||
# RUN: %t.exe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Runnable tests need to be under bolt/test/runtime. But in this case, there's no need to run the binary to verify the behavior. Please remove these lines with running the binary.
# RUN: %t.exe | ||
# RUN: llvm-bolt -funcs=main,foo/1 %t.exe -o %t.exe.bolt -jump-tables=move | ||
# RUN: %t.exe.bolt | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a CHECK line verifying the intended behavior of the pass: that the output binary contains the correct reference.
# REQUIRES: system-linux | ||
|
||
|
||
# RUN: %clang -no-pie %s -o %t.exe -Wl,-q |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted.
Summary: In ValidateMemRefs pass, when we validate references of the form `Symbol + Addend`, we should check Symbol against aliasing a jump table instead of the Symbol + Addend value. llvm#88838 Test Plan: NFC Reviewers: aaupov, #llvm-bolt Reviewed By: aaupov Differential Revision: https://phabricator.intern.facebook.com/D56213679 Tags: accept2ship
In ValidateMemRefs pass, when we validate references in the form of `Symbol + Addend`, we should check `Symbol` not `Symbol + Addend` against aliasing a jump table. Recommitting with a modified test case: #88838 Co-authored-by: sinan <sinan.lin@linux.alibaba.com>
In ValidateMemRefs pass, when we validate references in the form of `Symbol + Addend`, we should check `Symbol` not `Symbol + Addend` against aliasing a jump table. Recommitting with a modified test case: llvm#88838 Co-authored-by: sinan <sinan.lin@linux.alibaba.com>
Add a check to skip updating references for operands that do not directly refer to jump table symbols but fall within a jump table's address range to prevent unintended modifications.