public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH 02/10] backends: Use elf_getshdrstrndx to find .odp section in ppc64_init
Date: Thu, 13 Sep 2018 23:02:00 -0000	[thread overview]
Message-ID: <1536879700-30439-3-git-send-email-mark@klomp.org> (raw)
In-Reply-To: <1536879700-30439-1-git-send-email-mark@klomp.org>

The .odp section is found by name. But ppc64_init used the e_shstrndx
Ehdr field for that. This is wrong if the file contains more than
SHN_LORESERVE sections. Use elf_getshdrstrndx instead to find the
shstrtab section.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 backends/ChangeLog    | 4 ++++
 backends/ppc64_init.c | 6 ++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/backends/ChangeLog b/backends/ChangeLog
index ada349f..fdff302 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,5 +1,9 @@
 2018-09-12  Mark Wielaard  <mark@klomp.org>
 
+	* ppc64_init.c (ppc64_init): Use elf_getshdrstrndx.
+
+2018-09-12  Mark Wielaard  <mark@klomp.org>
+
 	* aarch64_symbol.c (aarch64_check_special_symbol): Drop ehdr argument,
 	use elf_getshdrstrndx.
 	* alpha_symbol.c (alpha_check_special_symbol): Drop ehdr argument.
diff --git a/backends/ppc64_init.c b/backends/ppc64_init.c
index e567033..3db5e76 100644
--- a/backends/ppc64_init.c
+++ b/backends/ppc64_init.c
@@ -80,7 +80,9 @@ ppc64_init (Elf *elf __attribute__ ((unused)),
   if (elf != NULL)
     {
       GElf_Ehdr ehdr_mem, *ehdr = gelf_getehdr (elf, &ehdr_mem);
-      if (ehdr != NULL && ehdr->e_type != ET_REL)
+      size_t shstrndx;
+      if (ehdr != NULL && ehdr->e_type != ET_REL
+	  && elf_getshdrstrndx (elf, &shstrndx) == 0)
 	{
 	  /* We could also try through DT_PPC64_OPD and DT_PPC64_OPDSZ. */
 	  GElf_Shdr opd_shdr_mem, *opd_shdr;
@@ -93,7 +95,7 @@ ppc64_init (Elf *elf __attribute__ ((unused)),
 		  && opd_shdr->sh_type == SHT_PROGBITS
 		  && opd_shdr->sh_size > 0)
 		{
-		  const char *name = elf_strptr (elf, ehdr->e_shstrndx,
+		  const char *name = elf_strptr (elf, shstrndx,
 						 opd_shdr->sh_name);
 		  if (name != NULL && strcmp (name, ".opd") == 0)
 		    {
-- 
1.8.3.1

  parent reply	other threads:[~2018-09-13 23:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-13 23:01 Fix various issues with ELF files containing many sections Mark Wielaard
2018-09-13 23:02 ` [PATCH 07/10] libdw: dwarf_begin_elf should use elf_getshdrstrndx to get section names Mark Wielaard
2018-09-13 23:02 ` [PATCH 09/10] readelf: Use elf_getshdrnum in print_shdr and print_phdr Mark Wielaard
2018-09-13 23:02 ` [PATCH 04/10] elfcmp: Get, check and shdrstrndx for section names Mark Wielaard
2018-09-13 23:02 ` [PATCH 01/10] backends: Always use elf_getshdrstrndx in check_special_symbol Mark Wielaard
2018-09-13 23:02 ` [PATCH 05/10] libelf: Fix shnum and section zero handling Mark Wielaard
2018-09-13 23:02 ` [PATCH 10/10] libdwfl: Document core memory and remote memory ELF shdrs reading Mark Wielaard
2018-09-13 23:02 ` [PATCH 03/10] libebl: Use elf_getshdrstrndx in ebl_section_strip_p Mark Wielaard
2018-09-13 23:02 ` [PATCH 06/10] elflint: Use shnum and shstrndx instead of ehdr field directly Mark Wielaard
2018-09-13 23:02 ` Mark Wielaard [this message]
2018-09-13 23:02 ` [PATCH 08/10] strip,unstrip: Use and set shdrstrndx consistently Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1536879700-30439-3-git-send-email-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).