From 22a95e1a37aff28238e9d40bbe4441aa554a14c6 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Fri, 6 Jan 2023 18:59:20 +1030 Subject: Make coff backend data read-only The bfd_coff_backend_data struct should be read-only, the only thing preventing this is that objcopy writes to one of the fields, _bfd_coff_long_section_names. This patch creates a copy of the field in bfd coff_obj_tdata, which makes more sense anyway. When enabling long section names the intent is to do so for a particular bfd, not for all bfds that might happen to be using the target xvec. bfd/ * coffcode.h: Update coff long section name comment. (bfd_coff_set_long_section_names_allowed): Use macro accessor to set flag. (bfd_coff_set_long_section_names_disallowed): Tidy. (coff_backend_info): Return a const pointer. (bfd_coff_std_swap_table, ticoff0_swap_table, ticoff1_swap_table), (bigobj_swap_table): Make const. (bfd_coff_long_section_names): Use tdata copy. (coff_mkobject): Set long_section_names from coff_backend_info. * coff-go32.c (_bfd_go32_mkobject): Likewise. * peicode.h (pe_mkobject): Likewise. * coff-sh.c (bfd_coff_small_swap_table): Make const. * libcoff-in.h (struct coff_tdata): Add long_section_names, reorder fields. * libcoff.h: Regenerate. binutils/ * objcopy.c (set_long_section_mode): Move earlier in file. (copy_object): Call set_long_section_mode here, after setting output format. (copy_file): Don't call set_long_section_mode. --- binutils/objcopy.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'binutils/objcopy.c') diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 80a5d52..b8958bc 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -2610,6 +2610,19 @@ check_new_section_flags (flagword flags, bfd * abfd, const char * secname) return flags; } +static void +set_long_section_mode (bfd *output_bfd, bfd *input_bfd, enum long_section_name_handling style) +{ + /* This is only relevant to Coff targets. */ + if (bfd_get_flavour (output_bfd) == bfd_target_coff_flavour) + { + if (style == KEEP + && bfd_get_flavour (input_bfd) == bfd_target_coff_flavour) + style = bfd_coff_long_section_names (input_bfd) ? ENABLE : DISABLE; + bfd_coff_set_long_section_names (output_bfd, style != DISABLE); + } +} + /* Copy object file IBFD onto OBFD. Returns TRUE upon success, FALSE otherwise. */ @@ -2660,6 +2673,9 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch) return false; } + /* This is a no-op on non-Coff targets. */ + set_long_section_mode (obfd, ibfd, long_section_names); + /* Set the Verilog output endianness based upon the input file's endianness. We may not be producing verilog format output, but testing this just adds extra code this is not really @@ -3765,19 +3781,6 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target, free (dir); } -static void -set_long_section_mode (bfd *output_bfd, bfd *input_bfd, enum long_section_name_handling style) -{ - /* This is only relevant to Coff targets. */ - if (bfd_get_flavour (output_bfd) == bfd_target_coff_flavour) - { - if (style == KEEP - && bfd_get_flavour (input_bfd) == bfd_target_coff_flavour) - style = bfd_coff_long_section_names (input_bfd) ? ENABLE : DISABLE; - bfd_coff_set_long_section_names (output_bfd, style != DISABLE); - } -} - /* The top-level control. */ static void @@ -3885,9 +3888,6 @@ copy_file (const char *input_filename, const char *output_filename, int ofd, gnu_debuglink_filename = NULL; } - /* This is a no-op on non-Coff targets. */ - set_long_section_mode (obfd, ibfd, long_section_names); - copy_archive (ibfd, obfd, output_target, force_output_target, input_arch); } else if (bfd_check_format_matches (ibfd, bfd_object, &obj_matching)) @@ -3913,9 +3913,6 @@ copy_file (const char *input_filename, const char *output_filename, int ofd, return; } - /* This is a no-op on non-Coff targets. */ - set_long_section_mode (obfd, ibfd, long_section_names); - if (! copy_object (ibfd, obfd, input_arch)) status = 1; -- cgit v1.1