Skip to content

Commit

Permalink
Fixes Issue dotnet/coreclr#20262 for CoreCLR 5.0 (dotnet/coreclr#25926)
Browse files Browse the repository at this point in the history
Disassembler:  ildasm/dasm.cpp

 In the CoreCLR with reference assemblies and redirection it is more difficult to determine if
 a particular Assembly is the System assembly, like mscorlib.dll is for the Desktop CLR.
 In the CoreCLR runtimes, the System assembly can be System.Private.CoreLib.dll, System.Runtime.dll
 or netstandard.dll and in the future a different Assembly name could be used.
 We now determine the identity of the System assembly by querying if the Assembly defines the
 well known type System.Object as that type must be defined by the System assembly
 If this type is defined then we will output the ".mscorlib" directive to indicate that this
 assembly is the System assembly.

Assembler:  ilasm/assembler.cpp

 In Assembler:GetBaseAsmRef() add a check for System.Private.CoreLib as the System or Base assembly.

Commit migrated from dotnet/coreclr@cb86146
  • Loading branch information
briansull authored Jul 31, 2019
1 parent fa19218 commit 88f7610
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 38 deletions.
8 changes: 8 additions & 0 deletions src/coreclr/src/ilasm/assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ mdToken Assembler::GetAsmRef(__in __nullterminated const char* szName)

mdToken Assembler::GetBaseAsmRef()
{
// First we check for "System.Private.CoreLib" as the base or System assembly
//
AsmManAssembly* coreLibAsm = m_pManifest->GetAsmRefByAsmName("System.Private.CoreLib");
if(coreLibAsm != NULL)
{
return GetAsmRef(coreLibAsm->szAlias ? coreLibAsm->szAlias : coreLibAsm->szName);
}

AsmManAssembly* sysRuntime = m_pManifest->GetAsmRefByAsmName("System.Runtime");
if(sysRuntime != NULL)
{
Expand Down
77 changes: 39 additions & 38 deletions src/coreclr/src/ildasm/dasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,50 +895,51 @@ bool HasSuppressingAttribute()
#endif
void DumpMscorlib(void* GUICookie)
{
if(g_pAssemblyImport==NULL) g_pAssemblyImport = GetAssemblyImport(GUICookie);
if(g_pAssemblyImport!=NULL)
{
mdAssembly tkAsm;
if(SUCCEEDED(g_pAssemblyImport->GetAssemblyFromScope(&tkAsm))&&(tkAsm != mdAssemblyNil))
{
const void* pPublicKey;
ULONG cbPublicKey = 0;
ULONG ulHashAlgId;
WCHAR wzName[1024];
ULONG ulNameLen=0;
ASSEMBLYMETADATA md;
WCHAR wzLocale[1024];
DWORD dwFlags;
//char szString[4096];

md.szLocale = wzLocale;
md.cbLocale = 1024;
md.rProcessor = NULL;
md.ulProcessor = 0;
md.rOS = NULL;
md.ulOS = 0;

if(SUCCEEDED(g_pAssemblyImport->GetAssemblyProps( // S_OK or error.
tkAsm, // [IN] The Assembly for which to get the properties.
&pPublicKey, // [OUT] Pointer to the public key.
&cbPublicKey,// [OUT] Count of bytes in the public key.
&ulHashAlgId,// [OUT] Hash Algorithm.
wzName, // [OUT] Buffer to fill with name.
1024, // [IN] Size of buffer in wide chars.
&ulNameLen, // [OUT] Actual # of wide chars in name.
&md, // [OUT] Assembly MetaData.
&dwFlags))) // [OUT] Flags.
// In the CoreCLR with reference assemblies and redirection it is more difficult to determine if
// a particular Assembly is the System assembly, like mscorlib.dll is for the Desktop CLR.
// In the CoreCLR runtimes, the System assembly can be System.Private.CoreLib.dll, System.Runtime.dll
// or netstandard.dll and in the future a different Assembly name could be used.
// We now determine the identity of the System assembly by querying if the Assembly defines the
// well known type System.Object as that type must be defined by the System assembly
// If this type is defined then we will output the ".mscorlib" directive to indicate that this
// assembly is the System assembly.
//
mdTypeDef tkObjectTypeDef = mdTypeDefNil;

// Lookup the type System.Object and see it it has a type definition in this assembly
if (SUCCEEDED(g_pPubImport->FindTypeDefByName(W("System.Object"), mdTypeDefNil, &tkObjectTypeDef)))
{
if (tkObjectTypeDef != mdTypeDefNil)
{
// We do have a type definition for System.Object in this assembly
//
DWORD dwClassAttrs = 0;
mdToken tkExtends = mdTypeDefNil;

// Retrieve the type def properties as well, so that we can check a few more things about
// the System.Object type
//
if (SUCCEEDED(g_pPubImport->GetTypeDefProps(tkObjectTypeDef, NULL, NULL, 0, &dwClassAttrs, &tkExtends)))
{
if(wcscmp(wzName,W("mscorlib")) == 0)
bool bExtends = g_pPubImport->IsValidToken(tkExtends);
bool isClass = ((dwClassAttrs & tdClassSemanticsMask) == tdClass);

// We also check the type properties to make sure that we have a class and not a Value type definition
// and that this type definition isn't extending another type.
//
if (isClass & !bExtends)
{
printLine(GUICookie,"");
sprintf_s(szString,SZSTRING_SIZE,"%s%s ",g_szAsmCodeIndent,KEYWORD(".mscorlib"));
printLine(GUICookie,szString);
printLine(GUICookie,"");
// We will mark this assembly with the System assembly directive: .mscorlib
//
printLine(GUICookie, "");
sprintf_s(szString, SZSTRING_SIZE, "%s%s ", g_szAsmCodeIndent, KEYWORD(".mscorlib"));
printLine(GUICookie, szString);
printLine(GUICookie, "");
}
}
}
}

}
void DumpTypelist(void* GUICookie)
{
Expand Down

0 comments on commit 88f7610

Please sign in to comment.