bfd: ld: sframe: set SEC_EXCLUDE when discarding SFrame sections

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.
This commit is contained in:
Indu Bhagat
2025-07-13 06:22:54 -07:00
parent 6a959b1270
commit 2bb9b88136
4 changed files with 23 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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?
#...

View File

@@ -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"