Skip to content

Commit

Permalink
Disable compact unwinding on osx-x64, add hack to stop linker from co…
Browse files Browse the repository at this point in the history
…rrupting DWARF CFI
  • Loading branch information
filipnavara committed Sep 15, 2022
1 parent a9dfa2d commit 22a8804
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<LinkerArg Include="-Wl,-z,now" Condition="'$(TargetOS)' != 'OSX'" />
<LinkerArg Include="-Wl,-u,_NativeAOT_StaticInitialization" Condition="'$(TargetOS)' == 'OSX' and '$(NativeLib)' == 'Shared'" />
<LinkerArg Include="-Wl,--require-defined,NativeAOT_StaticInitialization" Condition="'$(TargetOS)' != 'OSX' and '$(NativeLib)' == 'Shared'" />
<LinkerArg Include="-Wl,-no_compact_unwind -Wl,-keep_dwarf_unwind" Condition="'$(TargetOS)' == 'OSX' and '$(TargetArchitecture)' == 'x64'" />

<LinkerArg Include="@(NativeFramework->'-framework %(Identity)')" Condition="'$(TargetOS)' == 'OSX'" />
</ItemGroup>
Expand Down
15 changes: 0 additions & 15 deletions src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,26 +653,11 @@ bool UnixNativeCodeManager::GetReturnAddressHijackInfo(MethodInfo * pMethodIn
GcInfoDecoderFlags flags = DECODE_RETURN_KIND;
#if defined(TARGET_ARM) || defined(TARGET_ARM64)
flags = (GcInfoDecoderFlags)(flags | DECODE_HAS_TAILCALLS);
#elif defined(TARGET_AMD64) && defined(TARGET_OSX)
flags = (GcInfoDecoderFlags)(flags | DECODE_PROLOG_LENGTH);
#endif // TARGET_ARM || TARGET_ARM64

GcInfoDecoder decoder(GCInfoToken(p), flags);
*pRetValueKind = GetGcRefKind(decoder.GetReturnKind());

#if defined(TARGET_AMD64) && defined(TARGET_OSX)
// Compact unwinding on macOS cannot properly handle unwinding the function prolog
if ((PTR_VOID)pRegisterSet->IP == pNativeMethodInfo->pMethodStartAddress)
{
*ppvRetAddrLocation = (PTR_PTR_VOID)pRegisterSet->GetSP();
return true;
}
else if ((PTR_UInt8)pRegisterSet->IP < (PTR_UInt8)pNativeMethodInfo->pMethodStartAddress + decoder.GetPrologSize())
{
return false;
}
#endif

int epilogueInstructions = TrailingEpilogueInstructionsCount((PTR_VOID)pRegisterSet->IP);
if (epilogueInstructions < 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,21 @@ public void EmitCFICodes(int offset)
// Internal compiler error
Debug.Assert(false);
}

if (_targetPlatform.OperatingSystem == TargetOS.OSX)
{
// Emit a symbol for beginning of the frame. This is workaround for ld64
// linker bug which would produce DWARF with incorrect pcStart offsets for
// exception handling blocks if there is no symbol present for them.
//
// To make things simple we just reuse blobSymbolName and change `_lsda`
// prefix to `_fram`.
blobSymbolName[1] = (byte)'f';
blobSymbolName[2] = (byte)'r';
blobSymbolName[3] = (byte)'a';
blobSymbolName[4] = (byte)'m';
EmitSymbolDef(blobSymbolName);
}
}

// Emit individual cfi blob for the given offset
Expand Down

0 comments on commit 22a8804

Please sign in to comment.