diff --git a/src/main.cpp b/src/main.cpp index 4531f72b..c4c79077 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -869,6 +869,9 @@ static int do_option(int optc, const char *arg) case 676: opt->o_unix.android_shlib = true; break; + case 677: + opt->o_unix.force_pie = true; + break; case '\0': return -1; @@ -1020,6 +1023,7 @@ static const struct mfx_option longopts[] = {"unmap-all-pages", 0x10, 0, 674}, // linux /proc/self/exe vanishes {"preserve-build-id", 0, 0, 675}, {"android-shlib", 0, 0, 676}, + {"force-pie", 0, 0, 677}, // watcom/le {"le", 0x10, 0, 620}, // produce LE output // win32/pe diff --git a/src/options.h b/src/options.h index bdd9da4d..d3e36612 100644 --- a/src/options.h +++ b/src/options.h @@ -147,6 +147,7 @@ struct options_t { unsigned char osabi0; // replacement if 0==.e_ident[EI_OSABI] bool preserve_build_id; // copy the build-id to the compressed binary bool android_shlib; // keep some ElfXX_Shdr for dlopen() + bool force_pie; // choose DF_1_PIE instead of is_shlib } o_unix; struct { bool le; diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index 1b0817d2..d933e51c 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -1840,7 +1840,8 @@ bool PackLinuxElf32::canPack() dynstr= (char const *)elf_find_dynamic(Elf32_Dyn::DT_STRTAB); dynsym= (Elf32_Sym const *)elf_find_dynamic(Elf32_Dyn::DT_SYMTAB); - if (Elf32_Dyn::DF_1_PIE & elf_unsigned_dynamic(Elf32_Dyn::DT_FLAGS_1) + if (opt->o_unix.force_pie + || Elf32_Dyn::DF_1_PIE & elf_unsigned_dynamic(Elf32_Dyn::DT_FLAGS_1) || calls_crt1((Elf32_Rel const *)elf_find_dynamic(Elf32_Dyn::DT_REL), (int)elf_unsigned_dynamic(Elf32_Dyn::DT_RELSZ)) || calls_crt1((Elf32_Rel const *)elf_find_dynamic(Elf32_Dyn::DT_JMPREL), @@ -2076,7 +2077,8 @@ PackLinuxElf64::canPack() dynstr= (char const *)elf_find_dynamic(Elf64_Dyn::DT_STRTAB); dynsym= (Elf64_Sym const *)elf_find_dynamic(Elf64_Dyn::DT_SYMTAB); - if (Elf64_Dyn::DF_1_PIE & elf_unsigned_dynamic(Elf64_Dyn::DT_FLAGS_1) + if (opt->o_unix.force_pie + || Elf64_Dyn::DF_1_PIE & elf_unsigned_dynamic(Elf64_Dyn::DT_FLAGS_1) || calls_crt1((Elf64_Rela const *)elf_find_dynamic(Elf64_Dyn::DT_RELA), (int)elf_unsigned_dynamic(Elf64_Dyn::DT_RELASZ)) || calls_crt1((Elf64_Rela const *)elf_find_dynamic(Elf64_Dyn::DT_JMPREL),