ubsan: m32r: left shift of negative value
[deliverable/binutils-gdb.git] / bfd / mach-o.c
index 7d70087c95e151ac8c3ceb8fe0754251d69de5aa..3b6fbb57888eec0228af39dc00c9b633d0af3a3e 100644 (file)
@@ -1,5 +1,5 @@
 /* Mach-O support for BFD.
-   Copyright (C) 1999-2019 Free Software Foundation, Inc.
+   Copyright (C) 1999-2020 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -437,7 +437,7 @@ bfd_mach_o_convert_section_name_to_mach_o (bfd *abfd ATTRIBUTE_UNUSED,
                                           bfd_mach_o_section *section)
 {
   const mach_o_section_name_xlat *xlat;
-  const char *name = bfd_get_section_name (abfd, sect);
+  const char *name = bfd_section_name (sect);
   const char *segname;
   const char *dot;
   unsigned int len;
@@ -618,12 +618,12 @@ cputype (unsigned long value)
 }
 
 static const char *
-cpusubtype (unsigned long cputype, unsigned long cpusubtype)
+cpusubtype (unsigned long cpu_type, unsigned long cpu_subtype)
 {
   static char buffer[128];
 
   buffer[0] = 0;
-  switch (cpusubtype & BFD_MACH_O_CPU_SUBTYPE_MASK)
+  switch (cpu_subtype & BFD_MACH_O_CPU_SUBTYPE_MASK)
     {
     case 0:
       break;
@@ -633,13 +633,13 @@ cpusubtype (unsigned long cputype, unsigned long cpusubtype)
       sprintf (buffer, _("<unknown mask flags>")); break;
     }
 
-  cpusubtype &= ~ BFD_MACH_O_CPU_SUBTYPE_MASK;
+  cpu_subtype &= ~ BFD_MACH_O_CPU_SUBTYPE_MASK;
 
-  switch (cputype)
+  switch (cpu_type)
     {
     case BFD_MACH_O_CPU_TYPE_X86_64:
     case BFD_MACH_O_CPU_TYPE_I386:
-      switch (cpusubtype)
+      switch (cpu_subtype)
        {
        case BFD_MACH_O_CPU_SUBTYPE_X86_ALL:
          return strcat (buffer, " (X86_ALL)");
@@ -649,7 +649,7 @@ cpusubtype (unsigned long cputype, unsigned long cpusubtype)
       break;
 
     case BFD_MACH_O_CPU_TYPE_ARM:
-      switch (cpusubtype)
+      switch (cpu_subtype)
        {
        case BFD_MACH_O_CPU_SUBTYPE_ARM_ALL:
          return strcat (buffer, " (ARM_ALL)");
@@ -669,7 +669,7 @@ cpusubtype (unsigned long cputype, unsigned long cpusubtype)
       break;
 
     case BFD_MACH_O_CPU_TYPE_ARM64:
-      switch (cpusubtype)
+      switch (cpu_subtype)
        {
        case BFD_MACH_O_CPU_SUBTYPE_ARM64_ALL:
          return strcat (buffer, " (ARM64_ALL)");
@@ -684,7 +684,7 @@ cpusubtype (unsigned long cputype, unsigned long cpusubtype)
       break;
     }
 
-  if (cpusubtype != 0)
+  if (cpu_subtype != 0)
     return strcat (buffer, _(" (<unknown>)"));
 
   return buffer;
@@ -2583,13 +2583,13 @@ bfd_mach_o_mangle_sections (bfd *abfd, bfd_mach_o_data_struct *mdata)
   target_index = 0;
   for (sec = abfd->sections; sec; sec = sec->next)
     {
-      unsigned bfd_align = bfd_get_section_alignment (abfd, sec);
+      unsigned bfd_align = bfd_section_alignment (sec);
       bfd_mach_o_section *msect = bfd_mach_o_get_mach_o_section (sec);
 
       mdata->sections[target_index] = msect;
 
-      msect->addr = bfd_get_section_vma (abfd, sec);
-      msect->size = bfd_get_section_size (sec);
+      msect->addr = bfd_section_vma (sec);
+      msect->size = bfd_section_size (sec);
 
       /* Use the largest alignment set, in case it was bumped after the
         section was created.  */
