* section.c (bfd_section_list_remove): Don't clear s->next.
authorAlan Modra <amodra@gmail.com>
Tue, 3 May 2005 17:05:51 +0000 (17:05 +0000)
committerAlan Modra <amodra@gmail.com>
Tue, 3 May 2005 17:05:51 +0000 (17:05 +0000)
(bfd_section_list_append): Always init s->prev.
(bfd_section_list_prepend): Define.
(bfd_section_list_insert_after): Minor optimization.
(bfd_section_removed_from_list): Rewrite.
* elf.c (assign_section_numbers): Simplify list traversal now that
bfd_section_list_remove doesn't destroy removed section next ptr.
* sunos.c (sunos_add_dynamic_symbols): Likewise.
* elfxx-ia64.c (elfNN_ia64_object_p): Use bfd_section_list_prepend.
* xcofflink.c (_bfd_xcoff_bfd_final_link): Simplify list traversal.
* bfd-in2.h: Regenerate.

bfd/ChangeLog
bfd/bfd-in2.h
bfd/elf.c
bfd/elfxx-ia64.c
bfd/section.c
bfd/sunos.c
bfd/xcofflink.c

index e99fd75..8f403c2 100644 (file)
@@ -1,3 +1,17 @@
+2005-05-04  Alan Modra  <amodra@bigpond.net.au>
+
+       * section.c (bfd_section_list_remove): Don't clear s->next.
+       (bfd_section_list_append): Always init s->prev.
+       (bfd_section_list_prepend): Define.
+       (bfd_section_list_insert_after): Minor optimization.
+       (bfd_section_removed_from_list): Rewrite.
+       * elf.c (assign_section_numbers): Simplify list traversal now that
+       bfd_section_list_remove doesn't destroy removed section next ptr.
+       * sunos.c (sunos_add_dynamic_symbols): Likewise.
+       * elfxx-ia64.c (elfNN_ia64_object_p): Use bfd_section_list_prepend.
+       * xcofflink.c (_bfd_xcoff_bfd_final_link): Simplify list traversal.
+       * bfd-in2.h: Regenerate.
+
 2005-05-02  H.J. Lu  <hongjiu.lu@intel.com>
 
        * bfd.c (bfd): Remove section_tail and add section_last.
index 545e442..944a33a 100644 (file)
@@ -1451,10 +1451,7 @@ extern const struct bfd_symbol * const bfd_ind_symbol;
       else                                             \
         (ABFD)->sections = _next;                      \
       if (_next)                                       \
-        {                                              \
-          _next->prev = _prev;                         \
-          _s->next = NULL;                             \
-        }                                              \
+        _next->prev = _prev;                           \
       else                                             \
         (ABFD)->section_last = _prev;                  \
     }                                                  \
@@ -1471,10 +1468,32 @@ extern const struct bfd_symbol * const bfd_ind_symbol;
           _abfd->section_last->next = _s;              \
         }                                              \
       else                                             \
-        _abfd->sections = _s;                          \
+        {                                              \
+          _s->prev = NULL;                             \
+          _abfd->sections = _s;                        \
+        }                                              \
       _abfd->section_last = _s;                        \
     }                                                  \
   while (0)
+#define bfd_section_list_prepend(ABFD, S) \
+  do                                                   \
+    {                                                  \
+      asection *_s = S;                                \
+      bfd *_abfd = ABFD;                               \
+      _s->prev = NULL;                                 \
+      if (_abfd->sections)                             \
+        {                                              \
+          _s->next = _abfd->sections;                  \
+          _abfd->sections->prev = _s;                  \
+        }                                              \
+      else                                             \
+        {                                              \
+          _s->next = NULL;                             \
+          _abfd->section_last = _s;                    \
+        }                                              \
+      _abfd->sections = _s;                            \
+    }                                                  \
+  while (0)
 #define bfd_section_list_insert_after(ABFD, A, S) \
   do                                                   \
     {                                                  \
@@ -1485,7 +1504,7 @@ extern const struct bfd_symbol * const bfd_ind_symbol;
       _s->prev = _a;                                   \
       _a->next = _s;                                   \
       if (_next)                                       \
-        _s->next->prev = _s;                           \
+        _next->prev = _s;                              \
       else                                             \
         (ABFD)->section_last = _s;                     \
     }                                                  \
@@ -1506,7 +1525,7 @@ extern const struct bfd_symbol * const bfd_ind_symbol;
     }                                                  \
   while (0)
 #define bfd_section_removed_from_list(ABFD, S) \
-  ((S)->next == NULL && (S) != (ABFD)->section_last)
+  ((S)->next == NULL ? (ABFD)->section_last != (S) : (S)->next->prev != (S))
 
 void bfd_section_list_clear (bfd *);
 
