Skip to content

Commit 52d2756

Browse files
committed
ARM64: unwind data generation. In general, this involved changing the registration
mechanism to more closely align with x64 than ARM32, since x64 has a similar requirement that unwind data be close (within 4GB) to the code. New files ARM64UnwindEncoder.cpp/.h provide a generic encoder for ARM64 unwind xdata, based strictly upon the final codegen. This code is designed to have few dependencies and be reusable in other contexts. Future work includes adding support for compact pdata and potentially merging more of the AMD64 and ARM64 code paths (specifically the xdataallocator).
1 parent bf60994 commit 52d2756

19 files changed

+1169
-1223
lines changed

lib/Backend/Chakra.Backend.vcxproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@
145145
<ExcludedFromBuild Condition="'$(Platform)'!='ARM64'">true</ExcludedFromBuild>
146146
<ObjectFileName Condition="'$(Platform)'!='ARM64'">$(IntDir)\arm64</ObjectFileName>
147147
</ClCompile>
148+
<ClCompile Include="arm64\ARM64UnwindEncoder.cpp">
149+
<ExcludedFromBuild Condition="'$(Platform)'!='ARM64'">true</ExcludedFromBuild>
150+
<ObjectFileName Condition="'$(Platform)'!='ARM64'">$(IntDir)\arm64</ObjectFileName>
151+
</ClCompile>
148152
<ClCompile Include="$(MSBuildThisFileDirectory)arm64\EncoderMD.cpp">
149153
<ExcludedFromBuild Condition="'$(Platform)'!='ARM64'">true</ExcludedFromBuild>
150154
<!-- Since there are more then one EncoderMD.cpp, we need to set them output into different directory, even when they are ExcludedFromBuild -->
@@ -260,6 +264,9 @@
260264
<ClInclude Include="arm64\ARM64NeonEncoder.h">
261265
<ExcludedFromBuild Condition="'$(Platform)'!='ARM64'">true</ExcludedFromBuild>
262266
</ClInclude>
267+
<ClInclude Include="arm64\ARM64UnwindEncoder.h">
268+
<ExcludedFromBuild Condition="'$(Platform)'!='ARM64'">true</ExcludedFromBuild>
269+
</ClInclude>
263270
<ClInclude Include="arm64\EncoderMD.h">
264271
<ExcludedFromBuild Condition="'$(Platform)'!='ARM64'">true</ExcludedFromBuild>
265272
</ClInclude>
@@ -528,4 +535,4 @@
528535
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
529536
<Import Project="$(BuildConfig_ARMASM_Path)armasm.targets" />
530537
</ImportGroup>
531-
</Project>
538+
</Project>

lib/Backend/Chakra.Backend.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@
147147
<ClCompile Include="$(MSBuildThisFileDirectory)JITThunkEmitter.cpp" />
148148
<ClCompile Include="$(MSBuildThisFileDirectory)JavascriptNativeOperators.cpp" />
149149
<ClCompile Include="$(MSBuildThisFileDirectory)EquivalentTypeSet.cpp" />
150+
<ClCompile Include="arm64\ARM64UnwindEncoder.cpp">
151+
<Filter>arm64</Filter>
152+
</ClCompile>
150153
</ItemGroup>
151154
<ItemGroup>
152155
<ClInclude Include="AgenPeeps.h" />
@@ -374,6 +377,9 @@
374377
<ClInclude Include="arm64\MdOpCodes.h">
375378
<Filter>arm64</Filter>
376379
</ClInclude>
380+
<ClInclude Include="arm64\ARM64UnwindEncoder.h">
381+
<Filter>arm64</Filter>
382+
</ClInclude>
377383
</ItemGroup>
378384
<ItemGroup>
379385
<MASM Include="$(MSBuildThisFileDirectory)amd64\LinearScanMdA.asm">

lib/Backend/Encoder.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,10 @@ Encoder::Encode()
329329
#ifdef _M_X64
330330
pdataCount = 1;
331331
xdataSize = (ushort)m_func->m_prologEncoder.SizeOfUnwindInfo();
332-
#elif defined(_M_ARM32_OR_ARM64)
332+
#elif defined(_M_ARM64)
333+
pdataCount = 1;
334+
xdataSize = XDATA_SIZE;
335+
#elif defined(_M_ARM)
333336
#pragma warning(push)
334337
#pragma warning(disable:4244) // warning C4244: 'argument': conversion from 'ptrdiff_t' to 'DWORD', possible loss of data
335338
pdataCount = (ushort)m_func->m_unwindInfo.GetPDataCount(codeSize);
@@ -393,9 +396,13 @@ Encoder::Encode()
393396
}
394397
#endif
395398

399+
#ifdef _M_X64_OR_ARM64
396400
#ifdef _M_X64
397-
m_func->m_prologEncoder.FinalizeUnwindInfo(
398-
(BYTE*)m_func->GetJITOutput()->GetCodeAddress(), (DWORD)codeSize);
401+
PrologEncoder &unwindInfo = m_func->m_prologEncoder;
402+
#else
403+
UnwindInfoManager &unwindInfo = m_func->m_unwindInfo;
404+
#endif
405+
unwindInfo.FinalizeUnwindInfo((BYTE*)m_func->GetJITOutput()->GetCodeAddress(), (DWORD)codeSize);
399406

