This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[committed/darwin]: Hard-code section flags for known sections


Hi,

section flags are now only guessed for not known sections, as the guess was
very approximative.  Know sections flags are now hard-coded.

This improve the output of nm.

Tristan.

bfd/
2009-12-15  Tristan Gingold  <gingold@adacore.com>

        * mach-o.c (struct mach_o_section_name_xlat): Add flags field.
        (dwarf_section_names_xlat): Add section flags.
        (text_section_names_xlat): Ditto.
        (data_section_names_xlat): Ditto.
        (bfd_mach_o_convert_section_name_to_bfd): Now return name and section
        flags by reference.
        (bfd_mach_o_make_bfd_section): Use section flags when know, otherwise
        try to guess.


diff -c -r1.48 mach-o.c
*** mach-o.c	11 Dec 2009 13:42:04 -0000	1.48
--- mach-o.c	15 Dec 2009 09:24:55 -0000
***************
*** 90,127 ****
  {
    const char *bfd_name;
    const char *mach_o_name;
  };
  
  static const struct mach_o_section_name_xlat dwarf_section_names_xlat[] =
    {
!     { ".debug_frame", "__debug_frame" },
!     { ".debug_info", "__debug_info" },
!     { ".debug_abbrev", "__debug_abbrev" },
!     { ".debug_aranges", "__debug_aranges" },
!     { ".debug_macinfo", "__debug_macinfo" },
!     { ".debug_line", "__debug_line" },
!     { ".debug_loc", "__debug_loc" },
!     { ".debug_pubnames", "__debug_pubnames" },
!     { ".debug_pubtypes", "__debug_pubtypes" },
!     { ".debug_str", "__debug_str" },
!     { ".debug_ranges", "__debug_ranges" },
!     { NULL, NULL}
    };
  
  static const struct mach_o_section_name_xlat text_section_names_xlat[] =
    {
!     { ".text", "__text" },
!     { ".const", "__const" },
!     { ".cstring", "__cstring" },
!     { ".eh_frame", "__eh_frame" },
!     { NULL, NULL}
    };
  
  static const struct mach_o_section_name_xlat data_section_names_xlat[] =
    {
!     { ".data", "__data" },
!     { ".bss", "__bss" },
!     { NULL, NULL}
    };
  
  struct mach_o_segment_name_xlat
--- 90,132 ----
  {
    const char *bfd_name;
    const char *mach_o_name;
+   flagword flags;
  };
  
  static const struct mach_o_section_name_xlat dwarf_section_names_xlat[] =
    {
!     { ".debug_frame",    "__debug_frame",    SEC_DEBUGGING },
!     { ".debug_info",     "__debug_info",     SEC_DEBUGGING },
!     { ".debug_abbrev",   "__debug_abbrev",   SEC_DEBUGGING },
!     { ".debug_aranges",  "__debug_aranges",  SEC_DEBUGGING },
!     { ".debug_macinfo",  "__debug_macinfo",  SEC_DEBUGGING },
!     { ".debug_line",     "__debug_line",     SEC_DEBUGGING },
!     { ".debug_loc",      "__debug_loc",      SEC_DEBUGGING },
!     { ".debug_pubnames", "__debug_pubnames", SEC_DEBUGGING },
!     { ".debug_pubtypes", "__debug_pubtypes", SEC_DEBUGGING },
!     { ".debug_str",      "__debug_str",      SEC_DEBUGGING },
!     { ".debug_ranges",   "__debug_ranges",   SEC_DEBUGGING },
!     { NULL, NULL, 0}
    };
  
  static const struct mach_o_section_name_xlat text_section_names_xlat[] =
    {
!     { ".text",     "__text",      SEC_CODE | SEC_LOAD },
!     { ".const",    "__const",     SEC_READONLY | SEC_DATA | SEC_LOAD },
!     { ".cstring",  "__cstring",   SEC_READONLY | SEC_DATA | SEC_LOAD },
!     { ".eh_frame", "__eh_frame",  SEC_READONLY | SEC_LOAD },
!     { NULL, NULL, 0}
    };
  
  static const struct mach_o_section_name_xlat data_section_names_xlat[] =
    {
!     { ".data",                "__data",          SEC_DATA | SEC_LOAD },
!     { ".const_data",          "__const",         SEC_DATA | SEC_LOAD },
!     { ".dyld",                "__dyld",          SEC_DATA | SEC_LOAD },
!     { ".lazy_symbol_ptr",     "__la_symbol_ptr", SEC_DATA | SEC_LOAD },
!     { ".non_lazy_symbol_ptr", "__nl_symbol_ptr", SEC_DATA | SEC_LOAD },
!     { ".bss",                 "__bss",           SEC_NO_FLAGS },
!     { NULL, NULL, 0}
    };
  
  struct mach_o_segment_name_xlat
***************
*** 141,154 ****
  
  /* Mach-O to bfd names.  */
  