index fac05e0..a469932 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -2762,14 +2762,11 @@ assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info)
   /* SHT_GROUP sections are in relocatable files only.  */
   if (link_info == NULL || link_info->relocatable)
     {
-      asection *n;
-
       /* Put SHT_GROUP sections first.  */
-      for (sec = abfd->sections; sec; sec = n)
+      for (sec = abfd->sections; sec != NULL; sec = sec->next)
        {
          d = elf_section_data (sec);
 
-         n = sec->next;
          if (d->this_hdr.sh_type == SHT_GROUP)
            { 
              if (sec->flags & SEC_LINKER_CREATED)
index a483e2d..5c3521c 100644 (file)
@@ -4934,7 +4934,7 @@ elfNN_ia64_object_p (bfd *abfd)
 
          /* Move the fake group section to the beginning.  */
          bfd_section_list_remove (abfd, group);
-         bfd_section_list_insert_before (abfd, abfd->sections, group);
+         bfd_section_list_prepend (abfd, group);
 
          elf_next_in_group (group) = sec;
 
index 45ede06..3f008ea 100644 (file)
@@ -552,10 +552,7 @@ CODE_FRAGMENT
 .      else                                            \
 .        (ABFD)->sections = _next;                     \
 .      if (_next)                                      \
-.        {                                             \
-.          _next->prev = _prev;                                \
-.          _s->next = NULL;                            \
-.        }                                             \
+.        _next->prev = _prev;                          \
 .      else                                            \
 .        (ABFD)->section_last = _prev;                 \
 .    }                                                 \
@@ -572,10 +569,32 @@ CODE_FRAGMENT
 .          _abfd->section_last->next = _s;             \
 .        }                                             \
 .      else                                            \
-.        _abfd->sections = _s;                         \
+.        {                                             \
+.          _s->prev = NULL;                            \
+.          _abfd->sections = _s;                       \
+.        }                                             \
 .      _abfd->section_last = _s;                       \
 .    }                                                 \
 .  while (0)
+.#define bfd_section_list_prepend(ABFD, S) \
+.  do                                                  \
+.    {                                                 \
+.      asection *_s = S;                               \
+.      bfd *_abfd = ABFD;                              \
+.      _s->prev = NULL;                                        \
+.      if (_abfd->sections)                            \
+.        {                                             \
+.          _s->next = _abfd->sections;                 \
+.          _abfd->sections->prev = _s;                 \
+.        }                                             \
+.      else                                            \
+.        {                                             \
+.          _s->next = NULL;                            \
+.          _abfd->section_last = _s;                   \
+.        }                                             \
+.      _abfd->sections = _s;                           \
+.    }                                                 \
+.  while (0)
 .#define bfd_section_list_insert_after(ABFD, A, S) \
 .  do                                                  \
 .    {                                                 \
@@ -586,7 +605,7 @@ CODE_FRAGMENT
 .      _s->prev = _a;                                  \
 .      _a->next = _s;                                  \
 .      if (_next)                                      \
-.        _s->next->prev = _s;                          \
+.        _next->prev = _s;                             \
 .      else                                            \
 .        (ABFD)->section_last = _s;                    \
 .    }                                                 \
@@ -607,7 +626,7 @@ CODE_FRAGMENT
 .    }                                                 \
 .  while (0)
 .#define bfd_section_removed_from_list(ABFD, S) \
-.  ((S)->next == NULL && (S) != (ABFD)->section_last)
+.  ((S)->next == NULL ? (ABFD)->section_last != (S) : (S)->next->prev != (S))
 .
 */
 
index 1b17d3e..5995f16 100644 (file)
@@ -859,11 +859,10 @@ sunos_add_dynamic_symbols (bfd *abfd,
     abfd->sections = NULL;
   else
     {
-      asection *s, *n;
+      asection *s;
 
-      for (s = abfd->sections; s != NULL; s = n)
+      for (s = abfd->sections; s != NULL; s = s->next)
        {
-         n = s->next;
          if ((s->flags & SEC_LINKER_CREATED) == 0)
            bfd_section_list_remove (abfd, s);
        }
index 127ac3d..c72507e 100644 (file)
@@ -5436,19 +5436,18 @@ _bfd_xcoff_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
        {
          bfd_boolean saw_contents;
          int indx;
-         asection **op;
          file_ptr sofar;
 
          /* Insert .pad sections before every section which has
             contents and is loaded, if it is preceded by some other
             section which has contents and is loaded.  */
          saw_contents = TRUE;
-         for (op = &abfd->sections; *op != NULL; op = &(*op)->next)
+         for (o = abfd->sections; o != NULL; o = o->next)
            {
-             if (strcmp ((*op)->name, ".pad") == 0)
+             if (strcmp (o->name, ".pad") == 0)
                saw_contents = FALSE;
-             else if (((*op)->flags & SEC_HAS_CONTENTS) != 0
-                      && ((*op)->flags & SEC_LOAD) != 0)
+             else if ((o->flags & SEC_HAS_CONTENTS) != 0
+                      && (o->flags & SEC_LOAD) != 0)
                {
                  if (! saw_contents)
                    saw_contents = TRUE;
@@ -5465,9 +5464,7 @@ _bfd_xcoff_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
                      n->alignment_power = 0;
 
                      bfd_section_list_remove (abfd, n);
-                     bfd_section_list_insert_before (abfd, *op, n);
-
-                     op = &n->next;
+                     bfd_section_list_insert_before (abfd, o, n);
                      saw_contents = FALSE;
                    }
                }