/* BFD back-end for PDP-11 a.out binaries.
- Copyright (C) 2001-2017 Free Software Foundation, Inc.
+ Copyright (C) 2001-2020 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
#define SEGMENT__SIZE TARGET_PAGE_SIZE
#define DEFAULT_ARCH bfd_arch_pdp11
-#define DEFAULT_MID M_PDP11
+#define DEFAULT_MID M_PDP11
/* Do not "beautify" the CONCAT* macro args. Traditional C will not
remove whitespace added here, and thus will fail to concatenate
&& N_MAGIC(x) != ZMAGIC)
#include "sysdep.h"
+#include <limits.h>
#include "bfd.h"
#define external_exec pdp11_external_exec
bfd_byte e_entry[2]; /* Start address. */
bfd_byte e_unused[2]; /* Not used. */
bfd_byte e_flag[2]; /* Relocation info stripped. */
- bfd_byte e_relocatable; /* Ugly hack. */
+ bfd_byte e_relocatable; /* Ugly hack. */
};
#define EXEC_BYTES_SIZE (8 * 2)
reloc_howto_type howto_table_pdp11[] =
{
- /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */
+ /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */
HOWTO( 0, 0, 1, 16, FALSE, 0, complain_overflow_signed,0,"16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
HOWTO( 1, 0, 1, 16, TRUE, 0, complain_overflow_signed,0,"DISP16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
};
static bfd_boolean aout_link_check_archive_element (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *, const char *, bfd_boolean *);
-static bfd_boolean aout_link_add_object_symbols (bfd *, struct bfd_link_info *);
-static bfd_boolean aout_link_add_symbols (bfd *, struct bfd_link_info *);
-static bfd_boolean aout_link_write_symbols (struct aout_final_link_info *, bfd *);
+static bfd_boolean aout_link_add_object_symbols (bfd *, struct bfd_link_info *);
+static bfd_boolean aout_link_add_symbols (bfd *, struct bfd_link_info *);
+static bfd_boolean aout_link_write_symbols (struct aout_final_link_info *, bfd *);
reloc_howto_type *
oldrawptr = abfd->tdata.aout_data;
abfd->tdata.aout_data = rawptr;
- /* Copy the contents of the old tdata struct.
- In particular, we want the subformat, since for hpux it was set in
- hp300hpux.c:swap_exec_header_in and will be used in
- hp300hpux.c:callback. */
+ /* Copy the contents of the old tdata struct. */
if (oldrawptr != NULL)
*abfd->tdata.aout_data = *oldrawptr;
abort ();
}
- bfd_get_start_address (abfd) = execp->a_entry;
+ abfd->start_address = execp->a_entry;
obj_aout_symbols (abfd) = NULL;
- bfd_get_symcount (abfd) = execp->a_syms / sizeof (struct external_nlist);
+ abfd->symcount = execp->a_syms / sizeof (struct external_nlist);
/* The default relocation entry size is that of traditional V7 Unix. */
obj_reloc_entry_size (abfd) = RELOC_SIZE;
struct stat stat_buf;
/* The original heuristic doesn't work in some important cases.
- The a.out file has no information about the text start
- address. For files (like kernels) linked to non-standard
- addresses (ld -Ttext nnn) the entry point may not be between
- the default text start (obj_textsec(abfd)->vma) and
- (obj_textsec(abfd)->vma) + text size. This is not just a mach
- issue. Many kernels are loaded at non standard addresses. */
+ The a.out file has no information about the text start
+ address. For files (like kernels) linked to non-standard
+ addresses (ld -Ttext nnn) the entry point may not be between
+ the default text start (obj_textsec(abfd)->vma) and
+ (obj_textsec(abfd)->vma) + text size. This is not just a mach
+ issue. Many kernels are loaded at non standard addresses. */
if (abfd->iostream != NULL
&& (abfd->flags & BFD_IN_MEMORY) == 0
&& (fstat(fileno((FILE *) (abfd->iostream)), &stat_buf) == 0)
arch_flags = M_SPARCLET;
break;
- case bfd_arch_m68k:
- switch (machine)
- {
- case 0: arch_flags = M_68010; break;
- case bfd_mach_m68000: arch_flags = M_UNKNOWN; *unknown = FALSE; break;
- case bfd_mach_m68010: arch_flags = M_68010; break;
- case bfd_mach_m68020: arch_flags = M_68020; break;
- default: arch_flags = M_UNKNOWN; break;
- }
- break;
-
case bfd_arch_i386:
if (machine == 0
|| machine == bfd_mach_i386_i386
case 0:
case 2000:
case bfd_mach_mips3000:
- arch_flags = M_MIPS1;
+ arch_flags = M_MIPS1;
break;
case bfd_mach_mips4000: /* MIPS3 */
case bfd_mach_mips4400:
case bfd_mach_mips8000: /* MIPS4 */
case bfd_mach_mips6000: /* Real MIPS2: */
- arch_flags = M_MIPS2;
+ arch_flags = M_MIPS2;
break;
default:
arch_flags = M_UNKNOWN;
case bfd_arch_ns32k:
switch (machine)
{
- case 0: arch_flags = M_NS32532; break;
+ case 0: arch_flags = M_NS32532; break;
case 32032: arch_flags = M_NS32032; break;
case 32532: arch_flags = M_NS32532; break;
default: arch_flags = M_UNKNOWN; break;
else
{
/* The VMA of the .bss section is set by the VMA of the
- .data section plus the size of the .data section. We may
- need to add padding bytes to make this true. */
+ .data section plus the size of the .data section. We may
+ need to add padding bytes to make this true. */
pad = obj_bsssec (abfd)->vma - vma;
if (pad > 0)
{
else
{
/* The .text section is being loaded at an unusual address. We
- may need to pad it such that the .data section starts at a page
- boundary. */
+ may need to pad it such that the .data section starts at a page
+ boundary. */
if (ztih)
text_pad = ((obj_textsec (abfd)->filepos - obj_textsec (abfd)->vma)
& (adata (abfd).page_size - 1));
str;
}),
obj_textsec(abfd)->vma, obj_textsec(abfd)->size,
- obj_textsec(abfd)->alignment_power,
+ obj_textsec(abfd)->alignment_power,
obj_datasec(abfd)->vma, obj_datasec(abfd)->size,
- obj_datasec(abfd)->alignment_power,
+ obj_datasec(abfd)->alignment_power,
obj_bsssec(abfd)->vma, obj_bsssec(abfd)->size,
- obj_bsssec(abfd)->alignment_power);
+ obj_bsssec(abfd)->alignment_power);
#endif
#endif
#ifdef BFD_AOUT_DEBUG
fprintf (stderr, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n",
obj_textsec(abfd)->vma, obj_textsec(abfd)->size,
- obj_textsec(abfd)->filepos,
+ obj_textsec(abfd)->filepos,
obj_datasec(abfd)->vma, obj_datasec(abfd)->size,
- obj_datasec(abfd)->filepos,
+ obj_datasec(abfd)->filepos,
obj_bsssec(abfd)->vma, obj_bsssec(abfd)->size);
#endif
{
_bfd_error_handler
/* xgettext:c-format */
- (_("%B: can not represent section `%A' in a.out object file format"),
+ (_("%pB: can not represent section `%pA' in a.out object file format"),
abfd, section);
bfd_set_error (bfd_error_nonrepresentable_section);
return FALSE;
if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
|| bfd_bwrite (location, count, abfd) != count)
return FALSE;
-
- /* If necessary, pad the section to its aligned size. */
- if ((section == obj_datasec (abfd)
- || section == obj_textsec (abfd))
- && count < section->size
- && (bfd_seek (abfd, section->filepos + offset + section->size - 1, SEEK_SET) != 0
- || bfd_bwrite ("", 1, abfd) != 1))
- return FALSE;
}
return TRUE;
to another. */
sym_pointer->e_type[0] &= ~N_TYPE;
- sec = bfd_get_section (cache_ptr);
+ sec = bfd_asymbol_section (cache_ptr);
off = 0;
if (sec == NULL)
file. */
_bfd_error_handler
/* xgettext:c-format */
- (_("%B: can not represent section for symbol `%s' in a.out object file format"),
+ (_("%pB: can not represent section for symbol `%s' in a.out object file format"),
abfd, cache_ptr->name != NULL ? cache_ptr->name : "*unknown*");
bfd_set_error (bfd_error_nonrepresentable_section);
return FALSE;
{
_bfd_error_handler
/* xgettext:c-format */
- (_("%B: can not represent section `%A' in a.out object file format"),
+ (_("%pB: can not represent section `%pA' in a.out object file format"),
abfd, sec);
bfd_set_error (bfd_error_nonrepresentable_section);
return FALSE;
return FALSE;
}
- bfd_get_symcount (abfd) = obj_aout_external_sym_count (abfd);
+ abfd->symcount = obj_aout_external_sym_count (abfd);
obj_aout_symbols (abfd) = cached;
to give the true offset from the section */
-#define MOVE_ADDRESS(ad) \
- if (r_extern) \
+#define MOVE_ADDRESS(ad) \
+ if (r_extern) \
{ \
/* Undefined symbol. */ \
cache_ptr->sym_ptr_ptr = symbols + r_index; \
} \
else \
{ \
- /* Defined, section relative. replace symbol with pointer to \
+ /* Defined, section relative. replace symbol with pointer to \
symbol which points to section. */ \
switch (r_index) \
{ \
}
static void
-pdp11_aout_swap_reloc_in (bfd * abfd,
- bfd_byte * bytes,
- arelent * cache_ptr,
- bfd_size_type offset,
- asymbol ** symbols,
- bfd_size_type symcount)
+pdp11_aout_swap_reloc_in (bfd * abfd,
+ bfd_byte * bytes,
+ arelent * cache_ptr,
+ bfd_size_type offset,
+ asymbol ** symbols,
+ bfd_size_type symcount)
{
struct aoutdata *su = &(abfd->tdata.aout_data->a);
unsigned int r_index;
if (r_extern && r_index > symcount)
{
/* We could arrange to return an error, but it might be useful
- to see the file even if it is bad. */
+ to see the file even if it is bad. */
r_extern = 0;
r_index = N_ABS;
}
long
NAME (aout, get_reloc_upper_bound) (bfd *abfd, sec_ptr asect)
{
+ bfd_size_type count;
+
if (bfd_get_format (abfd) != bfd_object)
{
bfd_set_error (bfd_error_invalid_operation);
}
if (asect->flags & SEC_CONSTRUCTOR)
- return (sizeof (arelent *) * (asect->reloc_count + 1));
-
- if (asect == obj_datasec (abfd))
- return (sizeof (arelent *)
- * ((exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd))
- + 1));
-
- if (asect == obj_textsec (abfd))
- return (sizeof (arelent *)
- * ((exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd))
- + 1));
-
- /* TODO: why are there two if statements for obj_bsssec()? */
-
- if (asect == obj_bsssec (abfd))
- return sizeof (arelent *);
-
- if (asect == obj_bsssec (abfd))
- return 0;
+ count = asect->reloc_count;
+ else if (asect == obj_datasec (abfd))
+ count = exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd);
+ else if (asect == obj_textsec (abfd))
+ count = exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd);
+ else if (asect == obj_bsssec (abfd))
+ count = 0;
+ else
+ {
+ bfd_set_error (bfd_error_invalid_operation);
+ return -1;
+ }
- bfd_set_error (bfd_error_invalid_operation);
- return -1;
+ if (count >= LONG_MAX / sizeof (arelent *))
+ {
+ bfd_set_error (bfd_error_file_too_big);
+ return -1;
+ }
+ return (count + 1) * sizeof (arelent *);
}
\f
definition of the symbol is undefined or common. If the
current definition is common, we have a case in which we
have already seen an object file including
- int a;
+ int a;
and this object file from the archive includes
- int a = 5;
+ int a = 5;
In such a case we must include this object file.
FIXME: The SunOS 4.1.3 linker will pull in the archive
break;
case N_TEXT | N_EXT:
section = obj_textsec (abfd);
- value -= bfd_get_section_vma (abfd, section);
+ value -= bfd_section_vma (section);
break;
case N_DATA | N_EXT:
/* Treat N_SETV symbols as N_DATA symbol; see comment in
translate_from_native_sym_flags. */
section = obj_datasec (abfd);
- value -= bfd_get_section_vma (abfd, section);
+ value -= bfd_section_vma (section);
break;
case N_BSS | N_EXT:
section = obj_bsssec (abfd);
- value -= bfd_get_section_vma (abfd, section);
+ value -= bfd_section_vma (section);
break;
}
return TRUE;
case bfd_link_hash_new:
/* This can happen for set symbols when sets are not being
- built. */
+ built. */
return TRUE;
case bfd_link_hash_undefined:
type = N_UNDF | N_EXT;
(*flaginfo->info->callbacks->reloc_overflow)
(flaginfo->info, NULL,
(p->type == bfd_section_reloc_link_order
- ? bfd_section_name (flaginfo->output_bfd,
- pr->u.section)
+ ? bfd_section_name (pr->u.section)
: pr->u.name),
howto->name, pr->addend, NULL,
(asection *) NULL, (bfd_vma) 0);
if (h != NULL)
{
/* We decided to strip this symbol, but it
- turns out that we can't. Note that we
- lose the other and desc information here.
- I don't think that will ever matter for a
- global symbol. */
+ turns out that we can't. Note that we
+ lose the other and desc information here.
+ I don't think that will ever matter for a
+ global symbol. */
if (h->indx < 0)
{
h->indx = -2;
}
/* Now warn if a global symbol is undefined. We could not
- do this earlier, because check_dynamic_reloc might want
- to skip this reloc. */
+ do this earlier, because check_dynamic_reloc might want
+ to skip this reloc. */
if (hundef && ! bfd_link_pic (flaginfo->info))
{
const char *name;
asection *s;
s = aout_reloc_type_to_section (input_bfd, r_type);
- name = bfd_section_name (input_bfd, s);
+ name = bfd_section_name (s);
}
(*flaginfo->info->callbacks->reloc_overflow)
(flaginfo->info, (h ? &h->root : NULL), name, howto->name,
by the reloc size. */
_bfd_error_handler
/* xgettext:c-format */
- (_("%B: relocatable link from %s to %s not supported"),
+ (_("%pB: relocatable link from %s to %s not supported"),
abfd, sub->xvec->name, abfd->xvec->name);
bfd_set_error (bfd_error_invalid_operation);
goto error_return;
FIXME: At this point we do not know how much space the symbol
table will require. This will not work for any (nonstandard)
a.out target that needs to know the symbol table size before it
- can compute the relocation file positions. This may or may not
- be the case for the hp300hpux target, for example. */
+ can compute the relocation file positions. */
(*callback) (abfd, &aout_info.treloff, &aout_info.dreloff,
&aout_info.symoff);
obj_textsec (abfd)->rel_filepos = aout_info.treloff;
return FALSE;
PUT_WORD (output_bfd, strtab_index, outsym->e_strx);
PUT_WORD (output_bfd,
- (bfd_get_section_vma (output_bfd,
- obj_textsec (input_bfd)->output_section)
+ (bfd_section_vma (obj_textsec (input_bfd)->output_section)
+ obj_textsec (input_bfd)->output_offset),
outsym->e_value);
++obj_aout_external_sym_count (output_bfd);
bfd_boolean copy;
/* We set *symbol_map to 0 above for all symbols. If it has
- already been set to -1 for this symbol, it means that we are
- discarding it because it appears in a duplicate header file.
- See the N_BINCL code below. */
+ already been set to -1 for this symbol, it means that we are
+ discarding it because it appears in a duplicate header file.
+ See the N_BINCL code below. */
if (*symbol_map == -1)
continue;
/* Initialize *symbol_map to -1, which means that the symbol was
- not copied into the output file. We will change it later if
- we do copy the symbol over. */
+ not copied into the output file. We will change it later if
+ we do copy the symbol over. */
*symbol_map = -1;
type = H_GET_8 (input_bfd, sym->e_type);
h = *sym_hash;
/* Use the name from the hash table, in case the symbol was
- wrapped. */
+ wrapped. */
if (h != NULL)
name = h->root.root.string;
BFD_ASSERT (bfd_is_abs_section (output_section)
|| output_section->owner == output_bfd);
val = (hresolve->root.u.def.value
- + bfd_get_section_vma (output_bfd, output_section)
+ + bfd_section_vma (output_section)
+ input_section->output_offset);
/* Get the correct type based on the section. If
}
/* If we have already included a header file with the
- same value, then replace this one with an N_EXCL
- symbol. */
+ same value, then replace this one with an N_EXCL
+ symbol. */
copy = ! flaginfo->info->keep_memory;
incl_entry = aout_link_includes_lookup (&flaginfo->includes,
name, TRUE, copy);
if (t == NULL)
{
/* This is the first time we have seen this header
- file with this set of stabs strings. */
+ file with this set of stabs strings. */
t = bfd_hash_allocate (&flaginfo->includes.root,
sizeof *t);
if (t == NULL)
int *incl_map;
/* This is a duplicate header file. We must change
- it to be an N_EXCL entry, and mark all the
- included symbols to prevent outputting them. */
+ it to be an N_EXCL entry, and mark all the
+ included symbols to prevent outputting them. */
type = N_EXCL;
nest = 0;
bfd_getl64, bfd_getl_signed_64, bfd_putl64,
bfd_getp32, bfd_getp_signed_32, bfd_putp32,
bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Headers. */
- {_bfd_dummy_target, MY_object_p, /* bfd_check_format. */
- bfd_generic_archive_p, MY_core_file_p},
- {bfd_false, MY_mkobject, /* bfd_set_format. */
- _bfd_generic_mkarchive, bfd_false},
- {bfd_false, MY_write_object_contents, /* bfd_write_contents. */
- _bfd_write_archive_contents, bfd_false},
-
- BFD_JUMP_TABLE_GENERIC (MY),
- BFD_JUMP_TABLE_COPY (MY),
- BFD_JUMP_TABLE_CORE (MY),
- BFD_JUMP_TABLE_ARCHIVE (MY),
- BFD_JUMP_TABLE_SYMBOLS (MY),
- BFD_JUMP_TABLE_RELOCS (MY),
- BFD_JUMP_TABLE_WRITE (MY),
- BFD_JUMP_TABLE_LINK (MY),
- BFD_JUMP_TABLE_DYNAMIC (MY),
+ { /* bfd_check_format. */
+ _bfd_dummy_target,
+ MY_object_p,
+ bfd_generic_archive_p,
+ MY_core_file_p
+ },
+ { /* bfd_set_format. */
+ _bfd_bool_bfd_false_error,
+ MY_mkobject,
+ _bfd_generic_mkarchive,
+ _bfd_bool_bfd_false_error
+ },
+ { /* bfd_write_contents. */
+ _bfd_bool_bfd_false_error,
+ MY_write_object_contents,
+ _bfd_write_archive_contents,
+ _bfd_bool_bfd_false_error
+ },
+
+ BFD_JUMP_TABLE_GENERIC (MY),
+ BFD_JUMP_TABLE_COPY (MY),
+ BFD_JUMP_TABLE_CORE (MY),
+ BFD_JUMP_TABLE_ARCHIVE (MY),
+ BFD_JUMP_TABLE_SYMBOLS (MY),
+ BFD_JUMP_TABLE_RELOCS (MY),
+ BFD_JUMP_TABLE_WRITE (MY),
+ BFD_JUMP_TABLE_LINK (MY),
+ BFD_JUMP_TABLE_DYNAMIC (MY),
/* Alternative_target. */
NULL,