Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike McLaughlin <mikem@microsoft.com>2021-02-21 00:51:39 +0300
committerGitHub <noreply@github.com>2021-02-21 00:51:39 +0300
commitf30a71824ed1c53848799b35d35cc0324e0752f1 (patch)
tree0da7848d02567864654605d9a9db1a228c4617bd /src/coreclr/ilasm
parentbc9259e7a8a9a9aebd91f367117c6909db1aafcf (diff)
Enable Hot Reload API on Linux (#48497)
Enable Hot Reload API on Linux Only define EnC_SUPPORTED for vm/ee on xplat. Doesn't enable the ENC ICorDebug API. Enable hotreload api tests on Linux/MacOS. API not implemented on arm/arm64 Remove all the ENC_DELTA_HACK code. Remove more ENC_DELTA_HACK code from ilasm
Diffstat (limited to 'src/coreclr/ilasm')
-rw-r--r--src/coreclr/ilasm/CMakeLists.txt1
-rw-r--r--src/coreclr/ilasm/asmman.cpp3
-rw-r--r--src/coreclr/ilasm/assem.cpp38
-rw-r--r--src/coreclr/ilasm/assembler.h6
-rw-r--r--src/coreclr/ilasm/main.cpp37
-rw-r--r--src/coreclr/ilasm/writer.cpp11
-rw-r--r--src/coreclr/ilasm/writer_enc.cpp501
7 files changed, 9 insertions, 588 deletions
diff --git a/src/coreclr/ilasm/CMakeLists.txt b/src/coreclr/ilasm/CMakeLists.txt
index 3e6c15b657a..3d385551b93 100644
--- a/src/coreclr/ilasm/CMakeLists.txt
+++ b/src/coreclr/ilasm/CMakeLists.txt
@@ -13,7 +13,6 @@ include_directories(.)
set(ILASM_SOURCES
assem.cpp
writer.cpp
- writer_enc.cpp
method.cpp
asmman.cpp
main.cpp
diff --git a/src/coreclr/ilasm/asmman.cpp b/src/coreclr/ilasm/asmman.cpp
index dc45b8f9f01..55fbeb06de7 100644
--- a/src/coreclr/ilasm/asmman.cpp
+++ b/src/coreclr/ilasm/asmman.cpp
@@ -843,8 +843,7 @@ HRESULT AsmMan::EmitManifest()
EmitFiles();
EmitAssembly();
- if((((Assembler*)m_pAssembler)->m_dwIncludeDebugInfo != 0) && (m_pAssembly == NULL)
- && !(((Assembler*)m_pAssembler)->m_fENCMode))
+ if((((Assembler*)m_pAssembler)->m_dwIncludeDebugInfo != 0) && (m_pAssembly == NULL))
{
mdToken tkOwner, tkMscorlib;
tkMscorlib = ((Assembler*)m_pAssembler)->GetAsmRef("mscorlib");
diff --git a/src/coreclr/ilasm/assem.cpp b/src/coreclr/ilasm/assem.cpp
index db89a880a0e..286447b4ec1 100644
--- a/src/coreclr/ilasm/assem.cpp
+++ b/src/coreclr/ilasm/assem.cpp
@@ -40,7 +40,6 @@ Assembler::Assembler()
m_fStdMapping = FALSE;
m_fDisplayTraceOutput= FALSE;
- m_fENCMode = FALSE;
m_fTolerateDupMethods = FALSE;
m_pCurOutputPos = NULL;
@@ -534,41 +533,21 @@ BOOL Assembler::EmitMethodBody(Method* pMethod, BinStr* pbsOut)
BYTE* outBuff;
unsigned align = (headerSize == 1)? 1 : 4;
ULONG PEFileOffset, methodRVA;
- if(m_fENCMode)
- {
- if(pbsOut)
- {
- PEFileOffset = pbsOut->length();
- align--;
- while(PEFileOffset & align)
- {
- pbsOut->appendInt8(0);
- PEFileOffset++;
- }
- pbsOut->append(pbsBody);
- outBuff = (BYTE*)(pbsOut->ptr()) + (pbsOut->length() - pbsBody->length());
- }
- else return FALSE;
- }
- else
- {
- if (FAILED(m_pCeeFileGen->GetSectionBlock (m_pILSection, totalSize,
- align, (void **) &outBuff))) return FALSE;
- memcpy(outBuff,pbsBody->ptr(),totalSize);
- // The offset where we start, (not where the alignment bytes start!
- if (FAILED(m_pCeeFileGen->GetSectionDataLen (m_pILSection, &PEFileOffset)))
- return FALSE;
- PEFileOffset -= totalSize;
- }
+ if (FAILED(m_pCeeFileGen->GetSectionBlock (m_pILSection, totalSize,
+ align, (void **) &outBuff))) return FALSE;
+ memcpy(outBuff,pbsBody->ptr(),totalSize);
+ // The offset where we start, (not where the alignment bytes start!
+ if (FAILED(m_pCeeFileGen->GetSectionDataLen (m_pILSection, &PEFileOffset)))
+ return FALSE;
+ PEFileOffset -= totalSize;
pMethod->m_pCode = outBuff + headerSize;
pMethod->m_headerOffset= PEFileOffset;
pMethod->m_methodOffset= PEFileOffset + headerSize;
DoDeferredILFixups(pMethod);
- if(m_fENCMode) methodRVA = PEFileOffset;
- else m_pCeeFileGen->GetMethodRVA(m_pCeeFile, PEFileOffset,&methodRVA);
+ m_pCeeFileGen->GetMethodRVA(m_pCeeFile, PEFileOffset,&methodRVA);
pMethod->m_headerOffset= methodRVA;
pMethod->m_methodOffset= methodRVA + headerSize;
@@ -881,7 +860,6 @@ BOOL Assembler::EmitMethodImpls()
int i;
for(i=0; (pMID = m_MethodImplDList.PEEK(i)); i++)
{
- if(m_fENCMode && (!pMID->m_fNew)) continue;
pMID->m_tkImplementingMethod = ResolveLocalMemberRef(pMID->m_tkImplementingMethod);
pMID->m_tkImplementedMethod = ResolveLocalMemberRef(pMID->m_tkImplementedMethod);
if(FAILED(m_pEmitter->DefineMethodImpl( pMID->m_tkDefiningClass,
diff --git a/src/coreclr/ilasm/assembler.h b/src/coreclr/ilasm/assembler.h
index b5dfd4d35dc..3edc1b40702 100644
--- a/src/coreclr/ilasm/assembler.h
+++ b/src/coreclr/ilasm/assembler.h
@@ -756,7 +756,6 @@ public:
BOOL m_fReportProgress;
BOOL m_fIsMscorlib;
BOOL m_fTolerateDupMethods;
- BOOL m_fENCMode;
BOOL m_fOptimize;
mdToken m_tkSysObject;
mdToken m_tkSysString;
@@ -1221,11 +1220,6 @@ public:
void SetCodePage(unsigned val) { g_uCodePage = val; };
Clockwork* bClock;
void SetClock(Clockwork* val) { bClock = val; };
- // ENC paraphernalia
- HRESULT InitMetaDataForENC(__in __nullterminated WCHAR* wzOrigFileName, BOOL generatePdb);
- BOOL EmitFieldsMethodsENC(Class* pClass);
- BOOL EmitEventsPropsENC(Class* pClass);
- HRESULT CreateDeltaFiles(__in __nullterminated WCHAR *pwzOutputFilename);
// Syntactic sugar paraphernalia
private:
diff --git a/src/coreclr/ilasm/main.cpp b/src/coreclr/ilasm/main.cpp
index 2e8f68beada..230d0df089a 100644
--- a/src/coreclr/ilasm/main.cpp
+++ b/src/coreclr/ilasm/main.cpp
@@ -194,7 +194,6 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv)
printf("\n/ARM Target processor: ARM (AArch32) processor");
printf("\n/ARM64 Target processor: ARM64 (AArch64) processor");
printf("\n/32BITPREFERRED Create a 32BitPreferred image (PE32)");
- printf("\n/ENC=<file> Create Edit-and-Continue deltas from specified source file");
printf("\n\nKey may be '-' or '/'\nOptions are recognized by first 3 characters (except ARM/ARM64)\nDefault source file extension is .il\n");
@@ -208,8 +207,6 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv)
}
uCodePage = CP_UTF8;
- WszSetEnvironmentVariable(W("COMP_ENC_OPENSCOPE"), W(""));
- WszSetEnvironmentVariable(W("COMP_ENC_EMIT"), W(""));
if((pAsm = new Assembler()))
{
pAsm->SetCodePage(uCodePage);
@@ -433,15 +430,6 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv)
}
}
}
- else if (!_stricmp(szOpt, "ENC"))
- {
- WCHAR *pStr = EqualOrColon(argv[i]);
- if(pStr == NULL) goto InvalidOption;
- for(pStr++; *pStr == L' '; pStr++); //skip the blanks
- if(wcslen(pStr)==0) goto InvalidOption; //if no file name
- pwzDeltaFiles[NumDeltaFiles++] = pStr;
- pAsm->m_fTolerateDupMethods = TRUE;
- }
else if (!_stricmp(szOpt, "SUB"))
{
WCHAR *pStr = EqualOrColon(argv[i]);
@@ -762,10 +750,8 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv)
}
}
if(bClock) cw.cEnd = GetTickCount();
-#define ENC_ENABLED
if(exitval==0)
{
- pAsm->m_fENCMode = TRUE;
WCHAR wzNewOutputFilename[MAX_FILENAME_LENGTH+16];
for(iFile = 0; iFile < NumDeltaFiles; iFile++)
{
@@ -801,27 +787,7 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv)
pParser->msg("%s is not a text file\n",szInputFilename);
fAllFilesPresent = FALSE;
}
- else
#endif
- if (SUCCEEDED(pAsm->InitMetaDataForENC(wzNewOutputFilename, bGeneratePdb)))
- {
- pAsm->SetSourceFileName(FullFileName(wzInputFilename,uCodePage)); // deletes the argument!
-
- pParser->ParseFile(pIn);
- if (pParser->Success() || pAsm->OnErrGo)
- {
- exitval = 1;
- if(FAILED(hr=pAsm->CreateDeltaFiles(wzNewOutputFilename)))
- pParser->msg("Could not create output delta files, error code=0x%08X\n",hr);
- else
- {
- if(pAsm->m_fFoldCode && pAsm->m_fReportProgress)
- pParser->msg("%d methods folded\n",pAsm->m_dwMethodsFolded);
- if(pParser->Success()) exitval = 0;
- else pParser->msg("Output delta files contain errors\n");
- }
- } // end if (pParser->Success() || pAsm->OnErrGo)
- } //end if (SUCCEEDED(pAsm->InitMetaDataForENC()))
} // end if ((!pIn) || !(pIn->IsValid())) -- else
if(pIn)
{
@@ -845,9 +811,6 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv)
}
else printf("Insufficient memory\n");
- WszSetEnvironmentVariable(W("COMP_ENC_OPENSCOPE"), W(""));
- WszSetEnvironmentVariable(W("COMP_ENC_EMIT"), W(""));
-
if (exitval || !bGeneratePdb)
{
// PE file was not created, or no debug info required. Kill PDB if any
diff --git a/src/coreclr/ilasm/writer.cpp b/src/coreclr/ilasm/writer.cpp
index f2a890201ea..8de68a22048 100644
--- a/src/coreclr/ilasm/writer.cpp
+++ b/src/coreclr/ilasm/writer.cpp
@@ -34,15 +34,6 @@ HRESULT Assembler::InitMetaData()
if (FAILED(hr))
goto exit;
- if(m_wzMetadataVersion)
- {
- VARIANT encOption;
- BSTR bstr;
- V_VT(&encOption) = VT_BSTR;
- V_BSTR(&encOption) = bstr = ::SysAllocString(m_wzMetadataVersion);
- hr = m_pDisp->SetOption(MetaDataRuntimeVersion, &encOption);
- ::SysFreeString(bstr);
- }
hr = m_pDisp->DefineScope(CLSID_CorMetaDataRuntime, 0, IID_IMetaDataEmit3,
(IUnknown **)&m_pEmitter);
if (FAILED(hr))
@@ -874,8 +865,6 @@ HRESULT Assembler::DoLocalMemberRefFixups()
int i;
for(i = 0; (pMRF = m_LocalMemberRefFixupList.PEEK(i)) != NULL; i++)
{
- if(m_fENCMode && (!pMRF->m_fNew)) continue;
-
switch(TypeFromToken(pMRF->tk))
{
case 0x99000000: pList = &m_LocalMethodRefDList; break;
diff --git a/src/coreclr/ilasm/writer_enc.cpp b/src/coreclr/ilasm/writer_enc.cpp
deleted file mode 100644
index a6670d03ce1..00000000000
--- a/src/coreclr/ilasm/writer_enc.cpp
+++ /dev/null
@@ -1,501 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-//
-// writer_ENC.cpp
-//
-
-//
-#include "ilasmpch.h"
-
-#include "assembler.h"
-
-HRESULT Assembler::InitMetaDataForENC(__in __nullterminated WCHAR* wzOrigFileName, BOOL generatePdb)
-{
- HRESULT hr = E_FAIL;
-
- if((wzOrigFileName==NULL)||(*wzOrigFileName == 0)||(m_pDisp==NULL)) return hr;
- if (m_pImporter != NULL)
- {
- m_pImporter->Release();
- m_pImporter = NULL;
- }
- if (m_pEmitter != NULL)
- {
- m_pEmitter->Release();
- m_pEmitter = NULL;
- }
- if (m_pPortablePdbWriter != NULL)
- {
- delete m_pPortablePdbWriter;
- m_pPortablePdbWriter = NULL;
- }
- //WszSetEnvironmentVariable(L"COMP_ENC_OPENSCOPE", wzOrigFileName);
- //hr = m_pDisp->DefineScope(CLSID_CorMetaDataRuntime, 0, IID_IMetaDataEmit2,
- // (IUnknown **)&m_pEmitter);
-
- if((m_pbsMD==NULL)||(m_pbsMD->length()==0))
- {
- _ASSERTE(!"NO BASE METADATA!");
- return E_FAIL;
- }
-
- VARIANT encOption;
- V_VT(&encOption) = VT_UI4;
- V_UI4(&encOption) = MDUpdateENC;
- m_pDisp->SetOption(MetaDataSetENC, &encOption);
- V_UI4(&encOption) = MDErrorOutOfOrderDefault;
- m_pDisp->SetOption(MetaDataErrorIfEmitOutOfOrder, &encOption);
- hr = m_pDisp->OpenScopeOnMemory( m_pbsMD->ptr(),
- m_pbsMD->length(),
- ofWrite,
- IID_IMetaDataEmit2,
- (IUnknown **)&m_pEmitter);
- _ASSERTE(SUCCEEDED(hr));
- if (FAILED(hr))
- goto exit;
-
- m_pManifest->SetEmitter(m_pEmitter);
- if(FAILED(hr = m_pEmitter->QueryInterface(IID_IMetaDataImport2, (void**)&m_pImporter)))
- goto exit;
-
- //WszSetEnvironmentVariable(L"COMP_ENC_EMIT", wzOrigFileName);
- if(!Init(generatePdb)) goto exit; // close and re-open CeeFileGen and CeeFile
- hr = S_OK;
-
-
-exit:
- return hr;
-}
-/*********************************************************************************/
-
-BOOL Assembler::EmitFieldsMethodsENC(Class* pClass)
-{
- unsigned n;
- BOOL ret = TRUE;
- // emit all field definition metadata tokens
- if((pClass->m_FieldDList.COUNT()))
- {
- FieldDescriptor* pFD;
- int j;
- for(j=0, n=0; (pFD = pClass->m_FieldDList.PEEK(j)); j++) // can't use POP here: we'll need field list for props
- {
- if(pFD->m_fNew)
- {
- if(!EmitField(pFD))
- {
- if(!OnErrGo) return FALSE;
- ret = FALSE;
- }
- pFD->m_fNew = FALSE;
- n++;
- }
- }
- if(m_fReportProgress) printf("Fields: %d;\t",n);
- }
- // Fields are emitted; emit the class layout
- {
- COR_FIELD_OFFSET *pOffsets = NULL;
- ULONG ul = pClass->m_ulPack;
- ULONG N = pClass->m_dwNumFieldsWithOffset;
-
- EmitSecurityInfo(pClass->m_cl,
- pClass->m_pPermissions,
- pClass->m_pPermissionSets);
- pClass->m_pPermissions = NULL;
- pClass->m_pPermissionSets = NULL;
- if((pClass->m_ulSize != 0xFFFFFFFF)||(ul != 0)||(N != 0))
- {
- if(IsTdAutoLayout(pClass->m_Attr)) report->warn("Layout specified for auto-layout class\n");
- if((ul > 128)||((ul & (ul-1)) !=0 ))
- report->error("Invalid packing parameter (%d), must be 1,2,4,8...128\n",pClass->m_ulPack);
- if(N)
- {
- pOffsets = new COR_FIELD_OFFSET[N+1];
- ULONG i,j=0;
- FieldDescriptor *pFD;
- for(i=0; (pFD = pClass->m_FieldDList.PEEK(i)); i++)
- {
- if(pFD->m_ulOffset != 0xFFFFFFFF)
- {
- pOffsets[j].ridOfField = RidFromToken(pFD->m_fdFieldTok);
- pOffsets[j].ulOffset = pFD->m_ulOffset;
- j++;
- }
- }
- _ASSERTE(j == N);
- pOffsets[j].ridOfField = mdFieldDefNil;
- }
- m_pEmitter->SetClassLayout (
- pClass->m_cl, // [IN] typedef
- ul, // [IN] packing size specified as 1, 2, 4, 8, or 16
- pOffsets, // [IN] array of layout specification
- pClass->m_ulSize); // [IN] size of the class
- if(pOffsets) delete [] pOffsets;
- }
- }
- // emit all method definition metadata tokens
- if((pClass->m_MethodList.COUNT()))
- {
- Method* pMethod;
- int i;
-
- for(i=0, n=0; (pMethod = pClass->m_MethodList.PEEK(i));i++)
- {
- if(pMethod->m_fNew)
- {
- if(!EmitMethod(pMethod))
- {
- if(!OnErrGo) return FALSE;
- ret = FALSE;
- }
- pMethod->m_fNew = FALSE;
- n++;
- }
- }
- if(m_fReportProgress) printf("Methods: %d;\t",n);
- }
- if(m_fReportProgress) printf("\n");
- return ret;
-}
-
-BOOL Assembler::EmitEventsPropsENC(Class* pClass)
-{
- unsigned n;
- BOOL ret = TRUE;
- // emit all event definition metadata tokens
- if((pClass->m_EventDList.COUNT()))
- {
- EventDescriptor* pED;
- int j;
- for(j=0,n=0; (pED = pClass->m_EventDList.PEEK(j)); j++) // can't use POP here: we'll need event list for props
- {
- if(pED->m_fNew)
- {
- if(!EmitEvent(pED))
- {
- if(!OnErrGo) return FALSE;
- ret = FALSE;
- }
- pED->m_fNew = FALSE;
- n++;
- }
- }
- if(m_fReportProgress) printf("Events: %d;\t",n);
- }
- // emit all property definition metadata tokens
- if((pClass->m_PropDList.COUNT()))
- {
- PropDescriptor* pPD;
- int j;
-
- for(j=0,n=0; (pPD = pClass->m_PropDList.PEEK(j)); j++)
- {
- if(pPD->m_fNew)
- {
- if(!EmitProp(pPD))
- {
- if(!OnErrGo) return FALSE;
- ret = FALSE;
- }
- pPD->m_fNew = FALSE;
- n++;
- }
- }
- if(m_fReportProgress) printf("Props: %d;\t",n);
- }
- if(m_fReportProgress) printf("\n");
- return ret;
-}
-
-HRESULT Assembler::CreateDeltaFiles(__in __nullterminated WCHAR *pwzOutputFilename)
-{
- HRESULT hr;
- DWORD mresourceSize = 0;
- BYTE* mresourceData = NULL;
- WCHAR* pEnd = NULL;
-
- if(m_fReportProgress) printf("Creating DMETA,DIL files\n");
- if (!m_pEmitter)
- {
- printf("Error: Cannot create a PE file with no metadata\n");
- return E_FAIL;
- }
-
- if(m_pManifest)
- {
- hr = S_OK;
- if(m_pManifest->m_pAsmEmitter==NULL)
- hr=m_pEmitter->QueryInterface(IID_IMetaDataAssemblyEmit, (void**) &(m_pManifest->m_pAsmEmitter));
-
- if(SUCCEEDED(hr))
- {
- m_pManifest->EmitAssemblyRefs();
- }
- }
- // Emit classes, class members and globals:
- {
- Class *pSearch;
- int i;
- BOOL bIsUndefClass = FALSE;
- if(m_fReportProgress) printf("\nEmitting classes:\n");
- for (i=1; (pSearch = m_lstClass.PEEK(i)); i++) // 0 is <Module>
- {
- if(pSearch->m_fNew)
- {
- if(m_fReportProgress)
- printf("Class %d:\t%s\n",i,pSearch->m_szFQN);
-
- if(pSearch->m_bIsMaster)
- {
- report->msg("Error: Reference to undefined class '%s'\n",pSearch->m_szFQN);
- bIsUndefClass = TRUE;
- }
- if(!EmitClass(pSearch))
- {
- if(!OnErrGo) return E_FAIL;
- }
- pSearch->m_fNew = FALSE;
- }
- }
- if(bIsUndefClass && !OnErrGo) return E_FAIL;
-
- if(m_fReportProgress) printf("\nEmitting fields and methods:\n");
- for (i=0; (pSearch = m_lstClass.PEEK(i)) != NULL; i++)
- {
- if(pSearch->m_fNewMembers)
- {
- if(m_fReportProgress)
- {
- if(i == 0) printf("Global \t");
- else printf("Class %d\t",i);
- }
- if(!EmitFieldsMethodsENC(pSearch))
- {
- if(!OnErrGo) return E_FAIL;
- }
- }
- }
- }
-
- // All ref'ed items def'ed in this file are emitted, resolve member refs to member defs:
- hr = ResolveLocalMemberRefs();
- if(FAILED(hr) &&(!OnErrGo)) goto exit;
-
- // Local member refs resolved, emit events, props and method impls
- {
- Class *pSearch;
- int i;
-
- if(m_fReportProgress) printf("\nEmitting events and properties:\n");
- for (i=0; (pSearch = m_lstClass.PEEK(i)); i++)
- {
- if(pSearch->m_fNewMembers)
- {
- if(m_fReportProgress)
- {
- if(i == 0) printf("Global \t");
- else printf("Class %d\t",i);
- }
- if(!EmitEventsPropsENC(pSearch))
- {
- if(!OnErrGo) return E_FAIL;
- }
- pSearch->m_fNewMembers = FALSE;
- }
- }
- }
- if(m_MethodImplDList.COUNT())
- {
- if(m_fReportProgress) report->msg("Method Implementations (total): %d\n",m_MethodImplDList.COUNT());
- if(!EmitMethodImpls())
- {
- if(!OnErrGo) return E_FAIL;
- }
- }
-
- // Emit the rest of the metadata
- hr = S_OK;
- if(m_pManifest)
- {
- if (FAILED(hr = m_pManifest->EmitManifest())) goto exit;
- }
- ResolveLocalMemberRefs(); // in case CAs added some
- EmitUnresolvedCustomAttributes();
-
- hr = DoLocalMemberRefFixups();
- if(FAILED(hr) &&(!OnErrGo)) goto exit;
-
- // Local member refs resolved and fixed up in BinStr method bodies. Emit the bodies to a separate file.
- pEnd = &pwzOutputFilename[wcslen(pwzOutputFilename)];
- {
- Class* pClass;
- Method* pMethod;
- FILE* pF = NULL;
- wcscat_s(pwzOutputFilename,MAX_SCOPE_LENGTH,W(".dil"));
- if(_wfopen_s(&pF,pwzOutputFilename,W("wb"))==0)
- {
- int i,j,L=0,M=0;
- BinStr bsOut;
- for (i=0; (pClass = m_lstClass.PEEK(i)); i++)
- {
- for(j=0; (pMethod = pClass->m_MethodList.PEEK(j)); j++)
- {
- if(pMethod->m_fNewBody)
- {
- L+= pMethod->m_pbsBody->length()+3;
- M++;
- }
- }
- }
- bsOut.getBuff(L+sizeof(DWORD)); // to avoid reallocs
- bsOut.remove(L);
- for (i=0; (pClass = m_lstClass.PEEK(i)); i++)
- {
- for(j=0; (pMethod = pClass->m_MethodList.PEEK(j)); j++)
- {
- if(pMethod->m_fNewBody)
- {
- if(!EmitMethodBody(pMethod,&bsOut))
- {
- report->msg("Error: failed to emit body of '%s'\n",pMethod->m_szName);
- hr = E_FAIL;
- if(!OnErrGo)
- {
- fclose(pF);
- *pEnd = 0;
- goto exit;
- }
- }
- pMethod->m_fNewBody = FALSE;
- }
- }
- }
- *((DWORD*)(bsOut.ptr())) = bsOut.length() - sizeof(DWORD);
- fwrite(bsOut.ptr(),bsOut.length(),1,pF);
- fclose(pF);
- }
- else
- report->msg("Error: failed to open file '%S'\n",pwzOutputFilename);
-
- *pEnd = 0;
- }
-
- // Emit the meta-data to a separate file
- IMetaDataEmit2* pENCEmitter;
- if(FAILED(hr = m_pEmitter->QueryInterface(IID_IMetaDataEmit2, (void**)&pENCEmitter)))
- goto exit;
-
- DWORD metaDataSize;
- if (FAILED(hr=pENCEmitter->GetDeltaSaveSize(cssAccurate, &metaDataSize))) goto exit;
-
- wcscat_s(pwzOutputFilename,MAX_SCOPE_LENGTH,W(".dmeta"));
- pENCEmitter->SaveDelta(pwzOutputFilename,0); // second arg (dwFlags) is not used
- *pEnd = 0;
- pENCEmitter->Release();
-
- // apply delta to create basis for the next ENC iteration
- if(m_pbsMD)
- {
- IMetaDataEmit2* pBaseMDEmit = NULL;
- if(FAILED(hr = m_pDisp->OpenScopeOnMemory(m_pbsMD->ptr(),
- m_pbsMD->length(),
- ofWrite,
- IID_IMetaDataEmit2,
- (IUnknown **)&pBaseMDEmit))) goto exit;
-
- if(FAILED(hr = pBaseMDEmit->ApplyEditAndContinue((IUnknown*)m_pImporter))) goto exit;
- delete m_pbsMD;
- if((m_pbsMD = new BinStr()) != NULL)
- {
- DWORD cb;
- hr = pBaseMDEmit->GetSaveSize(cssAccurate,&cb);
- BYTE* pb = m_pbsMD->getBuff(cb);
- hr = pBaseMDEmit->SaveToMemory(pb,cb);
- }
- pBaseMDEmit->Release();
- }
-
-
- // release all interfaces
- if (m_pImporter != NULL)
- {
- m_pImporter->Release();
- m_pImporter = NULL;
- }
- if (m_pEmitter != NULL)
- {
- m_pEmitter->Release();
- m_pEmitter = NULL;
- }
- if (m_pPortablePdbWriter != NULL)
- {
- delete m_pPortablePdbWriter;
- m_pPortablePdbWriter = NULL;
- }
-
- return S_OK;
-
- // set managed resource entry, if any
- if(m_pManifest && m_pManifest->m_dwMResSizeTotal)
- {
- mresourceSize = m_pManifest->m_dwMResSizeTotal;
-
- if (FAILED(hr=m_pCeeFileGen->GetSectionBlock(m_pILSection, mresourceSize,
- sizeof(DWORD), (void**) &mresourceData))) goto exit;
- if (FAILED(hr=m_pCeeFileGen->SetManifestEntry(m_pCeeFile, mresourceSize, 0))) goto exit;
- }
-
- //Compute all the RVAs
- if (FAILED(hr=m_pCeeFileGen->LinkCeeFile(m_pCeeFile))) goto exit;
-
- // actually output the resources
- if(mresourceSize && mresourceData)
- {
- size_t i, N = m_pManifest->m_dwMResNum, sizeread, L;
- BYTE *ptr = (BYTE*)mresourceData;
- BOOL mrfail = FALSE;
- FILE* pFile = NULL;
- char sz[2048];
- for(i=0; i < N; i++)
- {
- if(!m_pManifest->m_fMResNew[i]) continue;
- m_pManifest->m_fMResNew[i] = FALSE;
- memset(sz,0,2048);
- WszWideCharToMultiByte(CP_ACP,0,m_pManifest->m_wzMResName[i],-1,sz,2047,NULL,NULL);
- L = m_pManifest->m_dwMResSize[i];
- sizeread = 0;
- memcpy(ptr,&L,sizeof(DWORD));
- ptr += sizeof(DWORD);
- pFile = NULL;
- if(fopen_s(&pFile,sz,"rb")==0)
- {
- sizeread = fread((void *)ptr,1,L,pFile);
- fclose(pFile);
- ptr += sizeread;
- }
- else
- {
- report->msg("Error: failed to open mgd resource file '%ls'\n",m_pManifest->m_wzMResName[i]);
- mrfail = TRUE;
- }
- if(sizeread < L)
- {
- report->msg("Error: failed to read expected %d bytes from mgd resource file '%ls'\n",L,m_pManifest->m_wzMResName[i]);
- mrfail = TRUE;
- L -= sizeread;
- memset(ptr,0,L);
- ptr += L;
- }
- }
- if(mrfail)
- {
- hr = E_FAIL;
- goto exit;
- }
- }
-
- hr = S_OK;
-
-exit:
- return hr;
-}