Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions eng/common/cross/build-rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ while :; do
__BuildArch=x86
__UbuntuArch=i386
__AlpineArch=x86
__FreeBSDArch=i386
__FreeBSDMachineArch=i386
__UbuntuRepo="https://archive.ubuntu.com/ubuntu/"
;;
lldb*)
Expand Down
2 changes: 2 additions & 0 deletions eng/common/cross/toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ elseif(TARGET_ARCH_NAME STREQUAL "x86")
set(CMAKE_SYSTEM_PROCESSOR i686)
if(EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/i586-alpine-linux-musl)
set(TOOLCHAIN "i586-alpine-linux-musl")
elseif(FREEBSD)
set(TOOLCHAIN "i686-unknown-freebsd14")
else()
set(TOOLCHAIN "i686-linux-gnu")
endif()
Expand Down
2 changes: 2 additions & 0 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ if (CLR_CMAKE_HOST_UNIX)
message("Detected FreeBSD aarch64")
elseif(CLR_CMAKE_HOST_UNIX_AMD64)
message("Detected FreeBSD amd64")
elseif(CLR_CMAKE_HOST_UNIX_X86)
message("Detected FreeBSD i386")
else()
message(FATAL_ERROR "Unsupported FreeBSD architecture")
endif()
Expand Down
2 changes: 2 additions & 0 deletions eng/native/configureplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ if(CLR_CMAKE_HOST_OS STREQUAL freebsd)
set(CLR_CMAKE_HOST_UNIX_AMD64 1)
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
set(CLR_CMAKE_HOST_UNIX_ARM64 1)
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL i386 OR CMAKE_SYSTEM_PROCESSOR STREQUAL i686)
set(CLR_CMAKE_HOST_UNIX_X86 1)
else()
clr_unknown_arch()
endif()
Expand Down
2 changes: 1 addition & 1 deletion eng/targetingpacks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
LatestRuntimeFrameworkVersion="$(ProductVersion)"
RuntimeFrameworkName="$(LocalFrameworkOverrideName)"
RuntimePackNamePatterns="$(LocalFrameworkOverrideName).Runtime.**RID**"
RuntimePackRuntimeIdentifiers="linux-arm;linux-arm64;linux-musl-arm64;linux-musl-x64;linux-x64;osx-x64;rhel.6-x64;tizen.4.0.0-armel;tizen.5.0.0-armel;win-arm64;win-x64;win-x86;linux-musl-arm;osx-arm64;maccatalyst-x64;maccatalyst-arm64;linux-s390x;linux-bionic-arm;linux-bionic-arm64;linux-bionic-x64;linux-bionic-x86;freebsd-x64;freebsd-arm64;linux-ppc64le;linux-riscv64;linux-musl-riscv64;linux-loongarch64;linux-musl-loongarch64"
RuntimePackRuntimeIdentifiers="linux-arm;linux-arm64;linux-musl-arm64;linux-musl-x64;linux-x64;osx-x64;rhel.6-x64;tizen.4.0.0-armel;tizen.5.0.0-armel;win-arm64;win-x64;win-x86;linux-musl-arm;osx-arm64;maccatalyst-x64;maccatalyst-arm64;linux-s390x;linux-bionic-arm;linux-bionic-arm64;linux-bionic-x64;linux-bionic-x86;freebsd-x64;freebsd-arm64;freebsd-x86;linux-ppc64le;linux-riscv64;linux-musl-riscv64;linux-loongarch64;linux-musl-loongarch64"
TargetFramework="$(NetCoreAppCurrent)"
TargetingPackName="$(LocalFrameworkOverrideName).Ref"
TargetingPackVersion="$(ProductVersion)"
Expand Down
25 changes: 25 additions & 0 deletions src/coreclr/jit/async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ PhaseStatus Compiler::SaveAsyncContexts()
CORINFO_ASYNC_INFO* asyncInfo = eeGetAsyncInfo();

