diff --git a/node.gyp b/node.gyp index 529a36ba83c113..31f95e03a26964 100644 --- a/node.gyp +++ b/node.gyp @@ -841,7 +841,8 @@ ], }], [ 'OS in "linux freebsd mac" and ' - 'target_arch=="x64"', { + 'target_arch=="x64" and ' + 'node_target_type=="executable"', { 'defines': [ 'NODE_ENABLE_LARGE_CODE_PAGES=1' ], 'sources': [ 'src/large_pages/node_large_page.cc', diff --git a/node.gypi b/node.gypi index e6f5872cc75460..a83c63e23da7f7 100644 --- a/node.gypi +++ b/node.gypi @@ -306,22 +306,6 @@ 'ldflags': [ '-Wl,-z,relro', '-Wl,-z,now' ] }], - [ 'OS=="linux" and ' - 'target_arch=="x64" and ' - 'llvm_version=="0.0"', { - 'ldflags': [ - '-Wl,-T', - '> std::hex >> start; @@ -136,26 +129,42 @@ static struct text_region FindNodeTextRegion() { iss >> offset; iss >> dev; iss >> inode; - if (inode != 0) { - std::string pathname; - iss >> pathname; - if (pathname == exename && permission == "r-xp") { - uintptr_t ntext = reinterpret_cast(&__nodetext); - if (ntext >= start && ntext < end) { - char* from = reinterpret_cast(hugepage_align_up(ntext)); - char* to = reinterpret_cast(hugepage_align_down(end)); - - if (from < to) { - size_t size = to - from; - nregion.found_text_region = true; - nregion.from = from; - nregion.to = to; - nregion.total_hugepages = size / hps; - } - break; - } - } - } + + if (inode == 0) + continue; + + std::string pathname; + iss >> pathname; + + if (start != reinterpret_cast(&__executable_start)) + continue; + + // The next line is our .text section. + if (!std::getline(ifs, map_line)) + break; + + iss = std::istringstream(map_line); + iss >> std::hex >> start; + iss >> dash; + iss >> std::hex >> end; + iss >> permission; + + if (permission != "r-xp") + break; + + char* from = reinterpret_cast(hugepage_align_up(start)); + char* to = reinterpret_cast(hugepage_align_down(end)); + + if (from >= to) + break; + + size_t size = to - from; + nregion.found_text_region = true; + nregion.from = from; + nregion.to = to; + nregion.total_hugepages = size / hps; + + break; } ifs.close(); @@ -408,14 +417,12 @@ int MapStaticCodeToLargePages() { return -1; } -#if defined(__linux__) || defined(__FreeBSD__) - if (r.from > reinterpret_cast(&MoveTextRegionToLargePages)) - return MoveTextRegionToLargePages(r); +#if defined(__FreeBSD__) + if (r.from < reinterpret_cast(&MoveTextRegionToLargePages)) + return -1; +#endif - return -1; -#elif defined(__APPLE__) return MoveTextRegionToLargePages(r); -#endif } bool IsLargePagesEnabled() {