From 4f5c4fce8878830d8e4e928fa0dbe3f4ee2eb2cd Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 14 Nov 2022 08:25:16 +1030 Subject: objcopy renaming section with explicit flags This tidies SEC_RELOC handling in bfd, in the process fixing a bug with objcopy when renaming sections. bfd/ * reloc.c (_bfd_generic_set_reloc): Set/clear SEC_RELOC depending on reloc count. * elf64-sparc.c (elf64_sparc_set_reloc): Likewise. binutils/ * objcopy.c (copy_relocations_in_section): Remove now unnecessary clearing of SEC_RELOC. * testsuite/binutils-all/rename-section-01.d: New test. * testsuite/binutils-all/objcopy.exp: Run it. gas/ * write.c (size_seg): Remove unneccesary twiddle of SEC_RELOC. (write_relocs): Likewise. Always call bfd_set_reloc. --- binutils/testsuite/binutils-all/objcopy.exp | 2 ++ binutils/testsuite/binutils-all/rename-section-01.d | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 binutils/testsuite/binutils-all/rename-section-01.d (limited to 'binutils/testsuite') diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp index 5871d43..aebfdb2 100644 --- a/binutils/testsuite/binutils-all/objcopy.exp +++ b/binutils/testsuite/binutils-all/objcopy.exp @@ -1448,3 +1448,5 @@ if { [istarget *-*-cygwin] || [istarget *-*-mingw*] } { if { ![is_xcoff_format] } { objcopy_test "pr25662" $src executable "" $ldflags } + +run_dump_test "rename-section-01" diff --git a/binutils/testsuite/binutils-all/rename-section-01.d b/binutils/testsuite/binutils-all/rename-section-01.d new file mode 100644 index 0000000..21d9013 --- /dev/null +++ b/binutils/testsuite/binutils-all/rename-section-01.d @@ -0,0 +1,14 @@ +#PROG: objcopy +#name: objcopy rename-section with flags - keep relocation +#source: needed-by-reloc.s +#objcopy: --rename-section .data=myrodata,contents,alloc,load,readonly +#objdump: -r +#notarget: alpha*-*-*vms* rx-*-elf [is_som_format] [is_aout_format] + +.*: +file format .* + +#... +RELOCATION RECORDS FOR .*myrodata.*: +OFFSET +TYPE +VALUE +0+ .* +#pass -- cgit v1.1