Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit a1dcf8c

Browse files
author
jashook
committed
Enable NativeVarargs for CoreCLR
This will allow coreclr run programs which have native varargs. It also re-enables the ArgIterator type for managed to managed native vararg calls. This will allow the use of the __arglist keyword. Limitations: NYI statements have been added for all Unix Targets. With this change __arglist (native varargs) will be supported, but not yet tested on: Amd64 Windows x86 Windows Arm32 Windows Arm64 Windows This change does not re-enable native vararg tests. This will be done in a seperate change.
1 parent 443597f commit a1dcf8c

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

src/System.Private.CoreLib/src/System/ArgIterator.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public ref struct ArgIterator
2727
private IntPtr ArgPtr; // Pointer to remaining args.
2828
private int RemainingArgs; // # of remaining args.
2929

30-
#if VARARGS_ENABLED //The JIT doesn't support Varargs calling convention.
3130
[MethodImplAttribute(MethodImplOptions.InternalCall)]
3231
private extern ArgIterator(IntPtr arglist);
3332

@@ -180,6 +179,5 @@ public int GetRemainingCount()
180179
{
181180
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator); // https://github.com/dotnet/coreclr/issues/9204
182181
}
183-
#endif //VARARGS_ENABLED
184182
}
185183
}

src/jit/lclvars.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,18 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo)
598598
isHfaArg = varTypeIsFloating(hfaType);
599599
}
600600
}
601+
else if (info.compIsVarArgs)
602+
{
603+
#ifdef _TARGET_UNIX_
604+
// Currently native varargs is not implemented on non windows targets.
605+
//
606+
// Note that some targets like Arm64 Unix should not need much work as
607+
// the ABI is the same. While other targets may only need small changes
608+
// such as amd64 Unix, which just expects RAX to pass numFPArguments.
609+
NYI("InitUserArgs for Vararg callee is not yet implemented on non Windows targets.");
610+
#endif
611+
}
612+
601613
if (isHfaArg)
602614
{
603615
// We have an HFA argument, so from here on out treat the type as a float or double.

src/jit/morph.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,6 +2742,18 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call)
27422742
bool callIsVararg = call->IsVarargs();
27432743
#endif
27442744

2745+
#ifdef _TARGET_UNIX_
2746+
if (callIsVararg)
2747+
{
2748+
// Currently native varargs is not implemented on non windows targets.
2749+
//
2750+
// Note that some targets like Arm64 Unix should not need much work as
2751+
// the ABI is the same. While other targets may only need small changes
2752+
// such as amd64 Unix, which just expects RAX to pass numFPArguments.
2753+
NYI("Morhing Vararg call not yet implemented on non Windows targets.");
2754+
}
2755+
#endif
2756+
27452757
#ifdef UNIX_AMD64_ABI
27462758
// If fgMakeOutgoingStructArgCopy is called and copies are generated, hasStackArgCopy is set
27472759
// to make sure to call EvalArgsToTemp. fgMakeOutgoingStructArgCopy just marks the argument

src/vm/callingconvention.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,10 @@ class ArgIteratorTemplate : public ARGITERATOR_BASE
417417

418418
#ifdef _TARGET_AMD64_
419419
#ifdef UNIX_AMD64_ABI
420-
PORTABILITY_ASSERT("ArgIteratorTemplate::IsVarArgPassedByRef");
421420
return FALSE;
422-
#else // UNIX_AMD64_ABI
421+
#else // !UNIX_AMD64_ABI
423422
return IsArgPassedByRef(size);
424-
#endif // UNIX_AMD64_ABI
423+
#endif // !UNIX_AMD64_ABI
425424

426425
#else
427426
return (size > ENREGISTERED_PARAMTYPE_MAXSIZE);

src/vm/jitinterface.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,6 @@ CEEInfo::ConvToJitSig(
489489
IfFailThrow(sig.GetCallingConvInfo(&data));
490490
sigRet->callConv = (CorInfoCallConv) data;
491491

492-
if ((isCallConv(sigRet->callConv, IMAGE_CEE_CS_CALLCONV_VARARG)) ||
493-
(isCallConv(sigRet->callConv, IMAGE_CEE_CS_CALLCONV_NATIVEVARARG)))
494-
{
495-
// This signature corresponds to a method that uses varargs, which are not supported.
496-
COMPlusThrow(kInvalidProgramException, IDS_EE_VARARG_NOT_SUPPORTED);
497-
}
498-
499492
// Skip number of type arguments
500493
if (sigRet->callConv & IMAGE_CEE_CS_CALLCONV_GENERIC)
501494
IfFailThrow(sig.GetData(NULL));

0 commit comments

Comments
 (0)