Skip to content

Commit 6abfacb

Browse files
parjongjkotas
authored andcommittedAug 12, 2016
Enable FEATURE_STUBS_AS_IL for ARM/Linux (dotnet#6500)
This commit enables FEATURE_STUBS_AS_IL for ARM/Linux. This commit tries to fix #6452.
1 parent 7912013 commit 6abfacb

13 files changed

+102
-13
lines changed
 

‎clr.coreclr.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
<FeaturePal>true</FeaturePal>
8383
<FeatureXplatEventSource>true</FeatureXplatEventSource>
8484

85-
<FeatureStubsAsIL Condition="'$(TargetArch)' != 'arm'">true</FeatureStubsAsIL>
85+
<FeatureStubsAsIL>true</FeatureStubsAsIL>
8686

8787
<!-- Windows specific features -->
8888
<FeatureWin32Registry>false</FeatureWin32Registry>

‎clrdefinitions.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ endif(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_I386)
160160
add_definitions(-DFEATURE_STANDALONE_SN)
161161
add_definitions(-DFEATURE_STRONGNAME_DELAY_SIGNING_ALLOWED)
162162
add_definitions(-DFEATURE_STRONGNAME_MIGRATION)
163-
if ((CLR_CMAKE_PLATFORM_UNIX OR CLR_CMAKE_TARGET_ARCH_ARM64) AND NOT CLR_CMAKE_TARGET_ARCH_ARM)
163+
if (CLR_CMAKE_PLATFORM_UNIX OR CLR_CMAKE_TARGET_ARCH_ARM64)
164164
add_definitions(-DFEATURE_STUBS_AS_IL)
165165
endif ()
166166
add_definitions(-DFEATURE_SVR_GC)

‎src/inc/corinfo.h

+10-5
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,11 @@ TODO: Talk about initializing strutures before use
231231
#if COR_JIT_EE_VERSION > 460
232232

233233
// Update this one
234-
SELECTANY const GUID JITEEVersionIdentifier = { /* 718c4238-2a85-45de-88ad-9b1fed806547 */
235-
0x718c4238,
236-
0x2a85,
237-
0x45de,
238-
{ 0x88, 0xad, 0x9b, 0x1f, 0xed, 0x80, 0x65, 0x47 }
234+
SELECTANY const GUID JITEEVersionIdentifier = { /* 0b17dfeb-1ead-4e06-b025-d60d3a493b53 */
235+
0x0b17dfeb,
236+
0x1ead,
237+
0x4e06,
238+
{ 0xb0, 0x25, 0xd6, 0x0d, 0x3a, 0x49, 0x3b, 0x53 }
239239
};
240240

241241
#else
@@ -1686,6 +1686,8 @@ struct CORINFO_CALL_INFO
16861686
};
16871687

16881688
CORINFO_CONST_LOOKUP instParamLookup; // Used by Ready-to-Run
1689+
1690+
BOOL secureDelegateInvoke;
16891691
};
16901692

16911693
//----------------------------------------------------------------------------
@@ -1808,6 +1810,9 @@ struct CORINFO_EE_INFO
18081810
unsigned offsetOfDelegateInstance;
18091811
unsigned offsetOfDelegateFirstTarget;
18101812

1813+
// Secure delegate offsets
1814+
unsigned offsetOfSecureDelegateIndirectCell;
1815+
18111816
// Remoting offsets
18121817
unsigned offsetOfTransparentProxyRP;
18131818
unsigned offsetOfRealProxyServer;

‎src/jit/codegenlegacy.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -18418,7 +18418,6 @@ regMaskTP CodeGen::genLoadIndirectCallTarget(GenTreePtr call)
1841818418
* register mask that describes where the result will be found is returned;
1841918419
* otherwise, RBM_NONE is returned.
1842018420
*/
18421-
1842218421
#ifdef _PREFAST_
1842318422
#pragma warning(push)
1842418423
#pragma warning(disable : 21000) // Suppress PREFast warning about overly large function
@@ -18837,6 +18836,14 @@ regMaskTP CodeGen::genCodeForCall(GenTreePtr call, bool valUsed)
1883718836
instOffs = pInfo->offsetOfDelegateInstance;
1883818837
firstTgtOffs = pInfo->offsetOfDelegateFirstTarget;
1883918838

