This bug is a result of an analysis of bug #465238. There sys-apps/elfix doesn't compile against dev-libs/libelf because the latter lacks ELF_C_RDWR_MMAP. This is a problem on uclibc systems where one cannot build dev-libs/elfutils due to numerous glibc-isms (some easily avoidable, others not). libelf does provide ELF_C_RDWR, but it doesn't work. (Interestingly enough, it also does not work with elfutils, although there ELF_C_RDWR_MMAP does.) Here's a little poc to demonstrate the problem --- its reduced code with no sanity checks. It simply toggles the SEGMEXEC flag on any program header marked PT_PAX_FLAGS. Replace ELF_C_RDWR_MMAP with ELF_C_RDWR as needed to demonstrate the above. #include <stdio.h> #include <stdlib.h> #include <gelf.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #define PF_SEGMEXEC (1 << 6) int main (int argc, char *argv[]) { Elf *elf; GElf_Phdr phdr; size_t i, phnum; int fd = open (argv[1], O_RDWR); elf_version(EV_CURRENT); elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL); elf_getphdrnum (elf, &phnum); for (i=0; i<phnum; i++) { gelf_getphdr (elf, i, &phdr); if (phdr.p_type == PT_PAX_FLAGS) { phdr.p_flags ^= PF_SEGMEXEC; gelf_update_phdr (elf, i, &phdr); } } elf_end (elf); close (fd); } Reproducible: Always
My attempt to get elfutils to build on uclibc are in bug #470884