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

Add relocs for TLS in neardiffer #98840

Merged
merged 2 commits into from
Feb 23, 2024
Merged
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
38 changes: 37 additions & 1 deletion src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,18 @@ const char* relocationTypeToString(uint16_t fRelocType)
// From corinfo.h
case IMAGE_REL_BASED_REL32:
return "rel32";
case IMAGE_REL_SECREL:
return "secrel";
case IMAGE_REL_TLSGD:
return "tlsgd";
case IMAGE_REL_AARCH64_TLSDESC_ADR_PAGE21:
return "tlsdesc_high21";
case IMAGE_REL_AARCH64_TLSDESC_LD64_LO12:
return "tlsdesc_lo12";
case IMAGE_REL_AARCH64_TLSDESC_ADD_LO12:
return "tlsdesc_add_lo12";
case IMAGE_REL_AARCH64_TLSDESC_CALL:
return "tlsdesc_call";
case IMAGE_REL_BASED_THUMB_BRANCH24:
return "thumb_branch24";
default:
Expand Down Expand Up @@ -851,6 +863,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b
break;

case IMAGE_REL_ARM64_PAGEBASE_REL21: // ADRP 21 bit PC-relative page address
case IMAGE_REL_AARCH64_TLSDESC_ADR_PAGE21: // ADRP 21 bit for TLSDesc
{
if ((section_begin <= address) && (address < section_end)) // A reloc for our section?
{
Expand All @@ -865,6 +878,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b
break;

case IMAGE_REL_ARM64_PAGEOFFSET_12A: // ADD 12 bit page offset
case IMAGE_REL_AARCH64_TLSDESC_ADD_LO12: // TLSDESC ADD for corresponding ADRP
{
if ((section_begin <= address) && (address < section_end)) // A reloc for our section?
{
Expand All @@ -875,6 +889,28 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b
}
break;

case IMAGE_REL_AARCH64_TLSDESC_CALL:
case IMAGE_REL_TLSGD:
{
DWORDLONG fixupLocation = tmp.location;

size_t address = section_begin + (size_t)fixupLocation - (size_t)originalAddr;
if ((section_begin <= address) && (address < section_end)) // A reloc for our section?
{
LogDebug(" fixupLoc-%016" PRIX64 " (@%p) : %08X => %08X", fixupLocation, address,
*(DWORD*)address, (DWORD)tmp.target);
*(DWORD*)address = (DWORD)tmp.target;
}
wasRelocHandled = true;
}
break;

case IMAGE_REL_AARCH64_TLSDESC_LD64_LO12:
{
// not needed
}
break;

default:
break;
}
Expand Down Expand Up @@ -908,7 +944,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b
continue;

// Now do all-platform relocations.
if (tmp.fRelocType == IMAGE_REL_BASED_REL32)
if ((tmp.fRelocType == IMAGE_REL_BASED_REL32) || (tmp.fRelocType == IMAGE_REL_SECREL))
{
DWORDLONG fixupLocation = tmp.location;

Expand Down