Skip to content

Commit 7088332

Browse files
VSadovelinor-fung
andauthored
Some more cleanups in Assembly/Binder/Loader area (#59590)
* moved default binder allocation to AppDomain::Create * allowNativeSkip parameter is unused. * Removed PEFile::IsResource and PEFile::IsIStream - these do not exist in CoreClr * make GCC happy * folded impl * Folded PEFile into PEAssembly * renamed pefile files * reorder PEAssembly members * removed meaningless LAYOUT_CREATEIFNEEDED - we always require that * r2r bundled image should Open via cache - no reasons not to. * Some cleanup in PEImage * PEAssembly needs only one reference to PEImage * a few tweaks * some more * We never update published hosted assemblies, no need to support the scenario. * Done with PEAssembly for now * couple fixes, mostly in comments afected by renames * more cleanups for PEImage * PR review suggestion Co-authored-by: Elinor Fung <[email protected]> * PR review feedback * this line should be deleted, not commented. * Apply suggestions from code review Co-authored-by: Elinor Fung <[email protected]> * More PR feedback Co-authored-by: Elinor Fung <[email protected]>
1 parent bda8727 commit 7088332

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1384
-2784
lines changed

src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ internal RuntimeType[] GetDefinedTypes()
3030
{
3131
return GetTypes(this);
3232
}
33-
34-
[MethodImpl(MethodImplOptions.InternalCall)]
35-
private static extern bool IsResource(RuntimeModule module);
3633
#endregion
3734

3835
#region Module overrides
@@ -472,7 +469,8 @@ public override Guid ModuleVersionId
472469

473470
public override bool IsResource()
474471
{
475-
return IsResource(this);
472+
// CoreClr does not support resource-only modules.
473+
return false;
476474
}
477475

478476
[RequiresUnreferencedCode("Fields might be removed")]

src/coreclr/binder/bindertracing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ namespace
147147
DomainAssembly *parentAssembly = spec->GetParentAssembly();
148148
if (parentAssembly != nullptr)
149149
{
150-
PEAssembly *peAssembly = parentAssembly->GetFile();
151-
_ASSERTE(peAssembly != nullptr);
152-
peAssembly->GetDisplayName(request.RequestingAssembly);
150+
PEAssembly *pPEAssembly = parentAssembly->GetPEAssembly();
151+
_ASSERTE(pPEAssembly != nullptr);
152+
pPEAssembly->GetDisplayName(request.RequestingAssembly);
153153

154154
AppDomain *domain = parentAssembly->GetAppDomain();
155-
AssemblyBinder *binder = peAssembly->GetAssemblyBinder();
155+
AssemblyBinder *binder = pPEAssembly->GetAssemblyBinder();
156156

157157
GetAssemblyLoadContextNameFromBinder(binder, domain, request.RequestingAssemblyLoadContext);
158158
}

src/coreclr/debug/createdump/crashinfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ CrashInfo::EnumerateManagedModules(IXCLRDataProcess* pClrDataProcess)
320320
if (SUCCEEDED(hr = moduleData.Request(pClrDataModule.GetPtr())))
321321
{
322322
TRACE("MODULE: %" PRIA PRIx64 " dyn %d inmem %d file %d pe %" PRIA PRIx64 " pdb %" PRIA PRIx64, (uint64_t)moduleData.LoadedPEAddress, moduleData.IsDynamic,
323-
moduleData.IsInMemory, moduleData.IsFileLayout, (uint64_t)moduleData.PEFile, (uint64_t)moduleData.InMemoryPdbAddress);
323+
moduleData.IsInMemory, moduleData.IsFileLayout, (uint64_t)moduleData.PEAssembly, (uint64_t)moduleData.InMemoryPdbAddress);
324324

325325
if (!moduleData.IsDynamic && moduleData.LoadedPEAddress != 0)
326326
{

src/coreclr/debug/daccess/daccess.cpp

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,6 @@ MetaEnum::New(Module* mod,
679679
*handle = TO_CDENUM(NULL);
680680
}
681681

682-
if (!mod->GetFile()->HasMetadata())
683-
{
684-
return S_FALSE;
685-
}
686-
687682
metaEnum = new (nothrow) MetaEnum;
688683
if (!metaEnum)
689684
{
@@ -4079,9 +4074,9 @@ ClrDataAccess::GetModuleByAddress(
40794074
{
40804075
TADDR base;
40814076
ULONG32 length;
4082-
PEFile* file = modDef->GetFile();
4077+
PEAssembly* pPEAssembly = modDef->GetPEAssembly();
40834078

4084-
if ((base = PTR_TO_TADDR(file->GetLoadedImageContents(&length))))
4079+
if ((base = PTR_TO_TADDR(pPEAssembly->GetLoadedImageContents(&length))))
40854080
{
40864081
if (TO_CDADDR(base) <= address &&
40874082
TO_CDADDR(base + length) > address)
@@ -4133,9 +4128,9 @@ ClrDataAccess::StartEnumMethodDefinitionsByAddress(
41334128
{
41344129
TADDR base;
41354130
ULONG32 length;
4136-
PEFile* file = modDef->GetFile();
4131+
PEAssembly* assembly = modDef->GetPEAssembly();
41374132

4138-
if ((base = PTR_TO_TADDR(file->GetLoadedImageContents(&length))))
4133+
if ((base = PTR_TO_TADDR(assembly->GetLoadedImageContents(&length))))
41394134
{
41404135
if (TO_CDADDR(base) <= address &&
41414136
TO_CDADDR(base + length) > address)
@@ -6459,7 +6454,7 @@ ClrDataAccess::GetHostGcNotificationTable()
64596454
}
64606455

64616456
/* static */ bool
6462-
ClrDataAccess::GetMetaDataFileInfoFromPEFile(PEFile *pPEFile,
6457+
ClrDataAccess::GetMetaDataFileInfoFromPEFile(PEAssembly *pPEAssembly,
64636458
DWORD &dwTimeStamp,
64646459
DWORD &dwSize,
64656460
DWORD &dwDataSize,
@@ -6477,7 +6472,7 @@ ClrDataAccess::GetMetaDataFileInfoFromPEFile(PEFile *pPEFile,
64776472
isNGEN = false;
64786473
if (pDir == NULL || pDir->Size == 0)
64796474
{
6480-
mdImage = pPEFile->GetILimage();
6475+
mdImage = pPEAssembly->GetPEImage();
64816476
if (mdImage != NULL)
64826477
{
64836478
layout = mdImage->GetLoadedLayout();
@@ -6526,7 +6521,7 @@ ClrDataAccess::GetMetaDataFileInfoFromPEFile(PEFile *pPEFile,
65266521
}
65276522

65286523
/* static */
6529-
bool ClrDataAccess::GetILImageInfoFromNgenPEFile(PEFile *peFile,
6524+
bool ClrDataAccess::GetILImageInfoFromNgenPEFile(PEAssembly *pPEAssembly,
65306525
DWORD &dwTimeStamp,
65316526
DWORD &dwSize,
65326527
__out_ecount(cchFilePath) LPWSTR wszFilePath,
@@ -6536,10 +6531,10 @@ bool ClrDataAccess::GetILImageInfoFromNgenPEFile(PEFile *peFile,
65366531
DWORD dwWritten = 0;
65376532

65386533
// use the IL File name
6539-
if (!peFile->GetPath().DacGetUnicode(cchFilePath, wszFilePath, (COUNT_T *)(&dwWritten)))
6534+
if (!pPEAssembly->GetPath().DacGetUnicode(cchFilePath, wszFilePath, (COUNT_T *)(&dwWritten)))
65406535
{
65416536
// Use DAC hint to retrieve the IL name.
6542-
peFile->GetModuleFileNameHint().DacGetUnicode(cchFilePath, wszFilePath, (COUNT_T *)(&dwWritten));
6537+
pPEAssembly->GetModuleFileNameHint().DacGetUnicode(cchFilePath, wszFilePath, (COUNT_T *)(&dwWritten));
65436538
}
65446539
dwTimeStamp = 0;
65456540
dwSize = 0;
@@ -6603,7 +6598,7 @@ bool ClrDataAccess::GetILImageNameFromNgenImage( LPCWSTR ilExtension,
66036598
#endif // FEATURE_CORESYSTEM
66046599

66056600
void *
6606-
ClrDataAccess::GetMetaDataFromHost(PEFile* peFile,
6601+
ClrDataAccess::GetMetaDataFromHost(PEAssembly* pPEAssembly,
66076602
bool* isAlternate)
66086603
{
66096604
DWORD imageTimestamp, imageSize, dataSize;
@@ -6634,7 +6629,7 @@ ClrDataAccess::GetMetaDataFromHost(PEFile* peFile,
66346629
// so the field remains for now.
66356630

66366631
if (!ClrDataAccess::GetMetaDataFileInfoFromPEFile(
6637-
peFile,
6632+
pPEAssembly,
66386633
imageTimestamp,
66396634
imageSize,
66406635
dataSize,
@@ -6647,7 +6642,7 @@ ClrDataAccess::GetMetaDataFromHost(PEFile* peFile,
66476642
}
66486643

66496644
// try direct match for the image that is loaded into the managed process
6650-
peFile->GetLoadedMetadata((COUNT_T *)(&dataSize));
6645+
pPEAssembly->GetLoadedMetadata((COUNT_T *)(&dataSize));
66516646

66526647
DWORD allocSize = 0;
66536648
if (!ClrSafeInt<DWORD>::addition(dataSize, sizeof(DAC_INSTANCE), allocSize))
@@ -6665,7 +6660,7 @@ ClrDataAccess::GetMetaDataFromHost(PEFile* peFile,
66656660
buffer = (void*)(inst + 1);
66666661

66676662
// APIs implemented by hosting debugger. It can use the path/filename, timestamp, and
6668-
// file size to find an exact match for the image. If that fails for an ngen'ed image,
6663+
// pPEAssembly size to find an exact match for the image. If that fails for an ngen'ed image,
66696664
// we can request the IL image which it came from.
66706665
if (m_legacyMetaDataLocator)
66716666
{
@@ -6701,7 +6696,7 @@ ClrDataAccess::GetMetaDataFromHost(PEFile* peFile,
67016696
//
67026697
isAlt = true;
67036698
if (!ClrDataAccess::GetILImageInfoFromNgenPEFile(
6704-
peFile,
6699+
pPEAssembly,
67056700
imageTimestamp,
67066701
imageSize,
67076702
uniPath,
@@ -6781,13 +6776,13 @@ ClrDataAccess::GetMetaDataFromHost(PEFile* peFile,
67816776

67826777
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
67836778
//
6784-
// Given a PEFile or a ReflectionModule try to find the corresponding metadata
6779+
// Given a PEAssembly or a ReflectionModule try to find the corresponding metadata
67856780
// We will first ask debugger to locate it. If fail, we will try
67866781
// to get it from the target process
67876782
//
67886783
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
67896784
IMDInternalImport*
6790-
ClrDataAccess::GetMDImport(const PEFile* peFile, const ReflectionModule* reflectionModule, bool throwEx)
6785+
ClrDataAccess::GetMDImport(const PEAssembly* pPEAssembly, const ReflectionModule* reflectionModule, bool throwEx)
67916786
{
67926787
HRESULT status;
67936788
PTR_CVOID mdBaseTarget = NULL;
@@ -6796,22 +6791,22 @@ ClrDataAccess::GetMDImport(const PEFile* peFile, const ReflectionModule* reflect
67966791
PVOID mdBaseHost = NULL;
67976792
bool isAlternate = false;
67986793

6799-
_ASSERTE((peFile == NULL && reflectionModule != NULL) || (peFile != NULL && reflectionModule == NULL));
6800-
TADDR peFileAddr = (peFile != NULL) ? dac_cast<TADDR>(peFile) : dac_cast<TADDR>(reflectionModule);
6794+
_ASSERTE((pPEAssembly == NULL && reflectionModule != NULL) || (pPEAssembly != NULL && reflectionModule == NULL));
6795+
TADDR peAssemblyAddr = (pPEAssembly != NULL) ? dac_cast<TADDR>(pPEAssembly) : dac_cast<TADDR>(reflectionModule);
68016796

68026797
//
68036798
// Look for one we've already created.
68046799
//
6805-
mdImport = m_mdImports.Get(peFileAddr);
6800+
mdImport = m_mdImports.Get(peAssemblyAddr);
68066801
if (mdImport != NULL)
68076802
{
68086803
return mdImport;
68096804
}
68106805

6811-
if (peFile != NULL)
6806+
if (pPEAssembly != NULL)
68126807
{
68136808
// Get the metadata size
6814-
mdBaseTarget = ((PEFile*)peFile)->GetLoadedMetadata(&mdSize);
6809+
mdBaseTarget = const_cast<PEAssembly*>(pPEAssembly)->GetLoadedMetadata(&mdSize);
68156810
}
68166811
else if (reflectionModule != NULL)
68176812
{
@@ -6862,12 +6857,12 @@ ClrDataAccess::GetMDImport(const PEFile* peFile, const ReflectionModule* reflect
68626857
}
68636858

68646859
// Try to see if debugger can locate it
6865-
if (peFile != NULL && mdBaseHost == NULL && (m_target3 || m_legacyMetaDataLocator))
6860+
if (pPEAssembly != NULL && mdBaseHost == NULL && (m_target3 || m_legacyMetaDataLocator))
68666861
{
68676862
// We couldn't read the metadata from memory. Ask
68686863
// the target for metadata as it may be able to
68696864
// provide it from some alternate means.
6870-
mdBaseHost = GetMetaDataFromHost(const_cast<PEFile *>(peFile), &isAlternate);
6865+
mdBaseHost = GetMetaDataFromHost(const_cast<PEAssembly *>(pPEAssembly), &isAlternate);
68716866
}
68726867

68736868
if (mdBaseHost == NULL)
@@ -6902,7 +6897,7 @@ ClrDataAccess::GetMDImport(const PEFile* peFile, const ReflectionModule* reflect
69026897
// The m_mdImports list does get cleaned up by calls to ClrDataAccess::Flush,
69036898
// i.e. every time the process changes state.
69046899

6905-
if (m_mdImports.Add(peFileAddr, mdImport, isAlternate) == NULL)
6900+
if (m_mdImports.Add(peAssemblyAddr, mdImport, isAlternate) == NULL)
69066901
{
69076902
mdImport->Release();
69086903
DacError(E_OUTOFMEMORY);
@@ -6970,9 +6965,9 @@ HRESULT ClrDataAccess::VerifyDlls()
69706965
}
69716966

69726967
// Read the debug directory timestamp from the target mscorwks image using DAC
6973-
// Note that we don't use the PE timestamp because the PE file might be changed in ways
6968+
// Note that we don't use the PE timestamp because the PE pPEAssembly might be changed in ways
69746969
// that don't effect the PDB (and therefore don't effect DAC). Specifically, we rebase
6975-
// our DLLs at the end of a build, that changes the PE file, but not the PDB.
6970+
// our DLLs at the end of a build, that changes the PE pPEAssembly, but not the PDB.
69766971
// Note that if we wanted to be extra careful, we could read the CV contents (which includes
69776972
// the GUID signature) and verify it matches. Using the timestamp is useful for helpful error
69786973
// messages, and should be sufficient in any real scenario.

0 commit comments

Comments
 (0)