! static char *
! bfd_mach_o_convert_section_name_to_bfd (bfd *abfd, bfd_mach_o_section *section)
  {
    const struct mach_o_segment_name_xlat *seg;
    char *res;
    unsigned int len;
    const char *pfx = "";
  
    for (seg = segsec_names_xlat; seg->segname; seg++)
      {
        if (strcmp (seg->segname, section->segname) == 0)
--- 146,163 ----
  
  /* Mach-O to bfd names.  */
  
! static void
! bfd_mach_o_convert_section_name_to_bfd (bfd *abfd, bfd_mach_o_section *section,
!                                         char **name, flagword *flags)
  {
    const struct mach_o_segment_name_xlat *seg;
    char *res;
    unsigned int len;
    const char *pfx = "";
  
+   *name = NULL;
+   *flags = SEC_NO_FLAGS;
+ 
    for (seg = segsec_names_xlat; seg->segname; seg++)
      {
        if (strcmp (seg->segname, section->segname) == 0)
***************
*** 163,171 ****
                    res = bfd_alloc (abfd, len + 1);
  
                    if (res == NULL)
!                     return NULL;
                    strcpy (res, sec->bfd_name);
!                   return res;
                  }
              }
          }
--- 172,182 ----
                    res = bfd_alloc (abfd, len + 1);
  
                    if (res == NULL)
!                     return;
                    strcpy (res, sec->bfd_name);
!                   *name = res;
!                   *flags = sec->flags;
!                   return;
                  }
              }
          }
***************
*** 186,194 ****
  
    res = bfd_alloc (abfd, len);
    if (res == NULL)
!     return NULL;
    snprintf (res, len, "%s%s.%s", pfx, section->segname, section->sectname);
!   return res;
  }
  
  /* Convert a bfd section name to a Mach-O segment + section name.  */
--- 197,205 ----
  
    res = bfd_alloc (abfd, len);
    if (res == NULL)
!     return;
    snprintf (res, len, "%s%s.%s", pfx, section->segname, section->sectname);
!   *name = res;
  }
  
  /* Convert a bfd section name to a Mach-O segment + section name.  */
***************
*** 1474,1505 ****
    char *sname;
    flagword flags;
  
!   sname = bfd_mach_o_convert_section_name_to_bfd (abfd, section);
    if (sname == NULL)
      return NULL;
  
!   if ((section->flags & BFD_MACH_O_S_ATTR_DEBUG)
!       || !strcmp (section->segname, "__DWARF"))
      {
!       /* Force flags for dwarf sections.  This looks weird but dsym files
!          have no flags for them and this is important for gdb.  */
!       flags = SEC_HAS_CONTENTS | SEC_DEBUGGING;
      }
    else
      {
!       flags = SEC_ALLOC;
!       if ((section->flags & BFD_MACH_O_SECTION_TYPE_MASK)
! 	  != BFD_MACH_O_S_ZEROFILL)
! 	{
! 	  flags |= SEC_HAS_CONTENTS | SEC_LOAD;
! 	  if (prot & BFD_MACH_O_PROT_EXECUTE)
! 	    flags |= SEC_CODE;
! 	  if (prot & BFD_MACH_O_PROT_WRITE)
! 	    flags |= SEC_DATA;
! 	  else if (prot & BFD_MACH_O_PROT_READ)
! 	    flags |= SEC_READONLY;
! 	}
      }
    if (section->nreloc != 0)
      flags |= SEC_RELOC;
  
--- 1485,1523 ----
    char *sname;
    flagword flags;
  
!   bfd_mach_o_convert_section_name_to_bfd (abfd, section, &sname, &flags);
    if (sname == NULL)
      return NULL;
  
!   if (flags == SEC_NO_FLAGS)
      {
!       /* Try to guess flags.  */
!       if (section->flags & BFD_MACH_O_S_ATTR_DEBUG)
!         flags = SEC_DEBUGGING;
!       else
!         {
!           flags = SEC_ALLOC;
!           if ((section->flags & BFD_MACH_O_SECTION_TYPE_MASK)
!               != BFD_MACH_O_S_ZEROFILL)
!             {
!               flags |= SEC_LOAD;
!               if (prot & BFD_MACH_O_PROT_EXECUTE)
!                 flags |= SEC_CODE;
!               if (prot & BFD_MACH_O_PROT_WRITE)
!                 flags |= SEC_DATA;
!               else if (prot & BFD_MACH_O_PROT_READ)
!                 flags |= SEC_READONLY;
!             }
!         }
      }
    else
      {
!       if ((flags & SEC_DEBUGGING) == 0)
!         flags |= SEC_ALLOC;
      }
+ 
+   if (section->offset != 0)
+     flags |= SEC_HAS_CONTENTS;
    if (section->nreloc != 0)
      flags |= SEC_RELOC;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]