Statically initialise target common sections
authorAlan Modra <amodra@gmail.com>
Wed, 16 Dec 2020 21:14:48 +0000 (07:44 +1030)
committerAlan Modra <amodra@gmail.com>
Fri, 18 Dec 2020 00:04:16 +0000 (10:34 +1030)
This tidies initialisation of target common sections, doing so using a
static initialiser rather than via code and deleting unnecessary
symbol_ptr_ptr variables (the one in asection is used instead).

The patch also initialises ecoff.c:bfd_debug_section using
BFD_FAKE_SECTION.  That does change bfd_debug_section slightly,
output_section was NULL now bfd_debug_section, and symbol_ptr_ptr
was NULL now &bfd_debug_section.symbol, but I believe those changes
are safe.

bfd/
* ecoff.c (bfd_debug_section): Init using BFD_FAKE_SECTION.
(ecoff_scom_section, ecoff_scom_symbol): Statically init using
BFD_FAKE_SECTION and GLOBAL_SYM_INIT.  Delete initialisation code.
(ecoff_scom_symbol_ptr): Delete.
* elf32-m32r.c (m32r_elf_scom_section, m32r_elf_scom_symbol),
(m32r_elf_scom_symbol_ptr),
* elf32-score.c (score_elf_scom_section, score_elf_scom_symbol),
(score_elf_scom_symbol_ptr),
* elf32-score7.c (score_elf_scom_section, score_elf_scom_symbol),
(score_elf_scom_symbol_ptr),
* elf32-tic6x.c (tic6x_elf_scom_section, tic6x_elf_scom_symbol),
(tic6x_elf_scom_symbol_ptr),
* elf32-v850.c (v850_elf_scom_section, v850_elf_scom_symbol),
(v850_elf_scom_symbol_ptr),
(v850_elf_tcom_section, v850_elf_tcom_symbol),
(v850_elf_tcom_symbol_ptr),
(v850_elf_zcom_section, v850_elf_zcom_symbol),
(v850_elf_zcom_symbol_ptr),
* elf64-mmix.c (mmix_elf_reg_section, mmix_elf_reg_section_symbol),
(mmix_elf_reg_section_symbol_ptr),
* elfxx-mips.c (mips_elf_scom_section, mips_elf_scom_symbol),
(mips_elf_scom_symbol_ptr): Likewise.
gas/
* ecoff.c (ecoff_frob_symbol): Rename scom_section to
ecoff_scom_section and statically initialise.

bfd/ChangeLog
bfd/ecoff.c
bfd/elf32-m32r.c
bfd/elf32-score.c
bfd/elf32-score7.c
bfd/elf32-tic6x.c
bfd/elf32-v850.c
bfd/elf64-mmix.c
bfd/elfxx-mips.c
gas/ChangeLog
gas/ecoff.c

index f88a56567eeec9a3785af9c3691c276e7f99c190..40d96a86a7627be2d3d07d90aac45585fb282dce 100644 (file)
@@ -1,3 +1,18 @@
+2020-12-18  Alan Modra  <amodra@gmail.com>
+
+       * ecoff.c (bfd_debug_section): Init using BFD_FAKE_SECTION.
+       (ecoff_scom_section, ecoff_scom_symbol): Statically init using
+       BFD_FAKE_SECTION and GLOBAL_SYM_INIT.  Delete initialisation code.
+       * elf32-m32r.c (m32r_elf_scom_section, m32r_elf_scom_symbol),
+       * elf32-score.c (score_elf_scom_section, score_elf_scom_symbol),
+       * elf32-score7.c (score_elf_scom_section, score_elf_scom_symbol),
+       * elf32-tic6x.c (tic6x_elf_scom_section, tic6x_elf_scom_symbol),
+       * elf32-v850.c (v850_elf_scom_section, v850_elf_scom_symbol),
+       (v850_elf_tcom_section, v850_elf_tcom_symbol),
+       (v850_elf_zcom_section, v850_elf_zcom_symbol),
+       * elf64-mmix.c (mmix_elf_reg_section, mmix_elf_reg_section_symbol),
+       * elfxx-mips.c (mips_elf_scom_section, mips_elf_scom_symbol): Likewise.
+
 2020-12-16  Alan Modra  <amodra@gmail.com>
 
        * elfxx-target.h (elfNN_bed): Constify.
