Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aarch64 page-size support #80

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/elf.h
Expand Up @@ -127,6 +127,7 @@ typedef struct
#define ELFCLASSNUM 3

#define EI_DATA 5 /* Data encoding byte index */
#define EI_MACHINE 0x12 /* Machine byte index; machine is two bytes, subject to endianness */
#define ELFDATANONE 0 /* Invalid data encoding */
#define ELFDATA2LSB 1 /* 2's complement, little endian */
#define ELFDATA2MSB 2 /* 2's complement, big endian */
Expand Down
34 changes: 24 additions & 10 deletions src/patchelf.cc
Expand Up @@ -39,15 +39,6 @@ unsigned char * contents = 0;
#define ElfFileParamNames Elf_Ehdr, Elf_Phdr, Elf_Shdr, Elf_Addr, Elf_Off, Elf_Dyn, Elf_Sym


static unsigned int getPageSize(){
#ifdef MIPSEL
/* The lemote fuloong 2f kernel defconfig sets a page size of
16KB. */
return 4096 * 4;
#else
return 4096;
#endif
}


template<ElfFileParams>
Expand All @@ -57,6 +48,7 @@ class ElfFile
vector<Elf_Phdr> phdrs;
vector<Elf_Shdr> shdrs;

uint8_t machine;
bool littleEndian;

bool changed;
Expand Down Expand Up @@ -169,6 +161,9 @@ class ElfFile

void noDefaultLib();

unsigned int getPageSize();


private:

/* Convert an integer in big or little endian representation (as
Expand All @@ -186,6 +181,21 @@ class ElfFile
}
};

template<ElfFileParams>
unsigned int
ElfFile<ElfFileParamNames>::getPageSize() { //ElfFile<ElfFileParamNames> &ef){
// uint8_t machine = ef.machine;

if(machine == EM_AARCH64)
return 65536;
/* The lemote fuloong 2f kernel defconfig sets a page size of
16KB. */
if(machine == EM_MIPS_RS3_LE)
return 16384;
// default that works for some popular machines
return 4096;
}


/* !!! G++ creates broken code if this function is inlined, don't know
why... */
Expand Down Expand Up @@ -280,6 +290,9 @@ void ElfFile<ElfFileParamNames>::parse()

littleEndian = contents[EI_DATA] == ELFDATA2LSB;

// two-bytes, subject to endianness
machine = contents[EI_MACHINE];

if (rdi(hdr->e_type) != ET_EXEC && rdi(hdr->e_type) != ET_DYN)
error("wrong ELF type");

Expand Down Expand Up @@ -417,6 +430,7 @@ void ElfFile<ElfFileParamNames>::shiftFile(unsigned int extraPages, Elf_Addr sta
for (int i = 0; i < rdi(hdr->e_phnum); ++i) {
wri(phdrs[i].p_offset, rdi(phdrs[i].p_offset) + shift);
if (rdi(phdrs[i].p_align) != 0 &&
rdi(phdrs[i].p_align) != 1 && // Values of zero and one mean no alignment is required -- man elf
(rdi(phdrs[i].p_vaddr) - rdi(phdrs[i].p_offset)) % rdi(phdrs[i].p_align) != 0) {
debug("changing alignment of program header %d from %d to %d\n", i,
rdi(phdrs[i].p_align), getPageSize());
Expand Down Expand Up @@ -1445,7 +1459,7 @@ 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());
// debug("Kernel page size is %u bytes\n", getPageSize());

readFile(fileName);

Expand Down
1 change: 1 addition & 0 deletions tests/Makefile.am
Expand Up @@ -4,6 +4,7 @@ check_PROGRAMS = simple main main-scoped big-dynstr no-rpath

no_rpath_arch_TESTS = \
no-rpath-amd64.sh \
no-rpath-aarch64.sh \
no-rpath-armel.sh \
no-rpath-armhf.sh \
no-rpath-hurd-i386.sh \
Expand Down
2 changes: 1 addition & 1 deletion tests/big-dynstr.sh
@@ -1,4 +1,4 @@
#! /bin/sh -e
#! /bin/bash -e
SCRATCH=scratch/$(basename $0 .sh)

rm -rf ${SCRATCH}
Expand Down
2 changes: 1 addition & 1 deletion tests/no-rpath-prebuild.sh
@@ -1,4 +1,4 @@
#! /bin/sh -e
#! /bin/bash -e
set -x
ARCH="$1"

Expand Down
Binary file added tests/no-rpath-prebuild/no-rpath-aarch64
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/no-rpath.sh
@@ -1,4 +1,4 @@
#! /bin/sh -e
#! /bin/bash -e
SCRATCH=scratch/$(basename $0 .sh)

rm -rf ${SCRATCH}
Expand Down