Skip to content
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

[NativeAOT/ARM] Bail out on IMAGE_REL_BASED_THUMB_BRANCH24 with >24-bit addends #97756

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private static unsafe int GetThumb2BlRel24(ushort* p)
//*****************************************************************************
// Returns whether the offset fits into bl instruction
//*****************************************************************************
private static bool FitsInThumb2BlRel24(int imm24)
public static bool FitsInThumb2BlRel24(int imm24)
{
return ((imm24 << 7) >> 7) == imm24;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,29 @@ or IMAGE_REL_BASED_THUMB_BRANCH24 or IMAGE_REL_BASED_THUMB_MOV32_PCREL &&
// For R_ARM_THM_JUMP24 the thumb bit cannot be encoded, so mask it out.
long maskThumbBitOut = relocType is IMAGE_REL_BASED_THUMB_BRANCH24 or IMAGE_REL_BASED_THUMB_MOV32_PCREL ? 1 : 0;
long maskThumbBitIn = relocType is IMAGE_REL_BASED_THUMB_MOV32_PCREL ? 1 : 0;
long adjustedAddend = addend;

addend -= relocType switch
adjustedAddend -= relocType switch
{
IMAGE_REL_BASED_REL32 => 4,
IMAGE_REL_BASED_THUMB_BRANCH24 => 4,
IMAGE_REL_BASED_THUMB_MOV32_PCREL => 12,
_ => 0
};

addend += definedSymbol.Value & ~maskThumbBitOut;
addend += Relocation.ReadValue(relocType, (void*)pData);
addend |= definedSymbol.Value & maskThumbBitIn;
addend -= offset;
Relocation.WriteValue(relocType, (void*)pData, addend);
adjustedAddend += definedSymbol.Value & ~maskThumbBitOut;
adjustedAddend += Relocation.ReadValue(relocType, (void*)pData);
adjustedAddend |= definedSymbol.Value & maskThumbBitIn;
adjustedAddend -= offset;

if (relocType is IMAGE_REL_BASED_THUMB_BRANCH24 && !Relocation.FitsInThumb2BlRel24((int)adjustedAddend))
{
EmitRelocation(sectionIndex, offset, data, relocType, symbolName, addend);
}
else
{
Relocation.WriteValue(relocType, (void*)pData, adjustedAddend);
}
}
}
else
Expand Down
Loading