18839+
#ifdef _TARGET_ARM_
18840+
if ((call->gtCall.gtCallMoreFlags & GTF_CALL_M_SECURE_DELEGATE_INV))
18841+
{
18842+
getEmitter()->emitIns_R_R_I(INS_add, EA_PTRSIZE, REG_VIRTUAL_STUB_PARAM, regThis, pInfo->offsetOfSecureDelegateIndirectCell);
18843+
regTracker.rsTrackRegTrash(REG_VIRTUAL_STUB_PARAM);
18844+
}
18845+
#endif // _TARGET_ARM_
18846+
1884018847
// Grab an available register to use for the CALL indirection
1884118848
regNumber indCallReg = regSet.rsGrabReg(RBM_ALLINT);
1884218849

‎src/jit/gentree.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -2929,8 +2929,9 @@ struct GenTreeCall final : public GenTree
29292929
// a Pinvoke but not as an unmanaged call. See impCheckForPInvokeCall() to
29302930
// know when these flags are set.
29312931

2932-
#define GTF_CALL_M_R2R_REL_INDIRECT 0x2000 // GT_CALL -- ready to run call is indirected through a relative address
2933-
#define GTF_CALL_M_DOES_NOT_RETURN 0x4000 // GT_CALL -- call does not return
2932+
#define GTF_CALL_M_R2R_REL_INDIRECT 0x2000 // GT_CALL -- ready to run call is indirected through a relative address
2933+
#define GTF_CALL_M_DOES_NOT_RETURN 0x4000 // GT_CALL -- call does not return
2934+
#define GTF_CALL_M_SECURE_DELEGATE_INV 0x8000 // GT_CALL -- call is in secure delegate
29342935

