From 86e4d2447667296ee28d5ca6019959aec06cc0a1 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Tue, 3 Oct 2006 20:21:36 -0700 Subject: [PATCH] avoid circularity of sz_pack2 in PackLinuxElf64amd::defineSymbols() --- src/p_lx_elf.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index 3a1de403..95ae7a97 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -548,12 +548,25 @@ void PackLinuxElf64amd::defineSymbols(Filter const *) { unsigned const hlen = sz_elf_hdrs + sizeof(l_info) + sizeof(p_info); - unsigned len = sz_pack2; + // We want to know if compressed data, plus stub, plus a couple pages, + // will fit below the uncompressed program in memory. But we don't + // know the final total compressed size yet, so use the uncompressed + // size (total over all PT_LOAD64) as an upper bound. + unsigned len = 0; + acc_uint64l_t lo_va_user = ~0ul; // infinity + for (int j= get_native16(&ehdri.e_phnum); --j>=0; ) { + if (PT_LOAD64 == get_native32(&phdri[j].p_type)) { + len += (unsigned)get_native64(&phdri[j].p_filesz); + acc_uint64l_t const va = get_native64(&phdri[j].p_vaddr); + if (va < lo_va_user) { + lo_va_user = va; + } + } + } #define PAGE_MASK (~0u<<12) #define PAGE_SIZE (-PAGE_MASK) lsize = /*getLoaderSize()*/ 64 * 1024; // upper bound; avoid circularity - acc_uint64l_t const lo_va_user = 0x400000; // XXX acc_uint64l_t lo_va_stub = elfout.phdr[0].p_vaddr; acc_uint64l_t adrc; acc_uint64l_t adrm;