-
Notifications
You must be signed in to change notification settings - Fork 14.7k
release/21.x: [lld] Add thunks for hexagon (#111217) #149723
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
Merged
Merged
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -2139,17 +2139,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> data = 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 = | ||
data.drop_front(rel.offset - (i + 1) * 4); | ||
memcpy(&instWord, instWordContents.data(), sizeof(instWord)); | ||
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. This assumes native endianness; use read32 |
||
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); | ||
return 0; | ||
} | ||
|
||
// Find or create a ThunkSection within the InputSectionDescription (ISD) that | ||
|
@@ -2161,7 +2188,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; | ||
|
@@ -2322,7 +2349,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 | ||
|
@@ -2481,7 +2508,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.
Why are you drop_front'ing every time rather than just offsetting from data.data()?
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 the suggestions @jrtc27, I'll make a new PR with these changes, targeting
main
.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.
No need - @jrtc27 has done it already.
TYVM!