X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=bfd%2Fpdp11.c;h=74617fc8a771efc130d3c5b3d6aa9dd0a102c18f;hb=f4e0d9f40b21fb42bbf7da07917683fb1cc16e8e;hp=1560f17762c55410027456fe97f1e2051a76ce04;hpb=22cdc249cd8dd8a43a5a4d2cba2b69f240362a8b;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/pdp11.c b/bfd/pdp11.c index 1560f17762..74617fc8a7 100644 --- a/bfd/pdp11.c +++ b/bfd/pdp11.c @@ -1,6 +1,5 @@ /* BFD back-end for PDP-11 a.out binaries. - Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011 - Free Software Foundation, Inc. + Copyright (C) 2001-2016 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -38,7 +37,7 @@ #define ARCH_SIZE 16 #undef TARGET_IS_BIG_ENDIAN_P -#define TARGET_PAGE_SIZE 1024 +#define TARGET_PAGE_SIZE 256 #define SEGMENT__SIZE TARGET_PAGE_SIZE #define DEFAULT_ARCH bfd_arch_pdp11 @@ -59,9 +58,9 @@ #define N_HEADER_IN_TEXT(x) 0 /* There is no flags field. */ -#define N_FLAGS(exec) 0 +#define N_FLAGS(execp) 0 -#define N_SET_FLAGS(exec, flags) do { } while (0) +#define N_SET_FLAGS(execp, flags) do { } while (0) #define N_BADMAG(x) (N_MAGIC(x) != OMAGIC \ && N_MAGIC(x) != NMAGIC \ && N_MAGIC(x) != ZMAGIC) @@ -112,11 +111,11 @@ struct pdp11_external_nlist #define EXTERNAL_NLIST_SIZE 8 #define N_TXTOFF(x) (EXEC_BYTES_SIZE) -#define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text) -#define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data) -#define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_trsize) -#define N_SYMOFF(x) (N_DRELOFF(x) + (x).a_drsize) -#define N_STROFF(x) (N_SYMOFF(x) + (x).a_syms) +#define N_DATOFF(x) (N_TXTOFF(x) + (x)->a_text) +#define N_TRELOFF(x) (N_DATOFF(x) + (x)->a_data) +#define N_DRELOFF(x) (N_TRELOFF(x) + (x)->a_trsize) +#define N_SYMOFF(x) (N_DRELOFF(x) + (x)->a_drsize) +#define N_STROFF(x) (N_SYMOFF(x) + (x)->a_syms) #define WRITE_HEADERS(abfd, execp) pdp11_aout_write_headers (abfd, execp) @@ -252,7 +251,7 @@ HOWTO( 1, 0, 1, 16, TRUE, 0, complain_overflow_signed,0,"DISP16", TRU #define TABLE_SIZE(TABLE) (sizeof(TABLE)/sizeof(TABLE[0])) -static bfd_boolean aout_link_check_archive_element (bfd *, struct bfd_link_info *, bfd_boolean *); +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 *); @@ -293,11 +292,9 @@ static int pdp11_aout_write_headers (bfd *abfd, struct internal_exec *execp) { struct external_exec exec_bytes; - bfd_size_type text_size; - file_ptr text_end; if (adata(abfd).magic == undecided_magic) - NAME (aout, adjust_sizes_and_vmas) (abfd, &text_size, &text_end); + NAME (aout, adjust_sizes_and_vmas) (abfd); execp->a_syms = bfd_get_symcount (abfd) * EXTERNAL_NLIST_SIZE; execp->a_entry = bfd_get_start_address (abfd); @@ -327,7 +324,7 @@ pdp11_aout_write_headers (bfd *abfd, struct internal_exec *execp) if (bfd_get_outsymbols (abfd) != NULL && bfd_get_symcount (abfd) != 0) { - if (bfd_seek (abfd, (file_ptr) (N_SYMOFF(*execp)), SEEK_SET) != 0) + if (bfd_seek (abfd, (file_ptr) (N_SYMOFF (execp)), SEEK_SET) != 0) return FALSE; if (! NAME (aout, write_syms) (abfd)) @@ -337,9 +334,9 @@ pdp11_aout_write_headers (bfd *abfd, struct internal_exec *execp) if (obj_textsec (abfd)->reloc_count > 0 || obj_datasec (abfd)->reloc_count > 0) { - if (bfd_seek (abfd, (file_ptr) (N_TRELOFF(*execp)), SEEK_SET) != 0 + if (bfd_seek (abfd, (file_ptr) (N_TRELOFF (execp)), SEEK_SET) != 0 || !NAME (aout, squirt_out_relocs) (abfd, obj_textsec (abfd)) - || bfd_seek (abfd, (file_ptr) (N_DRELOFF(*execp)), SEEK_SET) != 0 + || bfd_seek (abfd, (file_ptr) (N_DRELOFF (execp)), SEEK_SET) != 0 || !NAME (aout, squirt_out_relocs) (abfd, obj_datasec (abfd))) return FALSE; } @@ -360,12 +357,7 @@ MY(write_object_contents) (bfd *abfd) will normally have been done by set_section_contents, but only if there actually are some section contents. */ if (! abfd->output_has_begun) - { - bfd_size_type text_size; - file_ptr text_end; - - NAME (aout, adjust_sizes_and_vmas) (abfd, &text_size, &text_end); - } + NAME (aout, adjust_sizes_and_vmas) (abfd); obj_reloc_entry_size (abfd) = RELOC_SIZE; @@ -493,20 +485,20 @@ NAME (aout, some_aout_object_p) (bfd *abfd, /* Setting of EXEC_P has been deferred to the bottom of this function. */ if (execp->a_syms) abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS; - if (N_DYNAMIC(*execp)) + if (N_DYNAMIC (execp)) abfd->flags |= DYNAMIC; - if (N_MAGIC (*execp) == ZMAGIC) + if (N_MAGIC (execp) == ZMAGIC) { abfd->flags |= D_PAGED | WP_TEXT; adata (abfd).magic = z_magic; } - else if (N_MAGIC (*execp) == NMAGIC) + else if (N_MAGIC (execp) == NMAGIC) { abfd->flags |= WP_TEXT; adata (abfd).magic = n_magic; } - else if (N_MAGIC (*execp) == OMAGIC) + else if (N_MAGIC (execp) == OMAGIC) adata (abfd).magic = o_magic; else { @@ -563,25 +555,25 @@ NAME (aout, some_aout_object_p) (bfd *abfd, in by the callback: */ struct exec *execp = exec_hdr (abfd); - obj_textsec (abfd)->size = N_TXTSIZE(*execp); + obj_textsec (abfd)->size = N_TXTSIZE (execp); /* Data and bss are already filled in since they're so standard. */ /* The virtual memory addresses of the sections. */ - obj_textsec (abfd)->vma = N_TXTADDR(*execp); - obj_datasec (abfd)->vma = N_DATADDR(*execp); - obj_bsssec (abfd)->vma = N_BSSADDR(*execp); + obj_textsec (abfd)->vma = N_TXTADDR (execp); + obj_datasec (abfd)->vma = N_DATADDR (execp); + obj_bsssec (abfd)->vma = N_BSSADDR (execp); /* The file offsets of the sections. */ - obj_textsec (abfd)->filepos = N_TXTOFF(*execp); - obj_datasec (abfd)->filepos = N_DATOFF(*execp); + obj_textsec (abfd)->filepos = N_TXTOFF (execp); + obj_datasec (abfd)->filepos = N_DATOFF (execp); /* The file offsets of the relocation info. */ - obj_textsec (abfd)->rel_filepos = N_TRELOFF(*execp); - obj_datasec (abfd)->rel_filepos = N_DRELOFF(*execp); + obj_textsec (abfd)->rel_filepos = N_TRELOFF (execp); + obj_datasec (abfd)->rel_filepos = N_DRELOFF (execp); /* The file offsets of the string table and symbol table. */ - obj_str_filepos (abfd) = N_STROFF (*execp); - obj_sym_filepos (abfd) = N_SYMOFF (*execp); + obj_str_filepos (abfd) = N_STROFF (execp); + obj_sym_filepos (abfd) = N_SYMOFF (execp); /* Determine the architecture and machine type of the object file. */ abfd->obj_arch = bfd_arch_obscure; @@ -861,7 +853,7 @@ adjust_o_magic (bfd *abfd, struct internal_exec *execp) 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); + N_SET_MAGIC (execp, OMAGIC); } static void @@ -945,7 +937,7 @@ adjust_z_magic (bfd *abfd, struct internal_exec *execp) execp->a_text = obj_textsec(abfd)->size; if (ztih && (!abdp || (abdp && !abdp->exec_header_not_counted))) execp->a_text += adata(abfd).exec_bytes_size; - N_SET_MAGIC (*execp, ZMAGIC); + N_SET_MAGIC (execp, ZMAGIC); /* Spec says data section should be rounded up to page boundary. */ obj_datasec(abfd)->size @@ -1012,13 +1004,11 @@ adjust_n_magic (bfd *abfd, struct internal_exec *execp) 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, NMAGIC); + N_SET_MAGIC (execp, NMAGIC); } bfd_boolean -NAME (aout, adjust_sizes_and_vmas) (bfd *abfd, - bfd_size_type *text_size, - file_ptr * text_end ATTRIBUTE_UNUSED) +NAME (aout, adjust_sizes_and_vmas) (bfd *abfd) { struct internal_exec *execp = exec_hdr (abfd); @@ -1032,7 +1022,6 @@ NAME (aout, adjust_sizes_and_vmas) (bfd *abfd, align_power(obj_textsec(abfd)->size, obj_textsec(abfd)->alignment_power); - *text_size = obj_textsec (abfd)->size; /* Rule (heuristic) for when to pad to a new page. Note that there are (at least) two ways demand-paged (ZMAGIC) files have been handled. Most Berkeley-based systems start the text segment at @@ -1143,12 +1132,9 @@ NAME (aout, set_section_contents) (bfd *abfd, file_ptr offset, bfd_size_type count) { - file_ptr text_end; - bfd_size_type text_size; - if (! abfd->output_has_begun) { - if (! NAME (aout, adjust_sizes_and_vmas) (abfd, & text_size, & text_end)) + if (! NAME (aout, adjust_sizes_and_vmas) (abfd)) return FALSE; } @@ -1173,6 +1159,14 @@ NAME (aout, set_section_contents) (bfd *abfd, 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; @@ -1190,6 +1184,14 @@ aout_get_external_symbols (bfd *abfd) count = exec_hdr (abfd)->a_syms / EXTERNAL_NLIST_SIZE; + /* PR 17512: file: 011f5a08. */ + if (count == 0) + { + obj_aout_external_syms (abfd) = NULL; + obj_aout_external_sym_count (abfd) = count; + return TRUE; + } + #ifdef USE_MMAP if (! bfd_get_file_window (abfd, obj_sym_filepos (abfd), exec_hdr (abfd)->a_syms, @@ -2183,12 +2185,13 @@ NAME (aout, minisymbol_to_symbol) (bfd *abfd, bfd_boolean NAME (aout, find_nearest_line) (bfd *abfd, - asection *section, asymbol **symbols, + asection *section, bfd_vma offset, const char **filename_ptr, const char **functionname_ptr, - unsigned int *line_ptr) + unsigned int *line_ptr, + unsigned int *discriminator_ptr) { /* Run down the file looking for the filename, function and linenumber. */ asymbol **p; @@ -2205,6 +2208,8 @@ NAME (aout, find_nearest_line) (bfd *abfd, *filename_ptr = abfd->filename; *functionname_ptr = 0; *line_ptr = 0; + if (discriminator_ptr) + *discriminator_ptr = 0; if (symbols != NULL) { @@ -2603,7 +2608,7 @@ aout_link_check_ar_symbols (bfd *abfd, However, it might be correct. */ if (!(*info->callbacks ->add_archive_element) (info, abfd, name, subsbfd)) - return FALSE; + continue; *pneeded = TRUE; return TRUE; } @@ -2680,6 +2685,8 @@ aout_link_check_ar_symbols (bfd *abfd, static bfd_boolean aout_link_check_archive_element (bfd *abfd, struct bfd_link_info *info, + struct bfd_link_hash_entry *h ATTRIBUTE_UNUSED, + const char *name ATTRIBUTE_UNUSED, bfd_boolean *pneeded) { bfd *oldbfd; @@ -3063,9 +3070,8 @@ aout_link_reloc_link_order (struct aout_final_link_info *flaginfo, } else { - if (! ((*flaginfo->info->callbacks->unattached_reloc) - (flaginfo->info, pr->u.name, NULL, NULL, (bfd_vma) 0))) - return FALSE; + (*flaginfo->info->callbacks->unattached_reloc) + (flaginfo->info, pr->u.name, NULL, NULL, (bfd_vma) 0); r_index = 0; } } @@ -3148,7 +3154,7 @@ aout_link_reloc_link_order (struct aout_final_link_info *flaginfo, size = bfd_get_reloc_size (howto); buf = bfd_zmalloc (size); - if (buf == NULL) + if (buf == NULL && size != 0) return FALSE; r = MY_relocate_contents (howto, flaginfo->output_bfd, pr->addend, buf); @@ -3160,18 +3166,14 @@ aout_link_reloc_link_order (struct aout_final_link_info *flaginfo, case bfd_reloc_outofrange: abort (); case bfd_reloc_overflow: - if (! ((*flaginfo->info->callbacks->reloc_overflow) - (flaginfo->info, NULL, - (p->type == bfd_section_reloc_link_order - ? bfd_section_name (flaginfo->output_bfd, - pr->u.section) - : pr->u.name), - howto->name, pr->addend, NULL, - (asection *) NULL, (bfd_vma) 0))) - { - free (buf); - return FALSE; - } + (*flaginfo->info->callbacks->reloc_overflow) + (flaginfo->info, NULL, + (p->type == bfd_section_reloc_link_order + ? bfd_section_name (flaginfo->output_bfd, + pr->u.section) + : pr->u.name), + howto->name, pr->addend, NULL, + (asection *) NULL, (bfd_vma) 0); break; } ok = bfd_set_section_contents (flaginfo->output_bfd, o, @@ -3244,7 +3246,7 @@ pdp11_aout_link_input_section (struct aout_final_link_info *flaginfo, BFD_ASSERT (input_bfd->xvec->header_byteorder == output_bfd->xvec->header_byteorder); - relocatable = flaginfo->info->relocatable; + relocatable = bfd_link_relocatable (flaginfo->info); syms = obj_aout_external_syms (input_bfd); strings = obj_aout_external_strings (input_bfd); sym_hashes = obj_aout_sym_hashes (input_bfd); @@ -3348,10 +3350,9 @@ pdp11_aout_link_input_section (struct aout_final_link_info *flaginfo, name = strings + GET_WORD (input_bfd, syms[r_index].e_strx); - if (! ((*flaginfo->info->callbacks->unattached_reloc) - (flaginfo->info, name, input_bfd, input_section, - r_addr))) - return FALSE; + (*flaginfo->info->callbacks->unattached_reloc) + (flaginfo->info, name, input_bfd, input_section, + r_addr); r_index = 0; } } @@ -3454,7 +3455,7 @@ pdp11_aout_link_input_section (struct aout_final_link_info *flaginfo, /* Now warn if a global symbol is undefined. We could not do this earlier, because check_dynamic_reloc might want to skip this reloc. */ - if (hundef && ! flaginfo->info->shared) + if (hundef && ! bfd_link_pic (flaginfo->info)) { const char *name; @@ -3462,10 +3463,9 @@ pdp11_aout_link_input_section (struct aout_final_link_info *flaginfo, name = h->root.root.string; else name = strings + GET_WORD (input_bfd, syms[r_index].e_strx); - if (! ((*flaginfo->info->callbacks->undefined_symbol) - (flaginfo->info, name, input_bfd, input_section, - r_addr, TRUE))) - return FALSE; + (*flaginfo->info->callbacks->undefined_symbol) + (flaginfo->info, name, input_bfd, input_section, + r_addr, TRUE); } r = MY_final_link_relocate (howto, @@ -3497,11 +3497,9 @@ pdp11_aout_link_input_section (struct aout_final_link_info *flaginfo, s = aout_reloc_type_to_section (input_bfd, r_type); name = bfd_section_name (input_bfd, s); } - if (! ((*flaginfo->info->callbacks->reloc_overflow) - (flaginfo->info, (h ? &h->root : NULL), name, - howto->name, (bfd_vma) 0, input_bfd, - input_section, r_addr))) - return FALSE; + (*flaginfo->info->callbacks->reloc_overflow) + (flaginfo->info, (h ? &h->root : NULL), name, howto->name, + (bfd_vma) 0, input_bfd, input_section, r_addr); } break; } @@ -3561,7 +3559,7 @@ aout_link_input_section (struct aout_final_link_info *flaginfo, /* If we are producing relocatable output, the relocs were modified, and we now write them out. */ - if (flaginfo->info->relocatable && rel_size > 0) + if (bfd_link_relocatable (flaginfo->info) && rel_size > 0) { if (bfd_seek (flaginfo->output_bfd, *reloff_ptr, SEEK_SET) != 0) return FALSE; @@ -3639,7 +3637,7 @@ aout_link_input_bfd (struct aout_final_link_info *flaginfo, bfd *input_bfd) /* Do the final link step. This is called on the output BFD. The INFO structure should point to a list of BFDs linked through the - link_next field which can be used to find each BFD which takes part + link.next field which can be used to find each BFD which takes part in the output. Also, each section in ABFD should point to a list of bfd_link_order structures which list all the input sections for the output section. */ @@ -3656,13 +3654,11 @@ NAME (aout, final_link) (bfd *abfd, bfd_size_type max_contents_size; bfd_size_type max_relocs_size; bfd_size_type max_sym_count; - bfd_size_type text_size; - file_ptr text_end; struct bfd_link_order *p; asection *o; bfd_boolean have_link_order_relocs; - if (info->shared) + if (bfd_link_pic (info)) abfd->flags |= DYNAMIC; aout_info.info = info; @@ -3686,11 +3682,11 @@ NAME (aout, final_link) (bfd *abfd, max_contents_size = 0; max_relocs_size = 0; max_sym_count = 0; - for (sub = info->input_bfds; sub != NULL; sub = sub->link_next) + for (sub = info->input_bfds; sub != NULL; sub = sub->link.next) { size_t sz; - if (info->relocatable) + if (bfd_link_relocatable (info)) { if (bfd_get_flavour (sub) == bfd_target_aout_flavour) { @@ -3734,7 +3730,7 @@ NAME (aout, final_link) (bfd *abfd, } } - if (info->relocatable) + if (bfd_link_relocatable (info)) { if (obj_textsec (abfd) != NULL) trsize += (_bfd_count_link_order_relocs (obj_textsec (abfd) @@ -3753,7 +3749,7 @@ NAME (aout, final_link) (bfd *abfd, /* Adjust the section sizes and vmas according to the magic number. This sets a_text, a_data and a_bss in the exec_hdr and sets the filepos for each section. */ - if (! NAME (aout, adjust_sizes_and_vmas) (abfd, &text_size, &text_end)) + if (! NAME (aout, adjust_sizes_and_vmas) (abfd)) goto error_return; /* The relocation and symbol file positions differ among a.out @@ -3824,7 +3820,7 @@ NAME (aout, final_link) (bfd *abfd, We use the output_has_begun field of the input BFDs to see whether we have already handled it. */ - for (sub = info->input_bfds; sub != NULL; sub = sub->link_next) + for (sub = info->input_bfds; sub != NULL; sub = sub->link.next) sub->output_has_begun = FALSE; /* Mark all sections which are to be included in the link. This