lang_input_statement_type next pointers
authorAlan Modra <amodra@gmail.com>
Sat, 10 Aug 2019 01:00:19 +0000 (10:30 +0930)
committerAlan Modra <amodra@gmail.com>
Sat, 10 Aug 2019 07:46:16 +0000 (17:16 +0930)
"next" and "next_real_file" in lang_input_statement_type always point
to another lang_input_statement_type, so it makes sense for these to
not be the generic lang_statement_union_type.  This patch also updates
a number of variables in ldlang.c for the same reason, and modifies
lang_statement_append to reduce the need for casts.

* ldlang.h (lang_input_statement_type): Make next
and next_real_file a lang_input_statement_type pointer.
(lang_statement_append): Delete prototype.
(LANG_FOR_EACH_INPUT_STATEMENT): Update for lang_input_statement_type
change.
* ldmain.c (add_archive_element): Likewise.
* ldlang.c: Likewise throughout.
(lang_statement_append): Make static.  Make element and field
void pointers.  Remove casts in calls.
(lang_check): Use a lang_input_statement_type pointer for "file".
(find_rescan_insertion): Similarly for "iter" and return value.
(lang_process): Similarly for "insert", "iter" and "temp".
* emultempl/spuelf.em (embedded_spu_file): Likewise.
* emultempl/aix.em (gld${EMULATION_NAME}_before_allocation): Expand
lang_statment_append call.

ld/ChangeLog
ld/emultempl/aix.em
ld/emultempl/spuelf.em
ld/ldlang.c
ld/ldlang.h
ld/ldmain.c

index 6ff1a4727a41727ceb9877f4d81434144f48161f..d4cb36d5dd951535bd82d9fbf209a6ab2bd5de99 100644 (file)
@@ -1,3 +1,21 @@
+2019-08-10  Alan Modra  <amodra@gmail.com>
+
+       * ldlang.h (lang_input_statement_type): Make next
+       and next_real_file a lang_input_statement_type pointer.
+       (lang_statement_append): Delete prototype.
+       (LANG_FOR_EACH_INPUT_STATEMENT): Update for lang_input_statement_type
+       change.
+       * ldmain.c (add_archive_element): Likewise.
+       * ldlang.c: Likewise throughout.
+       (lang_statement_append): Make static.  Make element and field
+       void pointers.  Remove casts in calls.
+       (lang_check): Use a lang_input_statement_type pointer for "file".
+       (find_rescan_insertion): Similarly for "iter" and return value.
+       (lang_process): Similarly for "insert", "iter" and "temp".
+       * emultempl/spuelf.em (embedded_spu_file): Likewise.
+       * emultempl/aix.em (gld${EMULATION_NAME}_before_allocation): Expand
+       lang_statment_append call.
+
 2019-08-09  Mihailo Stojanovic  <mihailo.stojanovic@rt-rk.com>
 
        * emulparams/elf32bmip.sh: Add .MIPS.xhash section.
index bcf959d613879b281bab7111a933a41befb29e92..8151a9d5e93bf0db5d40fc22a43076f8c14508ec 100644 (file)
@@ -945,9 +945,8 @@ gld${EMULATION_NAME}_before_allocation (void)
       else
        {
          is->header.next = NULL;
-         lang_statement_append (&os->children,
-                                (lang_statement_union_type *) is,
-                                &is->header.next);
+         *os->children.tail = (lang_statement_union_type *) is;
+         os->children.tail = &is->header.next;
        }
     }
 
index f63097522fb898c9fdf36382dae25fae1d6e62e6..5ddf41c54912423db8dcddb04a499dc2e7276912 100644 (file)
@@ -512,9 +512,9 @@ embedded_spu_file (lang_input_statement_type *entry, const char *flags)
     return FALSE;
   close (fd);
 
