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

Commit

Permalink
Enable NativeVarargs for CoreCLR
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jashook committed Jun 10, 2018
1 parent 443597f commit 890cd77
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 37 deletions.
6 changes: 3 additions & 3 deletions src/System.Private.CoreLib/src/System/ArgIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ref struct ArgIterator
private IntPtr ArgPtr; // Pointer to remaining args.
private int RemainingArgs; // # of remaining args.

#if VARARGS_ENABLED //The JIT doesn't support Varargs calling convention.
#if PLATFORM_WINDOWS // Native Varargs are not supported on Unix
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern ArgIterator(IntPtr arglist);

Expand Down Expand Up @@ -132,7 +132,7 @@ public override bool Equals(Object o)
{
throw new NotSupportedException(SR.NotSupported_NYI);
}
#else
#else
public ArgIterator(RuntimeArgumentHandle arglist)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator); // https://github.com/dotnet/coreclr/issues/9204
Expand Down Expand Up @@ -180,6 +180,6 @@ public int GetRemainingCount()
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator); // https://github.com/dotnet/coreclr/issues/9204
}
#endif //VARARGS_ENABLED
#endif // PLATFORM_WINDOWS
}
}
12 changes: 12 additions & 0 deletions src/jit/lclvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,18 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo)
isHfaArg = varTypeIsFloating(hfaType);
}
}
else if (info.compIsVarArgs)
{
#ifdef _TARGET_UNIX_
// Currently native varargs is not implemented on non windows targets.
//
// Note that some targets like Arm64 Unix should not need much work as
// the ABI is the same. While other targets may only need small changes
// such as amd64 Unix, which just expects RAX to pass numFPArguments.
NYI("InitUserArgs for Vararg callee is not yet implemented on non Windows targets.");
#endif
}

if (isHfaArg)
{
// We have an HFA argument, so from here on out treat the type as a float or double.
Expand Down
13 changes: 11 additions & 2 deletions src/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2737,9 +2737,18 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call)
unsigned nonRegPassedStructSlots = 0;
bool reMorphing = call->AreArgsComplete();
bool callHasRetBuffArg = call->HasRetBufArg();
bool callIsVararg = call->IsVarargs();

#ifndef _TARGET_X86_ // i.e. _TARGET_AMD64_ or _TARGET_ARM_
bool callIsVararg = call->IsVarargs();
#ifdef _TARGET_UNIX_
if (callIsVararg)
{
// Currently native varargs is not implemented on non windows targets.
//
// Note that some targets like Arm64 Unix should not need much work as
// the ABI is the same. While other targets may only need small changes
// such as amd64 Unix, which just expects RAX to pass numFPArguments.
NYI("Morhing Vararg call not yet implemented on non Windows targets.");
}
#endif

#ifdef UNIX_AMD64_ABI
Expand Down
2 changes: 2 additions & 0 deletions src/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,14 @@ CEEInfo::ConvToJitSig(
IfFailThrow(sig.GetCallingConvInfo(&data));
sigRet->callConv = (CorInfoCallConv) data;

#ifdef PLATFORM_UNIX
if ((isCallConv(sigRet->callConv, IMAGE_CEE_CS_CALLCONV_VARARG)) ||
(isCallConv(sigRet->callConv, IMAGE_CEE_CS_CALLCONV_NATIVEVARARG)))
{
// This signature corresponds to a method that uses varargs, which are not supported.
COMPlusThrow(kInvalidProgramException, IDS_EE_VARARG_NOT_SUPPORTED);
}
#endif // PLATFORM_UNIX

// Skip number of type arguments
if (sigRet->callConv & IMAGE_CEE_CS_CALLCONV_GENERIC)
Expand Down
16 changes: 0 additions & 16 deletions tests/arm/Tests.lst
Original file line number Diff line number Diff line change
Expand Up @@ -48428,14 +48428,6 @@ MaxAllowedDurationSeconds=600
Categories=EXPECTED_PASS;Pri1
HostStyle=0

[varargsupport_r.cmd_6076]
RelativePath=baseservices\varargs\varargsupport_r\varargsupport_r.cmd
WorkingDir=baseservices\varargs\varargsupport_r
Expected=0
MaxAllowedDurationSeconds=600
Categories=EXPECTED_PASS
HostStyle=0

[_il_relcatchfault_tail.cmd_6077]
RelativePath=JIT\Methodical\Invoke\SEH\_il_relcatchfault_tail\_il_relcatchfault_tail.cmd
WorkingDir=JIT\Methodical\Invoke\SEH\_il_relcatchfault_tail
Expand Down Expand Up @@ -74412,14 +74404,6 @@ MaxAllowedDurationSeconds=600
Categories=EXPECTED_PASS
HostStyle=0

[varargsupport.cmd_9339]
RelativePath=baseservices\varargs\varargsupport\varargsupport.cmd
WorkingDir=baseservices\varargs\varargsupport
Expected=0
MaxAllowedDurationSeconds=600
Categories=EXPECTED_PASS
HostStyle=0

[uint8_d.cmd_9340]
RelativePath=JIT\Directed\shift\uint8_d\uint8_d.cmd
WorkingDir=JIT\Directed\shift\uint8_d
Expand Down
16 changes: 0 additions & 16 deletions tests/arm64/Tests.lst
Original file line number Diff line number Diff line change
Expand Up @@ -4612,22 +4612,6 @@ MaxAllowedDurationSeconds=600
Categories=EXPECTED_PASS;Pri1
HostStyle=0

[varargsupport.cmd_576]
RelativePath=baseservices\varargs\varargsupport\varargsupport.cmd
WorkingDir=baseservices\varargs\varargsupport
Expected=0
MaxAllowedDurationSeconds=600
Categories=EXPECTED_PASS
HostStyle=0

[varargsupport_r.cmd_577]
RelativePath=baseservices\varargs\varargsupport_r\varargsupport_r.cmd
WorkingDir=baseservices\varargs\varargsupport_r
Expected=0
MaxAllowedDurationSeconds=600
Categories=EXPECTED_PASS
HostStyle=0

[Co9600Ctor.cmd_578]
RelativePath=CoreMangLib\components\stopwatch\Co9600Ctor\Co9600Ctor.cmd
WorkingDir=CoreMangLib\components\stopwatch\Co9600Ctor
Expand Down
6 changes: 6 additions & 0 deletions tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@
<ExcludeList Include="$(XunitTestBinBase)\JIT\Regression\JitBlue\GitHub_18056\Bool_And_Op_cs_do\Bool_And_Op_cs_do.cmd">
<Issue>18056</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)\baseservices\varargs\varargsupport\varargsupport.cmd">
<Issue>Varargs supported on this platform</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)\baseservices\varargs\varargsupport_r\varargsupport_r.cmd">
<Issue>Varargs supported on this platform</Issue>
</ExcludeList>
</ItemGroup>

<!-- The following are x86 failures -->
Expand Down

0 comments on commit 890cd77

Please sign in to comment.