Maintain order of LTO sections
[gcc.git] / gcc / lto / lto-object.c
index 3be58dec3809d6cd0bc36d545e5d9b9f36467395..daf3bd002a32a6781b2e9a3a219bf71d84d0cd58 100644 (file)
@@ -204,6 +204,8 @@ struct lto_obj_add_section_data
   htab_t section_hash_table;
   /* The offset of this file.  */
   off_t base_offset;
+  /* List in linker order */
+  struct lto_section_list *list;
 };
 
 /* This is called for each section in the file.  */
@@ -218,6 +220,7 @@ lto_obj_add_section (void *data, const char *name, off_t offset,
   char *new_name;
   struct lto_section_slot s_slot;
   void **slot;
+  struct lto_section_list *list = loasd->list;
 
   if (strncmp (name, LTO_SECTION_NAME_PREFIX,
               strlen (LTO_SECTION_NAME_PREFIX)) != 0)
@@ -228,12 +231,21 @@ lto_obj_add_section (void *data, const char *name, off_t offset,
   slot = htab_find_slot (section_hash_table, &s_slot, INSERT);
   if (*slot == NULL)
     {
-      struct lto_section_slot *new_slot = XNEW (struct lto_section_slot);
+      struct lto_section_slot *new_slot = XCNEW (struct lto_section_slot);
 
       new_slot->name = new_name;
       new_slot->start = loasd->base_offset + offset;
       new_slot->len = length;
       *slot = new_slot;
+
+      if (list != NULL)
+        {
+          if (!list->first)
+            list->first = new_slot;
+          if (list->last)
+            list->last->next = new_slot;
+          list->last = new_slot;
+        }
     }
   else
     {
@@ -248,7 +260,7 @@ lto_obj_add_section (void *data, const char *name, off_t offset,
    the start and size of each section in the .o file.  */
 
 htab_t
-lto_obj_build_section_table (lto_file *lto_file)
+lto_obj_build_section_table (lto_file *lto_file, struct lto_section_list *list)
 {
   struct lto_simple_object *lo = (struct lto_simple_object *) lto_file;
   htab_t section_hash_table;
@@ -261,6 +273,7 @@ lto_obj_build_section_table (lto_file *lto_file)
   gcc_assert (lo->sobj_r != NULL && lo->sobj_w == NULL);
   loasd.section_hash_table = section_hash_table;
   loasd.base_offset = lo->base.offset;
+  loasd.list = list;
   errmsg = simple_object_find_sections (lo->sobj_r, lto_obj_add_section,
                                        &loasd, &err);
   if (errmsg != NULL)