/* 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.
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;
break;
}
break;
-
+
case BFD_MACH_O_CPU_TYPE_ARM:
switch (cpusubtype)
{
break;
}
break;
-
+
case BFD_MACH_O_CPU_TYPE_ARM64:
switch (cpusubtype)
{
fprintf (file, _(" sizeocmds: %#lx\n"), (long) mdata->header.sizeofcmds);
fprintf (file, _(" flags: %#lx\n"), (long) mdata->header.flags);
fprintf (file, _(" version: %x\n"), mdata->header.version);
-
+
return TRUE;
}
/* Copy the cpusubtype. */
omdata->header.cpusubtype = imdata->header.cpusubtype;
-
+
/* Copy commands. */
for (icmd = imdata->first_command; icmd != NULL; icmd = icmd->next)
{
return TRUE;
}
-#if GCC_VERSION >= 4003
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wtype-limits"
-#endif
long
bfd_mach_o_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
asection *asect)
{
+#if SIZEOF_LONG == SIZEOF_INT
if (asect->reloc_count >= LONG_MAX / sizeof (arelent *))
{
bfd_set_error (bfd_error_file_too_big);
return -1;
}
+#endif
return (asect->reloc_count + 1) * sizeof (arelent *);
}
-#if GCC_VERSION >= 4003
-# pragma GCC diagnostic pop
-#endif
/* In addition to the need to byte-swap the symbol number, the bit positions
of the fields in the relocation information vary per target endian-ness. */
{
/* PR 17512: file: 006-2964-0.004. */
if (num > mdata->nsects)
- return FALSE;
+ {
+ _bfd_error_handler (_("\
+malformed mach-o reloc: section index is greater than the number of sections"));
+ return FALSE;
+ }
/* A section number. */
sym = mdata->sections[num - 1]->bfdsection->symbol_ptr_ptr;
{
bfd_mach_o_backend_data *bed = bfd_mach_o_get_backend_data (abfd);
unsigned long i;
- struct mach_o_reloc_info_external *native_relocs;
+ struct mach_o_reloc_info_external *native_relocs = NULL;
bfd_size_type native_size;
/* Allocate and read relocs. */
/* PR 17512: file: 09477b57. */
if (native_size < count)
- return -1;
+ goto err;
native_relocs =
(struct mach_o_reloc_info_external *) bfd_malloc (native_size);
}
free (native_relocs);
return i;
+
err:
free (native_relocs);
+ if (bfd_get_error () == bfd_error_no_error)
+ bfd_set_error (bfd_error_invalid_operation);
return -1;
}
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. */
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
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);
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)
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. */
}
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
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;
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;
}
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;
}
break;
case BFD_MACH_O_LC_NOTE:
if (!bfd_mach_o_read_note (abfd, command))
- return FALSE;
+ return FALSE;
break;
case BFD_MACH_O_LC_BUILD_VERSION:
if (!bfd_mach_o_read_build_version (abfd, command))
- return FALSE;
+ return FALSE;
break;
default:
command->len = 0;
ARCH_TYPE/ARCH_SUBTYPE and corresponding entry in header is ENTRY.
Set arelt_data and origin fields too. */
-static void
+static bfd_boolean
bfd_mach_o_fat_member_init (bfd *abfd,
enum bfd_architecture arch_type,
unsigned long arch_subtype,
struct areltdata *areltdata;
/* Create the member filename. Use ARCH_NAME. */
const bfd_arch_info_type *ap = bfd_lookup_arch (arch_type, arch_subtype);
+ char *filename;
if (ap)
{
/* Use the architecture name if known. */
- abfd->filename = xstrdup (ap->printable_name);
+ filename = bfd_strdup (ap->printable_name);
+ if (filename == NULL)
+ return FALSE;
}
else
{
/* Forge a uniq id. */
const size_t namelen = 2 + 8 + 1 + 2 + 8 + 1;
- char *name = xmalloc (namelen);
- snprintf (name, namelen, "0x%lx-0x%lx",
+ filename = bfd_malloc (namelen);
+ if (filename == NULL)
+ return FALSE;
+ snprintf (filename, namelen, "0x%lx-0x%lx",
entry->cputype, entry->cpusubtype);
- abfd->filename = name;
}
+ bfd_set_filename (abfd, filename);
areltdata = bfd_zmalloc (sizeof (struct areltdata));
+ if (areltdata == NULL)
+ return FALSE;
areltdata->parsed_size = entry->size;
abfd->arelt_data = areltdata;
abfd->iostream = NULL;
abfd->origin = entry->offset;
+ return TRUE;
}
bfd *
bfd_mach_o_convert_architecture (entry->cputype, entry->cpusubtype,
&arch_type, &arch_subtype);
- bfd_mach_o_fat_member_init (nbfd, arch_type, arch_subtype, entry);
+ if (!bfd_mach_o_fat_member_init (nbfd, arch_type, arch_subtype, entry))
+ {
+ bfd_close (nbfd);
+ return NULL;
+ }
bfd_set_arch_mach (nbfd, arch_type, arch_subtype);
if (res == NULL)
return NULL;
- bfd_mach_o_fat_member_init (res, cpu_type, cpu_subtype, e);
-
- if (bfd_check_format (res, format))
+ if (bfd_mach_o_fat_member_init (res, cpu_type, cpu_subtype, e)
+ && bfd_check_format (res, format))
{
BFD_ASSERT (bfd_get_arch_info (res) == arch);
return res;
return _bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
filename_ptr, functionname_ptr,
line_ptr, discriminator_ptr,
- dwarf_debug_sections, 0,
+ dwarf_debug_sections,
&mdata->dwarf2_find_line_info);
}