diff options
Diffstat (limited to 'src/patchelf.cc')
-rw-r--r-- | src/patchelf.cc | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc index 2d9077c..ea6c6c0 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -48,7 +48,11 @@ static bool forceRPath = false; static std::vector<std::string> fileNames; static std::string outputFileName; static bool alwaysWrite = false; -static int pageSize = PAGESIZE; +#ifdef DEFAULT_PAGESIZE +static int forcedPageSize = DEFAULT_PAGESIZE; +#else +static int forcedPageSize = -1; +#endif typedef std::shared_ptr<std::vector<unsigned char>> FileContents; @@ -81,12 +85,6 @@ static bool hasAllowedPrefix(const std::string & s, const std::vector<std::strin } -static unsigned int getPageSize() -{ - return pageSize; -} - - template<ElfFileParams> class ElfFile { @@ -161,6 +159,8 @@ private: friend struct CompShdr; + unsigned int getPageSize() const; + void sortShdrs(); void shiftFile(unsigned int extraPages, Elf_Addr startPage); @@ -444,6 +444,29 @@ ElfFile<ElfFileParamNames>::ElfFile(FileContents fileContents) template<ElfFileParams> +unsigned int ElfFile<ElfFileParamNames>::getPageSize() const +{ + if (forcedPageSize > 0) + return forcedPageSize; + + // Architectures (and ABIs) can have different minimum section alignment + // requirements. There is no authoritative list of these values. The + // current list is extracted from GNU gold's source code (abi_pagesize). + switch (hdr->e_machine) { + case EM_SPARC: + case EM_MIPS: + case EM_PPC: + case EM_PPC64: + case EM_AARCH64: + case EM_TILEGX: + return 0x10000; + default: + return 0x1000; + } +} + + +template<ElfFileParams> void ElfFile<ElfFileParamNames>::sortPhdrs() { /* Sort the segments by offset. */ @@ -1608,8 +1631,6 @@ static void patchElf() if (!printInterpreter && !printRPath && !printSoname && !printNeeded) debug("patching ELF file '%s'\n", fileName.c_str()); - debug("Kernel page size is %u bytes\n", getPageSize()); - auto fileContents = readFile(fileName); std::string outputFileName2 = outputFileName.empty() ? fileName : outputFileName; @@ -1665,8 +1686,8 @@ int mainWrapped(int argc, char * * argv) } else if (arg == "--page-size") { if (++i == argc) error("missing argument"); - pageSize = atoi(argv[i]); - if (pageSize <= 0) error("invalid argument to --page-size"); + forcedPageSize = atoi(argv[i]); + if (forcedPageSize <= 0) error("invalid argument to --page-size"); } else if (arg == "--print-interpreter") { printInterpreter = true; |