diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index ff075893ec7826..a6ad06fade3389 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID; #define GUID_DEFINED #endif // !GUID_DEFINED -constexpr GUID JITEEVersionIdentifier = { /* 273ba350-32bf-4714-beb0-7fa46c11364d */ - 0x273ba350, - 0x32bf, - 0x4714, - {0xbe, 0xb0, 0x7f, 0xa4, 0x6c, 0x11, 0x36, 0x4d} +constexpr GUID JITEEVersionIdentifier = { /* 488a17ce-26c9-4ad0-a7b7-79bf320ea4d1 */ + 0x488a17ce, + 0x26c9, + 0x4ad0, + {0xa7, 0xb7, 0x79, 0xbf, 0x32, 0x0e, 0xa4, 0xd1} }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/coreclr/jit/codegenarm64.cpp b/src/coreclr/jit/codegenarm64.cpp index 2f6ebaf56fc841..2ac66ba5ea7770 100644 --- a/src/coreclr/jit/codegenarm64.cpp +++ b/src/coreclr/jit/codegenarm64.cpp @@ -2236,18 +2236,12 @@ void CodeGen::instGen_Set_Reg_To_Imm(emitAttr size, // reg cannot be a FP register assert(!genIsValidFloatReg(reg)); - emitAttr origAttr = size; if (!compiler->opts.compReloc) { size = EA_SIZE(size); // Strip any Reloc flags from size if we aren't doing relocs } - if (compiler->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && EA_IS_CNS_SEC_RELOC(origAttr)) - { - // This emits pair of `add` instructions for TLS reloc - GetEmitter()->emitIns_Add_Add_Tls_Reloc(size, reg, imm DEBUGARG(gtFlags)); - } - else if (EA_IS_RELOC(size)) + if (EA_IS_RELOC(size)) { // This emits a pair of adrp/add (two instructions) with fix-ups. GetEmitter()->emitIns_R_AI(INS_adrp, size, reg, imm DEBUGARG(targetHandle) DEBUGARG(gtFlags)); @@ -2764,6 +2758,18 @@ void CodeGen::genCodeForBinary(GenTreeOp* tree) genProduceReg(tree); return; } + else if (compiler->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && TargetOS::IsWindows && + op2->IsIconHandle(GTF_ICON_SECREL_OFFSET)) + { + // This emits pair of `add` instructions for TLS reloc on windows/arm64/nativeaot + assert(op2->AsIntCon()->ImmedValNeedsReloc(compiler)); + + emitAttr attr = emitActualTypeSize(targetType); + attr = EA_SET_FLG(attr, EA_CNS_RELOC_FLG | EA_CNS_SEC_RELOC); + + emit->emitIns_Add_Add_Tls_Reloc(attr, targetReg, op1->GetRegNum(), op2->AsIntCon()->IconValue()); + return; + } instruction ins = genGetInsForOper(tree->OperGet(), targetType); diff --git a/src/coreclr/jit/emitarm64.cpp b/src/coreclr/jit/emitarm64.cpp index f98264590aedaa..f831e0aa1b6915 100644 --- a/src/coreclr/jit/emitarm64.cpp +++ b/src/coreclr/jit/emitarm64.cpp @@ -3756,6 +3756,7 @@ void emitter::emitIns_R(instruction ins, emitAttr attr, regNumber reg, insOpts o // gtFlags - DEBUG only gtFlags. // void emitter::emitIns_Add_Add_Tls_Reloc(emitAttr attr, + regNumber targetReg, regNumber reg, ssize_t imm DEBUGARG(GenTreeFlags gtFlags /* = GTF_EMPTY */)) { @@ -3777,7 +3778,7 @@ void emitter::emitIns_Add_Add_Tls_Reloc(emitAttr attr, id->idInsOpt(INS_OPTS_LSL12); id->idAddr()->iiaAddr = (BYTE*)imm; - id->idReg1(reg); + id->idReg1(targetReg); id->idReg2(reg); // Since this is relocation, set to 8 byte size. @@ -3804,7 +3805,7 @@ void emitter::emitIns_Add_Add_Tls_Reloc(emitAttr attr, id->idInsFmt(fmt); id->idAddr()->iiaAddr = (BYTE*)imm; - id->idReg1(reg); + id->idReg1(targetReg); id->idReg2(reg); // Since this is relocation, set to 8 byte size. @@ -11349,7 +11350,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) else { // This is second "add" of "add/add" pair - emitRecordRelocation(odst, id->idAddr()->iiaAddr, IMAGE_REL_ARM64_SECREL_LOW12L); + emitRecordRelocation(odst, id->idAddr()->iiaAddr, IMAGE_REL_ARM64_SECREL_LOW12A); } } else @@ -13539,13 +13540,32 @@ void emitter::emitDispInsHelp( if (id->idIsReloc()) { assert(ins == INS_add); - printf("[LOW RELOC "); + + if (emitComp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && TargetOS::IsWindows && id->idIsTlsGD()) + { + printf("[HIGH RELOC "); + } + else + { + printf("[LOW RELOC "); + } + emitDispImm((ssize_t)id->idAddr()->iiaAddr, false); printf("]"); } else { - emitDispImmOptsLSL(emitGetInsSC(id), insOptsLSL12(id->idInsOpt()), 12); + if (emitComp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && TargetOS::IsWindows && id->idIsTlsGD()) + { + assert(ins == INS_add); + printf("[LOW RELOC "); + emitDispImm((ssize_t)id->idAddr()->iiaAddr, false); + printf("]"); + } + else + { + emitDispImmOptsLSL(emitGetInsSC(id), insOptsLSL12(id->idInsOpt()), 12); + } } break; diff --git a/src/coreclr/jit/emitarm64.h b/src/coreclr/jit/emitarm64.h index 4629923358d189..1aeeb46942e5f1 100644 --- a/src/coreclr/jit/emitarm64.h +++ b/src/coreclr/jit/emitarm64.h @@ -1455,7 +1455,10 @@ void emitIns_R_I(instruction ins, insOpts opt = INS_OPTS_NONE, insScalableOpts sopt = INS_SCALABLE_OPTS_NONE DEBUGARG(size_t targetHandle = 0) DEBUGARG(GenTreeFlags gtFlags = GTF_EMPTY)); -void emitIns_Add_Add_Tls_Reloc(emitAttr attr, regNumber reg, ssize_t imm DEBUGARG(GenTreeFlags gtFlags = GTF_EMPTY)); +void emitIns_Add_Add_Tls_Reloc(emitAttr attr, + regNumber targetReg, + regNumber reg, + ssize_t imm DEBUGARG(GenTreeFlags gtFlags = GTF_EMPTY)); void emitInsSve_R_I(instruction ins, emitAttr attr, diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 739edf207f6c5d..1580a3fbba362e 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -595,7 +595,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St CORINFO_CONST_LOOKUP tlsIndexObject = threadStaticInfo.tlsIndexObject; - GenTree* dllRef = gtNewIconHandleNode((size_t)tlsIndexObject.handle, GTF_ICON_OBJ_HDL); + GenTree* dllRef = gtNewIconHandleNode((size_t)tlsIndexObject.handle, GTF_ICON_CONST_PTR); dllRef = gtNewIndir(TYP_INT, dllRef, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); dllRef = gtNewCastNode(TYP_I_IMPL, dllRef, true, TYP_I_IMPL); dllRef = gtNewOperNode(GT_LSH, TYP_I_IMPL, dllRef, gtNewIconNode(3, TYP_I_IMPL)); diff --git a/src/coreclr/jit/lowerarmarch.cpp b/src/coreclr/jit/lowerarmarch.cpp index cd5032921804d2..855c4f21917e50 100644 --- a/src/coreclr/jit/lowerarmarch.cpp +++ b/src/coreclr/jit/lowerarmarch.cpp @@ -68,7 +68,20 @@ bool Lowering::IsContainableImmed(GenTree* parentNode, GenTree* childNode) const if (!childNode->IsCnsIntOrI()) return false; if (childNode->AsIntCon()->ImmedValNeedsReloc(comp)) - return false; + { + if (comp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && TargetOS::IsWindows && + childNode->IsIconHandle(GTF_ICON_SECREL_OFFSET)) + { + // for windows/arm64, the immediate constant should be contained because it gets + // generated as part of ADD instruction that consumes this constant. See + // emitIns_Add_Add_Tls_Reloc(). + return true; + } + else + { + return false; + } + } // TODO-CrossBitness: we wouldn't need the cast below if GenTreeIntCon::gtIconVal had target_ssize_t type. target_ssize_t immVal = (target_ssize_t)childNode->AsIntCon()->gtIconVal; diff --git a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs index cba453eff5489c..07d9d0ccb4a061 100644 --- a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs +++ b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs @@ -59,7 +59,7 @@ public enum RelocType // Windows arm64 TLS access IMAGE_REL_ARM64_TLS_SECREL_HIGH12A = 0x10F, // ADD high 12-bit offset for tls - IMAGE_REL_ARM64_TLS_SECREL_LOW12L = 0x110, // ADD low 12-bit offset for tls + IMAGE_REL_ARM64_TLS_SECREL_LOW12A = 0x110, // ADD low 12-bit offset for tls // // Relocations for R2R image production @@ -536,7 +536,7 @@ public static unsafe void WriteValue(RelocType relocType, void* location, long v break; case RelocType.IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A: case RelocType.IMAGE_REL_AARCH64_TLSDESC_ADD_LO12: - case RelocType.IMAGE_REL_ARM64_TLS_SECREL_LOW12L: + case RelocType.IMAGE_REL_ARM64_TLS_SECREL_LOW12A: PutArm64Rel12((uint*)location, (int)value); break; case RelocType.IMAGE_REL_BASED_LOONGARCH64_PC: @@ -593,7 +593,7 @@ public static unsafe long ReadValue(RelocType relocType, void* location) return GetArm64Rel21((uint*)location); case RelocType.IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A: case RelocType.IMAGE_REL_ARM64_TLS_SECREL_HIGH12A: - case RelocType.IMAGE_REL_ARM64_TLS_SECREL_LOW12L: + case RelocType.IMAGE_REL_ARM64_TLS_SECREL_LOW12A: return GetArm64Rel12((uint*)location); case RelocType.IMAGE_REL_AARCH64_TLSDESC_LD64_LO12: case RelocType.IMAGE_REL_AARCH64_TLSDESC_ADD_LO12: diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 0033a758669307..05a3389013be2f 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -3920,8 +3920,8 @@ private static RelocType GetRelocType(TargetArchitecture targetArchitecture, ush const ushort IMAGE_REL_ARM64_BRANCH26 = 3; const ushort IMAGE_REL_ARM64_PAGEBASE_REL21 = 4; const ushort IMAGE_REL_ARM64_PAGEOFFSET_12A = 6; + const ushort IMAGE_REL_ARM64_SECREL_LOW12A = 9; const ushort IMAGE_REL_ARM64_SECREL_HIGH12A = 0xA; - const ushort IMAGE_REL_ARM64_SECREL_LOW12L = 0xB; const ushort IMAGE_REL_ARM64_TLSDESC_ADR_PAGE21 = 0x107; const ushort IMAGE_REL_ARM64_TLSDESC_LD64_LO12 = 0x108; const ushort IMAGE_REL_ARM64_TLSDESC_ADD_LO12 = 0x109; @@ -3946,8 +3946,8 @@ private static RelocType GetRelocType(TargetArchitecture targetArchitecture, ush return RelocType.IMAGE_REL_AARCH64_TLSDESC_CALL; case IMAGE_REL_ARM64_SECREL_HIGH12A: return RelocType.IMAGE_REL_ARM64_TLS_SECREL_HIGH12A; - case IMAGE_REL_ARM64_SECREL_LOW12L: - return RelocType.IMAGE_REL_ARM64_TLS_SECREL_LOW12L; + case IMAGE_REL_ARM64_SECREL_LOW12A: + return RelocType.IMAGE_REL_ARM64_TLS_SECREL_LOW12A; default: Debug.Fail("Invalid RelocType: " + fRelocType); return 0; diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/CoffObjectWriter.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/CoffObjectWriter.cs index 3660c16daf4827..d6deb27606a4a1 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/CoffObjectWriter.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/CoffObjectWriter.cs @@ -355,7 +355,7 @@ private protected override void EmitRelocations(int sectionIndex, List IMAGE_REL_ARM64_PAGEBASE_REL21, IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A => IMAGE_REL_ARM64_PAGEOFFSET_12A, IMAGE_REL_ARM64_TLS_SECREL_HIGH12A => IMAGE_REL_ARM64_SECREL_HIGH12A, - IMAGE_REL_ARM64_TLS_SECREL_LOW12L => IMAGE_REL_ARM64_SECREL_LOW12L, + IMAGE_REL_ARM64_TLS_SECREL_LOW12A => IMAGE_REL_ARM64_SECREL_LOW12A, IMAGE_REL_SECREL => IMAGE_REL_ARM64_SECREL, IMAGE_REL_SECTION => IMAGE_REL_ARM64_SECTION, _ => throw new NotSupportedException($"Unsupported relocation: {relocation.Type}") diff --git a/src/coreclr/tools/aot/ILCompiler/reproNative/reproNative.vcxproj b/src/coreclr/tools/aot/ILCompiler/reproNative/reproNative.vcxproj index 5a94961e04926e..d0e08605427a3a 100644 --- a/src/coreclr/tools/aot/ILCompiler/reproNative/reproNative.vcxproj +++ b/src/coreclr/tools/aot/ILCompiler/reproNative/reproNative.vcxproj @@ -1,9 +1,17 @@ + + Checked + ARM64 + Checked Win32 + + Debug + ARM64 + Debug Win32 @@ -16,6 +24,10 @@ Checked x64 + + Release + ARM64 + Release Win32 @@ -42,6 +54,12 @@ v143 Unicode + + Application + true + v143 + Unicode + Application true @@ -55,6 +73,13 @@ true Unicode + + Application + false + v143 + true + Unicode + Application false @@ -69,6 +94,13 @@ true Unicode + + Application + false + v143 + true + Unicode + Application false @@ -82,18 +114,27 @@ + + + + + + + + + @@ -102,6 +143,10 @@ false false + + false + false + false false @@ -110,6 +155,10 @@ false false + + false + false + false false @@ -118,6 +167,10 @@ false false + + false + false + false false @@ -140,6 +193,24 @@ $(ArtifactsRoot)bin\repro\x64\Debug\repro.obj;$(Win32SDKLibs);%(AdditionalDependencies);$(ArtifactsRoot)bin\coreclr\windows.x64.Debug\aotsdk\Runtime.WorkstationGC.lib;$(ArtifactsRoot)bin\coreclr\windows.x64.Debug\aotsdk\System.Globalization.Native.Aot.lib;$(ArtifactsRoot)bin\coreclr\windows.x64.Debug\aotsdk\System.IO.Compression.Native.Aot.lib;$(ArtifactsRoot)bin\coreclr\windows.x64.Debug\aotsdk\eventpipe-disabled.lib;$(ArtifactsRoot)bin\coreclr\windows.x64.Debug\aotsdk\Runtime.VxsortDisabled.lib;$(ArtifactsRoot)bin\coreclr\windows.x64.Debug\aotsdk\standalonegc-disabled.lib + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;HOST_ARM64;%(PreprocessorDefinitions) + true + $(CoreClrSourceRoot)gc;$(CoreClrSourceRoot)gc\env + 4477 + MultiThreadedDebug + false + ProgramDatabase + + + Console + true + $(ArtifactsRoot)bin\repro\Arm64\Debug\repro.obj;$(Win32SDKLibs);%(AdditionalDependencies);$(ArtifactsRoot)bin\coreclr\windows.Arm64.Debug\aotsdk\Runtime.WorkstationGC.lib;$(ArtifactsRoot)bin\coreclr\windows.Arm64.Debug\aotsdk\System.Globalization.Native.Aot.lib;$(ArtifactsRoot)bin\coreclr\windows.Arm64.Debug\aotsdk\System.IO.Compression.Native.Aot.lib;$(ArtifactsRoot)bin\coreclr\windows.Arm64.Debug\aotsdk\eventpipe-disabled.lib;$(ArtifactsRoot)bin\coreclr\windows.Arm64.Debug\aotsdk\standalonegc-disabled.lib + + Level3 @@ -179,6 +250,26 @@ $(ArtifactsRoot)bin\repro\x64\Checked\repro.obj;$(Win32SDKLibs);%(AdditionalDependencies);$(ArtifactsRoot)bin\coreclr\windows.x64.Checked\aotsdk\Runtime.WorkstationGC.lib;$(ArtifactsRoot)bin\coreclr\windows.x64.Checked\aotsdk\System.Globalization.Native.Aot.lib;$(ArtifactsRoot)bin\coreclr\windows.x64.Checked\aotsdk\System.IO.Compression.Native.Aot.lib;$(ArtifactsRoot)bin\coreclr\windows.x64.Checked\aotsdk\eventpipe-disabled.lib;$(ArtifactsRoot)bin\coreclr\windows.x64.Checked\aotsdk\Runtime.VxsortDisabled.lib;$(ArtifactsRoot)bin\coreclr\windows.x64.Checked\aotsdk\standalonegc-disabled.lib + + + Level3 + MaxSpeed + true + true + _DEBUG;_CONSOLE;_LIB;HOST_ARM64;%(PreprocessorDefinitions) + true + $(CoreClrSourceRoot)gc;$(CoreClrSourceRoot)gc\env + 4477 + MultiThreadedDebug + + + Console + true + true + true + $(ArtifactsRoot)bin\repro\Arm64\Checked\repro.obj;$(Win32SDKLibs);%(AdditionalDependencies);$(ArtifactsRoot)bin\coreclr\windows.Arm64.Checked\aotsdk\Runtime.WorkstationGC.lib;$(ArtifactsRoot)bin\coreclr\windows.Arm64.Checked\aotsdk\System.Globalization.Native.Aot.lib;$(ArtifactsRoot)bin\coreclr\windows.Arm64.Checked\aotsdk\System.IO.Compression.Native.Aot.lib;$(ArtifactsRoot)bin\coreclr\windows.Arm64.Checked\aotsdk\eventpipe-disabled.lib;$(ArtifactsRoot)bin\coreclr\windows.Arm64.Checked\aotsdk\standalonegc-disabled.lib + + Level3 @@ -220,6 +311,26 @@ $(ArtifactsRoot)bin\repro\x64\Release\repro.obj;$(Win32SDKLibs);%(AdditionalDependencies);$(ArtifactsRoot)bin\coreclr\windows.x64.Release\aotsdk\Runtime.WorkstationGC.lib;$(ArtifactsRoot)bin\coreclr\windows.x64.Release\aotsdk\System.Globalization.Native.Aot.lib;$(ArtifactsRoot)bin\coreclr\windows.x64.Release\aotsdk\System.IO.Compression.Native.Aot.lib;$(ArtifactsRoot)bin\coreclr\windows.x64.Release\aotsdk\eventpipe-disabled.lib;$(ArtifactsRoot)bin\coreclr\windows.x64.Release\aotsdk\Runtime.VxsortDisabled.lib;$(ArtifactsRoot)bin\coreclr\windows.x64.Release\aotsdk\standalonegc-disabled.lib + + + Level3 + MaxSpeed + true + true + NDEBUG;_CONSOLE;_LIB;HOST_ARM64;%(PreprocessorDefinitions) + true + $(CoreClrSourceRoot)gc;$(CoreClrSourceRoot)gc\env + 4477 + MultiThreaded + + + Console + true + true + true + $(ArtifactsRoot)bin\repro\Arm64\Release\repro.obj;$(Win32SDKLibs);%(AdditionalDependencies);$(ArtifactsRoot)bin\coreclr\windows.Arm64.Release\aotsdk\Runtime.WorkstationGC.lib;$(ArtifactsRoot)bin\coreclr\windows.Arm64.Release\aotsdk\System.Globalization.Native.Aot.lib;$(ArtifactsRoot)bin\coreclr\windows.Arm64.Release\aotsdk\System.IO.Compression.Native.Aot.lib;$(ArtifactsRoot)bin\coreclr\windows.Arm64.Release\aotsdk\eventpipe-disabled.lib;$(ArtifactsRoot)bin\coreclr\windows.Arm64.Release\aotsdk\standalonegc-disabled.lib + + Level3 @@ -252,4 +363,4 @@ - + \ No newline at end of file diff --git a/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp b/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp index c49182402648c9..8f846d7014c105 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp @@ -894,6 +894,8 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b } break; + case IMAGE_REL_ARM64_SECREL_HIGH12A: + case IMAGE_REL_ARM64_SECREL_LOW12A: case IMAGE_REL_AARCH64_TLSDESC_LD64_LO12: case IMAGE_REL_AARCH64_TLSDESC_ADD_LO12: // TLSDESC ADD for corresponding ADRP case IMAGE_REL_AARCH64_TLSDESC_CALL: