From: Steve Chamberlain Date: Fri, 24 Jan 1992 22:44:51 +0000 (+0000) Subject: Uses the new small reloc type now. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e98e6ec1;p=binutils-gdb.git Uses the new small reloc type now. Currently self hosts on sun4 and sun3 --- diff --git a/bfd/.Sanitize b/bfd/.Sanitize index 93ecce72106..2935b0f1756 100644 --- a/bfd/.Sanitize +++ b/bfd/.Sanitize @@ -88,6 +88,7 @@ newsos3.c oasys.c opncls.c reloc.c +seclet.c section.c srec.c stab-syms.c @@ -120,7 +121,12 @@ echo Done in `pwd`. # # # $Log$ -# Revision 1.34 1991/12/18 23:01:48 bothner +# Revision 1.35 1992/01/24 22:42:49 sac +# Uses the new small reloc type now. +# +# Currently self hosts on sun4 and sun3 +# +# Revision 1.34 1991/12/18 23:01:48 bothner # Use aout-target.h more extensively. # Replace Berkeley functions (e.g. bcopy) with ANSI ones (e.g. memcpy). # Other improvements (see ChangeLog). diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 72d3c87e906..2f73749756b 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,15 @@ +Fri Jan 24 14:40:17 1992 Steve Chamberlain (sac at rtl.cygnus.com) + + * everything: now modified to use smaller reloc type. Self hosts + on sun3 & sun4. + +Sat Jan 18 17:00:16 1992 Fred Fish (fnf at cygnus.com) + + * config/mh-stratus, config/mt-i860-elf, hosts/h-stratus: + New files for stratus. + + * configure.in: Add configuration fragments for stratus. + Wed Jan 15 10:02:43 1992 Fred Fish (fnf at cygnus.com) * aoutx.h (NAME(aout,find_nearest_line)): Declare various filename diff --git a/bfd/aout-target.h b/bfd/aout-target.h new file mode 100644 index 00000000000..868a9e605a6 --- /dev/null +++ b/bfd/aout-target.h @@ -0,0 +1,332 @@ +/* Define a target vector for a variant of a.out. + Copyright (C) 1990-1991 Free Software Foundation, Inc. + +This file is part of BFD, the Binary File Descriptor library. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +/* Set parameters about this a.out file that are machine-dependent. + This routine is called from some_aout_object_p just before it returns. */ +static bfd_target * +DEFUN(MY(callback),(abfd), + bfd *abfd) +{ + struct internal_exec *execp = exec_hdr (abfd); + +/* Calculate the file positions of the parts of a newly read aout header */ + obj_textsec (abfd)->_raw_size = N_TXTSIZE(*execp); + + /* 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); + + /* The file offsets of the sections */ + 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); + + /* The file offsets of the string table and symbol table. */ + obj_sym_filepos (abfd) = N_SYMOFF (*execp); + obj_str_filepos (abfd) = N_STROFF (*execp); + + /* Determine the architecture and machine type of the object file. + */ +#ifdef SET_ARCH_MACH + SET_ARCH_MACH(abfd, *execp); +#else + bfd_default_set_arch_mach(abfd, DEFAULT_ARCH, 0); +#endif + + adata(abfd).page_size = PAGE_SIZE; +#ifdef SEGMENT_SIZE + adata(abfd).segment_size = SEGMENT_SIZE; +#else + adata(abfd).segment_size = PAGE_SIZE; +#endif + adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE; + + return abfd->xvec; +} + +#ifndef MY_object_p +/* Finish up the reading of an a.out file header */ + +static bfd_target * +DEFUN(MY(object_p),(abfd), + bfd *abfd) +{ + struct external_exec exec_bytes; /* Raw exec header from file */ + struct internal_exec exec; /* Cleaned-up exec header */ + bfd_target *target; + + if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd) + != EXEC_BYTES_SIZE) { + bfd_error = wrong_format; + return 0; + } + + exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info); + + if (N_BADMAG (exec)) return 0; + + NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec); + target = NAME(aout,some_aout_object_p) (abfd, &exec, MY(callback)); + +#ifdef ENTRY_CAN_BE_ZERO + /* The NEWSOS3 entry-point is/was 0, which (amongst other lossage) + * means that it isn't obvious if EXEC_P should be set. + * All of the following must be true for an executable: + * There must be no relocations, the bfd can be neither an + * archive nor an archive element, and the file must be executable. */ + + if (exec.a_trsize + exec.a_drsize == 0 + && bfd_get_format(abfd) == bfd_object && abfd->my_archive == NULL) + { + struct stat buf; +#ifndef S_IXUSR +#define S_IXUSR 0100 /* Execute by owner. */ +#endif + if (stat(abfd->filename, &buf) == 0 && (buf.st_mode & S_IXUSR)) + abfd->flags |= EXEC_P; + } +#endif /* ENTRY_CAN_BE_ZERO */ + + return target; +} +#define MY_object_p MY(object_p) +#endif + + +#ifndef MY_mkobject +static boolean +DEFUN(MY(mkobject),(abfd), + bfd *abfd) +{ + if (NAME(aout,mkobject)(abfd) == false) + return false; + adata(abfd).page_size = PAGE_SIZE; +#ifdef SEGMENT_SIZE + adata(abfd).segment_size = SEGMENT_SIZE; +#else + adata(abfd).segment_size = PAGE_SIZE; +#endif + adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE; + return true; +} +#define MY_mkobject MY(mkobject) +#endif + +/* Write an object file. + Section contents have already been written. We write the + file header, symbols, and relocation. */ + +#ifndef MY_write_object_contents +static boolean +DEFUN(MY(write_object_contents),(abfd), + bfd *abfd) +{ + bfd_size_type data_pad = 0; + struct external_exec exec_bytes; + struct internal_exec *execp = exec_hdr (abfd); + + WRITE_HEADERS(abfd, execp); + return true; +} +#define MY_write_object_contents MY(write_object_contents) +#endif + +/* We assume BFD generic archive files. */ +#ifndef MY_openr_next_archived_file +#define MY_openr_next_archived_file bfd_generic_openr_next_archived_file +#endif +#ifndef MY_generic_stat_arch_elt +#define MY_generic_stat_arch_elt bfd_generic_stat_arch_elt +#endif +#ifndef MY_slurp_armap +#define MY_slurp_armap bfd_slurp_bsd_armap +#endif +#ifndef MY_slurp_extended_name_table +#define MY_slurp_extended_name_table bfd_true +#endif +#ifndef MY_write_armap +#define MY_write_armap bsd_write_armap +#endif +#ifndef MY_truncate_arname +#define MY_truncate_arname bfd_bsd_truncate_arname +#endif + +/* No core file defined here -- configure in trad-core.c separately. */ +#ifndef MY_core_file_failing_command +#define MY_core_file_failing_command _bfd_dummy_core_file_failing_command +#endif +#ifndef MY_core_file_failing_signal +#define MY_core_file_failing_signal _bfd_dummy_core_file_failing_signal +#endif +#ifndef MY_core_file_matches_executable_p +#define MY_core_file_matches_executable_p \ + _bfd_dummy_core_file_matches_executable_p +#endif +#ifndef MY_core_file_p +#define MY_core_file_p _bfd_dummy_target +#endif + +#ifndef MY_bfd_debug_info_start +#define MY_bfd_debug_info_start bfd_void +#endif +#ifndef MY_bfd_debug_info_end +#define MY_bfd_debug_info_end bfd_void +#endif +#ifndef MY_bfd_debug_info_accumulate +#define MY_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void +#endif + +#ifndef MY_core_file_failing_command +#define MY_core_file_failing_command NAME(aout,core_file_failing_command) +#endif +#ifndef MY_core_file_failing_signal +#define MY_core_file_failing_signal NAME(aout,core_file_failing_signal) +#endif +#ifndef MY_core_file_matches_executable_p +#define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p) +#endif +#ifndef MY_slurp_armap +#define MY_slurp_armap NAME(aout,slurp_armap) +#endif +#ifndef MY_slurp_extended_name_table +#define MY_slurp_extended_name_table NAME(aout,slurp_extended_name_table) +#endif +#ifndef MY_truncate_arname +#define MY_truncate_arname NAME(aout,truncate_arname) +#endif +#ifndef MY_write_armap +#define MY_write_armap NAME(aout,write_armap) +#endif +#ifndef MY_close_and_cleanup +#define MY_close_and_cleanup NAME(aout,close_and_cleanup) +#endif +#ifndef MY_set_section_contents +#define MY_set_section_contents NAME(aout,set_section_contents) +#endif +#ifndef MY_get_section_contents +#define MY_get_section_contents NAME(aout,get_section_contents) +#endif +#ifndef MY_new_section_hook +#define MY_new_section_hook NAME(aout,new_section_hook) +#endif +#ifndef MY_get_symtab_upper_bound +#define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound) +#endif +#ifndef MY_get_symtab +#define MY_get_symtab NAME(aout,get_symtab) +#endif +#ifndef MY_get_reloc_upper_bound +#define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound) +#endif +#ifndef MY_canonicalize_reloc +#define MY_canonicalize_reloc NAME(aout,canonicalize_reloc) +#endif +#ifndef MY_make_empty_symbol +#define MY_make_empty_symbol NAME(aout,make_empty_symbol) +#endif +#ifndef MY_print_symbol +#define MY_print_symbol NAME(aout,print_symbol) +#endif +#ifndef MY_get_lineno +#define MY_get_lineno NAME(aout,get_lineno) +#endif +#ifndef MY_set_arch_mach +#define MY_set_arch_mach NAME(aout,set_arch_mach) +#endif +#ifndef MY_openr_next_archived_file +#define MY_openr_next_archived_file NAME(aout,openr_next_archived_file) +#endif +#ifndef MY_find_nearest_line +#define MY_find_nearest_line NAME(aout,find_nearest_line) +#endif +#ifndef MY_generic_stat_arch_elt +#define MY_generic_stat_arch_elt NAME(aout,generic_stat_arch_elt) +#endif +#ifndef MY_sizeof_headers +#define MY_sizeof_headers NAME(aout,sizeof_headers) +#endif +#ifndef MY_bfd_debug_info_start +#define MY_bfd_debug_info_start NAME(aout,bfd_debug_info_start) +#endif +#ifndef MY_bfd_debug_info_end +#define MY_bfd_debug_info_end NAME(aout,bfd_debug_info_end) +#endif +#ifndef MY_bfd_debug_info_accumulat +#define MY_bfd_debug_info_accumulat NAME(aout,bfd_debug_info_accumulat) +#endif + +bfd_target MY(vec) = +{ + TARGETNAME, /* name */ + bfd_target_aout_flavour, + true, /* target byte order */ + true, /* target headers byte order */ + (HAS_RELOC | EXEC_P | /* object flags */ + HAS_LINENO | HAS_DEBUG | + HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED), + (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ + ' ', /* ar_pad_char */ + 16, /* ar_max_namelen */ + 1, /* minimum alignment */ +#ifdef TARGET_IS_BIG_ENDIAN_P + _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */ + _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */ +#else + _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */ + _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */ +#endif + {_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}, + + MY_core_file_failing_command, + MY_core_file_failing_signal, + MY_core_file_matches_executable_p, + MY_slurp_armap, + MY_slurp_extended_name_table, + MY_truncate_arname, + MY_write_armap, + MY_close_and_cleanup, + MY_set_section_contents, + MY_get_section_contents, + MY_new_section_hook, + MY_get_symtab_upper_bound, + MY_get_symtab, + MY_get_reloc_upper_bound, + MY_canonicalize_reloc, + MY_make_empty_symbol, + MY_print_symbol, + MY_get_lineno, + MY_set_arch_mach, + MY_openr_next_archived_file, + MY_find_nearest_line, + MY_generic_stat_arch_elt, + MY_sizeof_headers, + MY_bfd_debug_info_start, + MY_bfd_debug_info_end, + MY_bfd_debug_info_accumulate, + bfd_generic_get_relocated_section_contents +}; diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h index a0915df9b52..1d299adad17 100644 --- a/bfd/bfd-in.h +++ b/bfd/bfd-in.h @@ -80,8 +80,6 @@ typedef HOST_64_BIT symvalue; typedef HOST_64_BIT bfd_64_type; #define fprintf_vma(s,x) \ fprintf(s,"%08x%08x", uint64_typeHIGH(x), uint64_typeLOW(x)) -#define printf_vma(x) \ - printf( "%08x%08x", uint64_typeHIGH(x), uint64_typeLOW(x)) #else typedef struct {int a,b;} bfd_64_type; typedef unsigned long rawdata_offset; @@ -91,9 +89,9 @@ typedef unsigned long bfd_word; typedef unsigned long bfd_size; typedef unsigned long symvalue; typedef unsigned long bfd_size_type; -#define printf_vma(x) printf( "%08lx", x) #define fprintf_vma(s,x) fprintf(s, "%08lx", x) #endif +#define printf_vma(x) fprintf_vma(stdout,x) typedef unsigned int flagword; /* 32 bits of flags */ @@ -183,7 +181,7 @@ typedef struct lineno_cache_entry { typedef struct sec *sec_ptr; #define bfd_section_name(bfd, ptr) ((ptr)->name) -#define bfd_section_size(bfd, ptr) ((ptr)->size) +#define bfd_section_size(bfd, ptr) (bfd_get_section_size_before_reloc(ptr)) #define bfd_section_vma(bfd, ptr) ((ptr)->vma) #define bfd_section_alignment(bfd, ptr) ((ptr)->alignment_power) #define bfd_get_section_flags(bfd, ptr) ((ptr)->flags) @@ -209,10 +207,23 @@ typedef enum bfd_error { invalid_error_code} bfd_ec; extern bfd_ec bfd_error; +struct reloc_cache_entry; +struct bfd_seclet_struct ; + typedef struct bfd_error_vector { PROTO(void,(* nonrepresentable_section ),(CONST bfd *CONST abfd, CONST char *CONST name)); + PROTO(void,(* undefined_symbol),(CONST struct reloc_cache_entry *rel, + CONST struct bfd_seclet_struct *sec + )); + PROTO(void, (* reloc_value_truncated),(CONST struct + reloc_cache_entry *rel, + struct bfd_seclet_struct *sec)); + + PROTO(void, (* reloc_dangerous),(CONST struct reloc_cache_entry *rel, + CONST struct bfd_seclet_struct *sec)); + } bfd_error_vector_type; PROTO (char *, bfd_errmsg, ()); @@ -223,7 +234,8 @@ typedef enum bfd_print_symbol { bfd_print_symbol_name, bfd_print_symbol_more, - bfd_print_symbol_all + bfd_print_symbol_all, + bfd_print_symbol_nm, /* Pretty format suitable for nm program. */ } bfd_print_symbol_type; @@ -268,7 +280,8 @@ CAT(NAME,_generic_stat_arch_elt),\ CAT(NAME,_sizeof_headers),\ CAT(NAME,_bfd_debug_info_start),\ CAT(NAME,_bfd_debug_info_end),\ -CAT(NAME,_bfd_debug_info_accumulate) +CAT(NAME,_bfd_debug_info_accumulate),\ +CAT(NAME,_bfd_get_relocated_section_contents) #define COFF_SWAP_TABLE \ coff_swap_aux_in, coff_swap_sym_in, coff_swap_lineno_in, \ @@ -294,7 +307,7 @@ extern CONST short _bfd_host_big_endian; #define bfd_get_file_flags(abfd) ((abfd)->flags) #define bfd_applicable_file_flags(abfd) ((abfd)->xvec->object_flags) #define bfd_applicable_section_flags(abfd) ((abfd)->xvec->section_flags) -#define bfd_my_archive(abfd) ((abfd)->my_archive); +#define bfd_my_archive(abfd) ((abfd)->my_archive) #define bfd_has_map(abfd) ((abfd)->has_armap) #define bfd_header_twiddle_required(abfd) \ ((((abfd)->xvec->header_byteorder_big_p) \ @@ -318,38 +331,13 @@ extern CONST short _bfd_host_big_endian; -/*THE FOLLOWING IS EXTRACTED FROM THE SOURCE */ - - -/*:init.c*/ - -/*:opncls.c*/ - - -/*:libbfd.c*/ - -/*:section.c*/ +/* ANd more from the source */ -/*:archures.c*/ -/*:reloc.c*/ - -/*:syms.c*/ - -/*:bfd.c*/ - -/*:archive.c*/ - -/*:core.c*/ - -/*:targets.c*/ - -/*:format.c*/ - -#endif + diff --git a/bfd/bfd.c b/bfd/bfd.c index d47a528030d..7d919da7c81 100644 --- a/bfd/bfd.c +++ b/bfd/bfd.c @@ -24,7 +24,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ SECTION <> -DESCRIPTION A BFD is has type <>; objects of this type are the cornerstone of any application using <>. References though the BFD and to data in the BFD give the entire BFD @@ -34,131 +33,142 @@ DESCRIPTION contains he major data about the file, and contains pointers to the rest of the data. +CODE_FRAGMENT +. .struct _bfd .{ - The filename the application opened the BFD with. - -. CONST char *filename; - - A pointer to the target jump table. - -. struct bfd_target *xvec; - - To avoid dragging too many header files into every file that - includes @file{bfd.h}, IOSTREAM has been declared as a "char - *", and MTIME as a "long". Their correct types, to which they - are cast when used, are "FILE *" and "time_t". The iostream - is the result of an fopen on the filename. - -. char *iostream; - -Is the file being cached @xref{File Caching}. - -. boolean cacheable; - - Marks whether there was a default target specified when the - BFD was opened. This is used to select what matching algorithm - to use to chose the back end. - -. boolean target_defaulted; - - The caching routines use these to maintain a - least-recently-used list of BFDs (@pxref{File Caching}). - -. struct _bfd *lru_prev, *lru_next; - - When a file is closed by the caching routines, BFD retains - state information on the file here: - -. file_ptr where; - - and here: - -. boolean opened_once; - -. boolean mtime_set; - -File modified time - -. long mtime; - - Reserved for an unimplemented file locking extension. - -. int ifd; - - The format which belongs to the BFD. - -. bfd_format format; - - The direction the BFD was opened with - -. enum bfd_direction {no_direction = 0, -. read_direction = 1, -. write_direction = 2, -. both_direction = 3} direction; - - Format_specific flags - -. flagword flags; - - Currently my_archive is tested before adding origin to - anything. I believe that this can become always an add of - origin, with origin set to 0 for non archive files. - -. file_ptr origin; - - Remember when output has begun, to stop strange things happening. - -. boolean output_has_begun; - - Pointer to linked list of sections - -. struct sec *sections; - - The number of sections - -. unsigned int section_count; - - Stuff only useful for object files: - The start address. - -. bfd_vma start_address; - - Used for input and output - -. unsigned int symcount; - - Symbol table for output BFD - -. struct symbol_cache_entry **outsymbols; - - Pointer to structure which contains architecture information - -. struct bfd_arch_info *arch_info; - - Stuff only useful for archives: - -. PTR arelt_data; -. struct _bfd *my_archive; -. struct _bfd *next; -. struct _bfd *archive_head; -. boolean has_armap; - - Used by the back end to hold private data. - -. PTR tdata; - - Used by the application to hold private data - -. PTR usrdata; - - Where all the allocated stuff under this BFD goes - (@pxref{Memory Usage}). - -. struct obstack memory; +. {* The filename the application opened the BFD with. *} +. CONST char *filename; +. +. {* A pointer to the target jump table. *} +. struct bfd_target *xvec; +. +. {* To avoid dragging too many header files into every file that +. includes @file{bfd.h}, IOSTREAM has been declared as a "char +. *", and MTIME as a "long". Their correct types, to which they +. are cast when used, are "FILE *" and "time_t". The iostream +. is the result of an fopen on the filename. *} +. char *iostream; +. +. {* Is the file being cached *} +. +. boolean cacheable; +. +. {* Marks whether there was a default target specified when the +. BFD was opened. This is used to select what matching algorithm +. to use to chose the back end. *} +. +. boolean target_defaulted; +. +. {* The caching routines use these to maintain a +. least-recently-used list of BFDs *} +. +. struct _bfd *lru_prev, *lru_next; +. +. {* When a file is closed by the caching routines, BFD retains +. state information on the file here: +. *} +. +. file_ptr where; +. +. {* and here:*} +. +. boolean opened_once; +. +. {* Set if we have a locally maintained mtime value, rather than +. getting it from the file each time: *} +. +. boolean mtime_set; +. +. {* File modified time, if mtime_set is true: *} +. +. long mtime; +. +. {* Reserved for an unimplemented file locking extension.*} +. +. int ifd; +. +. {* The format which belongs to the BFD.*} +. +. bfd_format format; +. +. {* The direction the BFD was opened with*} +. +. enum bfd_direction {no_direction = 0, +. read_direction = 1, +. write_direction = 2, +. both_direction = 3} direction; +. +. {* Format_specific flags*} +. +. flagword flags; +. +. {* Currently my_archive is tested before adding origin to +. anything. I believe that this can become always an add of +. origin, with origin set to 0 for non archive files. *} +. +. file_ptr origin; +. +. {* Remember when output has begun, to stop strange things +. happening. *} +. boolean output_has_begun; +. +. {* Pointer to linked list of sections*} +. struct sec *sections; +. +. {* The number of sections *} +. unsigned int section_count; +. +. {* Stuff only useful for object files: +. The start address. *} +. bfd_vma start_address; +. +. {* Used for input and output*} +. unsigned int symcount; +. +. {* Symbol table for output BFD*} +. struct symbol_cache_entry **outsymbols; +. +. {* Pointer to structure which contains architecture information*} +. struct bfd_arch_info *arch_info; +. +. {* Stuff only useful for archives:*} +. PTR arelt_data; +. struct _bfd *my_archive; +. struct _bfd *next; +. struct _bfd *archive_head; +. boolean has_armap; +. +. {* Used by the back end to hold private data. *} +. +. union +. { +. struct aout_data_struct *aout_data; +. struct artdata *aout_ar_data; +. struct _oasys_data *oasys_obj_data; +. struct _oasys_ar_data *oasys_ar_data; +. struct coff_tdata *coff_obj_data; +. struct ieee_data_struct *ieee_data; +. struct ieee_ar_data_struct *ieee_ar_data; +. struct srec_data_struct *srec_data; +. struct elf_obj_tdata_struct *elf_obj_data; +. struct elf_core_tdata_struct *elf_core_data; +. struct bout_data_struct *bout_data; +. struct sun_core_struct *sun_core_data; +. PTR any; +. } tdata; +. +. {* Used by the application to hold private data*} +. PTR usrdata; +. +. {* Where all the allocated stuff under this BFD goes *} +. struct obstack memory; +. +. asymbol **ld_symbols; .}; - +. */ + #include "bfd.h" #include "sysdep.h" #include "libbfd.h" @@ -215,11 +225,47 @@ DEFUN(bfd_nonrepresentable_section,(abfd, name), exit(1); } +static +void +DEFUN(bfd_undefined_symbol,(relent, seclet), + CONST arelent *relent AND + CONST struct bfd_seclet_struct *seclet) +{ + asymbol *symbol = *(relent->sym_ptr_ptr); + printf("bfd error relocating, symbol %s is undefined\n", + symbol->name); + exit(1); +} +static +void +DEFUN(bfd_reloc_value_truncated,(relent, seclet), + CONST arelent *relent AND + struct bfd_seclet_struct *seclet) +{ + asymbol *symbol = *(relent->sym_ptr_ptr); + printf("bfd error relocating, value truncated\n"); + exit(1); +} +static +void +DEFUN(bfd_reloc_is_dangerous,(relent, seclet), + CONST arelent *relent AND + CONST struct bfd_seclet_struct *seclet) +{ + asymbol *symbol = *(relent->sym_ptr_ptr); + printf("bfd error relocating, dangerous\n"); + exit(1); +} + bfd_error_vector_type bfd_error_vector = { - bfd_nonrepresentable_section + bfd_nonrepresentable_section , + bfd_undefined_symbol, + bfd_reloc_value_truncated, + bfd_reloc_is_dangerous, }; + char * bfd_errmsg (error_tag) bfd_ec error_tag; @@ -264,12 +310,26 @@ DEFUN(bfd_perror,(message), /** Symbols */ -/* returns the number of octets of storage required */ + +/* +FUNCTION + bfd_get_reloc_upper_bound + +SYNOPSIS + unsigned int bfd_get_reloc_upper_bound(bfd *abfd, asection *sect); + +DESCRIPTION + This function return the number of bytes required to store the + relocation information associated with section <> + attached to bfd <> + +*/ + unsigned int -get_reloc_upper_bound (abfd, asect) - bfd *abfd; - sec_ptr asect; +DEFUN(bfd_get_reloc_upper_bound,(abfd, asect), + bfd *abfd AND + sec_ptr asect) { if (abfd->format != bfd_object) { bfd_error = invalid_operation; @@ -279,6 +339,30 @@ get_reloc_upper_bound (abfd, asect) return BFD_SEND (abfd, _get_reloc_upper_bound, (abfd, asect)); } +/* +FUNCTION + bfd_canonicalize_reloc + +SYNOPSIS + unsigned int bfd_canonicalize_reloc + (bfd *abfd, + asection *sec, + arelent **loc, + asymbol **syms); + +DESCRIPTION + This function calls the back end associated with the open + <> and translates the external form of the relocation + information attached to <> into the internal canonical + form. The table is placed into memory at <>, which has + been preallocated, usually by a call to + <>. + + The <> table is also needed for horrible internal magic + reasons. + + +*/ unsigned int DEFUN(bfd_canonicalize_reloc,(abfd, asect, location, symbols), bfd *abfd AND @@ -287,13 +371,35 @@ DEFUN(bfd_canonicalize_reloc,(abfd, asect, location, symbols), asymbol **symbols) { if (abfd->format != bfd_object) { - bfd_error = invalid_operation; - return 0; - } - return BFD_SEND (abfd, _bfd_canonicalize_reloc, (abfd, asect, location, symbols)); + bfd_error = invalid_operation; + return 0; + } + return BFD_SEND (abfd, _bfd_canonicalize_reloc, + (abfd, asect, location, symbols)); } +/* +FUNCTION + bfd_set_file_flags + +SYNOPSIS + boolean bfd_set_file_flags(bfd *abfd, flagword flags); + +DESCRIPTION + This function attempts to set the flag word in the referenced + BFD structure to the value supplied. + + Possible errors are: + o wrong_format - The target bfd was not of object format. + o invalid_operation - The target bfd was open for reading. + o invalid_operation - + The flag word contained a bit which was not applicable to the + type of file. eg, an attempt was made to set the D_PAGED bit + on a bfd format which does not support demand paging + +*/ + boolean bfd_set_file_flags (abfd, flags) bfd *abfd; @@ -318,6 +424,19 @@ bfd_set_file_flags (abfd, flags) return true; } +/* +FUNCTION + bfd_set_reloc + +SYNOPSIS + void bfd_set_reloc + (bfd *abfd, asection *sec, arelent **rel, unsigned int count) + +DESCRIPTION + This function sets the relocation pointer and count within a + section to the supplied values. + +*/ void bfd_set_reloc (ignore_abfd, asect, location, count) @@ -344,7 +463,6 @@ FUNCTION bfd_set_start_address DESCRIPTION - Marks the entry point of an output BFD. RETURNS @@ -366,16 +484,15 @@ bfd_vma vma; /* FUNCTION - bfd_get_mtime - -DESCRIPTION - Return cached file modification time (e.g. as read from - archive header for archive members, or from file system if we - have been called before); else determine modify time, cache - it, and return it. + The bfd_get_mtime function SYNOPSIS long bfd_get_mtime(bfd *); + +DESCRIPTION + Return file modification time (as read from file system, or + from archive header for archive members). + */ long @@ -392,9 +509,8 @@ bfd_get_mtime (abfd) if (0 != fstat (fileno (fp), &buf)) return 0; - abfd->mtime_set = true; - abfd->mtime = buf.st_mtime; - return abfd->mtime; + abfd->mtime = buf.st_mtime; /* Save value in case anyone wants it */ + return buf.st_mtime; } /* @@ -407,8 +523,8 @@ DESCRIPTION .#define bfd_sizeof_headers(abfd, reloc) \ . BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc)) . -.#define bfd_find_nearest_line(abfd, section, symbols, offset, filename_ptr, func, line_ptr) \ -. BFD_SEND (abfd, _bfd_find_nearest_line, (abfd, section, symbols, offset, filename_ptr, func, line_ptr)) +.#define bfd_find_nearest_line(abfd, sec, syms, off, file, func, line) \ +. BFD_SEND (abfd, _bfd_find_nearest_line, (abfd, sec, syms, off, file, func, line)) . .#define bfd_debug_info_start(abfd) \ . BFD_SEND (abfd, _bfd_debug_info_start, (abfd)) @@ -455,6 +571,8 @@ DESCRIPTION .#define bfd_coff_swap_aouthdr_out(abfd, i,o) \ . BFD_SEND (abfd, _bfd_coff_swap_aouthdr_out, (abfd, i, o)) . +.#define bfd_get_relocated_section_contents(abfd, seclet) \ +. BFD_SEND (abfd, _bfd_get_relocated_section_contents, (abfd, seclet)) */ diff --git a/bfd/bout.c b/bfd/bout.c index 25609e28744..7656bb807e8 100644 --- a/bfd/bout.c +++ b/bfd/bout.c @@ -153,6 +153,10 @@ b_out_callback (abfd) /* The starting addresses of the sections. */ obj_textsec (abfd)->vma = execp->a_tload; obj_datasec (abfd)->vma = execp->a_dload; + + /* And reload the sizes, since the aout module zaps them */ + obj_textsec (abfd)->_raw_size = execp->a_text; + bss_start = execp->a_dload + execp->a_data; /* BSS = end of data section */ obj_bsssec (abfd)->vma = align_power (bss_start, execp->a_balign); @@ -164,14 +168,14 @@ b_out_callback (abfd) obj_textsec (abfd)->rel_filepos = N_TROFF(*execp); obj_datasec (abfd)->rel_filepos = N_DROFF(*execp); - adata(abfd)->page_size = 1; /* Not applicable. */ - adata(abfd)->segment_size = 1; /* Not applicable. */ - adata(abfd)->exec_bytes_size = EXEC_BYTES_SIZE; + adata(abfd).page_size = 1; /* Not applicable. */ + adata(abfd).segment_size = 1; /* Not applicable. */ + adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE; return abfd->xvec; } -struct container { +struct bout_data_struct { struct aoutdata a; struct internal_exec e; }; @@ -180,15 +184,15 @@ static boolean b_out_mkobject (abfd) bfd *abfd; { - struct container *rawptr; + struct bout_data_struct *rawptr; - rawptr = (struct container *) bfd_zalloc (abfd, sizeof (struct container)); + rawptr = (struct bout_data_struct *) bfd_zalloc (abfd, sizeof (struct bout_data_struct)); if (rawptr == NULL) { - bfd_error = no_memory; - return false; - } + bfd_error = no_memory; + return false; + } - set_tdata (abfd, &rawptr->a); + abfd->tdata.bout_data = rawptr; exec_hdr (abfd) = &rawptr->e; /* For simplicity's sake we just make all the sections right here. */ @@ -211,9 +215,9 @@ b_out_write_object_contents (abfd) exec_hdr (abfd)->a_info = BMAGIC; - exec_hdr (abfd)->a_text = obj_textsec (abfd)->size; - exec_hdr (abfd)->a_data = obj_datasec (abfd)->size; - exec_hdr (abfd)->a_bss = obj_bsssec (abfd)->size; + exec_hdr (abfd)->a_text = obj_textsec (abfd)->_cooked_size; + exec_hdr (abfd)->a_data = obj_datasec (abfd)->_cooked_size; + exec_hdr (abfd)->a_bss = obj_bsssec (abfd)->_cooked_size; exec_hdr (abfd)->a_syms = bfd_get_symcount (abfd) * sizeof (struct nlist); exec_hdr (abfd)->a_entry = bfd_get_start_address (abfd); exec_hdr (abfd)->a_trsize = ((obj_textsec (abfd)->reloc_count) * @@ -318,6 +322,9 @@ b_out_slurp_reloc_table (abfd, asect, symbols) sec_ptr asect; asymbol **symbols; { + abort(); + +#if 0 unsigned int count; size_t reloc_size; struct relocation_info *relocs; @@ -399,7 +406,7 @@ b_out_slurp_reloc_table (abfd, asect, symbols) */ cache_ptr->sym_ptr_ptr = symbols + symnum; cache_ptr->addend = 0; - cache_ptr->section = (asection*)NULL; +/*!! cache_ptr->section = (asection*)NULL;*/ } else { /* In a.out symbols are relative to the beginning of the * file rather than sections ? @@ -449,6 +456,8 @@ b_out_slurp_reloc_table (abfd, asect, symbols) free (relocs); asect->relocation = reloc_cache; asect->reloc_count = count; + +#endif return true; } @@ -458,6 +467,9 @@ b_out_squirt_out_relocs (abfd, section) bfd *abfd; asection *section; { + abort(); + +#if 0 arelent **generic; unsigned int count = section->reloc_count; @@ -556,7 +568,7 @@ b_out_squirt_out_relocs (abfd, section) return false; } free ((PTR)native); - +#endif return true; } @@ -617,14 +629,14 @@ b_out_set_section_contents (abfd, section, location, offset, count) { if (abfd->output_has_begun == false) { /* set by bfd.c handler */ if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL) /*|| - (obj_textsec (abfd)->size == 0) || (obj_datasec (abfd)->size == 0)*/) { + (obj_textsec (abfd)->_cooked_size == 0) || (obj_datasec (abfd)->_cooked_size == 0)*/) { bfd_error = invalid_operation; return false; } obj_textsec (abfd)->filepos = sizeof(struct internal_exec); obj_datasec(abfd)->filepos = obj_textsec(abfd)->filepos - + obj_textsec (abfd)->size; + + obj_textsec (abfd)->_cooked_size; } /* regardless, once we know what we're doing, we might as well get going */ @@ -701,7 +713,7 @@ DEFUN(b_out_sizeof_headers,(ignore_abfd, ignore), #define aout_32_bfd_debug_info_end bfd_void #define aout_32_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void - +#define aout_32_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents bfd_target b_out_vec_big_host = { "b.out.big", /* name */ diff --git a/bfd/coff-a29k.c b/bfd/coff-a29k.c index 0be7ba41388..c3ac63c702c 100644 --- a/bfd/coff-a29k.c +++ b/bfd/coff-a29k.c @@ -45,7 +45,9 @@ asymbol *symbol; long relocation = 0; if (symbol != (asymbol *)NULL) { - if (symbol->flags & BSF_FORT_COMM) { + if (symbol->section == &bfd_com_section) + { + relocation = 0; } else { relocation = symbol->value; @@ -83,7 +85,7 @@ DEFUN(a29k_reloc,(abfd, reloc_entry, symbol_in, data, input_section), r_type = reloc_entry->howto->type; /* FIXME: Do we need to check for partial linking here */ - if (symbol_in && (symbol_in->flags & BSF_UNDEFINED)) + if (symbol_in && (symbol_in->section == &bfd_und_section)) { /* Keep the state machine happy in case we're called again */ if (r_type == R_IHIHALF) @@ -233,7 +235,7 @@ static reloc_howto_type howto_table[] = #define RELOC_PROCESSING(relent, reloc, symbols, abfd, section) \ reloc_processing(relent, reloc, symbols, abfd, section) -void DEFUN(reloc_processing,(relent,reloc, symbols, abfd, section) , +static void DEFUN(reloc_processing,(relent,reloc, symbols, abfd, section) , arelent *relent AND struct internal_reloc *reloc AND asymbol **symbols AND @@ -266,7 +268,7 @@ void DEFUN(reloc_processing,(relent,reloc, symbols, abfd, section) , relent->addend = 0; } relent->address-= section->vma; - relent->section = 0; +/* relent->section = 0;*/ } } diff --git a/bfd/coff-h8300.c b/bfd/coff-h8300.c index 79757f4832d..8240850f5a8 100644 --- a/bfd/coff-h8300.c +++ b/bfd/coff-h8300.c @@ -1,6 +1,7 @@ -/* Motorola 68000 COFF back-end for BFD. +/* Hitachi H8/300 COFF back-end for BFD. Copyright (C) 1990-1991 Free Software Foundation, Inc. - Written by Cygnus Support. + Written by Steve Chamberlain + sac@cygnus.com This file is part of BFD, the Binary File Descriptor library. @@ -23,8 +24,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "sysdep.h" #include "libbfd.h" #include "obstack.h" -#include "coff-h8300.h" -#include "internalcoff.h" +#include "coff/h8300.h" +#include "coff/internal.h" #include "libcoff.h" static reloc_howto_type howto_table[] = @@ -35,12 +36,21 @@ static reloc_howto_type howto_table[] = HOWTO(R_PCRBYTE, 0, 0, 8, true, 0, false, true,0,"DISP8", true, 0x000000ff,0x000000ff, true), HOWTO(R_PCRWORD, 0, 1, 16, true, 0, false, true,0,"DISP16", true, 0x0000ffff,0x0000ffff, true), HOWTO(R_PCRLONG, 0, 2, 32, true, 0, false, true,0,"DISP32", true, 0xffffffff,0xffffffff, true), + HOWTO(R_MOVB1, 0, 1, 16, false, 0, true, + true,0,"16/8", true, 0x0000ffff,0x0000ffff, false), + HOWTO(R_MOVB2, 0, 1, 16, false, 0, true, + true,0,"8/16", true, 0x0000ffff,0x0000ffff, false), + HOWTO(R_JMP1, 0, 1, 16, false, 0, true, true,0,"16/pcrel", true, 0x0000ffff,0x0000ffff, false), + HOWTO(R_JMP2, 0, 0, 8, false, 0, true, true,0,"pcrecl/16", true, 0x000000ff,0x000000ff, false), + }; /* Turn a howto into a reloc number */ -#define SELECT_RELOC(x,howto) { x = howto_table[howto->size +(int)howto->pc_relative*3].type; } +#define SELECT_RELOC(x,howto) \ + { x = howto_table[howto->size +(int)howto->pc_relative*3].type; } + #define BADMAG(x) H8300BADMAG(x) #define H8300 1 /* Customize coffcode.h */ #define __A_MAGIC_SET__ @@ -48,8 +58,8 @@ static reloc_howto_type howto_table[] = /* Code to swap in the reloc */ -#define SWAP_IN_RELOC_OFFSET bfd_h_get_16 -#define SWAP_OUT_RELOC_OFFSET bfd_h_put_16 +#define SWAP_IN_RELOC_OFFSET bfd_h_get_32 +#define SWAP_OUT_RELOC_OFFSET bfd_h_put_32 #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \ dst->r_stuff[0] = 'S'; \ dst->r_stuff[1] = 'C'; @@ -57,8 +67,45 @@ static reloc_howto_type howto_table[] = /* Code to turn a r_type into a howto ptr, uses the above howto table */ -#define RTYPE2HOWTO(internal, relocentry) \ - (internal)->howto = ( howto_table + (relocentry).r_type - R_RELBYTE); +static void +DEFUN(rtype2howto,(internal, dst), +arelent *internal AND +struct internal_reloc *dst) +{ + switch (dst->r_type) { + case R_RELBYTE: + internal->howto = howto_table+ 0; + break; + case R_RELWORD: + internal->howto = howto_table+ 1; + break; + case R_PCRBYTE: + internal->howto = howto_table+3; + break; + case R_PCRWORD: + internal->howto = howto_table+ 4; + break; + case R_MOVB1: + internal->howto = howto_table + 6; + break; + case R_MOVB2: + internal->howto = howto_table + 7; + break; + case R_JMP1: + internal->howto = howto_table +8; + break; + + case R_JMP2: + internal->howto = howto_table +9; + break; + + default: + abort(); + break; + } +} + +#define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry) /* Perform any necessaru magic to the addend in a reloc entry */ @@ -68,6 +115,40 @@ static reloc_howto_type howto_table[] = cache_ptr->addend = ext_reloc.r_offset; +#define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \ + reloc_processing(relent, reloc, symbols, abfd, section) + +static void DEFUN(reloc_processing,(relent,reloc, symbols, abfd, section) , + arelent *relent AND + struct internal_reloc *reloc AND + asymbol **symbols AND + bfd *abfd AND + asection *section) +{ + + asymbol *ptr; + relent->address = reloc->r_vaddr; + rtype2howto(relent,reloc); + + if (reloc->r_symndx > 0) + { + + relent->sym_ptr_ptr = symbols + obj_convert(abfd)[reloc->r_symndx]; + + } + else + { + relent->sym_ptr_ptr = &(bfd_abs_symbol); + } + + + + relent->addend = reloc->r_offset; + + relent->address-= section->vma; +/* relent->section = 0;*/ +} + #include "coffcode.h" @@ -84,7 +165,7 @@ bfd_target h8300coff_vec = HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT), - (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ + ( SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 1, /* minimum section alignment */ diff --git a/bfd/coffcode.h b/bfd/coffcode.h index dd8151d964f..3662269eccf 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -212,6 +212,7 @@ DESCRIPTION coff_ptr_struct, which is typedefed to a combined_entry_type CODE_FRAGMENT +. .typedef struct coff_ptr_struct .{ . @@ -818,7 +819,8 @@ DEFUN(coff_swap_scnhdr_in,(abfd, scnhdr_ext, scnhdr_int), memcpy(scnhdr_int->s_name, scnhdr_ext->s_name, sizeof(scnhdr_int->s_name)); scnhdr_int->s_vaddr = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_vaddr); scnhdr_int->s_paddr = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_paddr); - scnhdr_int->s_size = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_size); + scnhdr_int->s_size = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_size); + scnhdr_int->s_scnptr = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_scnptr); scnhdr_int->s_relptr = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_relptr); scnhdr_int->s_lnnoptr = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_lnnoptr); @@ -872,89 +874,98 @@ DEFUN(coff_swap_scnhdr_out,(abfd, in, out), */ static boolean -DEFUN(coff_new_section_hook,(abfd_ignore, section_ignore), +DEFUN(coff_new_section_hook,(abfd_ignore, section), bfd *abfd_ignore AND - asection *section_ignore) + asection *section) { - section_ignore->alignment_power = abfd_ignore->xvec->align_power_min; + section->alignment_power = abfd_ignore->xvec->align_power_min; return true; } +static void +DEFUN(make_abs_section,(abfd), + bfd *abfd) +{ + abort(); + +} + /* Take a section header read from a coff file (in HOST byte order), and make a BFD "section" out of it. */ static boolean -DEFUN(make_a_section_from_file,(abfd, hdr), +DEFUN(make_a_section_from_file,(abfd, hdr, target_index), bfd *abfd AND - struct internal_scnhdr *hdr) + struct internal_scnhdr *hdr AND + unsigned int target_index) { - asection *return_section; + asection *return_section; + char *name; + + /* Assorted wastage to null-terminate the name, thanks AT&T! */ + name = bfd_alloc(abfd, sizeof (hdr->s_name)+1); + if (name == NULL) { + bfd_error = no_memory; + return false; + } + strncpy(name, (char *) &hdr->s_name[0], sizeof (hdr->s_name)); + name[sizeof (hdr->s_name)] = 0; - { - /* Assorted wastage to null-terminate the name, thanks AT&T! */ - char *name = bfd_alloc(abfd, sizeof (hdr->s_name)+1); - if (name == NULL) { - bfd_error = no_memory; - return false; - } - strncpy(name, (char *) &hdr->s_name[0], sizeof (hdr->s_name)); - name[sizeof (hdr->s_name)] = 0; + return_section = bfd_make_section(abfd, name); + if (return_section == NULL) + return false; - return_section = bfd_make_section(abfd, name); - if (return_section == NULL) - return false; - } + /* s_paddr is presumed to be = to s_vaddr */ - /* s_paddr is presumed to be = to s_vaddr */ -#define assign(to, from) return_section->to = hdr->from - assign(vma, s_vaddr); - /* assign (vma, s_vaddr); */ - assign(size, s_size); - assign(filepos, s_scnptr); - assign(rel_filepos, s_relptr); - assign(reloc_count, s_nreloc); + return_section->vma = hdr->s_vaddr; + return_section->_raw_size = hdr->s_size; + return_section->filepos = hdr->s_scnptr; + return_section->rel_filepos = hdr->s_relptr; + return_section->reloc_count = hdr->s_nreloc; #ifdef I960 - { - /* FIXME, use a temp var rather than alignment_power */ - assign(alignment_power, s_align); - { - unsigned int i; - for (i = 0; i < 32; i++) { - if ((1 << i) >= (int) (return_section->alignment_power)) { - return_section->alignment_power = i; - break; - } - } + + /* FIXME, use a temp var rather than alignment_power */ + return_section->alignment_power = hdr->s_align; +{ + unsigned int i; + for (i = 0; i < 32; i++) { + if ((1 << i) >= (int) (return_section->alignment_power)) { + return_section->alignment_power = i; + break; } } +} + #endif - assign(line_filepos, s_lnnoptr); - /* - return_section->linesize = hdr->s_nlnno * sizeof (struct lineno); +return_section->line_filepos = hdr->s_lnnoptr; + /* + return_section->linesize = hdr->s_nlnno * sizeof (struct lineno); */ - return_section->lineno_count = hdr->s_nlnno; - return_section->userdata = NULL; - return_section->next = (asection *) NULL; - return_section->flags = styp_to_sec_flags(hdr->s_flags); + return_section->lineno_count = hdr->s_nlnno; + return_section->userdata = NULL; + return_section->next = (asection *) NULL; + return_section->flags = styp_to_sec_flags(hdr->s_flags); + return_section->target_index = target_index; - if (hdr->s_nreloc != 0) - return_section->flags |= SEC_RELOC; - /* FIXME: should this check 'hdr->s_size > 0' */ - if (hdr->s_scnptr != 0) - return_section->flags |= SEC_HAS_CONTENTS; - return true; + if (hdr->s_nreloc != 0) + return_section->flags |= SEC_RELOC; + /* FIXME: should this check 'hdr->s_size > 0' */ + if (hdr->s_scnptr != 0) + return_section->flags |= SEC_HAS_CONTENTS; + return true; } static boolean DEFUN(coff_mkobject,(abfd), bfd *abfd) { - set_tdata (abfd, bfd_zalloc (abfd,sizeof(coff_data_type))); - if (coff_data(abfd) == 0) { + abfd->tdata.coff_obj_data = (struct coff_tdata *)bfd_zalloc (abfd,sizeof(coff_data_type)); + if (abfd->tdata.coff_obj_data == 0){ bfd_error = no_memory; return false; } coff_data(abfd)->relocbase = 0; + make_abs_section(abfd); return true; } @@ -975,6 +986,7 @@ DEFUN(coff_real_object_p,(abfd, nscns, internal_f, internal_a), /* Build a play area */ if (coff_mkobject(abfd) != true) return 0; + coff = coff_data(abfd); @@ -998,9 +1010,12 @@ DEFUN(coff_real_object_p,(abfd, nscns, internal_f, internal_a), for (i = 0; i < nscns; i++) { struct internal_scnhdr tmp; coff_swap_scnhdr_in(abfd, external_sections + i, &tmp); - make_a_section_from_file(abfd,&tmp); + make_a_section_from_file(abfd,&tmp, i+1); } } + +/* make_abs_section(abfd);*/ + /* Determine the machine architecture and type. */ machine = 0; switch (internal_f->f_magic) { @@ -1242,7 +1257,7 @@ DEFUN(coff_symbol_from,(ignore_abfd, symbol), if (symbol->the_bfd->xvec->flavour != bfd_target_coff_flavour) return (coff_symbol_type *)NULL; - if (symbol->the_bfd->tdata == (PTR)NULL) + if (symbol->the_bfd->tdata.coff_obj_data == (coff_data_type*)NULL) return (coff_symbol_type *)NULL; return (coff_symbol_type *) symbol; @@ -1257,7 +1272,7 @@ struct internal_syment *syment) { /* Normalize the symbol flags */ - if (coff_symbol_ptr->symbol.flags & BSF_FORT_COMM) { + if (coff_symbol_ptr->symbol.section == &bfd_com_section) { /* a common symbol is undefined with a value */ syment->n_scnum = N_UNDEF; syment->n_value = coff_symbol_ptr->symbol.value; @@ -1265,18 +1280,14 @@ struct internal_syment *syment) else if (coff_symbol_ptr->symbol.flags & BSF_DEBUGGING) { syment->n_value = coff_symbol_ptr->symbol.value; } - else if (coff_symbol_ptr->symbol.flags & BSF_UNDEFINED) { + else if (coff_symbol_ptr->symbol.section == & bfd_und_section) { syment->n_scnum = N_UNDEF; syment->n_value = 0; } - else if (coff_symbol_ptr->symbol.flags & BSF_ABSOLUTE) { - syment->n_scnum = N_ABS; - syment->n_value = coff_symbol_ptr->symbol.value; - } else { if (coff_symbol_ptr->symbol.section) { syment->n_scnum = - coff_symbol_ptr->symbol.section->output_section->index+1; + coff_symbol_ptr->symbol.section->output_section->target_index; syment->n_value = coff_symbol_ptr->symbol.value + @@ -1284,6 +1295,7 @@ struct internal_syment *syment) coff_symbol_ptr->symbol.section->output_section->vma; } else { + BFD_ASSERT(0); /* This can happen, but I don't know why yet (steve@cygnus.com) */ syment->n_scnum = N_ABS; syment->n_value = coff_symbol_ptr->symbol.value; @@ -1444,8 +1456,10 @@ unsigned int written) int class = native->u.syment.n_sclass; SYMENT buf; unsigned int j; - + native->u.syment.n_scnum = symbol->section->output_section->target_index; + coff_fix_symbol_name(abfd, symbol, native); + coff_swap_sym_out(abfd, &native->u.syment, &buf); bfd_write((PTR)& buf, 1, SYMESZ, abfd); for (j = 0; j != native->u.syment.n_numaux; j++) @@ -1475,43 +1489,45 @@ DEFUN(coff_write_alien_symbol,(abfd, symbol, written), coff format. It has no native element to inherit, make our own */ - combined_entry_type *native; - combined_entry_type dummy; + combined_entry_type *native; + combined_entry_type dummy; native = &dummy; native->u.syment.n_type = T_NULL; #ifdef I960 native->u.syment.n_flags = 0; #endif - if (symbol->flags & BSF_ABSOLUTE) { - native->u.syment.n_scnum = N_ABS; - native->u.syment.n_value = symbol->value; - } - else if (symbol->flags & (BSF_UNDEFINED | BSF_FORT_COMM)) { - native->u.syment.n_scnum = N_UNDEF; - native->u.syment.n_value = symbol->value; + if (symbol->section == &bfd_und_section) { + native->u.syment.n_scnum = N_UNDEF; + native->u.syment.n_value = symbol->value; + } + else if (symbol->section == &bfd_com_section) + { + native->u.syment.n_scnum = N_UNDEF; + native->u.syment.n_value = symbol->value; + } + else if (symbol->flags & BSF_DEBUGGING) { - /* - remove name so it doesn't take up any space - */ - symbol->name = ""; - } + /* + remove name so it doesn't take up any space + */ + symbol->name = ""; + } else { - native->u.syment.n_scnum = symbol->section->output_section->index + - 1; - native->u.syment.n_value = symbol->value + - symbol->section->output_section->vma + + native->u.syment.n_scnum = symbol->section->output_section->target_index; + native->u.syment.n_value = symbol->value + + symbol->section->output_section->vma + symbol->section->output_offset; #ifdef I960 - /* Copy the any flags from the the file hdr into the symbol */ - { - coff_symbol_type *c = coff_symbol_from(abfd, symbol); - if (c != (coff_symbol_type *)NULL) { + /* Copy the any flags from the the file hdr into the symbol */ + { + coff_symbol_type *c = coff_symbol_from(abfd, symbol); + if (c != (coff_symbol_type *)NULL) { native->u.syment.n_flags = c->symbol.the_bfd->flags; } - } + } #endif - } + } #ifdef HASPAD1 native->u.syment.pad1[0] = 0; @@ -1520,9 +1536,9 @@ DEFUN(coff_write_alien_symbol,(abfd, symbol, written), native->u.syment.n_type = 0; if (symbol->flags & BSF_LOCAL) - native->u.syment.n_sclass = C_STAT; + native->u.syment.n_sclass = C_STAT; else - native->u.syment.n_sclass = C_EXT; + native->u.syment.n_sclass = C_EXT; native->u.syment.n_numaux = 0; return coff_write_symbol(abfd, symbol, native, written); @@ -1555,6 +1571,7 @@ unsigned int written) /* And count and relocate all other linenumbers */ + count++; while (lineno[count].line_number) { lineno[count].u.offset += @@ -1778,8 +1795,7 @@ DEFUN(coff_print_symbol,(ignore_abfd, filep, symbol, how), case bfd_print_symbol_nm: { - CONST char *section_name = symbol->section == (asection *) NULL ? - "*abs" : symbol->section->name; + CONST char *section_name = symbol->section->name; bfd_print_symbol_vandf((PTR) file, symbol); @@ -1795,8 +1811,7 @@ DEFUN(coff_print_symbol,(ignore_abfd, filep, symbol, how), case bfd_print_symbol_all: /* Print out the symbols in a reasonable way */ { - CONST char *section_name = symbol->section == (asection *) NULL ? - "*abs" : symbol->section->name; + CONST char *section_name = symbol->section->name; if (coffsymbol(symbol)->native) @@ -1805,8 +1820,8 @@ DEFUN(coff_print_symbol,(ignore_abfd, filep, symbol, how), combined_entry_type *combined = coffsymbol(symbol)->native; combined_entry_type *root = obj_raw_syments(ignore_abfd); -fprintf(file,"[%3d]", - combined - root); + fprintf(file,"[%3d]", + combined - root); fprintf(file, "(sc %2d)(fl%4x)(ty%3x)(sc%3d) nx(%d) %08x %s", @@ -1983,61 +1998,61 @@ static void DEFUN(coff_compute_section_file_positions,(abfd), bfd *abfd) { - asection *current; - asection *previous = (asection *)NULL; - file_ptr sofar = FILHSZ; - file_ptr old_sofar; - if (bfd_get_start_address(abfd)) - { - /* A start address may have been added to the original file. In this - case it will need an optional header to record it. */ - abfd->flags |= EXEC_P; - } + asection *current; + asection *previous = (asection *)NULL; + file_ptr sofar = FILHSZ; + file_ptr old_sofar; + if (bfd_get_start_address(abfd)) + { + /* A start address may have been added to the original file. In this + case it will need an optional header to record it. */ + abfd->flags |= EXEC_P; + } - if (abfd->flags & EXEC_P) - sofar += AOUTSZ; + if (abfd->flags & EXEC_P) + sofar += AOUTSZ; - sofar += abfd->section_count * SCNHSZ; - for (current = abfd->sections; - current != (asection *)NULL; - current = current->next) { + sofar += abfd->section_count * SCNHSZ; + for (current = abfd->sections; + current != (asection *)NULL; + current = current->next) { - /* Only deal with sections which have contents */ - if (!(current->flags & SEC_HAS_CONTENTS)) - continue; + /* Only deal with sections which have contents */ + if (!(current->flags & SEC_HAS_CONTENTS)) + continue; - /* Align the sections in the file to the same boundary on - which they are aligned in virtual memory. I960 doesn't - do this (FIXME) so we can stay in sync with Intel. 960 - doesn't yet page from files... */ + /* Align the sections in the file to the same boundary on + which they are aligned in virtual memory. I960 doesn't + do this (FIXME) so we can stay in sync with Intel. 960 + doesn't yet page from files... */ #ifndef I960 - { - /* make sure this section is aligned on the right boundary - by - padding the previous section up if necessary */ - - old_sofar= sofar; - sofar = BFD_ALIGN(sofar, 1 << current->alignment_power); - if (previous != (asection *)NULL) { - previous->size += sofar - old_sofar; - } - } + { + /* make sure this section is aligned on the right boundary - by + padding the previous section up if necessary */ + + old_sofar= sofar; + sofar = BFD_ALIGN(sofar, 1 << current->alignment_power); + if (previous != (asection *)NULL) { + previous->_cooked_size += sofar - old_sofar; + } + } #endif - /* FIXME, in demand paged files, the low order bits of the file - offset must match the low order bits of the virtual address. - "Low order" is apparently implementation defined. Add code - here to round sofar up to match the virtual address. */ + /* FIXME, in demand paged files, the low order bits of the file + offset must match the low order bits of the virtual address. + "Low order" is apparently implementation defined. Add code + here to round sofar up to match the virtual address. */ - current->filepos = sofar; + current->filepos = sofar; - /* make sure that this section is of the right size too */ - old_sofar = sofar += current->size; - sofar = BFD_ALIGN(sofar, 1 << current->alignment_power); - current->size += sofar - old_sofar ; + /* make sure that this section is of the right size too */ + old_sofar = sofar += current->_cooked_size; + sofar = BFD_ALIGN(sofar, 1 << current->alignment_power); + current->_raw_size += sofar - old_sofar ; - previous = current; + previous = current; } - obj_relocbase(abfd) = sofar; + obj_relocbase(abfd) = sofar; } @@ -2048,40 +2063,55 @@ DEFUN(coff_compute_section_file_positions,(abfd), static boolean DEFUN(coff_write_object_contents,(abfd), bfd *abfd) - { - asection *current; - boolean hasrelocs = false; - boolean haslinno = false; - file_ptr reloc_base; - file_ptr lineno_base; - file_ptr sym_base; - file_ptr scn_base; - file_ptr data_base; - unsigned long reloc_size = 0; - unsigned long lnno_size = 0; - asection *text_sec = NULL; - asection *data_sec = NULL; - asection *bss_sec = NULL; - - struct internal_filehdr internal_f; - struct internal_aouthdr internal_a; +{ + asection *current; + unsigned int count; + + boolean hasrelocs = false; + boolean haslinno = false; + file_ptr reloc_base; + file_ptr lineno_base; + file_ptr sym_base; + file_ptr scn_base; + file_ptr data_base; + unsigned long reloc_size = 0; + unsigned long lnno_size = 0; + asection *text_sec = NULL; + asection *data_sec = NULL; + asection *bss_sec = NULL; + struct internal_filehdr internal_f; + struct internal_aouthdr internal_a; - bfd_error = system_call_error; + bfd_error = system_call_error; + /* Number the output sections, starting from one on the first section + with a name which doesn't start with a * */ + count = 1; + for (current = abfd->sections; current != (asection *)NULL; + current = current->next) + { + if (current->name[0] != '*') + { + current->target_index = count; + count++; + } + } + + - if(abfd->output_has_begun == false) { + if(abfd->output_has_begun == false) { coff_compute_section_file_positions(abfd); } - if (abfd->sections != (asection *)NULL) { + if (abfd->sections != (asection *)NULL) { scn_base = abfd->sections->filepos; - } + } else { - scn_base = 0; - } + scn_base = 0; + } if (bfd_seek(abfd, scn_base, SEEK_SET) != 0) - return false; + return false; reloc_base = obj_relocbase(abfd); /* Make a pass through the symbol table to count line number entries and @@ -2094,86 +2124,107 @@ DEFUN(coff_write_object_contents,(abfd), /* Work out the size of the reloc and linno areas */ - for (current = abfd->sections; current != NULL; current = current->next) { - reloc_size += current->reloc_count * RELSZ; + for (current = abfd->sections; current != NULL; current = + current->next) + { + /* We give section headers to +ve indexes */ + if (current->target_index > 0) + { + + reloc_size += current->reloc_count * RELSZ; #ifndef NO_COFF_LINENOS - lnno_size += current->lineno_count * LINESZ; + lnno_size += current->lineno_count * LINESZ; #endif - data_base += SCNHSZ; + data_base += SCNHSZ; + } + } lineno_base = reloc_base + reloc_size; sym_base = lineno_base + lnno_size; /* Indicate in each section->line_filepos its actual file address */ - for (current = abfd->sections; current != NULL; current = current->next) { - if (current->lineno_count) { - current->line_filepos = lineno_base; - current->moving_line_filepos = lineno_base; + for (current = abfd->sections; current != NULL; current = + current->next) + { + if (current->target_index > 0) + { + + if (current->lineno_count) { + current->line_filepos = lineno_base; + current->moving_line_filepos = lineno_base; #ifndef NO_COFF_LINENOS - lineno_base += current->lineno_count * LINESZ; + lineno_base += current->lineno_count * LINESZ; #endif + } + else { + current->line_filepos = 0; + } + if (current->reloc_count) { + current->rel_filepos = reloc_base; + reloc_base += current->reloc_count * sizeof(struct internal_reloc); + } + else { + current->rel_filepos = 0; + } } - else { - current->line_filepos = 0; - } - if (current->reloc_count) { - current->rel_filepos = reloc_base; - reloc_base += current->reloc_count * sizeof(struct internal_reloc); - } - else { - current->rel_filepos = 0; - } - } + } + - /* Write section headers to the file. */ + /* Write section headers to the file. */ + internal_f.f_nscns = 0; bfd_seek(abfd, (file_ptr) ((abfd->flags & EXEC_P) ? (FILHSZ + AOUTSZ) : FILHSZ), SEEK_SET); - { +{ #if 0 - unsigned int pad = abfd->flags & D_PAGED ? data_base : 0; + unsigned int pad = abfd->flags & D_PAGED ? data_base : 0; #endif - unsigned int pad = 0; + unsigned int pad = 0; - for (current = abfd->sections; current != NULL; current = current->next) { - struct internal_scnhdr section; + for (current = abfd->sections; + current != NULL; + current = current->next) { + struct internal_scnhdr section; + if (current->target_index > 0) + { + internal_f.f_nscns ++; strncpy(&(section.s_name[0]), current->name, 8); section.s_vaddr = current->vma + pad; section.s_paddr = current->vma + pad; - section.s_size = current->size - pad; + section.s_size = current->_cooked_size - pad; /* If this section has no size or is unloadable then the scnptr will be 0 too */ - if (current->size - pad == 0 || + if (current->_cooked_size - pad == 0 || (current->flags & SEC_LOAD) == 0) { - section.s_scnptr = 0; - } + section.s_scnptr = 0; + } else { - section.s_scnptr = current->filepos; - } + section.s_scnptr = current->filepos; + } section.s_relptr = current->rel_filepos; section.s_lnnoptr = current->line_filepos; section.s_nreloc = current->reloc_count; section.s_nlnno = current->lineno_count; if (current->reloc_count != 0) - hasrelocs = true; + hasrelocs = true; if (current->lineno_count != 0) - haslinno = true; + haslinno = true; section.s_flags = sec_to_styp_flags(current->name,current->flags); if (!strcmp(current->name, _TEXT)) { - text_sec = current; - } else if (!strcmp(current->name, _DATA)) { - data_sec = current; - } else if (!strcmp(current->name, _BSS)) { - bss_sec = current; - } + text_sec = current; + } else if (!strcmp(current->name, _DATA)) { + data_sec = current; + } else if (!strcmp(current->name, _BSS)) { + bss_sec = current; + } #ifdef I960 section.s_align = (current->alignment_power @@ -2181,19 +2232,24 @@ DEFUN(coff_write_object_contents,(abfd), : 0); #endif - { - SCNHDR buff; + { + SCNHDR buff; - coff_swap_scnhdr_out(abfd, §ion, &buff); - bfd_write((PTR) (&buff), 1, SCNHSZ, abfd); + coff_swap_scnhdr_out(abfd, §ion, &buff); + bfd_write((PTR) (&buff), 1, SCNHSZ, abfd); + + } - } pad = 0; } - } + } +} + /* OK, now set up the filehdr... */ - internal_f.f_nscns = abfd->section_count; + + /* Don't include the internal abs section in the section count */ + /* We will NOT put a fucking timestamp in the header here. Every time you put it back, I will come in and take it out again. I'm sorry. This @@ -2211,30 +2267,30 @@ DEFUN(coff_write_object_contents,(abfd), #endif if (bfd_get_symcount(abfd) != 0) - internal_f.f_symptr = sym_base; + internal_f.f_symptr = sym_base; else - internal_f.f_symptr = 0; + internal_f.f_symptr = 0; internal_f.f_flags = 0; if (abfd->flags & EXEC_P) - internal_f.f_opthdr = AOUTSZ; + internal_f.f_opthdr = AOUTSZ; else - internal_f.f_opthdr = 0; + internal_f.f_opthdr = 0; if (!hasrelocs) - internal_f.f_flags |= F_RELFLG; + internal_f.f_flags |= F_RELFLG; if (!haslinno) - internal_f.f_flags |= F_LNNO; + internal_f.f_flags |= F_LNNO; if (0 == bfd_get_symcount(abfd)) - internal_f.f_flags |= F_LSYMS; + internal_f.f_flags |= F_LSYMS; if (abfd->flags & EXEC_P) - internal_f.f_flags |= F_EXEC; + internal_f.f_flags |= F_EXEC; #if M88 internal_f.f_flags |= F_AR32W; #else if (!abfd->xvec->byteorder_big_p) - internal_f.f_flags |= F_AR32WR; + internal_f.f_flags |= F_AR32WR; #endif /* FIXME, should do something about the other byte orders and @@ -2243,45 +2299,45 @@ DEFUN(coff_write_object_contents,(abfd), /* Set up architecture-dependent stuff */ - { unsigned int magic = 0; - unsigned short flags = 0; - coff_set_flags(abfd, &magic, &flags); - internal_f.f_magic = magic; - internal_f.f_flags |= flags; - /* ...and the "opt"hdr... */ +{ unsigned int magic = 0; + unsigned short flags = 0; + coff_set_flags(abfd, &magic, &flags); + internal_f.f_magic = magic; + internal_f.f_flags |= flags; + /* ...and the "opt"hdr... */ #ifdef A29K -# ifdef ULTRA3 /* NYU's machine */ - /* FIXME: This is a bogus check. I really want to see if there - * is a .shbss or a .shdata section, if so then set the magic - * number to indicate a shared data executable. - */ - if (internal_f.f_nscns >= 7) - internal_a.magic = SHMAGIC; /* Shared magic */ - else -# endif /* ULTRA3 */ - internal_a.magic = NMAGIC; /* Assume separate i/d */ +# ifdef ULTRA3 /* NYU's machine */ + /* FIXME: This is a bogus check. I really want to see if there + * is a .shbss or a .shdata section, if so then set the magic + * number to indicate a shared data executable. + */ + if (internal_f.f_nscns >= 7) + internal_a.magic = SHMAGIC; /* Shared magic */ + else +# endif /* ULTRA3 */ + internal_a.magic = NMAGIC; /* Assume separate i/d */ #define __A_MAGIC_SET__ -#endif /* A29K */ +#endif /* A29K */ #ifdef I960 - internal_a.magic = (magic == I960ROMAGIC ? NMAGIC : OMAGIC); + internal_a.magic = (magic == I960ROMAGIC ? NMAGIC : OMAGIC); #define __A_MAGIC_SET__ -#endif /* I960 */ +#endif /* I960 */ #if M88 #define __A_MAGIC_SET__ - internal_a.magic = PAGEMAGICBCS; -#endif /* M88 */ + internal_a.magic = PAGEMAGICBCS; +#endif /* M88 */ #if M68 || I386 || MIPS #define __A_MAGIC_SET__ - /* Never was anything here for the 68k */ -#endif /* M88 */ + /* Never was anything here for the 68k */ +#endif /* M88 */ #if RS6000COFF_C #define __A_MAGIC_SET__ - internal_a.magic = (abfd->flags & D_PAGED)? RS6K_AOUTHDR_ZMAGIC: - (abfd->flags & WP_TEXT)? RS6K_AOUTHDR_NMAGIC: - RS6K_AOUTHDR_OMAGIC; + internal_a.magic = (abfd->flags & D_PAGED)? RS6K_AOUTHDR_ZMAGIC: + (abfd->flags & WP_TEXT)? RS6K_AOUTHDR_NMAGIC: + RS6K_AOUTHDR_OMAGIC; #endif #ifndef __A_MAGIC_SET__ @@ -2289,47 +2345,47 @@ DEFUN(coff_write_object_contents,(abfd), #else # undef __A_MAGIC_SET__ #endif - } +} /* Now should write relocs, strings, syms */ obj_sym_filepos(abfd) = sym_base; #ifndef NO_COFF_SYMBOLS if (bfd_get_symcount(abfd) != 0) { - coff_renumber_symbols(abfd); - coff_mangle_symbols(abfd); - coff_write_symbols(abfd); - coff_write_linenumbers(abfd); - coff_write_relocs(abfd); - } -#endif /* NO_COFF_SYMBOLS */ + coff_renumber_symbols(abfd); + coff_mangle_symbols(abfd); + coff_write_symbols(abfd); + coff_write_linenumbers(abfd); + coff_write_relocs(abfd); + } +#endif /* NO_COFF_SYMBOLS */ if (text_sec) { - internal_a.tsize = text_sec->size; - internal_a.text_start =text_sec->size ? text_sec->vma : 0; - } + internal_a.tsize = bfd_get_section_size_after_reloc(text_sec); + internal_a.text_start = internal_a.tsize ? text_sec->vma : 0; + } if (data_sec) { - internal_a.dsize = data_sec->size; - internal_a.data_start = data_sec->size ? data_sec->vma : 0; - } + internal_a.dsize = bfd_get_section_size_after_reloc(data_sec); + internal_a.data_start = internal_a.dsize ? data_sec->vma : 0; + } if (bss_sec) { - internal_a.bsize = bss_sec->size; - } + internal_a.bsize = bfd_get_section_size_after_reloc(bss_sec); + } internal_a.entry = bfd_get_start_address(abfd); internal_f.f_nsyms = bfd_get_symcount(abfd); /* now write them */ if (bfd_seek(abfd, 0L, SEEK_SET) != 0) - return false; - { - FILHDR buff; - coff_swap_filehdr_out(abfd, &internal_f, &buff); - bfd_write((PTR) &buff, 1, FILHSZ, abfd); - } + return false; +{ + FILHDR buff; + coff_swap_filehdr_out(abfd, &internal_f, &buff); + bfd_write((PTR) &buff, 1, FILHSZ, abfd); +} if (abfd->flags & EXEC_P) { - AOUTHDR buff; - coff_swap_aouthdr_out(abfd, &internal_a, &buff); - bfd_write((PTR) &buff, 1, AOUTSZ, abfd); - } + AOUTHDR buff; + coff_swap_aouthdr_out(abfd, &internal_a, &buff); + bfd_write((PTR) &buff, 1, AOUTSZ, abfd); + } return true; } @@ -2482,7 +2538,8 @@ DEFUN(build_debug_section,(abfd), return NULL; } - debug_section = (PTR) bfd_alloc (abfd, bfd_section_size (abfd, sect)); + debug_section = (PTR) bfd_alloc (abfd, + bfd_get_section_size_before_reloc (sect)); if (debug_section == NULL) { bfd_error = no_memory; return NULL; @@ -2494,8 +2551,9 @@ DEFUN(build_debug_section,(abfd), position = bfd_tell (abfd); bfd_seek (abfd, sect->filepos, SEEK_SET); - if (bfd_read (debug_section, bfd_section_size (abfd, sect), 1, abfd) - != bfd_section_size (abfd, sect)) { + if (bfd_read (debug_section, + bfd_get_section_size_before_reloc (sect), 1, abfd) + != bfd_get_section_size_before_reloc(sect)) { bfd_error = system_call_error; return NULL; } @@ -2694,14 +2752,14 @@ DEFUN(section_from_bfd_index,(abfd, index), bfd *abfd AND int index) { - if (index > 0) { - struct sec *answer = abfd->sections; - while (--index) { + struct sec *answer = abfd->sections; + + while (answer) { + if (answer->target_index == index) + return answer; answer = answer->next; } - return answer; - } - return 0; + BFD_ASSERT(0); } #ifndef NO_COFF_LINENOS @@ -2855,11 +2913,11 @@ DEFUN(coff_slurp_symbol_table,(abfd), #endif if ((src->u.syment.n_scnum) == 0) { if ((src->u.syment.n_value) == 0) { - dst->symbol.flags = BSF_UNDEFINED; + dst->symbol.section = &bfd_und_section; dst->symbol.value= 0; } else { - dst->symbol.flags = BSF_FORT_COMM; + dst->symbol.section = &bfd_com_section; dst->symbol.value = (src->u.syment.n_value); } } @@ -2868,14 +2926,10 @@ DEFUN(coff_slurp_symbol_table,(abfd), Base the value as an index from the base of the section */ - if (dst->symbol.section == (asection *) NULL) { - dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL | BSF_ABSOLUTE; - dst->symbol.value = src->u.syment.n_value; - } - else { + dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL; dst->symbol.value = src->u.syment.n_value - dst->symbol.section->vma; - } + if (ISFCN((src->u.syment.n_type))) { /* A function ext does not go at the end of a file @@ -3193,10 +3247,10 @@ DEFUN(coff_slurp_reloc_table,(abfd, asect, symbols), CALC_ADDEND(abfd, ptr, dst, cache_ptr); cache_ptr->address -= asect->vma; - cache_ptr->section = (asection *) NULL; +/* !! cache_ptr->section = (asection *) NULL;*/ /* Fill in the cache_ptr->howto field from dst.r_type */ - RTYPE2HOWTO(cache_ptr, dst); + RTYPE2HOWTO(cache_ptr, &dst); #endif } @@ -3214,39 +3268,39 @@ sec_ptr section AND arelent **relptr AND asymbol **symbols) { - arelent *tblptr = section->relocation; - unsigned int count = 0; + arelent *tblptr = section->relocation; + unsigned int count = 0; - if (section->flags & SEC_CONSTRUCTOR) + if (section->flags & SEC_CONSTRUCTOR) + { + /* this section has relocs made up by us, they are not in the + file, so take them out of their chain and place them into + the data area provided */ + arelent_chain *chain = section->constructor_chain; + for (count = 0; count < section->reloc_count; count ++) { - /* this section has relocs made up by us, they are not in the - file, so take them out of their chain and place them into - the data area provided */ - arelent_chain *chain = section->constructor_chain; - for (count = 0; count < section->reloc_count; count ++) - { - *relptr ++ = &chain->relent; - chain = chain->next; - } - + *relptr ++ = &chain->relent; + chain = chain->next; } - else - { - coff_slurp_reloc_table(abfd, section, symbols); + + } + else + { + coff_slurp_reloc_table(abfd, section, symbols); - tblptr = section->relocation; - if (!tblptr) - return 0; + tblptr = section->relocation; + if (!tblptr) + return 0; - for (; count++ < section->reloc_count;) - *relptr++ = tblptr++; + for (; count++ < section->reloc_count;) + *relptr++ = tblptr++; - } - *relptr = 0; - return section->reloc_count; + } + *relptr = 0; + return section->reloc_count; } #ifndef NO_COFF_SYMBOLS @@ -3407,3 +3461,5 @@ DEFUN(coff_sizeof_headers,(abfd, reloc), #define coff_bfd_debug_info_start bfd_void #define coff_bfd_debug_info_end bfd_void #define coff_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void +#define coff_bfd_get_relocated_section_contents \ + bfd_generic_get_relocated_section_contents diff --git a/bfd/ctor.c b/bfd/ctor.c index 1bcb49c1f16..d81df612b48 100644 --- a/bfd/ctor.c +++ b/bfd/ctor.c @@ -132,18 +132,18 @@ void DEFUN(bfd_constructor_entry,(abfd, symbol_ptr_ptr, type), arelent_chain *reloc = (arelent_chain *)bfd_alloc(abfd, sizeof(arelent_chain)); - reloc->relent.section = (asection *)NULL; +/* reloc->relent.section = (asection *)NULL;*/ reloc->relent.addend = 0; reloc->relent.sym_ptr_ptr = symbol_ptr_ptr; reloc->next = rel_section->constructor_chain; rel_section->constructor_chain = reloc; - reloc->relent.address = rel_section->size; + reloc->relent.address = rel_section->_cooked_size; /* ask the cpu which howto to use */ reloc->relent.howto = bfd_reloc_type_lookup(abfd->arch_info, BFD_RELOC_CTOR); - rel_section->size += sizeof(int *); + rel_section->_cooked_size += sizeof(int *); rel_section->reloc_count++; } diff --git a/bfd/elf.c b/bfd/elf.c index aa3e2fbe502..5230ebb3904 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -100,16 +100,17 @@ typedef struct in the bfd structure. This information is different for ELF core files and other ELF files. */ -typedef struct +typedef struct elf_core_tdata_struct { void *prstatus; /* The raw /proc prstatus structure */ void *prpsinfo; /* The raw /proc prpsinfo structure */ } elf_core_tdata; -#define core_prpsinfo(bfd) (((elf_core_tdata *)((bfd)->tdata))->prpsinfo) -#define core_prstatus(bfd) (((elf_core_tdata *)((bfd)->tdata))->prstatus) +#define core_prpsinfo(bfd) (((bfd)->tdata.elf_core_data))->prpsinfo) +#define core_prpstatus(bfd) (((bfd)->tdata.elf_core_data))->prpstatus) -typedef struct + +typedef struct elf_obj_tdata_struct { file_ptr symtab_filepos; /* Offset to start of ELF symtab section */ long symtab_filesz; /* Size of ELF symtab section */ @@ -117,7 +118,7 @@ typedef struct long strtab_filesz; /* Size of ELF string tbl section */ } elf_obj_tdata; -#define elf_tdata(bfd) ((elf_obj_tdata *) ((bfd) -> tdata)) +#define elf_tdata(bfd) ((bfd) -> tdata.elf_obj_data) #define elf_symtab_filepos(bfd) (elf_tdata(bfd) -> symtab_filepos) #define elf_symtab_filesz(bfd) (elf_tdata(bfd) -> symtab_filesz) #define elf_strtab_filepos(bfd) (elf_tdata(bfd) -> strtab_filepos) @@ -150,7 +151,7 @@ DEFUN(elf_swap_ehdr_in,(abfd, src, dst), Elf_External_Ehdr *src AND Elf_Internal_Ehdr *dst) { - bcopy (src -> e_ident, dst -> e_ident, EI_NIDENT); + memcpy (dst -> e_ident, src -> e_ident, EI_NIDENT); dst -> e_type = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_type); dst -> e_machine = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_machine); dst -> e_version = bfd_h_get_32 (abfd, (bfd_byte *) src -> e_version); @@ -223,7 +224,7 @@ DEFUN(bfd_section_from_shdr, (abfd, hdr, shstrtab), name = hdr -> sh_name ? shstrtab + hdr -> sh_name : "unnamed"; newsect = bfd_make_section (abfd, name); newsect -> vma = hdr -> sh_addr; - newsect -> size = hdr -> sh_size; + newsect -> _raw_size = hdr -> sh_size; if (!(hdr -> sh_type == SHT_NOBITS)) { newsect -> filepos = hdr -> sh_offset; @@ -298,7 +299,7 @@ DEFUN(bfd_section_from_phdr, (abfd, hdr, index), (void) strcpy (name, namebuf); newsect = bfd_make_section (abfd, name); newsect -> vma = hdr -> p_vaddr; - newsect -> size = hdr -> p_filesz; + newsect -> _raw_size = hdr -> p_filesz; newsect -> filepos = hdr -> p_offset; newsect -> flags |= SEC_HAS_CONTENTS; if (hdr -> p_type == PT_LOAD) @@ -324,7 +325,7 @@ DEFUN(bfd_section_from_phdr, (abfd, hdr, index), (void) strcpy (name, namebuf); newsect = bfd_make_section (abfd, name); newsect -> vma = hdr -> p_vaddr + hdr -> p_filesz; - newsect -> size = hdr -> p_memsz - hdr -> p_filesz; + newsect -> _raw_size = hdr -> p_memsz - hdr -> p_filesz; if (hdr -> p_type == PT_LOAD) { newsect -> flags |= SEC_ALLOC; @@ -362,7 +363,7 @@ DEFUN(bfd_prstatus,(abfd, descdata, descsz, filepos), newsect -> alignment_power = 2; if ((core_prstatus (abfd) = bfd_alloc (abfd, descsz)) != NULL) { - bcopy (descdata, core_prstatus (abfd), descsz); + memcpy (core_prstatus (abfd), descdata, descsz); } } } @@ -418,7 +419,7 @@ char * DEFUN(elf_core_file_failing_command, (abfd), bfd *abfd) { -#if HAVE_PROCFS +#ifdef HAVE_PROCFS if (core_prpsinfo (abfd)) { prpsinfo_t *p = core_prpsinfo (abfd); @@ -444,7 +445,7 @@ static int DEFUN(elf_core_file_failing_signal, (abfd), bfd *abfd) { -#if HAVE_PROCFS +#ifdef HAVE_PROCFS if (core_prstatus (abfd)) { return (((prstatus_t *)(core_prstatus (abfd))) -> pr_cursig); @@ -464,7 +465,7 @@ DEFUN(elf_core_file_matches_executable_p, (core_bfd, exec_bfd), bfd *core_bfd AND bfd *exec_bfd) { -#if HAVE_PROCFS +#ifdef HAVE_PROCFS char *corename; char *execname; #endif @@ -477,7 +478,7 @@ DEFUN(elf_core_file_matches_executable_p, (core_bfd, exec_bfd), return (false); } -#if HAVE_PROCFS +#ifdef HAVE_PROCFS /* If no prpsinfo, just return true. Otherwise, grab the last component of the exec'd pathname from the prpsinfo. */ @@ -587,7 +588,7 @@ DEFUN(elf_corefile_note, (abfd, hdr), if (sectname != NULL) { newsect = bfd_make_section (abfd, sectname); - newsect -> size = i_note.descsz; + newsect -> _raw_size = i_note.descsz; newsect -> filepos = filepos; newsect -> flags = SEC_ALLOC | SEC_HAS_CONTENTS; newsect -> alignment_power = 2; @@ -707,7 +708,9 @@ wrong: /* Allocate an instance of the elf_obj_tdata structure and hook it up to the tdata pointer in the bfd. */ - if ((abfd -> tdata = bfd_zalloc (abfd, sizeof (elf_obj_tdata))) == NULL) + if ((abfd -> tdata.elf_obj_data = + (elf_obj_tdata*) bfd_zalloc (abfd, sizeof (elf_obj_tdata))) + == NULL) { bfd_error = no_memory; return (NULL); @@ -882,7 +885,9 @@ wrong: /* Allocate an instance of the elf_core_tdata structure and hook it up to the tdata pointer in the bfd. */ - if ((abfd -> tdata = bfd_zalloc (abfd, sizeof (elf_core_tdata))) == NULL) + if ((abfd -> tdata.elf_core_data = + (elf_core_tdata *) bfd_zalloc (abfd, sizeof (elf_core_tdata))) + == NULL) { bfd_error = no_memory; return (NULL); @@ -1049,11 +1054,11 @@ DEFUN (elf_slurp_symbol_table, (abfd), bfd *abfd) } else if (i_sym.st_shndx == SHN_ABS) { - sym -> flags |= BSF_ABSOLUTE; +/* sym -> flags |= BSF_ABSOLUTE; OBSOLETE */ } else if (i_sym.st_shndx == SHN_COMMON) { - sym -> flags |= BSF_FORT_COMM; + sym -> section = &bfd_com_section; } switch (ELF_ST_BIND (i_sym.st_info)) { @@ -1256,6 +1261,8 @@ DEFUN (elf_sizeof_headers, (abfd, reloc), #define elf_bfd_debug_info_start bfd_void #define elf_bfd_debug_info_end bfd_void #define elf_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void +#define elf_bfd_get_relocated_section_contents \ + bfd_generic_get_relocated_section_contents bfd_target elf_big_vec = { diff --git a/bfd/ieee.c b/bfd/ieee.c index dd4478a6886..28dd40e4290 100644 --- a/bfd/ieee.c +++ b/bfd/ieee.c @@ -185,19 +185,21 @@ DEFUN(read_id,(ieee), } static void -DEFUN(ieee_write_expression,(abfd, value, section, symbol, pcrel, index), +DEFUN(ieee_write_expression,(abfd, value,/* section,*/ symbol, pcrel, index), bfd*abfd AND bfd_vma value AND - asection *section AND +/* asection *section AND*/ asymbol *symbol AND boolean pcrel AND unsigned int index) { + asection *section; + unsigned int plus_count = 0; if (value != 0) ieee_write_int(abfd, value); - if (section != (asection *)NULL) { + if (section != &bfd_abs_section) { plus_count++; ieee_write_byte(abfd, ieee_variable_R_enum); ieee_write_byte(abfd, section->index +IEEE_SECTION_NUMBER_BASE); @@ -207,8 +209,8 @@ DEFUN(ieee_write_expression,(abfd, value, section, symbol, pcrel, index), if (symbol != (asymbol *)NULL) { plus_count++; - if ((symbol->flags & BSF_UNDEFINED ) || - (symbol->flags & BSF_FORT_COMM)) { + if ((symbol->section == &bfd_und_section) || + (symbol->section == &bfd_com_section)) { ieee_write_byte(abfd, ieee_variable_X_enum); ieee_write_int(abfd, symbol->value); } @@ -219,8 +221,8 @@ DEFUN(ieee_write_expression,(abfd, value, section, symbol, pcrel, index), else if (symbol->flags & BSF_LOCAL) { /* This is a reference to a defined local symbol, We can easily do a local as a section+offset */ - if (symbol->section != (asection *)NULL) { - /* If this symbol is not absolute, add the base of it */ + if (bfd_symbol_is_absolute(symbol) == false) { + /* If this symbol is not absolute, add the base of it */ ieee_write_byte(abfd, ieee_variable_R_enum); /* or L */ ieee_write_byte(abfd, symbol->section->index + IEEE_SECTION_NUMBER_BASE); @@ -369,10 +371,10 @@ static ieee_symbol_index_type NOSYMBOL = { 0, 0}; static void -DEFUN(parse_expression,(ieee, value, section, symbol, pcrel, extra), +DEFUN(parse_expression,(ieee, value,/* section,*/ symbol, pcrel, extra), ieee_data_type *ieee AND bfd_vma *value AND - asection **section AND +/* asection **section AND*/ ieee_symbol_index_type *symbol AND boolean *pcrel AND unsigned int *extra) @@ -383,7 +385,8 @@ DEFUN(parse_expression,(ieee, value, section, symbol, pcrel, extra), #define NOS sp[-1] #define INC sp++; #define DEC sp--; - + asection **section; + boolean loop = true; ieee_value_type stack[10]; @@ -423,7 +426,7 @@ DEFUN(parse_expression,(ieee, value, section, symbol, pcrel, extra), next_byte(&(ieee->h)); PUSH(NOSYMBOL, 0, - ieee->section_table[must_parse_int(&(ieee->h))]->size); + ieee->section_table[must_parse_int(&(ieee->h))]->_cooked_size); break; case ieee_variable_I_enum: case ieee_variable_X_enum: @@ -501,9 +504,9 @@ DEFUN(parse_expression,(ieee, value, section, symbol, pcrel, extra), #define ieee_seek(abfd, offset) \ - ieee_data(abfd)->h.input_p = ieee_data(abfd)->h.first_byte + offset + IEEE_DATA(abfd)->h.input_p = IEEE_DATA(abfd)->h.first_byte + offset -#define ieee_pos(abfd) ieee_data(abfd)->h.input_p -ieee_data(abfd)->h.first_byte +#define ieee_pos(abfd) IEEE_DATA(abfd)->h.input_p -IEEE_DATA(abfd)->h.first_byte static unsigned int last_index; @@ -545,7 +548,7 @@ static void DEFUN(ieee_slurp_external_symbols,(abfd), bfd *abfd) { - ieee_data_type *ieee = ieee_data(abfd); + ieee_data_type *ieee = IEEE_DATA(abfd); file_ptr offset = ieee->w.r.external_part; @@ -628,16 +631,13 @@ DEFUN(ieee_slurp_external_symbols,(abfd), symbol_name_index = must_parse_int(&(ieee->h)); parse_expression(ieee, &symbol->symbol.value, - &symbol->symbol.section, +/* &symbol->symbol.section,*/ &symbol_ignore, &pcrel_ignore, &extra); - if (symbol->symbol.section != (asection *)NULL) { + symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT; - } - else { - symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT | BSF_ABSOLUTE; - } + } break; case ieee_weak_external_reference_enum: @@ -653,7 +653,7 @@ DEFUN(ieee_slurp_external_symbols,(abfd), value = 0; } /* This turns into a common */ - symbol->symbol.flags = BSF_FORT_COMM; + symbol->symbol.section = &bfd_com_section; symbol->symbol.value = size; } break; @@ -669,9 +669,9 @@ DEFUN(ieee_slurp_external_symbols,(abfd), symbol->symbol.the_bfd = abfd; symbol->symbol.name = read_id(&(ieee->h)); symbol->symbol.udata = (PTR)NULL; - symbol->symbol.section = (asection *)NULL; + symbol->symbol.section = &bfd_und_section; symbol->symbol.value = (bfd_vma)0; - symbol->symbol.flags = BSF_UNDEFINED; + symbol->symbol.flags = 0; BFD_ASSERT (symbol->index >= ieee->external_reference_min_index); break; @@ -717,9 +717,9 @@ static void DEFUN(ieee_slurp_symbol_table,(abfd), bfd *abfd) { - if (ieee_data(abfd)->read_symbols == false) { + if (IEEE_DATA(abfd)->read_symbols == false) { ieee_slurp_external_symbols(abfd); - ieee_data(abfd)->read_symbols= true; + IEEE_DATA(abfd)->read_symbols= true; } } @@ -747,14 +747,14 @@ DEFUN(ieee_get_symtab,(abfd, location), ieee_symbol_type *symp; static bfd dummy_bfd; static asymbol empty_symbol = - { &dummy_bfd," ieee empty",(symvalue)0,BSF_DEBUGGING | BSF_ABSOLUTE}; + { &dummy_bfd," ieee empty",(symvalue)0,BSF_DEBUGGING }; if (abfd->symcount) { - ieee_data_type *ieee = ieee_data(abfd); + ieee_data_type *ieee = IEEE_DATA(abfd); dummy_bfd.xvec= &ieee_vec; ieee_slurp_symbol_table(abfd); @@ -769,7 +769,7 @@ if (abfd->symcount) { ieee->external_symbol_base_offset= - ieee->external_symbol_min_index; - for (symp = ieee_data(abfd)->external_symbols; + for (symp = IEEE_DATA(abfd)->external_symbols; symp != (ieee_symbol_type *)NULL; symp = symp->next) { /* Place into table at correct index locations */ @@ -781,7 +781,7 @@ if (abfd->symcount) { ieee->external_reference_base_offset = - ieee->external_reference_min_index +ieee->external_symbol_count ; - for (symp = ieee_data(abfd)->external_reference; + for (symp = IEEE_DATA(abfd)->external_reference; symp != (ieee_symbol_type *)NULL; symp = symp->next) { location[symp->index + ieee->external_reference_base_offset] = @@ -815,7 +815,7 @@ static void DEFUN(ieee_slurp_sections,(abfd), bfd *abfd) { - ieee_data_type *ieee = ieee_data(abfd); + ieee_data_type *ieee = IEEE_DATA(abfd); file_ptr offset = ieee->w.r.section_part; asection *section = (asection *)NULL; @@ -923,11 +923,11 @@ DEFUN(ieee_slurp_sections,(abfd), switch (t) { case ieee_section_size_enum: section = ieee->section_table[must_parse_int(&(ieee->h))]; - section->size = must_parse_int(&(ieee->h)); + section->_raw_size = must_parse_int(&(ieee->h)); break; case ieee_physical_region_size_enum: section = ieee->section_table[must_parse_int(&(ieee->h))]; - section->size = must_parse_int(&(ieee->h)); + section->_raw_size = must_parse_int(&(ieee->h)); break; case ieee_region_base_address_enum: section = ieee->section_table[must_parse_int(&(ieee->h))]; @@ -975,10 +975,10 @@ DEFUN(ieee_archive_p,(abfd), uint8e_type buffer[512]; int buffer_offset = 0; - ieee_ar_data_type *save = ieee_ar_data(abfd); + ieee_ar_data_type *save = IEEE_AR_DATA(abfd); ieee_ar_data_type *ieee ; - set_tdata(abfd, bfd_alloc(abfd, sizeof(ieee_ar_data_type))); - ieee= ieee_ar_data(abfd); + abfd->tdata.ieee_ar_data = (ieee_ar_data_type *)bfd_alloc(abfd, sizeof(ieee_ar_data_type)); + ieee= IEEE_AR_DATA(abfd); bfd_read((PTR)buffer, 1, sizeof(buffer), abfd); @@ -994,7 +994,7 @@ uint8e_type buffer[512]; library= read_id(&(ieee->h)); if (strcmp(library , "LIBRARY") != 0) { bfd_release(abfd, ieee); - set_tdata (abfd, save); + abfd->tdata.ieee_ar_data = save; return (bfd_target *)NULL; } /* Throw away the filename */ @@ -1066,7 +1066,7 @@ static boolean DEFUN(ieee_mkobject,(abfd), bfd *abfd) { - set_tdata (abfd, bfd_zalloc(abfd,sizeof(ieee_data_type))); +abfd->tdata.ieee_data = (ieee_data_type *)bfd_zalloc(abfd,sizeof(ieee_data_type)); return true; @@ -1080,10 +1080,10 @@ DEFUN(ieee_object_p,(abfd), unsigned int part; ieee_data_type *ieee; uint8e_type buffer[300]; - ieee_data_type *save = ieee_data(abfd); - set_tdata (abfd, 0); + ieee_data_type *save = IEEE_DATA(abfd); + abfd->tdata.ieee_data = 0; ieee_mkobject(abfd); - ieee = ieee_data(abfd); + ieee = IEEE_DATA(abfd); /* Read the first few bytes in to see if it makes sense */ bfd_read((PTR)buffer, 1, sizeof(buffer), abfd); @@ -1155,16 +1155,16 @@ DEFUN(ieee_object_p,(abfd), quickly. We can work out how big the file is from the trailer record */ - ieee_data(abfd)->h.first_byte = (uint8e_type *) bfd_alloc(ieee->h.abfd, ieee->w.r.me_record + IEEE_DATA(abfd)->h.first_byte = (uint8e_type *) bfd_alloc(ieee->h.abfd, ieee->w.r.me_record + 50); bfd_seek(abfd, 0, 0); - bfd_read((PTR)(ieee_data(abfd)->h.first_byte), 1, ieee->w.r.me_record+50, abfd); + bfd_read((PTR)(IEEE_DATA(abfd)->h.first_byte), 1, ieee->w.r.me_record+50, abfd); ieee_slurp_sections(abfd); return abfd->xvec; fail: (void) bfd_release(abfd, ieee); - set_tdata (abfd, save); +abfd->tdata.ieee_data = save; return (bfd_target *)NULL; } @@ -1262,9 +1262,11 @@ DEFUN(do_one,(ieee, current_map, location_ptr,s), current_map->reloc_tail_ptr= &r->next; r->next = (ieee_reloc_type *)NULL; next_byte(&(ieee->h)); + abort(); + parse_expression(ieee, &r->relent.addend, - &r->relent.section, +/* &r->relent.section,*/ &r->symbol, &pcrel, &extra); r->relent.address = current_map->pc; @@ -1394,7 +1396,7 @@ DEFUN(ieee_slurp_section_data,(abfd), bfd *abfd) { bfd_byte *location_ptr = (bfd_byte *)NULL; - ieee_data_type *ieee = ieee_data(abfd); + ieee_data_type *ieee = IEEE_DATA(abfd); unsigned int section_number ; ieee_per_section_type *current_map = (ieee_per_section_type *)NULL; @@ -1409,7 +1411,7 @@ DEFUN(ieee_slurp_section_data,(abfd), for (s = abfd->sections; s != (asection *)NULL; s = s->next) { ieee_per_section_type *per = (ieee_per_section_type *) s->used_by_bfd; - per->data = (bfd_byte *) bfd_alloc(ieee->h.abfd, s->size); + per->data = (bfd_byte *) bfd_alloc(ieee->h.abfd, s->_raw_size); /*SUPPRESS 68*/ per->reloc_tail_ptr = (ieee_reloc_type **)&(s->relocation); @@ -1450,10 +1452,12 @@ DEFUN(ieee_slurp_section_data,(abfd), boolean pcrel; next_byte(&(ieee->h)); must_parse_int(&(ieee->h)); /* Thow away section #*/ - parse_expression(ieee, &value, &dsection, &symbol, + parse_expression(ieee, &value, +/* &dsection, */ +&symbol, &pcrel, &extra); current_map->pc = value; - BFD_ASSERT((unsigned)(value - s->vma) <= s->size); + BFD_ASSERT((unsigned)(value - s->vma) <= s->_raw_size); } break; @@ -1556,7 +1560,7 @@ DEFUN(ieee_canonicalize_reloc,(abfd, section, relptr, symbols), { /* ieee_per_section_type *p = (ieee_per_section_type *) section->used_by_bfd;*/ ieee_reloc_type *src = (ieee_reloc_type *)(section->relocation); - ieee_data_type *ieee = ieee_data(abfd); + ieee_data_type *ieee = IEEE_DATA(abfd); while (src != (ieee_reloc_type *)NULL) { /* Work out which symbol to attach it this reloc to */ @@ -1599,25 +1603,28 @@ static void DEFUN(ieee_write_section_part,(abfd), bfd *abfd) { - ieee_data_type *ieee = ieee_data(abfd); + ieee_data_type *ieee = IEEE_DATA(abfd); asection *s; ieee->w.r.section_part = bfd_tell(abfd); for (s = abfd->sections; s != (asection *)NULL; s=s->next) { - ieee_write_byte(abfd, ieee_section_type_enum); - ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE); + if (s != &bfd_abs_section) + { + + ieee_write_byte(abfd, ieee_section_type_enum); + ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE); - if (abfd->flags & EXEC_P) + if (abfd->flags & EXEC_P) { /* This image is executable, so output absolute sections */ ieee_write_byte(abfd, ieee_variable_A_enum); ieee_write_byte(abfd, ieee_variable_S_enum); } - else + else { ieee_write_byte(abfd, ieee_variable_C_enum); } - switch (s->flags &(SEC_CODE | SEC_DATA | SEC_ROM)) + switch (s->flags &(SEC_CODE | SEC_DATA | SEC_ROM)) { case SEC_CODE | SEC_LOAD: case SEC_CODE: @@ -1636,30 +1643,31 @@ DEFUN(ieee_write_section_part,(abfd), } - ieee_write_id(abfd, s->name); + ieee_write_id(abfd, s->name); #if 0 - ieee_write_int(abfd, 0); /* Parent */ - ieee_write_int(abfd, 0); /* Brother */ - ieee_write_int(abfd, 0); /* Context */ + ieee_write_int(abfd, 0); /* Parent */ + ieee_write_int(abfd, 0); /* Brother */ + ieee_write_int(abfd, 0); /* Context */ #endif - /* Alignment */ - ieee_write_byte(abfd, ieee_section_alignment_enum); - ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE); - ieee_write_int(abfd, 1 << s->alignment_power); - - /* Size */ - ieee_write_2bytes(abfd, ieee_section_size_enum); - ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE); - ieee_write_int(abfd, s->size); - if (abfd->flags & EXEC_P) { - /* Relocateable sections don't have asl records */ - /* Vma */ - ieee_write_2bytes(abfd, ieee_section_base_address_enum); - ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE); - ieee_write_int(abfd, s->vma); + /* Alignment */ + ieee_write_byte(abfd, ieee_section_alignment_enum); + ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE); + ieee_write_int(abfd, 1 << s->alignment_power); + + /* Size */ + ieee_write_2bytes(abfd, ieee_section_size_enum); + ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE); + ieee_write_int(abfd, s->_cooked_size); + if (abfd->flags & EXEC_P) { + /* Relocateable sections don't have asl records */ + /* Vma */ + ieee_write_2bytes(abfd, ieee_section_base_address_enum); + ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE); + ieee_write_int(abfd, s->vma); + } + } + } - - } } @@ -1688,19 +1696,19 @@ DEFUN(do_with_relocs,(abfd, s), ieee_write_twobyte(abfd, ieee_set_current_pc_enum); ieee_write_byte(abfd, s->index + IEEE_SECTION_NUMBER_BASE); - ieee_write_expression(abfd, 0, s, 0, 0, 0); + ieee_write_expression(abfd, 0,/* s,!!!!*/ 0, 0, 0); if (relocs_to_go == 0) { /* If there arn't any relocations then output the load constant byte opcode rather than the load with relocation opcode */ - while (current_byte_index < s->size) { + while (current_byte_index < s->_cooked_size) { bfd_size_type run; unsigned int MAXRUN = 32; run = MAXRUN; - if (run > s->size - current_byte_index) { - run = s->size - current_byte_index; + if (run > s->_cooked_size - current_byte_index) { + run = s->_cooked_size - current_byte_index; } if (run != 0) { @@ -1726,10 +1734,10 @@ DEFUN(do_with_relocs,(abfd, s), if ((PTR)stream == (PTR)NULL) { /* Outputting a section without data, fill it up */ - stream = (uint8e_type *)(bfd_alloc(abfd, s->size)); - memset((PTR)stream, 0, s->size); + stream = (uint8e_type *)(bfd_alloc(abfd, s->_cooked_size)); + memset((PTR)stream, 0, s->_cooked_size); } - while (current_byte_index < s->size) { + while (current_byte_index < s->_cooked_size) { bfd_size_type run; unsigned int MAXRUN = 32; if (relocs_to_go) { @@ -1738,8 +1746,8 @@ DEFUN(do_with_relocs,(abfd, s), else { run = MAXRUN; } - if (run > s->size - current_byte_index) { - run = s->size - current_byte_index; + if (run > s->_cooked_size - current_byte_index) { + run = s->_cooked_size - current_byte_index; } if (run != 0) { @@ -1786,16 +1794,17 @@ DEFUN(do_with_relocs,(abfd, s), BFD_FAIL(); } ieee_write_byte(abfd, ieee_function_either_open_b_enum); - + abort(); + if (r->sym_ptr_ptr != (asymbol **)NULL) { ieee_write_expression(abfd, r->addend + ov, - r->section, +/* !!! r->section,*/ *(r->sym_ptr_ptr), r->howto->pc_relative, s->index); } else { ieee_write_expression(abfd, r->addend + ov, - r->section, +/*!!! r->section,*/ (asymbol *)NULL, r->howto->pc_relative, s->index); } @@ -1833,7 +1842,7 @@ DEFUN(do_as_repeat, (abfd, s), ieee_write_int(abfd, s->vma ); ieee_write_byte(abfd,ieee_repeat_data_enum); - ieee_write_int(abfd, s->size); + ieee_write_int(abfd, s->_cooked_size); ieee_write_byte(abfd, ieee_load_constant_bytes_enum); ieee_write_byte(abfd, 1); ieee_write_byte(abfd, 0); @@ -1853,7 +1862,7 @@ DEFUN(do_without_relocs, (abfd, s), else { unsigned int i; - for (i = 0; i < s->size; i++) { + for (i = 0; i < s->_cooked_size; i++) { if (stream[i] != 0) { do_with_relocs(abfd, s); return; @@ -2004,7 +2013,7 @@ NEXT(); section_number = THIS(); NEXT(); - ieee= ieee_data(input_bfd); + ieee= IEEE_DATA(input_bfd); s = ieee->section_table[section_number]; if (s->output_section) { value = s->output_section->vma ; @@ -2387,7 +2396,7 @@ static void DEFUN(ieee_write_debug_part, (abfd), bfd *abfd) { - ieee_data_type *ieee = ieee_data(abfd); + ieee_data_type *ieee = IEEE_DATA(abfd); bfd_chain_type *chain = ieee->chain_root; unsigned char output_buffer[OBS]; boolean some_debug = false; @@ -2400,58 +2409,64 @@ DEFUN(ieee_write_debug_part, (abfd), if (chain == (bfd_chain_type *)NULL) { #if 0 - /* There is no debug info, so we'll fake some up */ - CONST static char fake[] = { - 0xf8, 0xa, 0, 5, 't', 't', 't', 't', 't', 0, 2, 3, - '1','.','1',0x82, 1991>>8, 1991 & 0xff, 9, 20, 11, 07,50 }; - ieee->w.r.debug_information_part = 0; + /* There is no debug info, so we'll fake some up */ + CONST static char fake[] = { + 0xf8, 0xa, 0, 5, 't', 't', 't', 't', 't', 0, 2, 3, + '1','.','1',0x82, 1991>>8, 1991 & 0xff, 9, 20, 11, 07,50 }; + ieee->w.r.debug_information_part = 0; -here; + here; -/* bfd_write(fake, 1, sizeof(fake), abfd);*/ - /* Now write a header for each section */ - { - int i = 0; - asection *s = abfd->sections; - while (s) { - ieee_write_byte(abfd, 0xf8); - ieee_write_byte(abfd, 0x0b); - ieee_write_byte(abfd, 0); - ieee_write_byte(abfd, 0); - ieee_write_byte(abfd, 1); - ieee_write_byte(abfd, i + IEEE_SECTION_NUMBER_BASE); - ieee_write_expression(abfd, 0, s, 0, 0, 0); - ieee_write_byte(abfd,0); - ieee_write_byte(abfd, 0xf9); - ieee_write_expression(abfd, s->size, 0, 0, 0, 0); + /* bfd_write(fake, 1, sizeof(fake), abfd);*/ + /* Now write a header for each section */ + { + int i = 0; + asection *s = abfd->sections; + while (s) { + if (s != abfd->abs_section) + { + + ieee_write_byte(abfd, 0xf8); + ieee_write_byte(abfd, 0x0b); + ieee_write_byte(abfd, 0); + ieee_write_byte(abfd, 0); + ieee_write_byte(abfd, 1); + ieee_write_byte(abfd, i + IEEE_SECTION_NUMBER_BASE); + ieee_write_expression(abfd, 0, s, 0, 0, 0); + ieee_write_byte(abfd,0); + ieee_write_byte(abfd, 0xf9); + ieee_write_expression(abfd, s->size, 0, 0, 0, 0); + i++; + } + s = s->next; - i++; + } - /* Close the scope */ - ieee_write_byte(abfd, 0xf9); - } + /* Close the scope */ + ieee_write_byte(abfd, 0xf9); + } #endif - } + } else{ - while (chain != (bfd_chain_type *)NULL) { - bfd *entry = chain->this; - ieee_data_type *entry_ieee = ieee_data(entry); - if (entry_ieee->w.r.debug_information_part) { - bfd_seek(entry, entry_ieee->w.r.debug_information_part, SEEK_SET); - relocate_debug(abfd, entry); - } + while (chain != (bfd_chain_type *)NULL) { + bfd *entry = chain->this; + ieee_data_type *entry_ieee = IEEE_DATA(entry); + if (entry_ieee->w.r.debug_information_part) { + bfd_seek(entry, entry_ieee->w.r.debug_information_part, SEEK_SET); + relocate_debug(abfd, entry); + } - chain = chain->next; - } - if (some_debug) { - ieee->w.r.debug_information_part = here; - } - else { - ieee->w.r.debug_information_part = 0; + chain = chain->next; + } + if (some_debug) { + ieee->w.r.debug_information_part = here; + } + else { + ieee->w.r.debug_information_part = 0; + } } - } flush(); } @@ -2461,7 +2476,7 @@ DEFUN(ieee_write_data_part,(abfd), bfd *abfd) { asection *s; - ieee_data_type *ieee = ieee_data(abfd); + ieee_data_type *ieee = IEEE_DATA(abfd); ieee->w.r.data_part = bfd_tell(abfd); for (s = abfd->sections; s != (asection *)NULL; s = s->next) { @@ -2486,8 +2501,8 @@ DEFUN(init_for_output,(abfd), { asection *s; for (s = abfd->sections; s != (asection *)NULL; s = s->next) { - if (s->size != 0) { - ieee_per_section(s)->data = (bfd_byte *)(bfd_alloc(abfd, s->size)); + if (s->_cooked_size != 0) { + ieee_per_section(s)->data = (bfd_byte *)(bfd_alloc(abfd, s->_cooked_size)); } } } @@ -2525,7 +2540,7 @@ DEFUN(ieee_write_external_part,(abfd), bfd *abfd) { asymbol **q; - ieee_data_type *ieee = ieee_data(abfd); + ieee_data_type *ieee = IEEE_DATA(abfd); unsigned int reference_index = IEEE_REFERENCE_BASE; unsigned int public_index = IEEE_PUBLIC_BASE+2; @@ -2536,7 +2551,7 @@ DEFUN(ieee_write_external_part,(abfd), for (q = abfd->outsymbols; *q != (asymbol *)NULL; q++) { asymbol *p = *q; hadone = true; - if (p->flags & BSF_UNDEFINED) { + if (p->section == &bfd_und_section) { /* This must be a symbol reference .. */ ieee_write_byte(abfd, ieee_external_reference_enum); ieee_write_int(abfd, reference_index); @@ -2544,7 +2559,7 @@ DEFUN(ieee_write_external_part,(abfd), p->value = reference_index; reference_index++; } - else if(p->flags & BSF_FORT_COMM) { + else if(p->section == &bfd_com_section) { /* This is a weak reference */ ieee_write_byte(abfd, ieee_external_reference_enum); ieee_write_int(abfd, reference_index); @@ -2574,28 +2589,28 @@ DEFUN(ieee_write_external_part,(abfd), /* Write out the value */ ieee_write_2bytes(abfd, ieee_value_record_enum); ieee_write_int(abfd, public_index); - if (p->section != (asection *)NULL) + if (p->section != &bfd_abs_section) { if (abfd->flags & EXEC_P) - { - /* If fully linked, then output all symbols - relocated */ - ieee_write_int(abfd, - p->value + p->section->output_offset+ p->section->output_section->vma); + { + /* If fully linked, then output all symbols + relocated */ + ieee_write_int(abfd, + p->value + p->section->output_offset+ p->section->output_section->vma); - } - else { - ieee_write_expression(abfd, - p->value + p->section->output_offset, - p->section->output_section, - (asymbol *)NULL, false, 0); } + else { + ieee_write_expression(abfd, + p->value + p->section->output_offset, +/*!!! p->section->output_section,*/ + (asymbol *)NULL, false, 0); + } } else { ieee_write_expression(abfd, p->value, - (asection *)NULL, +/*!!! (asection *)NULL,*/ (asymbol *)NULL, false, 0); } p->value = public_index; @@ -2639,7 +2654,7 @@ void DEFUN(ieee_write_me_part,(abfd), bfd *abfd) { - ieee_data_type *ieee= ieee_data(abfd); + ieee_data_type *ieee= IEEE_DATA(abfd); ieee->w.r.trailer_part = bfd_tell(abfd); if (abfd->start_address) { ieee->w.r.me_record = bfd_tell(abfd); @@ -2658,7 +2673,7 @@ boolean DEFUN(ieee_write_object_contents,(abfd), bfd *abfd) { - ieee_data_type *ieee = ieee_data(abfd); + ieee_data_type *ieee = IEEE_DATA(abfd); unsigned int i; file_ptr old; /* Fast forward over the header area */ @@ -2695,7 +2710,7 @@ DEFUN(ieee_write_object_contents,(abfd), else ieee_write_byte(abfd, 0x2); /* Relocateable */ - ieee->w.r.envimental_record = bfd_tell(abfd); + ieee->w.r.environmental_record = bfd_tell(abfd); bfd_write(envi, 1, sizeof(envi), abfd); output_bfd = abfd; flush(); @@ -2768,7 +2783,7 @@ DEFUN(ieee_openr_next_archived_file,(arch, prev), bfd *arch AND bfd *prev) { - ieee_ar_data_type *ar = ieee_ar_data(arch); + ieee_ar_data_type *ar = IEEE_AR_DATA(arch); /* take the next one from the arch state, or reset */ if (prev == (bfd *)NULL) { /* Reset the index - the first two entries are bogus*/ @@ -2819,7 +2834,7 @@ ieee_generic_stat_arch_elt(abfd, buf) bfd *abfd; struct stat *buf; { - ieee_ar_data_type *ar = ieee_ar_data(abfd); + ieee_ar_data_type *ar = IEEE_AR_DATA(abfd); if (ar == (ieee_ar_data_type *)NULL) { bfd_error = invalid_operation; return -1; @@ -2863,8 +2878,8 @@ DEFUN(ieee_bfd_debug_info_accumulate,(abfd, section), bfd *abfd AND asection *section) { - ieee_data_type *ieee = ieee_data(section->owner); - ieee_data_type *output_ieee = ieee_data(abfd); + ieee_data_type *ieee = IEEE_DATA(section->owner); + ieee_data_type *output_ieee = IEEE_DATA(abfd); /* can only accumulate data from other ieee bfds */ if (section->owner->xvec != abfd->xvec) return; @@ -2911,6 +2926,7 @@ DEFUN(ieee_bfd_debug_info_accumulate,(abfd, section), #define ieee_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr #define ieee_close_and_cleanup bfd_generic_close_and_cleanup #define ieee_set_arch_mach bfd_default_set_arch_mach +#define ieee_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents /*SUPPRESS 460 */ bfd_target ieee_vec = @@ -2922,7 +2938,7 @@ bfd_target ieee_vec = (HAS_RELOC | EXEC_P | /* object flags */ HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED), - (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS + ( SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ diff --git a/bfd/libbfd.h b/bfd/libbfd.h index 08b2170384c..81f327d778c 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -46,7 +46,7 @@ struct artdata { char *extended_names; /* clever intel extension */ }; -#define bfd_ardata(bfd) ((struct artdata *) ((bfd)->tdata)) +#define bfd_ardata(bfd) ((bfd)->tdata.aout_ar_data) /* Goes in bfd's arelt_data slot */ struct areltdata { @@ -189,11 +189,16 @@ extern bfd *bfd_last_cache; /* And more follows */ void EXFUN(bfd_check_init, (void)); +PTR EXFUN(bfd_xmalloc, ( bfd_size_type size)); +void EXFUN(bfd_write_bigendian_4byte_int, (bfd *abfd, int i)); bfd_vma EXFUN(bfd_log2, (bfd_vma x)); void EXFUN(bfd_check_init, (void)); +PTR EXFUN(bfd_xmalloc, ( bfd_size_type size)); +void EXFUN(bfd_write_bigendian_4byte_int, (bfd *abfd, int i)); bfd_vma EXFUN(bfd_log2, (bfd_vma x)); #define BFD_CACHE_MAX_OPEN 10 extern bfd *bfd_last_cache; + #define bfd_cache_lookup(x) \ ((x)==bfd_last_cache? \ (FILE*)(bfd_last_cache->iostream): \ @@ -203,17 +208,23 @@ void EXFUN(bfd_cache_close , (bfd *)); FILE* EXFUN(bfd_open_file, (bfd *)); FILE *EXFUN(bfd_cache_lookup_worker, (bfd *)); void EXFUN(bfd_constructor_entry, (bfd *abfd, -asymbol **symbol_ptr_ptr, -CONST char*type)); + asymbol **symbol_ptr_ptr, + CONST char*type)); CONST struct reloc_howto_struct *EXFUN(bfd_default_reloc_type_lookup -, (CONST struct bfd_arch_info *, -bfd_reloc_code_type code)); + , (CONST struct bfd_arch_info *, + bfd_reloc_code_type code)); +bfd_byte * +EXFUN(bfd_generic_get_relocated_section_contents, (bfd *abfd, + struct bfd_seclet_struct *seclet) + + ); +extern bfd_arch_info_type bfd_default_arch_struct; boolean EXFUN(bfd_default_set_arch_mach, (bfd *abfd, -enum bfd_architecture arch, -unsigned long mach)); + enum bfd_architecture arch, + unsigned long mach)); void EXFUN(bfd_arch_init, (void)); void EXFUN(bfd_arch_linkin, (bfd_arch_info_type *)); CONST bfd_arch_info_type *EXFUN(bfd_default_compatible -, (CONST bfd_arch_info_type *a, -CONST bfd_arch_info_type *b)); + , (CONST bfd_arch_info_type *a, + CONST bfd_arch_info_type *b)); boolean EXFUN(bfd_default_scan, (CONST struct bfd_arch_info *, CONST char *)); diff --git a/bfd/oasys.c b/bfd/oasys.c index e5e34e68c7c..7a7d1d4e6d3 100644 --- a/bfd/oasys.c +++ b/bfd/oasys.c @@ -21,10 +21,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* $Id$ */ #define UNDERSCORE_HACK 1 -#include -#include - #include "bfd.h" +#include "sysdep.h" #include "libbfd.h" #include "oasys.h" #include "liboasys.h" @@ -83,7 +81,7 @@ DEFUN(oasys_slurp_symbol_table,(abfd), bfd * CONST abfd) { oasys_record_union_type record; - oasys_data_type *data = oasys_data(abfd); + oasys_data_type *data = OASYS_DATA(abfd); boolean loop = true; asymbol *dest_defined; asymbol *dest; @@ -118,7 +116,7 @@ DEFUN(oasys_slurp_symbol_table,(abfd), case oasys_record_is_local_enum: case oasys_record_is_symbol_enum: { - int flag = record.header.type == oasys_record_is_local_enum ? + int flag = record.header.type == (int)oasys_record_is_local_enum ? (BSF_LOCAL) : (BSF_GLOBAL | BSF_EXPORT); @@ -126,15 +124,16 @@ DEFUN(oasys_slurp_symbol_table,(abfd), switch (record.symbol.relb & RELOCATION_TYPE_BITS) { case RELOCATION_TYPE_ABS: dest = dest_defined--; - dest->section = 0; - dest->flags = BSF_ABSOLUTE | flag; + dest->section = &bfd_abs_section; + dest->flags = 0; + break; case RELOCATION_TYPE_REL: dest = dest_defined--; dest->section = - oasys_data(abfd)->sections[record.symbol.relb & + OASYS_DATA(abfd)->sections[record.symbol.relb & RELOCATION_SECT_BITS]; - if (record.header.type == oasys_record_is_local_enum) + if (record.header.type == (int)oasys_record_is_local_enum) { dest->flags = BSF_LOCAL; if (dest->section ==(asection *)(~0)) { @@ -151,16 +150,15 @@ DEFUN(oasys_slurp_symbol_table,(abfd), break; case RELOCATION_TYPE_UND: dest = data->symbols + bfd_h_get_16(abfd, (bfd_byte *)&record.symbol.refno[0]); - dest->section = (asection *)NULL; - dest->flags = BSF_UNDEFINED; + dest->section = &bfd_und_section; break; case RELOCATION_TYPE_COM: dest = dest_defined--; dest->name = string_ptr; dest->the_bfd = abfd; - dest->section = (asection *)NULL; - dest->flags = BSF_FORT_COMM; + dest->section = &bfd_com_section; + break; default: dest = dest_defined--; @@ -216,7 +214,7 @@ DEFUN(oasys_get_symtab,(abfd, location), if (oasys_slurp_symbol_table(abfd) == false) { return 0; } - symbase = oasys_data(abfd)->symbols; + symbase = OASYS_DATA(abfd)->symbols; for (counter = 0; counter < abfd->symcount; counter++) { *(location++) = symbase++; } @@ -279,7 +277,7 @@ DEFUN(oasys_archive_p,(abfd), oasys_module_table_type record; - set_tdata(abfd, ar); + abfd->tdata.oasys_ar_data = ar; ar->module = module; ar->module_count = header.mod_count; @@ -350,8 +348,7 @@ DEFUN(oasys_mkobject,(abfd), bfd *abfd) { - set_tdata (abfd, - (oasys_data_type*)bfd_alloc(abfd, sizeof(oasys_data_type))); + abfd->tdata.oasys_obj_data = (oasys_data_type*)bfd_alloc(abfd, sizeof(oasys_data_type)); return true; } @@ -361,13 +358,13 @@ DEFUN(oasys_object_p,(abfd), bfd *abfd) { oasys_data_type *oasys; - oasys_data_type *save = oasys_data(abfd); + oasys_data_type *save = OASYS_DATA(abfd); boolean loop = true; boolean had_usefull = false; - set_tdata (abfd, 0); + abfd->tdata.oasys_obj_data = 0; oasys_mkobject(abfd); - oasys = oasys_data(abfd); + oasys = OASYS_DATA(abfd); memset((PTR)oasys->sections, 0xff, sizeof(oasys->sections)); /* Point to the start of the file */ @@ -418,7 +415,7 @@ DEFUN(oasys_object_p,(abfd), BFD_FAIL(); } - s->size = bfd_h_get_32(abfd, (bfd_byte *) & record.section.value[0]) ; + s->_raw_size = bfd_h_get_32(abfd, (bfd_byte *) & record.section.value[0]) ; s->vma = bfd_h_get_32(abfd, (bfd_byte *)&record.section.vma[0]); s->flags= 0; had_usefull = true; @@ -442,8 +439,7 @@ DEFUN(oasys_object_p,(abfd), Oasys support several architectures, but I can't see a simple way to discover which one is in a particular file - we'll guess */ - abfd->obj_arch = bfd_arch_m68k; - abfd->obj_machine =0; + bfd_default_set_arch_mach(abfd, bfd_arch_m68k, 0); if (abfd->symcount != 0) { abfd->flags |= HAS_SYMS; } @@ -459,7 +455,7 @@ DEFUN(oasys_object_p,(abfd), fail: (void) bfd_release(abfd, oasys); - set_tdata (abfd, save); + abfd->tdata.oasys_obj_data = save; return (bfd_target *)NULL; } @@ -469,19 +465,20 @@ DEFUN(oasys_print_symbol,(ignore_abfd, afile, symbol, how), bfd *ignore_abfd AND PTR afile AND asymbol *symbol AND - bfd_print_symbol_enum_type how) + bfd_print_symbol_type how) { FILE *file = (FILE *)afile; switch (how) { - case bfd_print_symbol_name_enum: - case bfd_print_symbol_type_enum: + case bfd_print_symbol_name: + case bfd_print_symbol_more: fprintf(file,"%s", symbol->name); break; - case bfd_print_symbol_all_enum: + case bfd_print_symbol_all: + case bfd_print_symbol_nm: { -CONST char *section_name = symbol->section == (asection *)NULL ? - "*abs" : symbol->section->name; + CONST char *section_name = symbol->section == (asection *)NULL ? + (CONST char *) "*abs" : symbol->section->name; bfd_print_symbol_vandf((PTR)file,symbol); @@ -511,7 +508,7 @@ DEFUN(oasys_slurp_section_data,(abfd), bfd *CONST abfd) { oasys_record_union_type record; - oasys_data_type *data = oasys_data(abfd); + oasys_data_type *data = OASYS_DATA(abfd); boolean loop = true; oasys_per_section_type *per ; @@ -552,7 +549,7 @@ DEFUN(oasys_slurp_section_data,(abfd), if (per->initialized == false) { - per->data = (bfd_byte *) bfd_zalloc(abfd, section->size); + per->data = (bfd_byte *) bfd_zalloc(abfd, section->_raw_size); per->reloc_tail_ptr = (oasys_reloc_type **)&(section->relocation); per->had_vma = false; per->initialized = true; @@ -623,9 +620,15 @@ DEFUN(oasys_slurp_section_data,(abfd), /* There is no symbol */ r->symbol = 0; /* Work out the howto */ + abort(); +#if 0 r->relent.section = - data->sections[reloc & RELOCATION_SECT_BITS]; - r->relent.addend = - r->relent.section->vma; + data->sections[reloc & + RELOCATION_SECT_BITS]; + + r->relent.addend = - + r->relent.section->vma; +#endif r->relent.address = dst_ptr - dst_base_ptr; r->relent.howto = &howto_table[reloc>>6]; r->relent.sym_ptr_ptr = (asymbol **)NULL; @@ -658,7 +661,12 @@ DEFUN(oasys_slurp_section_data,(abfd), /* Get symbol number */ r->symbol = (src[0]<<8) | src[1]; /* Work out the howto */ - r->relent.section = (asection *)NULL; + abort(); + +#if 0 + r->relent.section = (asection + *)NULL; +#endif r->relent.addend = 0; r->relent.address = dst_ptr - dst_base_ptr; r->relent.howto = &howto_table[reloc>>6]; @@ -766,10 +774,15 @@ DEFUN(oasys_canonicalize_reloc,(ignore_abfd, section, relptr, symbols), unsigned int reloc_count = 0; oasys_reloc_type *src = (oasys_reloc_type *)(section->relocation); while (src != (oasys_reloc_type *)NULL) { + abort(); + +#if 0 if (src->relent.section == (asection *)NULL) { src->relent.sym_ptr_ptr = symbols + src->symbol; } +#endif + *relptr ++ = &src->relent; src = src->next; reloc_count++; @@ -779,17 +792,6 @@ DEFUN(oasys_canonicalize_reloc,(ignore_abfd, section, relptr, symbols), } -boolean -DEFUN(oasys_set_arch_mach, (abfd, arch, machine), - bfd *abfd AND - enum bfd_architecture arch AND - unsigned long machine) -{ - abfd->obj_arch = arch; - abfd->obj_machine = machine; - return true; -} - /* Writing */ @@ -807,7 +809,7 @@ DEFUN(oasys_write_record,(abfd, type, record, size), size_t i; uint8e_type *ptr; record->header.length = size; - record->header.type = type; + record->header.type = (int)type; record->header.check_sum = 0; record->header.fill = 0; ptr = &record->pad[0]; @@ -837,17 +839,17 @@ DEFUN(oasys_write_syms, (abfd), char *dst = symbol.name; unsigned int l = 0; - if (g->flags & BSF_FORT_COMM) { + if (g->section == & bfd_com_section) { symbol.relb = RELOCATION_TYPE_COM; bfd_h_put_16(abfd, index, (uint8e_type *)(&symbol.refno[0])); index++; } - else if (g->flags & BSF_ABSOLUTE) { + else if (g->section == & bfd_abs_section) { symbol.relb = RELOCATION_TYPE_ABS; bfd_h_put_16(abfd, 0, (uint8e_type *)(&symbol.refno[0])); } - else if (g->flags & BSF_UNDEFINED) { + else if (g->section == &bfd_und_section) { symbol.relb = RELOCATION_TYPE_UND ; bfd_h_put_16(abfd, index, (uint8e_type *)(&symbol.refno[0])); /* Overload the value field with the output index number */ @@ -909,7 +911,7 @@ DEFUN(oasys_write_sections, (abfd), s->name); } out.relb = RELOCATION_TYPE_REL | s->target_index; - bfd_h_put_32(abfd, s->size, (bfd_byte *) out.value); + bfd_h_put_32(abfd, s->_cooked_size, (bfd_byte *) out.value); bfd_h_put_32(abfd, s->vma, (bfd_byte *) out.vma); oasys_write_record(abfd, @@ -1003,7 +1005,7 @@ DEFUN(oasys_write_data, (abfd), current_byte_index = 0; processed_data.relb = s->target_index | RELOCATION_TYPE_REL; - while (current_byte_index < s->size) + while (current_byte_index < s->_cooked_size) { /* Scan forwards by eight bytes or however much is left and see if there are any relocations going on */ @@ -1015,8 +1017,8 @@ DEFUN(oasys_write_data, (abfd), bfd_h_put_32(abfd, s->vma + current_byte_index, processed_data.addr); - if ((size_t)(long_length + current_byte_index) > (size_t)(s->size)) { - long_length = s->size - current_byte_index; + if ((size_t)(long_length + current_byte_index) > (size_t)(s->_cooked_size)) { + long_length = s->_cooked_size - current_byte_index; } while (long_length > 0 && (dst - (uint8e_type*)&processed_data < 128)) { @@ -1062,6 +1064,9 @@ DEFUN(oasys_write_data, (abfd), /* Is this a section relative relocation, or a symbol relative relocation ? */ + abort(); + +#if 0 if (r->section != (asection*)NULL) { /* The relent has a section attached, so it must be section @@ -1071,6 +1076,7 @@ DEFUN(oasys_write_data, (abfd), *dst++ = rel_byte; } else +#endif { asymbol *p = *(r->sym_ptr_ptr); @@ -1155,7 +1161,7 @@ DEFUN(oasys_set_section_contents,(abfd, section, location, offset, count), if (oasys_per_section(section)->data == (bfd_byte *)NULL ) { oasys_per_section(section)->data = - (bfd_byte *)(bfd_alloc(abfd,section->size)); + (bfd_byte *)(bfd_alloc(abfd,section->_cooked_size)); } (void) memcpy((PTR)(oasys_per_section(section)->data + offset), location, @@ -1195,7 +1201,7 @@ oasys_openr_next_archived_file(arch, prev) bfd *arch; bfd *prev; { - oasys_ar_data_type *ar = oasys_ar_data(arch); + oasys_ar_data_type *ar = OASYS_AR_DATA(arch); oasys_module_info_type *p; /* take the next one from the arch state, or reset */ if (prev == (bfd *)NULL) { @@ -1277,17 +1283,17 @@ return 0; #define oasys_write_armap 0 #define oasys_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr #define oasys_close_and_cleanup bfd_generic_close_and_cleanup - +#define oasys_set_arch_mach bfd_default_set_arch_mach #define oasys_bfd_debug_info_start bfd_void #define oasys_bfd_debug_info_end bfd_void #define oasys_bfd_debug_info_accumulate (FOO(void, (*), (bfd *, asection *)))bfd_void - +#define oasys_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents /*SUPPRESS 460 */ bfd_target oasys_vec = { "oasys", /* name */ - bfd_target_oasys_flavour_enum, + bfd_target_oasys_flavour, true, /* target byte order */ true, /* target headers byte order */ (HAS_RELOC | EXEC_P | /* object flags */ diff --git a/bfd/reloc.c b/bfd/reloc.c index e22d920104a..622d1983798 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -22,7 +22,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ SECTION Relocations -DESCRIPTION BFD maintains relocations in much the same was as it maintains symbols; they are left alone until required, then read in en-mass and traslated into an internal form. There is a common @@ -37,338 +36,299 @@ DESCRIPTION in a particuar section, and fill in the right bits: @menu -* typedef arelent:: -* howto manager:: +@* typedef arelent:: +@* howto manager:: @end menu */ #include "bfd.h" #include "sysdep.h" #include "libbfd.h" +#include "seclet.h" /*doc* -@node typedef arelent, howto manager, Relocations, Relocations +INODE + typedef arelent, howto manager, Relocations, Relocations SUBSECTION typedef arelent -*/ - -/* -FUNCTION - bfd_perform_relocation - -DESCRIPTION - The relocation routine returns as a status an enumerated type: - -.typedef enum bfd_reloc_status { - No errors detected + This is the structure of a relocation entry: +CODE_FRAGMENT +. +.typedef enum bfd_reloc_status +.{ +. {* No errors detected *} . bfd_reloc_ok, - - The relocation was performed, but there was an overflow. - +. +. {* The relocation was performed, but there was an overflow. *} . bfd_reloc_overflow, - - The address to relocate was not within the section supplied - +. +. {* The address to relocate was not within the section supplied*} . bfd_reloc_outofrange, - - Used by special functions - +. +. {* Used by special functions *} . bfd_reloc_continue, - - Unused - +. +. {* Unused *} . bfd_reloc_notsupported, - - Unsupported relocation size requested. - +. +. {* Unsupported relocation size requested. *} . bfd_reloc_other, - - The symbol to relocate against was undefined. - +. +. {* The symbol to relocate against was undefined.*} . bfd_reloc_undefined, - - The relocation was performed, but may not be ok - presently - generated only when linking i960 coff files with i960 b.out symbols. - +. +. {* The relocation was performed, but may not be ok - presently +. generated only when linking i960 coff files with i960 b.out +. symbols. *} . bfd_reloc_dangerous -. } +. } . bfd_reloc_status_type; - - +. +. .typedef struct reloc_cache_entry .{ +. {* A pointer into the canonical table of pointers *} +. struct symbol_cache_entry **sym_ptr_ptr; +. +. {* offset in section *} +. rawdata_offset address; +. +. {* addend for relocation value *} +. bfd_vma addend; +. +. {* Pointer to how to perform the required relocation *} +. CONST struct reloc_howto_struct *howto; +. +.} arelent; - A pointer into the canonical table of pointers +*/ -. struct symbol_cache_entry **sym_ptr_ptr; +/* +DESCRIPTION - offset in section + Here is a description of each of the fields within a relent: -. rawdata_offset address; + o sym_ptr_ptr - addend for relocation value + The symbol table pointer points to a pointer to the symbol + associated with the relocation request. This would naturally + be the pointer into the table returned by the back end's + get_symtab action. @xref{Symbols}. The symbol is referenced + through a pointer to a pointer so that tools like the linker + can fix up all the symbols of the same name by modifying only + one pointer. The relocation routine looks in the symbol and + uses the base of the section the symbol is attached to and the + value of the symbol as the initial relocation offset. If the + symbol pointer is zero, then the section provided is looked up. -. bfd_vma addend; + o address - if sym is null this is the section + The address field gives the offset in bytes from the base of + the section data which owns the relocation record to the first + byte of relocatable information. The actual data relocated + will be relative to this point - for example, a relocation + type which modifies the bottom two bytes of a four byte word + would not touch the first byte pointed to in a big endian + world. @item addend The addend is a value provided by the back + end to be added (!) to the relocation offset. Its + interpretation is dependent upon the howto. For example, on + the 68k the code: -. struct sec *section; - Pointer to how to perform the required relocation +| char foo[]; +| main() +| { +| return foo[0x12345678]; +| } -. CONST struct reloc_howto_struct *howto; -.} arelent; + Could be compiled into: +| linkw fp,#-4 +| moveb @@#12345678,d0 +| extbl d0 +| unlk fp +| rts -*/ -/* -DESCRIPTION + This could create a reloc pointing to foo, but leave the + offset in the data (something like) - o sym_ptr_ptr - The symbol table pointer points to a pointer to the symbol - associated with the relocation request. This would naturally - be the pointer into the table returned by the back end's - get_symtab action. @xref{Symbols}. The symbol is referenced - through a pointer to a pointer so that tools like the linker - can fix up all the symbols of the same name by modifying only - one pointer. The relocation routine looks in the symbol and - uses the base of the section the symbol is attached to and the - value of the symbol as the initial relocation offset. If the - symbol pointer is zero, then the section provided is looked up. - - o address - The address field gives the offset in bytes from the base of - the section data which owns the relocation record to the first - byte of relocatable information. The actual data relocated - will be relative to this point - for example, a relocation - type which modifies the bottom two bytes of a four byte word - would not touch the first byte pointed to in a big endian - world. @item addend The addend is a value provided by the back - end to be added (!) to the relocation offset. Its - interpretation is dependent upon the howto. For example, on - the 68k the code: - -EXAMPLE - - char foo[]; - main() - { - return foo[0x12345678]; - } -DESCRIPTION - Could be compiled into: +|RELOCATION RECORDS FOR [.text]: +|offset type value +|00000006 32 _foo +| +|00000000 4e56 fffc ; linkw fp,#-4 +|00000004 1039 1234 5678 ; moveb @@#12345678,d0 +|0000000a 49c0 ; extbl d0 +|0000000c 4e5e ; unlk fp +|0000000e 4e75 ; rts -EXAMPLE - linkw fp,#-4 - moveb @@#12345678,d0 - extbl d0 - unlk fp - rts -DESCRIPTION + Using coff and an 88k, some instructions don't have enough + space in them to represent the full address range, and + pointers have to be loaded in two parts. So you'd get something like: - This could create a reloc pointing to foo, but leave the - offset in the data (something like) -EXAMPLE -RELOCATION RECORDS FOR [.text]: -offset type value -00000006 32 _foo +| or.u r13,r0,hi16(_foo+0x12345678) +| ld.b r2,r13,lo16(_foo+0x12345678) +| jmp r1 -00000000 4e56 fffc ; linkw fp,#-4 -00000004 1039 1234 5678 ; moveb @@#12345678,d0 -0000000a 49c0 ; extbl d0 -0000000c 4e5e ; unlk fp -0000000e 4e75 ; rts -DESCRIPTION - Using coff and an 88k, some instructions don't have enough - space in them to represent the full address range, and - pointers have to be loaded in two parts. So you'd get something like: + This whould create two relocs, both pointing to _foo, and with + 0x12340000 in their addend field. The data would consist of: -EXAMPLE - or.u r13,r0,hi16(_foo+0x12345678) - ld.b r2,r13,lo16(_foo+0x12345678) - jmp r1 -DESCRIPTION - This whould create two relocs, both pointing to _foo, and with - 0x12340000 in their addend field. The data would consist of: +|RELOCATION RECORDS FOR [.text]: +|offset type value +|00000002 HVRT16 _foo+0x12340000 +|00000006 LVRT16 _foo+0x12340000 -EXAMPLE -RELOCATION RECORDS FOR [.text]: -offset type value -00000002 HVRT16 _foo+0x12340000 -00000006 LVRT16 _foo+0x12340000 +|00000000 5da05678 ; or.u r13,r0,0x5678 +|00000004 1c4d5678 ; ld.b r2,r13,0x5678 +|00000008 f400c001 ; jmp r1 -00000000 5da05678 ; or.u r13,r0,0x5678 -00000004 1c4d5678 ; ld.b r2,r13,0x5678 -00000008 f400c001 ; jmp r1 -DESCRIPTION - The relocation routine digs out the value from the data, adds - it to the addend to get the original offset and then adds the - value of _foo. Note that all 32 bits have to be kept around - somewhere, to cope with carry from bit 15 to bit 16. - - On further example is the sparc and the a.out format. The - sparc has a similar problem to the 88k, in that some - instructions don't have room for an entire offset, but on the - sparc the parts are created odd sized lumps. The designers of - the a.out format chose not to use the data within the section - for storing part of the offset; all the offset is kept within - the reloc. Any thing in the data should be ignored. -EXAMPLE - save %sp,-112,%sp - sethi %hi(_foo+0x12345678),%g2 - ldsb [%g2+%lo(_foo+0x12345678)],%i0 - ret - restore + The relocation routine digs out the value from the data, adds + it to the addend to get the original offset and then adds the + value of _foo. Note that all 32 bits have to be kept around + somewhere, to cope with carry from bit 15 to bit 16. -DESCRIPTION - Both relocs contains a pointer to foo, and the offsets would - contain junk. + On further example is the sparc and the a.out format. The + sparc has a similar problem to the 88k, in that some + instructions don't have room for an entire offset, but on the + sparc the parts are created odd sized lumps. The designers of + the a.out format chose not to use the data within the section + for storing part of the offset; all the offset is kept within + the reloc. Any thing in the data should be ignored. -EXAMPLE +| save %sp,-112,%sp +| sethi %hi(_foo+0x12345678),%g2 +| ldsb [%g2+%lo(_foo+0x12345678)],%i0 +| ret +| restore -RELOCATION RECORDS FOR [.text]: -offset type value -00000004 HI22 _foo+0x12345678 -00000008 LO10 _foo+0x12345678 + Both relocs contains a pointer to foo, and the offsets would + contain junk. -00000000 9de3bf90 ; save %sp,-112,%sp -00000004 05000000 ; sethi %hi(_foo+0),%g2 -00000008 f048a000 ; ldsb [%g2+%lo(_foo+0)],%i0 -0000000c 81c7e008 ; ret -00000010 81e80000 ; restore -DESCRIPTION +|RELOCATION RECORDS FOR [.text]: +|offset type value +|00000004 HI22 _foo+0x12345678 +|00000008 LO10 _foo+0x12345678 + +|00000000 9de3bf90 ; save %sp,-112,%sp +|00000004 05000000 ; sethi %hi(_foo+0),%g2 +|00000008 f048a000 ; ldsb [%g2+%lo(_foo+0)],%i0 +|0000000c 81c7e008 ; ret +|00000010 81e80000 ; restore + - o section - The section field is only used when the symbol pointer field - is null. It supplies the section into which the data should be - relocated. The field's main use comes from assemblers which do - most of the symbol fixups themselves; an assembler may take an - internal reference to a label, but since it knows where the - label is, it can turn the relocation request from a symbol - lookup into a section relative relocation - the relocation - emitted has no symbol, just a section to relocate against. I'm - not sure what it means when both a symbol pointer an a section - pointer are present. Some formats use this sort of mechanism - to describe PIC relocations, but BFD can't to that sort of - thing yet. @item howto The howto field can be imagined as a - relocation instruction. It is a pointer to a struct which - contains information on what to do with all the other - information in the reloc record and data section. A back end - would normally have a relocation instruction set and turn - relocations into pointers to the correct structure on input - - but it would be possible to create each howto field on demand. - + o howto + + The howto field can be imagined as a + relocation instruction. It is a pointer to a struct which + contains information on what to do with all the other + information in the reloc record and data section. A back end + would normally have a relocation instruction set and turn + relocations into pointers to the correct structure on input - + but it would be possible to create each howto field on demand. + */ /* SUBSUBSECTION - <> + <> -DESCRIPTION - The <> is a structure which contains all the - information that BFD needs to know to tie up a back end's data. + The <> is a structure which contains all the + information that BFD needs to know to tie up a back end's data. +CODE_FRAGMENT +. .typedef CONST struct reloc_howto_struct .{ - The type field has mainly a documetary use - the back end can - to what it wants with it, though the normally the back end's - external idea of what a reloc number would be would be stored - in this field. For example, the a PC relative word relocation - in a coff environment would have the type 023 - because that's - what the outside world calls a R_PCRWORD reloc. - +. {* The type field has mainly a documetary use - the back end can +. to what it wants with it, though the normally the back end's +. external idea of what a reloc number would be would be stored +. in this field. For example, the a PC relative word relocation +. in a coff environment would have the type 023 - because that's +. what the outside world calls a R_PCRWORD reloc. *} . unsigned int type; - - The value the final relocation is shifted right by. This drops - unwanted data from the relocation. - +. +. {* The value the final relocation is shifted right by. This drops +. unwanted data from the relocation. *} . unsigned int rightshift; - - The size of the item to be relocated - 0, is one byte, 1 is 2 - bytes, 3 is four bytes. - +. +. {* The size of the item to be relocated - 0, is one byte, 1 is 2 +. bytes, 3 is four bytes. *} . unsigned int size; - - Now obsolete - +. +. {* Now obsolete *} . unsigned int bitsize; - - Notes that the relocation is relative to the location in the - data section of the addend. The relocation function will - subtract from the relocation value the address of the location - being relocated. - +. +. {* Notes that the relocation is relative to the location in the +. data section of the addend. The relocation function will +. subtract from the relocation value the address of the location +. being relocated. *} . boolean pc_relative; - - Now obsolete - +. +. {* Now obsolete *} . unsigned int bitpos; - - Now obsolete - +. +. {* Now obsolete *} . boolean absolute; - - Causes the relocation routine to return an error if overflow - is detected when relocating. - +. +. {* Causes the relocation routine to return an error if overflow +. is detected when relocating. *} . boolean complain_on_overflow; - - If this field is non null, then the supplied function is - called rather than the normal function. This allows really - strange relocation methods to be accomodated (eg, i960 callj - instructions). - +. +. {* If this field is non null, then the supplied function is +. called rather than the normal function. This allows really +. strange relocation methods to be accomodated (eg, i960 callj +. instructions). *} . bfd_reloc_status_type (*special_function)(); - - The textual name of the relocation type. - +. +. {* The textual name of the relocation type. *} . char *name; - - When performing a partial link, some formats must modify the - relocations rather than the data - this flag signals this. - +. +. {* When performing a partial link, some formats must modify the +. relocations rather than the data - this flag signals this.*} . boolean partial_inplace; - - The src_mask is used to select what parts of the read in data - are to be used in the relocation sum. Eg, if this was an 8 bit - bit of data which we read and relocated, this would be - 0x000000ff. When we have relocs which have an addend, such as - sun4 extended relocs, the value in the offset part of a - relocating field is garbage so we never use it. In this case - the mask would be 0x00000000. +. +. {* The src_mask is used to select what parts of the read in data +. are to be used in the relocation sum. Eg, if this was an 8 bit +. bit of data which we read and relocated, this would be +. 0x000000ff. When we have relocs which have an addend, such as +. sun4 extended relocs, the value in the offset part of a +. relocating field is garbage so we never use it. In this case +. the mask would be 0x00000000. *} . bfd_word src_mask; - - The dst_mask is what parts of the instruction are replaced - into the instruction. In most cases src_mask == dst_mask, - except in the above special case, where dst_mask would be - 0x000000ff, and src_mask would be 0x00000000. +. +. {* The dst_mask is what parts of the instruction are replaced +. into the instruction. In most cases src_mask == dst_mask, +. except in the above special case, where dst_mask would be +. 0x000000ff, and src_mask would be 0x00000000. *} . bfd_word dst_mask; - - When some formats create PC relative instructions, they leave - the value of the pc of the place being relocated in the offset - slot of the instruction, so that a PC relative relocation can - be made just by adding in an ordinary offset (eg sun3 a.out). - Some formats leave the displacement part of an instruction - empty (eg m88k bcs), this flag signals the fact. +. +. {* When some formats create PC relative instructions, they leave +. the value of the pc of the place being relocated in the offset +. slot of the instruction, so that a PC relative relocation can +. be made just by adding in an ordinary offset (eg sun3 a.out). +. Some formats leave the displacement part of an instruction +. empty (eg m88k bcs), this flag signals the fact.*} . boolean pcrel_offset; +. .} reloc_howto_type; */ /* FUNCTION - HOWTO + the HOWTO macro + DESCRIPTION The HOWTO define is horrible and will go away. @@ -386,21 +346,17 @@ DESCRIPTION DESCRIPTION Helper routine to turn a symbol into a relocation value. -.#define HOWTO_PREPARE(relocation, symbol) \ -. { \ -. if (symbol != (asymbol *)NULL) { \ -. if (symbol->flags & BSF_FORT_COMM) { \ -. relocation = 0; \ -. } \ -. else { \ -. relocation = symbol->value; \ -. } \ -. } \ -. if (symbol->section != (asection *)NULL) { \ -. relocation += symbol->section->output_section->vma + \ -. symbol->section->output_offset; \ -. } \ -.} +.#define HOWTO_PREPARE(relocation, symbol) \ +. { \ +. if (symbol != (asymbol *)NULL) { \ +. if (symbol->section == &bfd_com_section) { \ +. relocation = 0; \ +. } \ +. else { \ +. relocation = symbol->value; \ +. } \ +. } \ +.} */ @@ -427,6 +383,15 @@ DESCRIPTION FUNCTION bfd_perform_relocation +SYNOPSIS + bfd_reloc_status_type + bfd_perform_relocation + (bfd * abfd, + arelent *reloc_entry, + PTR data, + asection *input_section, + bfd *output_bfd); + DESCRIPTION If an output_bfd is supplied to this function the generated image will be relocatable, the relocations are copied to the @@ -441,14 +406,6 @@ DESCRIPTION enough for the addend. Complex reloc types with addends were invented to solve just this problem. -SYNOPSIS - bfd_reloc_status_type - bfd_perform_relocation - (bfd * abfd, - arelent *reloc_entry, - PTR data, - asection *input_section, - bfd *output_bfd); */ @@ -469,29 +426,24 @@ DEFUN(bfd_perform_relocation,(abfd, bfd_vma addr = reloc_entry->address ; bfd_vma output_base = 0; reloc_howto_type *howto = reloc_entry->howto; - asection *reloc_target_output_section; - asection *reloc_target_input_section; + asection *reloc_target_output_section ; + asymbol *symbol; - if (reloc_entry->sym_ptr_ptr) { - symbol = *( reloc_entry->sym_ptr_ptr); - if ((symbol->flags & BSF_UNDEFINED) && output_bfd == (bfd *)NULL) { + symbol = *( reloc_entry->sym_ptr_ptr); + if ((symbol->section == &bfd_und_section) && output_bfd == (bfd *)NULL) { flag = bfd_reloc_undefined; } - } - else { - symbol = (asymbol*)NULL; - } if (howto->special_function){ - bfd_reloc_status_type cont; - cont = howto->special_function(abfd, - reloc_entry, - symbol, - data, - input_section); - if (cont != bfd_reloc_continue) return cont; - } + bfd_reloc_status_type cont; + cont = howto->special_function(abfd, + reloc_entry, + symbol, + data, + input_section); + if (cont != bfd_reloc_continue) return cont; + } /* Work out which section the relocation is targetted at and the @@ -499,116 +451,90 @@ DEFUN(bfd_perform_relocation,(abfd, */ - if (symbol != (asymbol *)NULL){ - if (symbol->flags & BSF_FORT_COMM) { + if (symbol->section == &bfd_com_section) { relocation = 0; } - else { + else { relocation = symbol->value; } - if (symbol->section != (asection *)NULL) - { - reloc_target_input_section = symbol->section; - } - else { - reloc_target_input_section = (asection *)NULL; - } - } - else if (reloc_entry->section != (asection *)NULL) - { - relocation = 0; - reloc_target_input_section = reloc_entry->section; - } - else { - relocation = 0; - reloc_target_input_section = (asection *)NULL; - } - - if (reloc_target_input_section != (asection *)NULL) { - reloc_target_output_section = - reloc_target_input_section->output_section; + reloc_target_output_section = symbol->section->output_section; - if (output_bfd && howto->partial_inplace==false) { + if (output_bfd && howto->partial_inplace==false) { output_base = 0; } - else { + else { output_base = reloc_target_output_section->vma; } - relocation += output_base + reloc_target_input_section->output_offset; - } + relocation += output_base + symbol->section->output_offset; + relocation += reloc_entry->addend ; - if(reloc_entry->address > (bfd_vma)(input_section->size)) - { - return bfd_reloc_outofrange; - } + if(reloc_entry->address > input_section->_cooked_size) + { + return bfd_reloc_outofrange; + } if (howto->pc_relative == true) - { - /* - Anything which started out as pc relative should end up that - way too. - - There are two ways we can see a pcrel instruction. Sometimes - the pcrel displacement has been partially calculated, it - includes the distance from the start of the section to the - instruction in it (eg sun3), and sometimes the field is - totally blank - eg m88kbcs. - */ + { + /* + Anything which started out as pc relative should end up that + way too. + + There are two ways we can see a pcrel instruction. Sometimes + the pcrel displacement has been partially calculated, it + includes the distance from the start of the section to the + instruction in it (eg sun3), and sometimes the field is + totally blank - eg m88kbcs. + */ - relocation -= - input_section->output_section->vma + input_section->output_offset; - - if (howto->pcrel_offset == true) { - relocation -= reloc_entry->address; - } + relocation -= + input_section->output_section->vma + input_section->output_offset; + if (howto->pcrel_offset == true) { + relocation -= reloc_entry->address; } + } + if (output_bfd!= (bfd *)NULL) { - if ( howto->partial_inplace == false) { - /* - This is a partial relocation, and we want to apply the relocation - to the reloc entry rather than the raw data. Modify the reloc - inplace to reflect what we now know. - */ - reloc_entry->addend = relocation ; - reloc_entry->section = reloc_target_input_section; - if (reloc_target_input_section != (asection *)NULL) { - /* If we know the output section we can forget the symbol */ - reloc_entry->sym_ptr_ptr = (asymbol**)NULL; + if ( howto->partial_inplace == false) { + /* + This is a partial relocation, and we want to apply the relocation + to the reloc entry rather than the raw data. Modify the reloc + inplace to reflect what we now know. + */ + reloc_entry->addend = relocation ; + reloc_entry->address += input_section->output_offset; + return flag; + } + else + { + /* This is a partial relocation, but inplace, so modify the + reloc record a bit. + + If we've relocated with a symbol with a section, change + into a ref to the section belonging to the symbol + */ + reloc_entry->addend = relocation ; + reloc_entry->address += input_section->output_offset; + + } - reloc_entry->address += - input_section->output_offset; - return flag; } - else - { - /* This is a partial relocation, but inplace, so modify the - reloc record a bit. - - If we've relocated with a symbol with a section, change - into a ref to the section belonging to the symbol - */ - - if (symbol != (asymbol *)NULL && reloc_target_input_section != (asection *)NULL) - { - reloc_entry->section = reloc_target_input_section; - reloc_entry->sym_ptr_ptr = (asymbol **)NULL; - } - - } - } - + else + { + reloc_entry->addend = 0; +} + /* @@ -658,37 +584,37 @@ DEFUN(bfd_perform_relocation,(abfd, #define DOIT(x) \ x = ( (x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask)) - switch (howto->size) - { - case 0: - { - char x = bfd_get_8(abfd, (char *)data + addr); - DOIT(x); - bfd_put_8(abfd,x, (unsigned char *) data + addr); - } - break; - - case 1: - { - short x = bfd_get_16(abfd, (bfd_byte *)data + addr); - DOIT(x); - bfd_put_16(abfd, x, (unsigned char *)data + addr); - } - break; - case 2: - { - long x = bfd_get_32(abfd, (bfd_byte *) data + addr); - DOIT(x); - bfd_put_32(abfd,x, (bfd_byte *)data + addr); - } - break; - case 3: - - /* Do nothing */ - break; - default: - return bfd_reloc_other; - } + switch (howto->size) + { + case 0: + { + char x = bfd_get_8(abfd, (char *)data + addr); + DOIT(x); + bfd_put_8(abfd,x, (unsigned char *) data + addr); + } + break; + + case 1: + { + short x = bfd_get_16(abfd, (bfd_byte *)data + addr); + DOIT(x); + bfd_put_16(abfd, x, (unsigned char *)data + addr); + } + break; + case 2: + { + long x = bfd_get_32(abfd, (bfd_byte *) data + addr); + DOIT(x); + bfd_put_32(abfd,x, (bfd_byte *)data + addr); + } + break; + case 3: + + /* Do nothing */ + break; + default: + return bfd_reloc_other; + } return flag; } @@ -696,11 +622,12 @@ DEFUN(bfd_perform_relocation,(abfd, /* -@node howto manager, , typedef arelent, Relocations +INODE + howto manager, , typedef arelent, Relocations + SECTION The howto manager -DESCRIPTION When an application wants to create a relocation, but doesn't know what the target machine might call it, it can find out by using this bit of code. @@ -714,34 +641,28 @@ TYPEDEF DESCRIPTION The insides of a reloc code -.typedef enum bfd_reloc_code_real { - - 16 bits wide, simple reloc - -. BFD_RELOC_16, - - 8 bits wide, but used to form an address like 0xffnn - +CODE_FRAGMENT +. +.typedef enum bfd_reloc_code_real +.{ +. {* 16 bits wide, simple reloc *} +. BFD_RELOC_16, +. +. {* 8 bits wide, but used to form an address like 0xffnn *} . BFD_RELOC_8_FFnn, - - 8 bits wide, simple - +. +. {* 8 bits wide, simple *} . BFD_RELOC_8, - - 8 bits wide, pc relative - +. +. {* 8 bits wide, pc relative *} . BFD_RELOC_8_PCREL, - - The type of reloc used to build a contructor table - at the - moment probably a 32 bit wide abs address, but the cpu can - choose. - +. +. {* The type of reloc used to build a contructor table - at the +. moment probably a 32 bit wide abs address, but the cpu can +. choose. *} +. . BFD_RELOC_CTOR - . } bfd_reloc_code_real_type; - - - */ @@ -750,15 +671,16 @@ DESCRIPTION SECTION bfd_reloc_type_lookup +SYNOPSIS + CONST struct reloc_howto_struct * + bfd_reloc_type_lookup + (CONST bfd_arch_info_type *arch, bfd_reloc_code_type code); + DESCRIPTION This routine returns a pointer to a howto struct which when invoked, will perform the supplied relocation on data from the architecture noted. -SYNOPSIS - CONST struct reloc_howto_struct * - bfd_reloc_type_lookup - (CONST bfd_arch_info_type *arch, bfd_reloc_code_type code); */ @@ -775,17 +697,18 @@ static reloc_howto_type bfd_howto_32 = /* -INTERNAL FUNCTION +INTERNAL_FUNCTION bfd_default_reloc_type_lookup -DESCRIPTION - Provides a default relocation lookuperer for any architectue - SYNOPSIS CONST struct reloc_howto_struct *bfd_default_reloc_type_lookup (CONST struct bfd_arch_info *, bfd_reloc_code_type code); +DESCRIPTION + Provides a default relocation lookuperer for any architectue + + */ CONST struct reloc_howto_struct * DEFUN(bfd_default_reloc_type_lookup,(arch, code), @@ -812,3 +735,103 @@ DEFUN(bfd_default_reloc_type_lookup,(arch, code), } return (struct reloc_howto_struct *)NULL; } + + + +/* +INTERNAL_FUNCTION + bfd_generic_get_relocated_section_contents + +SYNOPSIS + bfd_byte * + bfd_generic_get_relocated_section_contents(bfd *abfd, + struct bfd_seclet_struct *seclet) + +DESCRIPTION + Provides default handling of relocation effort for back ends + which can't be bothered to do it efficiently. + +*/ + +bfd_byte * +DEFUN(bfd_generic_get_relocated_section_contents,(abfd, seclet), + bfd *abfd AND + struct bfd_seclet_struct *seclet) +{ + extern bfd_error_vector_type bfd_error_vector; + + + asymbol **symbols = 0; + + /* Get enough memory to hold the stuff */ + bfd *input_bfd = seclet->u.indirect.section->owner; + asection *input_section = seclet->u.indirect.section; + + bfd_byte *data = (bfd_byte *)malloc(input_section->_raw_size); + bfd_byte *dst = data; + bfd_byte *prev_dst = data; + unsigned int gap = 0; + + bfd_size_type reloc_size = bfd_get_reloc_upper_bound(input_bfd, + input_section); + arelent **reloc_vector = (arelent **)malloc(reloc_size); + + /* read in the section */ + bfd_get_section_contents(input_bfd, + input_section, + data, + 0, + input_section->_raw_size); + +/* We're not relaxing the section, so just copy the size info */ + input_section->_cooked_size = input_section->_raw_size; + input_section->reloc_done = true; + + + if (bfd_canonicalize_reloc(input_bfd, + input_section, + reloc_vector, + seclet->u.indirect.symbols) ) + { + arelent **parent; + for (parent = reloc_vector; * parent != (arelent *)NULL; + parent++) + { + bfd_reloc_status_type r= + bfd_perform_relocation(input_bfd, + *parent, + data, + input_section, 0); + + + if (r != bfd_reloc_ok) + { + asymbol *s; + + switch (r) + { + case bfd_reloc_undefined: + bfd_error_vector.undefined_symbol(*parent, seclet); + break; + case bfd_reloc_dangerous: + bfd_error_vector.reloc_dangerous(*parent, seclet); + break; + case bfd_reloc_outofrange: + case bfd_reloc_overflow: + bfd_error_vector.reloc_value_truncated(*parent, seclet); + break; + default: + abort(); + break; + } + + } + } + } + + free((char *)reloc_vector); + return data; + + +} + diff --git a/bfd/seclet.c b/bfd/seclet.c new file mode 100644 index 00000000000..4088f0eb9ba --- /dev/null +++ b/bfd/seclet.c @@ -0,0 +1,370 @@ +/* This module is part of BFD */ + + +/* The intention is that one day, all the code which uses sections + will change and use seclets instead - maybe seglet would have been + a better name.. + + Anyway, a seclet contains enough info to be able to describe an + area of output memory in one go. + + The only description so far catered for is that of the + <>, which is a select which points to a + <
> and the <> associated with the section, so + that relocation can be done when needed. + + One day there will be more types - they will at least migrate from + the linker's data structures - also there could be extra stuff, + like a bss seclet, which descibes a lump of memory as containing + zeros compactly, without the horrible SEC_* flag cruft. + + +*/ + +#include "bfd.h" +#include "sysdep.h" +#include "libbfd.h" +#include "seclet.h" +#include "coff/internal.h" +bfd_seclet_type * +DEFUN(bfd_new_seclet,(abfd, section), + bfd *abfd AND + asection *section) +{ + bfd_seclet_type *n = (bfd_seclet_type *)bfd_alloc(abfd, sizeof(bfd_seclet_type)); + if (section->seclets_tail != (bfd_seclet_type *)NULL) { + section->seclets_tail->next = n; + } + else + { + section->seclets_head = n; + } + section->seclets_tail = n; + + return n; + +} + + + + +#define MAX_ERRORS_IN_A_ROW 10 +extern bfd_error_vector_type bfd_error_vector; +bfd_vma +DEFUN(get_value,(reloc, seclet), + arelent *reloc AND + bfd_seclet_type *seclet) +{ + bfd_vma value; + if (reloc->sym_ptr_ptr) + { + asymbol *symbol = *(reloc->sym_ptr_ptr); + + + /* A symbol holds a pointer to a section, and an offset from the + base of the section. To relocate, we find where the section will + live in the output and add that in */ + + if (symbol->section == (asection *)NULL) + { + /* Ouch, this is an undefined symbol.. */ + bfd_error_vector.undefined_symbol(reloc, seclet); + value = symbol->value; + } + else + { + value = symbol->value + + symbol->section->output_offset + + symbol->section->output_section->vma; + } + } + + else + { + value = 0; + } + + /* Add the value contained in the relocation */ + value += (short)((reloc->addend) & 0xffff); + + return value; + + +} + +static char * +DEFUN(foo_bfd_get_relocated_section_contents,(seclet), + bfd_seclet_type *seclet) + +{ + asymbol **symbols = 0; + extern bfd *output_bfd; + bfd *abfd; + + /* Get enough memory to hold the stuff */ + bfd *input_bfd = seclet->u.indirect.section->owner; + asection *input_section = seclet->u.indirect.section; + + char *data = malloc(input_section->_raw_size); + char *dst = data; + char *prev_dst = data; + unsigned int gap = 0; + + bfd_size_type reloc_size = bfd_get_reloc_upper_bound(input_bfd, + input_section); + arelent **reloc_vector = (arelent **)ldmalloc(reloc_size); + abfd = output_bfd; + + /* read in the section */ + bfd_get_section_contents(input_bfd, + input_section, + data, + 0, + input_section->_raw_size); + + + if (bfd_canonicalize_reloc(input_bfd, + input_section, + reloc_vector, + seclet->u.indirect.symbols) ) + { + arelent **parent = reloc_vector; + arelent *reloc ; + + + + unsigned int dst_address = 0; + unsigned int src_address = 0; + unsigned int run; + unsigned int idx; + + /* Find how long a run we can do */ + while (dst_address < seclet->size) + { + + reloc = *parent; + if (reloc) + { + /* Note that the relaxing didn't tie up the addresses in the + relocation, so we use the original address to work out the + run of non-relocated data */ + run = reloc->address - src_address; + parent++; + + } + else + { + run = seclet->size - dst_address; + } + /* Copy the bytes */ + for (idx = 0; idx < run; idx++) + { + data[dst_address++] = data[src_address++]; + } + + /* Now do the relocation */ + + if (reloc) + { + switch (reloc->howto->type) + { + case R_JMP2: + /* Speciial relaxed type */ + { + bfd_vma dot = seclet->offset + dst_address + seclet->u.indirect.section->output_section->vma; + int gap = get_value(reloc,seclet)-dot-1; + if ((gap & ~0xff ) != 0 &&((gap & 0xff00)!= 0xff00)) abort(); + + bfd_put_8(abfd,gap, data+dst_address); + + switch (data[dst_address-1]) + { + + case 0x5e: + /* jsr -> bsr */ + bfd_put_8(abfd, 0x55, data+dst_address-1); + break; + case 0x5a: + /* jmp ->bra */ + bfd_put_8(abfd, 0x40, data+dst_address-1); + break; + + default: + abort(); + + } + + + + + dst_address++; + src_address+=3; + + break; + } + + + case R_MOVB2: + /* Special relaxed type, there will be a gap between where we + get stuff from and where we put stuff to now + + for a mov.b @aa:16 -> mov.b @aa:8 + opcode 0x6a 0x0y offset + -> 0x2y off + */ + if (data[dst_address-1] != 0x6a) + abort(); + switch (data[dst_address] & 0xf0) + { + case 0x00: + /* Src is memory */ + data[dst_address-1] = (data[src_address] & 0xf) | 0x20; + break; + case 0x80: + /* Src is reg */ + data[dst_address-1] = (data[src_address] & 0xf) | 0x30; + break; + default: + abort(); + } + + /* the offset must fit ! after all, what was all the relaxing + about ? */ + + bfd_put_8(abfd, get_value(reloc, seclet), data + dst_address); + + /* Note the magic - src goes up by two bytes, but dst by only + one */ + dst_address+=1; + src_address+=3; + + break; + /* PCrel 8 bits */ + case R_PCRBYTE: + { + bfd_vma dot = seclet->offset + dst_address + seclet->u.indirect.section->output_section->vma; + int gap = get_value(reloc,seclet)-dot; + if (gap > 127 || gap < -128) + { + bfd_error_vector.reloc_value_truncated(reloc, seclet); + } + + bfd_put_8(abfd,gap, data+dst_address); + dst_address++; + src_address++; + + break; + } + + case R_RELBYTE: + { + unsigned int gap =get_value(reloc,seclet); + if (gap > 256) + { + bfd_error_vector.reloc_value_truncated(reloc, seclet); + } + + bfd_put_8(abfd, gap, data+dst_address); + dst_address+=1; + src_address+=1; + + + } + break; + case R_JMP1: + /* A relword which would have like to have been a pcrel */ + case R_MOVB1: + /* A relword which would like to have been modified but + didn't make it */ + case R_RELWORD: + bfd_put_16(abfd, get_value(reloc,seclet), data+dst_address); + dst_address+=2; + src_address+=2; + break; + + default: + abort(); + } + } + } + } + free((char *)reloc_vector); + return data; + +} + +void +DEFUN(rel,(abfd, seclet, output_section), + bfd *abfd AND + bfd_seclet_type *seclet AND + asection *output_section) +{ + bfd_byte *data; + if (output_section->flags & SEC_HAS_CONTENTS ) + { + + data = bfd_get_relocated_section_contents(abfd, seclet); + + if(bfd_set_section_contents(abfd, + output_section, + data, + seclet->offset, + seclet->size) == false) + { + abort(); + } + +} + + + + + +} + +void +DEFUN(seclet_dump_seclet,(abfd, seclet, section), + bfd *abfd AND + bfd_seclet_type *seclet AND + asection *section) +{ + switch (seclet->type) + { + + case bfd_indirect_seclet: + /* The contents of this section come from another one somewhere + else */ + rel(abfd, seclet, section); + + + break; + + default: + abort(); + } + + + +} + +void +DEFUN(seclet_dump,(abfd), + bfd *abfd) +{ + /* Write all the seclets on the bfd out, relocate etc according to the + rules */ + + asection *o = abfd->sections; + while (o != (asection *)NULL) + { + bfd_seclet_type *p = o->seclets_head; + while (p != (bfd_seclet_type *)NULL) + { + seclet_dump_seclet(abfd, p, o); + p = p ->next; + } + + o = o->next; + } + +} diff --git a/bfd/seclet.h b/bfd/seclet.h new file mode 100644 index 00000000000..1ef1c309e90 --- /dev/null +++ b/bfd/seclet.h @@ -0,0 +1,29 @@ +typedef enum +{ + + bfd_indirect_seclet, + +} bfd_seclet_enum_type; + + +struct bfd_seclet_struct +{ + struct bfd_seclet_struct *next; + bfd_seclet_enum_type type; + unsigned int offset; + unsigned int size; + union + { + struct + { + asection *section; + asymbol **symbols; + + } indirect; + } + u; +}; + +typedef struct bfd_seclet_struct bfd_seclet_type; + +bfd_seclet_type *EXFUN(bfd_new_seclet,(bfd*,asection*)); diff --git a/bfd/section.c b/bfd/section.c index ab3bb51627e..8cdb23bc340 100644 --- a/bfd/section.c +++ b/bfd/section.c @@ -36,9 +36,7 @@ SECTION * section prototypes:: @end menu -INODE - Section Input, Section Output, Sections, Sections - +@node Section Input, Section Output, Sections, Sections SUBSECTION Section Input @@ -67,8 +65,7 @@ SUBSECTION the data area has to be parsed to get out the data and relocations. -INODE - Section Output, typedef asection, Section Input, Sections +@node Section Output, typedef asection, Section Input, Sections SUBSECTION Section Output @@ -104,6 +101,25 @@ SUBSECTION | output_section --------| +SUBSECTION + Seglets + + The data within a section is stored in a <>. These + are much like the fixups in <>. The seglet abstraction + allows the a section to grow and shrink within itself. + + A seglet knows how big it is, and which is the next seglet and + where the raw data for it is, and also points to a list of + relocations which apply to it. + + The seglet is used by the linker to perform relaxing on final + code. The application creates code which is as big as + necessary to make it work without relaxing, and the user can + select whether to relax. Sometimes relaxing takes a lot of + time. The linker runs around the relocations to see if any + are attached to data which can be shrunk, if so it does it on + a seglet by seglet basis. + */ @@ -111,12 +127,9 @@ SUBSECTION #include "sysdep.h" #include "libbfd.h" -/* -INODE - typedef asection, section prototypes, Section Output, Sections -SUBSECTION - typedef asection +/*doc* +@node typedef asection, section prototypes, Section Output, Sections SUBSECTION typedef asection @@ -131,6 +144,11 @@ CODE_FRAGMENT . . CONST char *name; . +. +. {* Which section is it 0.nth *} +. +. int index; +. . {* The next section in the list belonging to the BFD, or NULL. *} . . struct sec *next; @@ -214,16 +232,21 @@ CODE_FRAGMENT . .#define SEC_NEVER_LOAD 0x400 . -. {* The base address of the section in the address space of the -. target. *} +. . . bfd_vma vma; . -. {* The size of the section in bytes of the loaded section. This +. {* The size of the section in bytes, as it will be output. . contains a value even if the section has no contents (eg, the -. size of <<.bss>>). *} +. size of <<.bss>>). This will be filled in after relocation *} +. +. bfd_size_type _cooked_size; +. +. {* The size on disk of the section in bytes originally. Normally this +. value is the same as the size, but if some relaxing has +. been done, then this value will be bigger. *} . -. bfd_size_type size; +. bfd_size_type _raw_size; . . {* If this section is going to be output, then this value is the . offset into the output section of the first byte in the input @@ -255,10 +278,6 @@ CODE_FRAGMENT . . unsigned reloc_count; . -. {* Which section is it 0.nth *} -. -. int index; -. . {* Information below is back end specific - and not always used . or updated . @@ -295,7 +314,7 @@ CODE_FRAGMENT . . {* what the section number is in the target world *} . -. unsigned int target_index; +. int target_index; . . PTR used_by_bfd; . @@ -308,13 +327,47 @@ CODE_FRAGMENT . . bfd *owner; . +. boolean reloc_done; +. {* A symbol which points at this section only *} +. struct symbol_cache_entry *symbol; +. struct symbol_cache_entry **symbol_ptr_ptr; +. struct bfd_seclet_struct *seclets_head; +. struct bfd_seclet_struct *seclets_tail; .} asection ; +. +. +.#define BFD_ABS_SECTION_NAME "*ABS*" +.#define BFD_UND_SECTION_NAME "*UND*" +.#define BFD_COM_SECTION_NAME "*COM*" +. +. {* the absolute section *} +. extern asection bfd_abs_section; +. {* Pointer to the undefined section *} +. extern asection bfd_und_section; +. {* Pointer to the common section *} +. extern asection bfd_com_section; +. +. extern struct symbol_cache_entry *bfd_abs_symbol; +. extern struct symbol_cache_entry *bfd_com_symbol; +. extern struct symbol_cache_entry *bfd_und_symbol; +.#define bfd_get_section_size_before_reloc(section) \ +. (section->reloc_done ? (abort(),1): (section)->_raw_size) +.#define bfd_get_section_size_after_reloc(section) \ +. ((section->reloc_done) ? (section)->_cooked_size: (abort(),1)) */ -/* -INODE - section prototypes, , typedef asection, Sections + +asection bfd_com_section = { BFD_COM_SECTION_NAME ,0 }; +asection bfd_und_section = { BFD_UND_SECTION_NAME ,0 }; +asection bfd_abs_section = { BFD_ABS_SECTION_NAME ,0 }; + +struct symbol_cache_entry *bfd_abs_symbol; +struct symbol_cache_entry *bfd_com_symbol; +struct symbol_cache_entry *bfd_und_symbol; + +/* +@node section prototypes, , typedef asection, Sections SUBSECTION section prototypes @@ -424,6 +477,19 @@ DEFUN(bfd_make_section,(abfd, name), return NULL; } + if (strcmp(name, BFD_ABS_SECTION_NAME) == 0) + { + return &bfd_abs_section; + } + if (strcmp(name, BFD_COM_SECTION_NAME) == 0) + { + return &bfd_com_section; + } + if (strcmp(name, BFD_UND_SECTION_NAME) == 0) + { + return &bfd_und_section; + } + while (sect) { if (!strcmp(sect->name, name)) return NULL; prev = §->next; @@ -446,6 +512,20 @@ DEFUN(bfd_make_section,(abfd, name), newsect->reloc_count = 0; newsect->line_filepos =0; newsect->owner = abfd; + +/* Create a symbol whos only job is to point to this section. This is + usfull for things like relocs which are relative to the base of a + section + */ + newsect->symbol = bfd_make_empty_symbol(abfd); + newsect->symbol->name = name; + newsect->symbol->value = 0; + newsect->symbol->section = newsect; + newsect->symbol->flags = BSF_SECTION_SYM; + + + newsect->symbol_ptr_ptr = &newsect->symbol; + if (BFD_SEND (abfd, _new_section_hook, (abfd, newsect)) != true) { free (newsect); return NULL; @@ -564,7 +644,8 @@ DEFUN(bfd_set_section_size,(abfd, ptr, val), return false; } - ptr->size = val; + ptr->_cooked_size = val; + ptr->_raw_size = val; return true; } @@ -588,6 +669,8 @@ DESCRIPTION data is written to the output section starting at offset @var{offset} for @var{count} bytes. + + Normally <> is returned, else <>. Possible error returns are: o no_contents @@ -668,3 +751,39 @@ DEFUN(bfd_get_section_contents,(abfd, section, location, offset, count), } } + +/* Initialize the internal data structures */ +DEFUN_VOID(bfd_section_init) +{ + + bfd_com_symbol = (asymbol *)zalloc(sizeof(asymbol)); + bfd_com_symbol->name = BFD_COM_SECTION_NAME; + bfd_com_symbol->flags = BSF_SECTION_SYM; + bfd_com_symbol->section = &bfd_com_section; + bfd_com_section.symbol = bfd_com_symbol; + bfd_com_section.symbol_ptr_ptr = &bfd_com_symbol; + bfd_com_section.output_section = &bfd_com_section; + + + + bfd_und_symbol = (asymbol *)zalloc(sizeof(asymbol)); + bfd_und_symbol->name = BFD_UND_SECTION_NAME; + bfd_und_symbol->flags = BSF_SECTION_SYM; + bfd_und_symbol->section = &bfd_und_section; + bfd_und_section.symbol = bfd_und_symbol; + bfd_und_section.symbol_ptr_ptr = &bfd_und_symbol; + bfd_und_section.output_section = &bfd_und_section; + + bfd_abs_symbol = (asymbol *)zalloc(sizeof(asymbol)); + bfd_abs_symbol->name = BFD_ABS_SECTION_NAME; + bfd_abs_symbol->flags = BSF_SECTION_SYM; + bfd_abs_symbol->section = &bfd_abs_section; + bfd_abs_section.symbol = bfd_abs_symbol; + bfd_abs_section.symbol_ptr_ptr = &bfd_abs_symbol; + bfd_abs_section.output_section = &bfd_abs_section; + + + + + +} diff --git a/bfd/srec.c b/bfd/srec.c index 226d6f2786e..4e344edf55a 100644 --- a/bfd/srec.c +++ b/bfd/srec.c @@ -93,7 +93,7 @@ d[0] = digs[((x)>>4)&0xf]; ch += (x & 0xff); -static +static void DEFUN_VOID(srec_init) { unsigned int i; @@ -142,7 +142,7 @@ struct srec_data_list_struct typedef struct srec_data_list_struct srec_data_list_type; -typedef struct +typedef struct srec_data_struct { srec_data_list_type *head; unsigned int type; @@ -208,7 +208,7 @@ DEFUN(pass_over,(abfd, func, section), { unsigned int bytes_on_line; boolean eof = false; - bfd_vma address; + /* To the front of the file */ bfd_seek(abfd, (file_ptr)0, SEEK_SET); while (eof == false) @@ -291,12 +291,12 @@ DEFUN(srec_object_p, (abfd), and allocate enough room for the entire file. */ section = bfd_make_section(abfd, ".text"); - section->size = 0; + section->_raw_size = 0; section->vma = 0xffffffff; low = 0xffffffff; high = 0; pass_over(abfd, size_srec, section); - section->size = high - low; + section->_raw_size = high - low; section->vma = low; section->flags = SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC; @@ -314,7 +314,7 @@ DEFUN(srec_get_section_contents,(abfd, section, location, offset, count), { if (section->used_by_bfd == (PTR)NULL) { - section->used_by_bfd = (PTR)bfd_alloc (abfd, section->size); + section->used_by_bfd = (PTR)bfd_alloc (abfd, section->_raw_size); pass_over(abfd, fillup, section); } (void) memcpy((PTR)location, @@ -346,7 +346,7 @@ DEFUN(srec_set_section_contents,(abfd, section, location, offset, bytes_to_do), file_ptr offset AND bfd_size_type bytes_to_do) { - tdata_type *tdata = (tdata_type *)(abfd->tdata); + tdata_type *tdata = abfd->tdata.srec_data; srec_data_list_type *entry = (srec_data_list_type *) bfd_alloc(abfd, sizeof(srec_data_list_type)); unsigned char *data = (unsigned char *) bfd_alloc(abfd, bytes_to_do); @@ -371,7 +371,7 @@ DEFUN(srec_set_section_contents,(abfd, section, location, offset, bytes_to_do), entry->size = bytes_to_do; entry->next = tdata->head; tdata->head = entry; - + return true; } /* Write a record of type, of the supplied number of bytes. The @@ -471,7 +471,6 @@ DEFUN(srec_write_section,(abfd, tdata, list), char buffer[MAXCHUNK]; char *dst = buffer; bfd_vma address; - unsigned int i; unsigned int bytes_this_chunk = list->size - bytes_written; @@ -511,7 +510,7 @@ DEFUN(srec_mkobject, (abfd), bfd *abfd) { tdata_type *tdata = (tdata_type *)bfd_alloc(abfd, sizeof(tdata_type)); - abfd->tdata = (PTR)tdata; + abfd->tdata.srec_data = tdata; tdata->type = 1; tdata->head = (srec_data_list_type *)NULL; return true; @@ -523,12 +522,8 @@ static boolean DEFUN(srec_write_object_contents,(abfd), bfd *abfd) { - bfd_vma address; int bytes_written; - - int type; - unsigned int i; - tdata_type *tdata = (tdata_type *)(abfd->tdata); + tdata_type *tdata = abfd->tdata.srec_data; srec_data_list_type *list; bytes_written = 0; @@ -591,7 +586,7 @@ DEFUN(srec_make_empty_symbol, (abfd), #define srec_bfd_debug_info_start bfd_void #define srec_bfd_debug_info_end bfd_void #define srec_bfd_debug_info_accumulate (FOO(void, (*), (bfd *, asection *))) bfd_void - +#define srec_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents bfd_target srec_vec = { diff --git a/bfd/syms.c b/bfd/syms.c index 795a4a22030..72243a47ac7 100644 --- a/bfd/syms.c +++ b/bfd/syms.c @@ -22,11 +22,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ SECTION Symbols -DESCRIPTION BFD trys to maintain as much symbol information as it can when it moves information from file to file. BFD passes information to applications though the <> structure. When the - applicationrequests the symbol table, BFD reads the table in + application requests the symbol table, BFD reads the table in the native form and translates parts of it into the internal format. To maintain more than the infomation passed to applications some targets keep some information 'behind the @@ -38,7 +37,7 @@ DESCRIPTION information unique to coff which BFD doesn't know or understand. If a coff symbol table was read, but was written through an a.out back end, all the coff specific information - would be lost. (.. until BFD 2 :). The symbol table of a BFD + would be lost. The symbol table of a BFD is not necessarily read in until a canonicalize request is made. Then the BFD back end fills in a table provided by the application with pointers to the canonical information. To @@ -57,33 +56,28 @@ DESCRIPTION SUBSECTION Reading Symbols -DESCRIPTION There are two stages to reading a symbol table from a BFD; allocating storage, and the actual reading process. This is an excerpt from an appliction which reads the symbol table: -EXAMPLE - - unsigned int storage_needed; - asymbol **symbol_table; - unsigned int number_of_symbols; - unsigned int i; - - storage_needed = get_symtab_upper_bound (abfd); - - if (storage_needed == 0) { - return ; - } - symbol_table = (asymbol **) bfd_xmalloc (storage_needed); - ... - number_of_symbols = - bfd_canonicalize_symtab (abfd, symbol_table); - - for (i = 0; i < number_of_symbols; i++) { - process_symbol (symbol_table[i]); - } - -DESCRIPTION +| unsigned int storage_needed; +| asymbol **symbol_table; +| unsigned int number_of_symbols; +| unsigned int i; +| +| storage_needed = get_symtab_upper_bound (abfd); +| +| if (storage_needed == 0) { +| return ; +| } +| symbol_table = (asymbol **) bfd_xmalloc (storage_needed); +| ... +| number_of_symbols = +| bfd_canonicalize_symtab (abfd, symbol_table); +| +| for (i = 0; i < number_of_symbols; i++) { +| process_symbol (symbol_table[i]); +| } All storage for the symbols themselves is in an obstack connected to the BFD, and is freed when the BFD is closed. @@ -93,7 +87,6 @@ DESCRIPTION SUBSECTION Writing Symbols -DESCRIPTION Writing of a symbol table is automatic when a BFD open for writing is closed. The application attaches a vector of pointers to pointers to symbols to the BFD being written, and @@ -104,35 +97,32 @@ DESCRIPTION which has been created using <>. An example showing the creation of a symbol table with only one element: -EXAMPLE -#include "bfd.h" -main() -{ - bfd *abfd; - asymbol *ptrs[2]; - asymbol *new; - - abfd = bfd_openw("foo","a.out-sunos-big"); - bfd_set_format(abfd, bfd_object); - new = bfd_make_empty_symbol(abfd); - new->name = "dummy_symbol"; - new->section = (asection *)0; - new->flags = BSF_ABSOLUTE | BSF_GLOBAL; - new->value = 0x12345; - - ptrs[0] = new; - ptrs[1] = (asymbol *)0; - - bfd_set_symtab(abfd, ptrs, 1); - bfd_close(abfd); -} - -./makesym -nm foo -00012345 A dummy_symbol - +| #include "bfd.h" +| main() +| { +| bfd *abfd; +| asymbol *ptrs[2]; +| asymbol *new; +| +| abfd = bfd_openw("foo","a.out-sunos-big"); +| bfd_set_format(abfd, bfd_object); +| new = bfd_make_empty_symbol(abfd); +| new->name = "dummy_symbol"; +| new->section = bfd_make_section_old_way(abfd, ".text"); +| new->flags = BSF_GLOBAL; +| new->value = 0x12345; +| +| ptrs[0] = new; +| ptrs[1] = (asymbol *)0; +| +| bfd_set_symtab(abfd, ptrs, 1); +| bfd_close(abfd); +| } +| +| ./makesym +| nm foo +| 00012345 A dummy_symbol -DESCRIPTION Many formats cannot represent arbitary symbol information; for instance the <> object format does not allow an arbitary number of sections. A symbol pointing to a section @@ -142,148 +132,135 @@ DESCRIPTION */ -/*doc* +/* @node typedef asymbol, symbol handling functions, Writing Symbols, Symbols */ /* -TYPEDEF +SUBSECTION typedef asymbol -DESCRIPTION An <> has the form: +*/ + +/* +CODE_FRAGMENT + .typedef struct symbol_cache_entry .{ - A pointer to the BFD which owns the symbol. This information - is necessary so that a back end can work out what additional - (invisible to the application writer) information is carried - with the symbol. - +. {* A pointer to the BFD which owns the symbol. This information +. is necessary so that a back end can work out what additional +. (invisible to the application writer) information is carried +. with the symbol. *} +. . struct _bfd *the_bfd; - -The text of the symbol. The name is left alone, and not copied - the -application may not alter it. - -. CONST char *name; - -The value of the symbol. - -. symvalue value; - -Attributes of a symbol: - +. +. {* The text of the symbol. The name is left alone, and not copied - the +. application may not alter it. *} +. CONST char *name; +. +. {* The value of the symbol.*} +. symvalue value; +. +. {* Attributes of a symbol: *} +. .#define BSF_NO_FLAGS 0x00 - -The symbol has local scope; <> in <>. The value is -the offset into the section of the data. - +. +. {* The symbol has local scope; <> in <>. The value +. is the offset into the section of the data. *} .#define BSF_LOCAL 0x01 - -The symbol has global scope; initialized data in <>. The value -is the offset into the section of the data. - +. +. {* The symbol has global scope; initialized data in <>. The +. value is the offset into the section of the data. *} .#define BSF_GLOBAL 0x02 - -Obsolete - +. +. {* Obsolete *} .#define BSF_IMPORT 0x04 - -The symbol has global scope, and is exported. The value is the offset -into the section of the data. - +. +. {* The symbol has global scope, and is exported. The value is +. the offset into the section of the data. *} .#define BSF_EXPORT 0x08 - -The symbol is undefined. <> in <>. The value has no meaning. - -.#define BSF_UNDEFINED 0x10 - -The symbol is common, initialized to zero; default in <>. The -value is the size of the object in bytes. - -.#define BSF_FORT_COMM 0x20 - -A normal <> symbol would be one of: -<>, <>, <> or <> - -The symbol is a debugging record. The value has an arbitary meaning. - +. +. {* The symbol is undefined. <> in <>. The value has +. no meaning. *} +.#define BSF_UNDEFINED_OBS 0x10 +. +. {* The symbol is common, initialized to zero; default in +. <>. The value is the size of the object in bytes. *} +.#define BSF_FORT_COMM_OBS 0x20 +. +. {* A normal C symbol would be one of: +. <>, <>, <> or +. <> *} +. +. {* The symbol is a debugging record. The value has an arbitary +. meaning. *} .#define BSF_DEBUGGING 0x40 - -The symbol has no section attached, any value is the actual value and -is not a relative offset to a section. - -.#define BSF_ABSOLUTE 0x80 - -Used by the linker - +. +. {* Used by the linker *} .#define BSF_KEEP 0x10000 .#define BSF_KEEP_G 0x80000 - -Unused - +. +. {* Unused *} .#define BSF_WEAK 0x100000 .#define BSF_CTOR 0x200000 -.#define BSF_FAKE 0x400000 - -The symbol used to be a common symbol, but now it is allocated. - +. +. {* This symbol was created to point to a section *} +.#define BSF_SECTION_SYM 0x400000 +. +. {* The symbol used to be a common symbol, but now it is +. allocated. *} .#define BSF_OLD_COMMON 0x800000 - -The default value for common data. - +. +. {* The default value for common data. *} .#define BFD_FORT_COMM_DEFAULT_VALUE 0 - -In some files the type of a symbol sometimes alters its location -in an output file - ie in coff a <> symbol which is also <> -symbol appears where it was declared and not at the end of a section. -This bit is set by the target BFD part to convey this information. - +. +. {* In some files the type of a symbol sometimes alters its +. location in an output file - ie in coff a <> symbol +. which is also <> symbol appears where it was +. declared and not at the end of a section. This bit is set +. by the target BFD part to convey this information. *} +. .#define BSF_NOT_AT_END 0x40000 - -Signal that the symbol is the label of constructor section. - +. +. {* Signal that the symbol is the label of constructor section. *} .#define BSF_CONSTRUCTOR 0x1000000 - -Signal that the symbol is a warning symbol. If the symbol is a warning -symbol, then the value field (I know this is tacky) will point to the -asymbol which when referenced will cause the warning. - +. +. {* Signal that the symbol is a warning symbol. If the symbol +. is a warning symbol, then the value field (I know this is +. tacky) will point to the asymbol which when referenced will +. cause the warning. *} .#define BSF_WARNING 0x2000000 - -Signal that the symbol is indirect. The value of the symbol is a -pointer to an undefined asymbol which contains the name to use -instead. - +. +. {* Signal that the symbol is indirect. The value of the symbol +. is a pointer to an undefined asymbol which contains the +. name to use instead. *} .#define BSF_INDIRECT 0x4000000 - +. . flagword flags; - -A pointer to the section to which this symbol is relative, or 0 if the -symbol is absolute or undefined. Note that it is not sufficient to set -this location to 0 to mark a symbol as absolute - the flag -<> must be set also. - +. +. {* A pointer to the section to which this symbol is +. relative. This will always be non NULL, there are special +. sections for undefined and absolute symbols *} . struct sec *section; - -Back end special data. This is being phased out in favour of making -this a union. - +. +. {* Back end special data. This is being phased out in favour +. of making this a union. *} . PTR udata; +. .} asymbol; - */ #include "bfd.h" #include "sysdep.h" #include "libbfd.h" -#include "stab.gnu.h" +#include "aout/stab_gnu.h" /* @node symbol handling functions, , typedef asymbol, Symbols SUBSECTION Symbol Handling Functions - */ /* @@ -372,13 +349,11 @@ asymbol *symbol) { fprintf_vma(file, symbol->value); } - fprintf(file," %c%c%c%c%c%c%c%c%c%c", + fprintf(file," %c%c%c%c%c%c%c%c", (type & BSF_LOCAL) ? 'l':' ', (type & BSF_GLOBAL) ? 'g' : ' ', (type & BSF_IMPORT) ? 'i' : ' ', (type & BSF_EXPORT) ? 'e' : ' ', - (type & BSF_UNDEFINED) ? 'u' : ' ', - (type & BSF_FORT_COMM) ? 'c' : ' ', (type & BSF_CONSTRUCTOR) ? 'C' : ' ', (type & BSF_WARNING) ? 'W' : ' ', (type & BSF_INDIRECT) ? 'I' : ' ', @@ -421,14 +396,12 @@ asymbol *symbol) { flagword flags = symbol->flags; - if (flags & BSF_FORT_COMM) return 'C'; - if (flags & BSF_UNDEFINED) return 'U'; - if (flags & BSF_ABSOLUTE) - return (flags & BSF_GLOBAL) ? 'A' : 'a'; + if (symbol->section == &bfd_com_section) return 'C'; + if (symbol->section == &bfd_und_section) return 'U'; if ( flags & (BSF_GLOBAL|BSF_LOCAL) ) { - if (symbol->section == (asection *)NULL) - return '*'; + if ( symbol->section == &bfd_abs_section) + return (flags & BSF_GLOBAL) ? 'A' : 'a'; else if ( !strcmp(symbol->section->name, ".text") ) return (flags & BSF_GLOBAL) ? 'T' : 't'; else if ( !strcmp(symbol->section->name, ".data") ) @@ -450,3 +423,11 @@ asymbol *symbol) return '?'; } + + +bfd_symbol_is_absolute() +{ + + abort(); +} + diff --git a/bfd/targets.c b/bfd/targets.c index 26b77e9db01..d67e6e21dcb 100644 --- a/bfd/targets.c +++ b/bfd/targets.c @@ -28,6 +28,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ SECTION Targets +DESCRIPTION Each port of BFD to a different machine requries the creation of a target back end. All the back end provides to the root part of BFD is a structure containing pointers to functions @@ -66,18 +67,20 @@ SECTION <> on the BFD with a suggested format. The routine returns <> when the application guesses right. @menu -* bfd_target:: +@* bfd_target:: @end menu */ /* -@node bfd_target, , Targets, Targets +INODE + bfd_target, , Targets, Targets SUBSECTION bfd_target +DESCRIPTION This structure contains everything that BFD knows about a target. It includes things like its byte order, name, what routines to call to do various operations, etc. @@ -264,6 +267,7 @@ Symbols and reloctions . SDEF (void, _bfd_debug_info_start, (bfd *)); . SDEF (void, _bfd_debug_info_end, (bfd *)); . SDEF (void, _bfd_debug_info_accumulate, (bfd *, struct sec *)); +. SDEF (bfd_byte *, _bfd_get_relocated_section_contents, (bfd*,struct bfd_seclet_struct *)); Special entry points for gdb to swap in coff symbol table parts