2011-12-07 Tristan Gingold <gingold@adacore.com>
[deliverable/binutils-gdb.git] / bfd / mach-o.c
index 832bc98a142437ecb38266bb7cbb804e8e14f53b..04c971e47f43c4c95c43bc0f3abb2602ef58a698 100644 (file)
@@ -183,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,
@@ -199,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.  */
@@ -214,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;
 }
@@ -544,7 +547,10 @@ bfd_mach_o_print_symbol (bfd *abfd,
        switch (asym->n_type & BFD_MACH_O_N_TYPE)
          {
          case BFD_MACH_O_N_UNDF:
-           name = "UND";
+            if (symbol->value == 0)
+              name = "UND";
+            else
+              name = "COM";
            break;
          case BFD_MACH_O_N_ABS:
            name = "ABS";
@@ -568,7 +574,7 @@ bfd_mach_o_print_symbol (bfd *abfd,
                asym->n_type, name, asym->n_sect, asym->n_desc);
       if ((asym->n_type & BFD_MACH_O_N_STAB) == 0
          && (asym->n_type & BFD_MACH_O_N_TYPE) == BFD_MACH_O_N_SECT)
-       fprintf (file, " %-5s", symbol->section->name);
+       fprintf (file, " [%s]", symbol->section->name);
       fprintf (file, " %s", symbol->name);
     }
 }
@@ -957,7 +963,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);
@@ -1288,6 +1294,7 @@ bfd_mach_o_write_contents (bfd *abfd)
        case BFD_MACH_O_LC_LOAD_WEAK_DYLIB:
        case BFD_MACH_O_LC_ID_DYLIB:
        case BFD_MACH_O_LC_REEXPORT_DYLIB:
+        case BFD_MACH_O_LC_LOAD_UPWARD_DYLIB:
        case BFD_MACH_O_LC_LOAD_DYLINKER:
        case BFD_MACH_O_LC_ID_DYLINKER:
        case BFD_MACH_O_LC_PREBOUND_DYLIB:
@@ -1406,6 +1413,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;
@@ -1892,10 +1901,12 @@ bfd_mach_o_read_symtab_symbol (bfd *abfd,
            }
          break;
        case BFD_MACH_O_N_INDR:
-         (*_bfd_error_handler) (_("bfd_mach_o_read_symtab_symbol: "
-                                  "symbol \"%s\" is unsupported 'indirect' reference: setting to undefined"),
-                                s->symbol.name);
-         s->symbol.section = bfd_und_section_ptr;
+         /* FIXME: we don't follow the BFD convention as this indirect symbol
+            won't be followed by the referenced one.  This looks harmless
+            unless we start using the linker.  */
+         s->symbol.flags |= BSF_INDIRECT;
+         s->symbol.section = bfd_ind_section_ptr;
+         s->symbol.value = 0;
          break;
        default:
          (*_bfd_error_handler) (_("bfd_mach_o_read_symtab_symbol: "
@@ -2092,6 +2103,7 @@ bfd_mach_o_read_dylib (bfd *abfd, bfd_mach_o_load_command *command)
     case BFD_MACH_O_LC_LOAD_WEAK_DYLIB:
     case BFD_MACH_O_LC_ID_DYLIB:
     case BFD_MACH_O_LC_REEXPORT_DYLIB:
+    case BFD_MACH_O_LC_LOAD_UPWARD_DYLIB:
       break;
     default:
       BFD_FAIL ();
@@ -2593,6 +2605,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++)
     {
@@ -2674,6 +2688,7 @@ bfd_mach_o_read_command (bfd *abfd, bfd_mach_o_load_command *command)
     case BFD_MACH_O_LC_ID_DYLIB:
     case BFD_MACH_O_LC_LOAD_WEAK_DYLIB:
     case BFD_MACH_O_LC_REEXPORT_DYLIB:
+    case BFD_MACH_O_LC_LOAD_UPWARD_DYLIB:
       if (bfd_mach_o_read_dylib (abfd, command) != 0)
        return -1;
       break;
@@ -2724,8 +2739,8 @@ bfd_mach_o_read_command (bfd *abfd, bfd_mach_o_load_command *command)
        return -1;
       break;
     default:
-      (*_bfd_error_handler) (_("unable to read unknown load command 0x%lx"),
-                            (unsigned long) command->type);
+      (*_bfd_error_handler)(_("%B: unable to read unknown load command 0x%lx"),
+         abfd, (unsigned long) command->type);
       break;
     }
 
@@ -3199,22 +3214,9 @@ bfd_mach_o_openr_next_archived_file (bfd *archive, bfd *prev)
 
   bfd_mach_o_convert_architecture (entry->cputype, entry->cpusubtype,
                                   &arch_type, &arch_subtype);
-  /* Create the member filename.
-     Use FILENAME:ARCH_NAME.  */
-  {
-    char *s = NULL;
-    const char *arch_name;
-    size_t arch_file_len = strlen (bfd_get_filename (archive));
 
-    arch_name = bfd_printable_arch_mach (arch_type, arch_subtype);
-    s = bfd_malloc (arch_file_len + 1 + strlen (arch_name) + 1);
-    if (s == NULL)
-      return NULL;
-    memcpy (s, bfd_get_filename (archive), arch_file_len);
-    s[arch_file_len] = ':';
-    strcpy (s + arch_file_len + 1, arch_name);
-    nbfd->filename = s;
-  }
+  /* Create the member filename. Use ARCH_NAME.  */
+  nbfd->filename = bfd_printable_arch_mach (arch_type, arch_subtype);
   nbfd->iostream = NULL;
   bfd_set_arch_mach (nbfd, arch_type, arch_subtype);
 
@@ -3267,7 +3269,7 @@ bfd_mach_o_fat_extract (bfd *abfd,
 
       res->origin = e->offset;
 
-      res->filename = strdup (abfd->filename);
+      res->filename = bfd_printable_arch_mach (cpu_type, cpu_subtype);
       res->iostream = NULL;
 
       if (bfd_check_format (res, format))
@@ -3954,6 +3956,7 @@ bfd_mach_o_bfd_print_private_bfd_data (bfd *abfd, void * ptr)
        case BFD_MACH_O_LC_LOAD_DYLIB:
        case BFD_MACH_O_LC_LOAD_WEAK_DYLIB:
        case BFD_MACH_O_LC_REEXPORT_DYLIB:
+        case BFD_MACH_O_LC_LOAD_UPWARD_DYLIB:
        case BFD_MACH_O_LC_ID_DYLIB:
          {
            bfd_mach_o_dylib_command *dylib = &cmd->command.dylib;
This page took 0.025456 seconds and 4 git commands to generate.