From 2a33f41b1d75db97a25b823dcc3cbb8f11713157 Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Fri, 25 May 2018 12:58:52 +0900 Subject: [PATCH] add --r2r option for nitool to test ready-to-run feature of coreclr 2.1 Change-Id: I2e5afc8cf0b64fb6627df196c0325607c22c401a --- NativeLauncher/installer-plugin/common.cc | 51 ++++++++++++---------- NativeLauncher/installer-plugin/common.h | 12 ++--- NativeLauncher/installer-plugin/nitool.cc | 14 ++++-- .../installer-plugin/prefer_dotnet_aot_plugin.cc | 2 +- 4 files changed, 46 insertions(+), 33 deletions(-) diff --git a/NativeLauncher/installer-plugin/common.cc b/NativeLauncher/installer-plugin/common.cc index 3ab426c..31596f4 100644 --- a/NativeLauncher/installer-plugin/common.cc +++ b/NativeLauncher/installer-plugin/common.cc @@ -102,7 +102,7 @@ static void smack_(const char* dllPath, const char* label) } } -static void crossgen(const char* dllPath, const char* appPath) +static void crossgen(const char* dllPath, const char* appPath, bool enableR2R) { //pid_t parent = getpid(); pid_t pid = fork(); @@ -148,9 +148,16 @@ static void crossgen(const char* dllPath, const char* appPath) std::vector argv = { __CROSSGEN_PATH, "/Trusted_Platform_Assemblies", tpa.c_str(), - "/JITPath", __JIT_PATH, - "/FragileNonVersionable" + "/JITPath", __JIT_PATH }; + + if (!enableR2R) { + fprintf(stderr, "FNV mode enabled!!!\n"); + argv.push_back("/FragileNonVersionable"); + } else { + fprintf(stderr, "R2R mode enabled!!!\n"); + } + if (appPath != nullptr) { argv.push_back("/App_Paths"); argv.push_back(appPath); @@ -245,7 +252,8 @@ static int appAotCb(pkgmgrinfo_appinfo_h handle, void *userData) } // When you create native image with pkgid, ni file is generated even though already ni file exist. - if (createNiUnderPkgRoot(pkgId) != 0) { + // Regenerate ni files with R2R mode forcibiliy. (there is no way to now which option is used) + if (createNiUnderPkgRoot(pkgId, true) != 0) { _ERR("Failed to get root path from [%s]", pkgId); return -1; } else { @@ -283,14 +291,14 @@ int regenerateAppNI() return 0; } -static void createCoreLibNI() +static void createCoreLibNI(bool enableR2R) { std::string coreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll"); std::string niCoreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.ni.dll"); std::string coreLibBackup = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll.Backup"); if (!niExist(coreLib, niCoreLib)) { - crossgen(coreLib.c_str(), nullptr); + crossgen(coreLib.c_str(), nullptr, enableR2R); if (!fileNotExist(niCoreLib)) { // change owner and groups for generated ni file. struct stat info; @@ -321,7 +329,6 @@ void removeNiUnderDirs(const char* rootPaths[], int count) void removeNiPlatform() { std::string coreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll"); - std::string niCoreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.ni.dll"); std::string coreLibBackup = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll.Backup"); if (fileNotExist(coreLibBackup)) { @@ -339,25 +346,25 @@ void removeNiPlatform() removeNiUnderDirs(platformDirs, 3); } -void createNiPlatform() +void createNiPlatform(bool enableR2R) { - createCoreLibNI(); + createCoreLibNI(enableR2R); const char* platformDirs[] = {__RUNTIME_DIR, __DEVICE_API_DIR, "/usr/bin"}; createNiUnderDirs(platformDirs, 3, [](const char* ni) { smack_(ni, "_"); - }, false); + }, enableR2R); } -void createNiSelect(const char* dllPath) +void createNiSelect(const char* dllPath, bool enableR2R) { - createCoreLibNI(); + createCoreLibNI(enableR2R); std::string niPath; if (!fileNotExist(dllPath)) { if (!niExist(dllPath, niPath)) { - crossgen(dllPath, nullptr); + crossgen(dllPath, nullptr, enableR2R); if (niExist(dllPath, niPath)) { // change owner and groups for generated ni file. struct stat info; @@ -375,7 +382,7 @@ void createNiSelect(const char* dllPath) } } -void createNiUnderDirs(const char* rootPaths[], int count, const char* ignores[], int igcount, afterCreate cb, bool update) +void createNiUnderDirs(const char* rootPaths[], int count, const char* ignores[], int igcount, afterCreate cb, bool update, bool enableR2R) { std::string appPaths; for (int i = 0; i < count; i++) { @@ -386,7 +393,7 @@ void createNiUnderDirs(const char* rootPaths[], int count, const char* ignores[] if (appPaths.back() == ':') appPaths.pop_back(); - auto convert = [&appPaths, ignores, igcount, &cb, update](const char* path, const char* name) { + auto convert = [&appPaths, ignores, igcount, &cb, update, enableR2R](const char* path, const char* name) { for (int i = 0; i < igcount; i++) { if (strcmp(path, ignores[i]) == 0) return; @@ -401,7 +408,7 @@ void createNiUnderDirs(const char* rootPaths[], int count, const char* ignores[] return; } } - crossgen(path, appPaths.c_str()); + crossgen(path, appPaths.c_str(), enableR2R); if (niExist(path, niPath)) { // change owner and groups for generated ni file. struct stat info; @@ -421,13 +428,13 @@ void createNiUnderDirs(const char* rootPaths[], int count, const char* ignores[] for (int i = 0; i < count; i++) scanFilesInDir(rootPaths[i], convert, 1); } -void createNiUnderDirs(const char* rootPaths[], int count, afterCreate cb, bool update) +void createNiUnderDirs(const char* rootPaths[], int count, afterCreate cb, bool update, bool enableR2R) { - createNiUnderDirs(rootPaths, count, nullptr, 0, cb, update); + createNiUnderDirs(rootPaths, count, nullptr, 0, cb, update, enableR2R); } -void createNiUnderDirs(const char* rootPaths[], int count, bool update) +void createNiUnderDirs(const char* rootPaths[], int count, bool update, bool enableR2R) { - createNiUnderDirs(rootPaths, count, nullptr, update); + createNiUnderDirs(rootPaths, count, nullptr, update, enableR2R); } int removeNiUnderPkgRoot(const char* pkgName) @@ -452,7 +459,7 @@ int removeNiUnderPkgRoot(const char* pkgName) } -int createNiUnderPkgRoot(const char* pkgName) +int createNiUnderPkgRoot(const char* pkgName, bool enableR2R) { std::string pkgRoot; if (getRootPath(pkgName, pkgRoot) < 0) @@ -487,7 +494,7 @@ int createNiUnderPkgRoot(const char* pkgName) _INFO("sleep %d usec", interval); usleep(interval); } - }, true); + }, true, enableR2R); return 0; } diff --git a/NativeLauncher/installer-plugin/common.h b/NativeLauncher/installer-plugin/common.h index 26fe0ee..325bb82 100644 --- a/NativeLauncher/installer-plugin/common.h +++ b/NativeLauncher/installer-plugin/common.h @@ -21,12 +21,12 @@ typedef std::function afterCreate; int regenerateAppNI(); -void createNiUnderDirs(const char* rootPaths[], int count, const char* ignores[], int igcount, afterCreate cb, bool update); -void createNiUnderDirs(const char* rootPaths[], int count, afterCreate cb, bool update); -void createNiUnderDirs(const char* rootPaths[], int count, bool update); -int createNiUnderPkgRoot(const char* pkgName); -void createNiPlatform(); -void createNiSelect(const char* dllPath); +void createNiUnderDirs(const char* rootPaths[], int count, const char* ignores[], int igcount, afterCreate cb, bool update, bool enableR2R); +void createNiUnderDirs(const char* rootPaths[], int count, afterCreate cb, bool update, bool enableR2R); +void createNiUnderDirs(const char* rootPaths[], int count, bool update, bool enableR2R); +int createNiUnderPkgRoot(const char* pkgName, bool enableR2R); +void createNiPlatform(bool enableR2R); +void createNiSelect(const char* dllPath, bool enableR2R); void removeNiPlatform(); int removeNiUnderPkgRoot(const char* pkgName); diff --git a/NativeLauncher/installer-plugin/nitool.cc b/NativeLauncher/installer-plugin/nitool.cc index 989fb42..bb996af 100644 --- a/NativeLauncher/installer-plugin/nitool.cc +++ b/NativeLauncher/installer-plugin/nitool.cc @@ -46,6 +46,7 @@ static void help(const char *argv0) " --dll - Create NI for DLL\n" " --pkg - Create NI for package\n" " --dir - Create NI for directory\n" + " --r2r - Use ready-to-run option (default: FNV)\n" " --reset-system - Remove System NI files\n" " --reset-pkg - Remove App NI files\n" " --regen-all-app - Re-generate All App NI files\n" @@ -66,12 +67,17 @@ int main(int argc, char* argv[]) bool dllMode = false; bool dirMode = false; bool rmPkgMode = false; + bool enableR2R = false; + + if (cmdOptionExists(argv, argv+argc, "--r2r")) { + enableR2R = true; + } if (cmdOptionExists(argv, argv+argc, "--help")) { help(argv[0]); return 0; } else if (cmdOptionExists(argv, argv+argc, "--system")) { - createNiPlatform(); + createNiPlatform(enableR2R); return 0; } else if (cmdOptionExists(argv, argv+argc, "--dll")) { dllMode = true; @@ -105,7 +111,7 @@ int main(int argc, char* argv[]) if (pkgMode) { for (const char* pkg : args) { - if (createNiUnderPkgRoot(pkg) != 0) { + if (createNiUnderPkgRoot(pkg, enableR2R) != 0) { fprintf(stderr, "Failed to get root path from [%s]\n", pkg); return 1; } @@ -119,9 +125,9 @@ int main(int argc, char* argv[]) } } else if (dllMode) { for (const char* dll : args) - createNiSelect(dll); + createNiSelect(dll, enableR2R); } else if (dirMode) { - createNiUnderDirs(args.data(), args.size(), false); + createNiUnderDirs(args.data(), args.size(), false, enableR2R); } return 0; diff --git a/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc b/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc index 83a018e..d7fd274 100644 --- a/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc +++ b/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc @@ -51,7 +51,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app } if (mdValue) { - if (createNiUnderPkgRoot(pkgId) != 0) { + if (createNiUnderPkgRoot(pkgId, false) != 0) { _ERR("Failed to get root path from [%s]", pkgId); return -1; } else { -- 2.7.4