GenTreeCall* capture = gtNewCallNode(CT_USER_FUNC, asyncInfo->captureContextsMethHnd, TYP_VOID);
#ifdef UNIX_X86_ABI
// Managed calls on Unix x86 are caller-pop. The importer sets this flag for
// managed calls (impImportCall), but calls created here bypass it.
capture->gtFlags |= GTF_CALL_POP_ARGS;
#endif // UNIX_X86_ABI
capture->gtArgs.PushFront(this, NewCallArg::Primitive(gtNewLclAddrNode(syncCtxLclNum, 0)));
capture->gtArgs.PushFront(this, NewCallArg::Primitive(gtNewLclAddrNode(execCtxLclNum, 0)));

Expand Down Expand Up @@ -175,6 +180,11 @@ PhaseStatus Compiler::SaveAsyncContexts()
}

GenTreeCall* restore = gtNewCallNode(CT_USER_FUNC, asyncInfo->restoreContextsMethHnd, TYP_VOID);
#ifdef UNIX_X86_ABI
// Managed calls on Unix x86 are caller-pop. The importer sets this flag for
// managed calls (impImportCall), but calls created here bypass it.
restore->gtFlags |= GTF_CALL_POP_ARGS;
#endif // UNIX_X86_ABI
restore->gtArgs.PushFront(this, NewCallArg::Primitive(gtNewLclVarNode(syncCtxLclNum)));
restore->gtArgs.PushFront(this, NewCallArg::Primitive(gtNewLclVarNode(execCtxLclNum)));
restore->gtArgs.PushFront(this, NewCallArg::Primitive(gtNewLclVarNode(suspendedLclNum)));
Expand Down Expand Up @@ -1522,6 +1532,11 @@ void AsyncTransformation::FillInGCPointersOnSuspension(GenTreeCall*
GenTree* flagsPlaceholder = m_comp->gtNewZeroConNode(TYP_BYREF);
GenTreeCall* captureCall =
m_comp->gtNewCallNode(CT_USER_FUNC, m_asyncInfo->captureContinuationContextMethHnd, TYP_VOID);
#ifdef UNIX_X86_ABI
// Managed calls on Unix x86 are caller-pop. The importer sets this flag for
// managed calls (impImportCall), but calls created here bypass it.
captureCall->gtFlags |= GTF_CALL_POP_ARGS;
#endif // UNIX_X86_ABI

captureCall->gtArgs.PushFront(m_comp, NewCallArg::Primitive(flagsPlaceholder));
captureCall->gtArgs.PushFront(m_comp, NewCallArg::Primitive(contextElementPlaceholder));
Expand Down Expand Up @@ -1572,6 +1587,11 @@ void AsyncTransformation::FillInGCPointersOnSuspension(GenTreeCall*
{
GenTreeCall* captureExecContext =
m_comp->gtNewCallNode(CT_USER_FUNC, m_asyncInfo->captureExecutionContextMethHnd, TYP_REF);
#ifdef UNIX_X86_ABI
// Managed calls on Unix x86 are caller-pop. The importer sets this flag for
// managed calls (impImportCall), but calls created here bypass it.
captureExecContext->gtFlags |= GTF_CALL_POP_ARGS;
#endif // UNIX_X86_ABI

m_comp->compCurBB = suspendBB;
m_comp->fgMorphTree(captureExecContext);
Expand Down Expand Up @@ -1866,6 +1886,11 @@ void AsyncTransformation::RestoreFromGCPointersOnResumption(unsigned
GenTree* valuePlaceholder = m_comp->gtNewZeroConNode(TYP_REF);
GenTreeCall* restoreCall =
m_comp->gtNewCallNode(CT_USER_FUNC, m_asyncInfo->restoreExecutionContextMethHnd, TYP_VOID);
#ifdef UNIX_X86_ABI
// Managed calls on Unix x86 are caller-pop. The importer sets this flag for
// managed calls (impImportCall), but calls created here bypass it.
restoreCall->gtFlags |= GTF_CALL_POP_ARGS;
#endif // UNIX_X86_ABI
restoreCall->gtArgs.PushFront(m_comp, NewCallArg::Primitive(valuePlaceholder));

m_comp->compCurBB = resumeBB;
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/jit/gcencode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,16 @@ size_t GCInfo::gcInfoBlockHdrSave(
}

size_t argCount = compiler->lvaParameterStackSize / REGSIZE_BYTES;
#ifdef UNIX_X86_ABI
// On x86 Unix, caller-pop calling conventions (cdecl-like) leave argument cleanup
// to the caller. Recording lvaParameterStackSize in the header made the runtime compute
// the caller SP too high by that amount. That breaks funclet parent-frame matching
// (m_csfEHClause) and leads to double GC reporting / stale object references.
if (IsCallerPop(compiler->info.compCallConv) && !compiler->info.compIsVarArgs)
{
argCount = 0;
}
#endif // UNIX_X86_ABI
assert(argCount <= MAX_USHORT_SIZE_T);
header->argCount = static_cast<unsigned short>(argCount);

Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/jit/gschecks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,11 @@ void Compiler::gsParamsToShadows()
CORINFO_METHOD_HANDLE copyHelper =
info.compCompHnd->getSpecialCopyHelper(varDsc->GetLayout()->GetClassHandle());
GenTreeCall* call = gtNewCallNode(CT_USER_FUNC, copyHelper, TYP_VOID);
#ifdef UNIX_X86_ABI
// Managed calls on Unix x86 are caller-pop. The importer sets this flag for
// managed calls (impImportCall), but calls created here bypass it.
call->gtFlags |= GTF_CALL_POP_ARGS;
#endif // UNIX_X86_ABI

GenTree* src = gtNewLclVarAddrNode(lclNum);
GenTree* dst = gtNewLclVarAddrNode(shadowVarNum);
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2100,6 +2100,11 @@ void Lowering::InsertSpecialCopyArg(GenTreePutArgStk* putArgStk, CORINFO_CLASS_H

GenTreeCall* call =
comp->gtNewCallNode(CT_USER_FUNC, comp->info.compCompHnd->getSpecialCopyHelper(argType), TYP_VOID);
#ifdef UNIX_X86_ABI
// Managed calls on Unix x86 are caller-pop. The importer sets this flag for
// managed calls (impImportCall), but calls created here bypass it.
call->gtFlags |= GTF_CALL_POP_ARGS;
#endif // UNIX_X86_ABI

call->gtArgs.PushBack(comp, NewCallArg::Primitive(destPlaceholder));
call->gtArgs.PushBack(comp, NewCallArg::Primitive(srcPlaceholder));
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5431,6 +5431,11 @@ GenTree* Compiler::fgCreateCallDispatcherAndGetResult(GenTreeCall* orig
CORINFO_METHOD_HANDLE dispatcherHnd)
{
GenTreeCall* callDispatcherNode = gtNewCallNode(CT_USER_FUNC, dispatcherHnd, TYP_VOID, fgMorphStmt->GetDebugInfo());
#ifdef UNIX_X86_ABI
// Managed calls on Unix x86 are caller-pop. The importer sets this flag for
// managed calls (impImportCall), but calls created here bypass it.
callDispatcherNode->gtFlags |= GTF_CALL_POP_ARGS;
#endif // UNIX_X86_ABI
// The dispatcher has signature
// void DispatchTailCalls(void* callersRetAddrSlot, void* callTarget, ref byte retValue)

Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/jit/rationalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ void Rationalizer::RewriteNodeAsCall(GenTree** use,

// Create the call node
GenTreeCall* call = comp->gtNewCallNode(CT_USER_FUNC, callHnd, tree->TypeGet());
#ifdef UNIX_X86_ABI
// Managed calls on Unix x86 are caller-pop. The importer sets this flag for
// managed calls (impImportCall), but calls created here bypass it.
call->gtFlags |= GTF_CALL_POP_ARGS;
#endif // UNIX_X86_ABI

if (isSpecialIntrinsic)
{
Expand Down
8 changes: 6 additions & 2 deletions src/coreclr/pal/inc/unixasmmacrosx86.inc
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,17 @@ C_FUNC(\Name\()_End):
PROLOG_END

lea \Target, [esp + 4]
// Keep the transition frame at its fixed EBP offset and align native call arguments separately.
and esp, -16
.endm

// Inlined version of GetThreadEEAllocContext.
.macro INLINE_GET_ALLOC_CONTEXT_BASE
push ecx
push eax
call C_FUNC(GetThreadEEAllocContext)
// The C helper returns in eax, while allocation helpers expect the context in edx.
mov edx, eax
pop eax
pop ecx
.endm
Expand All @@ -154,8 +158,8 @@ C_FUNC(\Name\()_End):
// restore stack pointer
EPILOG_BEG

// skip over alignment (4) + ArgumentRegisters (8)
EPILOG_FREE 12
// Restore the saved-register area below EBP, skipping any dynamic alignment padding.
lea esp, [ebp - 12]

// pop CalleeSavedRegisters
EPILOG_POP edi
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/pal/src/arch/i386/context2.S
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// and is always apply to the current thread.
//
LEAF_ENTRY CONTEXT_CaptureContext, _TEXT
LOCAL_LABEL(CaptureContext):
// Store
push eax
push ebx
Expand Down Expand Up @@ -89,7 +90,8 @@ LEAF_ENTRY RtlCaptureContext, _TEXT
mov eax, [esp + 8]
mov DWORD PTR [eax + CONTEXT_ContextFlags], (CONTEXT_FLOATING_POINT)
pop eax
jmp C_FUNC(CONTEXT_CaptureContext)
// Use the local entry to keep this branch position independent in shared libraries.
jmp LOCAL_LABEL(CaptureContext)
LEAF_END RtlCaptureContext, _TEXT

LEAF_ENTRY RtlRestoreContext, _TEXT
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ if(CLR_CMAKE_TARGET_APPLE)
elseif(CLR_CMAKE_TARGET_FREEBSD)
set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 0)
set(PAL_PTRACE "ptrace((cmd), (pid), (caddr_t)(addr), (data))")
if (CLR_CMAKE_HOST_ARCH_AMD64)
if(CLR_CMAKE_HOST_ARCH_AMD64 OR CLR_CMAKE_HOST_ARCH_I386)
set(BSD_REGS_STYLE "((reg).r_##rr)")
elseif(CLR_CMAKE_HOST_ARCH_ARM64)
set(BSD_REGS_STYLE "((reg).rr)")
Expand Down
11 changes: 7 additions & 4 deletions src/coreclr/vm/callingconvention.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,13 @@ class ArgIteratorTemplate : public ARGITERATOR_BASE
{
WRAPPER_NO_CONTRACT;

if (this->IsVarArg())
return 0;
else
return SizeOfArgStack();
#ifdef UNIX_X86_ABI
// Managed/cdecl calls are caller-pop on Unix x86 (see IsCallerPop in corinfo.h):
// the callee does not pop its stack arguments.
return 0;
#else
if (this->IsVarArg()) return 0; else return SizeOfArgStack();
#endif // UNIX_X86_ABI
}
#endif

Expand Down
10 changes: 4 additions & 6 deletions src/coreclr/vm/i386/asmhelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,9 @@ NESTED_ENTRY ResolveWorkerAsmStub, _TEXT, NoHandler

mov esi, esp

#define STACK_ALIGN_PADDING 8

sub esp, STACK_ALIGN_PADDING
// Keep the transition block at ESI while aligning the three native arguments.
and esp, -16
sub esp, 4
push [esi + 4*4] // dispatch token
push [esi + 5*4] // siteAddrForRegisterIndirect
push esi // pTransitionBlock
Expand All @@ -625,9 +625,7 @@ NESTED_ENTRY ResolveWorkerAsmStub, _TEXT, NoHandler
CHECK_STACK_ALIGNMENT
call C_FUNC(VSD_ResolveWorker)

add esp, STACK_ALIGN_PADDING

#undef STACK_ALIGN_PADDING
mov esp, esi

// From here on, mustn't trash eax

Expand Down
3 changes: 3 additions & 0 deletions src/installer/pkg/projects/netcoreappRIDs.props
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
in our runtime.json to enable others to provide them. -->
<UnofficialBuildRID Include="freebsd-x64" />
<UnofficialBuildRID Include="freebsd-arm64" />
<UnofficialBuildRID Include="freebsd-x86">
<Platform>x86</Platform>
</UnofficialBuildRID>
<UnofficialBuildRID Include="tizen.4.0.0-armel">
<Platform>armel</Platform>
</UnofficialBuildRID>
Expand Down
Loading
Loading