public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Mark and init shstrtab[_len] and const in optimize_multifile
@ 2022-06-30 11:34 Mark Wielaard
  2022-06-30 11:47 ` Jakub Jelinek
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Wielaard @ 2022-06-30 11:34 UTC (permalink / raw)
  To: dwz; +Cc: Mark Wielaard

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-30 12:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-30 11:34 [PATCH] Mark and init shstrtab[_len] and const in optimize_multifile Mark Wielaard
2022-06-30 11:47 ` Jakub Jelinek
2022-06-30 12:47   ` Mark Wielaard

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).