-  for (search = (lang_input_statement_type *) input_file_chain.head;
+  for (search = &input_file_chain.head->input_statement;
        search != NULL;
-       search = (lang_input_statement_type *) search->next_real_file)
+       search = search->next_real_file)
     if (search->filename != NULL)
       {
        const char *infile = base_name (search->filename);
@@ -575,7 +575,7 @@ embedded_spu_file (lang_input_statement_type *entry, const char *flags)
   new_ent->header.next = entry->header.next;
   entry->header.next = new_ent;
   new_ent->input_statement.next_real_file = entry->next_real_file;
-  entry->next_real_file = new_ent;
+  entry->next_real_file = &new_ent->input_statement;
 
   /* Ensure bfd sections are excluded from the output.  */
   bfd_section_list_clear (entry->the_bfd);
index 8119cfc45bf95ea8949ecab19639ad75f13382a3..3ec534e1fc191be0710e7f7249e5c086b64d11c7 100644 (file)
@@ -1026,6 +1026,15 @@ lang_list_init (lang_statement_list_type *list)
   list->tail = &list->head;
 }
 
+static void
+lang_statement_append (lang_statement_list_type *list,
+                      void *element,
+                      void *field)
+{
+  *(list->tail) = element;
+  list->tail = field;
+}
+
 void
 push_stat_ptr (lang_statement_list_type *new_ptr)
 {
@@ -1142,9 +1151,7 @@ new_afile (const char *name,
       FAIL ();
     }
 
-  lang_statement_append (&input_file_chain,
-                        (lang_statement_union_type *) p,
-                        &p->next_real_file);
+  lang_statement_append (&input_file_chain, p, &p->next_real_file);
   return p;
 }
 
@@ -1234,9 +1241,7 @@ output_section_statement_newfunc (struct bfd_hash_entry *entry,
      address, so we store the pointer in a variable and cast that
      instead.  */
   nextp = &ret->s.output_section_statement.next;
-  lang_statement_append (&lang_os_list,
-                        &ret->s,
-                        (lang_statement_union_type **) nextp);
+  lang_statement_append (&lang_os_list, &ret->s, nextp);
   return &ret->root;
 }
 
@@ -2843,9 +2848,9 @@ lookup_name (const char *name)
 {
   lang_input_statement_type *search;
 
-  for (search = (lang_input_statement_type *) input_file_chain.head;
+  for (search = &input_file_chain.head->input_statement;
        search != NULL;
-       search = (lang_input_statement_type *) search->next_real_file)
+       search = search->next_real_file)
     {
       /* Use the local_sym_name as the name of the file that has
         already been loaded as filename might have been transformed
@@ -6522,18 +6527,20 @@ ignore_bfd_errors (const char *fmt ATTRIBUTE_UNUSED,
 static void
 lang_check (void)
 {
-  lang_statement_union_type *file;
+  lang_input_statement_type *file;
   bfd *input_bfd;
   const bfd_arch_info_type *compatible;
 
-  for (file = file_chain.head; file != NULL; file = file->input_statement.next)
+  for (file = &file_chain.head->input_statement;
+       file != NULL;
+       file = file->next)
     {
 #ifdef ENABLE_PLUGINS
       /* Don't check format of files claimed by plugin.  */
-      if (file->input_statement.flags.claimed)
+      if (file->flags.claimed)
        continue;
 #endif /* ENABLE_PLUGINS */
-      input_bfd = file->input_statement.the_bfd;
+      input_bfd = file->the_bfd;
       compatible
        = bfd_arch_get_compatible (input_bfd, link_info.output_bfd,
                                   command_line.accept_unknown_input_arch);
@@ -6868,7 +6875,7 @@ lang_for_each_input_file (void (*func) (lang_input_statement_type *))
 
   for (f = &input_file_chain.head->input_statement;
        f != NULL;
-       f = &f->next_real_file->input_statement)
+       f = f->next_real_file)
     func (f);
 }
 
