aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIndu Bhagat <indu.bhagat@oracle.com>2025-07-13 06:22:54 -0700
committerIndu Bhagat <indu.bhagat@oracle.com>2025-07-13 14:54:39 -0700
commit2bb9b8813667f40396be429639ecc1b636a726c1 (patch)
tree40d4d0863324eb389ed174db35ed267c08267b0f
parent6a959b127014b262bb62b9fd31fd4d1f4ce4777f (diff)
downloadgdb-users/ibhagat/try-pr33127-v1.zip
gdb-users/ibhagat/try-pr33127-v1.tar.gz
gdb-users/ibhagat/try-pr33127-v1.tar.bz2
bfd: ld: sframe: set SEC_EXCLUDE when discarding SFrame sectionsusers/ibhagat/try-pr33127-v1
Fix PR libsframe/33127 "ld -r" doesn't remove the sframe relocation against the discarded section When an SFrame section is marked for deletion, set its section size to zero. And mark it with SEC_EXCLUDE. Using the testcase provided by H.J. Lu. bfd/ PR ld/33127 * elf-sframe.c: Set section size to 0 if all FDEs are to be deleted. While at it, keep the rawsize updated. * elflink.c (bfd_elf_discard_info): Set SEC_EXCLUDE to mark for exclusion from final link. ld/ PR ld/33127 * testsuite/ld-x86-64/sframe-reloc-2.d: New test. * testsuite/ld-x86-64/x86-64.exp: Run sframe-reloc-2.
-rw-r--r--bfd/elf-sframe.c9
-rw-r--r--bfd/elflink.c2
-rw-r--r--ld/testsuite/ld-x86-64/sframe-reloc-2.d11
-rw-r--r--ld/testsuite/ld-x86-64/x86-64.exp1
4 files changed, 23 insertions, 0 deletions
diff --git a/bfd/elf-sframe.c b/bfd/elf-sframe.c
index b709e59..4e20e9a 100644
--- a/bfd/elf-sframe.c
+++ b/bfd/elf-sframe.c
@@ -274,12 +274,14 @@ _bfd_elf_discard_section_sframe
unsigned int i;
unsigned int func_desc_offset;
unsigned int num_fidx;
+ unsigned int num_fidx_deleted = 0;
struct sframe_dec_info *sfd_info;
changed = false;
/* FIXME - if relocatable link and changed = true, how does the final
.rela.sframe get updated ?. */
keep = false;
+ sec->rawsize = sec->size;
sfd_info = (struct sframe_dec_info *) elf_section_data (sec)->sec_info;
@@ -299,9 +301,16 @@ _bfd_elf_discard_section_sframe
if (!keep)
{
sframe_decoder_mark_func_deleted (sfd_info, i);
+ num_fidx_deleted++;
changed = true;
}
}
+
+ /* PR libsframe/33127
+ Set section size to zero if all FDE are to be deleted. Using size,
+ later bfd_elf_discard_info will mark this section as SEC_EXCLUDE. */
+ if (changed && num_fidx_deleted == num_fidx)
+ bfd_set_section_size (sec, 0);
}
return changed;
}
diff --git a/bfd/elflink.c b/bfd/elflink.c
index c4f57cf..852884e 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -15298,6 +15298,8 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
{
if (i->size != i->rawsize)
changed = 1;
+ if (i->size == 0)
+ i->flags |= SEC_EXCLUDE;
}
}
fini_reloc_cookie_for_section (&cookie, i);
diff --git a/ld/testsuite/ld-x86-64/sframe-reloc-2.d b/ld/testsuite/ld-x86-64/sframe-reloc-2.d
new file mode 100644
index 0000000..b1b787d
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/sframe-reloc-2.d
@@ -0,0 +1,11 @@
+#name: SFrame relocatable link - discarded section (PR ld/33127)
+#source: ../ld-elf/eh-group1.s
+#source: ../ld-elf/eh-group2.s
+#as: --gsframe
+#ld: -r
+#readelf: -rW
+
+#failif
+#...
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_NONE *0?
+#...
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index a682b13..8e3297e 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -568,6 +568,7 @@ run_dump_test "pr32809"
if { ![skip_sframe_tests] } {
run_dump_test "sframe-simple-1"
run_dump_test "sframe-reloc-1"
+ run_dump_test "sframe-reloc-2"
run_dump_test "sframe-plt-1"
run_dump_test "sframe-ibt-plt-1"
run_dump_test "sframe-pltgot-1"