index 2e4bf888bea6a7bfa6c875278c9e04790ee8eaa5..22060e7477846889da6123cea01b5048c85f6d42 100644 (file)
 \f
 /* This stuff is somewhat copied from coffcode.h.  */
 static asection bfd_debug_section =
-{
-  /* name,     id,  section_id, index, next, prev, flags,        */
-     "*DEBUG*", 0,   0,                 0,     NULL, NULL, 0,
-  /* user_set_vma,        */
-     0,
-  /* linker_mark, linker_has_input, gc_mark, compress_status,     */
-     0,                  0,                1,       0,
-  /* segment_mark, sec_info_type, use_rela_p,                     */
-     0,                   0,             0,
-  /* sec_flg0, sec_flg1, sec_flg2, sec_flg3, sec_flg4, sec_flg5,   */
-     0,               0,        0,        0,        0,        0,
-  /* vma, lma, size, rawsize, compressed_size, relax, relax_count, */
-     0,          0,   0,    0,       0,               0,     0,
-  /* output_offset, output_section, alignment_power,              */
-     0,                    NULL,           0,
-  /* relocation, orelocation, reloc_count, filepos, rel_filepos,   */
-     NULL,      NULL,        0,           0,       0,
-  /* line_filepos, userdata, contents, lineno, lineno_count,      */
-     0,                   NULL,     NULL,     NULL,   0,
-  /* entsize, kept_section, moving_line_filepos,                  */
-     0,              NULL,         0,
-  /* target_index, used_by_bfd, constructor_chain, owner,         */
-     0,                   NULL,        NULL,              NULL,
-  /* symbol,                                                      */
-     NULL,
-  /* symbol_ptr_ptr,                                              */
-     NULL,
-  /* map_head, map_tail,                                          */
-     { NULL }, { NULL },
-  /* already_assigned                                             */
-     NULL,
-};
+  BFD_FAKE_SECTION (bfd_debug_section, NULL, "*DEBUG*", 0, 0);
 
 /* Create an ECOFF object.  */
 
