-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[lld] Add thunks for hexagon #111217
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
androm3da
wants to merge
3
commits into
llvm:main
Choose a base branch
from
androm3da:bcain/lld_thunk
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.
+620
−46
Open
[lld] Add thunks for hexagon #111217
Changes from all commits
Commits
Show all changes
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2129,17 +2129,44 @@ void ThunkCreator::mergeThunks(ArrayRef<OutputSection *> outputSections) { | |
}); | ||
} | ||
|
||
static int64_t getPCBias(Ctx &ctx, RelType type) { | ||
if (ctx.arg.emachine != EM_ARM) | ||
return 0; | ||
switch (type) { | ||
case R_ARM_THM_JUMP19: | ||
case R_ARM_THM_JUMP24: | ||
case R_ARM_THM_CALL: | ||
return 4; | ||
default: | ||
return 8; | ||
constexpr uint32_t HEXAGON_MASK_END_PACKET = 3 << 14; | ||
constexpr uint32_t HEXAGON_END_OF_PACKET = 3 << 14; | ||
constexpr uint32_t HEXAGON_END_OF_DUPLEX = 0 << 14; | ||
|
||
// Return the distance between the packet start and the instruction in the | ||
// relocation. | ||
static int getHexagonPacketOffset(const InputSection &isec, | ||
const Relocation &rel) { | ||
const ArrayRef<uint8_t> SectContents = isec.content(); | ||
|
||
// Search back as many as 3 instructions. | ||
for (unsigned i = 0;; i++) { | ||
if (i == 3 || rel.offset < (i + 1) * 4) | ||
return i * 4; | ||
uint32_t instWord = 0; | ||
const ArrayRef<uint8_t> InstWordContents = | ||
SectContents.drop_front(rel.offset - (i + 1) * 4); | ||
::memcpy(&instWord, InstWordContents.data(), sizeof(instWord)); | ||
if (((instWord & HEXAGON_MASK_END_PACKET) == HEXAGON_END_OF_PACKET) || | ||
((instWord & HEXAGON_MASK_END_PACKET) == HEXAGON_END_OF_DUPLEX)) | ||
return i * 4; | ||
} | ||
} | ||
static int64_t getPCBias(Ctx &ctx, const InputSection &isec, | ||
const Relocation &rel) { | ||
if (ctx.arg.emachine == EM_ARM) { | ||
switch (rel.type) { | ||
case R_ARM_THM_JUMP19: | ||
case R_ARM_THM_JUMP24: | ||
case R_ARM_THM_CALL: | ||
return 4; | ||
default: | ||
return 8; | ||
} | ||
} | ||
if (ctx.arg.emachine == EM_HEXAGON) | ||
return -getHexagonPacketOffset(isec, rel); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. fixed, thank you. |
||
return 0; | ||
} | ||
|
||
// Find or create a ThunkSection within the InputSectionDescription (ISD) that | ||
|
@@ -2151,7 +2178,7 @@ ThunkSection *ThunkCreator::getISDThunkSec(OutputSection *os, | |
const Relocation &rel, | ||
uint64_t src) { | ||
// See the comment in getThunk for -pcBias below. | ||
const int64_t pcBias = getPCBias(ctx, rel.type); | ||
const int64_t pcBias = getPCBias(ctx, *isec, rel); | ||
for (std::pair<ThunkSection *, uint32_t> tp : isd->thunkSections) { | ||
ThunkSection *ts = tp.first; | ||
uint64_t tsBase = os->addr + ts->outSecOff - pcBias; | ||
|
@@ -2312,7 +2339,7 @@ std::pair<Thunk *, bool> ThunkCreator::getThunk(InputSection *isec, | |
// out in the relocation addend. We compensate for the PC bias so that | ||
// an Arm and Thumb relocation to the same destination get the same keyAddend, | ||
// which is usually 0. | ||
const int64_t pcBias = getPCBias(ctx, rel.type); | ||
const int64_t pcBias = getPCBias(ctx, *isec, rel); | ||
const int64_t keyAddend = rel.addend + pcBias; | ||
|
||
// We use a ((section, offset), addend) pair to find the thunk position if | ||
|
@@ -2471,7 +2498,7 @@ bool ThunkCreator::createThunks(uint32_t pass, | |
// STT_SECTION + non-zero addend, clear the addend after | ||
// redirection. | ||
if (ctx.arg.emachine != EM_MIPS) | ||
rel.addend = -getPCBias(ctx, rel.type); | ||
rel.addend = -getPCBias(ctx, *isec, rel); | ||
} | ||
|
||
for (auto &p : isd->thunkSections) | ||
|
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
We need tests to test the thunk range. aarch64-thunk-pi.s ppc64-long-branch.s are examples to test the exact range.
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 will add the necessary tests.
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.
range test cases added