@@ -2808,7 +2808,7 @@ bfd_mach_o_set_section_flags_from_bfd (bfd *abfd ATTRIBUTE_UNUSED,
   bfd_mach_o_section *s = bfd_mach_o_get_mach_o_section (sec);
 
   /* Create default flags.  */
-  bfd_flags = bfd_get_section_flags (abfd, sec);
+  bfd_flags = bfd_section_flags (sec);
   if ((bfd_flags & SEC_CODE) == SEC_CODE)
     s->flags = BFD_MACH_O_S_ATTR_PURE_INSTRUCTIONS
       | BFD_MACH_O_S_ATTR_SOME_INSTRUCTIONS
@@ -2983,7 +2983,7 @@ bfd_mach_o_build_exec_seg_command (bfd *abfd, bfd_mach_o_segment_command *seg)
   for (s = seg->sect_head; s != NULL; s = s->next)
     {
       asection *sec = s->bfdsection;
-      flagword flags = bfd_get_section_flags (abfd, sec);
+      flagword flags = bfd_section_flags (sec);
 
       /* Adjust segment size.  */
       seg->vmsize = FILE_ALIGN (seg->vmsize, s->align);
@@ -3502,7 +3502,7 @@ bfd_boolean
 bfd_mach_o_new_section_hook (bfd *abfd, asection *sec)
 {
   bfd_mach_o_section *s;
-  unsigned bfdalign = bfd_get_section_alignment (abfd, sec);
+  unsigned bfdalign = bfd_section_alignment (sec);
 
   s = bfd_mach_o_get_mach_o_section (sec);
   if (s == NULL)
@@ -3526,10 +3526,10 @@ 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;
-         (void) bfd_set_section_alignment (abfd, sec, s->align);
-         bfd_flags = bfd_get_section_flags (abfd, sec);
+         bfd_set_section_alignment (sec, s->align);
+         bfd_flags = bfd_section_flags (sec);
          if (bfd_flags == SEC_NO_FLAGS)
-           bfd_set_section_flags (abfd, sec, xlat->bfd_flags);
+           bfd_set_section_flags (sec, xlat->bfd_flags);
        }
       else
        /* Create default flags.  */
@@ -3540,13 +3540,12 @@ bfd_mach_o_new_section_hook (bfd *abfd, asection *sec)
 }
 
 static void
-bfd_mach_o_init_section_from_mach_o (bfd *abfd, asection *sec,
-                                    unsigned long prot)
+bfd_mach_o_init_section_from_mach_o (asection *sec, unsigned long prot)
 {
   flagword flags;
   bfd_mach_o_section *section;
 
-  flags = bfd_get_section_flags (abfd, sec);
+  flags = bfd_section_flags (sec);
   section = bfd_mach_o_get_mach_o_section (sec);
 
   /* TODO: see if we should use the xlat system for doing this by
@@ -3584,7 +3583,7 @@ bfd_mach_o_init_section_from_mach_o (bfd *abfd, asection *sec,
   if (section->nreloc != 0)
     flags |= SEC_RELOC;
 
-  bfd_set_section_flags (abfd, sec, flags);
+  bfd_set_section_flags (sec, flags);
 
   sec->vma = section->addr;
   sec->lma = section->addr;
@@ -3651,7 +3650,7 @@ bfd_mach_o_read_section_32 (bfd *abfd, unsigned long prot)
   section->reserved2 = bfd_h_get_32 (abfd, raw.reserved2);
   section->reserved3 = 0;
 
-  bfd_mach_o_init_section_from_mach_o (abfd, sec, prot);
+  bfd_mach_o_init_section_from_mach_o (sec, prot);
 
   return sec;
 }
@@ -3694,7 +3693,7 @@ bfd_mach_o_read_section_64 (bfd *abfd, unsigned long prot)
   section->reserved2 = bfd_h_get_32 (abfd, raw.reserved2);
   section->reserved3 = bfd_h_get_32 (abfd, raw.reserved3);
 
-  bfd_mach_o_init_section_from_mach_o (abfd, sec, prot);
+  bfd_mach_o_init_section_from_mach_o (sec, prot);
 
   return sec;
 }
@@ -5102,8 +5101,8 @@ bfd_mach_o_scan (bfd *abfd,
                 bfd_mach_o_data_struct *mdata)
 {
   unsigned int i;
-  enum bfd_architecture cputype;
-  unsigned long cpusubtype;
+  enum bfd_architecture cpu_type;
+  unsigned long cpu_subtype;
   unsigned int hdrsize;
 
   hdrsize = mach_o_wide_p (header) ?
@@ -5129,8 +5128,8 @@ bfd_mach_o_scan (bfd *abfd,
   abfd->tdata.mach_o_data = mdata;
 
   bfd_mach_o_convert_architecture (header->cputype, header->cpusubtype,
-                                  &cputype, &cpusubtype);
-  if (cputype == bfd_arch_unknown)
+                                  &cpu_type, &cpu_subtype);
+  if (cpu_type == bfd_arch_unknown)
     {
       _bfd_error_handler
        /* xgettext:c-format */
@@ -5139,7 +5138,7 @@ bfd_mach_o_scan (bfd *abfd,
       return FALSE;
     }
 
-  bfd_set_arch_mach (abfd, cputype, cpusubtype);
+  bfd_set_arch_mach (abfd, cpu_type, cpu_subtype);
 
   if (header->ncmds != 0)
     {
@@ -5227,8 +5226,8 @@ bfd_mach_o_gen_mkobject (bfd *abfd)
 const bfd_target *
 bfd_mach_o_header_p (bfd *abfd,
                     file_ptr hdr_off,
-                    bfd_mach_o_filetype filetype,
-                    bfd_mach_o_cpu_type cputype)
+                    bfd_mach_o_filetype file_type,
+                    bfd_mach_o_cpu_type cpu_type)
 {
   bfd_mach_o_header header;
   bfd_mach_o_data_struct *mdata;
@@ -5255,9 +5254,9 @@ bfd_mach_o_header_p (bfd *abfd,
   /* Check cputype and filetype.
      In case of wildcard, do not accept magics that are handled by existing
      targets.  */
-  if (cputype)
+  if (cpu_type)
     {
-      if (header.cputype != cputype)
+      if (header.cputype != cpu_type)
        goto wrong;
     }
   else
@@ -5270,9 +5269,9 @@ bfd_mach_o_header_p (bfd *abfd,
 #endif
     }
 
-  if (filetype)
+  if (file_type)
     {
-      if (header.filetype != filetype)
+      if (header.filetype != file_type)
        goto wrong;
     }
   else
@@ -5753,6 +5752,8 @@ bfd_mach_o_core_fetch_environment (bfd *abfd,
          unsigned char *buf = bfd_malloc (1024);
          unsigned long size = 1024;
 
+         if (buf == NULL)
+           return -1;
          for (;;)
            {
              bfd_size_type nread = 0;
@@ -5798,6 +5799,8 @@ bfd_mach_o_core_fetch_environment (bfd *abfd,
                      bottom = seg->fileoff + seg->filesize - offset;
                      top = seg->fileoff + seg->filesize - 4;
                      *rbuf = bfd_malloc (top - bottom);
+                     if (*rbuf == NULL)
+                       return -1;
                      *rlen = top - bottom;
 
                      memcpy (*rbuf, buf + size - *rlen, *rlen);
@@ -5942,6 +5945,9 @@ bfd_mach_o_follow_dsym (bfd *abfd)
   dsym_filename = (char *)bfd_malloc (strlen (base_bfd->filename)
                                       + strlen (dsym_subdir) + 1
                                       + strlen (base_basename) + 1);
+  if (dsym_filename == NULL)
+    return NULL;
+
   sprintf (dsym_filename, "%s%s/%s",
           base_bfd->filename, dsym_subdir, base_basename);
 
This page took 0.028517 seconds and 4 git commands to generate.