@@ -644,8 +613,11 @@ _bfd_ecoff_slurp_symbolic_info (bfd *abfd,
    faster assembler code.  This is what we use for the small common
    section.  */
 static asection ecoff_scom_section;
-static asymbol ecoff_scom_symbol;
-static asymbol *ecoff_scom_symbol_ptr;
+static const asymbol ecoff_scom_symbol =
+  GLOBAL_SYM_INIT (SCOMMON, &ecoff_scom_section);
+static asection ecoff_scom_section =
+  BFD_FAKE_SECTION (ecoff_scom_section, &ecoff_scom_symbol,
+                   SCOMMON, 0, SEC_IS_COMMON | SEC_SMALL_DATA);
 
 /* Create an empty symbol.  */
 
@@ -787,19 +759,6 @@ ecoff_set_symbol_info (bfd *abfd,
        }
       /* Fall through.  */
     case scSCommon:
-      if (ecoff_scom_section.name == NULL)
-       {
-         /* Initialize the small common section.  */
-         ecoff_scom_section.name = SCOMMON;
-         ecoff_scom_section.flags = SEC_IS_COMMON | SEC_SMALL_DATA;
-         ecoff_scom_section.output_section = &ecoff_scom_section;
-         ecoff_scom_section.symbol = &ecoff_scom_symbol;
-         ecoff_scom_section.symbol_ptr_ptr = &ecoff_scom_symbol_ptr;
-         ecoff_scom_symbol.name = SCOMMON;
-         ecoff_scom_symbol.flags = BSF_SECTION_SYM;
-         ecoff_scom_symbol.section = &ecoff_scom_section;
-         ecoff_scom_symbol_ptr = &ecoff_scom_symbol;
-       }
       asym->section = &ecoff_scom_section;
       asym->flags = 0;
       break;
@@ -3400,19 +3359,6 @@ ecoff_link_add_externals (bfd *abfd,
            }
          /* Fall through.  */
        case scSCommon:
-         if (ecoff_scom_section.name == NULL)
-           {
-             /* Initialize the small common section.  */
-             ecoff_scom_section.name = SCOMMON;
-             ecoff_scom_section.flags = SEC_IS_COMMON | SEC_SMALL_DATA;
-             ecoff_scom_section.output_section = &ecoff_scom_section;
-             ecoff_scom_section.symbol = &ecoff_scom_symbol;
-             ecoff_scom_section.symbol_ptr_ptr = &ecoff_scom_symbol_ptr;
-             ecoff_scom_symbol.name = SCOMMON;
-             ecoff_scom_symbol.flags = BSF_SECTION_SYM;
-             ecoff_scom_symbol.section = &ecoff_scom_section;
-             ecoff_scom_symbol_ptr = &ecoff_scom_symbol;
-           }
          section = &ecoff_scom_section;
          break;
        case scSUndefined:
index 533d662ee8956b2df1fe8c5c0db855aa13e32fb1..46fb6c7975286cfa149b8673d8b8264a67238cd3 100644 (file)
@@ -1337,8 +1337,11 @@ _bfd_m32r_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
    _SDA_BASE.  This is what we use for the small common section.  This
    approach is copied from elf32-mips.c.  */
 static asection m32r_elf_scom_section;
-static asymbol m32r_elf_scom_symbol;
-static asymbol *m32r_elf_scom_symbol_ptr;
+static const asymbol m32r_elf_scom_symbol =
+  GLOBAL_SYM_INIT (".scommon", &m32r_elf_scom_section);
+static asection m32r_elf_scom_section =
+  BFD_FAKE_SECTION (m32r_elf_scom_section, &m32r_elf_scom_symbol,
+                   ".scommon", 0, SEC_IS_COMMON | SEC_SMALL_DATA);
 
 /* Handle the special M32R section numbers that a symbol may use.  */
 
@@ -1350,19 +1353,6 @@ _bfd_m32r_elf_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, asymbol *asym)
   switch (elfsym->internal_elf_sym.st_shndx)
     {
     case SHN_M32R_SCOMMON:
-      if (m32r_elf_scom_section.name == NULL)
-       {
-         /* Initialize the small common section.  */
-         m32r_elf_scom_section.name = ".scommon";
-         m32r_elf_scom_section.flags = SEC_IS_COMMON | SEC_SMALL_DATA;
-         m32r_elf_scom_section.output_section = &m32r_elf_scom_section;
-         m32r_elf_scom_section.symbol = &m32r_elf_scom_symbol;
-         m32r_elf_scom_section.symbol_ptr_ptr = &m32r_elf_scom_symbol_ptr;
-         m32r_elf_scom_symbol.name = ".scommon";
-         m32r_elf_scom_symbol.flags = BSF_SECTION_SYM;
-         m32r_elf_scom_symbol.section = &m32r_elf_scom_section;
-         m32r_elf_scom_symbol_ptr = &m32r_elf_scom_symbol;
-       }
       asym->section = &m32r_elf_scom_section;
       asym->value = elfsym->internal_elf_sym.st_size;
       break;
index 80380573d5ef560dc5f4d885cf56ab1c25830a5e..5c15c7014551c4bc851289658d5ea214dff976d6 100644 (file)
@@ -201,8 +201,11 @@ static bfd *reldyn_sorting_bfd;
    faster assembler code.  This is what we use for the small common
    section.  This approach is copied from ecoff.c.  */
 static asection score_elf_scom_section;
-static asymbol  score_elf_scom_symbol;
-static asymbol  *score_elf_scom_symbol_ptr;
+static const asymbol score_elf_scom_symbol =
+  GLOBAL_SYM_INIT (".scommon", &score_elf_scom_section);
+static asection score_elf_scom_section =
+  BFD_FAKE_SECTION (score_elf_scom_section, &score_elf_scom_symbol,
+                   ".scommon", 0, SEC_IS_COMMON | SEC_SMALL_DATA);
 
 static bfd_vma
 score_bfd_get_16 (bfd *abfd, const void *data)
@@ -3031,19 +3034,6 @@ s3_bfd_score_elf_symbol_processing (bfd *abfd, asymbol *asym)
        break;
       /* Fall through.  */
     case SHN_SCORE_SCOMMON:
-      if (score_elf_scom_section.name == NULL)
-       {
-         /* Initialize the small common section.  */
-         score_elf_scom_section.name = ".scommon";
-         score_elf_scom_section.flags = SEC_IS_COMMON | SEC_SMALL_DATA;
-         score_elf_scom_section.output_section = &score_elf_scom_section;
-         score_elf_scom_section.symbol = &score_elf_scom_symbol;
-         score_elf_scom_section.symbol_ptr_ptr = &score_elf_scom_symbol_ptr;
-         score_elf_scom_symbol.name = ".scommon";
-         score_elf_scom_symbol.flags = BSF_SECTION_SYM;
-         score_elf_scom_symbol.section = &score_elf_scom_section;
-         score_elf_scom_symbol_ptr = &score_elf_scom_symbol;
-       }
       asym->section = &score_elf_scom_section;
       asym->value = elfsym->internal_elf_sym.st_size;
       break;
index 8b2b4bc54b8cb61bfc3867827f284a8b215ab8c1..40ae21b727a96acf5c3d79dc2cb1a94fb8ddd4ea 100644 (file)
@@ -197,9 +197,12 @@ static bfd *reldyn_sorting_bfd;
    together, and then referenced via the gp pointer, which yields
    faster assembler code.  This is what we use for the small common
    section.  This approach is copied from ecoff.c.  */
-static asection  score_elf_scom_section;
-static asymbol   score_elf_scom_symbol;
-static asymbol * score_elf_scom_symbol_ptr;
+static asection score_elf_scom_section;
+static const asymbol score_elf_scom_symbol =
+  GLOBAL_SYM_INIT (".scommon", &score_elf_scom_section);
+static asection score_elf_scom_section =
+  BFD_FAKE_SECTION (score_elf_scom_section, &score_elf_scom_symbol,
+                   ".scommon", 0, SEC_IS_COMMON | SEC_SMALL_DATA);
 
 static bfd_reloc_status_type
 score_elf_hi16_reloc (bfd *abfd ATTRIBUTE_UNUSED,
@@ -2836,19 +2839,6 @@ s7_bfd_score_elf_symbol_processing (bfd *abfd, asymbol *asym)
        break;
       /* Fall through.  */
     case SHN_SCORE_SCOMMON:
-      if (score_elf_scom_section.name == NULL)
-       {
-         /* Initialize the small common section.  */
-         score_elf_scom_section.name = ".scommon";
-         score_elf_scom_section.flags = SEC_IS_COMMON | SEC_SMALL_DATA;
-         score_elf_scom_section.output_section = &score_elf_scom_section;
-         score_elf_scom_section.symbol = &score_elf_scom_symbol;
-         score_elf_scom_section.symbol_ptr_ptr = &score_elf_scom_symbol_ptr;
-         score_elf_scom_symbol.name = ".scommon";
-         score_elf_scom_symbol.flags = BSF_SECTION_SYM;
-         score_elf_scom_symbol.section = &score_elf_scom_section;
-         score_elf_scom_symbol_ptr = &score_elf_scom_symbol;
-       }
       asym->section = &score_elf_scom_section;
       asym->value = elfsym->internal_elf_sym.st_size;
       break;
index 5f5abd591fe6bd03b6d21930edad4b3f0b68c20e..3ccb9c70ea305613abb11ef0136b75403cafd59b 100644 (file)
@@ -128,8 +128,11 @@ struct elf32_tic6x_obj_tdata
    faster assembler code.  This is what we use for the small common
    section.  This approach is copied from ecoff.c.  */
 static asection tic6x_elf_scom_section;
-static asymbol  tic6x_elf_scom_symbol;
-static asymbol  *tic6x_elf_scom_symbol_ptr;
+static const asymbol tic6x_elf_scom_symbol =
+  GLOBAL_SYM_INIT (".scommon", &tic6x_elf_scom_section);
+static asection tic6x_elf_scom_section =
+  BFD_FAKE_SECTION (tic6x_elf_scom_section, &tic6x_elf_scom_symbol,
+                   ".scommon", 0, SEC_IS_COMMON | SEC_SMALL_DATA);
 
 static reloc_howto_type elf32_tic6x_howto_table[] =
 {
@@ -2970,19 +2973,6 @@ elf32_tic6x_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, asymbol *asym)
   switch (elfsym->internal_elf_sym.st_shndx)
     {
     case SHN_TIC6X_SCOMMON:
-      if (tic6x_elf_scom_section.name == NULL)
-       {
-         /* Initialize the small common section.  */
-         tic6x_elf_scom_section.name = ".scommon";
-         tic6x_elf_scom_section.flags = SEC_IS_COMMON | SEC_SMALL_DATA;
-         tic6x_elf_scom_section.output_section = &tic6x_elf_scom_section;
-         tic6x_elf_scom_section.symbol = &tic6x_elf_scom_symbol;
-         tic6x_elf_scom_section.symbol_ptr_ptr = &tic6x_elf_scom_symbol_ptr;
-         tic6x_elf_scom_symbol.name = ".scommon";
-         tic6x_elf_scom_symbol.flags = BSF_SECTION_SYM;
-         tic6x_elf_scom_symbol.section = &tic6x_elf_scom_section;
-         tic6x_elf_scom_symbol_ptr = &tic6x_elf_scom_symbol;
-       }
       asym->section = &tic6x_elf_scom_section;
       asym->value = elfsym->internal_elf_sym.st_size;
       break;
index 8c6af580fc7e885ecf7a775cf90d890b578479ae..88e774b88e499f83bb6931a0a70d2538ce287018 100644 (file)
@@ -2929,15 +2929,29 @@ v850_elf_print_private_bfd_data (bfd *abfd, void * ptr)
    respectively, which yields smaller, faster assembler code.  This
    approach is copied from elf32-mips.c.  */
 
-static asection  v850_elf_scom_section;
-static asymbol   v850_elf_scom_symbol;
-static asymbol * v850_elf_scom_symbol_ptr;
-static asection  v850_elf_tcom_section;
-static asymbol   v850_elf_tcom_symbol;
-static asymbol * v850_elf_tcom_symbol_ptr;
-static asection  v850_elf_zcom_section;
-static asymbol   v850_elf_zcom_symbol;
-static asymbol * v850_elf_zcom_symbol_ptr;
+static asection v850_elf_scom_section;
+static const asymbol v850_elf_scom_symbol =
+  GLOBAL_SYM_INIT (".scommon", &v850_elf_scom_section);
+static asection v850_elf_scom_section =
+  BFD_FAKE_SECTION (v850_elf_scom_section, &v850_elf_scom_symbol,
+                   ".scommon", 0,
+                   SEC_IS_COMMON | SEC_SMALL_DATA | SEC_ALLOC | SEC_DATA);
+
+static asection v850_elf_tcom_section;
+static const asymbol v850_elf_tcom_symbol =
+  GLOBAL_SYM_INIT (".tcommon", &v850_elf_tcom_section);
+static asection v850_elf_tcom_section =
+  BFD_FAKE_SECTION (v850_elf_tcom_section, &v850_elf_tcom_symbol,
+                   ".tcommon", 0,
+                   SEC_IS_COMMON | SEC_SMALL_DATA);
+
+static asection v850_elf_zcom_section;
+static const asymbol v850_elf_zcom_symbol =
+  GLOBAL_SYM_INIT (".zcommon", &v850_elf_zcom_section);
+static asection v850_elf_zcom_section =
+  BFD_FAKE_SECTION (v850_elf_zcom_section, &v850_elf_zcom_symbol,
+                   ".zcommon", 0,
+                   SEC_IS_COMMON | SEC_SMALL_DATA);
 
 /* Given a BFD section, try to locate the
    corresponding ELF section index.  */
@@ -2997,56 +3011,16 @@ v850_elf_symbol_processing (bfd *abfd, asymbol *asym)
   switch (indx)
     {
     case SHN_V850_SCOMMON:
-      if (v850_elf_scom_section.name == NULL)
-       {
-         /* Initialize the small common section.  */
-         v850_elf_scom_section.name           = ".scommon";
-         v850_elf_scom_section.flags
-           = SEC_IS_COMMON | SEC_SMALL_DATA | SEC_ALLOC | SEC_DATA;
-         v850_elf_scom_section.output_section = & v850_elf_scom_section;
-         v850_elf_scom_section.symbol         = & v850_elf_scom_symbol;
-         v850_elf_scom_section.symbol_ptr_ptr = & v850_elf_scom_symbol_ptr;
-         v850_elf_scom_symbol.name            = ".scommon";
-         v850_elf_scom_symbol.flags           = BSF_SECTION_SYM;
-         v850_elf_scom_symbol.section         = & v850_elf_scom_section;
-         v850_elf_scom_symbol_ptr             = & v850_elf_scom_symbol;
-       }
       asym->section = & v850_elf_scom_section;
       asym->value = elfsym->internal_elf_sym.st_size;
       break;
 
     case SHN_V850_TCOMMON:
-      if (v850_elf_tcom_section.name == NULL)
-       {
-         /* Initialize the tcommon section.  */
-         v850_elf_tcom_section.name           = ".tcommon";
-         v850_elf_tcom_section.flags          = SEC_IS_COMMON | SEC_SMALL_DATA;
-         v850_elf_tcom_section.output_section = & v850_elf_tcom_section;
-         v850_elf_tcom_section.symbol         = & v850_elf_tcom_symbol;
-         v850_elf_tcom_section.symbol_ptr_ptr = & v850_elf_tcom_symbol_ptr;
-         v850_elf_tcom_symbol.name            = ".tcommon";
-         v850_elf_tcom_symbol.flags           = BSF_SECTION_SYM;
-         v850_elf_tcom_symbol.section         = & v850_elf_tcom_section;
-         v850_elf_tcom_symbol_ptr             = & v850_elf_tcom_symbol;
-       }
       asym->section = & v850_elf_tcom_section;
       asym->value = elfsym->internal_elf_sym.st_size;
       break;
 
     case SHN_V850_ZCOMMON:
-      if (v850_elf_zcom_section.name == NULL)
-       {
-         /* Initialize the zcommon section.  */
-         v850_elf_zcom_section.name           = ".zcommon";
-         v850_elf_zcom_section.flags          = SEC_IS_COMMON | SEC_SMALL_DATA;
-         v850_elf_zcom_section.output_section = & v850_elf_zcom_section;
-         v850_elf_zcom_section.symbol         = & v850_elf_zcom_symbol;
-         v850_elf_zcom_section.symbol_ptr_ptr = & v850_elf_zcom_symbol_ptr;
-         v850_elf_zcom_symbol.name            = ".zcommon";
-         v850_elf_zcom_symbol.flags           = BSF_SECTION_SYM;
-         v850_elf_zcom_symbol.section         = & v850_elf_zcom_section;
-         v850_elf_zcom_symbol_ptr             = & v850_elf_zcom_symbol;
-       }
       asym->section = & v850_elf_zcom_section;
       asym->value = elfsym->internal_elf_sym.st_size;
       break;
index 2fc491c5ffa268d133a10a1235d6b0978f5534e6..fad1a0a07cefb0d7b572776f254cbd55c92e6185 100644 (file)
@@ -2076,8 +2076,11 @@ mmix_elf_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
    formats (e.g. mmo) than for example a STT_REGISTER attribute.
    This section faking is based on a construct in elf32-mips.c.  */
 static asection mmix_elf_reg_section;
-static asymbol mmix_elf_reg_section_symbol;
-static asymbol *mmix_elf_reg_section_symbol_ptr;
+static const asymbol mmix_elf_reg_section_symbol =
+  GLOBAL_SYM_INIT (MMIX_REG_SECTION_NAME, &mmix_elf_reg_section);
+static asection mmix_elf_reg_section =
+  BFD_FAKE_SECTION (mmix_elf_reg_section, &mmix_elf_reg_section_symbol,
+                   MMIX_REG_SECTION_NAME, 0, SEC_NO_FLAGS);
 
 /* Handle the special section numbers that a symbol may use.  */
 
@@ -2090,19 +2093,6 @@ mmix_elf_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, asymbol *asym)
   switch (elfsym->internal_elf_sym.st_shndx)
     {
     case SHN_REGISTER:
-      if (mmix_elf_reg_section.name == NULL)
-       {
-         /* Initialize the register section.  */
-         mmix_elf_reg_section.name = MMIX_REG_SECTION_NAME;
-         mmix_elf_reg_section.flags = SEC_NO_FLAGS;
-         mmix_elf_reg_section.output_section = &mmix_elf_reg_section;
-         mmix_elf_reg_section.symbol = &mmix_elf_reg_section_symbol;
-         mmix_elf_reg_section.symbol_ptr_ptr = &mmix_elf_reg_section_symbol_ptr;
-         mmix_elf_reg_section_symbol.name = MMIX_REG_SECTION_NAME;
-         mmix_elf_reg_section_symbol.flags = BSF_SECTION_SYM;
-         mmix_elf_reg_section_symbol.section = &mmix_elf_reg_section;
-         mmix_elf_reg_section_symbol_ptr = &mmix_elf_reg_section_symbol;
-       }
       asym->section = &mmix_elf_reg_section;
       break;
 
index 4ea04d48c023f4327d61648aeec5e4c9c87a3da8..6d43d107428be6280356488c640a58e55e12247c 100644 (file)
@@ -7058,15 +7058,21 @@ elf_mips_abi_name (bfd *abfd)
    faster assembler code.  This is what we use for the small common
    section.  This approach is copied from ecoff.c.  */
 static asection mips_elf_scom_section;
-static asymbol mips_elf_scom_symbol;
-static asymbol *mips_elf_scom_symbol_ptr;
+static const asymbol mips_elf_scom_symbol =
+  GLOBAL_SYM_INIT (".scommon", &mips_elf_scom_section);
+static asection mips_elf_scom_section =
+  BFD_FAKE_SECTION (mips_elf_scom_section, &mips_elf_scom_symbol,
+                   ".scommon", 0, SEC_IS_COMMON | SEC_SMALL_DATA);
 
 /* MIPS ELF also uses an acommon section, which represents an
    allocated common symbol which may be overridden by a
    definition in a shared library.  */
 static asection mips_elf_acom_section;
-static asymbol mips_elf_acom_symbol;
-static asymbol *mips_elf_acom_symbol_ptr;
+static const asymbol mips_elf_acom_symbol =
+  GLOBAL_SYM_INIT (".acommon", &mips_elf_acom_section);
+static asection mips_elf_acom_section =
+  BFD_FAKE_SECTION (mips_elf_acom_section, &mips_elf_acom_symbol,
+                   ".acommon", 0, SEC_ALLOC);
 
 /* This is used for both the 32-bit and the 64-bit ABI.  */
 
@@ -7085,19 +7091,6 @@ _bfd_mips_elf_symbol_processing (bfd *abfd, asymbol *asym)
         either resolve these symbols to something in a shared
         library, or it can just leave them here.  For our purposes,
         we can consider these symbols to be in a new section.  */
-      if (mips_elf_acom_section.name == NULL)
-       {
-         /* Initialize the acommon section.  */
-         mips_elf_acom_section.name = ".acommon";
-         mips_elf_acom_section.flags = SEC_ALLOC;
-         mips_elf_acom_section.output_section = &mips_elf_acom_section;
-         mips_elf_acom_section.symbol = &mips_elf_acom_symbol;
-         mips_elf_acom_section.symbol_ptr_ptr = &mips_elf_acom_symbol_ptr;
-         mips_elf_acom_symbol.name = ".acommon";
-         mips_elf_acom_symbol.flags = BSF_SECTION_SYM;
-         mips_elf_acom_symbol.section = &mips_elf_acom_section;
-         mips_elf_acom_symbol_ptr = &mips_elf_acom_symbol;
-       }
       asym->section = &mips_elf_acom_section;
       break;
 
@@ -7110,19 +7103,6 @@ _bfd_mips_elf_symbol_processing (bfd *abfd, asymbol *asym)
        break;
       /* Fall through.  */
     case SHN_MIPS_SCOMMON:
-      if (mips_elf_scom_section.name == NULL)
-       {
-         /* Initialize the small common section.  */
-         mips_elf_scom_section.name = ".scommon";
-         mips_elf_scom_section.flags = SEC_IS_COMMON | SEC_SMALL_DATA;
-         mips_elf_scom_section.output_section = &mips_elf_scom_section;
-         mips_elf_scom_section.symbol = &mips_elf_scom_symbol;
-         mips_elf_scom_section.symbol_ptr_ptr = &mips_elf_scom_symbol_ptr;
-         mips_elf_scom_symbol.name = ".scommon";
-         mips_elf_scom_symbol.flags = BSF_SECTION_SYM;
-         mips_elf_scom_symbol.section = &mips_elf_scom_section;
-         mips_elf_scom_symbol_ptr = &mips_elf_scom_symbol;
-       }
       asym->section = &mips_elf_scom_section;
       asym->value = elfsym->internal_elf_sym.st_size;
       break;
index 2816395825e0adcde0126a5e2e9fe059d118cb98..8cdf93b6a2e32367bc903c27f9b1c4194ec1824e 100644 (file)
@@ -1,3 +1,8 @@
+2020-12-18  Alan Modra  <amodra@gmail.com>
+
+       * ecoff.c (ecoff_frob_symbol): Rename scom_section to
+       ecoff_scom_section, move to file scope and statically initialise.
+
 2020-12-16  Alan Modra  <amodra@gmail.com>
 
        * config/obj-elf.c (obj_elf_section): Don't set elf_osabi here.
index 69af2cef98b32787f494aa33fccc2a55d2bc48dd..b708f53dd1c60372cf3686980f3b2ad7acc1a803 100644 (file)
@@ -3551,6 +3551,13 @@ ecoff_stab (segT sec ATTRIBUTE_UNUSED,
   cur_file_ptr = save_file_ptr;
 }
 \f
+static asection ecoff_scom_section;
+static const asymbol ecoff_scom_symbol =
+  GLOBAL_SYM_INIT (SCOMMON, &ecoff_scom_section);
+static asection ecoff_scom_section =
+  BFD_FAKE_SECTION (ecoff_scom_section, &ecoff_scom_symbol,
+                   SCOMMON, 0, SEC_IS_COMMON | SEC_SMALL_DATA);
+
 /* Frob an ECOFF symbol.  Small common symbols go into a special
    .scommon section rather than bfd_com_section.  */
 
@@ -3561,23 +3568,7 @@ ecoff_frob_symbol (symbolS *sym)
       && S_GET_VALUE (sym) > 0
       && S_GET_VALUE (sym) <= bfd_get_gp_size (stdoutput))
     {
-      static asection scom_section;
-      static asymbol scom_symbol;
-
-      /* We must construct a fake section similar to bfd_com_section
-         but with the name .scommon.  */
-      if (scom_section.name == NULL)
-       {
-         scom_section = *bfd_com_section_ptr;
-         scom_section.name = ".scommon";
-         scom_section.output_section = &scom_section;
-         scom_section.symbol = &scom_symbol;
-         scom_section.symbol_ptr_ptr = &scom_section.symbol;
-         scom_symbol = *bfd_com_section_ptr->symbol;
-         scom_symbol.name = ".scommon";
-         scom_symbol.section = &scom_section;
-       }
-      S_SET_SEGMENT (sym, &scom_section);
+      S_SET_SEGMENT (sym, &ecoff_scom_section);
     }
 
   /* Double check weak symbols.  */
This page took 0.039615 seconds and 4 git commands to generate.