aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@suse.com>2023-12-15 12:41:49 +0100
committerJan Beulich <jbeulich@suse.com>2023-12-15 12:41:49 +0100
commitc26906716eacae672a32309865ea5cc9f3e192c5 (patch)
tree725ef6f8ea43bf77588d8423cd2bb798bcec51dc
parentf27110955454028a389d38a7c5017e36b625bdb5 (diff)
downloadfsf-binutils-gdb-c26906716eacae672a32309865ea5cc9f3e192c5.zip
fsf-binutils-gdb-c26906716eacae672a32309865ea5cc9f3e192c5.tar.gz
fsf-binutils-gdb-c26906716eacae672a32309865ea5cc9f3e192c5.tar.bz2
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.)
-rw-r--r--gas/config/obj-elf.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index 23eff51..1b77b27 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