public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: dwz@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] Mark and init shstrtab[_len] and const in optimize_multifile
Date: Thu, 30 Jun 2022 13:34:55 +0200	[thread overview]
Message-ID: <20220630113455.30700-1-mark@klomp.org> (raw)

Old gcc (4.8.5) warn that shstrtab and shstrtab_len can be clobbered
by the longjump. Work around that by marking shstrtab_gnu and
shstrtab_dwarf5 as static and shstrtab and shstrtab_len as const.
Init shstrtab and shstrtab_len at declaration.

	* dwz.c (optimize_multifile): Make shstrtab_[gnu|dwarf5],
	shstrtab[_len] static. shstrtab[_len] init and make const.
---

https://code.wildebeest.org/git/user/mjw/dwz/commit/?h=static-const-shstrtab

 dwz.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/dwz.c b/dwz.c
index a3b289f..266d7e7 100644
--- a/dwz.c
+++ b/dwz.c
@@ -15589,15 +15589,17 @@ optimize_multifile (unsigned int *die_count)
   Elf_Scn *scn;
   Elf_Data *data;
   char *e_ident;
-  const char shstrtab_gnu[]
+  static const char shstrtab_gnu[]
     = "\0.shstrtab\0.note.gnu.build-id\0.gdb_index\0"
       ".debug_info\0.debug_abbrev\0.debug_line\0.debug_str\0.debug_macro";
-  const char shstrtab_dwarf5[]
+  static const char shstrtab_dwarf5[]
     = "\0.shstrtab\0.gdb_index\0"
       ".debug_info\0.debug_abbrev\0.debug_line\0.debug_str\0.debug_macro\0"
       ".debug_sup";
-  const char *shstrtab;
-  size_t shstrtab_len;
+  const char *shstrtab = dwarf_5 ? shstrtab_dwarf5 : shstrtab_gnu;
+  const size_t shstrtab_len = (dwarf_5
+			       ? sizeof shstrtab_dwarf5
+			       : sizeof shstrtab_gnu);
   const char *p;
   unsigned char note[0x24], *np, *supp;
   struct sha1_ctx ctx;
@@ -15623,16 +15625,6 @@ optimize_multifile (unsigned int *die_count)
       fprintf (stderr, "optimize_multifile\n");
     }
 
-  if (dwarf_5)
-    {
-      shstrtab = shstrtab_dwarf5;
-      shstrtab_len = sizeof shstrtab_dwarf5;
-    }
-  else
-    {
-      shstrtab = shstrtab_gnu;
-      shstrtab_len = sizeof shstrtab_gnu;
-    }
   debug_sections[DEBUG_INFO].size = multi_info_off;
   debug_sections[DEBUG_INFO].data
     = (multi_info_off
-- 
2.18.4


             reply	other threads:[~2022-06-30 11:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-30 11:34 Mark Wielaard [this message]
2022-06-30 11:47 ` Jakub Jelinek
2022-06-30 12:47   ` 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=20220630113455.30700-1-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=dwz@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).