From d04209d30f457ab2f0758c516678176d039e022f Mon Sep 17 00:00:00 2001 From: John Reiser Date: Thu, 28 Nov 2024 19:09:46 -0800 Subject: [PATCH] Unify 32-bit and 64-bit ::buildLinuxLoader modified: p_lx_elf.cpp --- src/p_lx_elf.cpp | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index e2af7287..5caa6130 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -1469,6 +1469,7 @@ PackLinuxElf32::buildLinuxLoader( int len = 0; unsigned m_decompr = methods_used | (1u << ph_forced_method(ph.method)); len += snprintf(sec, sizeof(sec), "%s", "SO_HEAD,ptr_NEXT,EXP_HEAD"); + // Start of dasiy-chain fall-through. if (((1u<e_machine==Elf32_Ehdr::EM_386 || this->e_machine==Elf32_Ehdr::EM_ARM) { len += snprintf(&sec[len], sizeof(sec) - len, ",%s", (opt->o_unix.android_old ? "UMF_ANDROID" : "UMF_LINUX")); } + else { + len += snprintf(&sec[len], sizeof(sec) - len, ",%s", "UMF_LINUX"); + } + if (hasLoaderSection("STRCON")) { + len += snprintf(&sec[len], sizeof(sec) - len, ",%s", "STRCON"); + } len += snprintf(&sec[len], sizeof(sec) - len, ",%s", "SO_TAIL,SO_MAIN"); (void)len; // Pacify the anal-retentive static analyzer which hates a good idiom. - NO_printf("%s\n", sec); + NO_printf("\n%s\n", sec); addLoader(sec, nullptr); relocateLoader(); { @@ -1510,7 +1518,7 @@ PackLinuxElf32::buildLinuxLoader( || this->e_machine==Elf32_Ehdr::EM_MIPS ) { // main program with ELF2 de-compressor (folded portion) initLoader(fold, szfold); - char sec[120]; + char sec[120]; memset(sec, 0, sizeof(sec)); // debug convenience int len = 0; unsigned m_decompr = methods_used | (1u << ph_forced_method(ph.method)); len += snprintf(sec, sizeof(sec), "%s", ".text,EXP_HEAD"); @@ -1539,8 +1547,8 @@ PackLinuxElf32::buildLinuxLoader( if (hasLoaderSection("SYSCALLS")) { len += snprintf(&sec[len], sizeof(sec) - len, ",%s", "SYSCALLS"); } - (void)len; - NO_printf("%s\n", sec); + (void)len; // Pacify the anal-retentive static analyzer which hates a good idiom. + NO_printf("\n%s\n", sec); addLoader(sec, nullptr); relocateLoader(); { @@ -1583,7 +1591,7 @@ PackLinuxElf32::buildLinuxLoader( set_te32(&h.sz_cpr, h.sz_cpr); set_te32(&h.sz_unc, h.sz_unc); memcpy(cprLoader, &h, sizeof(h)); // cprLoader will become FOLDEXEC - } + } // end (0 < szfold) initLoader(proto, szproto, -1, sz_cpr); NO_printf("FOLDEXEC unc=%#x cpr=%#x\n", sz_unc, sz_cpr); @@ -1620,7 +1628,7 @@ PackLinuxElf32::buildLinuxLoader( addLoader("ELFMAINZ,FOLDEXEC,IDENTSTR"); defineSymbols(ft); } - else { // ELF1 de-compressor + else { // main program with ELF1 de-compressor addStubEntrySections(ft, methods_used | (1u << ph_forced_method(ph.method)) ); if (!xct_off) { // main program defineSymbols(ft); @@ -1658,10 +1666,12 @@ PackLinuxElf64::buildLinuxLoader( // EXP_TAIL FIXME: unfilter // SO_TAIL // SO_MAIN C-language supervision based on PT_LOADs - char sec[120]; + char sec[120]; memset(sec, 0, sizeof(sec)); // debug convenience int len = 0; unsigned m_decompr = methods_used | (1u << ph_forced_method(ph.method)); len += snprintf(sec, sizeof(sec), "%s", "SO_HEAD,ptr_NEXT,EXP_HEAD"); + + // Start of dasiy-chain fall-through. if (((1u<e_machine==Elf64_Ehdr::EM_X86_64 || this->e_machine==Elf64_Ehdr::EM_AARCH64 || this->e_machine==Elf64_Ehdr::EM_PPC64 - ) { // main program with ELF2 de-compressor + ) { // main program with ELF2 de-compressor (folded portion) initLoader(fold, szfold); char sec[120]; memset(sec, 0, sizeof(sec)); // debug convenience int len = 0; @@ -1780,7 +1794,7 @@ PackLinuxElf64::buildLinuxLoader( NO_printf("FOLDEXEC unc=%#x cpr=%#x\n", sz_unc, sz_cpr); linker->addSection("FOLDEXEC", mb_cprLoader, sizeof(b_info) + sz_cpr, 0); if (xct_off - && (0 + && (this->e_machine==Elf64_Ehdr::EM_NONE || this->e_machine==Elf64_Ehdr::EM_X86_64 || this->e_machine==Elf64_Ehdr::EM_AARCH64 || this->e_machine==Elf64_Ehdr::EM_PPC64 @@ -1798,13 +1812,13 @@ PackLinuxElf64::buildLinuxLoader( && elfout.ehdr.e_ident[Elf64_Ehdr::EI_DATA]==Elf64_Ehdr::ELFDATA2MSB) { addLoader("ELFMAINZe"); } - if (!xct_off) { + if (!xct_off) { // main program defineSymbols(ft); } } else { // main program with ELF1 de-compressor addStubEntrySections(ft, methods_used | (1u << ph_forced_method(ph.method)) ); - if (!xct_off) { + if (!xct_off) { // main program defineSymbols(ft); } } @@ -5661,7 +5675,7 @@ int PackLinuxElf64::pack2_shlib(OutputFile *fo, Filter &ft, unsigned pre_xct_top fi->seek(p_offset, SEEK_SET); fi->read(ibuf, sz_elf_hdrs); total_in += sz_elf_hdrs; fo->write(ibuf, sz_elf_hdrs); total_out += sz_elf_hdrs; - fo->seek(sz_phdrx, SEEK_CUR); total_out += sz_phdrx; + fo->seek(sz_phdrx, SEEK_CUR); total_out += sz_phdrx; // leave space // Compare PackUnix::packExtent, especially "if (u_len)" . //