/* BFD back-end for PDP-11 a.out binaries.
- Copyright (C) 2001-2019 Free Software Foundation, Inc.
+ Copyright (C) 2001-2020 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
#define ARCH_SIZE 16
#undef TARGET_IS_BIG_ENDIAN_P
-#define TARGET_PAGE_SIZE 256
+#define TARGET_PAGE_SIZE 8192
#define SEGMENT__SIZE TARGET_PAGE_SIZE
#define DEFAULT_ARCH bfd_arch_pdp11
#define N_SET_FLAGS(execp, flags) do { } while (0)
#define N_BADMAG(x) (N_MAGIC(x) != OMAGIC \
&& N_MAGIC(x) != NMAGIC \
+ && N_MAGIC(x) != IMAGIC \
&& N_MAGIC(x) != ZMAGIC)
#include "sysdep.h"
+#include <limits.h>
#include "bfd.h"
#define external_exec pdp11_external_exec
#define A_MAGIC2 NMAGIC
#define NMAGIC 0410 /* Pure executable. */
#define ZMAGIC 0413 /* Demand-paged executable. */
-#define A_MAGIC3 0411 /* Separated I&D. */
+#define IMAGIC 0411 /* Separated I&D. */
+#define A_MAGIC3 IMAGIC
#define A_MAGIC4 0405 /* Overlay. */
#define A_MAGIC5 0430 /* Auto-overlay (nonseparate). */
#define A_MAGIC6 0431 /* Auto-overlay (separate). */
#undef N_REG
#undef N_FN
#undef N_EXT
+#undef N_STAB
#define N_TYPE 0x1f /* Type mask. */
#define N_UNDF 0x00 /* Undefined. */
#define N_ABS 0x01 /* Absolute. */
#define N_REG 0x14 /* Register symbol. */
#define N_FN 0x1f /* File name. */
#define N_EXT 0x20 /* External flag. */
+#define N_STAB 0xc0 /* Not relevant; modified aout64.h's 0xe0 to avoid N_EXT. */
#define RELOC_SIZE 2
struct external_nlist *output_syms;
};
+/* Copy of the link_info.separate_code boolean to select the output format with
+ separate instruction and data spaces selected by --imagic */
+static bfd_boolean separate_i_d = FALSE;
+
reloc_howto_type howto_table_pdp11[] =
{
/* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */
environment's "finish up" function just before returning, to
handle any last-minute setup. */
-const bfd_target *
+bfd_cleanup
NAME (aout, some_aout_object_p) (bfd *abfd,
struct internal_exec *execp,
- const bfd_target *(*callback_to_real_object_p) (bfd *))
+ bfd_cleanup (*callback_to_real_object_p) (bfd *))
{
struct aout_data_struct *rawptr, *oldrawptr;
- const bfd_target *result;
- bfd_size_type amt = sizeof (struct aout_data_struct);
+ bfd_cleanup cleanup;
+ size_t amt = sizeof (struct aout_data_struct);
rawptr = bfd_zalloc (abfd, amt);
if (rawptr == NULL)
}
else if (N_MAGIC (execp) == OMAGIC)
adata (abfd).magic = o_magic;
+ else if (N_MAGIC (execp) == IMAGIC)
+ adata (abfd).magic = i_magic;
else
{
/* Should have been checked with N_BADMAG before this routine
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;
adata(abfd)->segment_size = SEGMENT_SIZE;
adata(abfd)->exec_bytes_size = EXEC_BYTES_SIZE;
- return abfd->xvec;
+ return _bfd_no_cleanup;
/* The architecture is encoded in various ways in various a.out variants,
or is not encoded at all in some of them. The relocation size depends
header, should cope with them in this callback as well. */
#endif /* DOCUMENTATION */
- result = (*callback_to_real_object_p)(abfd);
+ cleanup = (*callback_to_real_object_p)(abfd);
/* Now that the segment addresses have been worked out, take a better
guess at whether the file is executable. If the entry point
}
#endif /* STAT_FOR_EXEC */
- if (!result)
+ if (!cleanup)
{
free (rawptr);
abfd->tdata.aout_data = oldrawptr;
}
- return result;
+ return cleanup;
}
/* Initialize ABFD for use with a.out files. */
NAME (aout, mkobject) (bfd *abfd)
{
struct aout_data_struct *rawptr;
- bfd_size_type amt = sizeof (struct aout_data_struct);
+ size_t amt = sizeof (struct aout_data_struct);
bfd_set_error (bfd_error_system_call);
file_ptr pos = adata (abfd).exec_bytes_size;
bfd_vma vma = 0;
int pad = 0;
+ asection *text = obj_textsec (abfd);
+ asection *data = obj_datasec (abfd);
+ asection *bss = obj_bsssec (abfd);
/* Text. */
- obj_textsec (abfd)->filepos = pos;
- if (! obj_textsec (abfd)->user_set_vma)
- obj_textsec (abfd)->vma = vma;
+ text->filepos = pos;
+ if (!text->user_set_vma)
+ text->vma = vma;
else
- vma = obj_textsec (abfd)->vma;
+ vma = text->vma;
- pos += obj_textsec (abfd)->size;
- vma += obj_textsec (abfd)->size;
+ pos += execp->a_text;
+ vma += execp->a_text;
/* Data. */
- if (!obj_datasec (abfd)->user_set_vma)
+ if (!data->user_set_vma)
{
- obj_textsec (abfd)->size += pad;
pos += pad;
vma += pad;
- obj_datasec (abfd)->vma = vma;
+ data->vma = vma;
}
else
- vma = obj_datasec (abfd)->vma;
- obj_datasec (abfd)->filepos = pos;
- pos += obj_datasec (abfd)->size;
- vma += obj_datasec (abfd)->size;
+ vma = data->vma;
+ execp->a_text += pad;
+
+ data->filepos = pos;
+ pos += data->size;
+ vma += data->size;
/* BSS. */
- if (! obj_bsssec (abfd)->user_set_vma)
+ if (!bss->user_set_vma)
{
- obj_datasec (abfd)->size += pad;
pos += pad;
vma += pad;
- obj_bsssec (abfd)->vma = vma;
+ bss->vma = vma;
}
- else
+ else if (data->size > 0 || bss->size > 0) /* PR25677: for objcopy --extract-symbol */
{
/* 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. */
- pad = obj_bsssec (abfd)->vma - vma;
- if (pad > 0)
- {
- obj_datasec (abfd)->size += pad;
- pos += pad;
- }
+ pad = bss->vma - vma;
+ if (pad < 0)
+ pad = 0;
+ pos += pad;
}
- obj_bsssec (abfd)->filepos = pos;
+ execp->a_data = data->size + pad;
+ bss->filepos = pos;
+ execp->a_bss = bss->size;
- /* Fix up the exec header. */
- execp->a_text = obj_textsec (abfd)->size;
- execp->a_data = obj_datasec (abfd)->size;
- execp->a_bss = obj_bsssec (abfd)->size;
N_SET_MAGIC (execp, OMAGIC);
}
bfd_size_type data_pad, text_pad;
file_ptr text_end;
const struct aout_backend_data *abdp;
- int ztih; /* Nonzero if text includes exec header. */
+ /* TRUE if text includes exec header. */
+ bfd_boolean ztih;
+ asection *text = obj_textsec (abfd);
+ asection *data = obj_datasec (abfd);
+ asection *bss = obj_bsssec (abfd);
abdp = aout_backend_info (abfd);
ztih = (abdp != NULL
&& (abdp->text_includes_header
|| obj_aout_subformat (abfd) == q_magic_format));
- obj_textsec(abfd)->filepos = (ztih
- ? adata(abfd).exec_bytes_size
- : adata(abfd).zmagic_disk_block_size);
- if (! obj_textsec(abfd)->user_set_vma)
+ text->filepos = (ztih
+ ? adata (abfd).exec_bytes_size
+ : adata (abfd).zmagic_disk_block_size);
+ if (!text->user_set_vma)
{
/* ?? Do we really need to check for relocs here? */
- obj_textsec(abfd)->vma = ((abfd->flags & HAS_RELOC)
- ? 0
- : (ztih
- ? (abdp->default_text_vma
- + adata (abfd).exec_bytes_size)
- : abdp->default_text_vma));
+ text->vma = ((abfd->flags & HAS_RELOC)
+ ? 0
+ : (ztih
+ ? abdp->default_text_vma + adata (abfd).exec_bytes_size
+ : abdp->default_text_vma));
text_pad = 0;
}
else
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)
+ text_pad = ((text->filepos - text->vma)
& (adata (abfd).page_size - 1));
else
- text_pad = ((- obj_textsec (abfd)->vma)
+ text_pad = (-text->vma
& (adata (abfd).page_size - 1));
}
/* Find start of data. */
if (ztih)
{
- text_end = obj_textsec (abfd)->filepos + obj_textsec (abfd)->size;
+ text_end = text->filepos + execp->a_text;
text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end;
}
else
/* Note that if page_size == zmagic_disk_block_size, then
filepos == page_size, and this case is the same as the ztih
case. */
- text_end = obj_textsec (abfd)->size;
+ text_end = execp->a_text;
text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end;
- text_end += obj_textsec (abfd)->filepos;
+ text_end += text->filepos;
}
-
- obj_textsec (abfd)->size += text_pad;
- text_end += text_pad;
+ execp->a_text += text_pad;
/* Data. */
- if (!obj_datasec(abfd)->user_set_vma)
+ if (!data->user_set_vma)
{
bfd_vma vma;
- vma = obj_textsec(abfd)->vma + obj_textsec(abfd)->size;
- obj_datasec(abfd)->vma = BFD_ALIGN (vma, adata(abfd).segment_size);
+ vma = text->vma + execp->a_text;
+ data->vma = BFD_ALIGN (vma, adata (abfd).segment_size);
}
if (abdp && abdp->zmagic_mapped_contiguous)
{
- text_pad = (obj_datasec(abfd)->vma
- - obj_textsec(abfd)->vma
- - obj_textsec(abfd)->size);
- obj_textsec(abfd)->size += text_pad;
+ text_pad = data->vma - (text->vma + execp->a_text);
+ /* Only pad the text section if the data
+ section is going to be placed after it. */
+ if (text_pad > 0)
+ execp->a_text += text_pad;
}
- obj_datasec (abfd)->filepos = (obj_textsec (abfd)->filepos
- + obj_textsec (abfd)->size);
+ data->filepos = text->filepos + execp->a_text;
/* Fix up exec header while we're at it. */
- execp->a_text = obj_textsec(abfd)->size;
if (ztih && (!abdp || (abdp && !abdp->exec_header_not_counted)))
- execp->a_text += adata(abfd).exec_bytes_size;
+ execp->a_text += adata (abfd).exec_bytes_size;
N_SET_MAGIC (execp, ZMAGIC);
/* Spec says data section should be rounded up to page boundary. */
- obj_datasec(abfd)->size
- = align_power (obj_datasec(abfd)->size,
- obj_bsssec(abfd)->alignment_power);
- execp->a_data = BFD_ALIGN (obj_datasec(abfd)->size,
- adata(abfd).page_size);
- data_pad = execp->a_data - obj_datasec(abfd)->size;
+ execp->a_data = align_power (data->size, bss->alignment_power);
+ execp->a_data = BFD_ALIGN (execp->a_data, adata (abfd).page_size);
+ data_pad = execp->a_data - data->size;
/* BSS. */
- if (!obj_bsssec(abfd)->user_set_vma)
- obj_bsssec(abfd)->vma = (obj_datasec(abfd)->vma
- + obj_datasec(abfd)->size);
+ if (!bss->user_set_vma)
+ bss->vma = data->vma + execp->a_data;
/* If the BSS immediately follows the data section and extra space
in the page is left after the data section, fudge data
in the header so that the bss section looks smaller by that
(Note that a linker script, as well as the above assignment,
could have explicitly set the BSS vma to immediately follow
the data section.) */
- if (align_power (obj_bsssec(abfd)->vma, obj_bsssec(abfd)->alignment_power)
- == obj_datasec(abfd)->vma + obj_datasec(abfd)->size)
- execp->a_bss = (data_pad > obj_bsssec(abfd)->size) ? 0 :
- obj_bsssec(abfd)->size - data_pad;
+ if (align_power (bss->vma, bss->alignment_power) == data->vma + execp->a_data)
+ execp->a_bss = data_pad > bss->size ? 0 : bss->size - data_pad;
else
- execp->a_bss = obj_bsssec(abfd)->size;
+ execp->a_bss = bss->size;
}
static void
adjust_n_magic (bfd *abfd, struct internal_exec *execp)
{
- file_ptr pos = adata(abfd).exec_bytes_size;
+ file_ptr pos = adata (abfd).exec_bytes_size;
bfd_vma vma = 0;
int pad;
+ asection *text = obj_textsec (abfd);
+ asection *data = obj_datasec (abfd);
+ asection *bss = obj_bsssec (abfd);
/* Text. */
- obj_textsec(abfd)->filepos = pos;
- if (!obj_textsec(abfd)->user_set_vma)
- obj_textsec(abfd)->vma = vma;
+ text->filepos = pos;
+ if (!text->user_set_vma)
+ text->vma = vma;
else
- vma = obj_textsec(abfd)->vma;
- pos += obj_textsec(abfd)->size;
- vma += obj_textsec(abfd)->size;
+ vma = text->vma;
+ pos += execp->a_text;
+ vma += execp->a_text;
/* Data. */
- obj_datasec(abfd)->filepos = pos;
- if (!obj_datasec(abfd)->user_set_vma)
- obj_datasec(abfd)->vma = BFD_ALIGN (vma, adata(abfd).segment_size);
- vma = obj_datasec(abfd)->vma;
+ data->filepos = pos;
+ if (!data->user_set_vma)
+ data->vma = BFD_ALIGN (vma, adata (abfd).segment_size);
+ vma = data->vma;
/* Since BSS follows data immediately, see if it needs alignment. */
- vma += obj_datasec(abfd)->size;
- pad = align_power (vma, obj_bsssec(abfd)->alignment_power) - vma;
- obj_datasec(abfd)->size += pad;
- pos += obj_datasec(abfd)->size;
+ vma += data->size;
+ pad = align_power (vma, bss->alignment_power) - vma;
+ execp->a_data = data->size + pad;
+ pos += execp->a_data;
/* BSS. */
- if (!obj_bsssec(abfd)->user_set_vma)
- obj_bsssec(abfd)->vma = vma;
+ if (!bss->user_set_vma)
+ bss->vma = vma;
else
- vma = obj_bsssec(abfd)->vma;
+ vma = bss->vma;
/* Fix up exec header. */
- execp->a_text = obj_textsec(abfd)->size;
- execp->a_data = obj_datasec(abfd)->size;
- execp->a_bss = obj_bsssec(abfd)->size;
+ execp->a_bss = bss->size;
N_SET_MAGIC (execp, NMAGIC);
}
+static void
+adjust_i_magic (bfd *abfd, struct internal_exec *execp)
+{
+ file_ptr pos = adata (abfd).exec_bytes_size;
+ bfd_vma vma = 0;
+ int pad;
+ asection *text = obj_textsec (abfd);
+ asection *data = obj_datasec (abfd);
+ asection *bss = obj_bsssec (abfd);
+
+ /* Text. */
+ text->filepos = pos;
+ if (!text->user_set_vma)
+ text->vma = vma;
+ else
+ vma = text->vma;
+ pos += execp->a_text;
+
+ /* Data. */
+ data->filepos = pos;
+ if (!data->user_set_vma)
+ data->vma = 0;
+ vma = data->vma;
+
+ /* Since BSS follows data immediately, see if it needs alignment. */
+ vma += data->size;
+ pad = align_power (vma, bss->alignment_power) - vma;
+ execp->a_data = data->size + pad;
+ pos += execp->a_data;
+
+ /* BSS. */
+ if (!bss->user_set_vma)
+ bss->vma = vma;
+ else
+ vma = bss->vma;
+
+ /* Fix up exec header. */
+ execp->a_bss = bss->size;
+ N_SET_MAGIC (execp, IMAGIC);
+}
+
bfd_boolean
NAME (aout, adjust_sizes_and_vmas) (bfd *abfd)
{
if (! NAME (aout, make_sections) (abfd))
return FALSE;
- if (adata(abfd).magic != undecided_magic)
+ if (adata (abfd).magic != undecided_magic)
return TRUE;
- obj_textsec(abfd)->size =
- align_power(obj_textsec(abfd)->size,
- obj_textsec(abfd)->alignment_power);
+ execp->a_text = align_power (obj_textsec (abfd)->size,
+ obj_textsec (abfd)->alignment_power);
/* Rule (heuristic) for when to pad to a new page. Note that there
are (at least) two ways demand-paged (ZMAGIC) files have been
(TARGET_PAGE_SIZE). However, newer versions of SUNOS start the text
segment right after the exec header; the latter is counted in the
text segment size, and is paged in by the kernel with the rest of
- the text. */
+ the text. */
/* This perhaps isn't the right way to do this, but made it simpler for me
to understand enough to implement it. Better would probably be to go
I understand it better now, but I haven't time to do the cleanup this
minute. */
- if (abfd->flags & WP_TEXT)
- adata(abfd).magic = n_magic;
+ if (separate_i_d)
+ adata (abfd).magic = i_magic;
+ else if (abfd->flags & WP_TEXT)
+ adata (abfd).magic = n_magic;
else
- adata(abfd).magic = o_magic;
+ adata (abfd).magic = o_magic;
#ifdef BFD_AOUT_DEBUG /* requires gcc2 */
#if __GNUC__ >= 2
fprintf (stderr, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n",
({ char *str;
- switch (adata(abfd).magic) {
- case n_magic: str = "NMAGIC"; break;
- case o_magic: str = "OMAGIC"; break;
- case z_magic: str = "ZMAGIC"; break;
- default: abort ();
- }
+ switch (adata (abfd).magic)
+ {
+ case n_magic: str = "NMAGIC"; break;
+ case o_magic: str = "OMAGIC"; break;
+ case i_magic: str = "IMAGIC"; break;
+ case z_magic: str = "ZMAGIC"; break;
+ default: abort ();
+ }
str;
}),
- obj_textsec(abfd)->vma, obj_textsec(abfd)->size,
- obj_textsec(abfd)->alignment_power,
- obj_datasec(abfd)->vma, obj_datasec(abfd)->size,
- obj_datasec(abfd)->alignment_power,
- obj_bsssec(abfd)->vma, obj_bsssec(abfd)->size,
- obj_bsssec(abfd)->alignment_power);
+ obj_textsec (abfd)->vma, obj_textsec (abfd)->size,
+ obj_textsec (abfd)->alignment_power,
+ obj_datasec (abfd)->vma, obj_datasec (abfd)->size,
+ obj_datasec (abfd)->alignment_power,
+ obj_bsssec (abfd)->vma, obj_bsssec (abfd)->size,
+ obj_bsssec (abfd)->alignment_power);
#endif
#endif
- switch (adata(abfd).magic)
+ switch (adata (abfd).magic)
{
case o_magic:
adjust_o_magic (abfd, execp);
case n_magic:
adjust_n_magic (abfd, execp);
break;
+ case i_magic:
+ adjust_i_magic (abfd, execp);
+ break;
default:
abort ();
}
#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_datasec(abfd)->vma, obj_datasec(abfd)->size,
- obj_datasec(abfd)->filepos,
- obj_bsssec(abfd)->vma, obj_bsssec(abfd)->size);
+ obj_textsec (abfd)->vma, execp->a_text,
+ obj_textsec (abfd)->filepos,
+ obj_datasec (abfd)->vma, execp->a_data,
+ obj_datasec (abfd)->filepos,
+ obj_bsssec (abfd)->vma, execp->a_bss);
#endif
return TRUE;
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;
/* We allocate using malloc to make the values easy to free
later on. If we put them on the objalloc it might not be
possible to free them. */
- syms = bfd_malloc (count * EXTERNAL_NLIST_SIZE);
+ if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
+ return FALSE;
+ syms = (struct external_nlist *)
+ _bfd_malloc_and_read (abfd, count * EXTERNAL_NLIST_SIZE,
+ count * EXTERNAL_NLIST_SIZE);
if (syms == NULL && count != 0)
return FALSE;
-
- if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
- || (bfd_bread (syms, exec_hdr (abfd)->a_syms, abfd)
- != exec_hdr (abfd)->a_syms))
- {
- free (syms);
- return FALSE;
- }
#endif
obj_aout_external_syms (abfd) = syms;
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)
asymbol *
NAME (aout, make_empty_symbol) (bfd *abfd)
{
- bfd_size_type amt = sizeof (aout_symbol_type);
+ size_t amt = sizeof (aout_symbol_type);
aout_symbol_type *new_symbol_type = bfd_zalloc (abfd, amt);
if (!new_symbol_type)
else
return FALSE;
- in->symbol.value = GET_SWORD (abfd, ext->e_value);
+ in->symbol.value = GET_WORD (abfd, ext->e_value);
/* TODO: is 0 a safe value here? */
in->desc = 0;
in->other = 0;
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;
return TRUE;
-error_return:
+ error_return:
_bfd_stringtab_free (strtab);
return FALSE;
}
if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0)
return FALSE;
-
- each_size = obj_reloc_entry_size (abfd);
-
- relocs = bfd_malloc (reloc_size);
+ relocs = _bfd_malloc_and_read (abfd, reloc_size, reloc_size);
if (relocs == NULL && reloc_size != 0)
return FALSE;
- if (bfd_bread (relocs, reloc_size, abfd) != reloc_size)
- {
- free (relocs);
- return FALSE;
- }
-
+ each_size = obj_reloc_entry_size (abfd);
count = reloc_size / each_size;
/* Count the number of NON-ZERO relocs, this is the count we want. */
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
size_t filelen, funclen;
char *buf;
- *filename_ptr = abfd->filename;
+ *filename_ptr = bfd_get_filename (abfd);
*functionname_ptr = 0;
*line_ptr = 0;
if (discriminator_ptr)
NAME (aout, link_hash_table_create) (bfd *abfd)
{
struct aout_link_hash_table *ret;
- bfd_size_type amt = sizeof (struct aout_link_hash_table);
+ size_t amt = sizeof (struct aout_link_hash_table);
ret = bfd_malloc (amt);
if (ret == NULL)
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;
}
bfd_vma val;
struct external_nlist outsym;
bfd_size_type indx;
- bfd_size_type amt;
+ size_t amt;
if (h->root.type == bfd_link_hash_warning)
{
(*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);
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,
if (bfd_link_pic (info))
abfd->flags |= DYNAMIC;
+ separate_i_d = info->separate_code;
aout_info.info = info;
aout_info.output_bfd = abfd;
aout_info.contents = NULL;
else if (obj_textsec (abfd)->reloc_count == 0
&& obj_datasec (abfd)->reloc_count == 0)
{
- bfd_byte b;
-
- b = 0;
- if (bfd_seek (abfd,
- (file_ptr) (obj_datasec (abfd)->filepos
- + exec_hdr (abfd)->a_data
- - 1),
- SEEK_SET) != 0
- || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
- goto error_return;
+ /* The layout of a typical a.out file is header, text, data,
+ relocs, symbols, string table. When there are no relocs,
+ symbols or string table, the last thing in the file is data
+ and a_data may be rounded up. However we may have a smaller
+ sized .data section and thus not written final padding. The
+ same thing can happen with text if there is no data. Write
+ final padding here to extend the file. */
+ file_ptr pos = 0;
+
+ if (exec_hdr (abfd)->a_data > obj_datasec (abfd)->size)
+ pos = obj_datasec (abfd)->filepos + exec_hdr (abfd)->a_data;
+ else if (obj_datasec (abfd)->size == 0
+ && exec_hdr (abfd)->a_text > obj_textsec (abfd)->size)
+ pos = obj_textsec (abfd)->filepos + exec_hdr (abfd)->a_text;
+ if (pos != 0)
+ {
+ bfd_byte b = 0;
+
+ if (bfd_seek (abfd, pos - 1, SEEK_SET) != 0
+ || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
+ goto error_return;
+ }
}
return TRUE;
discarding such symbols. */
if (strip != strip_all
&& (strip != strip_some
- || bfd_hash_lookup (flaginfo->info->keep_hash, input_bfd->filename,
+ || bfd_hash_lookup (flaginfo->info->keep_hash,
+ bfd_get_filename (input_bfd),
FALSE, FALSE) != NULL)
&& discard != discard_all)
{
H_PUT_8 (output_bfd, N_TEXT, outsym->e_type);
strtab_index = add_to_stringtab (output_bfd, flaginfo->strtab,
- input_bfd->filename, FALSE);
+ bfd_get_filename (input_bfd), FALSE);
if (strtab_index == (bfd_size_type) -1)
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_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