From b4d95f84a56d15fa3e641efe89209bd0d963f782 Mon Sep 17 00:00:00 2001 From: Jarret Shook Date: Mon, 11 Jun 2018 11:28:26 -0700 Subject: [PATCH] (Re)Enable NativeVarargs for CoreCLR (dotnet/coreclr#18373) * 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 separate change. Commit migrated from https://github.com/dotnet/coreclr/commit/e6004705f3e14742e9dcdfce3d8d9caeada83451 --- .../src/System.Private.CoreLib/src/System/ArgIterator.cs | 6 +++--- src/coreclr/src/jit/lclvars.cpp | 12 ++++++++++++ src/coreclr/src/jit/morph.cpp | 15 ++++++++++++--- src/coreclr/src/vm/jitinterface.cpp | 2 ++ src/coreclr/tests/arm/Tests.lst | 16 ---------------- src/coreclr/tests/arm64/Tests.lst | 16 ---------------- src/coreclr/tests/issues.targets | 6 ++++++ 7 files changed, 35 insertions(+), 38 deletions(-) diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/ArgIterator.cs b/src/coreclr/src/System.Private.CoreLib/src/System/ArgIterator.cs index 67e549c..7a4131e 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/ArgIterator.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/ArgIterator.cs @@ -27,7 +27,7 @@ namespace System 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); @@ -132,7 +132,7 @@ namespace System { 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 @@ -180,6 +180,6 @@ namespace System { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator); // https://github.com/dotnet/coreclr/issues/9204 } -#endif //VARARGS_ENABLED +#endif // PLATFORM_WINDOWS } } diff --git a/src/coreclr/src/jit/lclvars.cpp b/src/coreclr/src/jit/lclvars.cpp index 19dadfc..1a18700 100644 --- a/src/coreclr/src/jit/lclvars.cpp +++ b/src/coreclr/src/jit/lclvars.cpp @@ -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. diff --git a/src/coreclr/src/jit/morph.cpp b/src/coreclr/src/jit/morph.cpp index 37bc2f3..c4d6bee 100644 --- a/src/coreclr/src/jit/morph.cpp +++ b/src/coreclr/src/jit/morph.cpp @@ -2737,10 +2737,19 @@ 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(); -#endif +#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("Morphing Vararg call not yet implemented on non Windows targets."); + } +#endif // _TARGET_UNIX_ #ifdef UNIX_AMD64_ABI // If fgMakeOutgoingStructArgCopy is called and copies are generated, hasStackArgCopy is set diff --git a/src/coreclr/src/vm/jitinterface.cpp b/src/coreclr/src/vm/jitinterface.cpp index ff8a89d..0a921e5 100644 --- a/src/coreclr/src/vm/jitinterface.cpp +++ b/src/coreclr/src/vm/jitinterface.cpp @@ -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) diff --git a/src/coreclr/tests/arm/Tests.lst b/src/coreclr/tests/arm/Tests.lst index 148d63b..9633cf6 100644 --- a/src/coreclr/tests/arm/Tests.lst +++ b/src/coreclr/tests/arm/Tests.lst @@ -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 @@ -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 diff --git a/src/coreclr/tests/arm64/Tests.lst b/src/coreclr/tests/arm64/Tests.lst index 574fb25..8c8fd8e 100644 --- a/src/coreclr/tests/arm64/Tests.lst +++ b/src/coreclr/tests/arm64/Tests.lst @@ -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 diff --git a/src/coreclr/tests/issues.targets b/src/coreclr/tests/issues.targets index aed787d..1772f8c 100644 --- a/src/coreclr/tests/issues.targets +++ b/src/coreclr/tests/issues.targets @@ -190,6 +190,12 @@ 18056 + + Varargs supported on this platform + + + Varargs supported on this platform + -- 2.7.4