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 /src/ilasm | |
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.
Diffstat (limited to 'src/ilasm')
-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 |
13 files changed, 214 insertions, 85 deletions
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(); |