public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] ELF: reliably invoke md_elf_section_change_hook()
@ 2023-12-15 11:43 Jan Beulich
  0 siblings, 0 replies; only message in thread
From: Jan Beulich @ 2023-12-15 11:43 UTC (permalink / raw)
  To: bfd-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c26906716eacae672a32309865ea5cc9f3e192c5

commit c26906716eacae672a32309865ea5cc9f3e192c5
Author: Jan Beulich <jbeulich@suse.com>
Date:   Fri Dec 15 12:41:49 2023 +0100

    ELF: reliably invoke md_elf_section_change_hook()
    
    ... after any (sub)section change. While certain existing target hooks
    only look at now_seg, for a few others it looks as if failing to do so
    could have caused anomalies if sub-sections were used. In any event a
    subsequent x86 change is going to require the sub-section to be properly
    in place at the time the hook is invoked.
    
    This primarily means for obj_elf_section() to pass the new subsection
    into change_section(), for it to be set right away (ahead of invoking
    the hook).
    
    Also adjust obj_elf_ident() to invoke the hook after all section
    changes. (Note that obj_elf_version(), which also changes sections and
    then changes them back, has no hook invocation at all so far, so none
    are added. Presumably there is a reason for this difference in
    behavior.)

Diff:
---
 gas/config/obj-elf.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index 23eff51dbcf..1b77b2715d1 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -547,7 +547,8 @@ change_section (const char *name,
 		int entsize,
 		struct elf_section_match *match_p,
 		bool linkonce,
-		bool push)
+		bool push,
+		subsegT new_subsection)
 {
   asection *old_sec;
   segT sec;
@@ -585,10 +586,10 @@ change_section (const char *name,
   if (old_sec)
     {
       sec = old_sec;
-      subseg_set (sec, 0);
+      subseg_set (sec, new_subsection);
     }
   else
-    sec = subseg_force_new (name, 0);
+    sec = subseg_force_new (name, new_subsection);
 
   bed = get_elf_backend_data (stdoutput);
   ssect = (*bed->get_sec_type_attr) (stdoutput, sec);
@@ -828,7 +829,7 @@ obj_elf_change_section (const char *name,
 			struct elf_section_match *match_p,
 			bool linkonce)
 {
-  change_section (name, type, attr, entsize, match_p, linkonce, false);
+  change_section (name, type, attr, entsize, match_p, linkonce, false, 0);
 }
 
 static bfd_vma
@@ -1114,8 +1115,8 @@ obj_elf_section (int push)
   bfd_vma attr;
   bfd_vma gnu_attr;
   int entsize;
-  int linkonce;
-  subsegT new_subsection = -1;
+  bool linkonce;
+  subsegT new_subsection = 0;
   struct elf_section_match match;
   unsigned long linked_to_section_index = -1UL;
 
@@ -1499,7 +1500,8 @@ obj_elf_section (int push)
 	}
     }
 
-  change_section (name, type, attr, entsize, &match, linkonce, push);
+  change_section (name, type, attr, entsize, &match, linkonce, push,
+		  new_subsection);
 
   if (linked_to_section_index != -1UL)
     {
@@ -1507,9 +1509,6 @@ obj_elf_section (int push)
       elf_section_data (now_seg)->this_hdr.sh_link = linked_to_section_index;
       /* FIXME: Should we perform some sanity checking on the section index ?  */
     }
-
-  if (push && new_subsection != -1)
-    subseg_set (now_seg, new_subsection);
 }
 
 /* Change to the .bss section.  */
@@ -2529,9 +2528,17 @@ obj_elf_ident (int ignore ATTRIBUTE_UNUSED)
       *p = 0;
     }
   else
-    subseg_set (comment_section, 0);
+    {
+      subseg_set (comment_section, 0);
+#ifdef md_elf_section_change_hook
+      md_elf_section_change_hook ();
+#endif
+    }
   stringer (8 + 1);
   subseg_set (old_section, old_subsection);
+#ifdef md_elf_section_change_hook
+  md_elf_section_change_hook ();
+#endif
 }
 
 #ifdef INIT_STAB_SECTION

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-12-15 11:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-15 11:43 [binutils-gdb] ELF: reliably invoke md_elf_section_change_hook() Jan Beulich

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