400407
char * localXdataAddr = nullptr;
401408
#if ENABLE_OOP_NATIVE_CODEGEN
@@ -414,8 +421,8 @@ Encoder::Encode()
414421
localXdataAddr = (char*)allocation->xdata.address;
415422
}
416423
m_func->GetJITOutput()->RecordUnwindInfo(
417-
m_func->m_prologEncoder.GetUnwindInfo(),
418-
m_func->m_prologEncoder.SizeOfUnwindInfo(),
424+
unwindInfo.GetUnwindInfo(),
425+
unwindInfo.SizeOfUnwindInfo(),
419426
allocation->xdata.address,
420427
(BYTE*)localXdataAddr);
421428
#elif _M_ARM
@@ -429,10 +436,9 @@ Encoder::Encode()
429436
}
430437
else
431438
{
432-
XDataAllocator::Register(&allocation->xdata, m_func->GetJITOutput()->GetCodeAddress(), m_func->GetJITOutput()->GetCodeSize());
439+
XDataAllocator::Register(&allocation->xdata, m_func->GetJITOutput()->GetCodeAddress(), (DWORD)m_func->GetJITOutput()->GetCodeSize());
433440
m_func->GetInProcJITEntryPointInfo()->SetXDataInfo(&allocation->xdata);
434441
}
435-
436442
m_func->GetJITOutput()->SetCodeAddress(m_func->GetJITOutput()->GetCodeAddress() | 0x1); // Set thumb mode
437443
#endif
438444

lib/Backend/JITOutput.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ JITOutput::RecordInlineeFrameOffsetsInfo(unsigned int offsetsArrayOffset, unsign
218218
m_outputData->inlineeFrameOffsetArrayCount = offsetsArrayCount;
219219
}
220220

221-
#if _M_X64
221+
#if _M_X64_OR_ARM64
222222
void
223223
JITOutput::RecordUnwindInfo(BYTE *unwindInfo, size_t size, BYTE * xdataAddr, BYTE* localXdataAddr)
224224
{
@@ -229,12 +229,12 @@ JITOutput::RecordUnwindInfo(BYTE *unwindInfo, size_t size, BYTE * xdataAddr, BYT
229229

230230
#elif _M_ARM
231231
size_t
232-
JITOutput::RecordUnwindInfo(size_t offset, BYTE *unwindInfo, size_t size, BYTE * xdataAddr)
232+
JITOutput::RecordUnwindInfo(size_t offset, const BYTE *unwindInfo, size_t size, BYTE * xdataAddr)
233233
{
234234
BYTE *xdataFinal = xdataAddr + offset;
235235

236236
Assert(xdataFinal);
237-
Assert(((DWORD)xdataFinal & 0x3) == 0); // 4 byte aligned
237+
Assert(((ULONG_PTR)xdataFinal & 0x3) == 0); // 4 byte aligned
238238
memcpy_s(xdataFinal, size, unwindInfo, size);
239239

240240
return (size_t)xdataFinal;

lib/Backend/JITOutput.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ class JITOutput
4242
void RecordNativeCode(const BYTE* sourceBuffer, BYTE* localCodeAddress);
4343
void RecordInlineeFrameOffsetsInfo(unsigned int offsetsArrayOffset, unsigned int offsetsArrayCount);
4444

45-
#if _M_X64
45+
#if _M_X64_OR_ARM64
4646
void RecordUnwindInfo(BYTE *unwindInfo, size_t size, BYTE * xdataAddr, BYTE* localXdataAddr);
4747
#elif _M_ARM
48-
size_t RecordUnwindInfo(size_t offset, BYTE *unwindInfo, size_t size, BYTE * xdataAddr);
48+
size_t RecordUnwindInfo(size_t offset, const BYTE *unwindInfo, size_t size, BYTE * xdataAddr);
4949
#endif
5050

5151
void FinalizeNativeCode();

lib/Backend/NativeCodeGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ NativeCodeGenerator::CodeGen(PageAllocator * pageAllocator, CodeGenWorkItem* wor
10721072
workItem->GetEntryPoint()->GetJitTransferData()->SetIsReady();
10731073
}
10741074

1075-
#if defined(_M_X64)
1075+
#if defined(_M_X64_OR_ARM64)
10761076
XDataAllocation * xdataInfo = HeapNewZ(XDataAllocation);
10771077
xdataInfo->address = (byte*)jitWriteData.xdataAddr;
10781078
XDataAllocator::Register(xdataInfo, jitWriteData.codeAddress, jitWriteData.codeSize);

lib/Backend/Opnd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3026,7 +3026,7 @@ Opnd::DumpAddress(void *address, bool printToConsole, bool skipMaskedAddress)
30263026
}
30273027
else
30283028
{
3029-
#ifdef _M_X64
3029+
#ifdef _M_X64_OR_ARM64
30303030
Output::Print(_u("0x%012I64X"), address);
30313031
#else
30323032
Output::Print(_u("0x%08X"), address);

lib/Backend/PDataManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//-------------------------------------------------------------------------------------------------------
55
#include "Backend.h"
66

7-
// Conditionally-compiled on x64 and arm
7+
// Conditionally-compiled on x64 and arm/arm64
88
#if PDATA_ENABLED
99

1010
#ifdef _WIN32

0 commit comments

Comments
 (0)