Run --gc-sections tests only if supported.
[deliverable/binutils-gdb.git] / bfd / mach-o.c
index d8020dfa101cd501e501eca6a8c10dd282b03c9c..91f0306f5e64cf53438ce17041359d3e1f2561e8 100644 (file)
@@ -134,15 +134,20 @@ static const struct mach_o_section_name_xlat data_section_names_xlat[] =
 
 struct mach_o_segment_name_xlat
 {
+  /* Segment name.  */
   const char *segname;
+
+  /* List of known sections for the segment.  */
   const struct mach_o_section_name_xlat *sections;
 };
 
+/* List of known segment names.  */
+
 static const struct mach_o_segment_name_xlat segsec_names_xlat[] =
   {
-    { "__DWARF", dwarf_section_names_xlat },
     { "__TEXT", text_section_names_xlat },
     { "__DATA", data_section_names_xlat },
+    { "__DWARF", dwarf_section_names_xlat },
     { NULL, NULL }
   };
 
@@ -178,6 +183,9 @@ bfd_mach_o_normalize_section_name (const char *segname, const char *sectname,
     }
 }
 
+/* Convert Mach-O section name to BFD.  Try to use standard names, otherwise
+   forge a new name.  SEGNAME and SECTNAME are 16 bytes strings.  */
+
 static void
 bfd_mach_o_convert_section_name_to_bfd
   (bfd *abfd, const char *segname, const char *sectname,
@@ -194,7 +202,7 @@ bfd_mach_o_convert_section_name_to_bfd
   if (*name)
     return;
 
-  len = strlen (segname) + 1 + strlen (sectname) + 1;
+  len = 16 + 1 + 16 + 1;
 
   /* Put "LC_SEGMENT." prefix if the segment name is weird (ie doesn't start
      with an underscore.  */
@@ -209,7 +217,7 @@ bfd_mach_o_convert_section_name_to_bfd
   res = bfd_alloc (abfd, len);
   if (res == NULL)
     return;
-  snprintf (res, len, "%s%s.%s", pfx, segname, sectname);
+  snprintf (res, len, "%s%.16s.%.16s", pfx, segname, sectname);
   *name = res;
   *flags = SEC_NO_FLAGS;
 }
@@ -952,7 +960,7 @@ bfd_mach_o_write_section_32 (bfd *abfd, bfd_mach_o_section *section)
   struct mach_o_section_32_external raw;
 
   memcpy (raw.sectname, section->sectname, 16);
-  memcpy (raw.segname + 16, section->segname, 16);
+  memcpy (raw.segname, section->segname, 16);
   bfd_h_put_32 (abfd, section->addr, raw.addr);
   bfd_h_put_32 (abfd, section->size, raw.size);
   bfd_h_put_32 (abfd, section->offset, raw.offset);
@@ -1401,6 +1409,8 @@ bfd_mach_o_build_commands (bfd *abfd)
     | BFD_MACH_O_PROT_EXECUTE;
   seg->initprot = seg->maxprot;
   seg->flags = 0;
+  seg->sect_head = NULL;
+  seg->sect_tail = NULL;
 
   /* Create Mach-O sections.  */
   target_index = 0;
@@ -1675,7 +1685,7 @@ bfd_mach_o_read_section_32 (bfd *abfd,
           != BFD_MACH_O_SECTION_SIZE))
     return NULL;
 
-  sec = bfd_mach_o_make_bfd_section (abfd, raw.sectname, raw.segname);
+  sec = bfd_mach_o_make_bfd_section (abfd, raw.segname, raw.sectname);
   if (sec == NULL)
     return NULL;
 
@@ -1714,7 +1724,7 @@ bfd_mach_o_read_section_64 (bfd *abfd,
           != BFD_MACH_O_SECTION_64_SIZE))
     return NULL;
 
-  sec = bfd_mach_o_make_bfd_section (abfd, raw.sectname, raw.segname);
+  sec = bfd_mach_o_make_bfd_section (abfd, raw.segname, raw.sectname);
   if (sec == NULL)
     return NULL;
 
@@ -2588,6 +2598,8 @@ bfd_mach_o_read_segment (bfd *abfd,
       seg->nsects = bfd_h_get_32 (abfd, raw.nsects);
       seg->flags = bfd_h_get_32 (abfd, raw.flags);
     }
+  seg->sect_head = NULL;
+  seg->sect_tail = NULL;
 
   for (i = 0; i < seg->nsects; i++)
     {
This page took 0.026593 seconds and 4 git commands to generate.