From 48c551a237ded45fdca722d2e3849d5427aa16e8 Mon Sep 17 00:00:00 2001 From: winesync Date: Fri, 11 Sep 2020 13:04:09 +0200 Subject: [PATCH] [WINESYNC] dbghelp: Read the ELF program header corresponding to the target's architecture. Signed-off-by: Zebediah Figura Signed-off-by: Alexandre Julliard wine commit id bd620ffb443eaa2dba997dc5597cb37c44d757b7 by Zebediah Figura --- dll/win32/dbghelp/elf_module.c | 31 ++++++++++++++++++++++++------- dll/win32/dbghelp/image_private.h | 2 -- sdk/tools/winesync/dbghelp.cfg | 2 +- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/dll/win32/dbghelp/elf_module.c b/dll/win32/dbghelp/elf_module.c index 8049210c550..f84df836da6 100644 --- a/dll/win32/dbghelp/elf_module.c +++ b/dll/win32/dbghelp/elf_module.c @@ -332,7 +332,6 @@ static BOOL elf_map_file(struct elf_map_file_data* emfd, struct image_file_map* static const BYTE elf_signature[4] = { ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3 }; struct stat statbuf; unsigned int i; - Elf_Phdr phdr; size_t tmp, page_mask = sysconf( _SC_PAGESIZE ) - 1; char* filename; unsigned len; @@ -429,13 +428,31 @@ static BOOL elf_map_file(struct elf_map_file_data* emfd, struct image_file_map* fmap->u.elf.elf_start = ~0L; for (i = 0; i < fmap->u.elf.elfhdr.e_phnum; i++) { - if (elf_map_file_read(fmap, emfd, &phdr, sizeof(phdr), - fmap->u.elf.elfhdr.e_phoff + i * sizeof(phdr)) && - phdr.p_type == PT_LOAD) + if (fmap->addr_size == 32) { - tmp = (phdr.p_vaddr + phdr.p_memsz + page_mask) & ~page_mask; - if (fmap->u.elf.elf_size < tmp) fmap->u.elf.elf_size = tmp; - if (phdr.p_vaddr < fmap->u.elf.elf_start) fmap->u.elf.elf_start = phdr.p_vaddr; + Elf32_Phdr phdr; + + if (elf_map_file_read(fmap, emfd, &phdr, sizeof(phdr), + fmap->u.elf.elfhdr.e_phoff + i * sizeof(phdr)) && + phdr.p_type == PT_LOAD) + { + tmp = (phdr.p_vaddr + phdr.p_memsz + page_mask) & ~page_mask; + if (fmap->u.elf.elf_size < tmp) fmap->u.elf.elf_size = tmp; + if (phdr.p_vaddr < fmap->u.elf.elf_start) fmap->u.elf.elf_start = phdr.p_vaddr; + } + } + else + { + Elf64_Phdr phdr; + + if (elf_map_file_read(fmap, emfd, &phdr, sizeof(phdr), + fmap->u.elf.elfhdr.e_phoff + i * sizeof(phdr)) && + phdr.p_type == PT_LOAD) + { + tmp = (phdr.p_vaddr + phdr.p_memsz + page_mask) & ~page_mask; + if (fmap->u.elf.elf_size < tmp) fmap->u.elf.elf_size = tmp; + if (phdr.p_vaddr < fmap->u.elf.elf_start) fmap->u.elf.elf_start = phdr.p_vaddr; + } } } /* if non relocatable ELF, then remove fixed address from computation diff --git a/dll/win32/dbghelp/image_private.h b/dll/win32/dbghelp/image_private.h index 47fd7eed91e..868d346abdb 100644 --- a/dll/win32/dbghelp/image_private.h +++ b/dll/win32/dbghelp/image_private.h @@ -61,12 +61,10 @@ typedef struct section macho_section; #if defined(__ELF__) && !defined(DBGHELP_STATIC_LIB) #ifdef _WIN64 -#define Elf_Phdr Elf64_Phdr #define Elf_Dyn Elf64_Dyn #define Elf_Sym Elf64_Sym #define Elf_auxv_t Elf64_auxv_t #else -#define Elf_Phdr Elf32_Phdr #define Elf_Dyn Elf32_Dyn #define Elf_Sym Elf32_Sym #define Elf_auxv_t Elf32_auxv_t diff --git a/sdk/tools/winesync/dbghelp.cfg b/sdk/tools/winesync/dbghelp.cfg index 7376e9c5177..ed6da1caf6a 100644 --- a/sdk/tools/winesync/dbghelp.cfg +++ b/sdk/tools/winesync/dbghelp.cfg @@ -3,4 +3,4 @@ directories: files: include/dbghelp.h: sdk/include/psdk/dbghelp.h tags: - wine: cf78601b3781e64ea2745cf8084848acb69300a8 + wine: bd620ffb443eaa2dba997dc5597cb37c44d757b7