@@ -6888,9 +6895,7 @@ lang_for_each_file (void (*func) (lang_input_statement_type *))
 void
 ldlang_add_file (lang_input_statement_type *entry)
 {
-  lang_statement_append (&file_chain,
-                        (lang_statement_union_type *) entry,
-                        &entry->next);
+  lang_statement_append (&file_chain, entry, &entry->next);
 
   /* The BFD linker needs to have a list of all input BFDs involved in
      a link.  */
@@ -7232,7 +7237,7 @@ find_replacements_insert_point (bfd_boolean *before)
   lastobject = &input_file_chain.head->input_statement;
   for (claim1 = &file_chain.head->input_statement;
        claim1 != NULL;
-       claim1 = &claim1->next->input_statement)
+       claim1 = claim1->next)
     {
       if (claim1->flags.claimed)
        {
@@ -7253,14 +7258,14 @@ find_replacements_insert_point (bfd_boolean *before)
 /* Find where to insert ADD, an archive element or shared library
    added during a rescan.  */
 
-static lang_statement_union_type **
+static lang_input_statement_type **
 find_rescan_insertion (lang_input_statement_type *add)
 {
   bfd *add_bfd = add->the_bfd;
   lang_input_statement_type *f;
   lang_input_statement_type *last_loaded = NULL;
   lang_input_statement_type *before = NULL;
-  lang_statement_union_type **iter = NULL;
+  lang_input_statement_type **iter = NULL;
 
   if (add_bfd->my_archive != NULL)
     add_bfd = add_bfd->my_archive;
@@ -7274,13 +7279,13 @@ find_rescan_insertion (lang_input_statement_type *add)
      then their input_statement->next points at it.  */
   for (f = &input_file_chain.head->input_statement;
        f != NULL;
-       f = &f->next_real_file->input_statement)
+       f = f->next_real_file)
     {
       if (f->the_bfd == add_bfd)
        {
          before = last_loaded;
          if (f->next != NULL)
-           return &f->next->input_statement.next;
+           return &f->next->next;
        }
       if (f->the_bfd != NULL && f->next != NULL)
        last_loaded = f;
@@ -7288,9 +7293,9 @@ find_rescan_insertion (lang_input_statement_type *add)
 
   for (iter = before ? &before->next : &file_chain.head->input_statement.next;
        *iter != NULL;
-       iter = &(*iter)->input_statement.next)
-    if (!(*iter)->input_statement.flags.claim_archive
-       && (*iter)->input_statement.the_bfd->my_archive == NULL)
+       iter = &(*iter)->next)
+    if (!(*iter)->flags.claim_archive
+       && (*iter)->the_bfd->my_archive == NULL)
       break;
 
   return iter;
@@ -7496,7 +7501,7 @@ lang_process (void)
          if (before)
            {
              prev = find_next_input_statement (prev);
-             if (*prev != plugin_insert->next_real_file)
+             if (*prev != (void *) plugin_insert->next_real_file)
                {
                  /* Huh?  We didn't find the expected input statement.  */
                  ASSERT (0);
@@ -7506,12 +7511,13 @@ lang_process (void)
          lang_list_insert_after (stat_ptr, &added, prev);
          /* Likewise for the file chains.  */
          lang_list_insert_after (&input_file_chain, &inputfiles,
-                                 &plugin_insert->next_real_file);
+                                 (void *) &plugin_insert->next_real_file);
          /* We must be careful when relinking file_chain; we may need to
             insert the new files at the head of the list if the insert
             point chosen is the dummy first input file.  */
          if (plugin_insert->filename)
-           lang_list_insert_after (&file_chain, &files, &plugin_insert->next);
+           lang_list_insert_after (&file_chain, &files,
+                                   (void *) &plugin_insert->next);
          else
            lang_list_insert_after (&file_chain, &files, &file_chain.head);
 
@@ -7522,8 +7528,8 @@ lang_process (void)
          lang_list_remove_tail (&file_chain, &files);
          while (files.head != NULL)
            {
-             lang_statement_union_type **insert;
-             lang_statement_union_type **iter, *temp;
+             lang_input_statement_type **insert;
+             lang_input_statement_type **iter, *temp;
              bfd *my_arch;
 
              insert = find_rescan_insertion (&files.head->input_statement);
@@ -7531,18 +7537,18 @@ lang_process (void)
              iter = &files.head->input_statement.next;
              my_arch = files.head->input_statement.the_bfd->my_archive;
              if (my_arch != NULL)
-               for (; *iter != NULL; iter = &(*iter)->input_statement.next)
-                 if ((*iter)->input_statement.the_bfd->my_archive != my_arch)
+               for (; *iter != NULL; iter = &(*iter)->next)
+                 if ((*iter)->the_bfd->my_archive != my_arch)
                    break;
              temp = *insert;
-             *insert = files.head;
-             files.head = *iter;
+             *insert = &files.head->input_statement;
+             files.head = (lang_statement_union_type *) *iter;
              *iter = temp;
              if (my_arch != NULL)
                {
                  lang_input_statement_type *parent = my_arch->usrdata;
                  if (parent != NULL)
-                   parent->next = (lang_statement_union_type *)
+                   parent->next = (lang_input_statement_type *)
                      ((char *) iter
                       - offsetof (lang_input_statement_type, next));
                }
@@ -7954,15 +7960,6 @@ lang_leave_output_section_statement (fill_type *fill, const char *memspec,
   pop_stat_ptr ();
 }
 
-void
-lang_statement_append (lang_statement_list_type *list,
-                      lang_statement_union_type *element,
-                      lang_statement_union_type **field)
-{
-  *(list->tail) = element;
-  list->tail = field;
-}
-
 /* Set the output format type.  -oformat overrides scripts.  */
 
 void
index 2298cba82dec6c6fbfa9b20b82c85d5512c001a2..6d5fe738f4fb608b508951f7d765d1000f4bc294 100644 (file)
@@ -309,10 +309,10 @@ typedef struct lang_input_statement_struct
   struct flag_info *section_flag_list;
 
   /* Next pointer for file_chain statement list.  */
-  union lang_statement_union *next;
+  struct lang_input_statement_struct *next;
 
   /* Next pointer for input_file_chain statement list.  */
-  union lang_statement_union *next_real_file;
+  struct lang_input_statement_struct *next_real_file;
 
   const char *target;
 
@@ -567,9 +567,6 @@ extern void lang_float
 extern void lang_leave_output_section_statement
   (fill_type *, const char *, lang_output_section_phdr_list *,
    const char *);
-extern void lang_statement_append
-  (lang_statement_list_type *, lang_statement_union_type *,
-   lang_statement_union_type **);
 extern void lang_for_each_input_file
   (void (*dothis) (lang_input_statement_type *));
 extern void lang_for_each_file
@@ -585,7 +582,7 @@ extern asection *section_for_dot
   lang_input_statement_type *statement;                                        \
   for (statement = &file_chain.head->input_statement;                  \
        statement != NULL;                                              \
-       statement = &statement->next->input_statement)
+       statement = statement->next)
 
 #define lang_output_section_find(NAME) \
   lang_output_section_statement_lookup (NAME, 0, FALSE)
index a7ca4f487db11cacaf2b755b43dd7ac0e580baf5..e24194ef87d8a51ba6ff7467df380be962a7c1b0 100644 (file)
@@ -818,7 +818,7 @@ add_archive_element (struct bfd_link_info *info,
 
   parent = abfd->my_archive->usrdata;
   if (parent != NULL && !parent->flags.reload)
-    parent->next = (lang_statement_union_type *) input;
+    parent->next = input;
 
   /* Save the original data for trace files/tries below, as plugins
      (if enabled) may possibly alter it to point to a replacement
This page took 0.034051 seconds and 4 git commands to generate.