29352936
bool IsUnmanaged() const
29362937
{

‎src/jit/importer.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -6586,6 +6586,11 @@ var_types Compiler::impImportCall(OPCODE opcode,
65866586
/* Set the delegate flag */
65876587
call->gtCall.gtCallMoreFlags |= GTF_CALL_M_DELEGATE_INV;
65886588

6589+
if (callInfo->secureDelegateInvoke)
6590+
{
6591+
call->gtCall.gtCallMoreFlags |= GTF_CALL_M_SECURE_DELEGATE_INV;
6592+
}
6593+
65896594
if (opcode == CEE_CALLVIRT)
65906595
{
65916596
assert(mflags & CORINFO_FLG_FINAL);

‎src/vm/comdelegate.cpp

+42-2
Original file line numberDiff line numberDiff line change
@@ -2596,7 +2596,7 @@ BOOL COMDelegate::NeedsWrapperDelegate(MethodDesc* pTargetMD)
25962596
#ifdef _TARGET_ARM_
25972597
// For arm VSD expects r4 to contain the indirection cell. However r4 is a non-volatile register
25982598
// and its value must be preserved. So we need to erect a frame and store indirection cell in r4 before calling
2599-
// virtual stub dispatch. Erecting frame is already done by secure delegates so the secureDelegate infrastructure
2599+
// virtual stub dispatch. Erecting frame is already done by secure delegates so the secureDelegate infrastructure
26002600
// can easliy be used for our purpose.
26012601
// set needsSecureDelegate flag in order to erect a frame. (Secure Delegate stub also loads the right value in r4)
26022602
if (!pTargetMD->IsStatic() && pTargetMD->IsVirtual() && !pTargetMD->GetMethodTable()->IsValueType())
@@ -2931,7 +2931,47 @@ PCODE COMDelegate::GetSecureInvoke(MethodDesc* pMD)
29312931
#ifdef FEATURE_CAS_POLICY
29322932
#error GetSecureInvoke not implemented
29332933
#else
2934-
UNREACHABLE();
2934+
GCX_PREEMP();
2935+
2936+
MetaSig sig(pMD);
2937+
2938+
BOOL fReturnVal = !sig.IsReturnTypeVoid();
2939+
2940+
SigTypeContext emptyContext;
2941+
ILStubLinker sl(pMD->GetModule(), pMD->GetSignature(), &emptyContext, pMD, TRUE, TRUE, FALSE);
2942+
2943+
ILCodeStream *pCode = sl.NewCodeStream(ILStubLinker::kDispatch);
2944+
2945+
// Load the "real" delegate
2946+
pCode->EmitLoadThis();
2947+
pCode->EmitLDFLD(pCode->GetToken(MscorlibBinder::GetField(FIELD__MULTICAST_DELEGATE__INVOCATION_LIST)));
2948+
2949+
// Load the arguments
2950+
UINT paramCount = 0;
2951+
while(paramCount < sig.NumFixedArgs())
2952+
pCode->EmitLDARG(paramCount++);
2953+
2954+
// Call the delegate
2955+
pCode->EmitCALL(pCode->GetToken(pMD), sig.NumFixedArgs(), fReturnVal);
2956+
2957+
// Return
2958+
pCode->EmitRET();
2959+
2960+
PCCOR_SIGNATURE pSig;
2961+
DWORD cbSig;
2962+
2963+
pMD->GetSig(&pSig,&cbSig);
2964+
2965+
MethodDesc* pStubMD =
2966+
ILStubCache::CreateAndLinkNewILStubMethodDesc(pMD->GetLoaderAllocator(),
2967+
pMD->GetMethodTable(),
2968+
ILSTUB_SECUREDELEGATE_INVOKE,
2969+
pMD->GetModule(),
2970+
pSig, cbSig,
2971+
NULL,
2972+
&sl);
2973+
2974+
return Stub::NewStub(JitILStub(pStubMD))->GetEntryPoint();
29352975
#endif
29362976
}
29372977
#else // FEATURE_STUBS_AS_IL

‎src/vm/dllimport.h

+2
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ enum ILStubTypes
215215
ILSTUB_MULTICASTDELEGATE_INVOKE = 0x80000010,
216216
ILSTUB_UNBOXINGILSTUB = 0x80000020,
217217
ILSTUB_INSTANTIATINGSTUB = 0x80000040,
218+
ILSTUB_SECUREDELEGATE_INVOKE = 0x80000080,
218219
#endif
219220
};
220221

@@ -245,6 +246,7 @@ inline bool SF_IsArrayOpStub (DWORD dwStubFlags) { LIMITED_METHOD_CONT
245246
#endif
246247

247248
#ifdef FEATURE_STUBS_AS_IL
249+
inline bool SF_IsSecureDelegateStub (DWORD dwStubFlags) { LIMITED_METHOD_CONTRACT; return (dwStubFlags == ILSTUB_SECUREDELEGATE_INVOKE); }
248250
inline bool SF_IsMulticastDelegateStub (DWORD dwStubFlags) { LIMITED_METHOD_CONTRACT; return (dwStubFlags == ILSTUB_MULTICASTDELEGATE_INVOKE); }
249251
inline bool SF_IsUnboxingILStub (DWORD dwStubFlags) { LIMITED_METHOD_CONTRACT; return (dwStubFlags == ILSTUB_UNBOXINGILSTUB); }
250252
inline bool SF_IsInstantiatingStub (DWORD dwStubFlags) { LIMITED_METHOD_CONTRACT; return (dwStubFlags == ILSTUB_INSTANTIATINGSTUB); }

‎src/vm/ilstubcache.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ MethodDesc* ILStubCache::CreateNewMethodDesc(LoaderHeap* pCreationHeap, MethodTa
217217
else
218218
#endif
219219
#ifdef FEATURE_STUBS_AS_IL
220+
if (SF_IsSecureDelegateStub(dwStubFlags))
221+
{
222+
pMD->m_dwExtendedFlags |= DynamicMethodDesc::nomdSecureDelegateStub;
223+
pMD->GetILStubResolver()->SetStubType(ILStubResolver::SecureDelegateStub);
224+
}
225+
else
220226
if (SF_IsMulticastDelegateStub(dwStubFlags))
221227
{
222228
pMD->m_dwExtendedFlags |= DynamicMethodDesc::nomdMulticastStub;

‎src/vm/ilstubresolver.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ LPCUTF8 ILStubResolver::GetStubMethodName()
9191
case MulticastDelegateStub: return "IL_STUB_MulticastDelegate_Invoke";
9292
case UnboxingILStub: return "IL_STUB_UnboxingStub";
9393
case InstantiatingStub: return "IL_STUB_InstantiatingStub";
94+
case SecureDelegateStub: return "IL_STUB_SecureDelegate_Invoke";
9495
#endif
9596
default:
9697
UNREACHABLE_MSG("Unknown stub type");

‎src/vm/ilstubresolver.h

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class ILStubResolver : DynamicResolver
8383
ArrayOpStub,
8484
#endif
8585
#ifdef FEATURE_STUBS_AS_IL
86+
SecureDelegateStub,
8687
MulticastDelegateStub,
8788
UnboxingILStub,
8889
InstantiatingStub,

‎src/vm/jitinterface.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -5169,7 +5169,6 @@ void CEEInfo::getCallInfo(
51695169
bool resolvedCallVirt = false;
51705170
bool callVirtCrossingVersionBubble = false;
51715171

5172-
51735172
// Delegate targets are always treated as direct calls here. (It would be nice to clean it up...).
51745173
if (flags & CORINFO_CALLINFO_LDFTN)
51755174
{
@@ -5686,6 +5685,19 @@ void CEEInfo::getCallInfo(
56865685
}
56875686
}
56885687

5688+
pResult->secureDelegateInvoke = FALSE;
5689+
5690+
#ifdef FEATURE_STUBS_AS_IL
5691+
if (m_pMethodBeingCompiled->IsDynamicMethod())
5692+
{
5693+
auto pMD = m_pMethodBeingCompiled->AsDynamicMethodDesc();
5694+
if (pMD->IsILStub() && pMD->IsSecureDelegateStub())
5695+
{
5696+
pResult->secureDelegateInvoke = TRUE;
5697+
}
5698+
}
5699+
#endif
5700+
56895701
EE_TO_JIT_TRANSITION();
56905702
}
56915703

@@ -9630,6 +9642,9 @@ void CEEInfo::getEEInfo(CORINFO_EE_INFO *pEEInfoOut)
96309642
pEEInfoOut->offsetOfDelegateInstance = DelegateObject::GetOffsetOfTarget();
96319643
pEEInfoOut->offsetOfDelegateFirstTarget = DelegateObject::GetOffsetOfMethodPtr();
96329644

9645+
// Secure delegate offsets
9646+
pEEInfoOut->offsetOfSecureDelegateIndirectCell = DelegateObject::GetOffsetOfMethodPtrAux();
9647+
96339648
// Remoting offsets
96349649
pEEInfoOut->offsetOfTransparentProxyRP = TransparentProxyObject::GetOffsetOfRP();
96359650
pEEInfoOut->offsetOfRealProxyServer = RealProxyObject::GetOffsetOfServerObject();

‎src/vm/method.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -2304,6 +2304,7 @@ class DynamicMethodDesc : public StoredSigMethodDesc
23042304
nomdStubNeedsCOMStarted = 0x0800, // EnsureComStarted must be called before executing the method
23052305
nomdMulticastStub = 0x1000,
23062306
nomdUnboxingILStub = 0x2000,
2307+
nomdSecureDelegateStub = 0x4000,
23072308

23082309
nomdILStub = 0x00010000,
23092310
nomdLCGMethod = 0x00020000,
@@ -2412,6 +2413,11 @@ class DynamicMethodDesc : public StoredSigMethodDesc
24122413
bool IsSignatureNeedsRestore() { LIMITED_METHOD_CONTRACT; _ASSERTE(IsILStub()); return (0 != (m_dwExtendedFlags & nomdSignatureNeedsRestore)); }
24132414
bool IsStubNeedsCOMStarted() { LIMITED_METHOD_CONTRACT; _ASSERTE(IsILStub()); return (0 != (m_dwExtendedFlags & nomdStubNeedsCOMStarted)); }
24142415
#ifdef FEATURE_STUBS_AS_IL
2416+
bool IsSecureDelegateStub() {
2417+
LIMITED_METHOD_DAC_CONTRACT;
2418+
_ASSERTE(IsILStub());
2419+
return !!(m_dwExtendedFlags & nomdSecureDelegateStub);
2420+
}
24152421
bool IsMulticastStub() {
24162422
LIMITED_METHOD_DAC_CONTRACT;
24172423
_ASSERTE(IsILStub());

0 commit comments

Comments
 (0)
Please sign in to comment.