daily update
[deliverable/binutils-gdb.git] / bfd / mach-o.c
index 7f4b968c9cfcd16ffefd53a9d4f3b1b5e7f1b662..da7f87de9e39fc2786a2cfbd6aa2e8fb38a8d8c4 100644 (file)
@@ -1,7 +1,5 @@
 /* Mach-O support for BFD.
-   Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-   2009, 2010, 2011, 2012
-   Free Software Foundation, Inc.
+   Copyright (C) 1999-2014 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -197,6 +195,9 @@ static const mach_o_section_name_xlat dwarf_section_names_xlat[] =
     {  ".debug_macro",                 "__debug_macro",
        SEC_DEBUGGING,                  BFD_MACH_O_S_REGULAR,
        BFD_MACH_O_S_ATTR_DEBUG,        0},
+    {  ".debug_gdb_scripts",           "__debug_gdb_scri",
+       SEC_DEBUGGING,                  BFD_MACH_O_S_REGULAR,
+       BFD_MACH_O_S_ATTR_DEBUG,        0},
     { NULL, NULL, 0, 0, 0, 0}
   };
 
@@ -2693,7 +2694,7 @@ bfd_mach_o_new_section_hook (bfd *abfd, asection *sec)
          s->flags = xlat->macho_sectype | xlat->macho_secattr;
          s->align = xlat->sectalign > bfdalign ? xlat->sectalign
                                                : bfdalign;
-         bfd_set_section_alignment (abfd, sec, s->align);
+         (void) bfd_set_section_alignment (abfd, sec, s->align);
          bfd_flags = bfd_get_section_flags (abfd, sec);
          if (bfd_flags == SEC_NO_FLAGS)
            bfd_set_section_flags (abfd, sec, xlat->bfd_flags);
@@ -3979,9 +3980,22 @@ bfd_mach_o_scan_start_address (bfd *abfd)
         cmd = &mdata->commands[i].command.thread;
         break;
       }
+    else if (mdata->commands[i].type == BFD_MACH_O_LC_MAIN
+            && mdata->nsects > 1)
+      {
+       bfd_mach_o_main_command *main_cmd = &mdata->commands[i].command.main;
+       bfd_mach_o_section *text_sect = mdata->sections[0];
+       if (text_sect)
+         {
+           abfd->start_address = main_cmd->entryoff
+             + (text_sect->addr - text_sect->offset);
+           return TRUE;
+         }
+      }
 
+  /* An object file has no start address, so do not fail if not found.  */
   if (cmd == NULL)
-    return FALSE;
+    return TRUE;
 
   /* FIXME: create a subtarget hook ?  */
   for (i = 0; i < cmd->nflavours; i++)
@@ -4121,10 +4135,11 @@ bfd_mach_o_scan (bfd *abfd,
        }
     }
 
-  if (bfd_mach_o_scan_start_address (abfd) < 0)
+  /* Sections should be flatten before scanning start address.  */
+  bfd_mach_o_flatten_sections (abfd);
+  if (!bfd_mach_o_scan_start_address (abfd))
     return FALSE;
 
-  bfd_mach_o_flatten_sections (abfd);
   return TRUE;
 }
 
@@ -4133,7 +4148,7 @@ bfd_mach_o_mkobject_init (bfd *abfd)
 {
   bfd_mach_o_data_struct *mdata = NULL;
 
-  mdata = bfd_alloc (abfd, sizeof (bfd_mach_o_data_struct));
+  mdata = bfd_zalloc (abfd, sizeof (bfd_mach_o_data_struct));
   if (mdata == NULL)
     return FALSE;
   abfd->tdata.mach_o_data = mdata;
@@ -4338,13 +4353,13 @@ bfd_mach_o_fat_member_init (bfd *abfd,
   if (ap)
     {
       /* Use the architecture name if known.  */
-      abfd->filename = ap->printable_name;
+      abfd->filename = xstrdup (ap->printable_name);
     }
   else
     {
       /* Forge a uniq id.  */
       const size_t namelen = 2 + 8 + 1 + 2 + 8 + 1;
-      char *name = bfd_alloc (abfd, namelen);
+      char *name = xmalloc (namelen);
       snprintf (name, namelen, "0x%lx-0x%lx",
                 entry->cputype, entry->cpusubtype);
       abfd->filename = name;
This page took 0.029398 seconds and 4 git commands to generate.