Skip to content

Commit 39d1161

Browse files
authored
Fix helloworld on x86 Linux (#55095)
Make managed->managed call use of ecx, edx to pass first two arguments. Make stack alignment returning after call.
1 parent c8486b6 commit 39d1161

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/coreclr/jit/gentree.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6423,6 +6423,9 @@ GenTreeCall* Compiler::gtNewCallNode(
64236423
GenTreeCall* node = new (this, GT_CALL) GenTreeCall(genActualType(type));
64246424

64256425
node->gtFlags |= (GTF_CALL | GTF_GLOB_REF);
6426+
#ifdef UNIX_X86_ABI
6427+
node->gtFlags |= GTF_CALL_POP_ARGS;
6428+
#endif // UNIX_X86_ABI
64266429
for (GenTreeCall::Use& use : GenTreeCall::UseList(args))
64276430
{
64286431
node->gtFlags |= (use.GetNode()->gtFlags & GTF_ALL_EFFECT);

src/coreclr/jit/morph.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ GenTree* Compiler::fgMorphIntoHelperCall(GenTree* tree, int helper, GenTreeCall:
7474
call->gtCallMoreFlags = GTF_CALL_M_EMPTY;
7575
call->gtInlineCandidateInfo = nullptr;
7676
call->gtControlExpr = nullptr;
77+
#ifdef UNIX_X86_ABI
78+
call->gtFlags |= GTF_CALL_POP_ARGS;
79+
#endif // UNIX_X86_ABI
7780

7881
#if DEBUG
7982
// Helper calls are never candidates.
@@ -2894,9 +2897,10 @@ void Compiler::fgInitArgInfo(GenTreeCall* call)
28942897
}
28952898

28962899
#ifdef TARGET_X86
2897-
// Compute the maximum number of arguments that can be passed in registers.
2898-
// For X86 we handle the varargs and unmanaged calling conventions
2900+
// Compute the maximum number of arguments that can be passed in registers.
2901+
// For X86 we handle the varargs and unmanaged calling conventions
28992902

2903+
#ifndef UNIX_X86_ABI
29002904
if (call->gtFlags & GTF_CALL_POP_ARGS)
29012905
{
29022906
noway_assert(intArgRegNum < MAX_REG_ARG);
@@ -2907,6 +2911,7 @@ void Compiler::fgInitArgInfo(GenTreeCall* call)
29072911
if (callHasRetBuffArg)
29082912
maxRegArgs++;
29092913
}
2914+
#endif // UNIX_X86_ABI
29102915

29112916
if (call->IsUnmanaged())
29122917
{

src/coreclr/vm/i386/jitinterfacex86.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,12 @@ void *JIT_TrialAlloc::GenBox(Flags flags)
490490

491491
// Do call to CopyValueClassUnchecked(object, data, pMT)
492492

493+
#ifdef UNIX_X86_ABI
494+
#define STACK_ALIGN_PADDING 12
495+
// Make pad to align esp
496+
sl.X86EmitSubEsp(STACK_ALIGN_PADDING);
497+
#endif // UNIX_X86_ABI
498+
493499
// Pass pMT (still in ECX)
494500
sl.X86EmitPushReg(kECX);
495501

@@ -507,6 +513,11 @@ void *JIT_TrialAlloc::GenBox(Flags flags)
507513

508514
// call CopyValueClass
509515
sl.X86EmitCall(sl.NewExternalCodeLabel((LPVOID) CopyValueClassUnchecked), 12);
516+
#ifdef UNIX_X86_ABI
517+
// Make pad to align esp
518+
sl.X86EmitAddEsp(STACK_ALIGN_PADDING);
519+
#undef STACK_ALIGN_PADDING
520+
#endif // UNIX_X86_ABI
510521

511522
// Restore the address of the newly allocated object and return it.
512523
// mov eax,ebx

0 commit comments

Comments
 (0)