From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 5AD843858D28 for ; Fri, 6 Jan 2023 10:43:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5AD843858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-x42e.google.com with SMTP id a30so785792pfr.6 for ; Fri, 06 Jan 2023 02:43:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=SZvIT1upsdh4qZuCzpizR+n7qCKJoKkTPWcWN6gaKWQ=; b=JxLKTYYxhe+rPKgAxPany2Db4SicYVmXYiZMXjGa/R/qobBkPBnBAsYZAVrwP9jo1N PLRgMVbEqCbqX+jrVbau/pESGXZSqh7EfMpEG5ZuJQVpCRdHHa5MOCtueFs5ep5kmaPf TlYB7hRh83lP314NinQueSJ65aiVlDyChzZb6e/lkf4S7cDeX2Eadn9uco1F8xWKnhJi VnHQx6+RdfRCtiGw1F8NIDyo9GY2AMPbPO2drYN2GnGHIpXjL7kA7jfL0GBL88AVT0jA RoPyeMfz6xP/B6Tlt9mof6GO7+17n2BL/I9cUJesXrKotx+wBymElLBLXX/HMnUs9WjR cAXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SZvIT1upsdh4qZuCzpizR+n7qCKJoKkTPWcWN6gaKWQ=; b=p1W/YjEv13xxjZInxMZoAEfr7uo3ZSWqtPOt3IQXNyr/IjvWeQv01LXv9uNcqWYtD8 2vpemqceJxNtNVDf+zHKueX9epi/aH/xB1M6z16YxlsUyR2LDYyWUt2Rjx/3TQWvBdWY U//1Kx8XpEChUyRfO8x8sOk7sf+R5sflOG+27lk4W2SWrMUDcTErUUhMuBbzOe3BikMt u1iuPJjcVdLws3972MqLC6YUeGGlcAzRKXrKh6Ifzr604OBV7cRJ65ol/gt9a1Z738nf MAGKLCCCUghaSxX0C/HQKdpypDq059pr8qX2cGm5g5lnFo+OqNOzcUjNyeOlT6vUoVUj sjlw== X-Gm-Message-State: AFqh2kqIQgBjp1IgIsbBXNffjiJXB8Lm5OKS+6TFdkqLeA0rb6LBSSEQ wpb38AT2bRlJzc58Xr4oJz+4MYqXuD8= X-Google-Smtp-Source: AMrXdXtC2qg7BHu7YwB+b8hyxqxk6mhswS1QLTg+SzhjJXBIE8ITDnni7o1EbKJ1EDFhu0GImaAy4g== X-Received: by 2002:a62:506:0:b0:56c:7216:fbc6 with SMTP id 6-20020a620506000000b0056c7216fbc6mr55246856pff.30.1673001799046; Fri, 06 Jan 2023 02:43:19 -0800 (PST) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id a79-20020a621a52000000b0057255b7c8easm839183pfa.33.2023.01.06.02.43.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:43:18 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 66781114072E; Fri, 6 Jan 2023 21:13:16 +1030 (ACDT) Date: Fri, 6 Jan 2023 21:13:16 +1030 From: Alan Modra To: binutils@sourceware.org Subject: Make coff backend data read-only Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3035.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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. diff --git a/bfd/coff-go32.c b/bfd/coff-go32.c index 2088b2c3f74..501f88fb62b 100644 --- a/bfd/coff-go32.c +++ b/bfd/coff-go32.c @@ -80,6 +80,9 @@ _bfd_go32_mkobject (bfd * abfd) coff_data (abfd)->go32 = true; + bfd_coff_long_section_names (abfd) + = coff_backend_info (abfd)->_bfd_coff_long_section_names; + return true; } diff --git a/bfd/coff-sh.c b/bfd/coff-sh.c index f043dc2f0f9..cc6faac4e80 100644 --- a/bfd/coff-sh.c +++ b/bfd/coff-sh.c @@ -3079,7 +3079,7 @@ coff_small_new_section_hook (bfd *abfd, asection *section) /* This is copied from bfd_coff_std_swap_table so that we can change the default section alignment power. */ -static bfd_coff_backend_data bfd_coff_small_swap_table = +static const bfd_coff_backend_data bfd_coff_small_swap_table = { coff_swap_aux_in, coff_swap_sym_in, coff_swap_lineno_in, coff_swap_aux_out, coff_swap_sym_out, diff --git a/bfd/coffcode.h b/bfd/coffcode.h index 81d5cb0155e..e952bd77d6a 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -134,9 +134,10 @@ SUBSUBSECTION in output BFDs at runtime; if it is false, as it will be by default when generating an executable image, long section names are truncated; if true, the long section names extension is employed. The hook - points to a function that allows the value of the flag to be altered - at runtime, on formats that support long section names at all; on - other formats it points to a stub that returns an error indication. + points to a function that allows the value of a copy of the flag + in coff object tdata to be altered at runtime, on formats that + support long section names at all; on other formats it points + to a stub that returns an error indication. With input BFDs, the flag is set according to whether any long section names are detected while reading the section headers. For a completely @@ -462,15 +463,14 @@ static bool ticoff1_bad_format_hook static bool bfd_coff_set_long_section_names_allowed (bfd *abfd, int enable) { - coff_backend_info (abfd)->_bfd_coff_long_section_names = enable; + bfd_coff_long_section_names (abfd) = enable; return true; } #else /* !defined (COFF_LONG_SECTION_NAMES) */ static bool -bfd_coff_set_long_section_names_disallowed (bfd *abfd, int enable) +bfd_coff_set_long_section_names_disallowed (bfd *abfd ATTRIBUTE_UNUSED, + int enable ATTRIBUTE_UNUSED) { - (void) abfd; - (void) enable; return false; } #endif /* defined (COFF_LONG_SECTION_NAMES) */ @@ -1541,7 +1541,7 @@ Special entry points for gdb to swap in coff symbol table parts: .} bfd_coff_backend_data; . .#define coff_backend_info(abfd) \ -. ((bfd_coff_backend_data *) (abfd)->xvec->backend_data) +. ((const bfd_coff_backend_data *) (abfd)->xvec->backend_data) . .#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \ . ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i)) @@ -1584,7 +1584,7 @@ Special entry points for gdb to swap in coff symbol table parts: .#define bfd_coff_long_filenames(abfd) \ . (coff_backend_info (abfd)->_bfd_coff_long_filenames) .#define bfd_coff_long_section_names(abfd) \ -. (coff_backend_info (abfd)->_bfd_coff_long_section_names) +. (coff_data (abfd)->long_section_names) .#define bfd_coff_set_long_section_names(abfd, enable) \ . ((coff_backend_info (abfd)->_bfd_coff_set_long_section_names) (abfd, enable)) .#define bfd_coff_default_section_alignment_power(abfd) \ @@ -2067,6 +2067,9 @@ coff_mkobject (bfd * abfd) coff->relocbase = 0; coff->local_toc_sym_map = 0; + bfd_coff_long_section_names (abfd) + = coff_backend_info (abfd)->_bfd_coff_long_section_names; + /* make_abs_section(abfd);*/ return true; @@ -5445,7 +5448,7 @@ coff_final_link_postscript (bfd * abfd ATTRIBUTE_UNUSED, #define coff_SWAP_scnhdr_in coff_swap_scnhdr_in #endif -static bfd_coff_backend_data bfd_coff_std_swap_table ATTRIBUTE_UNUSED = +static const bfd_coff_backend_data bfd_coff_std_swap_table ATTRIBUTE_UNUSED = { coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in, coff_SWAP_aux_out, coff_SWAP_sym_out, @@ -5486,7 +5489,7 @@ static bfd_coff_backend_data bfd_coff_std_swap_table ATTRIBUTE_UNUSED = #ifdef TICOFF /* COFF0 differs in file/section header size and relocation entry size. */ -static bfd_coff_backend_data ticoff0_swap_table = +static const bfd_coff_backend_data ticoff0_swap_table = { coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in, coff_SWAP_aux_out, coff_SWAP_sym_out, @@ -5528,7 +5531,7 @@ static bfd_coff_backend_data ticoff0_swap_table = #ifdef TICOFF /* COFF1 differs in section header size. */ -static bfd_coff_backend_data ticoff1_swap_table = +static const bfd_coff_backend_data ticoff1_swap_table = { coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in, coff_SWAP_aux_out, coff_SWAP_sym_out, @@ -5789,7 +5792,7 @@ coff_bigobj_swap_aux_out (bfd * abfd, return AUXESZ; } -static bfd_coff_backend_data bigobj_swap_table = +static const bfd_coff_backend_data bigobj_swap_table = { coff_bigobj_swap_aux_in, coff_bigobj_swap_sym_in, coff_SWAP_lineno_in, coff_bigobj_swap_aux_out, coff_bigobj_swap_sym_out, diff --git a/bfd/libcoff-in.h b/bfd/libcoff-in.h index 8dec2852032..d27e5d4394f 100644 --- a/bfd/libcoff-in.h +++ b/bfd/libcoff-in.h @@ -79,21 +79,34 @@ typedef struct coff_tdata /* The unswapped external symbols. May be NULL. Read by _bfd_coff_get_external_symbols. */ void * external_syms; - /* If this is TRUE, the external_syms may not be freed. */ - bool keep_syms; /* The string table. May be NULL. Read by _bfd_coff_read_string_table. */ char *strings; /* The length of the strings table. For error checking. */ bfd_size_type strings_len; + + /* Set if long section names are supported. A writable copy of the COFF + backend flag _bfd_coff_long_section_names. */ + bool long_section_names; + + /* If this is TRUE, the external_syms may not be freed. */ + bool keep_syms; /* If this is TRUE, the strings may not be freed. */ bool keep_strings; /* If this is TRUE, the strings have been written out already. */ bool strings_written; + /* Is this a GO32 coff file? */ + bool go32; + /* Is this a PE format coff file? */ int pe; + + /* Copy of some of the f_flags bits in the COFF filehdr structure, + used by ARM code. */ + flagword flags; + /* Used by the COFF backend linker. */ struct coff_link_hash_entry **sym_hashes; @@ -111,13 +124,6 @@ typedef struct coff_tdata /* The timestamp from the COFF file header. */ long timestamp; - /* Copy of some of the f_flags bits in the COFF filehdr structure, - used by ARM code. */ - flagword flags; - - /* Is this a GO32 coff file? */ - bool go32; - /* A stub (extra data prepended before the COFF image) and its size. Used by coff-go32-exe, it contains executable data that loads the COFF object into memory. */ diff --git a/bfd/libcoff.h b/bfd/libcoff.h index 9d51cef13c7..f03330fcfa0 100644 --- a/bfd/libcoff.h +++ b/bfd/libcoff.h @@ -83,21 +83,34 @@ typedef struct coff_tdata /* The unswapped external symbols. May be NULL. Read by _bfd_coff_get_external_symbols. */ void * external_syms; - /* If this is TRUE, the external_syms may not be freed. */ - bool keep_syms; /* The string table. May be NULL. Read by _bfd_coff_read_string_table. */ char *strings; /* The length of the strings table. For error checking. */ bfd_size_type strings_len; + + /* Set if long section names are supported. A writable copy of the COFF + backend flag _bfd_coff_long_section_names. */ + bool long_section_names; + + /* If this is TRUE, the external_syms may not be freed. */ + bool keep_syms; /* If this is TRUE, the strings may not be freed. */ bool keep_strings; /* If this is TRUE, the strings have been written out already. */ bool strings_written; + /* Is this a GO32 coff file? */ + bool go32; + /* Is this a PE format coff file? */ int pe; + + /* Copy of some of the f_flags bits in the COFF filehdr structure, + used by ARM code. */ + flagword flags; + /* Used by the COFF backend linker. */ struct coff_link_hash_entry **sym_hashes; @@ -115,13 +128,6 @@ typedef struct coff_tdata /* The timestamp from the COFF file header. */ long timestamp; - /* Copy of some of the f_flags bits in the COFF filehdr structure, - used by ARM code. */ - flagword flags; - - /* Is this a GO32 coff file? */ - bool go32; - /* A stub (extra data prepended before the COFF image) and its size. Used by coff-go32-exe, it contains executable data that loads the COFF object into memory. */ @@ -841,7 +847,7 @@ typedef struct } bfd_coff_backend_data; #define coff_backend_info(abfd) \ - ((bfd_coff_backend_data *) (abfd)->xvec->backend_data) + ((const bfd_coff_backend_data *) (abfd)->xvec->backend_data) #define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \ ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i)) @@ -884,7 +890,7 @@ typedef struct #define bfd_coff_long_filenames(abfd) \ (coff_backend_info (abfd)->_bfd_coff_long_filenames) #define bfd_coff_long_section_names(abfd) \ - (coff_backend_info (abfd)->_bfd_coff_long_section_names) + (coff_data (abfd)->long_section_names) #define bfd_coff_set_long_section_names(abfd, enable) \ ((coff_backend_info (abfd)->_bfd_coff_set_long_section_names) (abfd, enable)) #define bfd_coff_default_section_alignment_power(abfd) \ diff --git a/bfd/peicode.h b/bfd/peicode.h index 6b71f204826..cc5a54e1843 100644 --- a/bfd/peicode.h +++ b/bfd/peicode.h @@ -292,6 +292,10 @@ pe_mkobject (bfd * abfd) pe->dos_message[15] = 0x0; memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr); + + bfd_coff_long_section_names (abfd) + = coff_backend_info (abfd)->_bfd_coff_long_section_names; + return true; } diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 80a5d52e227..b8958bcab57 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; -- Alan Modra Australia Development Lab, IBM