From 5bcf9dd8afda0309f056f0485feaef46c8a22cd8 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Sat, 25 Dec 2021 12:39:31 -0800 Subject: [PATCH] Do not complain for minimal DT_GNU_HASH as by Rust. Also: .p_type is 32 bits only! https://github.com/upx/upx/issues/525 modified: p_lx_elf.cpp --- src/p_lx_elf.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index a3efd18d..27c23d89 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -815,7 +815,7 @@ PackLinuxElf64::PackLinuxElf64help1(InputFile *f) Elf64_Phdr const *phdr= phdri; for (int j = e_phnum; --j>=0; ++phdr) - if (Elf64_Phdr::PT_DYNAMIC==get_te64(&phdr->p_type)) { + if (Elf64_Phdr::PT_DYNAMIC==get_te32(&phdr->p_type)) { upx_uint64_t offset = check_pt_dynamic(phdr); dynseg= (Elf64_Dyn const *)(offset + file_image); invert_pt_dynamic(dynseg, @@ -1751,6 +1751,12 @@ PackLinuxElf32::invert_pt_dynamic(Elf32_Dyn const *dynp, unsigned headway) } } } + if (1==n_bucket && 0==buckets[0] + && 1==n_bitmask && 0==bitmask[0]) { + // 2021-09-11 Rust on RaspberryPi apparently uses this to minimize space. + // But then the DT_GNU_HASH symbol lookup algorithm always fails? + // https://github.com/upx/upx/issues/525 + } else if ((1+ bmax) < symbias) { char msg[90]; snprintf(msg, sizeof(msg), "bad DT_GNU_HASH (1+ max_bucket)=%#x < symbias=%#x", 1+ bmax, symbias); @@ -5620,6 +5626,12 @@ PackLinuxElf64::invert_pt_dynamic(Elf64_Dyn const *dynp, upx_uint64_t headway) } } } + if (1==n_bucket && 0==buckets[0] + && 1==n_bitmask && 0==bitmask[0]) { + // 2021-09-11 Rust on RaspberryPi apparently uses this to minimize space. + // But then the DT_GNU_HASH symbol lookup algorithm always fails? + // https://github.com/upx/upx/issues/525 + } else if ((1+ bmax) < symbias) { char msg[90]; snprintf(msg, sizeof(msg), "bad DT_GNU_HASH (1+ max_bucket)=%#x < symbias=%#x", 1+ bmax, symbias); @@ -5783,6 +5795,10 @@ Elf32_Sym const *PackLinuxElf32::elf_lookup(char const *name) const } } } + // 2021-12-25 FIXME: Some Rust programs use + // (1==n_bucket && 0==buckets[0] && 1==n_bitmask && 0==bitmask[0]) + // to minimize space in DT_GNU_HASH. This causes the fancy lookup to fail. + // Is a fallback to linear seach assumed? return nullptr; } @@ -5860,6 +5876,10 @@ Elf64_Sym const *PackLinuxElf64::elf_lookup(char const *name) const } } } + // 2021-12-25 FIXME: Some Rust programs use + // (1==n_bucket && 0==buckets[0] && 1==n_bitmask && 0==bitmask[0]) + // to minimize space in DT_GNU_HASH. This causes the fancy lookup to fail. + // Is a fallback to linear seach assumed? return nullptr; }