From 4359a7ef33670fb3637b9962d35a35774aa6845f Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Sat, 19 Mar 1994 05:06:54 +0000 Subject: [PATCH] * som.h (struct som_exec_data): New structure to hold exec info that must be preserved when running objcopy/strip. (struct somdata): Add new "exec_data" field and accessor macro. Add some comments on how the various fields are used. (som_section_data_struct): Make is_space and is_subspace bitfields. Delete unused subspace_index. All references now use the target_index field within the section structure itself. * som.c (make_unique_section): Delete unused declaration. (som_bfd_copy_private_bfd_data): New function. (som_object_setup): Allocate space for and save exec information that needs to be copied during objcopy/strip. (som_mkobject): Do not allocate space for a file header here. It is not used when only reading SOM objects. (som_prep_headers): Allocate space for and attach a file header to the output bfd. For executables, use the saved system_id value rather than trying to guess the right value. Do not abort wwhen setting file_hdr->entry* for executables. (som_begin_writing): For executables, set the exec_entry and exec_flags fields. (som_copy_private_backend_section_data): Always return a value. --- bfd/ChangeLog | 22 +++++++++++++ bfd/som.c | 103 ++++++++++++++++++++++++++++++++++++++-------------------- bfd/som.h | 40 +++++++++++++++++++---- 3 files changed, 124 insertions(+), 41 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 6bd7b50..e30a927 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,27 @@ Fri Mar 18 18:13:49 1994 Jeffrey A. Law (law@snake.cs.utah.edu) + * som.h (struct som_exec_data): New structure to hold exec + info that must be preserved when running objcopy/strip. + (struct somdata): Add new "exec_data" field and accessor + macro. Add some comments on how the various fields are used. + (som_section_data_struct): Make is_space and is_subspace bitfields. + Delete unused subspace_index. All references now use the + target_index field within the section structure itself. + + * som.c (make_unique_section): Delete unused declaration. + (som_bfd_copy_private_bfd_data): New function. + (som_object_setup): Allocate space for and save exec information + that needs to be copied during objcopy/strip. + (som_mkobject): Do not allocate space for a file header here. + It is not used when only reading SOM objects. + (som_prep_headers): Allocate space for and attach a file header + to the output bfd. For executables, use the saved system_id + value rather than trying to guess the right value. Do not abort + wwhen setting file_hdr->entry* for executables. + (som_begin_writing): For executables, set the exec_entry and + exec_flags fields. + (som_copy_private_backend_section_data): Always return a value. + * libhppa.h (PA_PAGESIZE): Define. * som.c (SOM_ALIGN): Define. diff --git a/bfd/som.c b/bfd/som.c index 630f7c8..e7d0092 100644 --- a/bfd/som.c +++ b/bfd/som.c @@ -133,7 +133,6 @@ static boolean som_mkobject PARAMS ((bfd *)); static bfd_target * som_object_setup PARAMS ((bfd *, struct header *, struct som_exec_auxhdr *)); -static asection * make_unique_section PARAMS ((bfd *, CONST char *, int)); static boolean setup_sections PARAMS ((bfd *, struct header *)); static bfd_target * som_object_p PARAMS ((bfd *)); static boolean som_write_object_contents PARAMS ((bfd *)); @@ -155,6 +154,7 @@ static void som_print_symbol PARAMS ((bfd *, PTR, static boolean som_new_section_hook PARAMS ((bfd *, asection *)); static boolean som_bfd_copy_private_section_data PARAMS ((bfd *, asection *, bfd *, asection *)); +static boolean som_bfd_copy_private_bfd_data PARAMS ((bfd *, bfd *)); static boolean som_bfd_is_local_label PARAMS ((bfd *, asymbol *)); static boolean som_set_section_contents PARAMS ((bfd *, sec_ptr, PTR, file_ptr, bfd_size_type)); @@ -962,7 +962,6 @@ static reloc_howto_type som_hppa_howto_table[] = {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"}, {R_RESERVED, 0, 0, 32, false, 0, 0, hppa_som_reloc, "R_RESERVED"}}; - /* Initialize the SOM relocation queue. By definition the queue holds the last four multibyte fixups. */ @@ -1592,6 +1591,16 @@ som_object_setup (abfd, file_hdrp, aux_hdrp) obj_som_str_filepos (abfd) = file_hdrp->symbol_strings_location; obj_som_reloc_filepos (abfd) = file_hdrp->fixup_request_location; + obj_som_exec_data (abfd) = (struct som_exec_data *) + bfd_zalloc (abfd, sizeof (struct som_exec_data )); + if (obj_som_exec_data (abfd) == NULL) + { + bfd_set_error (bfd_error_no_memory); + return NULL; + } + + obj_som_exec_data (abfd)->system_id = file_hdrp->system_id; + obj_som_exec_data (abfd)->exec_flags = aux_hdrp->exec_flags; return abfd->xvec; } @@ -1717,8 +1726,7 @@ setup_sections (abfd, file_hdr) subspace.quadrant); /* Keep an easy mapping between subspaces and sections. */ - som_section_data (subspace_asect)->subspace_index - = total_subspaces++; + subspace_asect->target_index = total_subspaces++; /* Set SEC_READONLY and SEC_CODE/SEC_DATA as specified by the access_control_bits in the subspace header. */ @@ -1911,14 +1919,6 @@ som_mkobject (abfd) bfd_set_error (bfd_error_no_memory); return false; } - obj_som_file_hdr (abfd) - = (struct header *) bfd_zalloc (abfd, sizeof (struct header)); - if (obj_som_file_hdr (abfd) == NULL) - - { - bfd_set_error (bfd_error_no_memory); - return false; - } return true; } @@ -1930,12 +1930,25 @@ static boolean som_prep_headers (abfd) bfd *abfd; { - struct header *file_hdr = obj_som_file_hdr (abfd); + struct header *file_hdr; asection *section; + /* Make and attach a file header to the BFD. */ + file_hdr = (struct header *) bfd_zalloc (abfd, sizeof (struct header)); + if (file_hdr == NULL) + + { + bfd_set_error (bfd_error_no_memory); + return false; + } + obj_som_file_hdr (abfd) = file_hdr; + /* FIXME. This should really be conditional based on whether or not PA1.1 instructions/registers have been used. */ - file_hdr->system_id = CPU_PA_RISC1_0; + if (abfd->flags & EXEC_P) + file_hdr->system_id = obj_som_exec_data (abfd)->system_id; + else + file_hdr->system_id = CPU_PA_RISC1_0; if (abfd->flags & EXEC_P) { @@ -1958,15 +1971,9 @@ som_prep_headers (abfd) file_hdr->file_time.secs = 0; file_hdr->file_time.nanosecs = 0; - if (abfd->flags & EXEC_P) - abort (); - else - { - file_hdr->entry_space = 0; - file_hdr->entry_subspace = 0; - file_hdr->entry_offset = 0; - } - + file_hdr->entry_space = 0; + file_hdr->entry_subspace = 0; + file_hdr->entry_offset = 0; file_hdr->presumed_dp = 0; /* Now iterate over the sections translating information from @@ -2905,7 +2912,7 @@ som_begin_writing (abfd) first_subspace = 0; } - som_section_data (subsection)->subspace_index = total_subspaces++; + subsection->target_index = total_subspaces++; /* This is real data to be loaded from the file. */ if (subsection->flags & SEC_LOAD) { @@ -2968,7 +2975,7 @@ som_begin_writing (abfd) || (subsection->flags & SEC_ALLOC) != 0) continue; - som_section_data (subsection)->subspace_index = total_subspaces++; + subsection->target_index = total_subspaces; /* This is real data to be loaded from the file. */ if ((subsection->flags & SEC_LOAD) == 0) { @@ -3021,6 +3028,9 @@ som_begin_writing (abfd) { long tmp; + exec_header.exec_entry = bfd_get_start_address (abfd); + exec_header.exec_flags = obj_som_exec_data (abfd)->exec_flags; + /* Oh joys. Ram some of the BSS data into the DATA section to be compatable with how the hp linker makes objects (saves memory space). */ @@ -3331,7 +3341,7 @@ som_bfd_derive_misc_symbol_info (abfd, sym, info) /* For all other symbols, the symbol_info field contains the subspace index of the space this symbol is contained in. */ else - info->symbol_info = som_section_data (sym->section)->subspace_index; + info->symbol_info = sym->section->target_index; /* Set the symbol's value. */ info->symbol_value = sym->value + sym->section->vma; @@ -3495,7 +3505,7 @@ som_section_from_subspace_index (abfd, index) asection *section; for (section = abfd->sections; section != NULL; section = section->next) - if (som_section_data (section)->subspace_index == index) + if (section->target_index == index) return section; /* Should never happen. */ @@ -4148,10 +4158,6 @@ som_new_section_hook (abfd, newsect) } newsect->alignment_power = 3; - /* Initialize the subspace_index field to -1 so that it does - not match a subspace with an index of 0. */ - som_section_data (newsect)->subspace_index = -1; - /* We allow more than three sections internally */ return true; } @@ -4177,8 +4183,38 @@ som_bfd_copy_private_section_data (ibfd, isection, obfd, osection) if (som_section_data (osection)->containing_space) som_section_data (osection)->containing_space = som_section_data (osection)->containing_space->output_section; + + return true; } - + +/* Copy any private info we understand from the input bfd + to the output bfd. */ + +static boolean +som_bfd_copy_private_bfd_data (ibfd, obfd) + bfd *ibfd, *obfd; +{ + /* One day we may try to grok other private data. */ + if (ibfd->xvec->flavour != bfd_target_som_flavour + || obfd->xvec->flavour != bfd_target_som_flavour) + return false; + + /* Allocate some memory to hold the data we need. */ + obj_som_exec_data (obfd) = (struct som_exec_data *) + bfd_zalloc (obfd, sizeof (struct som_exec_data)); + if (obj_som_exec_data (obfd) == NULL) + { + bfd_set_error (bfd_error_no_memory); + return false; + } + + /* Now copy the data. */ + memcpy (obj_som_exec_data (obfd), obj_som_exec_data (ibfd), + sizeof (struct som_exec_data)); + + return true; +} + /* Set backend info for sections which can not be described in the BFD data structures. */ @@ -5373,9 +5409,6 @@ som_write_armap (abfd) #define som_core_file_failing_signal _bfd_dummy_core_file_failing_signal #define som_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p -#define som_bfd_copy_private_bfd_data \ - ((boolean (*) PARAMS ((bfd *, bfd *))) bfd_true) - bfd_target som_vec = { "som", /* name */ diff --git a/bfd/som.h b/bfd/som.h index 38c04bc..5d52c7b 100644 --- a/bfd/som.h +++ b/bfd/som.h @@ -1,5 +1,5 @@ /* HP PA-RISC SOM object file format: definitions internal to BFD. - Copyright (C) 1990-1991 Free Software Foundation, Inc. + Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc. Contributed by the Center for Software Science at the University of Utah (pa-gdb-bugs@cs.utah.edu). @@ -76,21 +76,49 @@ typedef struct som_symbol } som_symbol_type; +/* A structure containing all the magic information stored in a BFD's + private data which needs to be copied during an objcopy/strip run. */ +struct som_exec_data + { + /* Sort-of a magic number. BSD uses it to distinguish between + native executables and hpux executables. */ + short system_id; + + /* Magic exec flags. These control things like whether or not + null pointer dereferencing is allowed and the like. */ + long exec_flags; + + /* Add more stuff here as needed. Good examples of information + we might want to pass would be presumed_dp, entry_* and maybe + others from the file header. */ + }; + struct somdata { + /* All the magic information about an executable which lives + in the private BFD structure and needs to be copied from + the input bfd to the output bfd during a objcopy/strip. */ + struct som_exec_data *exec_data; + + /* These three fields are only used when writing files and are + generated from scratch. They need not be copied for objcopy + or strip to work. */ struct header *file_hdr; struct copyright_aux_hdr *copyright_aux_hdr; struct user_string_aux_hdr *version_aux_hdr; + + /* Pointers to a saved copy of the symbol and string tables. These + need not be copied for objcopy or strip to work. */ som_symbol_type *symtab; char *stringtab; /* We remember these offsets so that after check_file_format, we have - no dependencies on the particular format of the exec_hdr. */ + no dependencies on the particular format of the exec_hdr. + These offsets need not be copied for objcopy or strip to work. */ file_ptr sym_filepos; file_ptr str_filepos; file_ptr reloc_filepos; - unsigned stringtab_size; }; @@ -113,17 +141,17 @@ struct som_data_struct struct som_section_data_struct { + unsigned int is_space : 1; + unsigned int is_subspace : 1; unsigned int reloc_size; char *reloc_stream; - unsigned int subspace_index; asection *containing_space; - int is_space; struct space_dictionary_record space_dict; - int is_subspace; struct subspace_dictionary_record subspace_dict; }; #define somdata(bfd) ((bfd)->tdata.som_data->a) +#define obj_som_exec_data(bfd) (somdata(bfd).exec_data) #define obj_som_file_hdr(bfd) (somdata(bfd).file_hdr) #define obj_som_copyright_hdr(bfd) (somdata(bfd).copyright_aux_hdr) #define obj_som_version_hdr(bfd) (somdata(bfd).version_aux_hdr) -- 2.7.4