diff options
Diffstat (limited to 'elf/readelflib.c')
-rw-r--r-- | elf/readelflib.c | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/elf/readelflib.c b/elf/readelflib.c index 5a1e2dc2df..499cccbcfc 100644 --- a/elf/readelflib.c +++ b/elf/readelflib.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1999-2018 Free Software Foundation, Inc. +/* Copyright (C) 1999-2019 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Andreas Jaeger <aj@suse.de>, 1999 and Jakub Jelinek <jakub@redhat.com>, 1999. @@ -15,7 +15,7 @@ You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, see - <http://www.gnu.org/licenses/>. */ + <https://www.gnu.org/licenses/>. */ /* This code is a heavily simplified version of the readelf program that's part of the current binutils development version. For architectures @@ -45,7 +45,6 @@ process_elf_file (const char *file_name, const char *lib, int *flag, { int i; unsigned int j; - ElfW(Addr) loadaddr; unsigned int dynamic_addr; size_t dynamic_size; char *program_interpreter; @@ -87,7 +86,6 @@ process_elf_file (const char *file_name, const char *lib, int *flag, libc5/libc6. */ *flag = FLAG_ELF; - loadaddr = -1; dynamic_addr = 0; dynamic_size = 0; program_interpreter = NULL; @@ -98,11 +96,6 @@ process_elf_file (const char *file_name, const char *lib, int *flag, switch (segment->p_type) { - case PT_LOAD: - if (loadaddr == (ElfW(Addr)) -1) - loadaddr = segment->p_vaddr - segment->p_offset; - break; - case PT_DYNAMIC: if (dynamic_addr) error (0, 0, _("more than one dynamic segment\n")); @@ -164,10 +157,10 @@ process_elf_file (const char *file_name, const char *lib, int *flag, if (size == 0) break; - *osversion = (abi_note [4] << 24) | - ((abi_note [5] & 0xff) << 16) | - ((abi_note [6] & 0xff) << 8) | - (abi_note [7] & 0xff); + *osversion = ((abi_note [4] << 24) + | ((abi_note [5] & 0xff) << 16) + | ((abi_note [6] & 0xff) << 8) + | (abi_note [7] & 0xff)); } break; @@ -176,11 +169,6 @@ process_elf_file (const char *file_name, const char *lib, int *flag, } } - if (loadaddr == (ElfW(Addr)) -1) - { - /* Very strange. */ - loadaddr = 0; - } /* Now we can read the dynamic sections. */ if (dynamic_size == 0) @@ -197,7 +185,29 @@ process_elf_file (const char *file_name, const char *lib, int *flag, check_ptr (dyn_entry); if (dyn_entry->d_tag == DT_STRTAB) { - dynamic_strings = (char *) (file_contents + dyn_entry->d_un.d_val - loadaddr); + /* Find the file offset of the segment containing the dynamic + string table. */ + ElfW(Off) loadoff = -1; + for (i = 0, segment = elf_pheader; + i < elf_header->e_phnum; i++, segment++) + { + if (segment->p_type == PT_LOAD + && dyn_entry->d_un.d_val >= segment->p_vaddr + && (dyn_entry->d_un.d_val - segment->p_vaddr + < segment->p_filesz)) + { + loadoff = segment->p_vaddr - segment->p_offset; + break; + } + } + if (loadoff == (ElfW(Off)) -1) + { + /* Very strange. */ + loadoff = 0; + } + + dynamic_strings = (char *) (file_contents + dyn_entry->d_un.d_val + - loadoff); check_ptr (dynamic_strings); break; } |