Skip to content

Commit

Permalink
Add relocs for TLS in neardiffer (dotnet#98840)
Browse files Browse the repository at this point in the history
* Add relocs for TLS

* add the missing break
  • Loading branch information
kunalspathak authored Feb 23, 2024
1 parent 42b5348 commit 427bc3d
Showing 1 changed file with 37 additions and 1 deletion.
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

0 comments on commit 427bc3d

Please sign in to comment.