-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[BOLT] Check if symbol is in data area of function #160143
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
Open
Asher8118
wants to merge
4
commits into
llvm:main
Choose a base branch
from
Asher8118:data_area
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// This test checks that when looking for a function corresponding to a | ||
// symbol, BOLT is not looking through a data area (constant island). | ||
|
||
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o | ||
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q | ||
# RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s | ||
|
||
// Before adding a check for constant islands, BOLT would exit with an error | ||
// of the form: "symbol not found" and throw an LLVM UNREACHABLE error. | ||
# CHECK-NOT: symbol not found | ||
# CHECK-NOT: UNREACHABLE | ||
|
||
// Now BOLT throws a warning and does not crash. | ||
# CHECK: BOLT-WARNING: symbol third_block/1 is in data region of function first_block(0x{{[0-9a-f]+}}). | ||
|
||
.text | ||
.global main | ||
main: | ||
add x0, x1, x1 | ||
bl first_block | ||
ret | ||
|
||
.global first_block | ||
$d: | ||
first_block: | ||
add x0, x1, x1 | ||
bl second_block | ||
ret | ||
second_block: | ||
add x0, x1, x1 | ||
bl third_block | ||
ret | ||
$x: | ||
third_block: | ||
add x0, x1, x1 | ||
ret |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hmm.. I'm not sure
Symbol->getOffset()
will always produce the expected output.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.
Thanks for taking a look. Could you please elaborate on what might be the problem here?
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.
Ah yes, sorry.
Symbol->getOffset()
is not guaranteed to return the offset from the start of the function at arbitrary point of execution.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.
As far as I understand, if
Symbol->getOffset()
does not return the symbol offset, then it returns0
. In which caseconst uint64_t Address = BF->getAddress() + Symbol->getOffset();
becomes the same asBF->getAddress()
. For the purpose of this patch, I think that is fine. Whether we're checking the function address or the symbol address, the point is to check if we're in a data area (constant island) before proceeding. This check is only reached ingetFunctionForSymbol
as a way to prevent callinggetEntryIDForSymbol
, and avoid hitting thellvm_unreachable
, if we're in a data area.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.
I see. I'd prefer to make
getEntryIDForSymbol()
return anoptional
(i.e. remove the unreachable) and not rely on the implicit behavior.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.
Okay, I'll look into making it an
optional
.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.
Thanks!
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.
It's now returning an optional. I did keep the
Symbol->getOffset()
check in order to give a warning to the user, but we are no longer relying on it to avoid thellvm_unreachable
.