diff options
author | Kyungwoo Lee <kyulee@microsoft.com> | 2015-12-10 16:18:25 -0800 |
---|---|---|
committer | Kyungwoo Lee <kyulee@microsoft.com> | 2015-12-11 08:19:16 -0800 |
commit | 1c472d376ac40130b78f32b62ab26dee1454c430 (patch) | |
tree | 961e0149f21b23da01d15a77e4c2cdca077431f6 | |
parent | cb25307b3022b67cf240ff534f05778845090921 (diff) | |
download | coreclr-1c472d376ac40130b78f32b62ab26dee1454c430.tar.gz coreclr-1c472d376ac40130b78f32b62ab26dee1454c430.tar.bz2 coreclr-1c472d376ac40130b78f32b62ab26dee1454c430.zip |
Enable ILASM for *nix
This enables ILASM for x-platforms.
1. Added a bunch of warning disable options mostly due to this prebuilt asmparse.cpp
2. Create a separte entry point "main" to pass WCHAR arguments.
3. PDB (CorSymWriter) part is disabled.
4. Converting/embedding resource file to binary is disabled.
5. jkotas kindly provided a code for IsTextUnicode which is unavailable on CoreCLR.
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/dlls/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/dlls/mscorpe/CMakeLists.txt | 10 | ||||
-rw-r--r-- | src/dlls/mscorpe/ceefilegenwriter.cpp | 24 | ||||
-rw-r--r-- | src/dlls/mscorpe/pewriter.cpp | 8 | ||||
-rw-r--r-- | src/dlls/mscorpe/pewriter.h | 2 | ||||
-rw-r--r-- | src/ilasm/CMakeLists.txt | 47 | ||||
-rw-r--r-- | src/ilasm/asmenum.h | 12 | ||||
-rw-r--r-- | src/ilasm/asmman.cpp | 18 | ||||
-rw-r--r-- | src/ilasm/asmman.hpp | 6 | ||||
-rw-r--r-- | src/ilasm/asmparse.h | 4 | ||||
-rw-r--r-- | src/ilasm/assem.cpp | 36 | ||||
-rw-r--r-- | src/ilasm/assembler.cpp | 24 | ||||
-rw-r--r-- | src/ilasm/assembler.h (renamed from src/ilasm/Assembler.h) | 19 | ||||
-rw-r--r-- | src/ilasm/grammar_after.cpp | 5 | ||||
-rw-r--r-- | src/ilasm/grammar_before.cpp | 3 | ||||
-rw-r--r-- | src/ilasm/main.cpp | 97 | ||||
-rw-r--r-- | src/ilasm/writer.cpp | 17 | ||||
-rw-r--r-- | src/ilasm/writer_enc.cpp | 11 | ||||
-rw-r--r-- | src/ildasm/unixcoreclrloader/coreclrloader.h | 3 | ||||
-rw-r--r-- | src/inc/cor.h | 2 | ||||
-rw-r--r-- | src/inc/corhdr.h | 2 | ||||
-rw-r--r-- | src/pal/inc/rt/ntimage.h | 3 | ||||
-rw-r--r-- | src/pal/inc/rt/palrt.h | 2 | ||||
-rw-r--r-- | src/palrt/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/palrt/unicode.cpp | 28 |
26 files changed, 281 insertions, 107 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 64d7d63f80..1046e3ded1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -86,9 +86,9 @@ add_subdirectory(ToolBox) add_subdirectory(tools) add_subdirectory(unwinder) add_subdirectory(ildasm) +add_subdirectory(ilasm) if(WIN32) - add_subdirectory(ilasm) add_subdirectory(ipcman) endif(WIN32) diff --git a/src/dlls/CMakeLists.txt b/src/dlls/CMakeLists.txt index e0bdd37a6f..932e65e350 100644 --- a/src/dlls/CMakeLists.txt +++ b/src/dlls/CMakeLists.txt @@ -1,9 +1,9 @@ if(WIN32) add_subdirectory(clretwrc) - add_subdirectory(mscorpe) endif(WIN32) add_subdirectory(dbgshim) add_subdirectory(mscordbi) add_subdirectory(mscordac) add_subdirectory(mscoree) +add_subdirectory(mscorpe) add_subdirectory(mscorrc) diff --git a/src/dlls/mscorpe/CMakeLists.txt b/src/dlls/mscorpe/CMakeLists.txt index b41848f2e6..f20f043eb7 100644 --- a/src/dlls/mscorpe/CMakeLists.txt +++ b/src/dlls/mscorpe/CMakeLists.txt @@ -3,10 +3,10 @@ project(mscorpe) add_definitions(-DFEATURE_CORECLR) set(MSCORPE_SOURCES - ICeeFileGen.cpp - CeeFileGenWriter.cpp - PEWriter.cpp - CeeFileGenWriterTokens.cpp + iceefilegen.cpp + ceefilegenwriter.cpp + pewriter.cpp + ceefilegenwritertokens.cpp utilcodeinit.cpp ) @@ -14,6 +14,8 @@ if(WIN32) list(APPEND MSCORPE_SOURCES Native.rc ) +else() + add_compile_options(-Wno-delete-non-virtual-dtor) endif(WIN32) add_library(mscorpe STATIC diff --git a/src/dlls/mscorpe/ceefilegenwriter.cpp b/src/dlls/mscorpe/ceefilegenwriter.cpp index 555dde2621..e40e8ac710 100644 --- a/src/dlls/mscorpe/ceefilegenwriter.cpp +++ b/src/dlls/mscorpe/ceefilegenwriter.cpp @@ -227,7 +227,7 @@ CeeFileGenWriter::CeeFileGenWriter() // ctor is protected #ifdef ENC_DELTA_HACK // for EnC we want the RVA to be right at the front of the IL stream WCHAR szFileName[256]; - DWORD len = WszGetEnvironmentVariable(L"COMP_ENC_EMIT", szFileName, NumItems(szFileName)); + DWORD len = WszGetEnvironmentVariable(W("COMP_ENC_EMIT"), szFileName, NumItems(szFileName)); if (len > 0) g_EnCMode = TRUE; #endif @@ -335,10 +335,11 @@ HRESULT CeeFileGenWriter::link() hr = emitExeMain(); if (FAILED(hr)) return hr; - +#ifndef FEATURE_PAL hr = emitResourceSection(); if (FAILED(hr)) return hr; +#endif } m_linked = true; @@ -386,8 +387,9 @@ HRESULT CeeFileGenWriter::fixup() HRESULT CeeFileGenWriter::generateImage(void **ppImage) { HRESULT hr = S_OK; - LPWSTR outputFileName = NULL; + LPCWSTR outputFileName = NULL; +#ifndef FEATURE_PAL HANDLE hThreadToken = NULL; // Impersonation is only supported on Win2k and above. if (!OpenThreadToken(GetCurrentThread(), TOKEN_READ | TOKEN_IMPERSONATE, TRUE, &hThreadToken)) @@ -408,6 +410,7 @@ HRESULT CeeFileGenWriter::generateImage(void **ppImage) return HRESULT_FROM_GetLastError(); } } +#endif // !FEATURE_PAL #ifdef ENC_DELTA_HACK // fixups break because we've set the base RVA to 0 for the delta stream @@ -420,13 +423,13 @@ HRESULT CeeFileGenWriter::generateImage(void **ppImage) if (! outputFileName && ppImage == NULL) { if (m_comImageFlags & COMIMAGE_FLAGS_IL_LIBRARY) - outputFileName = L"output.ill"; + outputFileName = W("output.ill"); else if (m_dllSwitch) - outputFileName = L"output.dll"; + outputFileName = W("output.dll"); else if (m_objSwitch) - outputFileName = L"output.obj"; + outputFileName = W("output.exe"); else - outputFileName = L"output.exe"; + outputFileName = W("output.obj"); } // output file name and ppImage are mutually exclusive @@ -438,6 +441,7 @@ HRESULT CeeFileGenWriter::generateImage(void **ppImage) IfFailGo(getPEWriter().write(ppImage)); ErrExit: +#ifndef FEATURE_PAL if (hThreadToken != NULL) { BOOL success = SetThreadToken(NULL, hThreadToken); @@ -449,6 +453,7 @@ ErrExit: hr = HRESULT_FROM_GetLastError(); } } +#endif // !FEATURE_PAL return hr; } // HRESULT CeeFileGenWriter::generateImage() @@ -504,7 +509,7 @@ HRESULT CeeFileGenWriter::emitLibraryName(IMetaDataEmit *emitter) WCHAR wzGuid[40]; BYTE rgCA[50]; IfFailRet(emitter->DefineTypeRefByName(mdTypeRefNil, INTEROP_GUID_TYPE_W, &tr)); - IfFailRet(emitter->DefineMemberRef(tr, L".ctor", _SIG, sizeof(_SIG), &mr)); + IfFailRet(emitter->DefineMemberRef(tr, W(".ctor"), _SIG, sizeof(_SIG), &mr)); StringFromGUID2(m_libraryGuid, wzGuid, lengthof(wzGuid)); memset(rgCA, 0, sizeof(rgCA)); // Tag is 0x0001 @@ -997,7 +1002,7 @@ HRESULT GetClrSystemDirectory(__out_ecount_part(cchBuffer, *pdwLength) LPWSTR pb return CopySystemDirectory(pPath, pbuffer, cchBuffer, pdwLength); } - +#ifndef FEATURE_PAL BOOL RunProcess(LPCWSTR tempResObj, LPCWSTR pszFilename, DWORD* pdwExitCode, PEWriter &pewriter) { BOOL fSuccess = FALSE; @@ -1472,6 +1477,7 @@ lDone: ; return hr; } // HRESULT CeeFileGenWriter::emitResourceSection() +#endif // !FEATURE_PAL HRESULT CeeFileGenWriter::setManifestEntry(ULONG size, ULONG offset) { diff --git a/src/dlls/mscorpe/pewriter.cpp b/src/dlls/mscorpe/pewriter.cpp index 7494ad9d3d..450b26cc53 100644 --- a/src/dlls/mscorpe/pewriter.cpp +++ b/src/dlls/mscorpe/pewriter.cpp @@ -242,6 +242,7 @@ static inline HRESULT SubOvf_U_U32(UINT64 & a, unsigned int b) return S_OK; } +#ifndef _AMD64_ /* subtract two unsigned pointers yeilding a signed pointer sized int */ static inline HRESULT SubOvf_U_U(INT64 & r, UINT64 a, UINT64 b) { @@ -253,6 +254,7 @@ static inline HRESULT SubOvf_U_U(INT64 & r, UINT64 a, UINT64 b) } return E_FAIL; } +#endif /******************************************************************/ @@ -1898,7 +1900,7 @@ HRESULT PEWriter::fixup(CeeGenTokenMapper *pMapper) for(PESectionReloc* rcur = textSection->m_relocStart; rcur < textSection->m_relocCur; rcur++) { - switch(rcur->type) + switch((int)rcur->type) { case 0x7FFA: // Ptr to symbol name #ifdef _WIN64 @@ -2026,7 +2028,7 @@ HRESULT PEWriter::fixup(CeeGenTokenMapper *pMapper) { IMAGE_SECTION_HEADER* phdr = textSection->m_header; // Add to reloc table - IMAGE_RELOC_FIELD(ir, VirtualAddress) = VAL32(rva); + ir.VirtualAddress = VAL32(rva); ir.SymbolTableIndex = VAL32(i); ir.Type = VAL16(IMAGE_REL_I386_SECREL); if(phdr->PointerToRelocations == 0) @@ -2176,7 +2178,7 @@ HRESULT PEWriter::Close() } /******************************************************************/ -HRESULT PEWriter::write(__in const LPWSTR fileName) { +HRESULT PEWriter::write(__in LPCWSTR fileName) { HRESULT hr; diff --git a/src/dlls/mscorpe/pewriter.h b/src/dlls/mscorpe/pewriter.h index 67441eee75..8ef9e5666a 100644 --- a/src/dlls/mscorpe/pewriter.h +++ b/src/dlls/mscorpe/pewriter.h @@ -43,7 +43,7 @@ public: HRESULT link(); HRESULT fixup(CeeGenTokenMapper *pMapper); - HRESULT write(__in const LPWSTR fileName); + HRESULT write(__in LPCWSTR fileName); HRESULT write(void **ppImage); // calling these functions is optional diff --git a/src/ilasm/CMakeLists.txt b/src/ilasm/CMakeLists.txt index 3481eb4a7a..eb84533770 100644 --- a/src/ilasm/CMakeLists.txt +++ b/src/ilasm/CMakeLists.txt @@ -8,6 +8,7 @@ add_definitions(-D__ILASM__) add_definitions(-DFEATURE_CORECLR) include_directories(.) +include_directories(../ildasm/unixcoreclrloader) set(ILASM_SOURCES assem.cpp @@ -19,31 +20,55 @@ set(ILASM_SOURCES assembler.cpp prebuilt/asmparse.c ) -if(WIN32) - set_source_files_properties(prebuilt/asmparse.c PROPERTIES COMPILE_FLAGS "/TP") -endif(WIN32) +set_source_files_properties( prebuilt/asmparse.c PROPERTIES LANGUAGE CXX ) + +if(CLR_CMAKE_PLATFORM_UNIX) + add_compile_options(-x c++) + # Need generate a right form of asmparse.c to avoid the following options. + # https://github.com/dotnet/coreclr/issues/2305 + add_compile_options(-Wno-delete-non-virtual-dtor) + add_compile_options(-Wno-deprecated-register) + add_compile_options(-Wno-array-bounds) + add_compile_options(-Wno-unused-label) +endif(CLR_CMAKE_PLATFORM_UNIX) add_executable(ilasm ${ILASM_SOURCES} ) set(ILASM_LINK_LIBRARIES - mscorpe utilcodestaticnohost + mscorpe mdhotdata_full corguids ) if(CLR_CMAKE_PLATFORM_UNIX) - #TODO + target_link_libraries(ilasm + ${ILASM_LINK_LIBRARIES} + ceefgen + unixcoreclrloader + utilcodestaticnohost + mscorrc_debug + coreclrpal + palrt + ) + + # FreeBSD implements dlopen in libc + if(NOT CMAKE_SYSTEM_NAME STREQUAL FreeBSD) + target_link_libraries(ilasm + dl + ) + endif(NOT CMAKE_SYSTEM_NAME STREQUAL FreeBSD) + else() target_link_libraries(ilasm - ${ILASM_LINK_LIBRARIES} - coreclr - msvcrt - ole32 - oleaut32 - shell32 + ${ILASM_LINK_LIBRARIES} + coreclr + msvcrt + ole32 + oleaut32 + shell32 ) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/ilasm.pdb DESTINATION PDB) diff --git a/src/ilasm/asmenum.h b/src/ilasm/asmenum.h index b8bd49966e..8dd4318cb5 100644 --- a/src/ilasm/asmenum.h +++ b/src/ilasm/asmenum.h @@ -9,14 +9,14 @@ typedef struct { - char * pszName; - OPCODE op; + const char * pszName; + OPCODE op; - BYTE Type; // Inline0 etc. + BYTE Type; // Inline0 etc. - BYTE Len; // std mapping - BYTE Std1; - BYTE Std2; + BYTE Len; // std mapping + BYTE Std1; + BYTE Std2; } opcodeinfo_t; #ifdef DECLARE_DATA diff --git a/src/ilasm/asmman.cpp b/src/ilasm/asmman.cpp index 4933cf1f5c..c457adddc9 100644 --- a/src/ilasm/asmman.cpp +++ b/src/ilasm/asmman.cpp @@ -115,7 +115,7 @@ mdToken AsmMan::GetComTypeTokByName( return(tmp ? tmp->tkTok : mdExportedTypeNil); } -AsmManAssembly* AsmMan::GetAsmRefByName(__in __nullterminated char* szAsmRefName) +AsmManAssembly* AsmMan::GetAsmRefByName(__in __nullterminated const char* szAsmRefName) { AsmManAssembly* ret = NULL; if(szAsmRefName) @@ -130,7 +130,7 @@ AsmManAssembly* AsmMan::GetAsmRefByName(__in __nullterminated char* szAsmRef } return ret; } -mdToken AsmMan::GetAsmRefTokByName(__in __nullterminated char* szAsmRefName) +mdToken AsmMan::GetAsmRefTokByName(__in __nullterminated const char* szAsmRefName) { AsmManAssembly* tmp = GetAsmRefByName(szAsmRefName); return(tmp ? tmp->tkTok : mdAssemblyRefNil); @@ -155,7 +155,7 @@ void AsmMan::SetModuleName(__inout_opt __nullterminated char* szName) } //============================================================================================================== // Borrowed from VM\assembly.cpp - +#ifndef FEATURE_CORECLR HRESULT GetHash(__in LPWSTR moduleName, ALG_ID iHashAlg, BYTE** pbCurrentValue, // should be NULL @@ -224,6 +224,7 @@ HRESULT GetHash(__in LPWSTR moduleName, return hr; } +#endif // !FEATURE_CORECLR //============================================================================================================== void AsmMan::AddFile(__in __nullterminated char* szName, DWORD dwAttr, BinStr* pHashBlob) @@ -277,15 +278,18 @@ void AsmMan::EmitFiles() if(m_pAssembly // and assembly is defined && m_pAssembly->ulHashAlgorithm) // and hash algorithm is defined... { // then try to compute it - if(FAILED(GetHash(wzUniBuf,(ALG_ID)(m_pAssembly->ulHashAlgorithm),&pHash,&cbHash))) +#ifndef FEATURE_CORECLR + if(SUCCEEDED(GetHash(wzUniBuf,(ALG_ID)(m_pAssembly->ulHashAlgorithm),&pHash,&cbHash))) { - pHash = NULL; - cbHash = 0; + tmp->pHash = new BinStr(pHash,cbHash); } else +#else { - tmp->pHash = new BinStr(pHash,cbHash); + pHash = NULL; + cbHash = 0; } +#endif // !FEATURE_CORECLR } } else diff --git a/src/ilasm/asmman.hpp b/src/ilasm/asmman.hpp index bf1a3fe0c7..31e73b743b 100644 --- a/src/ilasm/asmman.hpp +++ b/src/ilasm/asmman.hpp @@ -207,7 +207,7 @@ class AsmMan void* m_pAssembler; AsmManFile* GetFileByName(__in __nullterminated char* szFileName); - AsmManAssembly* GetAsmRefByName(__in __nullterminated char* szAsmRefName); + AsmManAssembly* GetAsmRefByName(__in __nullterminated const char* szAsmRefName); AsmManComType* GetComTypeByName(__in_opt __nullterminated char* szComTypeName, __in_opt __nullterminated char* szComEnclosingTypeName = NULL); mdToken GetComTypeTokByName(__in_opt __nullterminated char* szComTypeName, @@ -284,8 +284,8 @@ public: void SetManifestResAsmRef(__in __nullterminated char* szAsmRefName); mdToken GetFileTokByName(__in __nullterminated char* szFileName); - mdToken GetAsmRefTokByName(__in __nullterminated char* szAsmRefName); - mdToken GetAsmTokByName(__in __nullterminated char* szAsmName) + mdToken GetAsmRefTokByName(__in __nullterminated const char* szAsmRefName); + mdToken GetAsmTokByName(__in __nullterminated const char* szAsmName) { return (m_pAssembly && (strcmp(m_pAssembly->szName,szAsmName)==0)) ? m_pAssembly->tkTok : 0; }; mdToken GetModuleRefTokByName(__in __nullterminated char* szName) diff --git a/src/ilasm/asmparse.h b/src/ilasm/asmparse.h index 9c1ced273e..2f9cf21bc5 100644 --- a/src/ilasm/asmparse.h +++ b/src/ilasm/asmparse.h @@ -71,7 +71,7 @@ public: const WCHAR* namew() { - return L"local_define"; + return W("local_define"); } BOOL IsValid() @@ -305,7 +305,7 @@ private: HANDLE hstderr; private: - friend void yyerror(__in __nullterminated char* str); + friend void yyerror(__in __nullterminated const char* str); friend int parse_literal(unsigned curSym, __inout __nullterminated char* &curPos, BOOL translate_escapes); friend int yyparse(); friend int yylex(); diff --git a/src/ilasm/assem.cpp b/src/ilasm/assem.cpp index 938cbaa1bd..f06320eda5 100644 --- a/src/ilasm/assem.cpp +++ b/src/ilasm/assem.cpp @@ -16,9 +16,15 @@ #define DECLARE_DATA #include "assembler.h" -#ifndef FEATURE_CORECLR +#ifdef FEATURE_CORECLR +#ifdef FEATURE_PAL +#include "coreclrloader.h" +CoreCLRLoader *g_loader; +#endif // FEATURE_PAL +MetaDataGetDispenserFunc metaDataGetDispenser; +#else #include "MscorpeSxS.h" -#endif +#endif // FEATURE_CORECLR void indexKeywords(Indx* indx); // defined in asmparse.y @@ -232,20 +238,38 @@ Assembler::~Assembler() m_pDisp = NULL; } +#ifdef FEATURE_CORECLR +#ifdef FEATURE_PAL + if (g_loader != NULL) + { + g_loader->Finish(); + } +#endif +#else if (m_fDidCoInitialise) CoUninitialize(); +#endif // FEATURE_CORECLR } BOOL Assembler::Init() { +#ifdef FEATURE_CORECLR +#ifdef FEATURE_PAL + g_loader = CoreCLRLoader::Create(g_pszExeFile); + metaDataGetDispenser = (MetaDataGetDispenserFunc)g_loader->LoadFunction("MetaDataGetDispenser"); +#else + metaDataGetDispenser = (MetaDataGetDispenserFunc)MetaDataGetDispenser; +#endif // FEATURE_PAL +#else if(!m_fDidCoInitialise) { if (FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) return FALSE; m_fDidCoInitialise = TRUE; } +#endif // FEATURE_CORECLR if (m_pCeeFileGen != NULL) { if (m_pCeeFile) m_pCeeFileGen->DestroyCeeFile(&m_pCeeFile); @@ -804,7 +828,7 @@ BOOL Assembler::EmitMethod(Method *pMethod) if(IsMdPrivateScope(pMethod->m_Attr)) { - WCHAR* p = wcsstr(wzMemberName,L"$PST06"); + WCHAR* p = wcsstr(wzMemberName,W("$PST06")); if(p) *p = 0; } @@ -832,7 +856,7 @@ BOOL Assembler::EmitMethod(Method *pMethod) { mdToken tkPseudoCtor; BYTE bSig[3] = {IMAGE_CEE_CS_CALLCONV_HASTHIS,0,ELEMENT_TYPE_VOID}; - if(FAILED(m_pEmitter->DefineMemberRef(tkPseudoClass, L".ctor", (PCCOR_SIGNATURE)bSig, 3, &tkPseudoCtor))) + if(FAILED(m_pEmitter->DefineMemberRef(tkPseudoClass, W(".ctor"), (PCCOR_SIGNATURE)bSig, 3, &tkPseudoCtor))) report->error("Unable to define member reference '%s::.ctor'\n", COR_REQUIRES_SECOBJ_ATTRIBUTE_ANSI); else DefineCV(new CustomDescr(MethodToken,tkPseudoCtor,NULL)); } @@ -1144,7 +1168,7 @@ BOOL Assembler::EmitProp(PropDescriptor* pPD) return TRUE; } -Class *Assembler::FindCreateClass(__in __nullterminated char *pszFQN) +Class *Assembler::FindCreateClass(__in __nullterminated const char *pszFQN) { Class *pSearch = NULL; @@ -1216,7 +1240,7 @@ BOOL Assembler::EmitClass(Class *pClass) L = wcslen(wzFullName); if((L==0)||(wzFullName[L-1]==L'.')) // Missing class name! { - wcscat_s(wzFullName,dwUniBuf,L"$UNNAMED_TYPE$"); + wcscat_s(wzFullName,dwUniBuf,W("$UNNAMED_TYPE$")); } pClass->m_Attr = CheckClassFlagsIfNested(pClass->m_pEncloser, pClass->m_Attr); diff --git a/src/ilasm/assembler.cpp b/src/ilasm/assembler.cpp index d83bf7ce2b..275b721f36 100644 --- a/src/ilasm/assembler.cpp +++ b/src/ilasm/assembler.cpp @@ -93,7 +93,7 @@ void Assembler::ClearBoundList(void) m_TyParList = NULL; } /**************************************************************************/ -mdToken Assembler::ResolveClassRef(mdToken tkResScope, __in __nullterminated char *pszFullClassName, Class** ppClass) +mdToken Assembler::ResolveClassRef(mdToken tkResScope, __in __nullterminated const char *pszFullClassName, Class** ppClass) { Class *pClass = NULL; mdToken tkRet = mdTokenNil; @@ -167,11 +167,11 @@ private: mdToken token_; public: // Constructor for a 'lookup' object - TypeSpecContainer(BinStr *typeSpec) : - len_(typeSpec->length()), - hash_(typeSpec->length()), - token_(mdTokenNil), - ptr_(typeSpec->ptr()) + TypeSpecContainer(BinStr *typeSpec) : + ptr_(typeSpec->ptr()), + len_(typeSpec->length()), + hash_(typeSpec->length()), + token_(mdTokenNil) { for (unsigned i = 0; i < len_; i++) hash_ = (hash_ * 257) ^ ((i + 1) * (ptr_[i] ^ 0xA5)); @@ -179,10 +179,10 @@ public: // Constructor for a 'permanent' object // Don't bother re-hashing, since we will always have already constructed the lookup object TypeSpecContainer(const TypeSpecContainer &t, mdToken tk) : - len_(t.len_), + ptr_(new unsigned __int8[t.len_]), + len_(t.len_), hash_(t.hash_), - token_(tk), - ptr_(new unsigned __int8[t.len_]) + token_(tk) { _ASSERT(tk != mdTokenNil); _ASSERT(t.token_ == mdTokenNil); @@ -252,7 +252,7 @@ mdToken Assembler::ResolveTypeSpec(BinStr* typeSpec) } /**************************************************************************/ -mdToken Assembler::GetAsmRef(__in __nullterminated char* szName) +mdToken Assembler::GetAsmRef(__in __nullterminated const char* szName) { mdToken tkResScope = 0; if(strcmp(szName,"*")==0) tkResScope = mdTokenNil; @@ -938,7 +938,7 @@ BOOL Assembler::EmitField(FieldDescriptor* pFD) WszMultiByteToWideChar(g_uCodePage,0,pFD->m_szName,-1,wzFieldName,dwUniBuf); //int)cFieldNameLength); if(IsFdPrivateScope(pFD->m_dwAttr)) { - WCHAR* p = wcsstr(wzFieldName,L"$PST04"); + WCHAR* p = wcsstr(wzFieldName,W("$PST04")); if(p) *p = 0; } @@ -2020,7 +2020,7 @@ void Assembler::EmitInstrStringLiteral(Instr* instr, BinStr* literal, BOOL Conve L = UnicodeString ? WszMultiByteToWideChar(g_uCodePage,0,(char*)pb,-1,UnicodeString,DataLen+1) : 0; if(L == 0) { - char* sz=NULL; + const char* sz=NULL; DWORD dw; switch(dw=GetLastError()) { diff --git a/src/ilasm/Assembler.h b/src/ilasm/assembler.h index 8b9b414e8c..8f3a71e7cc 100644 --- a/src/ilasm/Assembler.h +++ b/src/ilasm/assembler.h @@ -51,6 +51,19 @@ #define NESTING_SEP ((char)0xF8) #define dwUniBuf 16384 + +#ifdef FEATURE_PAL +#include "coreclrloader.h" +extern CoreCLRLoader *g_loader; +extern char *g_pszExeFile; +#endif +typedef int(*MetaDataGetDispenserFunc) ( + REFCLSID rclsid, // The class to desired. + REFIID riid, // Interface wanted on class factory. + LPVOID FAR *ppv); // Return interface pointer here. + +extern MetaDataGetDispenserFunc metaDataGetDispenser; + extern WCHAR wzUniBuf[]; // Unicode conversion global buffer (assem.cpp) class Class; @@ -776,13 +789,13 @@ public: HRESULT CreateTLSDirectory(); HRESULT CreateDebugDirectory(); HRESULT InitMetaData(); - Class *FindCreateClass(__in __nullterminated char *pszFQN); + Class *FindCreateClass(__in __nullterminated const char *pszFQN); BOOL EmitFieldRef(__in_z __in char *pszArg, int opcode); BOOL EmitSwitchData(__in_z __in char *pszArg); - mdToken ResolveClassRef(mdToken tkResScope, __in __nullterminated char *pszClassName, Class** ppClass); + mdToken ResolveClassRef(mdToken tkResScope, __in __nullterminated const char *pszClassName, Class** ppClass); mdToken ResolveTypeSpec(BinStr* typeSpec); mdToken GetBaseAsmRef(); - mdToken GetAsmRef(__in __nullterminated char* szName); + mdToken GetAsmRef(__in __nullterminated const char* szName); mdToken GetModRef(__in __nullterminated char* szName); mdToken GetInterfaceImpl(mdToken tsClass, mdToken tsInterface); char* ReflectionNotation(mdToken tk); diff --git a/src/ilasm/grammar_after.cpp b/src/ilasm/grammar_after.cpp index 8fe93dab4b..d0271a64e1 100644 --- a/src/ilasm/grammar_after.cpp +++ b/src/ilasm/grammar_after.cpp @@ -6,6 +6,7 @@ /* Code goes here */ /********************************************************************************/ +extern int yyparse(); struct Keywords { const char* name; @@ -204,7 +205,7 @@ char* yygetline(int Line) return buff; } -void yyerror(__in __nullterminated char* str) { +void yyerror(__in __nullterminated const char* str) { char tokBuff[64]; WCHAR *wzfile = (WCHAR*)(PENV->in->namew()); int iline = PENV->curLine; @@ -1174,7 +1175,7 @@ Just_A_Character: #endif /**************************************************************************/ -static char* newString(__in __nullterminated char* str1) +static char* newString(__in __nullterminated const char* str1) { char* ret = new char[strlen(str1)+1]; if(ret) strcpy_s(ret, strlen(str1)+1, str1); diff --git a/src/ilasm/grammar_before.cpp b/src/ilasm/grammar_before.cpp index 60d6b57b3b..c6b238813d 100644 --- a/src/ilasm/grammar_before.cpp +++ b/src/ilasm/grammar_before.cpp @@ -11,6 +11,7 @@ #endif #define YYMAXDEPTH 0x80000 +#define YYLOCAL int //#define YYRECURSIVE //#define DEBUG_PARSING @@ -60,7 +61,7 @@ void SetFunctionPtrs() #endif static char* newStringWDel(__in __nullterminated char* str1, char delimiter, __in __nullterminated char* str3 = 0); -static char* newString(__in __nullterminated char* str1); +static char* newString(__in __nullterminated const char* str1); static void corEmitInt(BinStr* buff, unsigned data); static void AppendStringWithLength(BinStr* pbs, __in __nullterminated char* sz); bool bParsingByteArray = FALSE; diff --git a/src/ilasm/main.cpp b/src/ilasm/main.cpp index 978f827188..18142e3f9f 100644 --- a/src/ilasm/main.cpp +++ b/src/ilasm/main.cpp @@ -14,6 +14,7 @@ #include "shimload.h" #include "strsafe.h" +#define ASSERTE_ALL_BUILDS(expr) _ASSERTE_ALL_BUILDS(__FILE__, (expr)) WCHAR* EqualOrColon(__in __nullterminated WCHAR* szArg) { @@ -30,6 +31,9 @@ static DWORD g_dwSubsystem=(DWORD)-1,g_dwComImageFlags=(DWORD)-1,g_dwFileAlig static ULONGLONG g_stBaseAddress=0; static size_t g_stSizeOfStackReserve=0; extern unsigned int g_uConsoleCP; +#ifdef FEATURE_PAL +char * g_pszExeFile; +#endif void MakeTestFile(__in __nullterminated char* szFileName) { @@ -66,7 +70,7 @@ void MakeProperSourceFileName(__in __nullterminated WCHAR* wzOrigName, if(wzProperName[j] == '.') break; if((wzProperName[j] == '\\')||(j == 0)) { - wcscat_s(wzProperName,MAX_FILENAME_LENGTH,L".il"); + wcscat_s(wzProperName,MAX_FILENAME_LENGTH,W(".il")); break; } } @@ -98,6 +102,7 @@ WCHAR wzIncludePathBuffer[MAX_FILENAME_LENGTH]; #pragma warning(push) #pragma warning(disable:21000) // Suppress PREFast warning about overly large function #endif + extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) { int i, NumFiles = 0, NumDeltaFiles = 0; @@ -139,7 +144,7 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) #pragma warning(push) #pragma warning(disable:26000) // "Suppress prefast warning about index overflow" #endif - if (! wcscmp(argv[1], L"/?") || ! wcscmp(argv[1],L"-?")) + if (! wcscmp(argv[1], W("/?")) || ! wcscmp(argv[1],W("-?"))) #ifdef _PREFAST_ #pragma warning(pop) #endif @@ -203,8 +208,8 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) } uCodePage = CP_UTF8; - WszSetEnvironmentVariable(L"COMP_ENC_OPENSCOPE", L""); - WszSetEnvironmentVariable(L"COMP_ENC_EMIT", L""); + WszSetEnvironmentVariable(W("COMP_ENC_OPENSCOPE"), W("")); + WszSetEnvironmentVariable(W("COMP_ENC_EMIT"), W("")); if((pAsm = new Assembler())) { pAsm->SetCodePage(uCodePage); @@ -214,7 +219,11 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) //------------------------------------------------- for (i = 1; i < argc; i++) { +#ifdef FEATURE_PAL + if(argv[i][0] == L'-') +#else if((argv[i][0] == L'/') || (argv[i][0] == L'-')) +#endif { memset(szOpt,0,sizeof(szOpt)); WszWideCharToMultiByte(uCodePage,0,&argv[i][1],-1,szOpt,sizeof(szOpt),NULL,NULL); @@ -240,7 +249,11 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) else if (!_stricmp(szOpt, "DEB")) { pAsm->m_dwIncludeDebugInfo = 0x101; +#ifdef FEATURE_CORECLR + printf("Warning: PDB is ignored under 'DEB' option for ilasm on CoreCLR.\n"); +#else pAsm->m_fGeneratePDB = TRUE; +#endif bNoDebug = FALSE; WCHAR *pStr = EqualOrColon(argv[i]); @@ -253,13 +266,13 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) WCHAR wzSubOpt[8]; wcsncpy_s(wzSubOpt,8,pStr,3); wzSubOpt[3] = 0; - if(0 == _wcsicmp(wzSubOpt,L"OPT")) + if(0 == _wcsicmp(wzSubOpt,W("OPT"))) pAsm->m_dwIncludeDebugInfo = 0x3; - else if(0 == _wcsicmp(wzSubOpt,L"IMP")) + else if(0 == _wcsicmp(wzSubOpt,W("IMP"))) pAsm->m_dwIncludeDebugInfo = 0x103; else { - WCHAR *pFmt =((*pStr == '0')&&(*(pStr+1) == 'x'))? L"%lx" : L"%ld"; + const WCHAR *pFmt =((*pStr == '0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld"); if(swscanf_s(pStr,pFmt,&(pAsm->m_dwIncludeDebugInfo))!=1) goto InvalidOption; // bad subooption } @@ -268,7 +281,11 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) } else if (!_stricmp(szOpt, "PDB")) { +#ifdef FEATURE_CORECLR + printf("Warning: 'PDB' option is ignored for ilasm on CoreCLR.\n"); +#else pAsm->m_fGeneratePDB = TRUE; +#endif bNoDebug = FALSE; } else if (!_stricmp(szOpt, "CLO")) @@ -406,7 +423,7 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) if(wcslen(pStr)==0) goto InvalidOption; //if no version { int major=-1,minor=-1; - if(swscanf_s(pStr,L"%d.%d",&major, &minor)==2) + if(swscanf_s(pStr,W("%d.%d"),&major, &minor)==2) { if((major >= 0)&&(major < 0xFF)) pAsm->m_wMSVmajor = (WORD)major; @@ -429,7 +446,7 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto InvalidOption; pStr++; - WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? L"%lx" : L"%ld"; + const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld"); if(swscanf_s(pStr,pFmt,&g_dwSubsystem)!=1) goto InvalidOption; } else if (!_stricmp(szOpt, "SSV")) @@ -440,7 +457,7 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) if(wcslen(pStr)==0) goto InvalidOption; //if no version { int major=-1,minor=-1; - if(swscanf_s(pStr,L"%d.%d",&major, &minor)==2) + if(swscanf_s(pStr,W("%d.%d"),&major, &minor)==2) { if((major >= 0)&&(major < 0xFFFF)) pAsm->m_wSSVersionMajor = (WORD)major; @@ -455,7 +472,7 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto InvalidOption; pStr++; - WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? L"%lx" : L"%ld"; + const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld"); if(swscanf_s(pStr,pFmt,&g_dwFileAlignment)!=1) goto InvalidOption; if((g_dwFileAlignment & (g_dwFileAlignment-1)) || (g_dwFileAlignment < 0x200) || (g_dwFileAlignment > 0x10000)) @@ -469,7 +486,7 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto InvalidOption; pStr++; - WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? L"%lx" : L"%ld"; + const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld"); if(swscanf_s(pStr,pFmt,&g_dwComImageFlags)!=1) goto InvalidOption; } else if (!_stricmp(szOpt, "BAS")) @@ -477,7 +494,7 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto InvalidOption; pStr++; - WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? L"%I64x" : L"%I64d"; + const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%I64x") : W("%I64d"); if(swscanf_s(pStr,pFmt,&g_stBaseAddress)!=1) goto InvalidOption; if(g_stBaseAddress & 0xFFFF) { @@ -490,7 +507,7 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto InvalidOption; pStr++; - WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? L"%lx" : L"%ld"; + const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld"); if(swscanf_s(pStr,pFmt,&g_stSizeOfStackReserve)!=1) goto InvalidOption; } #ifdef _SPECIAL_INTERNAL_USE_ONLY @@ -606,11 +623,11 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) } } while(j); - wcscat_s(wzOutputFilename, MAX_FILENAME_LENGTH,(IsDLL ? L".dll" : (IsOBJ ? L".obj" : L".exe"))); + wcscat_s(wzOutputFilename, MAX_FILENAME_LENGTH,(IsDLL ? W(".dll") : (IsOBJ ? W(".obj") : W(".exe")))); } if(wzIncludePath == NULL) { - if(0!=WszGetEnvironmentVariable(L"ILASM_INCLUDE",wzIncludePathBuffer,MAX_FILENAME_LENGTH)) + if(0!=WszGetEnvironmentVariable(W("ILASM_INCLUDE"),wzIncludePathBuffer,MAX_FILENAME_LENGTH)) wzIncludePath = wzIncludePathBuffer; } //------------ Assembler initialization done. Now, to business ----------------------- @@ -672,6 +689,7 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) } else { +#ifndef FEATURE_PAL DWORD dwBinType; if(GetBinaryTypeA(szInputFilename,&dwBinType)) { @@ -679,6 +697,7 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) fAllFilesPresent = FALSE; } else +#endif { pAsm->SetSourceFileName(FullFileName(wzInputFilename,uCodePage)); // deletes the argument! @@ -745,7 +764,7 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) { wcscpy_s(wzNewOutputFilename,MAX_FILENAME_LENGTH+16,wzOutputFilename); exitval = (int)StringCchPrintfW(&wzNewOutputFilename[wcslen(wzNewOutputFilename)], 32, - L".%d",iFile+1); + W(".%d"),iFile+1); MakeProperSourceFileName(pwzDeltaFiles[iFile], uCodePage, wzInputFilename, szInputFilename); if(pAsm->m_fReportProgress) { @@ -770,6 +789,7 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) } else { +#ifndef FEATURE_PAL DWORD dwBinType; if(GetBinaryTypeA(szInputFilename,&dwBinType)) { @@ -777,6 +797,7 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) fAllFilesPresent = FALSE; } else +#endif if (SUCCEEDED(pAsm->InitMetaDataForENC(wzNewOutputFilename))) { pAsm->SetSourceFileName(FullFileName(wzInputFilename,uCodePage)); // deletes the argument! @@ -847,8 +868,8 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) } else printf("Insufficient memory\n"); - WszSetEnvironmentVariable(L"COMP_ENC_OPENSCOPE", L""); - WszSetEnvironmentVariable(L"COMP_ENC_EMIT", L""); + WszSetEnvironmentVariable(W("COMP_ENC_OPENSCOPE"), W("")); + WszSetEnvironmentVariable(W("COMP_ENC_EMIT"), W("")); if(exitval || bNoDebug) { @@ -859,7 +880,7 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) pc = &wzOutputFilename[wcslen(wzOutputFilename)]; *pc = L'.'; } - wcscpy_s(pc+1,4,L"PDB"); + wcscpy_s(pc+1,4,W("PDB")); #undef DeleteFileW DeleteFileW(wzOutputFilename); } @@ -896,11 +917,45 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv) #pragma warning(pop) #endif - +#ifndef FEATURE_CORECLR HINSTANCE GetModuleInst() { return (NULL); } +#endif // !FEATURE_CORECLR +#ifdef FEATURE_PAL +int main(int argc, char* str[]) +{ + g_pszExeFile = str[0]; + if (0 != PAL_Initialize(argc, str)) + { + fprintf(stderr,"Error: Fail to PAL_Initialize\n"); + exit(1); + } + + WCHAR **argv = new WCHAR*[argc]; + for (int i = 0; i < argc; i++) { + int length = MultiByteToWideChar(CP_ACP, 0, str[i], -1, NULL, 0); + ASSERTE_ALL_BUILDS(length != 0); + LPWSTR result = new (nothrow) WCHAR[length]; + ASSERTE_ALL_BUILDS(result != NULL); + + length = MultiByteToWideChar(CP_ACP, 0, str[i], -1, result, length); + ASSERTE_ALL_BUILDS (length != 0); + + argv[i] = result; + } + + int ret = wmain(argc, argv); + + for (int i = 0 ; i < argc; i++) { + delete[] argv[i]; + } + delete[] argv; + + return ret; +} +#endif // FEATURE_PAL diff --git a/src/ilasm/writer.cpp b/src/ilasm/writer.cpp index 1b1056213a..542b2fd3c3 100644 --- a/src/ilasm/writer.cpp +++ b/src/ilasm/writer.cpp @@ -36,7 +36,7 @@ HRESULT Assembler::InitMetaData() if(bClock) bClock->cMDInitBegin = GetTickCount(); #ifdef FEATURE_CORECLR - hr = MetaDataGetDispenser(CLSID_CorMetaDataDispenser, + hr = metaDataGetDispenser(CLSID_CorMetaDataDispenser, IID_IMetaDataDispenserEx, (void **)&m_pDisp); #else hr = LegacyActivationShim::ClrCoCreateInstance( @@ -67,6 +67,7 @@ HRESULT Assembler::InitMetaData() if(FAILED(hr = m_pEmitter->QueryInterface(IID_IMetaDataImport2, (void**)&m_pImporter))) goto exit; +#ifndef FEATURE_CORECLR hr = CoCreateInstance(CLSID_CorSymWriter_SxS, NULL, CLSCTX_INPROC_SERVER, @@ -84,6 +85,7 @@ HRESULT Assembler::InitMetaData() fprintf(stderr, "Error: QueryInterface(IID_ISymUnmanagedWriter) returns %X\n",hr); m_pSymWriter = NULL; } +#endif // !FEATURE_CORECLR //m_Parser = new AsmParse(m_pEmitter); m_fInitialisedMetaData = TRUE; @@ -231,6 +233,9 @@ HRESULT Assembler::CreateTLSDirectory() { HRESULT Assembler::CreateDebugDirectory() { HRESULT hr = S_OK; + HCEESECTION sec = m_pILSection; + BYTE *de; + ULONG deOffset; // Only emit this if we're also emitting debug info. if (!(m_fGeneratePDB && m_pSymWriter)) @@ -281,9 +286,6 @@ HRESULT Assembler::CreateDebugDirectory() // Note that UpdateResource doesn't work correctly if the debug directory is // in the data section. So instead we put it in the text section (same as // cs compiler). - HCEESECTION sec = m_pILSection;//m_pGlobalDataSection; - BYTE *de; - if (FAILED(hr = m_pCeeFileGen->GetSectionBlock(sec, sizeof(debugDirIDD) + param.debugDirDataSize, @@ -292,7 +294,6 @@ HRESULT Assembler::CreateDebugDirectory() goto ErrExit; // Where did we get that memory? - ULONG deOffset; if (FAILED(hr = m_pCeeFileGen->GetSectionDataLen(sec, &deOffset))) goto ErrExit; @@ -1026,7 +1027,7 @@ HRESULT Assembler::ResolveLocalMemberRefs() if(IsMdPrivateScope(pListMD->m_Attr)) { - WCHAR* p = wcsstr(wzUniBuf,L"$PST06"); + WCHAR* p = wcsstr(wzUniBuf,W("$PST06")); if(p) *p = 0; } @@ -1466,11 +1467,15 @@ HRESULT Assembler::CreatePEFile(__in __nullterminated WCHAR *pwzOutputFilename) if(m_wzResourceFile) { +#ifdef FEATURE_PAL + report->msg("Warning: The Win32 resource file '%S' is ignored and not emitted on xPlatform.\n", m_wzResourceFile); +#else if (FAILED(hr=m_pCeeFileGen->SetResourceFileName(m_pCeeFile, m_wzResourceFile))) { report->msg("Warning: failed to set Win32 resource file name '%S', hr=0x%8.8X\n The Win32 resource is not emitted.\n", m_wzResourceFile, hr); } +#endif } if (FAILED(hr=CreateTLSDirectory())) goto exit; diff --git a/src/ilasm/writer_enc.cpp b/src/ilasm/writer_enc.cpp index 79f5245448..d8b87bb88c 100644 --- a/src/ilasm/writer_enc.cpp +++ b/src/ilasm/writer_enc.cpp @@ -71,6 +71,7 @@ HRESULT Assembler::InitMetaDataForENC(__in __nullterminated WCHAR* wzOrigFileNam if(!Init()) goto exit; // close and re-open CeeFileGen and CeeFile hr = S_OK; +#ifndef FEATURE_CORECLR hr = CoCreateInstance(CLSID_CorSymWriter_SxS, NULL, CLSCTX_INPROC_SERVER, @@ -79,7 +80,7 @@ HRESULT Assembler::InitMetaDataForENC(__in __nullterminated WCHAR* wzOrigFileNam if(SUCCEEDED(hr)) { WCHAR* pwc = &wzOrigFileName[wcslen(wzOrigFileName)]; - wcscat_s(wzOrigFileName,MAX_SCOPE_LENGTH,L".pdb"); + wcscat_s(wzOrigFileName,MAX_SCOPE_LENGTH,W(".pdb")); if(m_pSymWriter) m_pSymWriter->Initialize((IUnknown*)m_pEmitter, wzOrigFileName, NULL, @@ -91,7 +92,7 @@ HRESULT Assembler::InitMetaDataForENC(__in __nullterminated WCHAR* wzOrigFileNam fprintf(stderr, "Error: CoCreateInstance(IID_ISymUnmanagedWriter) returns %X\n",hr); m_pSymWriter = NULL; } - +#endif exit: return hr; @@ -363,8 +364,8 @@ REPT_STEP Class* pClass; Method* pMethod; FILE* pF = NULL; - wcscat_s(pwzOutputFilename,MAX_SCOPE_LENGTH,L".dil"); - if(_wfopen_s(&pF,pwzOutputFilename,L"wb")==0) + 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; @@ -426,7 +427,7 @@ REPT_STEP DWORD metaDataSize; if (FAILED(hr=pENCEmitter->GetDeltaSaveSize(cssAccurate, &metaDataSize))) goto exit; - wcscat_s(pwzOutputFilename,MAX_SCOPE_LENGTH,L".dmeta"); + wcscat_s(pwzOutputFilename,MAX_SCOPE_LENGTH,W(".dmeta")); pENCEmitter->SaveDelta(pwzOutputFilename,0); // second arg (dwFlags) is not used *pEnd = 0; pENCEmitter->Release(); diff --git a/src/ildasm/unixcoreclrloader/coreclrloader.h b/src/ildasm/unixcoreclrloader/coreclrloader.h index 0b1aa481f8..7a938ab808 100644 --- a/src/ildasm/unixcoreclrloader/coreclrloader.h +++ b/src/ildasm/unixcoreclrloader/coreclrloader.h @@ -3,6 +3,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // +#ifndef CORECLRLOADER_H +#define CORECLRLOADER_H typedef int (*InitializeCoreCLRFunction)( const char* exePath, const char* appDomainFriendlyName, @@ -29,4 +31,5 @@ public: void* LoadFunction(const char* functionName); int Finish(); }; +#endif // CORECLRLOADER_H diff --git a/src/inc/cor.h b/src/inc/cor.h index 7ef264d80c..159e7aaf46 100644 --- a/src/inc/cor.h +++ b/src/inc/cor.h @@ -2012,7 +2012,7 @@ typedef enum // slot on the caller's stack. // -#define COR_REQUIRES_SECOBJ_ATTRIBUTE L"System.Security.DynamicSecurityMethodAttribute" +#define COR_REQUIRES_SECOBJ_ATTRIBUTE W("System.Security.DynamicSecurityMethodAttribute") #define COR_REQUIRES_SECOBJ_ATTRIBUTE_ANSI "System.Security.DynamicSecurityMethodAttribute" #define COR_COMPILERSERVICE_DISCARDABLEATTRIBUTE L"System.Runtime.CompilerServices.DiscardableAttribute" diff --git a/src/inc/corhdr.h b/src/inc/corhdr.h index 4ff22db0a6..7a036afd1e 100644 --- a/src/inc/corhdr.h +++ b/src/inc/corhdr.h @@ -1703,7 +1703,7 @@ typedef enum CorAttributeTargets #define INTEROP_COMIMPORT_TYPE "System.Runtime.InteropServices.ComImportAttribute" #define INTEROP_COMIMPORT_SIG {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 0, ELEMENT_TYPE_VOID} -#define INTEROP_GUID_TYPE_W L"System.Runtime.InteropServices.GuidAttribute" +#define INTEROP_GUID_TYPE_W W("System.Runtime.InteropServices.GuidAttribute") #define INTEROP_GUID_TYPE "System.Runtime.InteropServices.GuidAttribute" #define INTEROP_GUID_SIG {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_STRING} diff --git a/src/pal/inc/rt/ntimage.h b/src/pal/inc/rt/ntimage.h index d6c273f794..7bd2faecab 100644 --- a/src/pal/inc/rt/ntimage.h +++ b/src/pal/inc/rt/ntimage.h @@ -428,6 +428,7 @@ typedef PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS; // IMAGE_LIBRARY_PROCESS_TERM 0x0002 // Reserved. // IMAGE_LIBRARY_THREAD_INIT 0x0004 // Reserved. // IMAGE_LIBRARY_THREAD_TERM 0x0008 // Reserved. +#define IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA 0x0020 // Image can handle a high entropy 64-bit virtual address space. #define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE 0x0040 // DLL can move #define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100 // Image ix NX compatible #define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400 // Image does not use SEH. No SE handler may reside in this image @@ -796,7 +797,7 @@ typedef struct _IMAGE_RELOCATION { union { ULONG VirtualAddress; ULONG RelocCount; // Set to the real count when IMAGE_SCN_LNK_NRELOC_OVFL is set - } u; + }; ULONG SymbolTableIndex; USHORT Type; } IMAGE_RELOCATION; diff --git a/src/pal/inc/rt/palrt.h b/src/pal/inc/rt/palrt.h index b983217343..7426d5654f 100644 --- a/src/pal/inc/rt/palrt.h +++ b/src/pal/inc/rt/palrt.h @@ -1285,6 +1285,8 @@ typedef HANDLE HWND; #define IS_TEXT_UNICODE_SIGNATURE 0x0008 #define IS_TEXT_UNICODE_UNICODE_MASK 0x000F +BOOL IsTextUnicode(CONST VOID* lpv, int iSize, LPINT lpiResult); + typedef struct _LIST_ENTRY { struct _LIST_ENTRY *Flink; struct _LIST_ENTRY *Blink; diff --git a/src/palrt/CMakeLists.txt b/src/palrt/CMakeLists.txt index a66f148082..bc965db15a 100644 --- a/src/palrt/CMakeLists.txt +++ b/src/palrt/CMakeLists.txt @@ -11,6 +11,7 @@ set(PALRT_SOURCES memorystream.cpp path.cpp urlpars.cpp + unicode.cpp variant.cpp ) diff --git a/src/palrt/unicode.cpp b/src/palrt/unicode.cpp new file mode 100644 index 0000000000..2ea581586c --- /dev/null +++ b/src/palrt/unicode.cpp @@ -0,0 +1,28 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// +// + +#include "common.h" + +// This is a simplified implementation of IsTextUnicode. +// https://github.com/dotnet/coreclr/issues/2307 +BOOL IsTextUnicode(CONST VOID* lpv, int iSize, LPINT lpiResult) +{ + *lpiResult = 0; + + if (iSize < 2) return FALSE; + + BYTE * p = (BYTE *)lpv; + + // Check for Unicode BOM + if ((*p == 0xFF) && (*(p+1) == 0xFE)) + { + *lpiResult |= IS_TEXT_UNICODE_SIGNATURE; + return TRUE; + } + + return FALSE; +} + |