Skip to content

Commit bf73d6e

Browse files
committed
Adjust PT_MIPS_ABIFLAGS segment if present
When loading the executable on MIPS, the dynamic loader looks for MIPS ABI flags using PT_MIPS_ABIFLAGS header. The flags themselves are stored in the .MIPS.abiflags section, so the header must be updated when the section is moved. Here we also import PT_MIPS_ABIFLAGS definition from glibc commit 0bd956720c457ff054325b48f26ac7c91cb060e8. Closes: #82 Signed-off-by: Ivan A. Melnikov <[email protected]>
1 parent b240bb8 commit bf73d6e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/elf.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,9 +1574,10 @@ typedef struct
15741574

15751575
/* Legal values for p_type field of Elf32_Phdr. */
15761576

1577-
#define PT_MIPS_REGINFO 0x70000000 /* Register usage information */
1578-
#define PT_MIPS_RTPROC 0x70000001 /* Runtime procedure table. */
1579-
#define PT_MIPS_OPTIONS 0x70000002
1577+
#define PT_MIPS_REGINFO 0x70000000 /* Register usage information. */
1578+
#define PT_MIPS_RTPROC 0x70000001 /* Runtime procedure table. */
1579+
#define PT_MIPS_OPTIONS 0x70000002
1580+
#define PT_MIPS_ABIFLAGS 0x70000003 /* FP mode requirement. */
15801581

15811582
/* Special program header types. */
15821583

src/patchelf.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,18 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
766766
}
767767
}
768768

769+
/* If there is .MIPS.abiflags section, then the PT_MIPS_ABIFLAGS
770+
segment must be sync'ed with it. */
771+
if (sectionName == ".MIPS.abiflags") {
772+
for (auto & phdr : phdrs) {
773+
if (rdi(phdr.p_type) == PT_MIPS_ABIFLAGS) {
774+
phdr.p_offset = shdr.sh_offset;
775+
phdr.p_vaddr = phdr.p_paddr = shdr.sh_addr;
776+
phdr.p_filesz = phdr.p_memsz = shdr.sh_size;
777+
}
778+
}
779+
}
780+
769781
curOff += roundUp(i.second.size(), sectionAlignment);
770782
}
771783

0 commit comments

Comments
 (0)