| 1 | /* BFD semi-generic back-end for a.out binaries.
|
|---|
| 2 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
|
|---|
| 3 | 2001, 2002, 2003
|
|---|
| 4 | Free Software Foundation, Inc.
|
|---|
| 5 | Written by Cygnus Support.
|
|---|
| 6 |
|
|---|
| 7 | This file is part of BFD, the Binary File Descriptor library.
|
|---|
| 8 |
|
|---|
| 9 | This program is free software; you can redistribute it and/or modify
|
|---|
| 10 | it under the terms of the GNU General Public License as published by
|
|---|
| 11 | the Free Software Foundation; either version 2 of the License, or
|
|---|
| 12 | (at your option) any later version.
|
|---|
| 13 |
|
|---|
| 14 | This program is distributed in the hope that it will be useful,
|
|---|
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 17 | GNU General Public License for more details.
|
|---|
| 18 |
|
|---|
| 19 | You should have received a copy of the GNU General Public License
|
|---|
| 20 | along with this program; if not, write to the Free Software
|
|---|
| 21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|---|
| 22 |
|
|---|
| 23 | /*
|
|---|
| 24 | SECTION
|
|---|
| 25 | a.out backends
|
|---|
| 26 |
|
|---|
| 27 | DESCRIPTION
|
|---|
| 28 |
|
|---|
| 29 | BFD supports a number of different flavours of a.out format,
|
|---|
| 30 | though the major differences are only the sizes of the
|
|---|
| 31 | structures on disk, and the shape of the relocation
|
|---|
| 32 | information.
|
|---|
| 33 |
|
|---|
| 34 | The support is split into a basic support file @file{aoutx.h}
|
|---|
| 35 | and other files which derive functions from the base. One
|
|---|
| 36 | derivation file is @file{aoutf1.h} (for a.out flavour 1), and
|
|---|
| 37 | adds to the basic a.out functions support for sun3, sun4, 386
|
|---|
| 38 | and 29k a.out files, to create a target jump vector for a
|
|---|
| 39 | specific target.
|
|---|
| 40 |
|
|---|
| 41 | This information is further split out into more specific files
|
|---|
| 42 | for each machine, including @file{sunos.c} for sun3 and sun4,
|
|---|
| 43 | @file{newsos3.c} for the Sony NEWS, and @file{demo64.c} for a
|
|---|
| 44 | demonstration of a 64 bit a.out format.
|
|---|
| 45 |
|
|---|
| 46 | The base file @file{aoutx.h} defines general mechanisms for
|
|---|
| 47 | reading and writing records to and from disk and various
|
|---|
| 48 | other methods which BFD requires. It is included by
|
|---|
| 49 | @file{aout32.c} and @file{aout64.c} to form the names
|
|---|
| 50 | <<aout_32_swap_exec_header_in>>, <<aout_64_swap_exec_header_in>>, etc.
|
|---|
| 51 |
|
|---|
| 52 | As an example, this is what goes on to make the back end for a
|
|---|
| 53 | sun4, from @file{aout32.c}:
|
|---|
| 54 |
|
|---|
| 55 | | #define ARCH_SIZE 32
|
|---|
| 56 | | #include "aoutx.h"
|
|---|
| 57 |
|
|---|
| 58 | Which exports names:
|
|---|
| 59 |
|
|---|
| 60 | | ...
|
|---|
| 61 | | aout_32_canonicalize_reloc
|
|---|
| 62 | | aout_32_find_nearest_line
|
|---|
| 63 | | aout_32_get_lineno
|
|---|
| 64 | | aout_32_get_reloc_upper_bound
|
|---|
| 65 | | ...
|
|---|
| 66 |
|
|---|
| 67 | from @file{sunos.c}:
|
|---|
| 68 |
|
|---|
| 69 | | #define TARGET_NAME "a.out-sunos-big"
|
|---|
| 70 | | #define VECNAME sunos_big_vec
|
|---|
| 71 | | #include "aoutf1.h"
|
|---|
| 72 |
|
|---|
| 73 | requires all the names from @file{aout32.c}, and produces the jump vector
|
|---|
| 74 |
|
|---|
| 75 | | sunos_big_vec
|
|---|
| 76 |
|
|---|
| 77 | The file @file{host-aout.c} is a special case. It is for a large set
|
|---|
| 78 | of hosts that use ``more or less standard'' a.out files, and
|
|---|
| 79 | for which cross-debugging is not interesting. It uses the
|
|---|
| 80 | standard 32-bit a.out support routines, but determines the
|
|---|
| 81 | file offsets and addresses of the text, data, and BSS
|
|---|
| 82 | sections, the machine architecture and machine type, and the
|
|---|
| 83 | entry point address, in a host-dependent manner. Once these
|
|---|
| 84 | values have been determined, generic code is used to handle
|
|---|
| 85 | the object file.
|
|---|
| 86 |
|
|---|
| 87 | When porting it to run on a new system, you must supply:
|
|---|
| 88 |
|
|---|
| 89 | | HOST_PAGE_SIZE
|
|---|
| 90 | | HOST_SEGMENT_SIZE
|
|---|
| 91 | | HOST_MACHINE_ARCH (optional)
|
|---|
| 92 | | HOST_MACHINE_MACHINE (optional)
|
|---|
| 93 | | HOST_TEXT_START_ADDR
|
|---|
| 94 | | HOST_STACK_END_ADDR
|
|---|
| 95 |
|
|---|
| 96 | in the file @file{../include/sys/h-@var{XXX}.h} (for your host). These
|
|---|
| 97 | values, plus the structures and macros defined in @file{a.out.h} on
|
|---|
| 98 | your host system, will produce a BFD target that will access
|
|---|
| 99 | ordinary a.out files on your host. To configure a new machine
|
|---|
| 100 | to use @file{host-aout.c}, specify:
|
|---|
| 101 |
|
|---|
| 102 | | TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec
|
|---|
| 103 | | TDEPFILES= host-aout.o trad-core.o
|
|---|
| 104 |
|
|---|
| 105 | in the @file{config/@var{XXX}.mt} file, and modify @file{configure.in}
|
|---|
| 106 | to use the
|
|---|
| 107 | @file{@var{XXX}.mt} file (by setting "<<bfd_target=XXX>>") when your
|
|---|
| 108 | configuration is selected. */
|
|---|
| 109 |
|
|---|
| 110 | /* Some assumptions:
|
|---|
| 111 | * Any BFD with D_PAGED set is ZMAGIC, and vice versa.
|
|---|
| 112 | Doesn't matter what the setting of WP_TEXT is on output, but it'll
|
|---|
| 113 | get set on input.
|
|---|
| 114 | * Any BFD with D_PAGED clear and WP_TEXT set is NMAGIC.
|
|---|
| 115 | * Any BFD with both flags clear is OMAGIC.
|
|---|
| 116 | (Just want to make these explicit, so the conditions tested in this
|
|---|
| 117 | file make sense if you're more familiar with a.out than with BFD.) */
|
|---|
| 118 |
|
|---|
| 119 | #define KEEPIT udata.i
|
|---|
| 120 |
|
|---|
| 121 | #include "bfd.h"
|
|---|
| 122 | #include "sysdep.h"
|
|---|
| 123 | #include "safe-ctype.h"
|
|---|
| 124 | #include "bfdlink.h"
|
|---|
| 125 |
|
|---|
| 126 | #include "libaout.h"
|
|---|
| 127 | #include "libbfd.h"
|
|---|
| 128 | #include "aout/aout64.h"
|
|---|
| 129 | #include "aout/stab_gnu.h"
|
|---|
| 130 | #include "aout/ar.h"
|
|---|
| 131 |
|
|---|
| 132 | static bfd_boolean aout_get_external_symbols
|
|---|
| 133 | PARAMS ((bfd *));
|
|---|
| 134 | static bfd_boolean translate_from_native_sym_flags
|
|---|
| 135 | PARAMS ((bfd *, aout_symbol_type *));
|
|---|
| 136 | static bfd_boolean translate_to_native_sym_flags
|
|---|
| 137 | PARAMS ((bfd *, asymbol *, struct external_nlist *));
|
|---|
| 138 | static void adjust_o_magic
|
|---|
| 139 | PARAMS ((bfd *, struct internal_exec *));
|
|---|
| 140 | static void adjust_z_magic
|
|---|
| 141 | PARAMS ((bfd *, struct internal_exec *));
|
|---|
| 142 | static void adjust_n_magic
|
|---|
| 143 | PARAMS ((bfd *, struct internal_exec *));
|
|---|
| 144 | reloc_howto_type * NAME(aout,reloc_type_lookup)
|
|---|
| 145 | PARAMS ((bfd *, bfd_reloc_code_real_type));
|
|---|
| 146 |
|
|---|
| 147 | /*
|
|---|
| 148 | SUBSECTION
|
|---|
| 149 | Relocations
|
|---|
| 150 |
|
|---|
| 151 | DESCRIPTION
|
|---|
| 152 | The file @file{aoutx.h} provides for both the @emph{standard}
|
|---|
| 153 | and @emph{extended} forms of a.out relocation records.
|
|---|
| 154 |
|
|---|
| 155 | The standard records contain only an
|
|---|
| 156 | address, a symbol index, and a type field. The extended records
|
|---|
| 157 | (used on 29ks and sparcs) also have a full integer for an
|
|---|
| 158 | addend. */
|
|---|
| 159 |
|
|---|
| 160 | #ifndef CTOR_TABLE_RELOC_HOWTO
|
|---|
| 161 | #define CTOR_TABLE_RELOC_IDX 2
|
|---|
| 162 | #define CTOR_TABLE_RELOC_HOWTO(BFD) \
|
|---|
| 163 | ((obj_reloc_entry_size (BFD) == RELOC_EXT_SIZE \
|
|---|
| 164 | ? howto_table_ext : howto_table_std) \
|
|---|
| 165 | + CTOR_TABLE_RELOC_IDX)
|
|---|
| 166 | #endif
|
|---|
| 167 |
|
|---|
| 168 | #ifndef MY_swap_std_reloc_in
|
|---|
| 169 | #define MY_swap_std_reloc_in NAME(aout,swap_std_reloc_in)
|
|---|
| 170 | #endif
|
|---|
| 171 |
|
|---|
| 172 | #ifndef MY_swap_ext_reloc_in
|
|---|
| 173 | #define MY_swap_ext_reloc_in NAME(aout,swap_ext_reloc_in)
|
|---|
| 174 | #endif
|
|---|
| 175 |
|
|---|
| 176 | #ifndef MY_swap_std_reloc_out
|
|---|
| 177 | #define MY_swap_std_reloc_out NAME(aout,swap_std_reloc_out)
|
|---|
| 178 | #endif
|
|---|
| 179 |
|
|---|
| 180 | #ifndef MY_swap_ext_reloc_out
|
|---|
| 181 | #define MY_swap_ext_reloc_out NAME(aout,swap_ext_reloc_out)
|
|---|
| 182 | #endif
|
|---|
| 183 |
|
|---|
| 184 | #ifndef MY_final_link_relocate
|
|---|
| 185 | #define MY_final_link_relocate _bfd_final_link_relocate
|
|---|
| 186 | #endif
|
|---|
| 187 |
|
|---|
| 188 | #ifndef MY_relocate_contents
|
|---|
| 189 | #define MY_relocate_contents _bfd_relocate_contents
|
|---|
| 190 | #endif
|
|---|
| 191 |
|
|---|
| 192 | #define howto_table_ext NAME(aout,ext_howto_table)
|
|---|
| 193 | #define howto_table_std NAME(aout,std_howto_table)
|
|---|
| 194 |
|
|---|
| 195 | reloc_howto_type howto_table_ext[] =
|
|---|
| 196 | {
|
|---|
| 197 | /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone. */
|
|---|
| 198 | HOWTO(RELOC_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,0,"8", FALSE, 0,0x000000ff, FALSE),
|
|---|
| 199 | HOWTO(RELOC_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,0,"16", FALSE, 0,0x0000ffff, FALSE),
|
|---|
| 200 | HOWTO(RELOC_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,"32", FALSE, 0,0xffffffff, FALSE),
|
|---|
| 201 | HOWTO(RELOC_DISP8, 0, 0, 8, TRUE, 0, complain_overflow_signed,0,"DISP8", FALSE, 0,0x000000ff, FALSE),
|
|---|
| 202 | HOWTO(RELOC_DISP16, 0, 1, 16, TRUE, 0, complain_overflow_signed,0,"DISP16", FALSE, 0,0x0000ffff, FALSE),
|
|---|
| 203 | HOWTO(RELOC_DISP32, 0, 2, 32, TRUE, 0, complain_overflow_signed,0,"DISP32", FALSE, 0,0xffffffff, FALSE),
|
|---|
| 204 | HOWTO(RELOC_WDISP30,2, 2, 30, TRUE, 0, complain_overflow_signed,0,"WDISP30", FALSE, 0,0x3fffffff, FALSE),
|
|---|
| 205 | HOWTO(RELOC_WDISP22,2, 2, 22, TRUE, 0, complain_overflow_signed,0,"WDISP22", FALSE, 0,0x003fffff, FALSE),
|
|---|
| 206 | HOWTO(RELOC_HI22, 10, 2, 22, FALSE, 0, complain_overflow_bitfield,0,"HI22", FALSE, 0,0x003fffff, FALSE),
|
|---|
| 207 | HOWTO(RELOC_22, 0, 2, 22, FALSE, 0, complain_overflow_bitfield,0,"22", FALSE, 0,0x003fffff, FALSE),
|
|---|
| 208 | HOWTO(RELOC_13, 0, 2, 13, FALSE, 0, complain_overflow_bitfield,0,"13", FALSE, 0,0x00001fff, FALSE),
|
|---|
| 209 | HOWTO(RELOC_LO10, 0, 2, 10, FALSE, 0, complain_overflow_dont,0,"LO10", FALSE, 0,0x000003ff, FALSE),
|
|---|
| 210 | HOWTO(RELOC_SFA_BASE,0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,"SFA_BASE", FALSE, 0,0xffffffff, FALSE),
|
|---|
| 211 | HOWTO(RELOC_SFA_OFF13,0,2, 32, FALSE, 0, complain_overflow_bitfield,0,"SFA_OFF13",FALSE, 0,0xffffffff, FALSE),
|
|---|
| 212 | HOWTO(RELOC_BASE10, 0, 2, 10, FALSE, 0, complain_overflow_dont,0,"BASE10", FALSE, 0,0x000003ff, FALSE),
|
|---|
| 213 | HOWTO(RELOC_BASE13, 0, 2, 13, FALSE, 0, complain_overflow_signed,0,"BASE13", FALSE, 0,0x00001fff, FALSE),
|
|---|
| 214 | HOWTO(RELOC_BASE22, 10, 2, 22, FALSE, 0, complain_overflow_bitfield,0,"BASE22", FALSE, 0,0x003fffff, FALSE),
|
|---|
| 215 | HOWTO(RELOC_PC10, 0, 2, 10, TRUE, 0, complain_overflow_dont,0,"PC10", FALSE, 0,0x000003ff, TRUE),
|
|---|
| 216 | HOWTO(RELOC_PC22, 10, 2, 22, TRUE, 0, complain_overflow_signed,0,"PC22", FALSE, 0,0x003fffff, TRUE),
|
|---|
| 217 | HOWTO(RELOC_JMP_TBL,2, 2, 30, TRUE, 0, complain_overflow_signed,0,"JMP_TBL", FALSE, 0,0x3fffffff, FALSE),
|
|---|
| 218 | HOWTO(RELOC_SEGOFF16,0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"SEGOFF16", FALSE, 0,0x00000000, FALSE),
|
|---|
| 219 | HOWTO(RELOC_GLOB_DAT,0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"GLOB_DAT", FALSE, 0,0x00000000, FALSE),
|
|---|
| 220 | HOWTO(RELOC_JMP_SLOT,0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"JMP_SLOT", FALSE, 0,0x00000000, FALSE),
|
|---|
| 221 | HOWTO(RELOC_RELATIVE,0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"RELATIVE", FALSE, 0,0x00000000, FALSE),
|
|---|
| 222 | HOWTO(0, 0, 0, 0, FALSE, 0, complain_overflow_dont, 0, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE),
|
|---|
| 223 | HOWTO(0, 0, 0, 0, FALSE, 0, complain_overflow_dont, 0, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE),
|
|---|
| 224 | #define RELOC_SPARC_REV32 RELOC_WDISP19
|
|---|
| 225 | HOWTO(RELOC_SPARC_REV32, 0, 2, 32, FALSE, 0, complain_overflow_dont,0,"R_SPARC_REV32", FALSE, 0,0xffffffff, FALSE),
|
|---|
| 226 | };
|
|---|
| 227 |
|
|---|
| 228 | /* Convert standard reloc records to "arelent" format (incl byte swap). */
|
|---|
| 229 |
|
|---|
| 230 | reloc_howto_type howto_table_std[] =
|
|---|
| 231 | {
|
|---|
| 232 | /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone. */
|
|---|
| 233 | HOWTO ( 0, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,0,"8", TRUE, 0x000000ff,0x000000ff, FALSE),
|
|---|
| 234 | HOWTO ( 1, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,0,"16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
|
|---|
| 235 | HOWTO ( 2, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,"32", TRUE, 0xffffffff,0xffffffff, FALSE),
|
|---|
| 236 | HOWTO ( 3, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,0,"64", TRUE, 0xdeaddead,0xdeaddead, FALSE),
|
|---|
| 237 | HOWTO ( 4, 0, 0, 8, TRUE, 0, complain_overflow_signed, 0,"DISP8", TRUE, 0x000000ff,0x000000ff, FALSE),
|
|---|
| 238 | HOWTO ( 5, 0, 1, 16, TRUE, 0, complain_overflow_signed, 0,"DISP16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
|
|---|
| 239 | HOWTO ( 6, 0, 2, 32, TRUE, 0, complain_overflow_signed, 0,"DISP32", TRUE, 0xffffffff,0xffffffff, FALSE),
|
|---|
| 240 | HOWTO ( 7, 0, 4, 64, TRUE, 0, complain_overflow_signed, 0,"DISP64", TRUE, 0xfeedface,0xfeedface, FALSE),
|
|---|
| 241 | HOWTO ( 8, 0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"GOT_REL", FALSE, 0,0x00000000, FALSE),
|
|---|
| 242 | HOWTO ( 9, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,0,"BASE16", FALSE,0xffffffff,0xffffffff, FALSE),
|
|---|
| 243 | HOWTO (10, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,"BASE32", FALSE,0xffffffff,0xffffffff, FALSE),
|
|---|
| 244 | EMPTY_HOWTO (-1),
|
|---|
| 245 | EMPTY_HOWTO (-1),
|
|---|
| 246 | EMPTY_HOWTO (-1),
|
|---|
| 247 | EMPTY_HOWTO (-1),
|
|---|
| 248 | EMPTY_HOWTO (-1),
|
|---|
| 249 | HOWTO (16, 0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"JMP_TABLE", FALSE, 0,0x00000000, FALSE),
|
|---|
| 250 | EMPTY_HOWTO (-1),
|
|---|
| 251 | EMPTY_HOWTO (-1),
|
|---|
| 252 | EMPTY_HOWTO (-1),
|
|---|
| 253 | EMPTY_HOWTO (-1),
|
|---|
| 254 | EMPTY_HOWTO (-1),
|
|---|
| 255 | EMPTY_HOWTO (-1),
|
|---|
| 256 | EMPTY_HOWTO (-1),
|
|---|
| 257 | EMPTY_HOWTO (-1),
|
|---|
| 258 | EMPTY_HOWTO (-1),
|
|---|
| 259 | EMPTY_HOWTO (-1),
|
|---|
| 260 | EMPTY_HOWTO (-1),
|
|---|
| 261 | EMPTY_HOWTO (-1),
|
|---|
| 262 | EMPTY_HOWTO (-1),
|
|---|
| 263 | EMPTY_HOWTO (-1),
|
|---|
| 264 | EMPTY_HOWTO (-1),
|
|---|
| 265 | HOWTO (32, 0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"RELATIVE", FALSE, 0,0x00000000, FALSE),
|
|---|
| 266 | EMPTY_HOWTO (-1),
|
|---|
| 267 | EMPTY_HOWTO (-1),
|
|---|
| 268 | EMPTY_HOWTO (-1),
|
|---|
| 269 | EMPTY_HOWTO (-1),
|
|---|
| 270 | EMPTY_HOWTO (-1),
|
|---|
| 271 | EMPTY_HOWTO (-1),
|
|---|
| 272 | EMPTY_HOWTO (-1),
|
|---|
| 273 | HOWTO (40, 0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"BASEREL", FALSE, 0,0x00000000, FALSE),
|
|---|
| 274 | };
|
|---|
| 275 |
|
|---|
| 276 | #define TABLE_SIZE(TABLE) (sizeof (TABLE) / sizeof (TABLE[0]))
|
|---|
| 277 |
|
|---|
| 278 | #ifndef IS_STAB
|
|---|
| 279 | # define IS_STAB(flags) ((flags) & N_STAB)
|
|---|
| 280 | #endif
|
|---|
| 281 |
|
|---|
| 282 | reloc_howto_type *
|
|---|
| 283 | NAME(aout,reloc_type_lookup) (abfd,code)
|
|---|
| 284 | bfd *abfd;
|
|---|
| 285 | bfd_reloc_code_real_type code;
|
|---|
| 286 | {
|
|---|
| 287 | #define EXT(i, j) case i: return &howto_table_ext[j]
|
|---|
| 288 | #define STD(i, j) case i: return &howto_table_std[j]
|
|---|
| 289 | int ext = obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE;
|
|---|
| 290 |
|
|---|
| 291 | if (code == BFD_RELOC_CTOR)
|
|---|
| 292 | switch (bfd_get_arch_info (abfd)->bits_per_address)
|
|---|
| 293 | {
|
|---|
| 294 | case 32:
|
|---|
| 295 | code = BFD_RELOC_32;
|
|---|
| 296 | break;
|
|---|
| 297 | case 64:
|
|---|
| 298 | code = BFD_RELOC_64;
|
|---|
| 299 | break;
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|
| 302 | if (ext)
|
|---|
| 303 | switch (code)
|
|---|
| 304 | {
|
|---|
| 305 | EXT (BFD_RELOC_8, 0);
|
|---|
| 306 | EXT (BFD_RELOC_16, 1);
|
|---|
| 307 | EXT (BFD_RELOC_32, 2);
|
|---|
| 308 | EXT (BFD_RELOC_HI22, 8);
|
|---|
| 309 | EXT (BFD_RELOC_LO10, 11);
|
|---|
| 310 | EXT (BFD_RELOC_32_PCREL_S2, 6);
|
|---|
| 311 | EXT (BFD_RELOC_SPARC_WDISP22, 7);
|
|---|
| 312 | EXT (BFD_RELOC_SPARC13, 10);
|
|---|
| 313 | EXT (BFD_RELOC_SPARC_GOT10, 14);
|
|---|
| 314 | EXT (BFD_RELOC_SPARC_BASE13, 15);
|
|---|
| 315 | EXT (BFD_RELOC_SPARC_GOT13, 15);
|
|---|
| 316 | EXT (BFD_RELOC_SPARC_GOT22, 16);
|
|---|
| 317 | EXT (BFD_RELOC_SPARC_PC10, 17);
|
|---|
| 318 | EXT (BFD_RELOC_SPARC_PC22, 18);
|
|---|
| 319 | EXT (BFD_RELOC_SPARC_WPLT30, 19);
|
|---|
| 320 | EXT (BFD_RELOC_SPARC_REV32, 26);
|
|---|
| 321 | default: return (reloc_howto_type *) NULL;
|
|---|
| 322 | }
|
|---|
| 323 | else
|
|---|
| 324 | /* std relocs. */
|
|---|
| 325 | switch (code)
|
|---|
| 326 | {
|
|---|
| 327 | STD (BFD_RELOC_8, 0);
|
|---|
| 328 | STD (BFD_RELOC_16, 1);
|
|---|
| 329 | STD (BFD_RELOC_32, 2);
|
|---|
| 330 | STD (BFD_RELOC_8_PCREL, 4);
|
|---|
| 331 | STD (BFD_RELOC_16_PCREL, 5);
|
|---|
| 332 | STD (BFD_RELOC_32_PCREL, 6);
|
|---|
| 333 | STD (BFD_RELOC_16_BASEREL, 9);
|
|---|
| 334 | STD (BFD_RELOC_32_BASEREL, 10);
|
|---|
| 335 | default: return (reloc_howto_type *) NULL;
|
|---|
| 336 | }
|
|---|
| 337 | }
|
|---|
| 338 |
|
|---|
| 339 | /*
|
|---|
| 340 | SUBSECTION
|
|---|
| 341 | Internal entry points
|
|---|
| 342 |
|
|---|
| 343 | DESCRIPTION
|
|---|
| 344 | @file{aoutx.h} exports several routines for accessing the
|
|---|
| 345 | contents of an a.out file, which are gathered and exported in
|
|---|
| 346 | turn by various format specific files (eg sunos.c).
|
|---|
| 347 |
|
|---|
| 348 | */
|
|---|
| 349 |
|
|---|
| 350 | /*
|
|---|
| 351 | FUNCTION
|
|---|
| 352 | aout_@var{size}_swap_exec_header_in
|
|---|
| 353 |
|
|---|
| 354 | SYNOPSIS
|
|---|
| 355 | void aout_@var{size}_swap_exec_header_in,
|
|---|
| 356 | (bfd *abfd,
|
|---|
| 357 | struct external_exec *raw_bytes,
|
|---|
| 358 | struct internal_exec *execp);
|
|---|
| 359 |
|
|---|
| 360 | DESCRIPTION
|
|---|
| 361 | Swap the information in an executable header @var{raw_bytes} taken
|
|---|
| 362 | from a raw byte stream memory image into the internal exec header
|
|---|
| 363 | structure @var{execp}.
|
|---|
| 364 | */
|
|---|
| 365 |
|
|---|
| 366 | #ifndef NAME_swap_exec_header_in
|
|---|
| 367 | void
|
|---|
| 368 | NAME(aout,swap_exec_header_in) (abfd, raw_bytes, execp)
|
|---|
| 369 | bfd *abfd;
|
|---|
| 370 | struct external_exec *raw_bytes;
|
|---|
| 371 | struct internal_exec *execp;
|
|---|
| 372 | {
|
|---|
| 373 | struct external_exec *bytes = (struct external_exec *)raw_bytes;
|
|---|
| 374 |
|
|---|
| 375 | /* The internal_exec structure has some fields that are unused in this
|
|---|
| 376 | configuration (IE for i960), so ensure that all such uninitialized
|
|---|
| 377 | fields are zero'd out. There are places where two of these structs
|
|---|
| 378 | are memcmp'd, and thus the contents do matter. */
|
|---|
| 379 | memset ((PTR) execp, 0, sizeof (struct internal_exec));
|
|---|
| 380 | /* Now fill in fields in the execp, from the bytes in the raw data. */
|
|---|
| 381 | execp->a_info = H_GET_32 (abfd, bytes->e_info);
|
|---|
| 382 | execp->a_text = GET_WORD (abfd, bytes->e_text);
|
|---|
| 383 | execp->a_data = GET_WORD (abfd, bytes->e_data);
|
|---|
| 384 | execp->a_bss = GET_WORD (abfd, bytes->e_bss);
|
|---|
| 385 | execp->a_syms = GET_WORD (abfd, bytes->e_syms);
|
|---|
| 386 | execp->a_entry = GET_WORD (abfd, bytes->e_entry);
|
|---|
| 387 | execp->a_trsize = GET_WORD (abfd, bytes->e_trsize);
|
|---|
| 388 | execp->a_drsize = GET_WORD (abfd, bytes->e_drsize);
|
|---|
| 389 | }
|
|---|
| 390 | #define NAME_swap_exec_header_in NAME(aout,swap_exec_header_in)
|
|---|
| 391 | #endif
|
|---|
| 392 |
|
|---|
| 393 | /*
|
|---|
| 394 | FUNCTION
|
|---|
| 395 | aout_@var{size}_swap_exec_header_out
|
|---|
| 396 |
|
|---|
| 397 | SYNOPSIS
|
|---|
| 398 | void aout_@var{size}_swap_exec_header_out
|
|---|
| 399 | (bfd *abfd,
|
|---|
| 400 | struct internal_exec *execp,
|
|---|
| 401 | struct external_exec *raw_bytes);
|
|---|
| 402 |
|
|---|
| 403 | DESCRIPTION
|
|---|
| 404 | Swap the information in an internal exec header structure
|
|---|
| 405 | @var{execp} into the buffer @var{raw_bytes} ready for writing to disk.
|
|---|
| 406 | */
|
|---|
| 407 | void
|
|---|
| 408 | NAME(aout,swap_exec_header_out) (abfd, execp, raw_bytes)
|
|---|
| 409 | bfd *abfd;
|
|---|
| 410 | struct internal_exec *execp;
|
|---|
| 411 | struct external_exec *raw_bytes;
|
|---|
| 412 | {
|
|---|
| 413 | struct external_exec *bytes = (struct external_exec *)raw_bytes;
|
|---|
| 414 |
|
|---|
| 415 | /* Now fill in fields in the raw data, from the fields in the exec struct. */
|
|---|
| 416 | H_PUT_32 (abfd, execp->a_info , bytes->e_info);
|
|---|
| 417 | PUT_WORD (abfd, execp->a_text , bytes->e_text);
|
|---|
| 418 | PUT_WORD (abfd, execp->a_data , bytes->e_data);
|
|---|
| 419 | PUT_WORD (abfd, execp->a_bss , bytes->e_bss);
|
|---|
| 420 | PUT_WORD (abfd, execp->a_syms , bytes->e_syms);
|
|---|
| 421 | PUT_WORD (abfd, execp->a_entry , bytes->e_entry);
|
|---|
| 422 | PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize);
|
|---|
| 423 | PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize);
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 | /* Make all the section for an a.out file. */
|
|---|
| 427 |
|
|---|
| 428 | bfd_boolean
|
|---|
| 429 | NAME(aout,make_sections) (abfd)
|
|---|
| 430 | bfd *abfd;
|
|---|
| 431 | {
|
|---|
| 432 | if (obj_textsec (abfd) == (asection *) NULL
|
|---|
| 433 | && bfd_make_section (abfd, ".text") == (asection *) NULL)
|
|---|
| 434 | return FALSE;
|
|---|
| 435 | if (obj_datasec (abfd) == (asection *) NULL
|
|---|
| 436 | && bfd_make_section (abfd, ".data") == (asection *) NULL)
|
|---|
| 437 | return FALSE;
|
|---|
| 438 | if (obj_bsssec (abfd) == (asection *) NULL
|
|---|
| 439 | && bfd_make_section (abfd, ".bss") == (asection *) NULL)
|
|---|
| 440 | return FALSE;
|
|---|
| 441 | return TRUE;
|
|---|
| 442 | }
|
|---|
| 443 |
|
|---|
| 444 | /*
|
|---|
| 445 | FUNCTION
|
|---|
| 446 | aout_@var{size}_some_aout_object_p
|
|---|
| 447 |
|
|---|
| 448 | SYNOPSIS
|
|---|
| 449 | const bfd_target *aout_@var{size}_some_aout_object_p
|
|---|
| 450 | (bfd *abfd,
|
|---|
| 451 | const bfd_target *(*callback_to_real_object_p) ());
|
|---|
| 452 |
|
|---|
| 453 | DESCRIPTION
|
|---|
| 454 | Some a.out variant thinks that the file open in @var{abfd}
|
|---|
| 455 | checking is an a.out file. Do some more checking, and set up
|
|---|
| 456 | for access if it really is. Call back to the calling
|
|---|
| 457 | environment's "finish up" function just before returning, to
|
|---|
| 458 | handle any last-minute setup.
|
|---|
| 459 | */
|
|---|
| 460 |
|
|---|
| 461 | const bfd_target *
|
|---|
| 462 | NAME(aout,some_aout_object_p) (abfd, execp, callback_to_real_object_p)
|
|---|
| 463 | bfd *abfd;
|
|---|
| 464 | struct internal_exec *execp;
|
|---|
| 465 | const bfd_target *(*callback_to_real_object_p) PARAMS ((bfd *));
|
|---|
| 466 | {
|
|---|
| 467 | struct aout_data_struct *rawptr, *oldrawptr;
|
|---|
| 468 | const bfd_target *result;
|
|---|
| 469 | bfd_size_type amt = sizeof (struct aout_data_struct);
|
|---|
| 470 |
|
|---|
| 471 | rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, amt);
|
|---|
| 472 | if (rawptr == NULL)
|
|---|
| 473 | return 0;
|
|---|
| 474 |
|
|---|
| 475 | oldrawptr = abfd->tdata.aout_data;
|
|---|
| 476 | abfd->tdata.aout_data = rawptr;
|
|---|
| 477 |
|
|---|
| 478 | /* Copy the contents of the old tdata struct.
|
|---|
| 479 | In particular, we want the subformat, since for hpux it was set in
|
|---|
| 480 | hp300hpux.c:swap_exec_header_in and will be used in
|
|---|
| 481 | hp300hpux.c:callback. */
|
|---|
| 482 | if (oldrawptr != NULL)
|
|---|
| 483 | *abfd->tdata.aout_data = *oldrawptr;
|
|---|
| 484 |
|
|---|
| 485 | abfd->tdata.aout_data->a.hdr = &rawptr->e;
|
|---|
| 486 | /* Copy in the internal_exec struct. */
|
|---|
| 487 | *(abfd->tdata.aout_data->a.hdr) = *execp;
|
|---|
| 488 | execp = abfd->tdata.aout_data->a.hdr;
|
|---|
| 489 |
|
|---|
| 490 | /* Set the file flags. */
|
|---|
| 491 | abfd->flags = BFD_NO_FLAGS;
|
|---|
| 492 | if (execp->a_drsize || execp->a_trsize)
|
|---|
| 493 | abfd->flags |= HAS_RELOC;
|
|---|
| 494 | /* Setting of EXEC_P has been deferred to the bottom of this function. */
|
|---|
| 495 | if (execp->a_syms)
|
|---|
| 496 | abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
|
|---|
| 497 | if (N_DYNAMIC (*execp))
|
|---|
| 498 | abfd->flags |= DYNAMIC;
|
|---|
| 499 |
|
|---|
| 500 | if (N_MAGIC (*execp) == ZMAGIC)
|
|---|
| 501 | {
|
|---|
| 502 | abfd->flags |= D_PAGED | WP_TEXT;
|
|---|
| 503 | adata (abfd).magic = z_magic;
|
|---|
| 504 | }
|
|---|
| 505 | else if (N_MAGIC (*execp) == QMAGIC)
|
|---|
| 506 | {
|
|---|
| 507 | abfd->flags |= D_PAGED | WP_TEXT;
|
|---|
| 508 | adata (abfd).magic = z_magic;
|
|---|
| 509 | adata (abfd).subformat = q_magic_format;
|
|---|
| 510 | }
|
|---|
| 511 | else if (N_MAGIC (*execp) == NMAGIC)
|
|---|
| 512 | {
|
|---|
| 513 | abfd->flags |= WP_TEXT;
|
|---|
| 514 | adata (abfd).magic = n_magic;
|
|---|
| 515 | }
|
|---|
| 516 | else if (N_MAGIC (*execp) == OMAGIC
|
|---|
| 517 | || N_MAGIC (*execp) == BMAGIC)
|
|---|
| 518 | adata (abfd).magic = o_magic;
|
|---|
| 519 | else
|
|---|
| 520 | {
|
|---|
| 521 | /* Should have been checked with N_BADMAG before this routine
|
|---|
| 522 | was called. */
|
|---|
| 523 | abort ();
|
|---|
| 524 | }
|
|---|
| 525 |
|
|---|
| 526 | bfd_get_start_address (abfd) = execp->a_entry;
|
|---|
| 527 |
|
|---|
| 528 | obj_aout_symbols (abfd) = (aout_symbol_type *)NULL;
|
|---|
| 529 | bfd_get_symcount (abfd) = execp->a_syms / sizeof (struct external_nlist);
|
|---|
| 530 |
|
|---|
| 531 | /* The default relocation entry size is that of traditional V7 Unix. */
|
|---|
| 532 | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
|
|---|
| 533 |
|
|---|
| 534 | /* The default symbol entry size is that of traditional Unix. */
|
|---|
| 535 | obj_symbol_entry_size (abfd) = EXTERNAL_NLIST_SIZE;
|
|---|
| 536 |
|
|---|
| 537 | #ifdef USE_MMAP
|
|---|
| 538 | bfd_init_window (&obj_aout_sym_window (abfd));
|
|---|
| 539 | bfd_init_window (&obj_aout_string_window (abfd));
|
|---|
| 540 | #endif
|
|---|
| 541 | obj_aout_external_syms (abfd) = NULL;
|
|---|
| 542 | obj_aout_external_strings (abfd) = NULL;
|
|---|
| 543 | obj_aout_sym_hashes (abfd) = NULL;
|
|---|
| 544 |
|
|---|
| 545 | if (! NAME(aout,make_sections) (abfd))
|
|---|
| 546 | goto error_ret;
|
|---|
| 547 |
|
|---|
| 548 | obj_datasec (abfd)->_raw_size = execp->a_data;
|
|---|
| 549 | obj_bsssec (abfd)->_raw_size = execp->a_bss;
|
|---|
| 550 |
|
|---|
| 551 | obj_textsec (abfd)->flags =
|
|---|
| 552 | (execp->a_trsize != 0
|
|---|
| 553 | ? (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_RELOC)
|
|---|
| 554 | : (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS));
|
|---|
| 555 | obj_datasec (abfd)->flags =
|
|---|
| 556 | (execp->a_drsize != 0
|
|---|
| 557 | ? (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS | SEC_RELOC)
|
|---|
| 558 | : (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS));
|
|---|
| 559 | obj_bsssec (abfd)->flags = SEC_ALLOC;
|
|---|
| 560 |
|
|---|
| 561 | #ifdef THIS_IS_ONLY_DOCUMENTATION
|
|---|
| 562 | /* The common code can't fill in these things because they depend
|
|---|
| 563 | on either the start address of the text segment, the rounding
|
|---|
| 564 | up of virtual addresses between segments, or the starting file
|
|---|
| 565 | position of the text segment -- all of which varies among different
|
|---|
| 566 | versions of a.out. */
|
|---|
| 567 |
|
|---|
| 568 | /* Call back to the format-dependent code to fill in the rest of the
|
|---|
| 569 | fields and do any further cleanup. Things that should be filled
|
|---|
| 570 | in by the callback: */
|
|---|
| 571 |
|
|---|
| 572 | struct exec *execp = exec_hdr (abfd);
|
|---|
| 573 |
|
|---|
| 574 | obj_textsec (abfd)->size = N_TXTSIZE (*execp);
|
|---|
| 575 | obj_textsec (abfd)->raw_size = N_TXTSIZE (*execp);
|
|---|
| 576 | /* Data and bss are already filled in since they're so standard. */
|
|---|
| 577 |
|
|---|
| 578 | /* The virtual memory addresses of the sections. */
|
|---|
| 579 | obj_textsec (abfd)->vma = N_TXTADDR (*execp);
|
|---|
| 580 | obj_datasec (abfd)->vma = N_DATADDR (*execp);
|
|---|
| 581 | obj_bsssec (abfd)->vma = N_BSSADDR (*execp);
|
|---|
| 582 |
|
|---|
| 583 | /* The file offsets of the sections. */
|
|---|
| 584 | obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
|
|---|
| 585 | obj_datasec (abfd)->filepos = N_DATOFF (*execp);
|
|---|
| 586 |
|
|---|
| 587 | /* The file offsets of the relocation info. */
|
|---|
| 588 | obj_textsec (abfd)->rel_filepos = N_TRELOFF (*execp);
|
|---|
| 589 | obj_datasec (abfd)->rel_filepos = N_DRELOFF (*execp);
|
|---|
| 590 |
|
|---|
| 591 | /* The file offsets of the string table and symbol table. */
|
|---|
| 592 | obj_str_filepos (abfd) = N_STROFF (*execp);
|
|---|
| 593 | obj_sym_filepos (abfd) = N_SYMOFF (*execp);
|
|---|
| 594 |
|
|---|
| 595 | /* Determine the architecture and machine type of the object file. */
|
|---|
| 596 | switch (N_MACHTYPE (*exec_hdr (abfd)))
|
|---|
| 597 | {
|
|---|
| 598 | default:
|
|---|
| 599 | abfd->obj_arch = bfd_arch_obscure;
|
|---|
| 600 | break;
|
|---|
| 601 | }
|
|---|
| 602 |
|
|---|
| 603 | adata (abfd)->page_size = TARGET_PAGE_SIZE;
|
|---|
| 604 | adata (abfd)->segment_size = SEGMENT_SIZE;
|
|---|
| 605 | adata (abfd)->exec_bytes_size = EXEC_BYTES_SIZE;
|
|---|
| 606 |
|
|---|
| 607 | return abfd->xvec;
|
|---|
| 608 |
|
|---|
| 609 | /* The architecture is encoded in various ways in various a.out variants,
|
|---|
| 610 | or is not encoded at all in some of them. The relocation size depends
|
|---|
| 611 | on the architecture and the a.out variant. Finally, the return value
|
|---|
| 612 | is the bfd_target vector in use. If an error occurs, return zero and
|
|---|
| 613 | set bfd_error to the appropriate error code.
|
|---|
| 614 |
|
|---|
| 615 | Formats such as b.out, which have additional fields in the a.out
|
|---|
| 616 | header, should cope with them in this callback as well. */
|
|---|
| 617 | #endif /* DOCUMENTATION */
|
|---|
| 618 |
|
|---|
| 619 | result = (*callback_to_real_object_p) (abfd);
|
|---|
| 620 |
|
|---|
| 621 | /* Now that the segment addresses have been worked out, take a better
|
|---|
| 622 | guess at whether the file is executable. If the entry point
|
|---|
| 623 | is within the text segment, assume it is. (This makes files
|
|---|
| 624 | executable even if their entry point address is 0, as long as
|
|---|
| 625 | their text starts at zero.).
|
|---|
| 626 |
|
|---|
| 627 | This test had to be changed to deal with systems where the text segment
|
|---|
| 628 | runs at a different location than the default. The problem is that the
|
|---|
| 629 | entry address can appear to be outside the text segment, thus causing an
|
|---|
| 630 | erroneous conclusion that the file isn't executable.
|
|---|
| 631 |
|
|---|
| 632 | To fix this, we now accept any non-zero entry point as an indication of
|
|---|
| 633 | executability. This will work most of the time, since only the linker
|
|---|
| 634 | sets the entry point, and that is likely to be non-zero for most systems. */
|
|---|
| 635 |
|
|---|
| 636 | if (execp->a_entry != 0
|
|---|
| 637 | || (execp->a_entry >= obj_textsec (abfd)->vma
|
|---|
| 638 | && execp->a_entry < (obj_textsec (abfd)->vma
|
|---|
| 639 | + obj_textsec (abfd)->_raw_size)))
|
|---|
| 640 | abfd->flags |= EXEC_P;
|
|---|
| 641 | #ifdef STAT_FOR_EXEC
|
|---|
| 642 | else
|
|---|
| 643 | {
|
|---|
| 644 | struct stat stat_buf;
|
|---|
| 645 |
|
|---|
| 646 | /* The original heuristic doesn't work in some important cases.
|
|---|
| 647 | The a.out file has no information about the text start
|
|---|
| 648 | address. For files (like kernels) linked to non-standard
|
|---|
| 649 | addresses (ld -Ttext nnn) the entry point may not be between
|
|---|
| 650 | the default text start (obj_textsec(abfd)->vma) and
|
|---|
| 651 | (obj_textsec(abfd)->vma) + text size. This is not just a mach
|
|---|
| 652 | issue. Many kernels are loaded at non standard addresses. */
|
|---|
| 653 | if (abfd->iostream != NULL
|
|---|
| 654 | && (abfd->flags & BFD_IN_MEMORY) == 0
|
|---|
| 655 | && (fstat (fileno ((FILE *) (abfd->iostream)), &stat_buf) == 0)
|
|---|
| 656 | && ((stat_buf.st_mode & 0111) != 0))
|
|---|
| 657 | abfd->flags |= EXEC_P;
|
|---|
| 658 | }
|
|---|
| 659 | #endif /* STAT_FOR_EXEC */
|
|---|
| 660 |
|
|---|
| 661 | if (result)
|
|---|
| 662 | {
|
|---|
| 663 | #if 0 /* These should be set correctly anyways. */
|
|---|
| 664 | abfd->sections = obj_textsec (abfd);
|
|---|
| 665 | obj_textsec (abfd)->next = obj_datasec (abfd);
|
|---|
| 666 | obj_datasec (abfd)->next = obj_bsssec (abfd);
|
|---|
| 667 | #endif
|
|---|
| 668 | return result;
|
|---|
| 669 | }
|
|---|
| 670 |
|
|---|
| 671 | error_ret:
|
|---|
| 672 | bfd_release (abfd, rawptr);
|
|---|
| 673 | abfd->tdata.aout_data = oldrawptr;
|
|---|
| 674 | return NULL;
|
|---|
| 675 | }
|
|---|
| 676 |
|
|---|
| 677 | /*
|
|---|
| 678 | FUNCTION
|
|---|
| 679 | aout_@var{size}_mkobject
|
|---|
| 680 |
|
|---|
| 681 | SYNOPSIS
|
|---|
| 682 | bfd_boolean aout_@var{size}_mkobject, (bfd *abfd);
|
|---|
| 683 |
|
|---|
| 684 | DESCRIPTION
|
|---|
| 685 | Initialize BFD @var{abfd} for use with a.out files.
|
|---|
| 686 | */
|
|---|
| 687 |
|
|---|
| 688 | bfd_boolean
|
|---|
| 689 | NAME(aout,mkobject) (abfd)
|
|---|
| 690 | bfd *abfd;
|
|---|
| 691 | {
|
|---|
| 692 | struct aout_data_struct *rawptr;
|
|---|
| 693 | bfd_size_type amt = sizeof (struct aout_data_struct);
|
|---|
| 694 |
|
|---|
| 695 | bfd_set_error (bfd_error_system_call);
|
|---|
| 696 |
|
|---|
| 697 | rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, amt);
|
|---|
| 698 | if (rawptr == NULL)
|
|---|
| 699 | return FALSE;
|
|---|
| 700 |
|
|---|
| 701 | abfd->tdata.aout_data = rawptr;
|
|---|
| 702 | exec_hdr (abfd) = &(rawptr->e);
|
|---|
| 703 |
|
|---|
| 704 | obj_textsec (abfd) = (asection *) NULL;
|
|---|
| 705 | obj_datasec (abfd) = (asection *) NULL;
|
|---|
| 706 | obj_bsssec (abfd) = (asection *) NULL;
|
|---|
| 707 |
|
|---|
| 708 | return TRUE;
|
|---|
| 709 | }
|
|---|
| 710 |
|
|---|
| 711 | /*
|
|---|
| 712 | FUNCTION
|
|---|
| 713 | aout_@var{size}_machine_type
|
|---|
| 714 |
|
|---|
| 715 | SYNOPSIS
|
|---|
| 716 | enum machine_type aout_@var{size}_machine_type
|
|---|
| 717 | (enum bfd_architecture arch,
|
|---|
| 718 | unsigned long machine));
|
|---|
| 719 |
|
|---|
| 720 | DESCRIPTION
|
|---|
| 721 | Keep track of machine architecture and machine type for
|
|---|
| 722 | a.out's. Return the <<machine_type>> for a particular
|
|---|
| 723 | architecture and machine, or <<M_UNKNOWN>> if that exact architecture
|
|---|
| 724 | and machine can't be represented in a.out format.
|
|---|
| 725 |
|
|---|
| 726 | If the architecture is understood, machine type 0 (default)
|
|---|
| 727 | is always understood.
|
|---|
| 728 | */
|
|---|
| 729 |
|
|---|
| 730 | enum machine_type
|
|---|
| 731 | NAME(aout,machine_type) (arch, machine, unknown)
|
|---|
| 732 | enum bfd_architecture arch;
|
|---|
| 733 | unsigned long machine;
|
|---|
| 734 | bfd_boolean *unknown;
|
|---|
| 735 | {
|
|---|
| 736 | enum machine_type arch_flags;
|
|---|
| 737 |
|
|---|
| 738 | arch_flags = M_UNKNOWN;
|
|---|
| 739 | *unknown = TRUE;
|
|---|
| 740 |
|
|---|
| 741 | switch (arch)
|
|---|
| 742 | {
|
|---|
| 743 | case bfd_arch_sparc:
|
|---|
| 744 | if (machine == 0
|
|---|
| 745 | || machine == bfd_mach_sparc
|
|---|
| 746 | || machine == bfd_mach_sparc_sparclite
|
|---|
| 747 | || machine == bfd_mach_sparc_sparclite_le
|
|---|
| 748 | || machine == bfd_mach_sparc_v9)
|
|---|
| 749 | arch_flags = M_SPARC;
|
|---|
| 750 | else if (machine == bfd_mach_sparc_sparclet)
|
|---|
| 751 | arch_flags = M_SPARCLET;
|
|---|
| 752 | break;
|
|---|
| 753 |
|
|---|
| 754 | case bfd_arch_m68k:
|
|---|
| 755 | switch (machine)
|
|---|
| 756 | {
|
|---|
| 757 | case 0: arch_flags = M_68010; break;
|
|---|
| 758 | case bfd_mach_m68000: arch_flags = M_UNKNOWN; *unknown = FALSE; break;
|
|---|
| 759 | case bfd_mach_m68010: arch_flags = M_68010; break;
|
|---|
| 760 | case bfd_mach_m68020: arch_flags = M_68020; break;
|
|---|
| 761 | default: arch_flags = M_UNKNOWN; break;
|
|---|
| 762 | }
|
|---|
| 763 | break;
|
|---|
| 764 |
|
|---|
| 765 | case bfd_arch_i386:
|
|---|
| 766 | if (machine == 0
|
|---|
| 767 | || machine == bfd_mach_i386_i386
|
|---|
| 768 | || machine == bfd_mach_i386_i386_intel_syntax)
|
|---|
| 769 | arch_flags = M_386;
|
|---|
| 770 | break;
|
|---|
| 771 |
|
|---|
| 772 | case bfd_arch_a29k:
|
|---|
| 773 | if (machine == 0)
|
|---|
| 774 | arch_flags = M_29K;
|
|---|
| 775 | break;
|
|---|
| 776 |
|
|---|
| 777 | case bfd_arch_arm:
|
|---|
| 778 | if (machine == 0)
|
|---|
| 779 | arch_flags = M_ARM;
|
|---|
| 780 | break;
|
|---|
| 781 |
|
|---|
| 782 | case bfd_arch_mips:
|
|---|
| 783 | switch (machine)
|
|---|
| 784 | {
|
|---|
| 785 | case 0:
|
|---|
| 786 | case bfd_mach_mips3000:
|
|---|
| 787 | case bfd_mach_mips3900:
|
|---|
| 788 | arch_flags = M_MIPS1;
|
|---|
| 789 | break;
|
|---|
| 790 | case bfd_mach_mips6000:
|
|---|
| 791 | arch_flags = M_MIPS2;
|
|---|
| 792 | break;
|
|---|
| 793 | case bfd_mach_mips4000:
|
|---|
| 794 | case bfd_mach_mips4010:
|
|---|
| 795 | case bfd_mach_mips4100:
|
|---|
| 796 | case bfd_mach_mips4300:
|
|---|
| 797 | case bfd_mach_mips4400:
|
|---|
| 798 | case bfd_mach_mips4600:
|
|---|
| 799 | case bfd_mach_mips4650:
|
|---|
| 800 | case bfd_mach_mips8000:
|
|---|
| 801 | case bfd_mach_mips10000:
|
|---|
| 802 | case bfd_mach_mips12000:
|
|---|
| 803 | case bfd_mach_mips16:
|
|---|
| 804 | case bfd_mach_mipsisa32:
|
|---|
| 805 | case bfd_mach_mipsisa32r2:
|
|---|
| 806 | case bfd_mach_mips5:
|
|---|
| 807 | case bfd_mach_mipsisa64:
|
|---|
| 808 | case bfd_mach_mips_sb1:
|
|---|
| 809 | /* FIXME: These should be MIPS3, MIPS4, MIPS16, MIPS32, etc. */
|
|---|
| 810 | arch_flags = M_MIPS2;
|
|---|
| 811 | break;
|
|---|
| 812 | default:
|
|---|
| 813 | arch_flags = M_UNKNOWN;
|
|---|
| 814 | break;
|
|---|
| 815 | }
|
|---|
| 816 | break;
|
|---|
| 817 |
|
|---|
| 818 | case bfd_arch_ns32k:
|
|---|
| 819 | switch (machine)
|
|---|
| 820 | {
|
|---|
| 821 | case 0: arch_flags = M_NS32532; break;
|
|---|
| 822 | case 32032: arch_flags = M_NS32032; break;
|
|---|
| 823 | case 32532: arch_flags = M_NS32532; break;
|
|---|
| 824 | default: arch_flags = M_UNKNOWN; break;
|
|---|
| 825 | }
|
|---|
| 826 | break;
|
|---|
| 827 |
|
|---|
| 828 | case bfd_arch_vax:
|
|---|
| 829 | *unknown = FALSE;
|
|---|
| 830 | break;
|
|---|
| 831 |
|
|---|
| 832 | case bfd_arch_cris:
|
|---|
| 833 | if (machine == 0 || machine == 255)
|
|---|
| 834 | arch_flags = M_CRIS;
|
|---|
| 835 | break;
|
|---|
| 836 |
|
|---|
| 837 | default:
|
|---|
| 838 | arch_flags = M_UNKNOWN;
|
|---|
| 839 | }
|
|---|
| 840 |
|
|---|
| 841 | if (arch_flags != M_UNKNOWN)
|
|---|
| 842 | *unknown = FALSE;
|
|---|
| 843 |
|
|---|
| 844 | return arch_flags;
|
|---|
| 845 | }
|
|---|
| 846 |
|
|---|
| 847 | /*
|
|---|
| 848 | FUNCTION
|
|---|
| 849 | aout_@var{size}_set_arch_mach
|
|---|
| 850 |
|
|---|
| 851 | SYNOPSIS
|
|---|
| 852 | bfd_boolean aout_@var{size}_set_arch_mach,
|
|---|
| 853 | (bfd *,
|
|---|
| 854 | enum bfd_architecture arch,
|
|---|
| 855 | unsigned long machine));
|
|---|
| 856 |
|
|---|
| 857 | DESCRIPTION
|
|---|
| 858 | Set the architecture and the machine of the BFD @var{abfd} to the
|
|---|
| 859 | values @var{arch} and @var{machine}. Verify that @var{abfd}'s format
|
|---|
| 860 | can support the architecture required.
|
|---|
| 861 | */
|
|---|
| 862 |
|
|---|
| 863 | bfd_boolean
|
|---|
| 864 | NAME(aout,set_arch_mach) (abfd, arch, machine)
|
|---|
| 865 | bfd *abfd;
|
|---|
| 866 | enum bfd_architecture arch;
|
|---|
| 867 | unsigned long machine;
|
|---|
| 868 | {
|
|---|
| 869 | if (! bfd_default_set_arch_mach (abfd, arch, machine))
|
|---|
| 870 | return FALSE;
|
|---|
| 871 |
|
|---|
| 872 | if (arch != bfd_arch_unknown)
|
|---|
| 873 | {
|
|---|
| 874 | bfd_boolean unknown;
|
|---|
| 875 |
|
|---|
| 876 | NAME(aout,machine_type) (arch, machine, &unknown);
|
|---|
| 877 | if (unknown)
|
|---|
| 878 | return FALSE;
|
|---|
| 879 | }
|
|---|
| 880 |
|
|---|
| 881 | /* Determine the size of a relocation entry. */
|
|---|
| 882 | switch (arch)
|
|---|
| 883 | {
|
|---|
| 884 | case bfd_arch_sparc:
|
|---|
| 885 | case bfd_arch_a29k:
|
|---|
| 886 | case bfd_arch_mips:
|
|---|
| 887 | obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
|
|---|
| 888 | break;
|
|---|
| 889 | default:
|
|---|
| 890 | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
|
|---|
| 891 | break;
|
|---|
| 892 | }
|
|---|
| 893 |
|
|---|
| 894 | return (*aout_backend_info (abfd)->set_sizes) (abfd);
|
|---|
| 895 | }
|
|---|
| 896 |
|
|---|
| 897 | static void
|
|---|
| 898 | adjust_o_magic (abfd, execp)
|
|---|
| 899 | bfd *abfd;
|
|---|
| 900 | struct internal_exec *execp;
|
|---|
| 901 | {
|
|---|
| 902 | file_ptr pos = adata (abfd).exec_bytes_size;
|
|---|
| 903 | bfd_vma vma = 0;
|
|---|
| 904 | int pad = 0;
|
|---|
| 905 |
|
|---|
| 906 | /* Text. */
|
|---|
| 907 | obj_textsec (abfd)->filepos = pos;
|
|---|
| 908 | if (!obj_textsec (abfd)->user_set_vma)
|
|---|
| 909 | obj_textsec (abfd)->vma = vma;
|
|---|
| 910 | else
|
|---|
| 911 | vma = obj_textsec (abfd)->vma;
|
|---|
| 912 |
|
|---|
| 913 | pos += obj_textsec (abfd)->_raw_size;
|
|---|
| 914 | vma += obj_textsec (abfd)->_raw_size;
|
|---|
| 915 |
|
|---|
| 916 | /* Data. */
|
|---|
| 917 | if (!obj_datasec (abfd)->user_set_vma)
|
|---|
| 918 | {
|
|---|
| 919 | #if 0 /* ?? Does alignment in the file image really matter? */
|
|---|
| 920 | pad = align_power (vma, obj_datasec (abfd)->alignment_power) - vma;
|
|---|
| 921 | #endif
|
|---|
| 922 | obj_textsec (abfd)->_raw_size += pad;
|
|---|
| 923 | pos += pad;
|
|---|
| 924 | vma += pad;
|
|---|
| 925 | obj_datasec (abfd)->vma = vma;
|
|---|
| 926 | }
|
|---|
| 927 | else
|
|---|
| 928 | vma = obj_datasec (abfd)->vma;
|
|---|
| 929 | obj_datasec (abfd)->filepos = pos;
|
|---|
| 930 | pos += obj_datasec (abfd)->_raw_size;
|
|---|
| 931 | vma += obj_datasec (abfd)->_raw_size;
|
|---|
| 932 |
|
|---|
| 933 | /* BSS. */
|
|---|
| 934 | if (!obj_bsssec (abfd)->user_set_vma)
|
|---|
| 935 | {
|
|---|
| 936 | #if 0
|
|---|
| 937 | pad = align_power (vma, obj_bsssec (abfd)->alignment_power) - vma;
|
|---|
| 938 | #endif
|
|---|
| 939 | obj_datasec (abfd)->_raw_size += pad;
|
|---|
| 940 | pos += pad;
|
|---|
| 941 | vma += pad;
|
|---|
| 942 | obj_bsssec (abfd)->vma = vma;
|
|---|
| 943 | }
|
|---|
| 944 | else
|
|---|
| 945 | {
|
|---|
| 946 | /* The VMA of the .bss section is set by the VMA of the
|
|---|
| 947 | .data section plus the size of the .data section. We may
|
|---|
| 948 | need to add padding bytes to make this true. */
|
|---|
| 949 | pad = obj_bsssec (abfd)->vma - vma;
|
|---|
| 950 | if (pad > 0)
|
|---|
| 951 | {
|
|---|
| 952 | obj_datasec (abfd)->_raw_size += pad;
|
|---|
| 953 | pos += pad;
|
|---|
| 954 | }
|
|---|
| 955 | }
|
|---|
| 956 | obj_bsssec (abfd)->filepos = pos;
|
|---|
| 957 |
|
|---|
| 958 | /* Fix up the exec header. */
|
|---|
| 959 | execp->a_text = obj_textsec (abfd)->_raw_size;
|
|---|
| 960 | execp->a_data = obj_datasec (abfd)->_raw_size;
|
|---|
| 961 | execp->a_bss = obj_bsssec (abfd)->_raw_size;
|
|---|
| 962 | N_SET_MAGIC (*execp, OMAGIC);
|
|---|
| 963 | }
|
|---|
| 964 |
|
|---|
| 965 | static void
|
|---|
| 966 | adjust_z_magic (abfd, execp)
|
|---|
| 967 | bfd *abfd;
|
|---|
| 968 | struct internal_exec *execp;
|
|---|
| 969 | {
|
|---|
| 970 | bfd_size_type data_pad, text_pad;
|
|---|
| 971 | file_ptr text_end;
|
|---|
| 972 | const struct aout_backend_data *abdp;
|
|---|
| 973 | int ztih; /* Nonzero if text includes exec header. */
|
|---|
| 974 |
|
|---|
| 975 | abdp = aout_backend_info (abfd);
|
|---|
| 976 |
|
|---|
| 977 | /* Text. */
|
|---|
| 978 | ztih = (abdp != NULL
|
|---|
| 979 | && (abdp->text_includes_header
|
|---|
| 980 | || obj_aout_subformat (abfd) == q_magic_format));
|
|---|
| 981 | obj_textsec (abfd)->filepos = (ztih
|
|---|
| 982 | ? adata (abfd).exec_bytes_size
|
|---|
| 983 | : adata (abfd).zmagic_disk_block_size);
|
|---|
| 984 | if (! obj_textsec (abfd)->user_set_vma)
|
|---|
| 985 | {
|
|---|
| 986 | /* ?? Do we really need to check for relocs here? */
|
|---|
| 987 | obj_textsec (abfd)->vma = ((abfd->flags & HAS_RELOC)
|
|---|
| 988 | ? 0
|
|---|
| 989 | : (ztih
|
|---|
| 990 | ? (abdp->default_text_vma
|
|---|
| 991 | + adata (abfd).exec_bytes_size)
|
|---|
| 992 | : abdp->default_text_vma));
|
|---|
| 993 | text_pad = 0;
|
|---|
| 994 | }
|
|---|
| 995 | else
|
|---|
| 996 | {
|
|---|
| 997 | /* The .text section is being loaded at an unusual address. We
|
|---|
| 998 | may need to pad it such that the .data section starts at a page
|
|---|
| 999 | boundary. */
|
|---|
| 1000 | if (ztih)
|
|---|
| 1001 | text_pad = ((obj_textsec (abfd)->filepos - obj_textsec (abfd)->vma)
|
|---|
| 1002 | & (adata (abfd).page_size - 1));
|
|---|
| 1003 | else
|
|---|
| 1004 | text_pad = ((- obj_textsec (abfd)->vma)
|
|---|
| 1005 | & (adata (abfd).page_size - 1));
|
|---|
| 1006 | }
|
|---|
| 1007 |
|
|---|
| 1008 | /* Find start of data. */
|
|---|
| 1009 | if (ztih)
|
|---|
| 1010 | {
|
|---|
| 1011 | text_end = obj_textsec (abfd)->filepos + obj_textsec (abfd)->_raw_size;
|
|---|
| 1012 | text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end;
|
|---|
| 1013 | }
|
|---|
| 1014 | else
|
|---|
| 1015 | {
|
|---|
| 1016 | /* Note that if page_size == zmagic_disk_block_size, then
|
|---|
| 1017 | filepos == page_size, and this case is the same as the ztih
|
|---|
| 1018 | case. */
|
|---|
| 1019 | text_end = obj_textsec (abfd)->_raw_size;
|
|---|
| 1020 | text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end;
|
|---|
| 1021 | text_end += obj_textsec (abfd)->filepos;
|
|---|
| 1022 | }
|
|---|
| 1023 | obj_textsec (abfd)->_raw_size += text_pad;
|
|---|
| 1024 | text_end += text_pad;
|
|---|
| 1025 |
|
|---|
| 1026 | /* Data. */
|
|---|
| 1027 | if (!obj_datasec (abfd)->user_set_vma)
|
|---|
| 1028 | {
|
|---|
| 1029 | bfd_vma vma;
|
|---|
| 1030 | vma = obj_textsec (abfd)->vma + obj_textsec (abfd)->_raw_size;
|
|---|
| 1031 | obj_datasec (abfd)->vma = BFD_ALIGN (vma, adata (abfd).segment_size);
|
|---|
| 1032 | }
|
|---|
| 1033 | if (abdp && abdp->zmagic_mapped_contiguous)
|
|---|
| 1034 | {
|
|---|
| 1035 | asection * text = obj_textsec (abfd);
|
|---|
| 1036 | asection * data = obj_datasec (abfd);
|
|---|
| 1037 |
|
|---|
| 1038 | text_pad = data->vma - (text->vma + text->_raw_size);
|
|---|
| 1039 | /* Only pad the text section if the data
|
|---|
| 1040 | section is going to be placed after it. */
|
|---|
| 1041 | if (text_pad > 0)
|
|---|
| 1042 | text->_raw_size += text_pad;
|
|---|
| 1043 | }
|
|---|
| 1044 | obj_datasec (abfd)->filepos = (obj_textsec (abfd)->filepos
|
|---|
| 1045 | + obj_textsec (abfd)->_raw_size);
|
|---|
| 1046 |
|
|---|
| 1047 | /* Fix up exec header while we're at it. */
|
|---|
| 1048 | execp->a_text = obj_textsec (abfd)->_raw_size;
|
|---|
| 1049 | if (ztih && (!abdp || (abdp && !abdp->exec_header_not_counted)))
|
|---|
| 1050 | execp->a_text += adata (abfd).exec_bytes_size;
|
|---|
| 1051 | if (obj_aout_subformat (abfd) == q_magic_format)
|
|---|
| 1052 | N_SET_MAGIC (*execp, QMAGIC);
|
|---|
| 1053 | else
|
|---|
| 1054 | N_SET_MAGIC (*execp, ZMAGIC);
|
|---|
| 1055 |
|
|---|
| 1056 | /* Spec says data section should be rounded up to page boundary. */
|
|---|
| 1057 | obj_datasec (abfd)->_raw_size
|
|---|
| 1058 | = align_power (obj_datasec (abfd)->_raw_size,
|
|---|
| 1059 | obj_bsssec (abfd)->alignment_power);
|
|---|
| 1060 | execp->a_data = BFD_ALIGN (obj_datasec (abfd)->_raw_size,
|
|---|
| 1061 | adata (abfd).page_size);
|
|---|
| 1062 | data_pad = execp->a_data - obj_datasec (abfd)->_raw_size;
|
|---|
| 1063 |
|
|---|
| 1064 | /* BSS. */
|
|---|
| 1065 | if (!obj_bsssec (abfd)->user_set_vma)
|
|---|
| 1066 | obj_bsssec (abfd)->vma = (obj_datasec (abfd)->vma
|
|---|
| 1067 | + obj_datasec (abfd)->_raw_size);
|
|---|
| 1068 | /* If the BSS immediately follows the data section and extra space
|
|---|
| 1069 | in the page is left after the data section, fudge data
|
|---|
| 1070 | in the header so that the bss section looks smaller by that
|
|---|
| 1071 | amount. We'll start the bss section there, and lie to the OS.
|
|---|
| 1072 | (Note that a linker script, as well as the above assignment,
|
|---|
| 1073 | could have explicitly set the BSS vma to immediately follow
|
|---|
| 1074 | the data section.) */
|
|---|
| 1075 | if (align_power (obj_bsssec (abfd)->vma, obj_bsssec (abfd)->alignment_power)
|
|---|
| 1076 | == obj_datasec (abfd)->vma + obj_datasec (abfd)->_raw_size)
|
|---|
| 1077 | execp->a_bss = (data_pad > obj_bsssec (abfd)->_raw_size
|
|---|
| 1078 | ? 0 : obj_bsssec (abfd)->_raw_size - data_pad);
|
|---|
| 1079 | else
|
|---|
| 1080 | execp->a_bss = obj_bsssec (abfd)->_raw_size;
|
|---|
| 1081 | }
|
|---|
| 1082 |
|
|---|
| 1083 | static void
|
|---|
| 1084 | adjust_n_magic (abfd, execp)
|
|---|
| 1085 | bfd *abfd;
|
|---|
| 1086 | struct internal_exec *execp;
|
|---|
| 1087 | {
|
|---|
| 1088 | file_ptr pos = adata (abfd).exec_bytes_size;
|
|---|
| 1089 | bfd_vma vma = 0;
|
|---|
| 1090 | int pad;
|
|---|
| 1091 |
|
|---|
| 1092 | /* Text. */
|
|---|
| 1093 | obj_textsec (abfd)->filepos = pos;
|
|---|
| 1094 | if (!obj_textsec (abfd)->user_set_vma)
|
|---|
| 1095 | obj_textsec (abfd)->vma = vma;
|
|---|
| 1096 | else
|
|---|
| 1097 | vma = obj_textsec (abfd)->vma;
|
|---|
| 1098 | pos += obj_textsec (abfd)->_raw_size;
|
|---|
| 1099 | vma += obj_textsec (abfd)->_raw_size;
|
|---|
| 1100 |
|
|---|
| 1101 | /* Data. */
|
|---|
| 1102 | obj_datasec (abfd)->filepos = pos;
|
|---|
| 1103 | if (!obj_datasec (abfd)->user_set_vma)
|
|---|
| 1104 | obj_datasec (abfd)->vma = BFD_ALIGN (vma, adata (abfd).segment_size);
|
|---|
| 1105 | vma = obj_datasec (abfd)->vma;
|
|---|
| 1106 |
|
|---|
| 1107 | /* Since BSS follows data immediately, see if it needs alignment. */
|
|---|
| 1108 | vma += obj_datasec (abfd)->_raw_size;
|
|---|
| 1109 | pad = align_power (vma, obj_bsssec (abfd)->alignment_power) - vma;
|
|---|
| 1110 | obj_datasec (abfd)->_raw_size += pad;
|
|---|
| 1111 | pos += obj_datasec (abfd)->_raw_size;
|
|---|
| 1112 |
|
|---|
| 1113 | /* BSS. */
|
|---|
| 1114 | if (!obj_bsssec (abfd)->user_set_vma)
|
|---|
| 1115 | obj_bsssec (abfd)->vma = vma;
|
|---|
| 1116 | else
|
|---|
| 1117 | vma = obj_bsssec (abfd)->vma;
|
|---|
| 1118 |
|
|---|
| 1119 | /* Fix up exec header. */
|
|---|
| 1120 | execp->a_text = obj_textsec (abfd)->_raw_size;
|
|---|
| 1121 | execp->a_data = obj_datasec (abfd)->_raw_size;
|
|---|
| 1122 | execp->a_bss = obj_bsssec (abfd)->_raw_size;
|
|---|
| 1123 | N_SET_MAGIC (*execp, NMAGIC);
|
|---|
| 1124 | }
|
|---|
| 1125 |
|
|---|
| 1126 | bfd_boolean
|
|---|
| 1127 | NAME(aout,adjust_sizes_and_vmas) (abfd, text_size, text_end)
|
|---|
| 1128 | bfd *abfd;
|
|---|
| 1129 | bfd_size_type *text_size;
|
|---|
| 1130 | file_ptr *text_end ATTRIBUTE_UNUSED;
|
|---|
| 1131 | {
|
|---|
| 1132 | struct internal_exec *execp = exec_hdr (abfd);
|
|---|
| 1133 |
|
|---|
| 1134 | if (! NAME(aout,make_sections) (abfd))
|
|---|
| 1135 | return FALSE;
|
|---|
| 1136 |
|
|---|
| 1137 | if (adata (abfd).magic != undecided_magic)
|
|---|
| 1138 | return TRUE;
|
|---|
| 1139 |
|
|---|
| 1140 | obj_textsec (abfd)->_raw_size =
|
|---|
| 1141 | align_power (obj_textsec (abfd)->_raw_size,
|
|---|
| 1142 | obj_textsec (abfd)->alignment_power);
|
|---|
| 1143 |
|
|---|
| 1144 | *text_size = obj_textsec (abfd)->_raw_size;
|
|---|
| 1145 | /* Rule (heuristic) for when to pad to a new page. Note that there
|
|---|
| 1146 | are (at least) two ways demand-paged (ZMAGIC) files have been
|
|---|
| 1147 | handled. Most Berkeley-based systems start the text segment at
|
|---|
| 1148 | (TARGET_PAGE_SIZE). However, newer versions of SUNOS start the text
|
|---|
| 1149 | segment right after the exec header; the latter is counted in the
|
|---|
| 1150 | text segment size, and is paged in by the kernel with the rest of
|
|---|
| 1151 | the text. */
|
|---|
| 1152 |
|
|---|
| 1153 | /* This perhaps isn't the right way to do this, but made it simpler for me
|
|---|
| 1154 | to understand enough to implement it. Better would probably be to go
|
|---|
| 1155 | right from BFD flags to alignment/positioning characteristics. But the
|
|---|
| 1156 | old code was sloppy enough about handling the flags, and had enough
|
|---|
| 1157 | other magic, that it was a little hard for me to understand. I think
|
|---|
| 1158 | I understand it better now, but I haven't time to do the cleanup this
|
|---|
| 1159 | minute. */
|
|---|
| 1160 |
|
|---|
| 1161 | if (abfd->flags & D_PAGED)
|
|---|
| 1162 | /* Whether or not WP_TEXT is set -- let D_PAGED override. */
|
|---|
| 1163 | adata (abfd).magic = z_magic;
|
|---|
| 1164 | else if (abfd->flags & WP_TEXT)
|
|---|
| 1165 | adata (abfd).magic = n_magic;
|
|---|
| 1166 | else
|
|---|
| 1167 | adata (abfd).magic = o_magic;
|
|---|
| 1168 |
|
|---|
| 1169 | #ifdef BFD_AOUT_DEBUG /* requires gcc2 */
|
|---|
| 1170 | #if __GNUC__ >= 2
|
|---|
| 1171 | fprintf (stderr, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n",
|
|---|
| 1172 | ({ char *str;
|
|---|
| 1173 | switch (adata (abfd).magic)
|
|---|
| 1174 | {
|
|---|
| 1175 | case n_magic: str = "NMAGIC"; break;
|
|---|
| 1176 | case o_magic: str = "OMAGIC"; break;
|
|---|
| 1177 | case z_magic: str = "ZMAGIC"; break;
|
|---|
| 1178 | default: abort ();
|
|---|
| 1179 | }
|
|---|
| 1180 | str;
|
|---|
| 1181 | }),
|
|---|
| 1182 | obj_textsec (abfd)->vma, obj_textsec (abfd)->_raw_size,
|
|---|
| 1183 | obj_textsec (abfd)->alignment_power,
|
|---|
| 1184 | obj_datasec (abfd)->vma, obj_datasec (abfd)->_raw_size,
|
|---|
| 1185 | obj_datasec (abfd)->alignment_power,
|
|---|
| 1186 | obj_bsssec (abfd)->vma, obj_bsssec (abfd)->_raw_size,
|
|---|
| 1187 | obj_bsssec (abfd)->alignment_power);
|
|---|
| 1188 | #endif
|
|---|
| 1189 | #endif
|
|---|
| 1190 |
|
|---|
| 1191 | switch (adata (abfd).magic)
|
|---|
| 1192 | {
|
|---|
| 1193 | case o_magic:
|
|---|
| 1194 | adjust_o_magic (abfd, execp);
|
|---|
| 1195 | break;
|
|---|
| 1196 | case z_magic:
|
|---|
| 1197 | adjust_z_magic (abfd, execp);
|
|---|
| 1198 | break;
|
|---|
| 1199 | case n_magic:
|
|---|
| 1200 | adjust_n_magic (abfd, execp);
|
|---|
| 1201 | break;
|
|---|
| 1202 | default:
|
|---|
| 1203 | abort ();
|
|---|
| 1204 | }
|
|---|
| 1205 |
|
|---|
| 1206 | #ifdef BFD_AOUT_DEBUG
|
|---|
| 1207 | fprintf (stderr, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n",
|
|---|
| 1208 | obj_textsec (abfd)->vma, obj_textsec (abfd)->_raw_size,
|
|---|
| 1209 | obj_textsec (abfd)->filepos,
|
|---|
| 1210 | obj_datasec (abfd)->vma, obj_datasec (abfd)->_raw_size,
|
|---|
| 1211 | obj_datasec (abfd)->filepos,
|
|---|
| 1212 | obj_bsssec (abfd)->vma, obj_bsssec (abfd)->_raw_size);
|
|---|
| 1213 | #endif
|
|---|
| 1214 |
|
|---|
| 1215 | return TRUE;
|
|---|
| 1216 | }
|
|---|
| 1217 |
|
|---|
| 1218 | /*
|
|---|
| 1219 | FUNCTION
|
|---|
| 1220 | aout_@var{size}_new_section_hook
|
|---|
| 1221 |
|
|---|
| 1222 | SYNOPSIS
|
|---|
| 1223 | bfd_boolean aout_@var{size}_new_section_hook,
|
|---|
| 1224 | (bfd *abfd,
|
|---|
| 1225 | asection *newsect));
|
|---|
| 1226 |
|
|---|
| 1227 | DESCRIPTION
|
|---|
| 1228 | Called by the BFD in response to a @code{bfd_make_section}
|
|---|
| 1229 | request.
|
|---|
| 1230 | */
|
|---|
| 1231 | bfd_boolean
|
|---|
| 1232 | NAME(aout,new_section_hook) (abfd, newsect)
|
|---|
| 1233 | bfd *abfd;
|
|---|
| 1234 | asection *newsect;
|
|---|
| 1235 | {
|
|---|
| 1236 | /* Align to double at least. */
|
|---|
| 1237 | newsect->alignment_power = bfd_get_arch_info (abfd)->section_align_power;
|
|---|
| 1238 |
|
|---|
| 1239 | if (bfd_get_format (abfd) == bfd_object)
|
|---|
| 1240 | {
|
|---|
| 1241 | if (obj_textsec (abfd) == NULL && !strcmp (newsect->name, ".text"))
|
|---|
| 1242 | {
|
|---|
| 1243 | obj_textsec (abfd)= newsect;
|
|---|
| 1244 | newsect->target_index = N_TEXT;
|
|---|
| 1245 | return TRUE;
|
|---|
| 1246 | }
|
|---|
| 1247 |
|
|---|
| 1248 | if (obj_datasec (abfd) == NULL && !strcmp (newsect->name, ".data"))
|
|---|
| 1249 | {
|
|---|
| 1250 | obj_datasec (abfd) = newsect;
|
|---|
| 1251 | newsect->target_index = N_DATA;
|
|---|
| 1252 | return TRUE;
|
|---|
| 1253 | }
|
|---|
| 1254 |
|
|---|
| 1255 | if (obj_bsssec (abfd) == NULL && !strcmp (newsect->name, ".bss"))
|
|---|
| 1256 | {
|
|---|
| 1257 | obj_bsssec (abfd) = newsect;
|
|---|
| 1258 | newsect->target_index = N_BSS;
|
|---|
| 1259 | return TRUE;
|
|---|
| 1260 | }
|
|---|
| 1261 | }
|
|---|
| 1262 |
|
|---|
| 1263 | /* We allow more than three sections internally. */
|
|---|
| 1264 | return TRUE;
|
|---|
| 1265 | }
|
|---|
| 1266 |
|
|---|
| 1267 | bfd_boolean
|
|---|
| 1268 | NAME(aout,set_section_contents) (abfd, section, location, offset, count)
|
|---|
| 1269 | bfd *abfd;
|
|---|
| 1270 | sec_ptr section;
|
|---|
| 1271 | PTR location;
|
|---|
| 1272 | file_ptr offset;
|
|---|
| 1273 | bfd_size_type count;
|
|---|
| 1274 | {
|
|---|
| 1275 | file_ptr text_end;
|
|---|
| 1276 | bfd_size_type text_size;
|
|---|
| 1277 |
|
|---|
| 1278 | if (! abfd->output_has_begun)
|
|---|
| 1279 | {
|
|---|
| 1280 | if (! NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end))
|
|---|
| 1281 | return FALSE;
|
|---|
| 1282 | }
|
|---|
| 1283 |
|
|---|
| 1284 | if (section == obj_bsssec (abfd))
|
|---|
| 1285 | {
|
|---|
| 1286 | bfd_set_error (bfd_error_no_contents);
|
|---|
| 1287 | return FALSE;
|
|---|
| 1288 | }
|
|---|
| 1289 |
|
|---|
| 1290 | if (section != obj_textsec (abfd)
|
|---|
| 1291 | && section != obj_datasec (abfd))
|
|---|
| 1292 | {
|
|---|
| 1293 | if (aout_section_merge_with_text_p (abfd, section))
|
|---|
| 1294 | section->filepos = obj_textsec (abfd)->filepos +
|
|---|
| 1295 | (section->vma - obj_textsec (abfd)->vma);
|
|---|
| 1296 | else
|
|---|
| 1297 | {
|
|---|
| 1298 | (*_bfd_error_handler)
|
|---|
| 1299 | (_("%s: can not represent section `%s' in a.out object file format"),
|
|---|
| 1300 | bfd_get_filename (abfd), bfd_get_section_name (abfd, section));
|
|---|
| 1301 | bfd_set_error (bfd_error_nonrepresentable_section);
|
|---|
| 1302 | return FALSE;
|
|---|
| 1303 | }
|
|---|
| 1304 | }
|
|---|
| 1305 |
|
|---|
| 1306 | if (count != 0)
|
|---|
| 1307 | {
|
|---|
| 1308 | if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
|
|---|
| 1309 | || bfd_bwrite (location, count, abfd) != count)
|
|---|
| 1310 | return FALSE;
|
|---|
| 1311 | }
|
|---|
| 1312 |
|
|---|
| 1313 | return TRUE;
|
|---|
| 1314 | }
|
|---|
| 1315 | |
|---|
| 1316 |
|
|---|
| 1317 | /* Read the external symbols from an a.out file. */
|
|---|
| 1318 |
|
|---|
| 1319 | static bfd_boolean
|
|---|
| 1320 | aout_get_external_symbols (abfd)
|
|---|
| 1321 | bfd *abfd;
|
|---|
| 1322 | {
|
|---|
| 1323 | if (obj_aout_external_syms (abfd) == (struct external_nlist *) NULL)
|
|---|
| 1324 | {
|
|---|
| 1325 | bfd_size_type count;
|
|---|
| 1326 | struct external_nlist *syms;
|
|---|
| 1327 | bfd_size_type amt;
|
|---|
| 1328 |
|
|---|
| 1329 | count = exec_hdr (abfd)->a_syms / EXTERNAL_NLIST_SIZE;
|
|---|
| 1330 |
|
|---|
| 1331 | #ifdef USE_MMAP
|
|---|
| 1332 | if (! bfd_get_file_window (abfd, obj_sym_filepos (abfd),
|
|---|
| 1333 | exec_hdr (abfd)->a_syms,
|
|---|
| 1334 | &obj_aout_sym_window (abfd), TRUE))
|
|---|
| 1335 | return FALSE;
|
|---|
| 1336 | syms = (struct external_nlist *) obj_aout_sym_window (abfd).data;
|
|---|
| 1337 | #else
|
|---|
| 1338 | /* We allocate using malloc to make the values easy to free
|
|---|
| 1339 | later on. If we put them on the objalloc it might not be
|
|---|
| 1340 | possible to free them. */
|
|---|
| 1341 | syms = ((struct external_nlist *)
|
|---|
| 1342 | bfd_malloc (count * EXTERNAL_NLIST_SIZE));
|
|---|
| 1343 | if (syms == (struct external_nlist *) NULL && count != 0)
|
|---|
| 1344 | return FALSE;
|
|---|
| 1345 |
|
|---|
| 1346 | amt = exec_hdr (abfd)->a_syms;
|
|---|
| 1347 | if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
|
|---|
| 1348 | || bfd_bread (syms, amt, abfd) != amt)
|
|---|
| 1349 | {
|
|---|
| 1350 | free (syms);
|
|---|
| 1351 | return FALSE;
|
|---|
| 1352 | }
|
|---|
| 1353 | #endif
|
|---|
| 1354 |
|
|---|
| 1355 | obj_aout_external_syms (abfd) = syms;
|
|---|
| 1356 | obj_aout_external_sym_count (abfd) = count;
|
|---|
| 1357 | }
|
|---|
| 1358 |
|
|---|
| 1359 | if (obj_aout_external_strings (abfd) == NULL
|
|---|
| 1360 | && exec_hdr (abfd)->a_syms != 0)
|
|---|
| 1361 | {
|
|---|
| 1362 | unsigned char string_chars[BYTES_IN_WORD];
|
|---|
| 1363 | bfd_size_type stringsize;
|
|---|
| 1364 | char *strings;
|
|---|
| 1365 | bfd_size_type amt = BYTES_IN_WORD;
|
|---|
| 1366 |
|
|---|
| 1367 | /* Get the size of the strings. */
|
|---|
| 1368 | if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0
|
|---|
| 1369 | || bfd_bread ((PTR) string_chars, amt, abfd) != amt)
|
|---|
| 1370 | return FALSE;
|
|---|
| 1371 | stringsize = GET_WORD (abfd, string_chars);
|
|---|
| 1372 |
|
|---|
| 1373 | #ifdef USE_MMAP
|
|---|
| 1374 | if (! bfd_get_file_window (abfd, obj_str_filepos (abfd), stringsize,
|
|---|
| 1375 | &obj_aout_string_window (abfd), TRUE))
|
|---|
| 1376 | return FALSE;
|
|---|
| 1377 | strings = (char *) obj_aout_string_window (abfd).data;
|
|---|
| 1378 | #else
|
|---|
| 1379 | strings = (char *) bfd_malloc (stringsize + 1);
|
|---|
| 1380 | if (strings == NULL)
|
|---|
| 1381 | return FALSE;
|
|---|
| 1382 |
|
|---|
| 1383 | /* Skip space for the string count in the buffer for convenience
|
|---|
| 1384 | when using indexes. */
|
|---|
| 1385 | amt = stringsize - BYTES_IN_WORD;
|
|---|
| 1386 | if (bfd_bread (strings + BYTES_IN_WORD, amt, abfd) != amt)
|
|---|
| 1387 | {
|
|---|
| 1388 | free (strings);
|
|---|
| 1389 | return FALSE;
|
|---|
| 1390 | }
|
|---|
| 1391 | #endif
|
|---|
| 1392 |
|
|---|
| 1393 | /* Ensure that a zero index yields an empty string. */
|
|---|
| 1394 | strings[0] = '\0';
|
|---|
| 1395 |
|
|---|
| 1396 | strings[stringsize - 1] = 0;
|
|---|
| 1397 |
|
|---|
| 1398 | obj_aout_external_strings (abfd) = strings;
|
|---|
| 1399 | obj_aout_external_string_size (abfd) = stringsize;
|
|---|
| 1400 | }
|
|---|
| 1401 |
|
|---|
| 1402 | return TRUE;
|
|---|
| 1403 | }
|
|---|
| 1404 |
|
|---|
| 1405 | /* Translate an a.out symbol into a BFD symbol. The desc, other, type
|
|---|
| 1406 | and symbol->value fields of CACHE_PTR will be set from the a.out
|
|---|
| 1407 | nlist structure. This function is responsible for setting
|
|---|
| 1408 | symbol->flags and symbol->section, and adjusting symbol->value. */
|
|---|
| 1409 |
|
|---|
| 1410 | static bfd_boolean
|
|---|
| 1411 | translate_from_native_sym_flags (abfd, cache_ptr)
|
|---|
| 1412 | bfd *abfd;
|
|---|
| 1413 | aout_symbol_type *cache_ptr;
|
|---|
| 1414 | {
|
|---|
| 1415 | flagword visible;
|
|---|
| 1416 |
|
|---|
| 1417 | if (IS_STAB(cache_ptr->type)
|
|---|
| 1418 | || cache_ptr->type == N_FN)
|
|---|
| 1419 | {
|
|---|
| 1420 | asection *sec;
|
|---|
| 1421 |
|
|---|
| 1422 | /* This is a debugging symbol. */
|
|---|
| 1423 | cache_ptr->symbol.flags = BSF_DEBUGGING;
|
|---|
| 1424 |
|
|---|
| 1425 | /* Work out the symbol section. */
|
|---|
| 1426 | switch (cache_ptr->type & N_TYPE)
|
|---|
| 1427 | {
|
|---|
| 1428 | case N_TEXT:
|
|---|
| 1429 | case N_FN:
|
|---|
| 1430 | sec = obj_textsec (abfd);
|
|---|
| 1431 | break;
|
|---|
| 1432 | case N_DATA:
|
|---|
| 1433 | sec = obj_datasec (abfd);
|
|---|
| 1434 | break;
|
|---|
| 1435 | case N_BSS:
|
|---|
| 1436 | sec = obj_bsssec (abfd);
|
|---|
| 1437 | break;
|
|---|
| 1438 | default:
|
|---|
| 1439 | case N_ABS:
|
|---|
| 1440 | sec = bfd_abs_section_ptr;
|
|---|
| 1441 | break;
|
|---|
| 1442 | }
|
|---|
| 1443 |
|
|---|
| 1444 | cache_ptr->symbol.section = sec;
|
|---|
| 1445 | cache_ptr->symbol.value -= sec->vma;
|
|---|
| 1446 |
|
|---|
| 1447 | return TRUE;
|
|---|
| 1448 | }
|
|---|
| 1449 |
|
|---|
| 1450 | /* Get the default visibility. This does not apply to all types, so
|
|---|
| 1451 | we just hold it in a local variable to use if wanted. */
|
|---|
| 1452 | if ((cache_ptr->type & N_EXT) == 0)
|
|---|
| 1453 | visible = BSF_LOCAL;
|
|---|
| 1454 | else
|
|---|
| 1455 | visible = BSF_GLOBAL;
|
|---|
| 1456 |
|
|---|
| 1457 | switch (cache_ptr->type)
|
|---|
| 1458 | {
|
|---|
| 1459 | default:
|
|---|
| 1460 | case N_ABS: case N_ABS | N_EXT:
|
|---|
| 1461 | cache_ptr->symbol.section = bfd_abs_section_ptr;
|
|---|
| 1462 | cache_ptr->symbol.flags = visible;
|
|---|
| 1463 | break;
|
|---|
| 1464 |
|
|---|
| 1465 | case N_UNDF | N_EXT:
|
|---|
| 1466 | if (cache_ptr->symbol.value != 0)
|
|---|
| 1467 | {
|
|---|
| 1468 | /* This is a common symbol. */
|
|---|
| 1469 | cache_ptr->symbol.flags = BSF_GLOBAL;
|
|---|
| 1470 | cache_ptr->symbol.section = bfd_com_section_ptr;
|
|---|
| 1471 | }
|
|---|
| 1472 | else
|
|---|
| 1473 | {
|
|---|
| 1474 | cache_ptr->symbol.flags = 0;
|
|---|
| 1475 | cache_ptr->symbol.section = bfd_und_section_ptr;
|
|---|
| 1476 | }
|
|---|
| 1477 | break;
|
|---|
| 1478 |
|
|---|
| 1479 | case N_TEXT: case N_TEXT | N_EXT:
|
|---|
| 1480 | cache_ptr->symbol.section = obj_textsec (abfd);
|
|---|
| 1481 | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
|
|---|
| 1482 | cache_ptr->symbol.flags = visible;
|
|---|
| 1483 | break;
|
|---|
| 1484 |
|
|---|
| 1485 | /* N_SETV symbols used to represent set vectors placed in the
|
|---|
| 1486 | data section. They are no longer generated. Theoretically,
|
|---|
| 1487 | it was possible to extract the entries and combine them with
|
|---|
| 1488 | new ones, although I don't know if that was ever actually
|
|---|
| 1489 | done. Unless that feature is restored, treat them as data
|
|---|
| 1490 | symbols. */
|
|---|
| 1491 | case N_SETV: case N_SETV | N_EXT:
|
|---|
| 1492 | case N_DATA: case N_DATA | N_EXT:
|
|---|
| 1493 | cache_ptr->symbol.section = obj_datasec (abfd);
|
|---|
| 1494 | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
|
|---|
| 1495 | cache_ptr->symbol.flags = visible;
|
|---|
| 1496 | break;
|
|---|
| 1497 |
|
|---|
| 1498 | case N_BSS: case N_BSS | N_EXT:
|
|---|
| 1499 | cache_ptr->symbol.section = obj_bsssec (abfd);
|
|---|
| 1500 | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
|
|---|
| 1501 | cache_ptr->symbol.flags = visible;
|
|---|
| 1502 | break;
|
|---|
| 1503 |
|
|---|
| 1504 | case N_SETA: case N_SETA | N_EXT:
|
|---|
| 1505 | case N_SETT: case N_SETT | N_EXT:
|
|---|
| 1506 | case N_SETD: case N_SETD | N_EXT:
|
|---|
| 1507 | case N_SETB: case N_SETB | N_EXT:
|
|---|
| 1508 | {
|
|---|
| 1509 | /* This code is no longer needed. It used to be used to make
|
|---|
| 1510 | the linker handle set symbols, but they are now handled in
|
|---|
| 1511 | the add_symbols routine instead. */
|
|---|
| 1512 | #if 0
|
|---|
| 1513 | asection *section;
|
|---|
| 1514 | arelent_chain *reloc;
|
|---|
| 1515 | asection *into_section;
|
|---|
| 1516 | bfd_size_type amt;
|
|---|
| 1517 |
|
|---|
| 1518 | /* This is a set symbol. The name of the symbol is the name
|
|---|
| 1519 | of the set (e.g., __CTOR_LIST__). The value of the symbol
|
|---|
| 1520 | is the value to add to the set. We create a section with
|
|---|
| 1521 | the same name as the symbol, and add a reloc to insert the
|
|---|
| 1522 | appropriate value into the section.
|
|---|
| 1523 |
|
|---|
| 1524 | This action is actually obsolete; it used to make the
|
|---|
| 1525 | linker do the right thing, but the linker no longer uses
|
|---|
| 1526 | this function. */
|
|---|
| 1527 |
|
|---|
| 1528 | section = bfd_get_section_by_name (abfd, cache_ptr->symbol.name);
|
|---|
| 1529 | if (section == NULL)
|
|---|
| 1530 | {
|
|---|
| 1531 | char *copy;
|
|---|
| 1532 |
|
|---|
| 1533 | amt = strlen (cache_ptr->symbol.name) + 1;
|
|---|
| 1534 | copy = bfd_alloc (abfd, amt);
|
|---|
| 1535 | if (copy == NULL)
|
|---|
| 1536 | return FALSE;
|
|---|
| 1537 |
|
|---|
| 1538 | strcpy (copy, cache_ptr->symbol.name);
|
|---|
| 1539 | section = bfd_make_section (abfd, copy);
|
|---|
| 1540 | if (section == NULL)
|
|---|
| 1541 | return FALSE;
|
|---|
| 1542 | }
|
|---|
| 1543 |
|
|---|
| 1544 | amt = sizeof (arelent_chain);
|
|---|
| 1545 | reloc = (arelent_chain *) bfd_alloc (abfd, amt);
|
|---|
| 1546 | if (reloc == NULL)
|
|---|
| 1547 | return FALSE;
|
|---|
| 1548 |
|
|---|
| 1549 | /* Build a relocation entry for the constructor. */
|
|---|
| 1550 | switch (cache_ptr->type & N_TYPE)
|
|---|
| 1551 | {
|
|---|
| 1552 | case N_SETA:
|
|---|
| 1553 | into_section = bfd_abs_section_ptr;
|
|---|
| 1554 | cache_ptr->type = N_ABS;
|
|---|
| 1555 | break;
|
|---|
| 1556 | case N_SETT:
|
|---|
| 1557 | into_section = obj_textsec (abfd);
|
|---|
| 1558 | cache_ptr->type = N_TEXT;
|
|---|
| 1559 | break;
|
|---|
| 1560 | case N_SETD:
|
|---|
| 1561 | into_section = obj_datasec (abfd);
|
|---|
| 1562 | cache_ptr->type = N_DATA;
|
|---|
| 1563 | break;
|
|---|
| 1564 | case N_SETB:
|
|---|
| 1565 | into_section = obj_bsssec (abfd);
|
|---|
| 1566 | cache_ptr->type = N_BSS;
|
|---|
| 1567 | break;
|
|---|
| 1568 | }
|
|---|
| 1569 |
|
|---|
| 1570 | /* Build a relocation pointing into the constructor section
|
|---|
| 1571 | pointing at the symbol in the set vector specified. */
|
|---|
| 1572 | reloc->relent.addend = cache_ptr->symbol.value;
|
|---|
| 1573 | cache_ptr->symbol.section = into_section;
|
|---|
| 1574 | reloc->relent.sym_ptr_ptr = into_section->symbol_ptr_ptr;
|
|---|
| 1575 |
|
|---|
| 1576 | /* We modify the symbol to belong to a section depending upon
|
|---|
| 1577 | the name of the symbol, and add to the size of the section
|
|---|
| 1578 | to contain a pointer to the symbol. Build a reloc entry to
|
|---|
| 1579 | relocate to this symbol attached to this section. */
|
|---|
| 1580 | section->flags = SEC_CONSTRUCTOR | SEC_RELOC;
|
|---|
| 1581 |
|
|---|
| 1582 | section->reloc_count++;
|
|---|
| 1583 | section->alignment_power = 2;
|
|---|
| 1584 |
|
|---|
| 1585 | reloc->next = section->constructor_chain;
|
|---|
| 1586 | section->constructor_chain = reloc;
|
|---|
| 1587 | reloc->relent.address = section->_raw_size;
|
|---|
| 1588 | section->_raw_size += BYTES_IN_WORD;
|
|---|
| 1589 |
|
|---|
| 1590 | reloc->relent.howto = CTOR_TABLE_RELOC_HOWTO (abfd);
|
|---|
| 1591 |
|
|---|
| 1592 | #endif /* 0 */
|
|---|
| 1593 |
|
|---|
| 1594 | switch (cache_ptr->type & N_TYPE)
|
|---|
| 1595 | {
|
|---|
| 1596 | case N_SETA:
|
|---|
| 1597 | cache_ptr->symbol.section = bfd_abs_section_ptr;
|
|---|
| 1598 | break;
|
|---|
| 1599 | case N_SETT:
|
|---|
| 1600 | cache_ptr->symbol.section = obj_textsec (abfd);
|
|---|
| 1601 | break;
|
|---|
| 1602 | case N_SETD:
|
|---|
| 1603 | cache_ptr->symbol.section = obj_datasec (abfd);
|
|---|
| 1604 | break;
|
|---|
| 1605 | case N_SETB:
|
|---|
| 1606 | cache_ptr->symbol.section = obj_bsssec (abfd);
|
|---|
| 1607 | break;
|
|---|
| 1608 | }
|
|---|
| 1609 |
|
|---|
| 1610 | cache_ptr->symbol.flags |= BSF_CONSTRUCTOR;
|
|---|
| 1611 | }
|
|---|
| 1612 | break;
|
|---|
| 1613 |
|
|---|
| 1614 | case N_WARNING:
|
|---|
| 1615 | /* This symbol is the text of a warning message. The next
|
|---|
| 1616 | symbol is the symbol to associate the warning with. If a
|
|---|
| 1617 | reference is made to that symbol, a warning is issued. */
|
|---|
| 1618 | cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_WARNING;
|
|---|
| 1619 | cache_ptr->symbol.section = bfd_abs_section_ptr;
|
|---|
| 1620 | break;
|
|---|
| 1621 |
|
|---|
| 1622 | case N_INDR: case N_INDR | N_EXT:
|
|---|
| 1623 | /* An indirect symbol. This consists of two symbols in a row.
|
|---|
| 1624 | The first symbol is the name of the indirection. The second
|
|---|
| 1625 | symbol is the name of the target. A reference to the first
|
|---|
| 1626 | symbol becomes a reference to the second. */
|
|---|
| 1627 | cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_INDIRECT | visible;
|
|---|
| 1628 | cache_ptr->symbol.section = bfd_ind_section_ptr;
|
|---|
| 1629 | break;
|
|---|
| 1630 |
|
|---|
| 1631 | case N_WEAKU:
|
|---|
| 1632 | cache_ptr->symbol.section = bfd_und_section_ptr;
|
|---|
| 1633 | cache_ptr->symbol.flags = BSF_WEAK;
|
|---|
| 1634 | break;
|
|---|
| 1635 |
|
|---|
| 1636 | case N_WEAKA:
|
|---|
| 1637 | cache_ptr->symbol.section = bfd_abs_section_ptr;
|
|---|
| 1638 | cache_ptr->symbol.flags = BSF_WEAK;
|
|---|
| 1639 | break;
|
|---|
| 1640 |
|
|---|
| 1641 | case N_WEAKT:
|
|---|
| 1642 | cache_ptr->symbol.section = obj_textsec (abfd);
|
|---|
| 1643 | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
|
|---|
| 1644 | cache_ptr->symbol.flags = BSF_WEAK;
|
|---|
| 1645 | break;
|
|---|
| 1646 |
|
|---|
| 1647 | case N_WEAKD:
|
|---|
| 1648 | cache_ptr->symbol.section = obj_datasec (abfd);
|
|---|
| 1649 | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
|
|---|
| 1650 | cache_ptr->symbol.flags = BSF_WEAK;
|
|---|
| 1651 | break;
|
|---|
| 1652 |
|
|---|
| 1653 | case N_WEAKB:
|
|---|
| 1654 | cache_ptr->symbol.section = obj_bsssec (abfd);
|
|---|
| 1655 | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
|
|---|
| 1656 | cache_ptr->symbol.flags = BSF_WEAK;
|
|---|
| 1657 | break;
|
|---|
| 1658 |
|
|---|
| 1659 | #ifdef EMX
|
|---|
| 1660 | case N_IMP1 | N_EXT:
|
|---|
| 1661 | cache_ptr->symbol.section = bfd_abs_section_ptr;
|
|---|
| 1662 | cache_ptr->symbol.flags = BSF_EMX_IMPORT1;
|
|---|
| 1663 | break;
|
|---|
| 1664 |
|
|---|
| 1665 | case N_IMP2 | N_EXT:
|
|---|
| 1666 | cache_ptr->symbol.section = bfd_abs_section_ptr;
|
|---|
| 1667 | cache_ptr->symbol.flags = BSF_EMX_IMPORT2;
|
|---|
| 1668 | break;
|
|---|
| 1669 | #endif /* EMX */
|
|---|
| 1670 | }
|
|---|
| 1671 |
|
|---|
| 1672 | return TRUE;
|
|---|
| 1673 | }
|
|---|
| 1674 |
|
|---|
| 1675 | /* Set the fields of SYM_POINTER according to CACHE_PTR. */
|
|---|
| 1676 |
|
|---|
| 1677 | static bfd_boolean
|
|---|
| 1678 | translate_to_native_sym_flags (abfd, cache_ptr, sym_pointer)
|
|---|
| 1679 | bfd *abfd;
|
|---|
| 1680 | asymbol *cache_ptr;
|
|---|
| 1681 | struct external_nlist *sym_pointer;
|
|---|
| 1682 | {
|
|---|
| 1683 | bfd_vma value = cache_ptr->value;
|
|---|
| 1684 | asection *sec;
|
|---|
| 1685 | bfd_vma off;
|
|---|
| 1686 |
|
|---|
| 1687 | /* Mask out any existing type bits in case copying from one section
|
|---|
| 1688 | to another. */
|
|---|
| 1689 | sym_pointer->e_type[0] &= ~N_TYPE;
|
|---|
| 1690 |
|
|---|
| 1691 | sec = bfd_get_section (cache_ptr);
|
|---|
| 1692 | off = 0;
|
|---|
| 1693 |
|
|---|
| 1694 | if (sec == NULL)
|
|---|
| 1695 | {
|
|---|
| 1696 | /* This case occurs, e.g., for the *DEBUG* section of a COFF
|
|---|
| 1697 | file. */
|
|---|
| 1698 | (*_bfd_error_handler)
|
|---|
| 1699 | (_("%s: can not represent section for symbol `%s' in a.out object file format"),
|
|---|
| 1700 | bfd_get_filename (abfd),
|
|---|
| 1701 | cache_ptr->name != NULL ? cache_ptr->name : _("*unknown*"));
|
|---|
| 1702 | bfd_set_error (bfd_error_nonrepresentable_section);
|
|---|
| 1703 | return FALSE;
|
|---|
| 1704 | }
|
|---|
| 1705 |
|
|---|
| 1706 | if (sec->output_section != NULL)
|
|---|
| 1707 | {
|
|---|
| 1708 | off = sec->output_offset;
|
|---|
| 1709 | sec = sec->output_section;
|
|---|
| 1710 | }
|
|---|
| 1711 |
|
|---|
| 1712 | if (bfd_is_abs_section (sec))
|
|---|
| 1713 | sym_pointer->e_type[0] |= N_ABS;
|
|---|
| 1714 | else if (sec == obj_textsec (abfd))
|
|---|
| 1715 | sym_pointer->e_type[0] |= N_TEXT;
|
|---|
| 1716 | else if (sec == obj_datasec (abfd))
|
|---|
| 1717 | sym_pointer->e_type[0] |= N_DATA;
|
|---|
| 1718 | else if (sec == obj_bsssec (abfd))
|
|---|
| 1719 | sym_pointer->e_type[0] |= N_BSS;
|
|---|
| 1720 | else if (bfd_is_und_section (sec))
|
|---|
| 1721 | sym_pointer->e_type[0] = N_UNDF | N_EXT;
|
|---|
| 1722 | else if (bfd_is_ind_section (sec))
|
|---|
| 1723 | sym_pointer->e_type[0] = N_INDR;
|
|---|
| 1724 | else if (bfd_is_com_section (sec))
|
|---|
| 1725 | sym_pointer->e_type[0] = N_UNDF | N_EXT;
|
|---|
| 1726 | else
|
|---|
| 1727 | {
|
|---|
| 1728 | if (aout_section_merge_with_text_p (abfd, sec))
|
|---|
| 1729 | sym_pointer->e_type[0] |= N_TEXT;
|
|---|
| 1730 | else
|
|---|
| 1731 | {
|
|---|
| 1732 | (*_bfd_error_handler)
|
|---|
| 1733 | (_("%s: can not represent section `%s' in a.out object file format"),
|
|---|
| 1734 | bfd_get_filename (abfd), bfd_get_section_name (abfd, sec));
|
|---|
| 1735 | bfd_set_error (bfd_error_nonrepresentable_section);
|
|---|
| 1736 | return FALSE;
|
|---|
| 1737 | }
|
|---|
| 1738 | }
|
|---|
| 1739 |
|
|---|
| 1740 | /* Turn the symbol from section relative to absolute again. */
|
|---|
| 1741 | value += sec->vma + off;
|
|---|
| 1742 |
|
|---|
| 1743 | if ((cache_ptr->flags & BSF_WARNING) != 0)
|
|---|
| 1744 | sym_pointer->e_type[0] = N_WARNING;
|
|---|
| 1745 |
|
|---|
| 1746 | if ((cache_ptr->flags & BSF_DEBUGGING) != 0)
|
|---|
| 1747 | sym_pointer->e_type[0] = ((aout_symbol_type *) cache_ptr)->type;
|
|---|
| 1748 | else if ((cache_ptr->flags & BSF_GLOBAL) != 0)
|
|---|
| 1749 | sym_pointer->e_type[0] |= N_EXT;
|
|---|
| 1750 | else if ((cache_ptr->flags & BSF_LOCAL) != 0)
|
|---|
| 1751 | sym_pointer->e_type[0] &= ~N_EXT;
|
|---|
| 1752 |
|
|---|
| 1753 | if ((cache_ptr->flags & BSF_CONSTRUCTOR) != 0)
|
|---|
| 1754 | {
|
|---|
| 1755 | int type = ((aout_symbol_type *) cache_ptr)->type;
|
|---|
| 1756 |
|
|---|
| 1757 | switch (type)
|
|---|
| 1758 | {
|
|---|
| 1759 | case N_ABS: type = N_SETA; break;
|
|---|
| 1760 | case N_TEXT: type = N_SETT; break;
|
|---|
| 1761 | case N_DATA: type = N_SETD; break;
|
|---|
| 1762 | case N_BSS: type = N_SETB; break;
|
|---|
| 1763 | }
|
|---|
| 1764 | sym_pointer->e_type[0] = type;
|
|---|
| 1765 | }
|
|---|
| 1766 |
|
|---|
| 1767 | if ((cache_ptr->flags & BSF_WEAK) != 0)
|
|---|
| 1768 | {
|
|---|
| 1769 | int type;
|
|---|
| 1770 |
|
|---|
| 1771 | switch (sym_pointer->e_type[0] & N_TYPE)
|
|---|
| 1772 | {
|
|---|
| 1773 | default:
|
|---|
| 1774 | case N_ABS: type = N_WEAKA; break;
|
|---|
| 1775 | case N_TEXT: type = N_WEAKT; break;
|
|---|
| 1776 | case N_DATA: type = N_WEAKD; break;
|
|---|
| 1777 | case N_BSS: type = N_WEAKB; break;
|
|---|
| 1778 | case N_UNDF: type = N_WEAKU; break;
|
|---|
| 1779 | }
|
|---|
| 1780 | sym_pointer->e_type[0] = type;
|
|---|
| 1781 | }
|
|---|
| 1782 |
|
|---|
| 1783 | PUT_WORD (abfd, value, sym_pointer->e_value);
|
|---|
| 1784 |
|
|---|
| 1785 | return TRUE;
|
|---|
| 1786 | }
|
|---|
| 1787 | |
|---|
| 1788 |
|
|---|
| 1789 | /* Native-level interface to symbols. */
|
|---|
| 1790 |
|
|---|
| 1791 | asymbol *
|
|---|
| 1792 | NAME(aout,make_empty_symbol) (abfd)
|
|---|
| 1793 | bfd *abfd;
|
|---|
| 1794 | {
|
|---|
| 1795 | bfd_size_type amt = sizeof (aout_symbol_type);
|
|---|
| 1796 | aout_symbol_type *new = (aout_symbol_type *) bfd_zalloc (abfd, amt);
|
|---|
| 1797 | if (!new)
|
|---|
| 1798 | return NULL;
|
|---|
| 1799 | new->symbol.the_bfd = abfd;
|
|---|
| 1800 |
|
|---|
| 1801 | return &new->symbol;
|
|---|
| 1802 | }
|
|---|
| 1803 |
|
|---|
| 1804 | /* Translate a set of internal symbols into external symbols. */
|
|---|
| 1805 |
|
|---|
| 1806 | bfd_boolean
|
|---|
| 1807 | NAME(aout,translate_symbol_table) (abfd, in, ext, count, str, strsize, dynamic)
|
|---|
| 1808 | bfd *abfd;
|
|---|
| 1809 | aout_symbol_type *in;
|
|---|
| 1810 | struct external_nlist *ext;
|
|---|
| 1811 | bfd_size_type count;
|
|---|
| 1812 | char *str;
|
|---|
| 1813 | bfd_size_type strsize;
|
|---|
| 1814 | bfd_boolean dynamic;
|
|---|
| 1815 | {
|
|---|
| 1816 | struct external_nlist *ext_end;
|
|---|
| 1817 |
|
|---|
| 1818 | ext_end = ext + count;
|
|---|
| 1819 | for (; ext < ext_end; ext++, in++)
|
|---|
| 1820 | {
|
|---|
| 1821 | bfd_vma x;
|
|---|
| 1822 |
|
|---|
| 1823 | x = GET_WORD (abfd, ext->e_strx);
|
|---|
| 1824 | in->symbol.the_bfd = abfd;
|
|---|
| 1825 |
|
|---|
| 1826 | /* For the normal symbols, the zero index points at the number
|
|---|
| 1827 | of bytes in the string table but is to be interpreted as the
|
|---|
| 1828 | null string. For the dynamic symbols, the number of bytes in
|
|---|
| 1829 | the string table is stored in the __DYNAMIC structure and the
|
|---|
| 1830 | zero index points at an actual string. */
|
|---|
| 1831 | if (x == 0 && ! dynamic)
|
|---|
| 1832 | in->symbol.name = "";
|
|---|
| 1833 | else if (x < strsize)
|
|---|
| 1834 | in->symbol.name = str + x;
|
|---|
| 1835 | else
|
|---|
| 1836 | return FALSE;
|
|---|
| 1837 |
|
|---|
| 1838 | in->symbol.value = GET_SWORD (abfd, ext->e_value);
|
|---|
| 1839 | in->desc = H_GET_16 (abfd, ext->e_desc);
|
|---|
| 1840 | in->other = H_GET_8 (abfd, ext->e_other);
|
|---|
| 1841 | in->type = H_GET_8 (abfd, ext->e_type);
|
|---|
| 1842 | in->symbol.udata.p = NULL;
|
|---|
| 1843 |
|
|---|
| 1844 | if (! translate_from_native_sym_flags (abfd, in))
|
|---|
| 1845 | return FALSE;
|
|---|
| 1846 |
|
|---|
| 1847 | if (dynamic)
|
|---|
| 1848 | in->symbol.flags |= BSF_DYNAMIC;
|
|---|
| 1849 | }
|
|---|
| 1850 |
|
|---|
| 1851 | return TRUE;
|
|---|
| 1852 | }
|
|---|
| 1853 |
|
|---|
| 1854 | /* We read the symbols into a buffer, which is discarded when this
|
|---|
| 1855 | function exits. We read the strings into a buffer large enough to
|
|---|
| 1856 | hold them all plus all the cached symbol entries. */
|
|---|
| 1857 |
|
|---|
| 1858 | bfd_boolean
|
|---|
| 1859 | NAME(aout,slurp_symbol_table) (abfd)
|
|---|
| 1860 | bfd *abfd;
|
|---|
| 1861 | {
|
|---|
| 1862 | struct external_nlist *old_external_syms;
|
|---|
| 1863 | aout_symbol_type *cached;
|
|---|
| 1864 | bfd_size_type cached_size;
|
|---|
| 1865 |
|
|---|
| 1866 | /* If there's no work to be done, don't do any. */
|
|---|
| 1867 | if (obj_aout_symbols (abfd) != (aout_symbol_type *) NULL)
|
|---|
| 1868 | return TRUE;
|
|---|
| 1869 |
|
|---|
| 1870 | old_external_syms = obj_aout_external_syms (abfd);
|
|---|
| 1871 |
|
|---|
| 1872 | if (! aout_get_external_symbols (abfd))
|
|---|
| 1873 | return FALSE;
|
|---|
| 1874 |
|
|---|
| 1875 | cached_size = obj_aout_external_sym_count (abfd);
|
|---|
| 1876 | cached_size *= sizeof (aout_symbol_type);
|
|---|
| 1877 | cached = (aout_symbol_type *) bfd_zmalloc (cached_size);
|
|---|
| 1878 | if (cached == NULL && cached_size != 0)
|
|---|
| 1879 | return FALSE;
|
|---|
| 1880 |
|
|---|
| 1881 | /* Convert from external symbol information to internal. */
|
|---|
| 1882 | if (! (NAME(aout,translate_symbol_table)
|
|---|
| 1883 | (abfd, cached,
|
|---|
| 1884 | obj_aout_external_syms (abfd),
|
|---|
| 1885 | obj_aout_external_sym_count (abfd),
|
|---|
| 1886 | obj_aout_external_strings (abfd),
|
|---|
| 1887 | obj_aout_external_string_size (abfd),
|
|---|
| 1888 | FALSE)))
|
|---|
| 1889 | {
|
|---|
| 1890 | free (cached);
|
|---|
| 1891 | return FALSE;
|
|---|
| 1892 | }
|
|---|
| 1893 |
|
|---|
| 1894 | bfd_get_symcount (abfd) = obj_aout_external_sym_count (abfd);
|
|---|
| 1895 |
|
|---|
| 1896 | obj_aout_symbols (abfd) = cached;
|
|---|
| 1897 |
|
|---|
| 1898 | /* It is very likely that anybody who calls this function will not
|
|---|
| 1899 | want the external symbol information, so if it was allocated
|
|---|
| 1900 | because of our call to aout_get_external_symbols, we free it up
|
|---|
| 1901 | right away to save space. */
|
|---|
| 1902 | if (old_external_syms == (struct external_nlist *) NULL
|
|---|
| 1903 | && obj_aout_external_syms (abfd) != (struct external_nlist *) NULL)
|
|---|
| 1904 | {
|
|---|
| 1905 | #ifdef USE_MMAP
|
|---|
| 1906 | bfd_free_window (&obj_aout_sym_window (abfd));
|
|---|
| 1907 | #else
|
|---|
| 1908 | free (obj_aout_external_syms (abfd));
|
|---|
| 1909 | #endif
|
|---|
| 1910 | obj_aout_external_syms (abfd) = NULL;
|
|---|
| 1911 | }
|
|---|
| 1912 |
|
|---|
| 1913 | return TRUE;
|
|---|
| 1914 | }
|
|---|
| 1915 | |
|---|
| 1916 |
|
|---|
| 1917 | /* We use a hash table when writing out symbols so that we only write
|
|---|
| 1918 | out a particular string once. This helps particularly when the
|
|---|
| 1919 | linker writes out stabs debugging entries, because each different
|
|---|
| 1920 | contributing object file tends to have many duplicate stabs
|
|---|
| 1921 | strings.
|
|---|
| 1922 |
|
|---|
| 1923 | This hash table code breaks dbx on SunOS 4.1.3, so we don't do it
|
|---|
| 1924 | if BFD_TRADITIONAL_FORMAT is set. */
|
|---|
| 1925 |
|
|---|
| 1926 | static bfd_size_type add_to_stringtab
|
|---|
| 1927 | PARAMS ((bfd *, struct bfd_strtab_hash *, const char *, bfd_boolean));
|
|---|
| 1928 | static bfd_boolean emit_stringtab
|
|---|
| 1929 | PARAMS ((bfd *, struct bfd_strtab_hash *));
|
|---|
| 1930 |
|
|---|
| 1931 | /* Get the index of a string in a strtab, adding it if it is not
|
|---|
| 1932 | already present. */
|
|---|
| 1933 |
|
|---|
| 1934 | static INLINE bfd_size_type
|
|---|
| 1935 | add_to_stringtab (abfd, tab, str, copy)
|
|---|
| 1936 | bfd *abfd;
|
|---|
| 1937 | struct bfd_strtab_hash *tab;
|
|---|
| 1938 | const char *str;
|
|---|
| 1939 | bfd_boolean copy;
|
|---|
| 1940 | {
|
|---|
| 1941 | bfd_boolean hash;
|
|---|
| 1942 | bfd_size_type index;
|
|---|
| 1943 |
|
|---|
| 1944 | /* An index of 0 always means the empty string. */
|
|---|
| 1945 | if (str == 0 || *str == '\0')
|
|---|
| 1946 | return 0;
|
|---|
| 1947 |
|
|---|
| 1948 | /* Don't hash if BFD_TRADITIONAL_FORMAT is set, because SunOS dbx
|
|---|
| 1949 | doesn't understand a hashed string table. */
|
|---|
| 1950 | hash = TRUE;
|
|---|
| 1951 | if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
|
|---|
| 1952 | hash = FALSE;
|
|---|
| 1953 |
|
|---|
| 1954 | index = _bfd_stringtab_add (tab, str, hash, copy);
|
|---|
| 1955 |
|
|---|
| 1956 | if (index != (bfd_size_type) -1)
|
|---|
| 1957 | {
|
|---|
| 1958 | /* Add BYTES_IN_WORD to the return value to account for the
|
|---|
| 1959 | space taken up by the string table size. */
|
|---|
| 1960 | index += BYTES_IN_WORD;
|
|---|
| 1961 | }
|
|---|
| 1962 |
|
|---|
| 1963 | return index;
|
|---|
| 1964 | }
|
|---|
| 1965 |
|
|---|
| 1966 | /* Write out a strtab. ABFD is already at the right location in the
|
|---|
| 1967 | file. */
|
|---|
| 1968 |
|
|---|
| 1969 | static bfd_boolean
|
|---|
| 1970 | emit_stringtab (abfd, tab)
|
|---|
| 1971 | register bfd *abfd;
|
|---|
| 1972 | struct bfd_strtab_hash *tab;
|
|---|
| 1973 | {
|
|---|
| 1974 | bfd_byte buffer[BYTES_IN_WORD];
|
|---|
| 1975 | bfd_size_type amt = BYTES_IN_WORD;
|
|---|
| 1976 |
|
|---|
| 1977 | /* The string table starts with the size. */
|
|---|
| 1978 | PUT_WORD (abfd, _bfd_stringtab_size (tab) + BYTES_IN_WORD, buffer);
|
|---|
| 1979 | if (bfd_bwrite ((PTR) buffer, amt, abfd) != amt)
|
|---|
| 1980 | return FALSE;
|
|---|
| 1981 |
|
|---|
| 1982 | return _bfd_stringtab_emit (abfd, tab);
|
|---|
| 1983 | }
|
|---|
| 1984 | |
|---|
| 1985 |
|
|---|
| 1986 | bfd_boolean
|
|---|
| 1987 | NAME(aout,write_syms) (abfd)
|
|---|
| 1988 | bfd *abfd;
|
|---|
| 1989 | {
|
|---|
| 1990 | unsigned int count ;
|
|---|
| 1991 | asymbol **generic = bfd_get_outsymbols (abfd);
|
|---|
| 1992 | struct bfd_strtab_hash *strtab;
|
|---|
| 1993 |
|
|---|
| 1994 | strtab = _bfd_stringtab_init ();
|
|---|
| 1995 | if (strtab == NULL)
|
|---|
| 1996 | return FALSE;
|
|---|
| 1997 |
|
|---|
| 1998 | for (count = 0; count < bfd_get_symcount (abfd); count++)
|
|---|
| 1999 | {
|
|---|
| 2000 | asymbol *g = generic[count];
|
|---|
| 2001 | bfd_size_type indx;
|
|---|
| 2002 | struct external_nlist nsp;
|
|---|
| 2003 | bfd_size_type amt;
|
|---|
| 2004 |
|
|---|
| 2005 | indx = add_to_stringtab (abfd, strtab, g->name, FALSE);
|
|---|
| 2006 | if (indx == (bfd_size_type) -1)
|
|---|
| 2007 | goto error_return;
|
|---|
| 2008 | PUT_WORD (abfd, indx, (bfd_byte *) nsp.e_strx);
|
|---|
| 2009 |
|
|---|
| 2010 | if (bfd_asymbol_flavour (g) == abfd->xvec->flavour)
|
|---|
| 2011 | {
|
|---|
| 2012 | H_PUT_16 (abfd, aout_symbol (g)->desc, nsp.e_desc);
|
|---|
| 2013 | H_PUT_8 (abfd, aout_symbol (g)->other, nsp.e_other);
|
|---|
| 2014 | H_PUT_8 (abfd, aout_symbol (g)->type, nsp.e_type);
|
|---|
| 2015 | }
|
|---|
| 2016 | else
|
|---|
| 2017 | {
|
|---|
| 2018 | H_PUT_16 (abfd, 0, nsp.e_desc);
|
|---|
| 2019 | H_PUT_8 (abfd, 0, nsp.e_other);
|
|---|
| 2020 | H_PUT_8 (abfd, 0, nsp.e_type);
|
|---|
| 2021 | }
|
|---|
| 2022 |
|
|---|
| 2023 | if (! translate_to_native_sym_flags (abfd, g, &nsp))
|
|---|
| 2024 | goto error_return;
|
|---|
| 2025 |
|
|---|
| 2026 | amt = EXTERNAL_NLIST_SIZE;
|
|---|
| 2027 | if (bfd_bwrite ((PTR) &nsp, amt, abfd) != amt)
|
|---|
| 2028 | goto error_return;
|
|---|
| 2029 |
|
|---|
| 2030 | /* NB: `KEEPIT' currently overlays `udata.p', so set this only
|
|---|
| 2031 | here, at the end. */
|
|---|
| 2032 | g->KEEPIT = count;
|
|---|
| 2033 | }
|
|---|
| 2034 |
|
|---|
| 2035 | if (! emit_stringtab (abfd, strtab))
|
|---|
| 2036 | goto error_return;
|
|---|
| 2037 |
|
|---|
| 2038 | _bfd_stringtab_free (strtab);
|
|---|
| 2039 |
|
|---|
| 2040 | return TRUE;
|
|---|
| 2041 |
|
|---|
| 2042 | error_return:
|
|---|
| 2043 | _bfd_stringtab_free (strtab);
|
|---|
| 2044 | return FALSE;
|
|---|
| 2045 | }
|
|---|
| 2046 | |
|---|
| 2047 |
|
|---|
| 2048 | long
|
|---|
| 2049 | NAME(aout,get_symtab) (abfd, location)
|
|---|
| 2050 | bfd *abfd;
|
|---|
| 2051 | asymbol **location;
|
|---|
| 2052 | {
|
|---|
| 2053 | unsigned int counter = 0;
|
|---|
| 2054 | aout_symbol_type *symbase;
|
|---|
| 2055 |
|
|---|
| 2056 | if (!NAME(aout,slurp_symbol_table) (abfd))
|
|---|
| 2057 | return -1;
|
|---|
| 2058 |
|
|---|
| 2059 | for (symbase = obj_aout_symbols (abfd);
|
|---|
| 2060 | counter++ < bfd_get_symcount (abfd);
|
|---|
| 2061 | )
|
|---|
| 2062 | *(location++) = (asymbol *) (symbase++);
|
|---|
| 2063 | *location++ =0;
|
|---|
| 2064 | return bfd_get_symcount (abfd);
|
|---|
| 2065 | }
|
|---|
| 2066 | |
|---|
| 2067 |
|
|---|
| 2068 | /* Standard reloc stuff. */
|
|---|
| 2069 | /* Output standard relocation information to a file in target byte order. */
|
|---|
| 2070 |
|
|---|
| 2071 | extern void NAME(aout,swap_std_reloc_out)
|
|---|
| 2072 | PARAMS ((bfd *, arelent *, struct reloc_std_external *));
|
|---|
| 2073 |
|
|---|
| 2074 | void
|
|---|
| 2075 | NAME(aout,swap_std_reloc_out) (abfd, g, natptr)
|
|---|
| 2076 | bfd *abfd;
|
|---|
| 2077 | arelent *g;
|
|---|
| 2078 | struct reloc_std_external *natptr;
|
|---|
| 2079 | {
|
|---|
| 2080 | int r_index;
|
|---|
| 2081 | asymbol *sym = *(g->sym_ptr_ptr);
|
|---|
| 2082 | int r_extern;
|
|---|
| 2083 | unsigned int r_length;
|
|---|
| 2084 | int r_pcrel;
|
|---|
| 2085 | int r_baserel, r_jmptable, r_relative;
|
|---|
| 2086 | asection *output_section = sym->section->output_section;
|
|---|
| 2087 |
|
|---|
| 2088 | /* bird - start */
|
|---|
| 2089 | /* Output reloctions to weak symbols as if they were undefined externals.
|
|---|
| 2090 | The aoutx.h code relocates them as if they were nothing special and I can't
|
|---|
| 2091 | see the linker doing the right thing either when it processes it. */
|
|---|
| 2092 | int is_weak = g->sym_ptr_ptr
|
|---|
| 2093 | && *g->sym_ptr_ptr
|
|---|
| 2094 | && ((*g->sym_ptr_ptr)->flags & BSF_WEAK);
|
|---|
| 2095 | /* bird - end */
|
|---|
| 2096 |
|
|---|
| 2097 | PUT_WORD (abfd, g->address, natptr->r_address);
|
|---|
| 2098 |
|
|---|
| 2099 | r_length = g->howto->size ; /* Size as a power of two. */
|
|---|
| 2100 | r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */
|
|---|
| 2101 | /* XXX This relies on relocs coming from a.out files. */
|
|---|
| 2102 | r_baserel = (g->howto->type & 8) != 0;
|
|---|
| 2103 | r_jmptable = (g->howto->type & 16) != 0;
|
|---|
| 2104 | r_relative = (g->howto->type & 32) != 0;
|
|---|
| 2105 |
|
|---|
| 2106 | #if 0
|
|---|
| 2107 | /* For a standard reloc, the addend is in the object file. */
|
|---|
| 2108 | r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma;
|
|---|
| 2109 | #endif
|
|---|
| 2110 |
|
|---|
| 2111 | /* Name was clobbered by aout_write_syms to be symbol index. */
|
|---|
| 2112 |
|
|---|
| 2113 | /* If this relocation is relative to a symbol then set the
|
|---|
| 2114 | r_index to the symbols index, and the r_extern bit.
|
|---|
| 2115 |
|
|---|
| 2116 | Absolute symbols can come in in two ways, either as an offset
|
|---|
| 2117 | from the abs section, or as a symbol which has an abs value.
|
|---|
| 2118 | check for that here. */
|
|---|
| 2119 |
|
|---|
| 2120 | if (bfd_is_com_section (output_section)
|
|---|
| 2121 | || bfd_is_abs_section (output_section)
|
|---|
| 2122 | || bfd_is_und_section (output_section)
|
|---|
| 2123 | || is_weak) /* bird */
|
|---|
| 2124 | {
|
|---|
| 2125 | if (bfd_abs_section_ptr->symbol == sym)
|
|---|
| 2126 | {
|
|---|
| 2127 | /* Whoops, looked like an abs symbol, but is
|
|---|
| 2128 | really an offset from the abs section. */
|
|---|
| 2129 | r_index = N_ABS;
|
|---|
| 2130 | r_extern = 0;
|
|---|
| 2131 | }
|
|---|
| 2132 | else
|
|---|
| 2133 | {
|
|---|
| 2134 | /* Fill in symbol. */
|
|---|
| 2135 | r_extern = 1;
|
|---|
| 2136 | r_index = (*(g->sym_ptr_ptr))->KEEPIT;
|
|---|
| 2137 | }
|
|---|
| 2138 | }
|
|---|
| 2139 | else
|
|---|
| 2140 | {
|
|---|
| 2141 | /* Just an ordinary section. */
|
|---|
| 2142 | r_extern = 0;
|
|---|
| 2143 | r_index = output_section->target_index;
|
|---|
| 2144 | }
|
|---|
| 2145 |
|
|---|
| 2146 | /* Now the fun stuff. */
|
|---|
| 2147 | if (bfd_header_big_endian (abfd))
|
|---|
| 2148 | {
|
|---|
| 2149 | natptr->r_index[0] = r_index >> 16;
|
|---|
| 2150 | natptr->r_index[1] = r_index >> 8;
|
|---|
| 2151 | natptr->r_index[2] = r_index;
|
|---|
| 2152 | natptr->r_type[0] = ((r_extern ? RELOC_STD_BITS_EXTERN_BIG : 0)
|
|---|
| 2153 | | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG : 0)
|
|---|
| 2154 | | (r_baserel ? RELOC_STD_BITS_BASEREL_BIG : 0)
|
|---|
| 2155 | | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_BIG : 0)
|
|---|
| 2156 | | (r_relative ? RELOC_STD_BITS_RELATIVE_BIG : 0)
|
|---|
| 2157 | | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG));
|
|---|
| 2158 | }
|
|---|
| 2159 | else
|
|---|
| 2160 | {
|
|---|
| 2161 | natptr->r_index[2] = r_index >> 16;
|
|---|
| 2162 | natptr->r_index[1] = r_index >> 8;
|
|---|
| 2163 | natptr->r_index[0] = r_index;
|
|---|
| 2164 | natptr->r_type[0] = ((r_extern ? RELOC_STD_BITS_EXTERN_LITTLE : 0)
|
|---|
| 2165 | | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE : 0)
|
|---|
| 2166 | | (r_baserel ? RELOC_STD_BITS_BASEREL_LITTLE : 0)
|
|---|
| 2167 | | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_LITTLE : 0)
|
|---|
| 2168 | | (r_relative ? RELOC_STD_BITS_RELATIVE_LITTLE : 0)
|
|---|
| 2169 | | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE));
|
|---|
| 2170 | }
|
|---|
| 2171 | }
|
|---|
| 2172 |
|
|---|
| 2173 | /* Extended stuff. */
|
|---|
| 2174 | /* Output extended relocation information to a file in target byte order. */
|
|---|
| 2175 |
|
|---|
| 2176 | extern void NAME(aout,swap_ext_reloc_out)
|
|---|
| 2177 | PARAMS ((bfd *, arelent *, struct reloc_ext_external *));
|
|---|
| 2178 |
|
|---|
| 2179 | void
|
|---|
| 2180 | NAME(aout,swap_ext_reloc_out) (abfd, g, natptr)
|
|---|
| 2181 | bfd *abfd;
|
|---|
| 2182 | arelent *g;
|
|---|
| 2183 | register struct reloc_ext_external *natptr;
|
|---|
| 2184 | {
|
|---|
| 2185 | int r_index;
|
|---|
| 2186 | int r_extern;
|
|---|
| 2187 | unsigned int r_type;
|
|---|
| 2188 | bfd_vma r_addend;
|
|---|
| 2189 | asymbol *sym = *(g->sym_ptr_ptr);
|
|---|
| 2190 | asection *output_section = sym->section->output_section;
|
|---|
| 2191 |
|
|---|
| 2192 | PUT_WORD (abfd, g->address, natptr->r_address);
|
|---|
| 2193 |
|
|---|
| 2194 | r_type = (unsigned int) g->howto->type;
|
|---|
| 2195 |
|
|---|
| 2196 | r_addend = g->addend;
|
|---|
| 2197 | if ((sym->flags & BSF_SECTION_SYM) != 0)
|
|---|
| 2198 | r_addend += (*(g->sym_ptr_ptr))->section->output_section->vma;
|
|---|
| 2199 |
|
|---|
| 2200 | /* If this relocation is relative to a symbol then set the
|
|---|
| 2201 | r_index to the symbols index, and the r_extern bit.
|
|---|
| 2202 |
|
|---|
| 2203 | Absolute symbols can come in in two ways, either as an offset
|
|---|
| 2204 | from the abs section, or as a symbol which has an abs value.
|
|---|
| 2205 | check for that here. */
|
|---|
| 2206 | if (bfd_is_abs_section (bfd_get_section (sym)))
|
|---|
| 2207 | {
|
|---|
| 2208 | r_extern = 0;
|
|---|
| 2209 | r_index = N_ABS;
|
|---|
| 2210 | }
|
|---|
| 2211 | else if ((sym->flags & BSF_SECTION_SYM) == 0)
|
|---|
| 2212 | {
|
|---|
| 2213 | if (bfd_is_und_section (bfd_get_section (sym))
|
|---|
| 2214 | || (sym->flags & BSF_GLOBAL) != 0)
|
|---|
| 2215 | r_extern = 1;
|
|---|
| 2216 | else
|
|---|
| 2217 | r_extern = 0;
|
|---|
| 2218 | r_index = (*(g->sym_ptr_ptr))->KEEPIT;
|
|---|
| 2219 | }
|
|---|
| 2220 | else
|
|---|
| 2221 | {
|
|---|
| 2222 | /* Just an ordinary section. */
|
|---|
| 2223 | r_extern = 0;
|
|---|
| 2224 | r_index = output_section->target_index;
|
|---|
| 2225 | }
|
|---|
| 2226 |
|
|---|
| 2227 | /* Now the fun stuff. */
|
|---|
| 2228 | if (bfd_header_big_endian (abfd))
|
|---|
| 2229 | {
|
|---|
| 2230 | natptr->r_index[0] = r_index >> 16;
|
|---|
| 2231 | natptr->r_index[1] = r_index >> 8;
|
|---|
| 2232 | natptr->r_index[2] = r_index;
|
|---|
| 2233 | natptr->r_type[0] = ((r_extern ? RELOC_EXT_BITS_EXTERN_BIG : 0)
|
|---|
| 2234 | | (r_type << RELOC_EXT_BITS_TYPE_SH_BIG));
|
|---|
| 2235 | }
|
|---|
| 2236 | else
|
|---|
| 2237 | {
|
|---|
| 2238 | natptr->r_index[2] = r_index >> 16;
|
|---|
| 2239 | natptr->r_index[1] = r_index >> 8;
|
|---|
| 2240 | natptr->r_index[0] = r_index;
|
|---|
| 2241 | natptr->r_type[0] = ((r_extern ? RELOC_EXT_BITS_EXTERN_LITTLE : 0)
|
|---|
| 2242 | | (r_type << RELOC_EXT_BITS_TYPE_SH_LITTLE));
|
|---|
| 2243 | }
|
|---|
| 2244 |
|
|---|
| 2245 | PUT_WORD (abfd, r_addend, natptr->r_addend);
|
|---|
| 2246 | }
|
|---|
| 2247 |
|
|---|
| 2248 | /* BFD deals internally with all things based from the section they're
|
|---|
| 2249 | in. so, something in 10 bytes into a text section with a base of
|
|---|
| 2250 | 50 would have a symbol (.text+10) and know .text vma was 50.
|
|---|
| 2251 |
|
|---|
| 2252 | Aout keeps all it's symbols based from zero, so the symbol would
|
|---|
| 2253 | contain 60. This macro subs the base of each section from the value
|
|---|
| 2254 | to give the true offset from the section. */
|
|---|
| 2255 |
|
|---|
| 2256 | #define MOVE_ADDRESS(ad) \
|
|---|
| 2257 | if (r_extern) \
|
|---|
| 2258 | { \
|
|---|
| 2259 | /* Undefined symbol. */ \
|
|---|
| 2260 | cache_ptr->sym_ptr_ptr = symbols + r_index; \
|
|---|
| 2261 | cache_ptr->addend = ad; \
|
|---|
| 2262 | } \
|
|---|
| 2263 | else \
|
|---|
| 2264 | { \
|
|---|
| 2265 | /* Defined, section relative. Replace symbol with pointer to \
|
|---|
| 2266 | symbol which points to section. */ \
|
|---|
| 2267 | switch (r_index) \
|
|---|
| 2268 | { \
|
|---|
| 2269 | case N_TEXT: \
|
|---|
| 2270 | case N_TEXT | N_EXT: \
|
|---|
| 2271 | cache_ptr->sym_ptr_ptr = obj_textsec (abfd)->symbol_ptr_ptr; \
|
|---|
| 2272 | cache_ptr->addend = ad - su->textsec->vma; \
|
|---|
| 2273 | break; \
|
|---|
| 2274 | case N_DATA: \
|
|---|
| 2275 | case N_DATA | N_EXT: \
|
|---|
| 2276 | cache_ptr->sym_ptr_ptr = obj_datasec (abfd)->symbol_ptr_ptr; \
|
|---|
| 2277 | cache_ptr->addend = ad - su->datasec->vma; \
|
|---|
| 2278 | break; \
|
|---|
| 2279 | case N_BSS: \
|
|---|
| 2280 | case N_BSS | N_EXT: \
|
|---|
| 2281 | cache_ptr->sym_ptr_ptr = obj_bsssec (abfd)->symbol_ptr_ptr; \
|
|---|
| 2282 | cache_ptr->addend = ad - su->bsssec->vma; \
|
|---|
| 2283 | break; \
|
|---|
| 2284 | default: \
|
|---|
| 2285 | case N_ABS: \
|
|---|
| 2286 | case N_ABS | N_EXT: \
|
|---|
| 2287 | cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; \
|
|---|
| 2288 | cache_ptr->addend = ad; \
|
|---|
| 2289 | break; \
|
|---|
| 2290 | } \
|
|---|
| 2291 | }
|
|---|
| 2292 |
|
|---|
| 2293 | void
|
|---|
| 2294 | NAME(aout,swap_ext_reloc_in) (abfd, bytes, cache_ptr, symbols, symcount)
|
|---|
| 2295 | bfd *abfd;
|
|---|
| 2296 | struct reloc_ext_external *bytes;
|
|---|
| 2297 | arelent *cache_ptr;
|
|---|
| 2298 | asymbol **symbols;
|
|---|
| 2299 | bfd_size_type symcount;
|
|---|
| 2300 | {
|
|---|
| 2301 | unsigned int r_index;
|
|---|
| 2302 | int r_extern;
|
|---|
| 2303 | unsigned int r_type;
|
|---|
| 2304 | struct aoutdata *su = &(abfd->tdata.aout_data->a);
|
|---|
| 2305 |
|
|---|
| 2306 | cache_ptr->address = (GET_SWORD (abfd, bytes->r_address));
|
|---|
| 2307 |
|
|---|
| 2308 | /* Now the fun stuff. */
|
|---|
| 2309 | if (bfd_header_big_endian (abfd))
|
|---|
| 2310 | {
|
|---|
| 2311 | r_index = (((unsigned int) bytes->r_index[0] << 16)
|
|---|
| 2312 | | ((unsigned int) bytes->r_index[1] << 8)
|
|---|
| 2313 | | bytes->r_index[2]);
|
|---|
| 2314 | r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
|
|---|
| 2315 | r_type = ((bytes->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
|
|---|
| 2316 | >> RELOC_EXT_BITS_TYPE_SH_BIG);
|
|---|
| 2317 | }
|
|---|
| 2318 | else
|
|---|
| 2319 | {
|
|---|
| 2320 | r_index = (((unsigned int) bytes->r_index[2] << 16)
|
|---|
| 2321 | | ((unsigned int) bytes->r_index[1] << 8)
|
|---|
| 2322 | | bytes->r_index[0]);
|
|---|
| 2323 | r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
|
|---|
| 2324 | r_type = ((bytes->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
|
|---|
| 2325 | >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
|
|---|
| 2326 | }
|
|---|
| 2327 |
|
|---|
| 2328 | cache_ptr->howto = howto_table_ext + r_type;
|
|---|
| 2329 |
|
|---|
| 2330 | /* Base relative relocs are always against the symbol table,
|
|---|
| 2331 | regardless of the setting of r_extern. r_extern just reflects
|
|---|
| 2332 | whether the symbol the reloc is against is local or global. */
|
|---|
| 2333 | if (r_type == (unsigned int) RELOC_BASE10
|
|---|
| 2334 | || r_type == (unsigned int) RELOC_BASE13
|
|---|
| 2335 | || r_type == (unsigned int) RELOC_BASE22)
|
|---|
| 2336 | r_extern = 1;
|
|---|
| 2337 |
|
|---|
| 2338 | if (r_extern && r_index > symcount)
|
|---|
| 2339 | {
|
|---|
| 2340 | /* We could arrange to return an error, but it might be useful
|
|---|
| 2341 | to see the file even if it is bad. */
|
|---|
| 2342 | r_extern = 0;
|
|---|
| 2343 | r_index = N_ABS;
|
|---|
| 2344 | }
|
|---|
| 2345 |
|
|---|
| 2346 | MOVE_ADDRESS (GET_SWORD (abfd, bytes->r_addend));
|
|---|
| 2347 | }
|
|---|
| 2348 |
|
|---|
| 2349 | void
|
|---|
| 2350 | NAME(aout,swap_std_reloc_in) (abfd, bytes, cache_ptr, symbols, symcount)
|
|---|
| 2351 | bfd *abfd;
|
|---|
| 2352 | struct reloc_std_external *bytes;
|
|---|
| 2353 | arelent *cache_ptr;
|
|---|
| 2354 | asymbol **symbols;
|
|---|
| 2355 | bfd_size_type symcount;
|
|---|
| 2356 | {
|
|---|
| 2357 | unsigned int r_index;
|
|---|
| 2358 | int r_extern;
|
|---|
| 2359 | unsigned int r_length;
|
|---|
| 2360 | int r_pcrel;
|
|---|
| 2361 | int r_baserel, r_jmptable, r_relative;
|
|---|
| 2362 | struct aoutdata *su = &(abfd->tdata.aout_data->a);
|
|---|
| 2363 | unsigned int howto_idx;
|
|---|
| 2364 |
|
|---|
| 2365 | cache_ptr->address = H_GET_32 (abfd, bytes->r_address);
|
|---|
| 2366 |
|
|---|
| 2367 | /* Now the fun stuff. */
|
|---|
| 2368 | if (bfd_header_big_endian (abfd))
|
|---|
| 2369 | {
|
|---|
| 2370 | r_index = (((unsigned int) bytes->r_index[0] << 16)
|
|---|
| 2371 | | ((unsigned int) bytes->r_index[1] << 8)
|
|---|
| 2372 | | bytes->r_index[2]);
|
|---|
| 2373 | r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
|
|---|
| 2374 | r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
|
|---|
| 2375 | r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
|
|---|
| 2376 | r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
|
|---|
| 2377 | r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG));
|
|---|
| 2378 | r_length = ((bytes->r_type[0] & RELOC_STD_BITS_LENGTH_BIG)
|
|---|
| 2379 | >> RELOC_STD_BITS_LENGTH_SH_BIG);
|
|---|
| 2380 | }
|
|---|
| 2381 | else
|
|---|
| 2382 | {
|
|---|
| 2383 | r_index = (((unsigned int) bytes->r_index[2] << 16)
|
|---|
| 2384 | | ((unsigned int) bytes->r_index[1] << 8)
|
|---|
| 2385 | | bytes->r_index[0]);
|
|---|
| 2386 | r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
|
|---|
| 2387 | r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
|
|---|
| 2388 | r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
|
|---|
| 2389 | r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE));
|
|---|
| 2390 | r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_LITTLE));
|
|---|
| 2391 | r_length = ((bytes->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE)
|
|---|
| 2392 | >> RELOC_STD_BITS_LENGTH_SH_LITTLE);
|
|---|
| 2393 | }
|
|---|
| 2394 |
|
|---|
| 2395 | howto_idx = (r_length + 4 * r_pcrel + 8 * r_baserel
|
|---|
| 2396 | + 16 * r_jmptable + 32 * r_relative);
|
|---|
| 2397 | BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std));
|
|---|
| 2398 | cache_ptr->howto = howto_table_std + howto_idx;
|
|---|
| 2399 | BFD_ASSERT (cache_ptr->howto->type != (unsigned int) -1);
|
|---|
| 2400 |
|
|---|
| 2401 | /* Base relative relocs are always against the symbol table,
|
|---|
| 2402 | regardless of the setting of r_extern. r_extern just reflects
|
|---|
| 2403 | whether the symbol the reloc is against is local or global. */
|
|---|
| 2404 | if (r_baserel)
|
|---|
| 2405 | r_extern = 1;
|
|---|
| 2406 |
|
|---|
| 2407 | if (r_extern && r_index > symcount)
|
|---|
| 2408 | {
|
|---|
| 2409 | /* We could arrange to return an error, but it might be useful
|
|---|
| 2410 | to see the file even if it is bad. */
|
|---|
| 2411 | r_extern = 0;
|
|---|
| 2412 | r_index = N_ABS;
|
|---|
| 2413 | }
|
|---|
| 2414 |
|
|---|
| 2415 | MOVE_ADDRESS (0);
|
|---|
| 2416 | }
|
|---|
| 2417 |
|
|---|
| 2418 | /* Read and swap the relocs for a section. */
|
|---|
| 2419 |
|
|---|
| 2420 | bfd_boolean
|
|---|
| 2421 | NAME(aout,slurp_reloc_table) (abfd, asect, symbols)
|
|---|
| 2422 | bfd *abfd;
|
|---|
| 2423 | sec_ptr asect;
|
|---|
| 2424 | asymbol **symbols;
|
|---|
| 2425 | {
|
|---|
| 2426 | bfd_size_type count;
|
|---|
| 2427 | bfd_size_type reloc_size;
|
|---|
| 2428 | PTR relocs;
|
|---|
| 2429 | arelent *reloc_cache;
|
|---|
| 2430 | size_t each_size;
|
|---|
| 2431 | unsigned int counter = 0;
|
|---|
| 2432 | arelent *cache_ptr;
|
|---|
| 2433 | bfd_size_type amt;
|
|---|
| 2434 |
|
|---|
| 2435 | if (asect->relocation)
|
|---|
| 2436 | return TRUE;
|
|---|
| 2437 |
|
|---|
| 2438 | if (asect->flags & SEC_CONSTRUCTOR)
|
|---|
| 2439 | return TRUE;
|
|---|
| 2440 |
|
|---|
| 2441 | if (asect == obj_datasec (abfd))
|
|---|
| 2442 | reloc_size = exec_hdr (abfd)->a_drsize;
|
|---|
| 2443 | else if (asect == obj_textsec (abfd))
|
|---|
| 2444 | reloc_size = exec_hdr (abfd)->a_trsize;
|
|---|
| 2445 | else if (asect == obj_bsssec (abfd))
|
|---|
| 2446 | reloc_size = 0;
|
|---|
| 2447 | else
|
|---|
| 2448 | {
|
|---|
| 2449 | bfd_set_error (bfd_error_invalid_operation);
|
|---|
| 2450 | return FALSE;
|
|---|
| 2451 | }
|
|---|
| 2452 |
|
|---|
| 2453 | if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0)
|
|---|
| 2454 | return FALSE;
|
|---|
| 2455 |
|
|---|
| 2456 | each_size = obj_reloc_entry_size (abfd);
|
|---|
| 2457 |
|
|---|
| 2458 | count = reloc_size / each_size;
|
|---|
| 2459 |
|
|---|
| 2460 | amt = count * sizeof (arelent);
|
|---|
| 2461 | reloc_cache = (arelent *) bfd_zmalloc (amt);
|
|---|
| 2462 | if (reloc_cache == NULL && count != 0)
|
|---|
| 2463 | return FALSE;
|
|---|
| 2464 |
|
|---|
| 2465 | relocs = bfd_malloc (reloc_size);
|
|---|
| 2466 | if (relocs == NULL && reloc_size != 0)
|
|---|
| 2467 | {
|
|---|
| 2468 | free (reloc_cache);
|
|---|
| 2469 | return FALSE;
|
|---|
| 2470 | }
|
|---|
| 2471 |
|
|---|
| 2472 | if (bfd_bread (relocs, reloc_size, abfd) != reloc_size)
|
|---|
| 2473 | {
|
|---|
| 2474 | free (relocs);
|
|---|
| 2475 | free (reloc_cache);
|
|---|
| 2476 | return FALSE;
|
|---|
| 2477 | }
|
|---|
| 2478 |
|
|---|
| 2479 | cache_ptr = reloc_cache;
|
|---|
| 2480 | if (each_size == RELOC_EXT_SIZE)
|
|---|
| 2481 | {
|
|---|
| 2482 | struct reloc_ext_external *rptr = (struct reloc_ext_external *) relocs;
|
|---|
| 2483 |
|
|---|
| 2484 | for (; counter < count; counter++, rptr++, cache_ptr++)
|
|---|
| 2485 | MY_swap_ext_reloc_in (abfd, rptr, cache_ptr, symbols,
|
|---|
| 2486 | (bfd_size_type) bfd_get_symcount (abfd));
|
|---|
| 2487 | }
|
|---|
| 2488 | else
|
|---|
| 2489 | {
|
|---|
| 2490 | struct reloc_std_external *rptr = (struct reloc_std_external *) relocs;
|
|---|
| 2491 |
|
|---|
| 2492 | for (; counter < count; counter++, rptr++, cache_ptr++)
|
|---|
| 2493 | MY_swap_std_reloc_in (abfd, rptr, cache_ptr, symbols,
|
|---|
| 2494 | (bfd_size_type) bfd_get_symcount (abfd));
|
|---|
| 2495 | }
|
|---|
| 2496 |
|
|---|
| 2497 | free (relocs);
|
|---|
| 2498 |
|
|---|
| 2499 | asect->relocation = reloc_cache;
|
|---|
| 2500 | asect->reloc_count = cache_ptr - reloc_cache;
|
|---|
| 2501 |
|
|---|
| 2502 | return TRUE;
|
|---|
| 2503 | }
|
|---|
| 2504 |
|
|---|
| 2505 | /* Write out a relocation section into an object file. */
|
|---|
| 2506 |
|
|---|
| 2507 | bfd_boolean
|
|---|
| 2508 | NAME(aout,squirt_out_relocs) (abfd, section)
|
|---|
| 2509 | bfd *abfd;
|
|---|
| 2510 | asection *section;
|
|---|
| 2511 | {
|
|---|
| 2512 | arelent **generic;
|
|---|
| 2513 | unsigned char *native, *natptr;
|
|---|
| 2514 | size_t each_size;
|
|---|
| 2515 |
|
|---|
| 2516 | unsigned int count = section->reloc_count;
|
|---|
| 2517 | bfd_size_type natsize;
|
|---|
| 2518 |
|
|---|
| 2519 | if (count == 0 || section->orelocation == NULL)
|
|---|
| 2520 | return TRUE;
|
|---|
| 2521 |
|
|---|
| 2522 | each_size = obj_reloc_entry_size (abfd);
|
|---|
| 2523 | natsize = (bfd_size_type) each_size * count;
|
|---|
| 2524 | native = (unsigned char *) bfd_zalloc (abfd, natsize);
|
|---|
| 2525 | if (!native)
|
|---|
| 2526 | return FALSE;
|
|---|
| 2527 |
|
|---|
| 2528 | generic = section->orelocation;
|
|---|
| 2529 |
|
|---|
| 2530 | if (each_size == RELOC_EXT_SIZE)
|
|---|
| 2531 | {
|
|---|
| 2532 | for (natptr = native;
|
|---|
| 2533 | count != 0;
|
|---|
| 2534 | --count, natptr += each_size, ++generic)
|
|---|
| 2535 | MY_swap_ext_reloc_out (abfd, *generic,
|
|---|
| 2536 | (struct reloc_ext_external *) natptr);
|
|---|
| 2537 | }
|
|---|
| 2538 | else
|
|---|
| 2539 | {
|
|---|
| 2540 | for (natptr = native;
|
|---|
| 2541 | count != 0;
|
|---|
| 2542 | --count, natptr += each_size, ++generic)
|
|---|
| 2543 | MY_swap_std_reloc_out (abfd, *generic,
|
|---|
| 2544 | (struct reloc_std_external *) natptr);
|
|---|
| 2545 | }
|
|---|
| 2546 |
|
|---|
| 2547 | if (bfd_bwrite ((PTR) native, natsize, abfd) != natsize)
|
|---|
| 2548 | {
|
|---|
| 2549 | bfd_release (abfd, native);
|
|---|
| 2550 | return FALSE;
|
|---|
| 2551 | }
|
|---|
| 2552 | bfd_release (abfd, native);
|
|---|
| 2553 |
|
|---|
| 2554 | return TRUE;
|
|---|
| 2555 | }
|
|---|
| 2556 |
|
|---|
| 2557 | /* This is stupid. This function should be a boolean predicate. */
|
|---|
| 2558 |
|
|---|
| 2559 | long
|
|---|
| 2560 | NAME(aout,canonicalize_reloc) (abfd, section, relptr, symbols)
|
|---|
| 2561 | bfd *abfd;
|
|---|
| 2562 | sec_ptr section;
|
|---|
| 2563 | arelent **relptr;
|
|---|
| 2564 | asymbol **symbols;
|
|---|
| 2565 | {
|
|---|
| 2566 | arelent *tblptr = section->relocation;
|
|---|
| 2567 | unsigned int count;
|
|---|
| 2568 |
|
|---|
| 2569 | if (section == obj_bsssec (abfd))
|
|---|
| 2570 | {
|
|---|
| 2571 | *relptr = NULL;
|
|---|
| 2572 | return 0;
|
|---|
| 2573 | }
|
|---|
| 2574 |
|
|---|
| 2575 | if (!(tblptr || NAME(aout,slurp_reloc_table) (abfd, section, symbols)))
|
|---|
| 2576 | return -1;
|
|---|
| 2577 |
|
|---|
| 2578 | if (section->flags & SEC_CONSTRUCTOR)
|
|---|
| 2579 | {
|
|---|
| 2580 | arelent_chain *chain = section->constructor_chain;
|
|---|
| 2581 | for (count = 0; count < section->reloc_count; count ++)
|
|---|
| 2582 | {
|
|---|
| 2583 | *relptr ++ = &chain->relent;
|
|---|
| 2584 | chain = chain->next;
|
|---|
| 2585 | }
|
|---|
| 2586 | }
|
|---|
| 2587 | else
|
|---|
| 2588 | {
|
|---|
| 2589 | tblptr = section->relocation;
|
|---|
| 2590 |
|
|---|
| 2591 | for (count = 0; count++ < section->reloc_count; )
|
|---|
| 2592 | {
|
|---|
| 2593 | *relptr++ = tblptr++;
|
|---|
| 2594 | }
|
|---|
| 2595 | }
|
|---|
| 2596 | *relptr = 0;
|
|---|
| 2597 |
|
|---|
| 2598 | return section->reloc_count;
|
|---|
| 2599 | }
|
|---|
| 2600 |
|
|---|
| 2601 | long
|
|---|
| 2602 | NAME(aout,get_reloc_upper_bound) (abfd, asect)
|
|---|
| 2603 | bfd *abfd;
|
|---|
| 2604 | sec_ptr asect;
|
|---|
| 2605 | {
|
|---|
| 2606 | if (bfd_get_format (abfd) != bfd_object)
|
|---|
| 2607 | {
|
|---|
| 2608 | bfd_set_error (bfd_error_invalid_operation);
|
|---|
| 2609 | return -1;
|
|---|
| 2610 | }
|
|---|
| 2611 |
|
|---|
| 2612 | if (asect->flags & SEC_CONSTRUCTOR)
|
|---|
| 2613 | return (sizeof (arelent *) * (asect->reloc_count+1));
|
|---|
| 2614 |
|
|---|
| 2615 | if (asect == obj_datasec (abfd))
|
|---|
| 2616 | return (sizeof (arelent *)
|
|---|
| 2617 | * ((exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd))
|
|---|
| 2618 | + 1));
|
|---|
| 2619 |
|
|---|
| 2620 | if (asect == obj_textsec (abfd))
|
|---|
| 2621 | return (sizeof (arelent *)
|
|---|
| 2622 | * ((exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd))
|
|---|
| 2623 | + 1));
|
|---|
| 2624 |
|
|---|
| 2625 | if (asect == obj_bsssec (abfd))
|
|---|
| 2626 | return sizeof (arelent *);
|
|---|
| 2627 |
|
|---|
| 2628 | if (asect == obj_bsssec (abfd))
|
|---|
| 2629 | return 0;
|
|---|
| 2630 |
|
|---|
| 2631 | bfd_set_error (bfd_error_invalid_operation);
|
|---|
| 2632 | return -1;
|
|---|
| 2633 | }
|
|---|
| 2634 | |
|---|
| 2635 |
|
|---|
| 2636 | long
|
|---|
| 2637 | NAME(aout,get_symtab_upper_bound) (abfd)
|
|---|
| 2638 | bfd *abfd;
|
|---|
| 2639 | {
|
|---|
| 2640 | if (!NAME(aout,slurp_symbol_table) (abfd))
|
|---|
| 2641 | return -1;
|
|---|
| 2642 |
|
|---|
| 2643 | return (bfd_get_symcount (abfd)+1) * (sizeof (aout_symbol_type *));
|
|---|
| 2644 | }
|
|---|
| 2645 |
|
|---|
| 2646 | alent *
|
|---|
| 2647 | NAME(aout,get_lineno) (ignore_abfd, ignore_symbol)
|
|---|
| 2648 | bfd *ignore_abfd ATTRIBUTE_UNUSED;
|
|---|
| 2649 | asymbol *ignore_symbol ATTRIBUTE_UNUSED;
|
|---|
| 2650 | {
|
|---|
| 2651 | return (alent *)NULL;
|
|---|
| 2652 | }
|
|---|
| 2653 |
|
|---|
| 2654 | void
|
|---|
| 2655 | NAME(aout,get_symbol_info) (ignore_abfd, symbol, ret)
|
|---|
| 2656 | bfd *ignore_abfd ATTRIBUTE_UNUSED;
|
|---|
| 2657 | asymbol *symbol;
|
|---|
| 2658 | symbol_info *ret;
|
|---|
| 2659 | {
|
|---|
| 2660 | bfd_symbol_info (symbol, ret);
|
|---|
| 2661 |
|
|---|
| 2662 | if (ret->type == '?')
|
|---|
| 2663 | {
|
|---|
| 2664 | int type_code = aout_symbol (symbol)->type & 0xff;
|
|---|
| 2665 | const char *stab_name = bfd_get_stab_name (type_code);
|
|---|
| 2666 | static char buf[10];
|
|---|
| 2667 |
|
|---|
| 2668 | if (stab_name == NULL)
|
|---|
| 2669 | {
|
|---|
| 2670 | sprintf (buf, "(%d)", type_code);
|
|---|
| 2671 | stab_name = buf;
|
|---|
| 2672 | }
|
|---|
| 2673 | ret->type = '-';
|
|---|
| 2674 | ret->stab_type = type_code;
|
|---|
| 2675 | ret->stab_other = (unsigned) (aout_symbol (symbol)->other & 0xff);
|
|---|
| 2676 | ret->stab_desc = (unsigned) (aout_symbol (symbol)->desc & 0xffff);
|
|---|
| 2677 | ret->stab_name = stab_name;
|
|---|
| 2678 | }
|
|---|
| 2679 | }
|
|---|
| 2680 |
|
|---|
| 2681 | void
|
|---|
| 2682 | NAME(aout,print_symbol) (abfd, afile, symbol, how)
|
|---|
| 2683 | bfd *abfd;
|
|---|
| 2684 | PTR afile;
|
|---|
| 2685 | asymbol *symbol;
|
|---|
| 2686 | bfd_print_symbol_type how;
|
|---|
| 2687 | {
|
|---|
| 2688 | FILE *file = (FILE *)afile;
|
|---|
| 2689 |
|
|---|
| 2690 | switch (how)
|
|---|
| 2691 | {
|
|---|
| 2692 | case bfd_print_symbol_name:
|
|---|
| 2693 | if (symbol->name)
|
|---|
| 2694 | fprintf (file,"%s", symbol->name);
|
|---|
| 2695 | break;
|
|---|
| 2696 | case bfd_print_symbol_more:
|
|---|
| 2697 | fprintf (file,"%4x %2x %2x",
|
|---|
| 2698 | (unsigned) (aout_symbol (symbol)->desc & 0xffff),
|
|---|
| 2699 | (unsigned) (aout_symbol (symbol)->other & 0xff),
|
|---|
| 2700 | (unsigned) (aout_symbol (symbol)->type));
|
|---|
| 2701 | break;
|
|---|
| 2702 | case bfd_print_symbol_all:
|
|---|
| 2703 | {
|
|---|
| 2704 | const char *section_name = symbol->section->name;
|
|---|
| 2705 |
|
|---|
| 2706 | bfd_print_symbol_vandf (abfd, (PTR)file, symbol);
|
|---|
| 2707 |
|
|---|
| 2708 | fprintf (file," %-5s %04x %02x %02x",
|
|---|
| 2709 | section_name,
|
|---|
| 2710 | (unsigned) (aout_symbol (symbol)->desc & 0xffff),
|
|---|
| 2711 | (unsigned) (aout_symbol (symbol)->other & 0xff),
|
|---|
| 2712 | (unsigned) (aout_symbol (symbol)->type & 0xff));
|
|---|
| 2713 | if (symbol->name)
|
|---|
| 2714 | fprintf (file," %s", symbol->name);
|
|---|
| 2715 | }
|
|---|
| 2716 | break;
|
|---|
| 2717 | }
|
|---|
| 2718 | }
|
|---|
| 2719 |
|
|---|
| 2720 | /* If we don't have to allocate more than 1MB to hold the generic
|
|---|
| 2721 | symbols, we use the generic minisymbol methord: it's faster, since
|
|---|
| 2722 | it only translates the symbols once, not multiple times. */
|
|---|
| 2723 | #define MINISYM_THRESHOLD (1000000 / sizeof (asymbol))
|
|---|
| 2724 |
|
|---|
| 2725 | /* Read minisymbols. For minisymbols, we use the unmodified a.out
|
|---|
| 2726 | symbols. The minisymbol_to_symbol function translates these into
|
|---|
| 2727 | BFD asymbol structures. */
|
|---|
| 2728 |
|
|---|
| 2729 | long
|
|---|
| 2730 | NAME(aout,read_minisymbols) (abfd, dynamic, minisymsp, sizep)
|
|---|
| 2731 | bfd *abfd;
|
|---|
| 2732 | bfd_boolean dynamic;
|
|---|
| 2733 | PTR *minisymsp;
|
|---|
| 2734 | unsigned int *sizep;
|
|---|
| 2735 | {
|
|---|
| 2736 | if (dynamic)
|
|---|
| 2737 | {
|
|---|
| 2738 | /* We could handle the dynamic symbols here as well, but it's
|
|---|
| 2739 | easier to hand them off. */
|
|---|
| 2740 | return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep);
|
|---|
| 2741 | }
|
|---|
| 2742 |
|
|---|
| 2743 | if (! aout_get_external_symbols (abfd))
|
|---|
| 2744 | return -1;
|
|---|
| 2745 |
|
|---|
| 2746 | if (obj_aout_external_sym_count (abfd) < MINISYM_THRESHOLD)
|
|---|
| 2747 | return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep);
|
|---|
| 2748 |
|
|---|
| 2749 | *minisymsp = (PTR) obj_aout_external_syms (abfd);
|
|---|
| 2750 |
|
|---|
| 2751 | /* By passing the external symbols back from this routine, we are
|
|---|
| 2752 | giving up control over the memory block. Clear
|
|---|
| 2753 | obj_aout_external_syms, so that we do not try to free it
|
|---|
| 2754 | ourselves. */
|
|---|
| 2755 | obj_aout_external_syms (abfd) = NULL;
|
|---|
| 2756 |
|
|---|
| 2757 | *sizep = EXTERNAL_NLIST_SIZE;
|
|---|
| 2758 | return obj_aout_external_sym_count (abfd);
|
|---|
| 2759 | }
|
|---|
| 2760 |
|
|---|
| 2761 | /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an
|
|---|
| 2762 | unmodified a.out symbol. The SYM argument is a structure returned
|
|---|
| 2763 | by bfd_make_empty_symbol, which we fill in here. */
|
|---|
| 2764 |
|
|---|
| 2765 | asymbol *
|
|---|
| 2766 | NAME(aout,minisymbol_to_symbol) (abfd, dynamic, minisym, sym)
|
|---|
| 2767 | bfd *abfd;
|
|---|
| 2768 | bfd_boolean dynamic;
|
|---|
| 2769 | const PTR minisym;
|
|---|
| 2770 | asymbol *sym;
|
|---|
| 2771 | {
|
|---|
| 2772 | if (dynamic
|
|---|
| 2773 | || obj_aout_external_sym_count (abfd) < MINISYM_THRESHOLD)
|
|---|
| 2774 | return _bfd_generic_minisymbol_to_symbol (abfd, dynamic, minisym, sym);
|
|---|
| 2775 |
|
|---|
| 2776 | memset (sym, 0, sizeof (aout_symbol_type));
|
|---|
| 2777 |
|
|---|
| 2778 | /* We call translate_symbol_table to translate a single symbol. */
|
|---|
| 2779 | if (! (NAME(aout,translate_symbol_table)
|
|---|
| 2780 | (abfd,
|
|---|
| 2781 | (aout_symbol_type *) sym,
|
|---|
| 2782 | (struct external_nlist *) minisym,
|
|---|
| 2783 | (bfd_size_type) 1,
|
|---|
| 2784 | obj_aout_external_strings (abfd),
|
|---|
| 2785 | obj_aout_external_string_size (abfd),
|
|---|
| 2786 | FALSE)))
|
|---|
| 2787 | return NULL;
|
|---|
| 2788 |
|
|---|
| 2789 | return sym;
|
|---|
| 2790 | }
|
|---|
| 2791 |
|
|---|
| 2792 | /* Provided a BFD, a section and an offset into the section, calculate
|
|---|
| 2793 | and return the name of the source file and the line nearest to the
|
|---|
| 2794 | wanted location. */
|
|---|
| 2795 |
|
|---|
| 2796 | bfd_boolean
|
|---|
| 2797 | NAME(aout,find_nearest_line)
|
|---|
| 2798 | (abfd, section, symbols, offset, filename_ptr, functionname_ptr, line_ptr)
|
|---|
| 2799 | bfd *abfd;
|
|---|
| 2800 | asection *section;
|
|---|
| 2801 | asymbol **symbols;
|
|---|
| 2802 | bfd_vma offset;
|
|---|
| 2803 | const char **filename_ptr;
|
|---|
| 2804 | const char **functionname_ptr;
|
|---|
| 2805 | unsigned int *line_ptr;
|
|---|
| 2806 | {
|
|---|
| 2807 | /* Run down the file looking for the filename, function and linenumber. */
|
|---|
| 2808 | asymbol **p;
|
|---|
| 2809 | const char *directory_name = NULL;
|
|---|
| 2810 | const char *main_file_name = NULL;
|
|---|
| 2811 | const char *current_file_name = NULL;
|
|---|
| 2812 | const char *line_file_name = NULL; /* Value of current_file_name at line number. */
|
|---|
| 2813 | const char *line_directory_name = NULL; /* Value of directory_name at line number. */
|
|---|
| 2814 | bfd_vma low_line_vma = 0;
|
|---|
| 2815 | bfd_vma low_func_vma = 0;
|
|---|
| 2816 | asymbol *func = 0;
|
|---|
| 2817 | bfd_size_type filelen, funclen;
|
|---|
| 2818 | char *buf;
|
|---|
| 2819 |
|
|---|
| 2820 | *filename_ptr = abfd->filename;
|
|---|
| 2821 | *functionname_ptr = 0;
|
|---|
| 2822 | *line_ptr = 0;
|
|---|
| 2823 |
|
|---|
| 2824 | if (symbols != (asymbol **)NULL)
|
|---|
| 2825 | {
|
|---|
| 2826 | for (p = symbols; *p; p++)
|
|---|
| 2827 | {
|
|---|
| 2828 | aout_symbol_type *q = (aout_symbol_type *) (*p);
|
|---|
| 2829 | next:
|
|---|
| 2830 | switch (q->type)
|
|---|
| 2831 | {
|
|---|
| 2832 | case N_TEXT:
|
|---|
| 2833 | /* If this looks like a file name symbol, and it comes after
|
|---|
| 2834 | the line number we have found so far, but before the
|
|---|
| 2835 | offset, then we have probably not found the right line
|
|---|
| 2836 | number. */
|
|---|
| 2837 | if (q->symbol.value <= offset
|
|---|
| 2838 | && ((q->symbol.value > low_line_vma
|
|---|
| 2839 | && (line_file_name != NULL
|
|---|
| 2840 | || *line_ptr != 0))
|
|---|
| 2841 | || (q->symbol.value > low_func_vma
|
|---|
| 2842 | && func != NULL)))
|
|---|
| 2843 | {
|
|---|
| 2844 | const char *symname;
|
|---|
| 2845 |
|
|---|
| 2846 | symname = q->symbol.name;
|
|---|
| 2847 | if (strcmp (symname + strlen (symname) - 2, ".o") == 0)
|
|---|
| 2848 | {
|
|---|
| 2849 | if (q->symbol.value > low_line_vma)
|
|---|
| 2850 | {
|
|---|
| 2851 | *line_ptr = 0;
|
|---|
| 2852 | line_file_name = NULL;
|
|---|
| 2853 | }
|
|---|
| 2854 | if (q->symbol.value > low_func_vma)
|
|---|
| 2855 | func = NULL;
|
|---|
| 2856 | }
|
|---|
| 2857 | }
|
|---|
| 2858 | break;
|
|---|
| 2859 |
|
|---|
| 2860 | case N_SO:
|
|---|
| 2861 | /* If this symbol is less than the offset, but greater than
|
|---|
| 2862 | the line number we have found so far, then we have not
|
|---|
| 2863 | found the right line number. */
|
|---|
| 2864 | if (q->symbol.value <= offset)
|
|---|
| 2865 | {
|
|---|
| 2866 | if (q->symbol.value > low_line_vma)
|
|---|
| 2867 | {
|
|---|
| 2868 | *line_ptr = 0;
|
|---|
| 2869 | line_file_name = NULL;
|
|---|
| 2870 | }
|
|---|
| 2871 | if (q->symbol.value > low_func_vma)
|
|---|
| 2872 | func = NULL;
|
|---|
| 2873 | }
|
|---|
| 2874 |
|
|---|
| 2875 | main_file_name = current_file_name = q->symbol.name;
|
|---|
| 2876 | /* Look ahead to next symbol to check if that too is an N_SO. */
|
|---|
| 2877 | p++;
|
|---|
| 2878 | if (*p == NULL)
|
|---|
| 2879 | break;
|
|---|
| 2880 | q = (aout_symbol_type *) (*p);
|
|---|
| 2881 | if (q->type != (int)N_SO)
|
|---|
| 2882 | goto next;
|
|---|
| 2883 |
|
|---|
| 2884 | /* Found a second N_SO First is directory; second is filename. */
|
|---|
| 2885 | directory_name = current_file_name;
|
|---|
| 2886 | main_file_name = current_file_name = q->symbol.name;
|
|---|
| 2887 | if (obj_textsec (abfd) != section)
|
|---|
| 2888 | goto done;
|
|---|
| 2889 | break;
|
|---|
| 2890 | case N_SOL:
|
|---|
| 2891 | current_file_name = q->symbol.name;
|
|---|
| 2892 | break;
|
|---|
| 2893 |
|
|---|
| 2894 | case N_SLINE:
|
|---|
| 2895 |
|
|---|
| 2896 | case N_DSLINE:
|
|---|
| 2897 | case N_BSLINE:
|
|---|
| 2898 | /* We'll keep this if it resolves nearer than the one we have
|
|---|
| 2899 | already. */
|
|---|
| 2900 | if (q->symbol.value >= low_line_vma
|
|---|
| 2901 | && q->symbol.value <= offset)
|
|---|
| 2902 | {
|
|---|
| 2903 | *line_ptr = q->desc;
|
|---|
| 2904 | low_line_vma = q->symbol.value;
|
|---|
| 2905 | line_file_name = current_file_name;
|
|---|
| 2906 | line_directory_name = directory_name;
|
|---|
| 2907 | }
|
|---|
| 2908 | break;
|
|---|
| 2909 | case N_FUN:
|
|---|
| 2910 | {
|
|---|
| 2911 | /* We'll keep this if it is nearer than the one we have already. */
|
|---|
| 2912 | if (q->symbol.value >= low_func_vma &&
|
|---|
| 2913 | q->symbol.value <= offset)
|
|---|
| 2914 | {
|
|---|
| 2915 | low_func_vma = q->symbol.value;
|
|---|
| 2916 | func = (asymbol *)q;
|
|---|
| 2917 | }
|
|---|
| 2918 | else if (q->symbol.value > offset)
|
|---|
| 2919 | goto done;
|
|---|
| 2920 | }
|
|---|
| 2921 | break;
|
|---|
| 2922 | }
|
|---|
| 2923 | }
|
|---|
| 2924 | }
|
|---|
| 2925 |
|
|---|
| 2926 | done:
|
|---|
| 2927 | if (*line_ptr != 0)
|
|---|
| 2928 | {
|
|---|
| 2929 | main_file_name = line_file_name;
|
|---|
| 2930 | directory_name = line_directory_name;
|
|---|
| 2931 | }
|
|---|
| 2932 |
|
|---|
| 2933 | if (main_file_name == NULL
|
|---|
| 2934 | || IS_ABSOLUTE_PATH (main_file_name)
|
|---|
| 2935 | || directory_name == NULL)
|
|---|
| 2936 | filelen = 0;
|
|---|
| 2937 | else
|
|---|
| 2938 | filelen = strlen (directory_name) + strlen (main_file_name);
|
|---|
| 2939 |
|
|---|
| 2940 | if (func == NULL)
|
|---|
| 2941 | funclen = 0;
|
|---|
| 2942 | else
|
|---|
| 2943 | funclen = strlen (bfd_asymbol_name (func));
|
|---|
| 2944 |
|
|---|
| 2945 | if (adata (abfd).line_buf != NULL)
|
|---|
| 2946 | free (adata (abfd).line_buf);
|
|---|
| 2947 |
|
|---|
| 2948 | if (filelen + funclen == 0)
|
|---|
| 2949 | adata (abfd).line_buf = buf = NULL;
|
|---|
| 2950 | else
|
|---|
| 2951 | {
|
|---|
| 2952 | buf = (char *) bfd_malloc (filelen + funclen + 3);
|
|---|
| 2953 | adata (abfd).line_buf = buf;
|
|---|
| 2954 | if (buf == NULL)
|
|---|
| 2955 | return FALSE;
|
|---|
| 2956 | }
|
|---|
| 2957 |
|
|---|
| 2958 | if (main_file_name != NULL)
|
|---|
| 2959 | {
|
|---|
| 2960 | if (IS_ABSOLUTE_PATH (main_file_name) || directory_name == NULL)
|
|---|
| 2961 | *filename_ptr = main_file_name;
|
|---|
| 2962 | else
|
|---|
| 2963 | {
|
|---|
| 2964 | sprintf (buf, "%s%s", directory_name, main_file_name);
|
|---|
| 2965 | *filename_ptr = buf;
|
|---|
| 2966 | buf += filelen + 1;
|
|---|
| 2967 | }
|
|---|
| 2968 | }
|
|---|
| 2969 |
|
|---|
| 2970 | if (func)
|
|---|
| 2971 | {
|
|---|
| 2972 | const char *function = func->name;
|
|---|
| 2973 | char *colon;
|
|---|
| 2974 |
|
|---|
| 2975 | /* The caller expects a symbol name. We actually have a
|
|---|
| 2976 | function name, without the leading underscore. Put the
|
|---|
| 2977 | underscore back in, so that the caller gets a symbol name. */
|
|---|
| 2978 | if (bfd_get_symbol_leading_char (abfd) == '\0')
|
|---|
| 2979 | strcpy (buf, function);
|
|---|
| 2980 | else
|
|---|
| 2981 | {
|
|---|
| 2982 | buf[0] = bfd_get_symbol_leading_char (abfd);
|
|---|
| 2983 | strcpy (buf + 1, function);
|
|---|
| 2984 | }
|
|---|
| 2985 | /* Have to remove : stuff. */
|
|---|
| 2986 | colon = strchr (buf, ':');
|
|---|
| 2987 | if (colon != NULL)
|
|---|
| 2988 | *colon = '\0';
|
|---|
| 2989 | *functionname_ptr = buf;
|
|---|
| 2990 | }
|
|---|
| 2991 |
|
|---|
| 2992 | return TRUE;
|
|---|
| 2993 | }
|
|---|
| 2994 |
|
|---|
| 2995 | int
|
|---|
| 2996 | NAME(aout,sizeof_headers) (abfd, execable)
|
|---|
| 2997 | bfd *abfd;
|
|---|
| 2998 | bfd_boolean execable ATTRIBUTE_UNUSED;
|
|---|
| 2999 | {
|
|---|
| 3000 | return adata (abfd).exec_bytes_size;
|
|---|
| 3001 | }
|
|---|
| 3002 |
|
|---|
| 3003 | /* Free all information we have cached for this BFD. We can always
|
|---|
| 3004 | read it again later if we need it. */
|
|---|
| 3005 |
|
|---|
| 3006 | bfd_boolean
|
|---|
| 3007 | NAME(aout,bfd_free_cached_info) (abfd)
|
|---|
| 3008 | bfd *abfd;
|
|---|
| 3009 | {
|
|---|
| 3010 | asection *o;
|
|---|
| 3011 |
|
|---|
| 3012 | if (bfd_get_format (abfd) != bfd_object
|
|---|
| 3013 | || abfd->tdata.aout_data == NULL)
|
|---|
| 3014 | return TRUE;
|
|---|
| 3015 |
|
|---|
| 3016 | #define BFCI_FREE(x) if (x != NULL) { free (x); x = NULL; }
|
|---|
| 3017 | BFCI_FREE (obj_aout_symbols (abfd));
|
|---|
| 3018 | #ifdef USE_MMAP
|
|---|
| 3019 | obj_aout_external_syms (abfd) = 0;
|
|---|
| 3020 | bfd_free_window (&obj_aout_sym_window (abfd));
|
|---|
| 3021 | bfd_free_window (&obj_aout_string_window (abfd));
|
|---|
| 3022 | obj_aout_external_strings (abfd) = 0;
|
|---|
| 3023 | #else
|
|---|
| 3024 | BFCI_FREE (obj_aout_external_syms (abfd));
|
|---|
| 3025 | BFCI_FREE (obj_aout_external_strings (abfd));
|
|---|
| 3026 | #endif
|
|---|
| 3027 | for (o = abfd->sections; o != (asection *) NULL; o = o->next)
|
|---|
| 3028 | BFCI_FREE (o->relocation);
|
|---|
| 3029 | #undef BFCI_FREE
|
|---|
| 3030 |
|
|---|
| 3031 | return TRUE;
|
|---|
| 3032 | }
|
|---|
| 3033 | |
|---|
| 3034 |
|
|---|
| 3035 | /* a.out link code. */
|
|---|
| 3036 |
|
|---|
| 3037 | static bfd_boolean aout_link_add_object_symbols
|
|---|
| 3038 | PARAMS ((bfd *, struct bfd_link_info *));
|
|---|
| 3039 | static bfd_boolean aout_link_check_archive_element
|
|---|
| 3040 | PARAMS ((bfd *, struct bfd_link_info *, bfd_boolean *));
|
|---|
| 3041 | static bfd_boolean aout_link_free_symbols
|
|---|
| 3042 | PARAMS ((bfd *));
|
|---|
| 3043 | static bfd_boolean aout_link_check_ar_symbols
|
|---|
| 3044 | PARAMS ((bfd *, struct bfd_link_info *, bfd_boolean *pneeded));
|
|---|
| 3045 | static bfd_boolean aout_link_add_symbols
|
|---|
| 3046 | PARAMS ((bfd *, struct bfd_link_info *));
|
|---|
| 3047 |
|
|---|
| 3048 | /* Routine to create an entry in an a.out link hash table. */
|
|---|
| 3049 |
|
|---|
| 3050 | struct bfd_hash_entry *
|
|---|
| 3051 | NAME(aout,link_hash_newfunc) (entry, table, string)
|
|---|
| 3052 | struct bfd_hash_entry *entry;
|
|---|
| 3053 | struct bfd_hash_table *table;
|
|---|
| 3054 | const char *string;
|
|---|
| 3055 | {
|
|---|
| 3056 | struct aout_link_hash_entry *ret = (struct aout_link_hash_entry *) entry;
|
|---|
| 3057 |
|
|---|
| 3058 | /* Allocate the structure if it has not already been allocated by a
|
|---|
| 3059 | subclass. */
|
|---|
| 3060 | if (ret == (struct aout_link_hash_entry *) NULL)
|
|---|
| 3061 | ret = ((struct aout_link_hash_entry *)
|
|---|
| 3062 | bfd_hash_allocate (table, sizeof (struct aout_link_hash_entry)));
|
|---|
| 3063 | if (ret == (struct aout_link_hash_entry *) NULL)
|
|---|
| 3064 | return (struct bfd_hash_entry *) ret;
|
|---|
| 3065 |
|
|---|
| 3066 | /* Call the allocation method of the superclass. */
|
|---|
| 3067 | ret = ((struct aout_link_hash_entry *)
|
|---|
| 3068 | _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
|
|---|
| 3069 | table, string));
|
|---|
| 3070 | if (ret)
|
|---|
| 3071 | {
|
|---|
| 3072 | /* Set local fields. */
|
|---|
| 3073 | ret->written = FALSE;
|
|---|
| 3074 | ret->indx = -1;
|
|---|
| 3075 | }
|
|---|
| 3076 |
|
|---|
| 3077 | return (struct bfd_hash_entry *) ret;
|
|---|
| 3078 | }
|
|---|
| 3079 |
|
|---|
| 3080 | /* Initialize an a.out link hash table. */
|
|---|
| 3081 |
|
|---|
| 3082 | bfd_boolean
|
|---|
| 3083 | NAME(aout,link_hash_table_init) (table, abfd, newfunc)
|
|---|
| 3084 | struct aout_link_hash_table *table;
|
|---|
| 3085 | bfd *abfd;
|
|---|
| 3086 | struct bfd_hash_entry *(*newfunc)
|
|---|
| 3087 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *,
|
|---|
| 3088 | const char *));
|
|---|
| 3089 | {
|
|---|
| 3090 | return _bfd_link_hash_table_init (&table->root, abfd, newfunc);
|
|---|
| 3091 | }
|
|---|
| 3092 |
|
|---|
| 3093 | /* Create an a.out link hash table. */
|
|---|
| 3094 |
|
|---|
| 3095 | struct bfd_link_hash_table *
|
|---|
| 3096 | NAME(aout,link_hash_table_create) (abfd)
|
|---|
| 3097 | bfd *abfd;
|
|---|
| 3098 | {
|
|---|
| 3099 | struct aout_link_hash_table *ret;
|
|---|
| 3100 | bfd_size_type amt = sizeof (struct aout_link_hash_table);
|
|---|
| 3101 |
|
|---|
| 3102 | ret = (struct aout_link_hash_table *) bfd_malloc (amt);
|
|---|
| 3103 | if (ret == NULL)
|
|---|
| 3104 | return (struct bfd_link_hash_table *) NULL;
|
|---|
| 3105 |
|
|---|
| 3106 | if (! NAME(aout,link_hash_table_init) (ret, abfd,
|
|---|
| 3107 | NAME(aout,link_hash_newfunc)))
|
|---|
| 3108 | {
|
|---|
| 3109 | free (ret);
|
|---|
| 3110 | return (struct bfd_link_hash_table *) NULL;
|
|---|
| 3111 | }
|
|---|
| 3112 | return &ret->root;
|
|---|
| 3113 | }
|
|---|
| 3114 |
|
|---|
| 3115 | /* Given an a.out BFD, add symbols to the global hash table as
|
|---|
| 3116 | appropriate. */
|
|---|
| 3117 |
|
|---|
| 3118 | bfd_boolean
|
|---|
| 3119 | NAME(aout,link_add_symbols) (abfd, info)
|
|---|
| 3120 | bfd *abfd;
|
|---|
| 3121 | struct bfd_link_info *info;
|
|---|
| 3122 | {
|
|---|
| 3123 | switch (bfd_get_format (abfd))
|
|---|
| 3124 | {
|
|---|
| 3125 | case bfd_object:
|
|---|
| 3126 | return aout_link_add_object_symbols (abfd, info);
|
|---|
| 3127 | case bfd_archive:
|
|---|
| 3128 | return _bfd_generic_link_add_archive_symbols
|
|---|
| 3129 | (abfd, info, aout_link_check_archive_element);
|
|---|
| 3130 | default:
|
|---|
| 3131 | bfd_set_error (bfd_error_wrong_format);
|
|---|
| 3132 | return FALSE;
|
|---|
| 3133 | }
|
|---|
| 3134 | }
|
|---|
| 3135 |
|
|---|
| 3136 | /* Add symbols from an a.out object file. */
|
|---|
| 3137 |
|
|---|
| 3138 | static bfd_boolean
|
|---|
| 3139 | aout_link_add_object_symbols (abfd, info)
|
|---|
| 3140 | bfd *abfd;
|
|---|
| 3141 | struct bfd_link_info *info;
|
|---|
| 3142 | {
|
|---|
| 3143 | if (! aout_get_external_symbols (abfd))
|
|---|
| 3144 | return FALSE;
|
|---|
| 3145 | if (! aout_link_add_symbols (abfd, info))
|
|---|
| 3146 | return FALSE;
|
|---|
| 3147 | if (! info->keep_memory)
|
|---|
| 3148 | {
|
|---|
| 3149 | if (! aout_link_free_symbols (abfd))
|
|---|
| 3150 | return FALSE;
|
|---|
| 3151 | }
|
|---|
| 3152 | return TRUE;
|
|---|
| 3153 | }
|
|---|
| 3154 |
|
|---|
| 3155 | /* Check a single archive element to see if we need to include it in
|
|---|
| 3156 | the link. *PNEEDED is set according to whether this element is
|
|---|
| 3157 | needed in the link or not. This is called from
|
|---|
| 3158 | _bfd_generic_link_add_archive_symbols. */
|
|---|
| 3159 |
|
|---|
| 3160 | static bfd_boolean
|
|---|
| 3161 | aout_link_check_archive_element (abfd, info, pneeded)
|
|---|
| 3162 | bfd *abfd;
|
|---|
| 3163 | struct bfd_link_info *info;
|
|---|
| 3164 | bfd_boolean *pneeded;
|
|---|
| 3165 | {
|
|---|
| 3166 | if (! aout_get_external_symbols (abfd))
|
|---|
| 3167 | return FALSE;
|
|---|
| 3168 |
|
|---|
| 3169 | if (! aout_link_check_ar_symbols (abfd, info, pneeded))
|
|---|
| 3170 | return FALSE;
|
|---|
| 3171 |
|
|---|
| 3172 | if (*pneeded)
|
|---|
| 3173 | {
|
|---|
| 3174 | if (! aout_link_add_symbols (abfd, info))
|
|---|
| 3175 | return FALSE;
|
|---|
| 3176 | }
|
|---|
| 3177 |
|
|---|
| 3178 | if (! info->keep_memory || ! *pneeded)
|
|---|
| 3179 | {
|
|---|
| 3180 | if (! aout_link_free_symbols (abfd))
|
|---|
| 3181 | return FALSE;
|
|---|
| 3182 | }
|
|---|
| 3183 |
|
|---|
| 3184 | return TRUE;
|
|---|
| 3185 | }
|
|---|
| 3186 |
|
|---|
| 3187 | /* Free up the internal symbols read from an a.out file. */
|
|---|
| 3188 |
|
|---|
| 3189 | static bfd_boolean
|
|---|
| 3190 | aout_link_free_symbols (abfd)
|
|---|
| 3191 | bfd *abfd;
|
|---|
| 3192 | {
|
|---|
| 3193 | if (obj_aout_external_syms (abfd) != (struct external_nlist *) NULL)
|
|---|
| 3194 | {
|
|---|
| 3195 | #ifdef USE_MMAP
|
|---|
| 3196 | bfd_free_window (&obj_aout_sym_window (abfd));
|
|---|
| 3197 | #else
|
|---|
| 3198 | free ((PTR) obj_aout_external_syms (abfd));
|
|---|
| 3199 | #endif
|
|---|
| 3200 | obj_aout_external_syms (abfd) = (struct external_nlist *) NULL;
|
|---|
| 3201 | }
|
|---|
| 3202 | if (obj_aout_external_strings (abfd) != (char *) NULL)
|
|---|
| 3203 | {
|
|---|
| 3204 | #ifdef USE_MMAP
|
|---|
| 3205 | bfd_free_window (&obj_aout_string_window (abfd));
|
|---|
| 3206 | #else
|
|---|
| 3207 | free ((PTR) obj_aout_external_strings (abfd));
|
|---|
| 3208 | #endif
|
|---|
| 3209 | obj_aout_external_strings (abfd) = (char *) NULL;
|
|---|
| 3210 | }
|
|---|
| 3211 | return TRUE;
|
|---|
| 3212 | }
|
|---|
| 3213 |
|
|---|
| 3214 | /* Look through the internal symbols to see if this object file should
|
|---|
| 3215 | be included in the link. We should include this object file if it
|
|---|
| 3216 | defines any symbols which are currently undefined. If this object
|
|---|
| 3217 | file defines a common symbol, then we may adjust the size of the
|
|---|
| 3218 | known symbol but we do not include the object file in the link
|
|---|
| 3219 | (unless there is some other reason to include it). */
|
|---|
| 3220 |
|
|---|
| 3221 | static bfd_boolean
|
|---|
| 3222 | aout_link_check_ar_symbols (abfd, info, pneeded)
|
|---|
| 3223 | bfd *abfd;
|
|---|
| 3224 | struct bfd_link_info *info;
|
|---|
| 3225 | bfd_boolean *pneeded;
|
|---|
| 3226 | {
|
|---|
| 3227 | register struct external_nlist *p;
|
|---|
| 3228 | struct external_nlist *pend;
|
|---|
| 3229 | char *strings;
|
|---|
| 3230 |
|
|---|
| 3231 | *pneeded = FALSE;
|
|---|
| 3232 |
|
|---|
| 3233 | /* Look through all the symbols. */
|
|---|
| 3234 | p = obj_aout_external_syms (abfd);
|
|---|
| 3235 | pend = p + obj_aout_external_sym_count (abfd);
|
|---|
| 3236 | strings = obj_aout_external_strings (abfd);
|
|---|
| 3237 | for (; p < pend; p++)
|
|---|
| 3238 | {
|
|---|
| 3239 | int type = H_GET_8 (abfd, p->e_type);
|
|---|
| 3240 | const char *name;
|
|---|
| 3241 | struct bfd_link_hash_entry *h;
|
|---|
| 3242 |
|
|---|
| 3243 | /* Ignore symbols that are not externally visible. This is an
|
|---|
| 3244 | optimization only, as we check the type more thoroughly
|
|---|
| 3245 | below. */
|
|---|
| 3246 | if (((type & N_EXT) == 0
|
|---|
| 3247 | || IS_STAB(type)
|
|---|
| 3248 | || type == N_FN)
|
|---|
| 3249 | && type != N_WEAKA
|
|---|
| 3250 | && type != N_WEAKT
|
|---|
| 3251 | && type != N_WEAKD
|
|---|
| 3252 | && type != N_WEAKB)
|
|---|
| 3253 | {
|
|---|
| 3254 | if (type == N_WARNING
|
|---|
| 3255 | || type == N_INDR)
|
|---|
| 3256 | ++p;
|
|---|
| 3257 | continue;
|
|---|
| 3258 | }
|
|---|
| 3259 |
|
|---|
| 3260 | name = strings + GET_WORD (abfd, p->e_strx);
|
|---|
| 3261 | h = bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE);
|
|---|
| 3262 |
|
|---|
| 3263 | /* We are only interested in symbols that are currently
|
|---|
| 3264 | undefined or common. */
|
|---|
| 3265 | if (h == (struct bfd_link_hash_entry *) NULL
|
|---|
| 3266 | || (h->type != bfd_link_hash_undefined
|
|---|
| 3267 | && h->type != bfd_link_hash_common))
|
|---|
| 3268 | {
|
|---|
| 3269 | if (type == (N_INDR | N_EXT))
|
|---|
| 3270 | ++p;
|
|---|
| 3271 | continue;
|
|---|
| 3272 | }
|
|---|
| 3273 |
|
|---|
| 3274 | if (type == (N_TEXT | N_EXT)
|
|---|
| 3275 | || type == (N_DATA | N_EXT)
|
|---|
| 3276 | || type == (N_BSS | N_EXT)
|
|---|
| 3277 | || type == (N_ABS | N_EXT)
|
|---|
| 3278 | || type == (N_INDR | N_EXT)
|
|---|
| 3279 | #if defined (EMX)
|
|---|
| 3280 | || type == (N_IMP1 | N_EXT)
|
|---|
| 3281 | #endif
|
|---|
| 3282 | )
|
|---|
| 3283 | {
|
|---|
| 3284 | /* This object file defines this symbol. We must link it
|
|---|
| 3285 | in. This is true regardless of whether the current
|
|---|
| 3286 | definition of the symbol is undefined or common.
|
|---|
| 3287 |
|
|---|
| 3288 | If the current definition is common, we have a case in
|
|---|
| 3289 | which we have already seen an object file including:
|
|---|
| 3290 | int a;
|
|---|
| 3291 | and this object file from the archive includes:
|
|---|
| 3292 | int a = 5;
|
|---|
| 3293 | In such a case, whether to include this object is target
|
|---|
| 3294 | dependant for backward compatability.
|
|---|
| 3295 |
|
|---|
| 3296 | FIXME: The SunOS 4.1.3 linker will pull in the archive
|
|---|
| 3297 | element if the symbol is defined in the .data section,
|
|---|
| 3298 | but not if it is defined in the .text section. That
|
|---|
| 3299 | seems a bit crazy to me, and it has not been implemented
|
|---|
| 3300 | yet. However, it might be correct. */
|
|---|
| 3301 | if (h->type == bfd_link_hash_common)
|
|---|
| 3302 | {
|
|---|
| 3303 | int skip = 0;
|
|---|
| 3304 |
|
|---|
| 3305 | switch (info->common_skip_ar_aymbols)
|
|---|
| 3306 | {
|
|---|
| 3307 | case bfd_link_common_skip_text:
|
|---|
| 3308 | skip = (type == (N_TEXT | N_EXT));
|
|---|
| 3309 | break;
|
|---|
| 3310 | case bfd_link_common_skip_data:
|
|---|
| 3311 | skip = (type == (N_DATA | N_EXT));
|
|---|
| 3312 | break;
|
|---|
| 3313 | default:
|
|---|
| 3314 | case bfd_link_common_skip_all:
|
|---|
| 3315 | skip = 1;
|
|---|
| 3316 | break;
|
|---|
| 3317 | }
|
|---|
| 3318 |
|
|---|
| 3319 | if (skip)
|
|---|
| 3320 | continue;
|
|---|
| 3321 | }
|
|---|
| 3322 |
|
|---|
| 3323 | if (! (*info->callbacks->add_archive_element) (info, abfd, name))
|
|---|
| 3324 | return FALSE;
|
|---|
| 3325 | *pneeded = TRUE;
|
|---|
| 3326 | return TRUE;
|
|---|
| 3327 | }
|
|---|
| 3328 |
|
|---|
| 3329 | if (type == (N_UNDF | N_EXT))
|
|---|
| 3330 | {
|
|---|
| 3331 | bfd_vma value;
|
|---|
| 3332 |
|
|---|
| 3333 | value = GET_WORD (abfd, p->e_value);
|
|---|
| 3334 | if (value != 0)
|
|---|
| 3335 | {
|
|---|
| 3336 | /* This symbol is common in the object from the archive
|
|---|
| 3337 | file. */
|
|---|
| 3338 | if (h->type == bfd_link_hash_undefined)
|
|---|
| 3339 | {
|
|---|
| 3340 | bfd *symbfd;
|
|---|
| 3341 | unsigned int power;
|
|---|
| 3342 |
|
|---|
| 3343 | symbfd = h->u.undef.abfd;
|
|---|
| 3344 | if (symbfd == (bfd *) NULL)
|
|---|
| 3345 | {
|
|---|
| 3346 | /* This symbol was created as undefined from
|
|---|
| 3347 | outside BFD. We assume that we should link
|
|---|
| 3348 | in the object file. This is done for the -u
|
|---|
| 3349 | option in the linker. */
|
|---|
| 3350 | if (! (*info->callbacks->add_archive_element) (info,
|
|---|
| 3351 | abfd,
|
|---|
| 3352 | name))
|
|---|
| 3353 | return FALSE;
|
|---|
| 3354 | *pneeded = TRUE;
|
|---|
| 3355 | return TRUE;
|
|---|
| 3356 | }
|
|---|
| 3357 | /* Turn the current link symbol into a common
|
|---|
| 3358 | symbol. It is already on the undefs list. */
|
|---|
| 3359 | h->type = bfd_link_hash_common;
|
|---|
| 3360 | h->u.c.p = ((struct bfd_link_hash_common_entry *)
|
|---|
| 3361 | bfd_hash_allocate (&info->hash->table,
|
|---|
| 3362 | sizeof (struct bfd_link_hash_common_entry)));
|
|---|
| 3363 | if (h->u.c.p == NULL)
|
|---|
| 3364 | return FALSE;
|
|---|
| 3365 |
|
|---|
| 3366 | h->u.c.size = value;
|
|---|
| 3367 |
|
|---|
| 3368 | /* FIXME: This isn't quite right. The maximum
|
|---|
| 3369 | alignment of a common symbol should be set by the
|
|---|
| 3370 | architecture of the output file, not of the input
|
|---|
| 3371 | file. */
|
|---|
| 3372 | power = bfd_log2 (value);
|
|---|
| 3373 | if (power > bfd_get_arch_info (abfd)->section_align_power)
|
|---|
| 3374 | power = bfd_get_arch_info (abfd)->section_align_power;
|
|---|
| 3375 | h->u.c.p->alignment_power = power;
|
|---|
| 3376 |
|
|---|
| 3377 | h->u.c.p->section = bfd_make_section_old_way (symbfd,
|
|---|
| 3378 | "COMMON");
|
|---|
| 3379 | }
|
|---|
| 3380 | else
|
|---|
| 3381 | {
|
|---|
| 3382 | /* Adjust the size of the common symbol if
|
|---|
| 3383 | necessary. */
|
|---|
| 3384 | if (value > h->u.c.size)
|
|---|
| 3385 | h->u.c.size = value;
|
|---|
| 3386 | }
|
|---|
| 3387 | }
|
|---|
| 3388 | }
|
|---|
| 3389 |
|
|---|
| 3390 | if (type == N_WEAKA
|
|---|
| 3391 | || type == N_WEAKT
|
|---|
| 3392 | || type == N_WEAKD
|
|---|
| 3393 | || type == N_WEAKB)
|
|---|
| 3394 | {
|
|---|
| 3395 | /* This symbol is weak but defined. We must pull it in if
|
|---|
| 3396 | the current link symbol is undefined, but we don't want
|
|---|
| 3397 | it if the current link symbol is common. */
|
|---|
| 3398 | if (h->type == bfd_link_hash_undefined)
|
|---|
| 3399 | {
|
|---|
| 3400 | if (! (*info->callbacks->add_archive_element) (info, abfd, name))
|
|---|
| 3401 | return FALSE;
|
|---|
| 3402 | *pneeded = TRUE;
|
|---|
| 3403 | return TRUE;
|
|---|
| 3404 | }
|
|---|
| 3405 | }
|
|---|
| 3406 | }
|
|---|
| 3407 |
|
|---|
| 3408 | /* We do not need this object file. */
|
|---|
| 3409 | return TRUE;
|
|---|
| 3410 | }
|
|---|
| 3411 |
|
|---|
| 3412 | /* Add all symbols from an object file to the hash table. */
|
|---|
| 3413 |
|
|---|
| 3414 | static bfd_boolean
|
|---|
| 3415 | aout_link_add_symbols (abfd, info)
|
|---|
| 3416 | bfd *abfd;
|
|---|
| 3417 | struct bfd_link_info *info;
|
|---|
| 3418 | {
|
|---|
| 3419 | bfd_boolean (*add_one_symbol)
|
|---|
| 3420 | PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword, asection *,
|
|---|
| 3421 | bfd_vma, const char *, bfd_boolean, bfd_boolean,
|
|---|
| 3422 | struct bfd_link_hash_entry **));
|
|---|
| 3423 | struct external_nlist *syms;
|
|---|
| 3424 | bfd_size_type sym_count;
|
|---|
| 3425 | char *strings;
|
|---|
| 3426 | bfd_boolean copy;
|
|---|
| 3427 | struct aout_link_hash_entry **sym_hash;
|
|---|
| 3428 | register struct external_nlist *p;
|
|---|
| 3429 | struct external_nlist *pend;
|
|---|
| 3430 | bfd_size_type amt;
|
|---|
| 3431 |
|
|---|
| 3432 | syms = obj_aout_external_syms (abfd);
|
|---|
| 3433 | sym_count = obj_aout_external_sym_count (abfd);
|
|---|
| 3434 | strings = obj_aout_external_strings (abfd);
|
|---|
| 3435 | if (info->keep_memory)
|
|---|
| 3436 | copy = FALSE;
|
|---|
| 3437 | else
|
|---|
| 3438 | copy = TRUE;
|
|---|
| 3439 |
|
|---|
| 3440 | if (aout_backend_info (abfd)->add_dynamic_symbols != NULL)
|
|---|
| 3441 | {
|
|---|
| 3442 | if (! ((*aout_backend_info (abfd)->add_dynamic_symbols)
|
|---|
| 3443 | (abfd, info, &syms, &sym_count, &strings)))
|
|---|
| 3444 | return FALSE;
|
|---|
| 3445 | }
|
|---|
| 3446 |
|
|---|
| 3447 | /* We keep a list of the linker hash table entries that correspond
|
|---|
| 3448 | to particular symbols. We could just look them up in the hash
|
|---|
| 3449 | table, but keeping the list is more efficient. Perhaps this
|
|---|
| 3450 | should be conditional on info->keep_memory. */
|
|---|
| 3451 | amt = sym_count * sizeof (struct aout_link_hash_entry *);
|
|---|
| 3452 | sym_hash = (struct aout_link_hash_entry **) bfd_alloc (abfd, amt);
|
|---|
| 3453 | if (sym_hash == NULL && sym_count != 0)
|
|---|
| 3454 | return FALSE;
|
|---|
| 3455 | obj_aout_sym_hashes (abfd) = sym_hash;
|
|---|
| 3456 |
|
|---|
| 3457 | add_one_symbol = aout_backend_info (abfd)->add_one_symbol;
|
|---|
| 3458 | if (add_one_symbol == NULL)
|
|---|
| 3459 | add_one_symbol = _bfd_generic_link_add_one_symbol;
|
|---|
| 3460 |
|
|---|
| 3461 | p = syms;
|
|---|
| 3462 | pend = p + sym_count;
|
|---|
| 3463 | for (; p < pend; p++, sym_hash++)
|
|---|
| 3464 | {
|
|---|
| 3465 | int type;
|
|---|
| 3466 | const char *name;
|
|---|
| 3467 | bfd_vma value;
|
|---|
| 3468 | asection *section;
|
|---|
| 3469 | flagword flags;
|
|---|
| 3470 | const char *string;
|
|---|
| 3471 |
|
|---|
| 3472 | *sym_hash = NULL;
|
|---|
| 3473 |
|
|---|
| 3474 | type = H_GET_8 (abfd, p->e_type);
|
|---|
| 3475 |
|
|---|
| 3476 | /* Ignore debugging symbols. */
|
|---|
| 3477 | if (IS_STAB(type))
|
|---|
| 3478 | continue;
|
|---|
| 3479 |
|
|---|
| 3480 | name = strings + GET_WORD (abfd, p->e_strx);
|
|---|
| 3481 | value = GET_WORD (abfd, p->e_value);
|
|---|
| 3482 | flags = BSF_GLOBAL;
|
|---|
| 3483 | string = NULL;
|
|---|
| 3484 | switch (type)
|
|---|
| 3485 | {
|
|---|
| 3486 | default:
|
|---|
| 3487 | abort ();
|
|---|
| 3488 |
|
|---|
| 3489 | case N_UNDF:
|
|---|
| 3490 | case N_ABS:
|
|---|
| 3491 | case N_TEXT:
|
|---|
| 3492 | case N_DATA:
|
|---|
| 3493 | case N_BSS:
|
|---|
| 3494 | case N_FN_SEQ:
|
|---|
| 3495 | case N_COMM:
|
|---|
| 3496 | case N_SETV:
|
|---|
| 3497 | case N_FN:
|
|---|
| 3498 | /* Ignore symbols that are not externally visible. */
|
|---|
| 3499 | continue;
|
|---|
| 3500 | case N_INDR:
|
|---|
| 3501 | /* Ignore local indirect symbol. */
|
|---|
| 3502 | ++p;
|
|---|
| 3503 | ++sym_hash;
|
|---|
| 3504 | continue;
|
|---|
| 3505 |
|
|---|
| 3506 | case N_UNDF | N_EXT:
|
|---|
| 3507 | if (value == 0)
|
|---|
| 3508 | {
|
|---|
| 3509 | section = bfd_und_section_ptr;
|
|---|
| 3510 | flags = 0;
|
|---|
| 3511 | }
|
|---|
| 3512 | else
|
|---|
| 3513 | section = bfd_com_section_ptr;
|
|---|
| 3514 | break;
|
|---|
| 3515 | case N_ABS | N_EXT:
|
|---|
| 3516 | section = bfd_abs_section_ptr;
|
|---|
| 3517 | break;
|
|---|
| 3518 | case N_TEXT | N_EXT:
|
|---|
| 3519 | section = obj_textsec (abfd);
|
|---|
| 3520 | value -= bfd_get_section_vma (abfd, section);
|
|---|
| 3521 | break;
|
|---|
| 3522 | case N_DATA | N_EXT:
|
|---|
| 3523 | case N_SETV | N_EXT:
|
|---|
| 3524 | /* Treat N_SETV symbols as N_DATA symbol; see comment in
|
|---|
| 3525 | translate_from_native_sym_flags. */
|
|---|
| 3526 | section = obj_datasec (abfd);
|
|---|
| 3527 | value -= bfd_get_section_vma (abfd, section);
|
|---|
| 3528 | break;
|
|---|
| 3529 | case N_BSS | N_EXT:
|
|---|
| 3530 | section = obj_bsssec (abfd);
|
|---|
| 3531 | value -= bfd_get_section_vma (abfd, section);
|
|---|
| 3532 | break;
|
|---|
| 3533 | case N_INDR | N_EXT:
|
|---|
| 3534 | /* An indirect symbol. The next symbol is the symbol
|
|---|
| 3535 | which this one really is. */
|
|---|
| 3536 | BFD_ASSERT (p + 1 < pend);
|
|---|
| 3537 | ++p;
|
|---|
| 3538 | string = strings + GET_WORD (abfd, p->e_strx);
|
|---|
| 3539 | section = bfd_ind_section_ptr;
|
|---|
| 3540 | flags |= BSF_INDIRECT;
|
|---|
| 3541 | break;
|
|---|
| 3542 | case N_COMM | N_EXT:
|
|---|
| 3543 | section = bfd_com_section_ptr;
|
|---|
| 3544 | break;
|
|---|
| 3545 | case N_SETA: case N_SETA | N_EXT:
|
|---|
| 3546 | section = bfd_abs_section_ptr;
|
|---|
| 3547 | flags |= BSF_CONSTRUCTOR;
|
|---|
| 3548 | break;
|
|---|
| 3549 | case N_SETT: case N_SETT | N_EXT:
|
|---|
| 3550 | section = obj_textsec (abfd);
|
|---|
| 3551 | flags |= BSF_CONSTRUCTOR;
|
|---|
| 3552 | value -= bfd_get_section_vma (abfd, section);
|
|---|
| 3553 | break;
|
|---|
| 3554 | case N_SETD: case N_SETD | N_EXT:
|
|---|
| 3555 | section = obj_datasec (abfd);
|
|---|
| 3556 | flags |= BSF_CONSTRUCTOR;
|
|---|
| 3557 | value -= bfd_get_section_vma (abfd, section);
|
|---|
| 3558 | break;
|
|---|
| 3559 | case N_SETB: case N_SETB | N_EXT:
|
|---|
| 3560 | section = obj_bsssec (abfd);
|
|---|
| 3561 | flags |= BSF_CONSTRUCTOR;
|
|---|
| 3562 | value -= bfd_get_section_vma (abfd, section);
|
|---|
| 3563 | break;
|
|---|
| 3564 | case N_WARNING:
|
|---|
| 3565 | /* A warning symbol. The next symbol is the one to warn
|
|---|
| 3566 | about. */
|
|---|
| 3567 | BFD_ASSERT (p + 1 < pend);
|
|---|
| 3568 | ++p;
|
|---|
| 3569 | string = name;
|
|---|
| 3570 | name = strings + GET_WORD (abfd, p->e_strx);
|
|---|
| 3571 | section = bfd_und_section_ptr;
|
|---|
| 3572 | flags |= BSF_WARNING;
|
|---|
| 3573 | break;
|
|---|
| 3574 | case N_WEAKU:
|
|---|
| 3575 | section = bfd_und_section_ptr;
|
|---|
| 3576 | flags = BSF_WEAK;
|
|---|
| 3577 | break;
|
|---|
| 3578 | case N_WEAKA:
|
|---|
| 3579 | section = bfd_abs_section_ptr;
|
|---|
| 3580 | flags = BSF_WEAK;
|
|---|
| 3581 | break;
|
|---|
| 3582 | case N_WEAKT:
|
|---|
| 3583 | section = obj_textsec (abfd);
|
|---|
| 3584 | value -= bfd_get_section_vma (abfd, section);
|
|---|
| 3585 | flags = BSF_WEAK;
|
|---|
| 3586 | break;
|
|---|
| 3587 | case N_WEAKD:
|
|---|
| 3588 | section = obj_datasec (abfd);
|
|---|
| 3589 | value -= bfd_get_section_vma (abfd, section);
|
|---|
| 3590 | flags = BSF_WEAK;
|
|---|
| 3591 | break;
|
|---|
| 3592 | case N_WEAKB:
|
|---|
| 3593 | section = obj_bsssec (abfd);
|
|---|
| 3594 | value -= bfd_get_section_vma (abfd, section);
|
|---|
| 3595 | flags = BSF_WEAK;
|
|---|
| 3596 | break;
|
|---|
| 3597 | #ifdef EMX
|
|---|
| 3598 | case N_IMP1 | N_EXT:
|
|---|
| 3599 | section = bfd_abs_section_ptr;
|
|---|
| 3600 | flags = BSF_EMX_IMPORT1;
|
|---|
| 3601 | value = -1; /* -1 in *ABS* means external imported symbol */
|
|---|
| 3602 | break;
|
|---|
| 3603 | case N_IMP2 | N_EXT:
|
|---|
| 3604 | section = bfd_abs_section_ptr;
|
|---|
| 3605 | flags = BSF_EMX_IMPORT2;
|
|---|
| 3606 | break;
|
|---|
| 3607 | #endif /* EMX */
|
|---|
| 3608 | }
|
|---|
| 3609 |
|
|---|
| 3610 | if (! ((*add_one_symbol)
|
|---|
| 3611 | (info, abfd, name, flags, section, value, string, copy, FALSE,
|
|---|
| 3612 | (struct bfd_link_hash_entry **) sym_hash)))
|
|---|
| 3613 | return FALSE;
|
|---|
| 3614 |
|
|---|
| 3615 | /* Restrict the maximum alignment of a common symbol based on
|
|---|
| 3616 | the architecture, since a.out has no way to represent
|
|---|
| 3617 | alignment requirements of a section in a .o file. FIXME:
|
|---|
| 3618 | This isn't quite right: it should use the architecture of the
|
|---|
| 3619 | output file, not the input files. */
|
|---|
| 3620 | if ((*sym_hash)->root.type == bfd_link_hash_common
|
|---|
| 3621 | && ((*sym_hash)->root.u.c.p->alignment_power >
|
|---|
| 3622 | bfd_get_arch_info (abfd)->section_align_power))
|
|---|
| 3623 | (*sym_hash)->root.u.c.p->alignment_power =
|
|---|
| 3624 | bfd_get_arch_info (abfd)->section_align_power;
|
|---|
| 3625 |
|
|---|
| 3626 | /* If this is a set symbol, and we are not building sets, then
|
|---|
| 3627 | it is possible for the hash entry to not have been set. In
|
|---|
| 3628 | such a case, treat the symbol as not globally defined. */
|
|---|
| 3629 | if ((*sym_hash)->root.type == bfd_link_hash_new)
|
|---|
| 3630 | {
|
|---|
| 3631 | BFD_ASSERT ((flags & BSF_CONSTRUCTOR) != 0);
|
|---|
| 3632 | *sym_hash = NULL;
|
|---|
| 3633 | }
|
|---|
| 3634 |
|
|---|
| 3635 | if (type == (N_INDR | N_EXT) || type == N_WARNING)
|
|---|
| 3636 | ++sym_hash;
|
|---|
| 3637 | }
|
|---|
| 3638 |
|
|---|
| 3639 | return TRUE;
|
|---|
| 3640 | }
|
|---|
| 3641 | |
|---|
| 3642 |
|
|---|
| 3643 | /* A hash table used for header files with N_BINCL entries. */
|
|---|
| 3644 |
|
|---|
| 3645 | struct aout_link_includes_table
|
|---|
| 3646 | {
|
|---|
| 3647 | struct bfd_hash_table root;
|
|---|
| 3648 | };
|
|---|
| 3649 |
|
|---|
| 3650 | /* A linked list of totals that we have found for a particular header
|
|---|
| 3651 | file. */
|
|---|
| 3652 |
|
|---|
| 3653 | struct aout_link_includes_totals
|
|---|
| 3654 | {
|
|---|
| 3655 | struct aout_link_includes_totals *next;
|
|---|
| 3656 | bfd_vma total;
|
|---|
| 3657 | };
|
|---|
| 3658 |
|
|---|
| 3659 | /* An entry in the header file hash table. */
|
|---|
| 3660 |
|
|---|
| 3661 | struct aout_link_includes_entry
|
|---|
| 3662 | {
|
|---|
| 3663 | struct bfd_hash_entry root;
|
|---|
| 3664 | /* List of totals we have found for this file. */
|
|---|
| 3665 | struct aout_link_includes_totals *totals;
|
|---|
| 3666 | };
|
|---|
| 3667 |
|
|---|
| 3668 | /* Look up an entry in an the header file hash table. */
|
|---|
| 3669 |
|
|---|
| 3670 | #define aout_link_includes_lookup(table, string, create, copy) \
|
|---|
| 3671 | ((struct aout_link_includes_entry *) \
|
|---|
| 3672 | bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
|
|---|
| 3673 |
|
|---|
| 3674 | /* During the final link step we need to pass around a bunch of
|
|---|
| 3675 | information, so we do it in an instance of this structure. */
|
|---|
| 3676 |
|
|---|
| 3677 | struct aout_final_link_info
|
|---|
| 3678 | {
|
|---|
| 3679 | /* General link information. */
|
|---|
| 3680 | struct bfd_link_info *info;
|
|---|
| 3681 | /* Output bfd. */
|
|---|
| 3682 | bfd *output_bfd;
|
|---|
| 3683 | /* Reloc file positions. */
|
|---|
| 3684 | file_ptr treloff, dreloff;
|
|---|
| 3685 | /* File position of symbols. */
|
|---|
| 3686 | file_ptr symoff;
|
|---|
| 3687 | /* String table. */
|
|---|
| 3688 | struct bfd_strtab_hash *strtab;
|
|---|
| 3689 | /* Header file hash table. */
|
|---|
| 3690 | struct aout_link_includes_table includes;
|
|---|
| 3691 | /* A buffer large enough to hold the contents of any section. */
|
|---|
| 3692 | bfd_byte *contents;
|
|---|
| 3693 | /* A buffer large enough to hold the relocs of any section. */
|
|---|
| 3694 | PTR relocs;
|
|---|
| 3695 | /* A buffer large enough to hold the symbol map of any input BFD. */
|
|---|
| 3696 | int *symbol_map;
|
|---|
| 3697 | /* A buffer large enough to hold output symbols of any input BFD. */
|
|---|
| 3698 | struct external_nlist *output_syms;
|
|---|
| 3699 | };
|
|---|
| 3700 |
|
|---|
| 3701 | static struct bfd_hash_entry *aout_link_includes_newfunc
|
|---|
| 3702 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
|
|---|
| 3703 | static bfd_boolean aout_link_input_bfd
|
|---|
| 3704 | PARAMS ((struct aout_final_link_info *, bfd *input_bfd));
|
|---|
| 3705 | static bfd_boolean aout_link_write_symbols
|
|---|
| 3706 | PARAMS ((struct aout_final_link_info *, bfd *input_bfd));
|
|---|
| 3707 | static bfd_boolean aout_link_write_other_symbol
|
|---|
| 3708 | PARAMS ((struct aout_link_hash_entry *, PTR));
|
|---|
| 3709 | static bfd_boolean aout_link_input_section
|
|---|
| 3710 | PARAMS ((struct aout_final_link_info *, bfd *input_bfd,
|
|---|
| 3711 | asection *input_section, file_ptr *reloff_ptr,
|
|---|
| 3712 | bfd_size_type rel_size));
|
|---|
| 3713 | static bfd_boolean aout_link_input_section_std
|
|---|
| 3714 | PARAMS ((struct aout_final_link_info *, bfd *input_bfd,
|
|---|
| 3715 | asection *input_section, struct reloc_std_external *,
|
|---|
| 3716 | bfd_size_type rel_size, bfd_byte *contents));
|
|---|
| 3717 | static bfd_boolean aout_link_input_section_ext
|
|---|
| 3718 | PARAMS ((struct aout_final_link_info *, bfd *input_bfd,
|
|---|
| 3719 | asection *input_section, struct reloc_ext_external *,
|
|---|
| 3720 | bfd_size_type rel_size, bfd_byte *contents));
|
|---|
| 3721 | static INLINE asection *aout_reloc_index_to_section
|
|---|
| 3722 | PARAMS ((bfd *, int));
|
|---|
| 3723 | static bfd_boolean aout_link_reloc_link_order
|
|---|
| 3724 | PARAMS ((struct aout_final_link_info *, asection *,
|
|---|
| 3725 | struct bfd_link_order *));
|
|---|
| 3726 |
|
|---|
| 3727 | /* The function to create a new entry in the header file hash table. */
|
|---|
| 3728 |
|
|---|
| 3729 | static struct bfd_hash_entry *
|
|---|
| 3730 | aout_link_includes_newfunc (entry, table, string)
|
|---|
| 3731 | struct bfd_hash_entry *entry;
|
|---|
| 3732 | struct bfd_hash_table *table;
|
|---|
| 3733 | const char *string;
|
|---|
| 3734 | {
|
|---|
| 3735 | struct aout_link_includes_entry *ret =
|
|---|
| 3736 | (struct aout_link_includes_entry *) entry;
|
|---|
| 3737 |
|
|---|
| 3738 | /* Allocate the structure if it has not already been allocated by a
|
|---|
| 3739 | subclass. */
|
|---|
| 3740 | if (ret == (struct aout_link_includes_entry *) NULL)
|
|---|
| 3741 | ret = ((struct aout_link_includes_entry *)
|
|---|
| 3742 | bfd_hash_allocate (table,
|
|---|
| 3743 | sizeof (struct aout_link_includes_entry)));
|
|---|
| 3744 | if (ret == (struct aout_link_includes_entry *) NULL)
|
|---|
| 3745 | return (struct bfd_hash_entry *) ret;
|
|---|
| 3746 |
|
|---|
| 3747 | /* Call the allocation method of the superclass. */
|
|---|
| 3748 | ret = ((struct aout_link_includes_entry *)
|
|---|
| 3749 | bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
|
|---|
| 3750 | if (ret)
|
|---|
| 3751 | {
|
|---|
| 3752 | /* Set local fields. */
|
|---|
| 3753 | ret->totals = NULL;
|
|---|
| 3754 | }
|
|---|
| 3755 |
|
|---|
| 3756 | return (struct bfd_hash_entry *) ret;
|
|---|
| 3757 | }
|
|---|
| 3758 |
|
|---|
| 3759 | /* Do the final link step. This is called on the output BFD. The
|
|---|
| 3760 | INFO structure should point to a list of BFDs linked through the
|
|---|
| 3761 | link_next field which can be used to find each BFD which takes part
|
|---|
| 3762 | in the output. Also, each section in ABFD should point to a list
|
|---|
| 3763 | of bfd_link_order structures which list all the input sections for
|
|---|
| 3764 | the output section. */
|
|---|
| 3765 |
|
|---|
| 3766 | bfd_boolean
|
|---|
| 3767 | NAME(aout,final_link) (abfd, info, callback)
|
|---|
| 3768 | bfd *abfd;
|
|---|
| 3769 | struct bfd_link_info *info;
|
|---|
| 3770 | void (*callback) PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));
|
|---|
| 3771 | {
|
|---|
| 3772 | struct aout_final_link_info aout_info;
|
|---|
| 3773 | bfd_boolean includes_hash_initialized = FALSE;
|
|---|
| 3774 | register bfd *sub;
|
|---|
| 3775 | bfd_size_type trsize, drsize;
|
|---|
| 3776 | bfd_size_type max_contents_size;
|
|---|
| 3777 | bfd_size_type max_relocs_size;
|
|---|
| 3778 | bfd_size_type max_sym_count;
|
|---|
| 3779 | bfd_size_type text_size;
|
|---|
| 3780 | file_ptr text_end;
|
|---|
| 3781 | register struct bfd_link_order *p;
|
|---|
| 3782 | asection *o;
|
|---|
| 3783 | bfd_boolean have_link_order_relocs;
|
|---|
| 3784 |
|
|---|
| 3785 | if (info->shared)
|
|---|
| 3786 | abfd->flags |= DYNAMIC;
|
|---|
| 3787 |
|
|---|
| 3788 | aout_info.info = info;
|
|---|
| 3789 | aout_info.output_bfd = abfd;
|
|---|
| 3790 | aout_info.contents = NULL;
|
|---|
| 3791 | aout_info.relocs = NULL;
|
|---|
| 3792 | aout_info.symbol_map = NULL;
|
|---|
| 3793 | aout_info.output_syms = NULL;
|
|---|
| 3794 |
|
|---|
| 3795 | if (! bfd_hash_table_init_n (&aout_info.includes.root,
|
|---|
| 3796 | aout_link_includes_newfunc,
|
|---|
| 3797 | 251))
|
|---|
| 3798 | goto error_return;
|
|---|
| 3799 | includes_hash_initialized = TRUE;
|
|---|
| 3800 |
|
|---|
| 3801 | /* Figure out the largest section size. Also, if generating
|
|---|
| 3802 | relocateable output, count the relocs. */
|
|---|
| 3803 | trsize = 0;
|
|---|
| 3804 | drsize = 0;
|
|---|
| 3805 | max_contents_size = 0;
|
|---|
| 3806 | max_relocs_size = 0;
|
|---|
| 3807 | max_sym_count = 0;
|
|---|
| 3808 | for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
|
|---|
| 3809 | {
|
|---|
| 3810 | bfd_size_type sz;
|
|---|
| 3811 |
|
|---|
| 3812 | if (info->relocateable)
|
|---|
| 3813 | {
|
|---|
| 3814 | if (bfd_get_flavour (sub) == bfd_target_aout_flavour)
|
|---|
| 3815 | {
|
|---|
| 3816 | trsize += exec_hdr (sub)->a_trsize;
|
|---|
| 3817 | drsize += exec_hdr (sub)->a_drsize;
|
|---|
| 3818 | }
|
|---|
| 3819 | else
|
|---|
| 3820 | {
|
|---|
| 3821 | /* FIXME: We need to identify the .text and .data sections
|
|---|
| 3822 | and call get_reloc_upper_bound and canonicalize_reloc to
|
|---|
| 3823 | work out the number of relocs needed, and then multiply
|
|---|
| 3824 | by the reloc size. */
|
|---|
| 3825 | (*_bfd_error_handler)
|
|---|
| 3826 | (_("%s: relocateable link from %s to %s not supported"),
|
|---|
| 3827 | bfd_get_filename (abfd),
|
|---|
| 3828 | sub->xvec->name, abfd->xvec->name);
|
|---|
| 3829 | bfd_set_error (bfd_error_invalid_operation);
|
|---|
| 3830 | goto error_return;
|
|---|
| 3831 | }
|
|---|
| 3832 | }
|
|---|
| 3833 |
|
|---|
| 3834 | if (bfd_get_flavour (sub) == bfd_target_aout_flavour)
|
|---|
| 3835 | {
|
|---|
| 3836 | sz = bfd_section_size (sub, obj_textsec (sub));
|
|---|
| 3837 | if (sz > max_contents_size)
|
|---|
| 3838 | max_contents_size = sz;
|
|---|
| 3839 | sz = bfd_section_size (sub, obj_datasec (sub));
|
|---|
| 3840 | if (sz > max_contents_size)
|
|---|
| 3841 | max_contents_size = sz;
|
|---|
| 3842 |
|
|---|
| 3843 | sz = exec_hdr (sub)->a_trsize;
|
|---|
| 3844 | if (sz > max_relocs_size)
|
|---|
| 3845 | max_relocs_size = sz;
|
|---|
| 3846 | sz = exec_hdr (sub)->a_drsize;
|
|---|
| 3847 | if (sz > max_relocs_size)
|
|---|
| 3848 | max_relocs_size = sz;
|
|---|
| 3849 |
|
|---|
| 3850 | sz = obj_aout_external_sym_count (sub);
|
|---|
| 3851 | if (sz > max_sym_count)
|
|---|
| 3852 | max_sym_count = sz;
|
|---|
| 3853 | }
|
|---|
| 3854 | }
|
|---|
| 3855 |
|
|---|
| 3856 | if (info->relocateable)
|
|---|
| 3857 | {
|
|---|
| 3858 | if (obj_textsec (abfd) != (asection *) NULL)
|
|---|
| 3859 | trsize += (_bfd_count_link_order_relocs (obj_textsec (abfd)
|
|---|
| 3860 | ->link_order_head)
|
|---|
| 3861 | * obj_reloc_entry_size (abfd));
|
|---|
| 3862 | if (obj_datasec (abfd) != (asection *) NULL)
|
|---|
| 3863 | drsize += (_bfd_count_link_order_relocs (obj_datasec (abfd)
|
|---|
| 3864 | ->link_order_head)
|
|---|
| 3865 | * obj_reloc_entry_size (abfd));
|
|---|
| 3866 | }
|
|---|
| 3867 |
|
|---|
| 3868 | exec_hdr (abfd)->a_trsize = trsize;
|
|---|
| 3869 | exec_hdr (abfd)->a_drsize = drsize;
|
|---|
| 3870 |
|
|---|
| 3871 | exec_hdr (abfd)->a_entry = bfd_get_start_address (abfd);
|
|---|
| 3872 |
|
|---|
| 3873 | /* Adjust the section sizes and vmas according to the magic number.
|
|---|
| 3874 | This sets a_text, a_data and a_bss in the exec_hdr and sets the
|
|---|
| 3875 | filepos for each section. */
|
|---|
| 3876 | if (! NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end))
|
|---|
| 3877 | goto error_return;
|
|---|
| 3878 |
|
|---|
| 3879 | /* The relocation and symbol file positions differ among a.out
|
|---|
| 3880 | targets. We are passed a callback routine from the backend
|
|---|
| 3881 | specific code to handle this.
|
|---|
| 3882 | FIXME: At this point we do not know how much space the symbol
|
|---|
| 3883 | table will require. This will not work for any (nonstandard)
|
|---|
| 3884 | a.out target that needs to know the symbol table size before it
|
|---|
| 3885 | can compute the relocation file positions. This may or may not
|
|---|
| 3886 | be the case for the hp300hpux target, for example. */
|
|---|
| 3887 | (*callback) (abfd, &aout_info.treloff, &aout_info.dreloff,
|
|---|
| 3888 | &aout_info.symoff);
|
|---|
| 3889 | obj_textsec (abfd)->rel_filepos = aout_info.treloff;
|
|---|
| 3890 | obj_datasec (abfd)->rel_filepos = aout_info.dreloff;
|
|---|
| 3891 | obj_sym_filepos (abfd) = aout_info.symoff;
|
|---|
| 3892 |
|
|---|
| 3893 | /* We keep a count of the symbols as we output them. */
|
|---|
| 3894 | obj_aout_external_sym_count (abfd) = 0;
|
|---|
| 3895 |
|
|---|
| 3896 | /* We accumulate the string table as we write out the symbols. */
|
|---|
| 3897 | aout_info.strtab = _bfd_stringtab_init ();
|
|---|
| 3898 | if (aout_info.strtab == NULL)
|
|---|
| 3899 | goto error_return;
|
|---|
| 3900 |
|
|---|
| 3901 | /* Allocate buffers to hold section contents and relocs. */
|
|---|
| 3902 | aout_info.contents = (bfd_byte *) bfd_malloc (max_contents_size);
|
|---|
| 3903 | aout_info.relocs = (PTR) bfd_malloc (max_relocs_size);
|
|---|
| 3904 | aout_info.symbol_map = (int *) bfd_malloc (max_sym_count * sizeof (int *));
|
|---|
| 3905 | aout_info.output_syms = ((struct external_nlist *)
|
|---|
| 3906 | bfd_malloc ((max_sym_count + 1)
|
|---|
| 3907 | * sizeof (struct external_nlist)));
|
|---|
| 3908 | if ((aout_info.contents == NULL && max_contents_size != 0)
|
|---|
| 3909 | || (aout_info.relocs == NULL && max_relocs_size != 0)
|
|---|
| 3910 | || (aout_info.symbol_map == NULL && max_sym_count != 0)
|
|---|
| 3911 | || aout_info.output_syms == NULL)
|
|---|
| 3912 | goto error_return;
|
|---|
| 3913 |
|
|---|
| 3914 | /* If we have a symbol named __DYNAMIC, force it out now. This is
|
|---|
| 3915 | required by SunOS. Doing this here rather than in sunos.c is a
|
|---|
| 3916 | hack, but it's easier than exporting everything which would be
|
|---|
| 3917 | needed. */
|
|---|
| 3918 | {
|
|---|
| 3919 | struct aout_link_hash_entry *h;
|
|---|
| 3920 |
|
|---|
| 3921 | h = aout_link_hash_lookup (aout_hash_table (info), "__DYNAMIC",
|
|---|
| 3922 | FALSE, FALSE, FALSE);
|
|---|
| 3923 | if (h != NULL)
|
|---|
| 3924 | aout_link_write_other_symbol (h, &aout_info);
|
|---|
| 3925 | }
|
|---|
| 3926 |
|
|---|
| 3927 | /* The most time efficient way to do the link would be to read all
|
|---|
| 3928 | the input object files into memory and then sort out the
|
|---|
| 3929 | information into the output file. Unfortunately, that will
|
|---|
| 3930 | probably use too much memory. Another method would be to step
|
|---|
| 3931 | through everything that composes the text section and write it
|
|---|
| 3932 | out, and then everything that composes the data section and write
|
|---|
| 3933 | it out, and then write out the relocs, and then write out the
|
|---|
| 3934 | symbols. Unfortunately, that requires reading stuff from each
|
|---|
| 3935 | input file several times, and we will not be able to keep all the
|
|---|
| 3936 | input files open simultaneously, and reopening them will be slow.
|
|---|
| 3937 |
|
|---|
| 3938 | What we do is basically process one input file at a time. We do
|
|---|
| 3939 | everything we need to do with an input file once--copy over the
|
|---|
| 3940 | section contents, handle the relocation information, and write
|
|---|
| 3941 | out the symbols--and then we throw away the information we read
|
|---|
| 3942 | from it. This approach requires a lot of lseeks of the output
|
|---|
| 3943 | file, which is unfortunate but still faster than reopening a lot
|
|---|
| 3944 | of files.
|
|---|
| 3945 |
|
|---|
| 3946 | We use the output_has_begun field of the input BFDs to see
|
|---|
| 3947 | whether we have already handled it. */
|
|---|
| 3948 | for (sub = info->input_bfds; sub != (bfd *) NULL; sub = sub->link_next)
|
|---|
| 3949 | sub->output_has_begun = FALSE;
|
|---|
| 3950 |
|
|---|
| 3951 | /* Mark all sections which are to be included in the link. This
|
|---|
| 3952 | will normally be every section. We need to do this so that we
|
|---|
| 3953 | can identify any sections which the linker has decided to not
|
|---|
| 3954 | include. */
|
|---|
| 3955 | for (o = abfd->sections; o != NULL; o = o->next)
|
|---|
| 3956 | {
|
|---|
| 3957 | for (p = o->link_order_head; p != NULL; p = p->next)
|
|---|
| 3958 | if (p->type == bfd_indirect_link_order)
|
|---|
| 3959 | p->u.indirect.section->linker_mark = TRUE;
|
|---|
| 3960 | }
|
|---|
| 3961 |
|
|---|
| 3962 | have_link_order_relocs = FALSE;
|
|---|
| 3963 | for (o = abfd->sections; o != (asection *) NULL; o = o->next)
|
|---|
| 3964 | {
|
|---|
| 3965 | for (p = o->link_order_head;
|
|---|
| 3966 | p != (struct bfd_link_order *) NULL;
|
|---|
| 3967 | p = p->next)
|
|---|
| 3968 | {
|
|---|
| 3969 | if (p->type == bfd_indirect_link_order
|
|---|
| 3970 | && (bfd_get_flavour (p->u.indirect.section->owner)
|
|---|
| 3971 | == bfd_target_aout_flavour))
|
|---|
| 3972 | {
|
|---|
| 3973 | bfd *input_bfd;
|
|---|
| 3974 |
|
|---|
| 3975 | input_bfd = p->u.indirect.section->owner;
|
|---|
| 3976 | if (! input_bfd->output_has_begun)
|
|---|
| 3977 | {
|
|---|
| 3978 | if (! aout_link_input_bfd (&aout_info, input_bfd))
|
|---|
| 3979 | goto error_return;
|
|---|
| 3980 | input_bfd->output_has_begun = TRUE;
|
|---|
| 3981 | }
|
|---|
| 3982 | }
|
|---|
| 3983 | else if (p->type == bfd_section_reloc_link_order
|
|---|
| 3984 | || p->type == bfd_symbol_reloc_link_order)
|
|---|
| 3985 | {
|
|---|
| 3986 | /* These are handled below. */
|
|---|
| 3987 | have_link_order_relocs = TRUE;
|
|---|
| 3988 | }
|
|---|
| 3989 | else
|
|---|
| 3990 | {
|
|---|
| 3991 | if (! _bfd_default_link_order (abfd, info, o, p))
|
|---|
| 3992 | goto error_return;
|
|---|
| 3993 | }
|
|---|
| 3994 | }
|
|---|
| 3995 | }
|
|---|
| 3996 |
|
|---|
| 3997 | /* Write out any symbols that we have not already written out. */
|
|---|
| 3998 | aout_link_hash_traverse (aout_hash_table (info),
|
|---|
| 3999 | aout_link_write_other_symbol,
|
|---|
| 4000 | (PTR) &aout_info);
|
|---|
| 4001 |
|
|---|
| 4002 | /* Now handle any relocs we were asked to create by the linker.
|
|---|
| 4003 | These did not come from any input file. We must do these after
|
|---|
| 4004 | we have written out all the symbols, so that we know the symbol
|
|---|
| 4005 | indices to use. */
|
|---|
| 4006 | if (have_link_order_relocs)
|
|---|
| 4007 | {
|
|---|
| 4008 | for (o = abfd->sections; o != (asection *) NULL; o = o->next)
|
|---|
| 4009 | {
|
|---|
| 4010 | for (p = o->link_order_head;
|
|---|
| 4011 | p != (struct bfd_link_order *) NULL;
|
|---|
| 4012 | p = p->next)
|
|---|
| 4013 | {
|
|---|
| 4014 | if (p->type == bfd_section_reloc_link_order
|
|---|
| 4015 | || p->type == bfd_symbol_reloc_link_order)
|
|---|
| 4016 | {
|
|---|
| 4017 | if (! aout_link_reloc_link_order (&aout_info, o, p))
|
|---|
| 4018 | goto error_return;
|
|---|
| 4019 | }
|
|---|
| 4020 | }
|
|---|
| 4021 | }
|
|---|
| 4022 | }
|
|---|
| 4023 |
|
|---|
| 4024 | if (aout_info.contents != NULL)
|
|---|
| 4025 | {
|
|---|
| 4026 | free (aout_info.contents);
|
|---|
| 4027 | aout_info.contents = NULL;
|
|---|
| 4028 | }
|
|---|
| 4029 | if (aout_info.relocs != NULL)
|
|---|
| 4030 | {
|
|---|
| 4031 | free (aout_info.relocs);
|
|---|
| 4032 | aout_info.relocs = NULL;
|
|---|
| 4033 | }
|
|---|
| 4034 | if (aout_info.symbol_map != NULL)
|
|---|
| 4035 | {
|
|---|
| 4036 | free (aout_info.symbol_map);
|
|---|
| 4037 | aout_info.symbol_map = NULL;
|
|---|
| 4038 | }
|
|---|
| 4039 | if (aout_info.output_syms != NULL)
|
|---|
| 4040 | {
|
|---|
| 4041 | free (aout_info.output_syms);
|
|---|
| 4042 | aout_info.output_syms = NULL;
|
|---|
| 4043 | }
|
|---|
| 4044 | if (includes_hash_initialized)
|
|---|
| 4045 | {
|
|---|
| 4046 | bfd_hash_table_free (&aout_info.includes.root);
|
|---|
| 4047 | includes_hash_initialized = FALSE;
|
|---|
| 4048 | }
|
|---|
| 4049 |
|
|---|
| 4050 | /* Finish up any dynamic linking we may be doing. */
|
|---|
| 4051 | if (aout_backend_info (abfd)->finish_dynamic_link != NULL)
|
|---|
| 4052 | {
|
|---|
| 4053 | if (! (*aout_backend_info (abfd)->finish_dynamic_link) (abfd, info))
|
|---|
| 4054 | goto error_return;
|
|---|
| 4055 | }
|
|---|
| 4056 |
|
|---|
| 4057 | /* Update the header information. */
|
|---|
| 4058 | abfd->symcount = obj_aout_external_sym_count (abfd);
|
|---|
| 4059 | exec_hdr (abfd)->a_syms = abfd->symcount * EXTERNAL_NLIST_SIZE;
|
|---|
| 4060 | obj_str_filepos (abfd) = obj_sym_filepos (abfd) + exec_hdr (abfd)->a_syms;
|
|---|
| 4061 | obj_textsec (abfd)->reloc_count =
|
|---|
| 4062 | exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd);
|
|---|
| 4063 | obj_datasec (abfd)->reloc_count =
|
|---|
| 4064 | exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd);
|
|---|
| 4065 |
|
|---|
| 4066 | /* Write out the string table, unless there are no symbols. */
|
|---|
| 4067 | if (abfd->symcount > 0)
|
|---|
| 4068 | {
|
|---|
| 4069 | if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0
|
|---|
| 4070 | || ! emit_stringtab (abfd, aout_info.strtab))
|
|---|
| 4071 | goto error_return;
|
|---|
| 4072 | }
|
|---|
| 4073 | else if (obj_textsec (abfd)->reloc_count == 0
|
|---|
| 4074 | && obj_datasec (abfd)->reloc_count == 0)
|
|---|
| 4075 | {
|
|---|
| 4076 | bfd_byte b;
|
|---|
| 4077 | file_ptr pos;
|
|---|
| 4078 |
|
|---|
| 4079 | b = 0;
|
|---|
| 4080 | pos = obj_datasec (abfd)->filepos + exec_hdr (abfd)->a_data - 1;
|
|---|
| 4081 | if (bfd_seek (abfd, pos, SEEK_SET) != 0
|
|---|
| 4082 | || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
|
|---|
| 4083 | goto error_return;
|
|---|
| 4084 | }
|
|---|
| 4085 |
|
|---|
| 4086 | return TRUE;
|
|---|
| 4087 |
|
|---|
| 4088 | error_return:
|
|---|
| 4089 | if (aout_info.contents != NULL)
|
|---|
| 4090 | free (aout_info.contents);
|
|---|
| 4091 | if (aout_info.relocs != NULL)
|
|---|
| 4092 | free (aout_info.relocs);
|
|---|
| 4093 | if (aout_info.symbol_map != NULL)
|
|---|
| 4094 | free (aout_info.symbol_map);
|
|---|
| 4095 | if (aout_info.output_syms != NULL)
|
|---|
| 4096 | free (aout_info.output_syms);
|
|---|
| 4097 | if (includes_hash_initialized)
|
|---|
| 4098 | bfd_hash_table_free (&aout_info.includes.root);
|
|---|
| 4099 | return FALSE;
|
|---|
| 4100 | }
|
|---|
| 4101 |
|
|---|
| 4102 | /* Link an a.out input BFD into the output file. */
|
|---|
| 4103 |
|
|---|
| 4104 | static bfd_boolean
|
|---|
| 4105 | aout_link_input_bfd (finfo, input_bfd)
|
|---|
| 4106 | struct aout_final_link_info *finfo;
|
|---|
| 4107 | bfd *input_bfd;
|
|---|
| 4108 | {
|
|---|
| 4109 | bfd_size_type sym_count;
|
|---|
| 4110 |
|
|---|
| 4111 | BFD_ASSERT (bfd_get_format (input_bfd) == bfd_object);
|
|---|
| 4112 |
|
|---|
| 4113 | /* If this is a dynamic object, it may need special handling. */
|
|---|
| 4114 | if ((input_bfd->flags & DYNAMIC) != 0
|
|---|
| 4115 | && aout_backend_info (input_bfd)->link_dynamic_object != NULL)
|
|---|
| 4116 | {
|
|---|
| 4117 | return ((*aout_backend_info (input_bfd)->link_dynamic_object)
|
|---|
| 4118 | (finfo->info, input_bfd));
|
|---|
| 4119 | }
|
|---|
| 4120 |
|
|---|
| 4121 | /* Get the symbols. We probably have them already, unless
|
|---|
| 4122 | finfo->info->keep_memory is FALSE. */
|
|---|
| 4123 | if (! aout_get_external_symbols (input_bfd))
|
|---|
| 4124 | return FALSE;
|
|---|
| 4125 |
|
|---|
| 4126 | sym_count = obj_aout_external_sym_count (input_bfd);
|
|---|
| 4127 |
|
|---|
| 4128 | /* Write out the symbols and get a map of the new indices. The map
|
|---|
| 4129 | is placed into finfo->symbol_map. */
|
|---|
| 4130 | if (! aout_link_write_symbols (finfo, input_bfd))
|
|---|
| 4131 | return FALSE;
|
|---|
| 4132 |
|
|---|
| 4133 | /* Relocate and write out the sections. These functions use the
|
|---|
| 4134 | symbol map created by aout_link_write_symbols. The linker_mark
|
|---|
| 4135 | field will be set if these sections are to be included in the
|
|---|
| 4136 | link, which will normally be the case. */
|
|---|
| 4137 | if (obj_textsec (input_bfd)->linker_mark)
|
|---|
| 4138 | {
|
|---|
| 4139 | if (! aout_link_input_section (finfo, input_bfd,
|
|---|
| 4140 | obj_textsec (input_bfd),
|
|---|
| 4141 | &finfo->treloff,
|
|---|
| 4142 | exec_hdr (input_bfd)->a_trsize))
|
|---|
| 4143 | return FALSE;
|
|---|
| 4144 | }
|
|---|
| 4145 | if (obj_datasec (input_bfd)->linker_mark)
|
|---|
| 4146 | {
|
|---|
| 4147 | if (! aout_link_input_section (finfo, input_bfd,
|
|---|
| 4148 | obj_datasec (input_bfd),
|
|---|
| 4149 | &finfo->dreloff,
|
|---|
| 4150 | exec_hdr (input_bfd)->a_drsize))
|
|---|
| 4151 | return FALSE;
|
|---|
| 4152 | }
|
|---|
| 4153 |
|
|---|
| 4154 | /* If we are not keeping memory, we don't need the symbols any
|
|---|
| 4155 | longer. We still need them if we are keeping memory, because the
|
|---|
| 4156 | strings in the hash table point into them. */
|
|---|
| 4157 | if (! finfo->info->keep_memory)
|
|---|
| 4158 | {
|
|---|
| 4159 | if (! aout_link_free_symbols (input_bfd))
|
|---|
| 4160 | return FALSE;
|
|---|
| 4161 | }
|
|---|
| 4162 |
|
|---|
| 4163 | return TRUE;
|
|---|
| 4164 | }
|
|---|
| 4165 |
|
|---|
| 4166 | /* Adjust and write out the symbols for an a.out file. Set the new
|
|---|
| 4167 | symbol indices into a symbol_map. */
|
|---|
| 4168 |
|
|---|
| 4169 | static bfd_boolean
|
|---|
| 4170 | aout_link_write_symbols (finfo, input_bfd)
|
|---|
| 4171 | struct aout_final_link_info *finfo;
|
|---|
| 4172 | bfd *input_bfd;
|
|---|
| 4173 | {
|
|---|
| 4174 | bfd *output_bfd;
|
|---|
| 4175 | bfd_size_type sym_count;
|
|---|
| 4176 | char *strings;
|
|---|
| 4177 | enum bfd_link_strip strip;
|
|---|
| 4178 | enum bfd_link_discard discard;
|
|---|
| 4179 | struct external_nlist *outsym;
|
|---|
| 4180 | bfd_size_type strtab_index;
|
|---|
| 4181 | register struct external_nlist *sym;
|
|---|
| 4182 | struct external_nlist *sym_end;
|
|---|
| 4183 | struct aout_link_hash_entry **sym_hash;
|
|---|
| 4184 | int *symbol_map;
|
|---|
| 4185 | bfd_boolean pass;
|
|---|
| 4186 | bfd_boolean skip_next;
|
|---|
| 4187 |
|
|---|
| 4188 | output_bfd = finfo->output_bfd;
|
|---|
| 4189 | sym_count = obj_aout_external_sym_count (input_bfd);
|
|---|
| 4190 | strings = obj_aout_external_strings (input_bfd);
|
|---|
| 4191 | strip = finfo->info->strip;
|
|---|
| 4192 | discard = finfo->info->discard;
|
|---|
| 4193 | outsym = finfo->output_syms;
|
|---|
| 4194 |
|
|---|
| 4195 | /* First write out a symbol for this object file, unless we are
|
|---|
| 4196 | discarding such symbols. */
|
|---|
| 4197 | if (strip != strip_all
|
|---|
| 4198 | && (strip != strip_some
|
|---|
| 4199 | || bfd_hash_lookup (finfo->info->keep_hash, input_bfd->filename,
|
|---|
| 4200 | FALSE, FALSE) != NULL)
|
|---|
| 4201 | && discard != discard_all)
|
|---|
| 4202 | {
|
|---|
| 4203 | H_PUT_8 (output_bfd, N_TEXT, outsym->e_type);
|
|---|
| 4204 | H_PUT_8 (output_bfd, 0, outsym->e_other);
|
|---|
| 4205 | H_PUT_16 (output_bfd, 0, outsym->e_desc);
|
|---|
| 4206 | strtab_index = add_to_stringtab (output_bfd, finfo->strtab,
|
|---|
| 4207 | input_bfd->filename, FALSE);
|
|---|
| 4208 | if (strtab_index == (bfd_size_type) -1)
|
|---|
| 4209 | return FALSE;
|
|---|
| 4210 | PUT_WORD (output_bfd, strtab_index, outsym->e_strx);
|
|---|
| 4211 | PUT_WORD (output_bfd,
|
|---|
| 4212 | (bfd_get_section_vma (output_bfd,
|
|---|
| 4213 | obj_textsec (input_bfd)->output_section)
|
|---|
| 4214 | + obj_textsec (input_bfd)->output_offset),
|
|---|
| 4215 | outsym->e_value);
|
|---|
| 4216 | ++obj_aout_external_sym_count (output_bfd);
|
|---|
| 4217 | ++outsym;
|
|---|
| 4218 | }
|
|---|
| 4219 |
|
|---|
| 4220 | pass = FALSE;
|
|---|
| 4221 | skip_next = FALSE;
|
|---|
| 4222 | sym = obj_aout_external_syms (input_bfd);
|
|---|
| 4223 | sym_end = sym + sym_count;
|
|---|
| 4224 | sym_hash = obj_aout_sym_hashes (input_bfd);
|
|---|
| 4225 | symbol_map = finfo->symbol_map;
|
|---|
| 4226 | memset (symbol_map, 0, (size_t) sym_count * sizeof *symbol_map);
|
|---|
| 4227 | for (; sym < sym_end; sym++, sym_hash++, symbol_map++)
|
|---|
| 4228 | {
|
|---|
| 4229 | const char *name;
|
|---|
| 4230 | int type;
|
|---|
| 4231 | struct aout_link_hash_entry *h;
|
|---|
| 4232 | bfd_boolean skip;
|
|---|
| 4233 | asection *symsec;
|
|---|
| 4234 | bfd_vma val = 0;
|
|---|
| 4235 | bfd_boolean copy;
|
|---|
| 4236 |
|
|---|
| 4237 | /* We set *symbol_map to 0 above for all symbols. If it has
|
|---|
| 4238 | already been set to -1 for this symbol, it means that we are
|
|---|
| 4239 | discarding it because it appears in a duplicate header file.
|
|---|
| 4240 | See the N_BINCL code below. */
|
|---|
| 4241 | if (*symbol_map == -1)
|
|---|
| 4242 | continue;
|
|---|
| 4243 |
|
|---|
| 4244 | /* Initialize *symbol_map to -1, which means that the symbol was
|
|---|
| 4245 | not copied into the output file. We will change it later if
|
|---|
| 4246 | we do copy the symbol over. */
|
|---|
| 4247 | *symbol_map = -1;
|
|---|
| 4248 |
|
|---|
| 4249 | type = H_GET_8 (input_bfd, sym->e_type);
|
|---|
| 4250 | name = strings + GET_WORD (input_bfd, sym->e_strx);
|
|---|
| 4251 |
|
|---|
| 4252 | h = NULL;
|
|---|
| 4253 |
|
|---|
| 4254 | if (pass)
|
|---|
| 4255 | {
|
|---|
| 4256 | /* Pass this symbol through. It is the target of an
|
|---|
| 4257 | indirect or warning symbol. */
|
|---|
| 4258 | val = GET_WORD (input_bfd, sym->e_value);
|
|---|
| 4259 | pass = FALSE;
|
|---|
| 4260 | }
|
|---|
| 4261 | else if (skip_next)
|
|---|
| 4262 | {
|
|---|
| 4263 | /* Skip this symbol, which is the target of an indirect
|
|---|
| 4264 | symbol that we have changed to no longer be an indirect
|
|---|
| 4265 | symbol. */
|
|---|
| 4266 | skip_next = FALSE;
|
|---|
| 4267 | continue;
|
|---|
| 4268 | }
|
|---|
| 4269 | else
|
|---|
| 4270 | {
|
|---|
| 4271 | struct aout_link_hash_entry *hresolve;
|
|---|
| 4272 |
|
|---|
| 4273 | /* We have saved the hash table entry for this symbol, if
|
|---|
| 4274 | there is one. Note that we could just look it up again
|
|---|
| 4275 | in the hash table, provided we first check that it is an
|
|---|
| 4276 | external symbol. */
|
|---|
| 4277 | h = *sym_hash;
|
|---|
| 4278 |
|
|---|
| 4279 | /* Use the name from the hash table, in case the symbol was
|
|---|
| 4280 | wrapped. */
|
|---|
| 4281 | if (h != NULL
|
|---|
| 4282 | && h->root.type != bfd_link_hash_warning)
|
|---|
| 4283 | name = h->root.root.string;
|
|---|
| 4284 |
|
|---|
| 4285 | /* If this is an indirect or warning symbol, then change
|
|---|
| 4286 | hresolve to the base symbol. We also change *sym_hash so
|
|---|
| 4287 | that the relocation routines relocate against the real
|
|---|
| 4288 | symbol. */
|
|---|
| 4289 | hresolve = h;
|
|---|
| 4290 | if (h != (struct aout_link_hash_entry *) NULL
|
|---|
| 4291 | && (h->root.type == bfd_link_hash_indirect
|
|---|
| 4292 | || h->root.type == bfd_link_hash_warning))
|
|---|
| 4293 | {
|
|---|
| 4294 | hresolve = (struct aout_link_hash_entry *) h->root.u.i.link;
|
|---|
| 4295 | while (hresolve->root.type == bfd_link_hash_indirect
|
|---|
| 4296 | || hresolve->root.type == bfd_link_hash_warning)
|
|---|
| 4297 | hresolve = ((struct aout_link_hash_entry *)
|
|---|
| 4298 | hresolve->root.u.i.link);
|
|---|
| 4299 | *sym_hash = hresolve;
|
|---|
| 4300 | }
|
|---|
| 4301 |
|
|---|
| 4302 | /* If the symbol has already been written out, skip it. */
|
|---|
| 4303 | if (h != (struct aout_link_hash_entry *) NULL
|
|---|
| 4304 | && h->written)
|
|---|
| 4305 | {
|
|---|
| 4306 | if ((type & N_TYPE) == N_INDR
|
|---|
| 4307 | || type == N_WARNING)
|
|---|
| 4308 | skip_next = TRUE;
|
|---|
| 4309 | *symbol_map = h->indx;
|
|---|
| 4310 | continue;
|
|---|
| 4311 | }
|
|---|
| 4312 |
|
|---|
| 4313 | /* See if we are stripping this symbol. */
|
|---|
| 4314 | skip = FALSE;
|
|---|
| 4315 | switch (strip)
|
|---|
| 4316 | {
|
|---|
| 4317 | case strip_none:
|
|---|
| 4318 | break;
|
|---|
| 4319 | case strip_debugger:
|
|---|
| 4320 | if (IS_STAB(type))
|
|---|
| 4321 | skip = TRUE;
|
|---|
| 4322 | break;
|
|---|
| 4323 | case strip_some:
|
|---|
| 4324 | if (bfd_hash_lookup (finfo->info->keep_hash, name, FALSE, FALSE)
|
|---|
| 4325 | == NULL)
|
|---|
| 4326 | skip = TRUE;
|
|---|
| 4327 | break;
|
|---|
| 4328 | case strip_all:
|
|---|
| 4329 | skip = TRUE;
|
|---|
| 4330 | break;
|
|---|
| 4331 | }
|
|---|
| 4332 | if (skip)
|
|---|
| 4333 | {
|
|---|
| 4334 | if (h != (struct aout_link_hash_entry *) NULL)
|
|---|
| 4335 | h->written = TRUE;
|
|---|
| 4336 | continue;
|
|---|
| 4337 | }
|
|---|
| 4338 |
|
|---|
| 4339 | /* Get the value of the symbol. */
|
|---|
| 4340 | if ((type & N_TYPE) == N_TEXT
|
|---|
| 4341 | || type == N_WEAKT)
|
|---|
| 4342 | symsec = obj_textsec (input_bfd);
|
|---|
| 4343 | else if ((type & N_TYPE) == N_DATA
|
|---|
| 4344 | || type == N_WEAKD)
|
|---|
| 4345 | symsec = obj_datasec (input_bfd);
|
|---|
| 4346 | else if ((type & N_TYPE) == N_BSS
|
|---|
| 4347 | || type == N_WEAKB)
|
|---|
| 4348 | symsec = obj_bsssec (input_bfd);
|
|---|
| 4349 | else if ((type & N_TYPE) == N_ABS
|
|---|
| 4350 | || type == N_WEAKA)
|
|---|
| 4351 | symsec = bfd_abs_section_ptr;
|
|---|
| 4352 | else if (((type & N_TYPE) == N_INDR
|
|---|
| 4353 | && (hresolve == (struct aout_link_hash_entry *) NULL
|
|---|
| 4354 | || (hresolve->root.type != bfd_link_hash_defined
|
|---|
| 4355 | && hresolve->root.type != bfd_link_hash_defweak
|
|---|
| 4356 | && hresolve->root.type != bfd_link_hash_common)))
|
|---|
| 4357 | || type == N_WARNING)
|
|---|
| 4358 | {
|
|---|
| 4359 | /* Pass the next symbol through unchanged. The
|
|---|
| 4360 | condition above for indirect symbols is so that if
|
|---|
| 4361 | the indirect symbol was defined, we output it with
|
|---|
| 4362 | the correct definition so the debugger will
|
|---|
| 4363 | understand it. */
|
|---|
| 4364 | pass = TRUE;
|
|---|
| 4365 | val = GET_WORD (input_bfd, sym->e_value);
|
|---|
| 4366 | symsec = NULL;
|
|---|
| 4367 | }
|
|---|
| 4368 | #ifdef EMX
|
|---|
| 4369 | else if ((type == (N_IMP1 | N_EXT))
|
|---|
| 4370 | || (type == (N_IMP2 | N_EXT)))
|
|---|
| 4371 | symsec = bfd_abs_section_ptr;
|
|---|
| 4372 | #endif
|
|---|
| 4373 | else if (IS_STAB(type))
|
|---|
| 4374 | {
|
|---|
| 4375 | val = GET_WORD (input_bfd, sym->e_value);
|
|---|
| 4376 | symsec = NULL;
|
|---|
| 4377 | }
|
|---|
| 4378 | else
|
|---|
| 4379 | {
|
|---|
| 4380 | /* If we get here with an indirect symbol, it means that
|
|---|
| 4381 | we are outputting it with a real definition. In such
|
|---|
| 4382 | a case we do not want to output the next symbol,
|
|---|
| 4383 | which is the target of the indirection. */
|
|---|
| 4384 | if ((type & N_TYPE) == N_INDR)
|
|---|
| 4385 | skip_next = TRUE;
|
|---|
| 4386 |
|
|---|
| 4387 | symsec = NULL;
|
|---|
| 4388 |
|
|---|
| 4389 | /* We need to get the value from the hash table. We use
|
|---|
| 4390 | hresolve so that if we have defined an indirect
|
|---|
| 4391 | symbol we output the final definition. */
|
|---|
| 4392 | if (h == (struct aout_link_hash_entry *) NULL)
|
|---|
| 4393 | {
|
|---|
| 4394 | switch (type & N_TYPE)
|
|---|
| 4395 | {
|
|---|
| 4396 | case N_SETT:
|
|---|
| 4397 | symsec = obj_textsec (input_bfd);
|
|---|
| 4398 | break;
|
|---|
| 4399 | case N_SETD:
|
|---|
| 4400 | symsec = obj_datasec (input_bfd);
|
|---|
| 4401 | break;
|
|---|
| 4402 | case N_SETB:
|
|---|
| 4403 | symsec = obj_bsssec (input_bfd);
|
|---|
| 4404 | break;
|
|---|
| 4405 | case N_SETA:
|
|---|
| 4406 | symsec = bfd_abs_section_ptr;
|
|---|
| 4407 | break;
|
|---|
| 4408 | default:
|
|---|
| 4409 | val = 0;
|
|---|
| 4410 | break;
|
|---|
| 4411 | }
|
|---|
| 4412 | }
|
|---|
| 4413 | else if (hresolve->root.type == bfd_link_hash_defined
|
|---|
| 4414 | || hresolve->root.type == bfd_link_hash_defweak)
|
|---|
| 4415 | {
|
|---|
| 4416 | asection *input_section;
|
|---|
| 4417 | asection *output_section;
|
|---|
| 4418 |
|
|---|
| 4419 | /* This case usually means a common symbol which was
|
|---|
| 4420 | turned into a defined symbol. */
|
|---|
| 4421 | input_section = hresolve->root.u.def.section;
|
|---|
| 4422 | output_section = input_section->output_section;
|
|---|
| 4423 | BFD_ASSERT (bfd_is_abs_section (output_section)
|
|---|
| 4424 | || output_section->owner == output_bfd);
|
|---|
| 4425 | val = (hresolve->root.u.def.value
|
|---|
| 4426 | + bfd_get_section_vma (output_bfd, output_section)
|
|---|
| 4427 | + input_section->output_offset);
|
|---|
| 4428 |
|
|---|
| 4429 | /* Get the correct type based on the section. If
|
|---|
| 4430 | this is a constructed set, force it to be
|
|---|
| 4431 | globally visible. */
|
|---|
| 4432 | if (type == N_SETT
|
|---|
| 4433 | || type == N_SETD
|
|---|
| 4434 | || type == N_SETB
|
|---|
| 4435 | || type == N_SETA)
|
|---|
| 4436 | type |= N_EXT;
|
|---|
| 4437 |
|
|---|
| 4438 | type &=~ N_TYPE;
|
|---|
| 4439 |
|
|---|
| 4440 | if (output_section == obj_textsec (output_bfd))
|
|---|
| 4441 | type |= (hresolve->root.type == bfd_link_hash_defined
|
|---|
| 4442 | ? N_TEXT
|
|---|
| 4443 | : N_WEAKT);
|
|---|
| 4444 | else if (output_section == obj_datasec (output_bfd))
|
|---|
| 4445 | type |= (hresolve->root.type == bfd_link_hash_defined
|
|---|
| 4446 | ? N_DATA
|
|---|
| 4447 | : N_WEAKD);
|
|---|
| 4448 | else if (output_section == obj_bsssec (output_bfd))
|
|---|
| 4449 | type |= (hresolve->root.type == bfd_link_hash_defined
|
|---|
| 4450 | ? N_BSS
|
|---|
| 4451 | : N_WEAKB);
|
|---|
| 4452 | else
|
|---|
| 4453 | type |= (hresolve->root.type == bfd_link_hash_defined
|
|---|
| 4454 | ? N_ABS
|
|---|
| 4455 | : N_WEAKA);
|
|---|
| 4456 | }
|
|---|
| 4457 | else if (hresolve->root.type == bfd_link_hash_common)
|
|---|
| 4458 | val = hresolve->root.u.c.size;
|
|---|
| 4459 | else if (hresolve->root.type == bfd_link_hash_undefweak)
|
|---|
| 4460 | {
|
|---|
| 4461 | val = 0;
|
|---|
| 4462 | type = N_WEAKU;
|
|---|
| 4463 | }
|
|---|
| 4464 | else
|
|---|
| 4465 | val = 0;
|
|---|
| 4466 | }
|
|---|
| 4467 | if (symsec != (asection *) NULL)
|
|---|
| 4468 | val = (symsec->output_section->vma
|
|---|
| 4469 | + symsec->output_offset
|
|---|
| 4470 | + (GET_WORD (input_bfd, sym->e_value)
|
|---|
| 4471 | - symsec->vma));
|
|---|
| 4472 |
|
|---|
| 4473 | /* If this is a global symbol set the written flag, and if
|
|---|
| 4474 | it is a local symbol see if we should discard it. */
|
|---|
| 4475 | if (h != (struct aout_link_hash_entry *) NULL)
|
|---|
| 4476 | {
|
|---|
| 4477 | h->written = TRUE;
|
|---|
| 4478 | h->indx = obj_aout_external_sym_count (output_bfd);
|
|---|
| 4479 | }
|
|---|
| 4480 | else if ((type & N_TYPE) != N_SETT
|
|---|
| 4481 | && (type & N_TYPE) != N_SETD
|
|---|
| 4482 | && (type & N_TYPE) != N_SETB
|
|---|
| 4483 | && (type & N_TYPE) != N_SETA)
|
|---|
| 4484 | {
|
|---|
| 4485 | switch (discard)
|
|---|
| 4486 | {
|
|---|
| 4487 | case discard_none:
|
|---|
| 4488 | case discard_sec_merge:
|
|---|
| 4489 | break;
|
|---|
| 4490 | case discard_l:
|
|---|
| 4491 | if (!IS_STAB(type)
|
|---|
| 4492 | && bfd_is_local_label_name (input_bfd, name))
|
|---|
| 4493 | skip = TRUE;
|
|---|
| 4494 | break;
|
|---|
| 4495 | case discard_all:
|
|---|
| 4496 | skip = TRUE;
|
|---|
| 4497 | break;
|
|---|
| 4498 | }
|
|---|
| 4499 | if (skip)
|
|---|
| 4500 | {
|
|---|
| 4501 | pass = FALSE;
|
|---|
| 4502 | continue;
|
|---|
| 4503 | }
|
|---|
| 4504 | }
|
|---|
| 4505 |
|
|---|
| 4506 | /* An N_BINCL symbol indicates the start of the stabs
|
|---|
| 4507 | entries for a header file. We need to scan ahead to the
|
|---|
| 4508 | next N_EINCL symbol, ignoring nesting, adding up all the
|
|---|
| 4509 | characters in the symbol names, not including the file
|
|---|
| 4510 | numbers in types (the first number after an open
|
|---|
| 4511 | parenthesis). */
|
|---|
| 4512 | if (type == (int) N_BINCL)
|
|---|
| 4513 | {
|
|---|
| 4514 | struct external_nlist *incl_sym;
|
|---|
| 4515 | int nest;
|
|---|
| 4516 | struct aout_link_includes_entry *incl_entry;
|
|---|
| 4517 | struct aout_link_includes_totals *t;
|
|---|
| 4518 |
|
|---|
| 4519 | val = 0;
|
|---|
| 4520 | nest = 0;
|
|---|
| 4521 | for (incl_sym = sym + 1; incl_sym < sym_end; incl_sym++)
|
|---|
| 4522 | {
|
|---|
| 4523 | int incl_type;
|
|---|
| 4524 |
|
|---|
| 4525 | incl_type = H_GET_8 (input_bfd, incl_sym->e_type);
|
|---|
| 4526 | if (incl_type == (int) N_EINCL)
|
|---|
| 4527 | {
|
|---|
| 4528 | if (nest == 0)
|
|---|
| 4529 | break;
|
|---|
| 4530 | --nest;
|
|---|
| 4531 | }
|
|---|
| 4532 | else if (incl_type == (int) N_BINCL)
|
|---|
| 4533 | ++nest;
|
|---|
| 4534 | else if (nest == 0)
|
|---|
| 4535 | {
|
|---|
| 4536 | const char *s;
|
|---|
| 4537 |
|
|---|
| 4538 | s = strings + GET_WORD (input_bfd, incl_sym->e_strx);
|
|---|
| 4539 | for (; *s != '\0'; s++)
|
|---|
| 4540 | {
|
|---|
| 4541 | val += *s;
|
|---|
| 4542 | if (*s == '(')
|
|---|
| 4543 | {
|
|---|
| 4544 | /* Skip the file number. */
|
|---|
| 4545 | ++s;
|
|---|
| 4546 | while (ISDIGIT (*s))
|
|---|
| 4547 | ++s;
|
|---|
| 4548 | --s;
|
|---|
| 4549 | }
|
|---|
| 4550 | }
|
|---|
| 4551 | }
|
|---|
| 4552 | }
|
|---|
| 4553 |
|
|---|
| 4554 | /* If we have already included a header file with the
|
|---|
| 4555 | same value, then replace this one with an N_EXCL
|
|---|
| 4556 | symbol. */
|
|---|
| 4557 | copy = (bfd_boolean) (! finfo->info->keep_memory);
|
|---|
| 4558 | incl_entry = aout_link_includes_lookup (&finfo->includes,
|
|---|
| 4559 | name, TRUE, copy);
|
|---|
| 4560 | if (incl_entry == NULL)
|
|---|
| 4561 | return FALSE;
|
|---|
| 4562 | for (t = incl_entry->totals; t != NULL; t = t->next)
|
|---|
| 4563 | if (t->total == val)
|
|---|
| 4564 | break;
|
|---|
| 4565 | if (t == NULL)
|
|---|
| 4566 | {
|
|---|
| 4567 | /* This is the first time we have seen this header
|
|---|
| 4568 | file with this set of stabs strings. */
|
|---|
| 4569 | t = ((struct aout_link_includes_totals *)
|
|---|
| 4570 | bfd_hash_allocate (&finfo->includes.root,
|
|---|
| 4571 | sizeof *t));
|
|---|
| 4572 | if (t == NULL)
|
|---|
| 4573 | return FALSE;
|
|---|
| 4574 | t->total = val;
|
|---|
| 4575 | t->next = incl_entry->totals;
|
|---|
| 4576 | incl_entry->totals = t;
|
|---|
| 4577 | }
|
|---|
| 4578 | else
|
|---|
| 4579 | {
|
|---|
| 4580 | int *incl_map;
|
|---|
| 4581 |
|
|---|
| 4582 | /* This is a duplicate header file. We must change
|
|---|
| 4583 | it to be an N_EXCL entry, and mark all the
|
|---|
| 4584 | included symbols to prevent outputting them. */
|
|---|
| 4585 | type = (int) N_EXCL;
|
|---|
| 4586 |
|
|---|
| 4587 | nest = 0;
|
|---|
| 4588 | for (incl_sym = sym + 1, incl_map = symbol_map + 1;
|
|---|
| 4589 | incl_sym < sym_end;
|
|---|
| 4590 | incl_sym++, incl_map++)
|
|---|
| 4591 | {
|
|---|
| 4592 | int incl_type;
|
|---|
| 4593 |
|
|---|
| 4594 | incl_type = H_GET_8 (input_bfd, incl_sym->e_type);
|
|---|
| 4595 | if (incl_type == (int) N_EINCL)
|
|---|
| 4596 | {
|
|---|
| 4597 | if (nest == 0)
|
|---|
| 4598 | {
|
|---|
| 4599 | *incl_map = -1;
|
|---|
| 4600 | break;
|
|---|
| 4601 | }
|
|---|
| 4602 | --nest;
|
|---|
| 4603 | }
|
|---|
| 4604 | else if (incl_type == (int) N_BINCL)
|
|---|
| 4605 | ++nest;
|
|---|
| 4606 | else if (nest == 0)
|
|---|
| 4607 | *incl_map = -1;
|
|---|
| 4608 | }
|
|---|
| 4609 | }
|
|---|
| 4610 | }
|
|---|
| 4611 | }
|
|---|
| 4612 |
|
|---|
| 4613 | /* Copy this symbol into the list of symbols we are going to
|
|---|
| 4614 | write out. */
|
|---|
| 4615 | H_PUT_8 (output_bfd, type, outsym->e_type);
|
|---|
| 4616 | H_PUT_8 (output_bfd, H_GET_8 (input_bfd, sym->e_other), outsym->e_other);
|
|---|
| 4617 | H_PUT_16 (output_bfd, H_GET_16 (input_bfd, sym->e_desc), outsym->e_desc);
|
|---|
| 4618 | copy = FALSE;
|
|---|
| 4619 | if (! finfo->info->keep_memory)
|
|---|
| 4620 | {
|
|---|
| 4621 | /* name points into a string table which we are going to
|
|---|
| 4622 | free. If there is a hash table entry, use that string.
|
|---|
| 4623 | Otherwise, copy name into memory. */
|
|---|
| 4624 | if (h != (struct aout_link_hash_entry *) NULL)
|
|---|
| 4625 | name = h->root.root.string;
|
|---|
| 4626 | else
|
|---|
| 4627 | copy = TRUE;
|
|---|
| 4628 | }
|
|---|
| 4629 | strtab_index = add_to_stringtab (output_bfd, finfo->strtab,
|
|---|
| 4630 | name, copy);
|
|---|
| 4631 | if (strtab_index == (bfd_size_type) -1)
|
|---|
| 4632 | return FALSE;
|
|---|
| 4633 | PUT_WORD (output_bfd, strtab_index, outsym->e_strx);
|
|---|
| 4634 | PUT_WORD (output_bfd, val, outsym->e_value);
|
|---|
| 4635 | *symbol_map = obj_aout_external_sym_count (output_bfd);
|
|---|
| 4636 | ++obj_aout_external_sym_count (output_bfd);
|
|---|
| 4637 | ++outsym;
|
|---|
| 4638 | }
|
|---|
| 4639 |
|
|---|
| 4640 | /* Write out the output symbols we have just constructed. */
|
|---|
| 4641 | if (outsym > finfo->output_syms)
|
|---|
| 4642 | {
|
|---|
| 4643 | bfd_size_type outsym_size;
|
|---|
| 4644 |
|
|---|
| 4645 | if (bfd_seek (output_bfd, finfo->symoff, SEEK_SET) != 0)
|
|---|
| 4646 | return FALSE;
|
|---|
| 4647 | outsym_size = outsym - finfo->output_syms;
|
|---|
| 4648 | outsym_size *= EXTERNAL_NLIST_SIZE;
|
|---|
| 4649 | if (bfd_bwrite ((PTR) finfo->output_syms, outsym_size, output_bfd)
|
|---|
| 4650 | != outsym_size)
|
|---|
| 4651 | return FALSE;
|
|---|
| 4652 | finfo->symoff += outsym_size;
|
|---|
| 4653 | }
|
|---|
| 4654 |
|
|---|
| 4655 | return TRUE;
|
|---|
| 4656 | }
|
|---|
| 4657 |
|
|---|
| 4658 | /* Write out a symbol that was not associated with an a.out input
|
|---|
| 4659 | object. */
|
|---|
| 4660 |
|
|---|
| 4661 | static bfd_boolean
|
|---|
| 4662 | aout_link_write_other_symbol (h, data)
|
|---|
| 4663 | struct aout_link_hash_entry *h;
|
|---|
| 4664 | PTR data;
|
|---|
| 4665 | {
|
|---|
| 4666 | struct aout_final_link_info *finfo = (struct aout_final_link_info *) data;
|
|---|
| 4667 | bfd *output_bfd;
|
|---|
| 4668 | int type;
|
|---|
| 4669 | bfd_vma val;
|
|---|
| 4670 | struct external_nlist outsym;
|
|---|
| 4671 | bfd_size_type indx;
|
|---|
| 4672 | bfd_size_type amt;
|
|---|
| 4673 |
|
|---|
| 4674 | if (h->root.type == bfd_link_hash_warning)
|
|---|
| 4675 | {
|
|---|
| 4676 | h = (struct aout_link_hash_entry *) h->root.u.i.link;
|
|---|
| 4677 | if (h->root.type == bfd_link_hash_new)
|
|---|
| 4678 | return TRUE;
|
|---|
| 4679 | }
|
|---|
| 4680 |
|
|---|
| 4681 | output_bfd = finfo->output_bfd;
|
|---|
| 4682 |
|
|---|
| 4683 | if (aout_backend_info (output_bfd)->write_dynamic_symbol != NULL)
|
|---|
| 4684 | {
|
|---|
| 4685 | if (! ((*aout_backend_info (output_bfd)->write_dynamic_symbol)
|
|---|
| 4686 | (output_bfd, finfo->info, h)))
|
|---|
| 4687 | {
|
|---|
| 4688 | /* FIXME: No way to handle errors. */
|
|---|
| 4689 | abort ();
|
|---|
| 4690 | }
|
|---|
| 4691 | }
|
|---|
| 4692 |
|
|---|
| 4693 | if (h->written)
|
|---|
| 4694 | return TRUE;
|
|---|
| 4695 |
|
|---|
| 4696 | h->written = TRUE;
|
|---|
| 4697 |
|
|---|
| 4698 | /* An indx of -2 means the symbol must be written. */
|
|---|
| 4699 | if (h->indx != -2
|
|---|
| 4700 | && (finfo->info->strip == strip_all
|
|---|
| 4701 | || (finfo->info->strip == strip_some
|
|---|
| 4702 | && bfd_hash_lookup (finfo->info->keep_hash, h->root.root.string,
|
|---|
| 4703 | FALSE, FALSE) == NULL)))
|
|---|
| 4704 | return TRUE;
|
|---|
| 4705 |
|
|---|
| 4706 | switch (h->root.type)
|
|---|
| 4707 | {
|
|---|
| 4708 | default:
|
|---|
| 4709 | case bfd_link_hash_warning:
|
|---|
| 4710 | abort ();
|
|---|
| 4711 | /* Avoid variable not initialized warnings. */
|
|---|
| 4712 | return TRUE;
|
|---|
| 4713 | case bfd_link_hash_new:
|
|---|
| 4714 | /* This can happen for set symbols when sets are not being
|
|---|
| 4715 | built. */
|
|---|
| 4716 | return TRUE;
|
|---|
| 4717 | case bfd_link_hash_undefined:
|
|---|
| 4718 | type = N_UNDF | N_EXT;
|
|---|
| 4719 | val = 0;
|
|---|
| 4720 | break;
|
|---|
| 4721 | case bfd_link_hash_defined:
|
|---|
| 4722 | case bfd_link_hash_defweak:
|
|---|
| 4723 | {
|
|---|
| 4724 | asection *sec;
|
|---|
| 4725 |
|
|---|
| 4726 | sec = h->root.u.def.section->output_section;
|
|---|
| 4727 | BFD_ASSERT (bfd_is_abs_section (sec)
|
|---|
| 4728 | || sec->owner == output_bfd);
|
|---|
| 4729 | if (sec == obj_textsec (output_bfd))
|
|---|
| 4730 | type = h->root.type == bfd_link_hash_defined ? N_TEXT : N_WEAKT;
|
|---|
| 4731 | else if (sec == obj_datasec (output_bfd))
|
|---|
| 4732 | type = h->root.type == bfd_link_hash_defined ? N_DATA : N_WEAKD;
|
|---|
| 4733 | else if (sec == obj_bsssec (output_bfd))
|
|---|
| 4734 | type = h->root.type == bfd_link_hash_defined ? N_BSS : N_WEAKB;
|
|---|
| 4735 | else
|
|---|
| 4736 | type = h->root.type == bfd_link_hash_defined ? N_ABS : N_WEAKA;
|
|---|
| 4737 | type |= N_EXT;
|
|---|
| 4738 | val = (h->root.u.def.value
|
|---|
| 4739 | + sec->vma
|
|---|
| 4740 | + h->root.u.def.section->output_offset);
|
|---|
| 4741 | }
|
|---|
| 4742 | break;
|
|---|
| 4743 | case bfd_link_hash_common:
|
|---|
| 4744 | type = N_UNDF | N_EXT;
|
|---|
| 4745 | val = h->root.u.c.size;
|
|---|
| 4746 | break;
|
|---|
| 4747 | case bfd_link_hash_undefweak:
|
|---|
| 4748 | type = N_WEAKU;
|
|---|
| 4749 | val = 0;
|
|---|
| 4750 | case bfd_link_hash_indirect:
|
|---|
| 4751 | /* We ignore these symbols, since the indirected symbol is
|
|---|
| 4752 | already in the hash table. */
|
|---|
| 4753 | return TRUE;
|
|---|
| 4754 | }
|
|---|
| 4755 |
|
|---|
| 4756 | H_PUT_8 (output_bfd, type, outsym.e_type);
|
|---|
| 4757 | H_PUT_8 (output_bfd, 0, outsym.e_other);
|
|---|
| 4758 | H_PUT_16 (output_bfd, 0, outsym.e_desc);
|
|---|
| 4759 | indx = add_to_stringtab (output_bfd, finfo->strtab, h->root.root.string,
|
|---|
| 4760 | FALSE);
|
|---|
| 4761 | if (indx == - (bfd_size_type) 1)
|
|---|
| 4762 | {
|
|---|
| 4763 | /* FIXME: No way to handle errors. */
|
|---|
| 4764 | abort ();
|
|---|
| 4765 | }
|
|---|
| 4766 | PUT_WORD (output_bfd, indx, outsym.e_strx);
|
|---|
| 4767 | PUT_WORD (output_bfd, val, outsym.e_value);
|
|---|
| 4768 |
|
|---|
| 4769 | amt = EXTERNAL_NLIST_SIZE;
|
|---|
| 4770 | if (bfd_seek (output_bfd, finfo->symoff, SEEK_SET) != 0
|
|---|
| 4771 | || bfd_bwrite ((PTR) &outsym, amt, output_bfd) != amt)
|
|---|
| 4772 | {
|
|---|
| 4773 | /* FIXME: No way to handle errors. */
|
|---|
| 4774 | abort ();
|
|---|
| 4775 | }
|
|---|
| 4776 |
|
|---|
| 4777 | finfo->symoff += EXTERNAL_NLIST_SIZE;
|
|---|
| 4778 | h->indx = obj_aout_external_sym_count (output_bfd);
|
|---|
| 4779 | ++obj_aout_external_sym_count (output_bfd);
|
|---|
| 4780 |
|
|---|
| 4781 | return TRUE;
|
|---|
| 4782 | }
|
|---|
| 4783 |
|
|---|
| 4784 | /* Link an a.out section into the output file. */
|
|---|
| 4785 |
|
|---|
| 4786 | static bfd_boolean
|
|---|
| 4787 | aout_link_input_section (finfo, input_bfd, input_section, reloff_ptr,
|
|---|
| 4788 | rel_size)
|
|---|
| 4789 | struct aout_final_link_info *finfo;
|
|---|
| 4790 | bfd *input_bfd;
|
|---|
| 4791 | asection *input_section;
|
|---|
| 4792 | file_ptr *reloff_ptr;
|
|---|
| 4793 | bfd_size_type rel_size;
|
|---|
| 4794 | {
|
|---|
| 4795 | bfd_size_type input_size;
|
|---|
| 4796 | PTR relocs;
|
|---|
| 4797 |
|
|---|
| 4798 | /* Get the section contents. */
|
|---|
| 4799 | input_size = bfd_section_size (input_bfd, input_section);
|
|---|
| 4800 | if (! bfd_get_section_contents (input_bfd, input_section,
|
|---|
| 4801 | (PTR) finfo->contents,
|
|---|
| 4802 | (file_ptr) 0, input_size))
|
|---|
| 4803 | return FALSE;
|
|---|
| 4804 |
|
|---|
| 4805 | /* Read in the relocs if we haven't already done it. */
|
|---|
| 4806 | if (aout_section_data (input_section) != NULL
|
|---|
| 4807 | && aout_section_data (input_section)->relocs != NULL)
|
|---|
| 4808 | relocs = aout_section_data (input_section)->relocs;
|
|---|
| 4809 | else
|
|---|
| 4810 | {
|
|---|
| 4811 | relocs = finfo->relocs;
|
|---|
| 4812 | if (rel_size > 0)
|
|---|
| 4813 | {
|
|---|
| 4814 | if (bfd_seek (input_bfd, input_section->rel_filepos, SEEK_SET) != 0
|
|---|
| 4815 | || bfd_bread (relocs, rel_size, input_bfd) != rel_size)
|
|---|
| 4816 | return FALSE;
|
|---|
| 4817 | }
|
|---|
| 4818 | }
|
|---|
| 4819 |
|
|---|
| 4820 | /* Relocate the section contents. */
|
|---|
| 4821 | if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
|
|---|
| 4822 | {
|
|---|
| 4823 | if (! aout_link_input_section_std (finfo, input_bfd, input_section,
|
|---|
| 4824 | (struct reloc_std_external *) relocs,
|
|---|
| 4825 | rel_size, finfo->contents))
|
|---|
| 4826 | return FALSE;
|
|---|
| 4827 | }
|
|---|
| 4828 | else
|
|---|
| 4829 | {
|
|---|
| 4830 | if (! aout_link_input_section_ext (finfo, input_bfd, input_section,
|
|---|
| 4831 | (struct reloc_ext_external *) relocs,
|
|---|
| 4832 | rel_size, finfo->contents))
|
|---|
| 4833 | return FALSE;
|
|---|
| 4834 | }
|
|---|
| 4835 |
|
|---|
| 4836 | /* Write out the section contents. */
|
|---|
| 4837 | if (! bfd_set_section_contents (finfo->output_bfd,
|
|---|
| 4838 | input_section->output_section,
|
|---|
| 4839 | (PTR) finfo->contents,
|
|---|
| 4840 | (file_ptr) input_section->output_offset,
|
|---|
| 4841 | input_size))
|
|---|
| 4842 | return FALSE;
|
|---|
| 4843 |
|
|---|
| 4844 | /* If we are producing relocateable output, the relocs were
|
|---|
| 4845 | modified, and we now write them out. */
|
|---|
| 4846 | if (finfo->info->relocateable && rel_size > 0)
|
|---|
| 4847 | {
|
|---|
| 4848 | if (bfd_seek (finfo->output_bfd, *reloff_ptr, SEEK_SET) != 0)
|
|---|
| 4849 | return FALSE;
|
|---|
| 4850 | if (bfd_bwrite (relocs, rel_size, finfo->output_bfd) != rel_size)
|
|---|
| 4851 | return FALSE;
|
|---|
| 4852 | *reloff_ptr += rel_size;
|
|---|
| 4853 |
|
|---|
| 4854 | /* Assert that the relocs have not run into the symbols, and
|
|---|
| 4855 | that if these are the text relocs they have not run into the
|
|---|
| 4856 | data relocs. */
|
|---|
| 4857 | BFD_ASSERT (*reloff_ptr <= obj_sym_filepos (finfo->output_bfd)
|
|---|
| 4858 | && (reloff_ptr != &finfo->treloff
|
|---|
| 4859 | || (*reloff_ptr
|
|---|
| 4860 | <= obj_datasec (finfo->output_bfd)->rel_filepos)));
|
|---|
| 4861 | }
|
|---|
| 4862 |
|
|---|
| 4863 | return TRUE;
|
|---|
| 4864 | }
|
|---|
| 4865 |
|
|---|
| 4866 | /* Get the section corresponding to a reloc index. */
|
|---|
| 4867 |
|
|---|
| 4868 | static INLINE asection *
|
|---|
| 4869 | aout_reloc_index_to_section (abfd, indx)
|
|---|
| 4870 | bfd *abfd;
|
|---|
| 4871 | int indx;
|
|---|
| 4872 | {
|
|---|
| 4873 | switch (indx & N_TYPE)
|
|---|
| 4874 | {
|
|---|
| 4875 | case N_TEXT:
|
|---|
| 4876 | return obj_textsec (abfd);
|
|---|
| 4877 | case N_DATA:
|
|---|
| 4878 | return obj_datasec (abfd);
|
|---|
| 4879 | case N_BSS:
|
|---|
| 4880 | return obj_bsssec (abfd);
|
|---|
| 4881 | case N_ABS:
|
|---|
| 4882 | case N_UNDF:
|
|---|
| 4883 | return bfd_abs_section_ptr;
|
|---|
| 4884 | default:
|
|---|
| 4885 | abort ();
|
|---|
| 4886 | }
|
|---|
| 4887 | /*NOTREACHED*/
|
|---|
| 4888 | return NULL;
|
|---|
| 4889 | }
|
|---|
| 4890 |
|
|---|
| 4891 | /* Relocate an a.out section using standard a.out relocs. */
|
|---|
| 4892 |
|
|---|
| 4893 | static bfd_boolean
|
|---|
| 4894 | aout_link_input_section_std (finfo, input_bfd, input_section, relocs,
|
|---|
| 4895 | rel_size, contents)
|
|---|
| 4896 | struct aout_final_link_info *finfo;
|
|---|
| 4897 | bfd *input_bfd;
|
|---|
| 4898 | asection *input_section;
|
|---|
| 4899 | struct reloc_std_external *relocs;
|
|---|
| 4900 | bfd_size_type rel_size;
|
|---|
| 4901 | bfd_byte *contents;
|
|---|
| 4902 | {
|
|---|
| 4903 | bfd_boolean (*check_dynamic_reloc)
|
|---|
| 4904 | PARAMS ((struct bfd_link_info *, bfd *, asection *,
|
|---|
| 4905 | struct aout_link_hash_entry *, PTR, bfd_byte *, bfd_boolean *,
|
|---|
| 4906 | bfd_vma *));
|
|---|
| 4907 | bfd *output_bfd;
|
|---|
| 4908 | bfd_boolean relocateable;
|
|---|
| 4909 | struct external_nlist *syms;
|
|---|
| 4910 | char *strings;
|
|---|
| 4911 | struct aout_link_hash_entry **sym_hashes;
|
|---|
| 4912 | int *symbol_map;
|
|---|
| 4913 | bfd_size_type reloc_count;
|
|---|
| 4914 | register struct reloc_std_external *rel;
|
|---|
| 4915 | struct reloc_std_external *rel_end;
|
|---|
| 4916 |
|
|---|
| 4917 | output_bfd = finfo->output_bfd;
|
|---|
| 4918 | check_dynamic_reloc = aout_backend_info (output_bfd)->check_dynamic_reloc;
|
|---|
| 4919 |
|
|---|
| 4920 | BFD_ASSERT (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE);
|
|---|
| 4921 | BFD_ASSERT (input_bfd->xvec->header_byteorder
|
|---|
| 4922 | == output_bfd->xvec->header_byteorder);
|
|---|
| 4923 |
|
|---|
| 4924 | relocateable = finfo->info->relocateable;
|
|---|
| 4925 | syms = obj_aout_external_syms (input_bfd);
|
|---|
| 4926 | strings = obj_aout_external_strings (input_bfd);
|
|---|
| 4927 | sym_hashes = obj_aout_sym_hashes (input_bfd);
|
|---|
| 4928 | symbol_map = finfo->symbol_map;
|
|---|
| 4929 |
|
|---|
| 4930 | reloc_count = rel_size / RELOC_STD_SIZE;
|
|---|
| 4931 | rel = relocs;
|
|---|
| 4932 | rel_end = rel + reloc_count;
|
|---|
| 4933 | for (; rel < rel_end; rel++)
|
|---|
| 4934 | {
|
|---|
| 4935 | bfd_vma r_addr;
|
|---|
| 4936 | int r_index;
|
|---|
| 4937 | int r_extern;
|
|---|
| 4938 | int r_pcrel;
|
|---|
| 4939 | int r_baserel = 0;
|
|---|
| 4940 | reloc_howto_type *howto;
|
|---|
| 4941 | struct aout_link_hash_entry *h = NULL;
|
|---|
| 4942 | bfd_vma relocation;
|
|---|
| 4943 | bfd_reloc_status_type r;
|
|---|
| 4944 |
|
|---|
| 4945 | r_addr = GET_SWORD (input_bfd, rel->r_address);
|
|---|
| 4946 |
|
|---|
| 4947 | #ifdef MY_reloc_howto
|
|---|
| 4948 | howto = MY_reloc_howto (input_bfd, rel, r_index, r_extern, r_pcrel);
|
|---|
| 4949 | #else
|
|---|
| 4950 | {
|
|---|
| 4951 | int r_jmptable;
|
|---|
| 4952 | int r_relative;
|
|---|
| 4953 | int r_length;
|
|---|
| 4954 | unsigned int howto_idx;
|
|---|
| 4955 |
|
|---|
| 4956 | if (bfd_header_big_endian (input_bfd))
|
|---|
| 4957 | {
|
|---|
| 4958 | r_index = (((unsigned int) rel->r_index[0] << 16)
|
|---|
| 4959 | | ((unsigned int) rel->r_index[1] << 8)
|
|---|
| 4960 | | rel->r_index[2]);
|
|---|
| 4961 | r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
|
|---|
| 4962 | r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
|
|---|
| 4963 | r_baserel = (0 != (rel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
|
|---|
| 4964 | r_jmptable= (0 != (rel->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
|
|---|
| 4965 | r_relative= (0 != (rel->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG));
|
|---|
| 4966 | r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_BIG)
|
|---|
| 4967 | >> RELOC_STD_BITS_LENGTH_SH_BIG);
|
|---|
| 4968 | }
|
|---|
| 4969 | else
|
|---|
| 4970 | {
|
|---|
| 4971 | r_index = (((unsigned int) rel->r_index[2] << 16)
|
|---|
| 4972 | | ((unsigned int) rel->r_index[1] << 8)
|
|---|
| 4973 | | rel->r_index[0]);
|
|---|
| 4974 | r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
|
|---|
| 4975 | r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
|
|---|
| 4976 | r_baserel = (0 != (rel->r_type[0]
|
|---|
| 4977 | & RELOC_STD_BITS_BASEREL_LITTLE));
|
|---|
| 4978 | r_jmptable= (0 != (rel->r_type[0]
|
|---|
| 4979 | & RELOC_STD_BITS_JMPTABLE_LITTLE));
|
|---|
| 4980 | r_relative= (0 != (rel->r_type[0]
|
|---|
| 4981 | & RELOC_STD_BITS_RELATIVE_LITTLE));
|
|---|
| 4982 | r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE)
|
|---|
| 4983 | >> RELOC_STD_BITS_LENGTH_SH_LITTLE);
|
|---|
| 4984 | }
|
|---|
| 4985 |
|
|---|
| 4986 | howto_idx = (r_length + 4 * r_pcrel + 8 * r_baserel
|
|---|
| 4987 | + 16 * r_jmptable + 32 * r_relative);
|
|---|
| 4988 | BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std));
|
|---|
| 4989 | howto = howto_table_std + howto_idx;
|
|---|
| 4990 | }
|
|---|
| 4991 | #endif
|
|---|
| 4992 |
|
|---|
| 4993 | if (relocateable)
|
|---|
| 4994 | {
|
|---|
| 4995 | /* We are generating a relocateable output file, and must
|
|---|
| 4996 | modify the reloc accordingly. */
|
|---|
| 4997 | if (r_extern)
|
|---|
| 4998 | {
|
|---|
| 4999 | /* If we know the symbol this relocation is against,
|
|---|
| 5000 | convert it into a relocation against a section. This
|
|---|
| 5001 | is what the native linker does. */
|
|---|
| 5002 | h = sym_hashes[r_index];
|
|---|
| 5003 | if (h != (struct aout_link_hash_entry *) NULL
|
|---|
| 5004 | #ifdef EMX
|
|---|
| 5005 | /* Don't touch imported symbols */
|
|---|
| 5006 | && (!bfd_is_abs_section (h->root.u.def.section)
|
|---|
| 5007 | || (h->root.u.def.value != (unsigned)-1))
|
|---|
| 5008 | #endif
|
|---|
| 5009 | && (h->root.type == bfd_link_hash_defined
|
|---|
| 5010 | || h->root.type == bfd_link_hash_defweak))
|
|---|
| 5011 | {
|
|---|
| 5012 | asection *output_section;
|
|---|
| 5013 |
|
|---|
| 5014 | /* Change the r_extern value. */
|
|---|
| 5015 | if (bfd_header_big_endian (output_bfd))
|
|---|
| 5016 | rel->r_type[0] &=~ RELOC_STD_BITS_EXTERN_BIG;
|
|---|
| 5017 | else
|
|---|
| 5018 | rel->r_type[0] &=~ RELOC_STD_BITS_EXTERN_LITTLE;
|
|---|
| 5019 |
|
|---|
| 5020 | /* Compute a new r_index. */
|
|---|
| 5021 | output_section = h->root.u.def.section->output_section;
|
|---|
| 5022 | if (output_section == obj_textsec (output_bfd))
|
|---|
| 5023 | r_index = N_TEXT;
|
|---|
| 5024 | else if (output_section == obj_datasec (output_bfd))
|
|---|
| 5025 | r_index = N_DATA;
|
|---|
| 5026 | else if (output_section == obj_bsssec (output_bfd))
|
|---|
| 5027 | r_index = N_BSS;
|
|---|
| 5028 | else
|
|---|
| 5029 | r_index = N_ABS;
|
|---|
| 5030 |
|
|---|
| 5031 | /* Add the symbol value and the section VMA to the
|
|---|
| 5032 | addend stored in the contents. */
|
|---|
| 5033 | relocation = (h->root.u.def.value
|
|---|
| 5034 | + output_section->vma
|
|---|
| 5035 | + h->root.u.def.section->output_offset);
|
|---|
| 5036 | }
|
|---|
| 5037 | else
|
|---|
| 5038 | {
|
|---|
| 5039 | /* We must change r_index according to the symbol
|
|---|
| 5040 | map. */
|
|---|
| 5041 | r_index = symbol_map[r_index];
|
|---|
| 5042 |
|
|---|
| 5043 | if (r_index == -1)
|
|---|
| 5044 | {
|
|---|
| 5045 | if (h != NULL)
|
|---|
| 5046 | {
|
|---|
| 5047 | /* We decided to strip this symbol, but it
|
|---|
| 5048 | turns out that we can't. Note that we
|
|---|
| 5049 | lose the other and desc information here.
|
|---|
| 5050 | I don't think that will ever matter for a
|
|---|
| 5051 | global symbol. */
|
|---|
| 5052 | if (h->indx < 0)
|
|---|
| 5053 | {
|
|---|
| 5054 | h->indx = -2;
|
|---|
| 5055 | h->written = FALSE;
|
|---|
| 5056 | if (! aout_link_write_other_symbol (h,
|
|---|
| 5057 | (PTR) finfo))
|
|---|
| 5058 | return FALSE;
|
|---|
| 5059 | }
|
|---|
| 5060 | r_index = h->indx;
|
|---|
| 5061 | }
|
|---|
| 5062 | else
|
|---|
| 5063 | {
|
|---|
| 5064 | const char *name;
|
|---|
| 5065 |
|
|---|
| 5066 | name = strings + GET_WORD (input_bfd,
|
|---|
| 5067 | syms[r_index].e_strx);
|
|---|
| 5068 | if (! ((*finfo->info->callbacks->unattached_reloc)
|
|---|
| 5069 | (finfo->info, name, input_bfd, input_section,
|
|---|
| 5070 | r_addr)))
|
|---|
| 5071 | return FALSE;
|
|---|
| 5072 | r_index = 0;
|
|---|
| 5073 | }
|
|---|
| 5074 | }
|
|---|
| 5075 |
|
|---|
| 5076 | relocation = 0;
|
|---|
| 5077 | }
|
|---|
| 5078 |
|
|---|
| 5079 | /* Write out the new r_index value. */
|
|---|
| 5080 | if (bfd_header_big_endian (output_bfd))
|
|---|
| 5081 | {
|
|---|
| 5082 | rel->r_index[0] = r_index >> 16;
|
|---|
| 5083 | rel->r_index[1] = r_index >> 8;
|
|---|
| 5084 | rel->r_index[2] = r_index;
|
|---|
| 5085 | }
|
|---|
| 5086 | else
|
|---|
| 5087 | {
|
|---|
| 5088 | rel->r_index[2] = r_index >> 16;
|
|---|
| 5089 | rel->r_index[1] = r_index >> 8;
|
|---|
| 5090 | rel->r_index[0] = r_index;
|
|---|
| 5091 | }
|
|---|
| 5092 | }
|
|---|
| 5093 | else
|
|---|
| 5094 | {
|
|---|
| 5095 | asection *section;
|
|---|
| 5096 |
|
|---|
| 5097 | /* This is a relocation against a section. We must
|
|---|
| 5098 | adjust by the amount that the section moved. */
|
|---|
| 5099 | section = aout_reloc_index_to_section (input_bfd, r_index);
|
|---|
| 5100 | relocation = (section->output_section->vma
|
|---|
| 5101 | + section->output_offset
|
|---|
| 5102 | - section->vma);
|
|---|
| 5103 | }
|
|---|
| 5104 |
|
|---|
| 5105 | /* Change the address of the relocation. */
|
|---|
| 5106 | PUT_WORD (output_bfd,
|
|---|
| 5107 | r_addr + input_section->output_offset,
|
|---|
| 5108 | rel->r_address);
|
|---|
| 5109 |
|
|---|
| 5110 | /* Adjust a PC relative relocation by removing the reference
|
|---|
| 5111 | to the original address in the section and including the
|
|---|
| 5112 | reference to the new address. */
|
|---|
| 5113 | if (r_pcrel)
|
|---|
| 5114 | relocation -= (input_section->output_section->vma
|
|---|
| 5115 | + input_section->output_offset
|
|---|
| 5116 | - input_section->vma);
|
|---|
| 5117 |
|
|---|
| 5118 | #ifdef MY_relocatable_reloc
|
|---|
| 5119 | MY_relocatable_reloc (howto, output_bfd, rel, relocation, r_addr);
|
|---|
| 5120 | #endif
|
|---|
| 5121 |
|
|---|
| 5122 | if (relocation == 0)
|
|---|
| 5123 | r = bfd_reloc_ok;
|
|---|
| 5124 | else
|
|---|
| 5125 | r = MY_relocate_contents (howto,
|
|---|
| 5126 | input_bfd, relocation,
|
|---|
| 5127 | contents + r_addr);
|
|---|
| 5128 | }
|
|---|
| 5129 | else
|
|---|
| 5130 | {
|
|---|
| 5131 | bfd_boolean hundef;
|
|---|
| 5132 |
|
|---|
| 5133 | /* We are generating an executable, and must do a full
|
|---|
| 5134 | relocation. */
|
|---|
| 5135 | hundef = FALSE;
|
|---|
| 5136 |
|
|---|
| 5137 | if (r_extern)
|
|---|
| 5138 | {
|
|---|
| 5139 | h = sym_hashes[r_index];
|
|---|
| 5140 |
|
|---|
| 5141 | if (h != (struct aout_link_hash_entry *) NULL
|
|---|
| 5142 | && (h->root.type == bfd_link_hash_defined
|
|---|
| 5143 | || h->root.type == bfd_link_hash_defweak))
|
|---|
| 5144 | {
|
|---|
| 5145 | relocation = (h->root.u.def.value
|
|---|
| 5146 | + h->root.u.def.section->output_section->vma
|
|---|
| 5147 | + h->root.u.def.section->output_offset);
|
|---|
| 5148 | }
|
|---|
| 5149 | else if (h != (struct aout_link_hash_entry *) NULL
|
|---|
| 5150 | && h->root.type == bfd_link_hash_undefweak)
|
|---|
| 5151 | relocation = 0;
|
|---|
| 5152 | else
|
|---|
| 5153 | {
|
|---|
| 5154 | hundef = TRUE;
|
|---|
| 5155 | relocation = 0;
|
|---|
| 5156 | }
|
|---|
| 5157 | }
|
|---|
| 5158 | else
|
|---|
| 5159 | {
|
|---|
| 5160 | asection *section;
|
|---|
| 5161 |
|
|---|
| 5162 | section = aout_reloc_index_to_section (input_bfd, r_index);
|
|---|
| 5163 | relocation = (section->output_section->vma
|
|---|
| 5164 | + section->output_offset
|
|---|
| 5165 | - section->vma);
|
|---|
| 5166 | if (r_pcrel)
|
|---|
| 5167 | relocation += input_section->vma;
|
|---|
| 5168 | }
|
|---|
| 5169 |
|
|---|
| 5170 | if (check_dynamic_reloc != NULL)
|
|---|
| 5171 | {
|
|---|
| 5172 | bfd_boolean skip;
|
|---|
| 5173 |
|
|---|
| 5174 | if (! ((*check_dynamic_reloc)
|
|---|
| 5175 | (finfo->info, input_bfd, input_section, h,
|
|---|
| 5176 | (PTR) rel, contents, &skip, &relocation)))
|
|---|
| 5177 | return FALSE;
|
|---|
| 5178 | if (skip)
|
|---|
| 5179 | continue;
|
|---|
| 5180 | }
|
|---|
| 5181 |
|
|---|
| 5182 | /* Now warn if a global symbol is undefined. We could not
|
|---|
| 5183 | do this earlier, because check_dynamic_reloc might want
|
|---|
| 5184 | to skip this reloc. */
|
|---|
| 5185 | if (hundef && ! finfo->info->shared && ! r_baserel)
|
|---|
| 5186 | {
|
|---|
| 5187 | const char *name;
|
|---|
| 5188 |
|
|---|
| 5189 | if (h != NULL)
|
|---|
| 5190 | name = h->root.root.string;
|
|---|
| 5191 | else
|
|---|
| 5192 | name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
|
|---|
| 5193 | if (! ((*finfo->info->callbacks->undefined_symbol)
|
|---|
| 5194 | (finfo->info, name, input_bfd, input_section,
|
|---|
| 5195 | r_addr, TRUE)))
|
|---|
| 5196 | return FALSE;
|
|---|
| 5197 | }
|
|---|
| 5198 |
|
|---|
| 5199 | r = MY_final_link_relocate (howto,
|
|---|
| 5200 | input_bfd, input_section,
|
|---|
| 5201 | contents, r_addr, relocation,
|
|---|
| 5202 | (bfd_vma) 0);
|
|---|
| 5203 | }
|
|---|
| 5204 |
|
|---|
| 5205 | if (r != bfd_reloc_ok)
|
|---|
| 5206 | {
|
|---|
| 5207 | switch (r)
|
|---|
| 5208 | {
|
|---|
| 5209 | default:
|
|---|
| 5210 | case bfd_reloc_outofrange:
|
|---|
| 5211 | abort ();
|
|---|
| 5212 | case bfd_reloc_overflow:
|
|---|
| 5213 | {
|
|---|
| 5214 | const char *name;
|
|---|
| 5215 |
|
|---|
| 5216 | if (h != NULL)
|
|---|
| 5217 | name = h->root.root.string;
|
|---|
| 5218 | else if (r_extern)
|
|---|
| 5219 | name = strings + GET_WORD (input_bfd,
|
|---|
| 5220 | syms[r_index].e_strx);
|
|---|
| 5221 | else
|
|---|
| 5222 | {
|
|---|
| 5223 | asection *s;
|
|---|
| 5224 |
|
|---|
| 5225 | s = aout_reloc_index_to_section (input_bfd, r_index);
|
|---|
| 5226 | name = bfd_section_name (input_bfd, s);
|
|---|
| 5227 | }
|
|---|
| 5228 | if (! ((*finfo->info->callbacks->reloc_overflow)
|
|---|
| 5229 | (finfo->info, name, howto->name,
|
|---|
| 5230 | (bfd_vma) 0, input_bfd, input_section, r_addr)))
|
|---|
| 5231 | return FALSE;
|
|---|
| 5232 | }
|
|---|
| 5233 | break;
|
|---|
| 5234 | }
|
|---|
| 5235 | }
|
|---|
| 5236 | }
|
|---|
| 5237 |
|
|---|
| 5238 | return TRUE;
|
|---|
| 5239 | }
|
|---|
| 5240 |
|
|---|
| 5241 | /* Relocate an a.out section using extended a.out relocs. */
|
|---|
| 5242 |
|
|---|
| 5243 | static bfd_boolean
|
|---|
| 5244 | aout_link_input_section_ext (finfo, input_bfd, input_section, relocs,
|
|---|
| 5245 | rel_size, contents)
|
|---|
| 5246 | struct aout_final_link_info *finfo;
|
|---|
| 5247 | bfd *input_bfd;
|
|---|
| 5248 | asection *input_section;
|
|---|
| 5249 | struct reloc_ext_external *relocs;
|
|---|
| 5250 | bfd_size_type rel_size;
|
|---|
| 5251 | bfd_byte *contents;
|
|---|
| 5252 | {
|
|---|
| 5253 | bfd_boolean (*check_dynamic_reloc)
|
|---|
| 5254 | PARAMS ((struct bfd_link_info *, bfd *, asection *,
|
|---|
| 5255 | struct aout_link_hash_entry *, PTR, bfd_byte *, bfd_boolean *,
|
|---|
| 5256 | bfd_vma *));
|
|---|
| 5257 | bfd *output_bfd;
|
|---|
| 5258 | bfd_boolean relocateable;
|
|---|
| 5259 | struct external_nlist *syms;
|
|---|
| 5260 | char *strings;
|
|---|
| 5261 | struct aout_link_hash_entry **sym_hashes;
|
|---|
| 5262 | int *symbol_map;
|
|---|
| 5263 | bfd_size_type reloc_count;
|
|---|
| 5264 | register struct reloc_ext_external *rel;
|
|---|
| 5265 | struct reloc_ext_external *rel_end;
|
|---|
| 5266 |
|
|---|
| 5267 | output_bfd = finfo->output_bfd;
|
|---|
| 5268 | check_dynamic_reloc = aout_backend_info (output_bfd)->check_dynamic_reloc;
|
|---|
| 5269 |
|
|---|
| 5270 | BFD_ASSERT (obj_reloc_entry_size (input_bfd) == RELOC_EXT_SIZE);
|
|---|
| 5271 | BFD_ASSERT (input_bfd->xvec->header_byteorder
|
|---|
| 5272 | == output_bfd->xvec->header_byteorder);
|
|---|
| 5273 |
|
|---|
| 5274 | relocateable = finfo->info->relocateable;
|
|---|
| 5275 | syms = obj_aout_external_syms (input_bfd);
|
|---|
| 5276 | strings = obj_aout_external_strings (input_bfd);
|
|---|
| 5277 | sym_hashes = obj_aout_sym_hashes (input_bfd);
|
|---|
| 5278 | symbol_map = finfo->symbol_map;
|
|---|
| 5279 |
|
|---|
| 5280 | reloc_count = rel_size / RELOC_EXT_SIZE;
|
|---|
| 5281 | rel = relocs;
|
|---|
| 5282 | rel_end = rel + reloc_count;
|
|---|
| 5283 | for (; rel < rel_end; rel++)
|
|---|
| 5284 | {
|
|---|
| 5285 | bfd_vma r_addr;
|
|---|
| 5286 | int r_index;
|
|---|
| 5287 | int r_extern;
|
|---|
| 5288 | unsigned int r_type;
|
|---|
| 5289 | bfd_vma r_addend;
|
|---|
| 5290 | struct aout_link_hash_entry *h = NULL;
|
|---|
| 5291 | asection *r_section = NULL;
|
|---|
| 5292 | bfd_vma relocation;
|
|---|
| 5293 |
|
|---|
| 5294 | r_addr = GET_SWORD (input_bfd, rel->r_address);
|
|---|
| 5295 |
|
|---|
| 5296 | if (bfd_header_big_endian (input_bfd))
|
|---|
| 5297 | {
|
|---|
| 5298 | r_index = (((unsigned int) rel->r_index[0] << 16)
|
|---|
| 5299 | | ((unsigned int) rel->r_index[1] << 8)
|
|---|
| 5300 | | rel->r_index[2]);
|
|---|
| 5301 | r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
|
|---|
| 5302 | r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
|
|---|
| 5303 | >> RELOC_EXT_BITS_TYPE_SH_BIG);
|
|---|
| 5304 | }
|
|---|
| 5305 | else
|
|---|
| 5306 | {
|
|---|
| 5307 | r_index = (((unsigned int) rel->r_index[2] << 16)
|
|---|
| 5308 | | ((unsigned int) rel->r_index[1] << 8)
|
|---|
| 5309 | | rel->r_index[0]);
|
|---|
| 5310 | r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
|
|---|
| 5311 | r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
|
|---|
| 5312 | >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
|
|---|
| 5313 | }
|
|---|
| 5314 |
|
|---|
| 5315 | r_addend = GET_SWORD (input_bfd, rel->r_addend);
|
|---|
| 5316 |
|
|---|
| 5317 | BFD_ASSERT (r_type < TABLE_SIZE (howto_table_ext));
|
|---|
| 5318 |
|
|---|
| 5319 | if (relocateable)
|
|---|
| 5320 | {
|
|---|
| 5321 | /* We are generating a relocateable output file, and must
|
|---|
| 5322 | modify the reloc accordingly. */
|
|---|
| 5323 | if (r_extern
|
|---|
| 5324 | || r_type == (unsigned int) RELOC_BASE10
|
|---|
| 5325 | || r_type == (unsigned int) RELOC_BASE13
|
|---|
| 5326 | || r_type == (unsigned int) RELOC_BASE22)
|
|---|
| 5327 | {
|
|---|
| 5328 | /* If we know the symbol this relocation is against,
|
|---|
| 5329 | convert it into a relocation against a section. This
|
|---|
| 5330 | is what the native linker does. */
|
|---|
| 5331 | if (r_type == (unsigned int) RELOC_BASE10
|
|---|
| 5332 | || r_type == (unsigned int) RELOC_BASE13
|
|---|
| 5333 | || r_type == (unsigned int) RELOC_BASE22)
|
|---|
| 5334 | h = NULL;
|
|---|
| 5335 | else
|
|---|
| 5336 | h = sym_hashes[r_index];
|
|---|
| 5337 | if (h != (struct aout_link_hash_entry *) NULL
|
|---|
| 5338 | && (h->root.type == bfd_link_hash_defined
|
|---|
| 5339 | || h->root.type == bfd_link_hash_defweak))
|
|---|
| 5340 | {
|
|---|
| 5341 | asection *output_section;
|
|---|
| 5342 |
|
|---|
| 5343 | /* Change the r_extern value. */
|
|---|
| 5344 | if (bfd_header_big_endian (output_bfd))
|
|---|
| 5345 | rel->r_type[0] &=~ RELOC_EXT_BITS_EXTERN_BIG;
|
|---|
| 5346 | else
|
|---|
| 5347 | rel->r_type[0] &=~ RELOC_EXT_BITS_EXTERN_LITTLE;
|
|---|
| 5348 |
|
|---|
| 5349 | /* Compute a new r_index. */
|
|---|
| 5350 | output_section = h->root.u.def.section->output_section;
|
|---|
| 5351 | if (output_section == obj_textsec (output_bfd))
|
|---|
| 5352 | r_index = N_TEXT;
|
|---|
| 5353 | else if (output_section == obj_datasec (output_bfd))
|
|---|
| 5354 | r_index = N_DATA;
|
|---|
| 5355 | else if (output_section == obj_bsssec (output_bfd))
|
|---|
| 5356 | r_index = N_BSS;
|
|---|
| 5357 | else
|
|---|
| 5358 | r_index = N_ABS;
|
|---|
| 5359 |
|
|---|
| 5360 | /* Add the symbol value and the section VMA to the
|
|---|
| 5361 | addend. */
|
|---|
| 5362 | relocation = (h->root.u.def.value
|
|---|
| 5363 | + output_section->vma
|
|---|
| 5364 | + h->root.u.def.section->output_offset);
|
|---|
| 5365 |
|
|---|
| 5366 | /* Now RELOCATION is the VMA of the final
|
|---|
| 5367 | destination. If this is a PC relative reloc,
|
|---|
| 5368 | then ADDEND is the negative of the source VMA.
|
|---|
| 5369 | We want to set ADDEND to the difference between
|
|---|
| 5370 | the destination VMA and the source VMA, which
|
|---|
| 5371 | means we must adjust RELOCATION by the change in
|
|---|
| 5372 | the source VMA. This is done below. */
|
|---|
| 5373 | }
|
|---|
| 5374 | else
|
|---|
| 5375 | {
|
|---|
| 5376 | /* We must change r_index according to the symbol
|
|---|
| 5377 | map. */
|
|---|
| 5378 | r_index = symbol_map[r_index];
|
|---|
| 5379 |
|
|---|
| 5380 | if (r_index == -1)
|
|---|
| 5381 | {
|
|---|
| 5382 | if (h != NULL)
|
|---|
| 5383 | {
|
|---|
| 5384 | /* We decided to strip this symbol, but it
|
|---|
| 5385 | turns out that we can't. Note that we
|
|---|
| 5386 | lose the other and desc information here.
|
|---|
| 5387 | I don't think that will ever matter for a
|
|---|
| 5388 | global symbol. */
|
|---|
| 5389 | if (h->indx < 0)
|
|---|
| 5390 | {
|
|---|
| 5391 | h->indx = -2;
|
|---|
| 5392 | h->written = FALSE;
|
|---|
| 5393 | if (! aout_link_write_other_symbol (h,
|
|---|
| 5394 | (PTR) finfo))
|
|---|
| 5395 | return FALSE;
|
|---|
| 5396 | }
|
|---|
| 5397 | r_index = h->indx;
|
|---|
| 5398 | }
|
|---|
| 5399 | else
|
|---|
| 5400 | {
|
|---|
| 5401 | const char *name;
|
|---|
| 5402 |
|
|---|
| 5403 | name = strings + GET_WORD (input_bfd,
|
|---|
| 5404 | syms[r_index].e_strx);
|
|---|
| 5405 | if (! ((*finfo->info->callbacks->unattached_reloc)
|
|---|
| 5406 | (finfo->info, name, input_bfd, input_section,
|
|---|
| 5407 | r_addr)))
|
|---|
| 5408 | return FALSE;
|
|---|
| 5409 | r_index = 0;
|
|---|
| 5410 | }
|
|---|
| 5411 | }
|
|---|
| 5412 |
|
|---|
| 5413 | relocation = 0;
|
|---|
| 5414 |
|
|---|
| 5415 | /* If this is a PC relative reloc, then the addend
|
|---|
| 5416 | is the negative of the source VMA. We must
|
|---|
| 5417 | adjust it by the change in the source VMA. This
|
|---|
| 5418 | is done below. */
|
|---|
| 5419 | }
|
|---|
| 5420 |
|
|---|
| 5421 | /* Write out the new r_index value. */
|
|---|
| 5422 | if (bfd_header_big_endian (output_bfd))
|
|---|
| 5423 | {
|
|---|
| 5424 | rel->r_index[0] = r_index >> 16;
|
|---|
| 5425 | rel->r_index[1] = r_index >> 8;
|
|---|
| 5426 | rel->r_index[2] = r_index;
|
|---|
| 5427 | }
|
|---|
| 5428 | else
|
|---|
| 5429 | {
|
|---|
| 5430 | rel->r_index[2] = r_index >> 16;
|
|---|
| 5431 | rel->r_index[1] = r_index >> 8;
|
|---|
| 5432 | rel->r_index[0] = r_index;
|
|---|
| 5433 | }
|
|---|
| 5434 | }
|
|---|
| 5435 | else
|
|---|
| 5436 | {
|
|---|
| 5437 | /* This is a relocation against a section. We must
|
|---|
| 5438 | adjust by the amount that the section moved. */
|
|---|
| 5439 | r_section = aout_reloc_index_to_section (input_bfd, r_index);
|
|---|
| 5440 | relocation = (r_section->output_section->vma
|
|---|
| 5441 | + r_section->output_offset
|
|---|
| 5442 | - r_section->vma);
|
|---|
| 5443 |
|
|---|
| 5444 | /* If this is a PC relative reloc, then the addend is
|
|---|
| 5445 | the difference in VMA between the destination and the
|
|---|
| 5446 | source. We have just adjusted for the change in VMA
|
|---|
| 5447 | of the destination, so we must also adjust by the
|
|---|
| 5448 | change in VMA of the source. This is done below. */
|
|---|
| 5449 | }
|
|---|
| 5450 |
|
|---|
| 5451 | /* As described above, we must always adjust a PC relative
|
|---|
| 5452 | reloc by the change in VMA of the source. However, if
|
|---|
| 5453 | pcrel_offset is set, then the addend does not include the
|
|---|
| 5454 | location within the section, in which case we don't need
|
|---|
| 5455 | to adjust anything. */
|
|---|
| 5456 | if (howto_table_ext[r_type].pc_relative
|
|---|
| 5457 | && ! howto_table_ext[r_type].pcrel_offset)
|
|---|
| 5458 | relocation -= (input_section->output_section->vma
|
|---|
| 5459 | + input_section->output_offset
|
|---|
| 5460 | - input_section->vma);
|
|---|
| 5461 |
|
|---|
| 5462 | /* Change the addend if necessary. */
|
|---|
| 5463 | if (relocation != 0)
|
|---|
| 5464 | PUT_WORD (output_bfd, r_addend + relocation, rel->r_addend);
|
|---|
| 5465 |
|
|---|
| 5466 | /* Change the address of the relocation. */
|
|---|
| 5467 | PUT_WORD (output_bfd,
|
|---|
| 5468 | r_addr + input_section->output_offset,
|
|---|
| 5469 | rel->r_address);
|
|---|
| 5470 | }
|
|---|
| 5471 | else
|
|---|
| 5472 | {
|
|---|
| 5473 | bfd_boolean hundef;
|
|---|
| 5474 | bfd_reloc_status_type r;
|
|---|
| 5475 |
|
|---|
| 5476 | /* We are generating an executable, and must do a full
|
|---|
| 5477 | relocation. */
|
|---|
| 5478 | hundef = FALSE;
|
|---|
| 5479 |
|
|---|
| 5480 | if (r_extern)
|
|---|
| 5481 | {
|
|---|
| 5482 | h = sym_hashes[r_index];
|
|---|
| 5483 |
|
|---|
| 5484 | if (h != (struct aout_link_hash_entry *) NULL
|
|---|
| 5485 | && (h->root.type == bfd_link_hash_defined
|
|---|
| 5486 | || h->root.type == bfd_link_hash_defweak))
|
|---|
| 5487 | {
|
|---|
| 5488 | relocation = (h->root.u.def.value
|
|---|
| 5489 | + h->root.u.def.section->output_section->vma
|
|---|
| 5490 | + h->root.u.def.section->output_offset);
|
|---|
| 5491 | }
|
|---|
| 5492 | else if (h != (struct aout_link_hash_entry *) NULL
|
|---|
| 5493 | && h->root.type == bfd_link_hash_undefweak)
|
|---|
| 5494 | relocation = 0;
|
|---|
| 5495 | else
|
|---|
| 5496 | {
|
|---|
| 5497 | hundef = TRUE;
|
|---|
| 5498 | relocation = 0;
|
|---|
| 5499 | }
|
|---|
| 5500 | }
|
|---|
| 5501 | else if (r_type == (unsigned int) RELOC_BASE10
|
|---|
| 5502 | || r_type == (unsigned int) RELOC_BASE13
|
|---|
| 5503 | || r_type == (unsigned int) RELOC_BASE22)
|
|---|
| 5504 | {
|
|---|
| 5505 | struct external_nlist *sym;
|
|---|
| 5506 | int type;
|
|---|
| 5507 |
|
|---|
| 5508 | /* For base relative relocs, r_index is always an index
|
|---|
| 5509 | into the symbol table, even if r_extern is 0. */
|
|---|
| 5510 | sym = syms + r_index;
|
|---|
| 5511 | type = H_GET_8 (input_bfd, sym->e_type);
|
|---|
| 5512 | if ((type & N_TYPE) == N_TEXT
|
|---|
| 5513 | || type == N_WEAKT)
|
|---|
| 5514 | r_section = obj_textsec (input_bfd);
|
|---|
| 5515 | else if ((type & N_TYPE) == N_DATA
|
|---|
| 5516 | || type == N_WEAKD)
|
|---|
| 5517 | r_section = obj_datasec (input_bfd);
|
|---|
| 5518 | else if ((type & N_TYPE) == N_BSS
|
|---|
| 5519 | || type == N_WEAKB)
|
|---|
| 5520 | r_section = obj_bsssec (input_bfd);
|
|---|
| 5521 | else if ((type & N_TYPE) == N_ABS
|
|---|
| 5522 | || type == N_WEAKA)
|
|---|
| 5523 | r_section = bfd_abs_section_ptr;
|
|---|
| 5524 | else
|
|---|
| 5525 | abort ();
|
|---|
| 5526 | relocation = (r_section->output_section->vma
|
|---|
| 5527 | + r_section->output_offset
|
|---|
| 5528 | + (GET_WORD (input_bfd, sym->e_value)
|
|---|
| 5529 | - r_section->vma));
|
|---|
| 5530 | }
|
|---|
| 5531 | else
|
|---|
| 5532 | {
|
|---|
| 5533 | r_section = aout_reloc_index_to_section (input_bfd, r_index);
|
|---|
| 5534 |
|
|---|
| 5535 | /* If this is a PC relative reloc, then R_ADDEND is the
|
|---|
| 5536 | difference between the two vmas, or
|
|---|
| 5537 | old_dest_sec + old_dest_off - (old_src_sec + old_src_off)
|
|---|
| 5538 | where
|
|---|
| 5539 | old_dest_sec == section->vma
|
|---|
| 5540 | and
|
|---|
| 5541 | old_src_sec == input_section->vma
|
|---|
| 5542 | and
|
|---|
| 5543 | old_src_off == r_addr
|
|---|
| 5544 |
|
|---|
| 5545 | _bfd_final_link_relocate expects RELOCATION +
|
|---|
| 5546 | R_ADDEND to be the VMA of the destination minus
|
|---|
| 5547 | r_addr (the minus r_addr is because this relocation
|
|---|
| 5548 | is not pcrel_offset, which is a bit confusing and
|
|---|
| 5549 | should, perhaps, be changed), or
|
|---|
| 5550 | new_dest_sec
|
|---|
| 5551 | where
|
|---|
| 5552 | new_dest_sec == output_section->vma + output_offset
|
|---|
| 5553 | We arrange for this to happen by setting RELOCATION to
|
|---|
| 5554 | new_dest_sec + old_src_sec - old_dest_sec
|
|---|
| 5555 |
|
|---|
| 5556 | If this is not a PC relative reloc, then R_ADDEND is
|
|---|
| 5557 | simply the VMA of the destination, so we set
|
|---|
| 5558 | RELOCATION to the change in the destination VMA, or
|
|---|
| 5559 | new_dest_sec - old_dest_sec
|
|---|
| 5560 | */
|
|---|
| 5561 | relocation = (r_section->output_section->vma
|
|---|
| 5562 | + r_section->output_offset
|
|---|
| 5563 | - r_section->vma);
|
|---|
| 5564 | if (howto_table_ext[r_type].pc_relative)
|
|---|
| 5565 | relocation += input_section->vma;
|
|---|
| 5566 | }
|
|---|
| 5567 |
|
|---|
| 5568 | if (check_dynamic_reloc != NULL)
|
|---|
| 5569 | {
|
|---|
| 5570 | bfd_boolean skip;
|
|---|
| 5571 |
|
|---|
| 5572 | if (! ((*check_dynamic_reloc)
|
|---|
| 5573 | (finfo->info, input_bfd, input_section, h,
|
|---|
| 5574 | (PTR) rel, contents, &skip, &relocation)))
|
|---|
| 5575 | return FALSE;
|
|---|
| 5576 | if (skip)
|
|---|
| 5577 | continue;
|
|---|
| 5578 | }
|
|---|
| 5579 |
|
|---|
| 5580 | /* Now warn if a global symbol is undefined. We could not
|
|---|
| 5581 | do this earlier, because check_dynamic_reloc might want
|
|---|
| 5582 | to skip this reloc. */
|
|---|
| 5583 | if (hundef
|
|---|
| 5584 | && ! finfo->info->shared
|
|---|
| 5585 | && r_type != (unsigned int) RELOC_BASE10
|
|---|
| 5586 | && r_type != (unsigned int) RELOC_BASE13
|
|---|
| 5587 | && r_type != (unsigned int) RELOC_BASE22)
|
|---|
| 5588 | {
|
|---|
| 5589 | const char *name;
|
|---|
| 5590 |
|
|---|
| 5591 | if (h != NULL)
|
|---|
| 5592 | name = h->root.root.string;
|
|---|
| 5593 | else
|
|---|
| 5594 | name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
|
|---|
| 5595 | if (! ((*finfo->info->callbacks->undefined_symbol)
|
|---|
| 5596 | (finfo->info, name, input_bfd, input_section,
|
|---|
| 5597 | r_addr, TRUE)))
|
|---|
| 5598 | return FALSE;
|
|---|
| 5599 | }
|
|---|
| 5600 |
|
|---|
| 5601 | if (r_type != (unsigned int) RELOC_SPARC_REV32)
|
|---|
| 5602 | r = MY_final_link_relocate (howto_table_ext + r_type,
|
|---|
| 5603 | input_bfd, input_section,
|
|---|
| 5604 | contents, r_addr, relocation,
|
|---|
| 5605 | r_addend);
|
|---|
| 5606 | else
|
|---|
| 5607 | {
|
|---|
| 5608 | bfd_vma x;
|
|---|
| 5609 |
|
|---|
| 5610 | x = bfd_get_32 (input_bfd, contents + r_addr);
|
|---|
| 5611 | x = x + relocation + r_addend;
|
|---|
| 5612 | bfd_putl32 (/*input_bfd,*/ x, contents + r_addr);
|
|---|
| 5613 | r = bfd_reloc_ok;
|
|---|
| 5614 | }
|
|---|
| 5615 |
|
|---|
| 5616 | if (r != bfd_reloc_ok)
|
|---|
| 5617 | {
|
|---|
| 5618 | switch (r)
|
|---|
| 5619 | {
|
|---|
| 5620 | default:
|
|---|
| 5621 | case bfd_reloc_outofrange:
|
|---|
| 5622 | abort ();
|
|---|
| 5623 | case bfd_reloc_overflow:
|
|---|
| 5624 | {
|
|---|
| 5625 | const char *name;
|
|---|
| 5626 |
|
|---|
| 5627 | if (h != NULL)
|
|---|
| 5628 | name = h->root.root.string;
|
|---|
| 5629 | else if (r_extern
|
|---|
| 5630 | || r_type == (unsigned int) RELOC_BASE10
|
|---|
| 5631 | || r_type == (unsigned int) RELOC_BASE13
|
|---|
| 5632 | || r_type == (unsigned int) RELOC_BASE22)
|
|---|
| 5633 | name = strings + GET_WORD (input_bfd,
|
|---|
| 5634 | syms[r_index].e_strx);
|
|---|
| 5635 | else
|
|---|
| 5636 | {
|
|---|
| 5637 | asection *s;
|
|---|
| 5638 |
|
|---|
| 5639 | s = aout_reloc_index_to_section (input_bfd, r_index);
|
|---|
| 5640 | name = bfd_section_name (input_bfd, s);
|
|---|
| 5641 | }
|
|---|
| 5642 | if (! ((*finfo->info->callbacks->reloc_overflow)
|
|---|
| 5643 | (finfo->info, name, howto_table_ext[r_type].name,
|
|---|
| 5644 | r_addend, input_bfd, input_section, r_addr)))
|
|---|
| 5645 | return FALSE;
|
|---|
| 5646 | }
|
|---|
| 5647 | break;
|
|---|
| 5648 | }
|
|---|
| 5649 | }
|
|---|
| 5650 | }
|
|---|
| 5651 | }
|
|---|
| 5652 |
|
|---|
| 5653 | return TRUE;
|
|---|
| 5654 | }
|
|---|
| 5655 |
|
|---|
| 5656 | /* Handle a link order which is supposed to generate a reloc. */
|
|---|
| 5657 |
|
|---|
| 5658 | static bfd_boolean
|
|---|
| 5659 | aout_link_reloc_link_order (finfo, o, p)
|
|---|
| 5660 | struct aout_final_link_info *finfo;
|
|---|
| 5661 | asection *o;
|
|---|
| 5662 | struct bfd_link_order *p;
|
|---|
| 5663 | {
|
|---|
| 5664 | struct bfd_link_order_reloc *pr;
|
|---|
| 5665 | int r_index;
|
|---|
| 5666 | int r_extern;
|
|---|
| 5667 | reloc_howto_type *howto;
|
|---|
| 5668 | file_ptr *reloff_ptr = NULL;
|
|---|
| 5669 | struct reloc_std_external srel;
|
|---|
| 5670 | struct reloc_ext_external erel;
|
|---|
| 5671 | PTR rel_ptr;
|
|---|
| 5672 | bfd_size_type amt;
|
|---|
| 5673 |
|
|---|
| 5674 | pr = p->u.reloc.p;
|
|---|
| 5675 |
|
|---|
| 5676 | if (p->type == bfd_section_reloc_link_order)
|
|---|
| 5677 | {
|
|---|
| 5678 | r_extern = 0;
|
|---|
| 5679 | if (bfd_is_abs_section (pr->u.section))
|
|---|
| 5680 | r_index = N_ABS | N_EXT;
|
|---|
| 5681 | else
|
|---|
| 5682 | {
|
|---|
| 5683 | BFD_ASSERT (pr->u.section->owner == finfo->output_bfd);
|
|---|
| 5684 | r_index = pr->u.section->target_index;
|
|---|
| 5685 | }
|
|---|
| 5686 | }
|
|---|
| 5687 | else
|
|---|
| 5688 | {
|
|---|
| 5689 | struct aout_link_hash_entry *h;
|
|---|
| 5690 |
|
|---|
| 5691 | BFD_ASSERT (p->type == bfd_symbol_reloc_link_order);
|
|---|
| 5692 | r_extern = 1;
|
|---|
| 5693 | h = ((struct aout_link_hash_entry *)
|
|---|
| 5694 | bfd_wrapped_link_hash_lookup (finfo->output_bfd, finfo->info,
|
|---|
| 5695 | pr->u.name, FALSE, FALSE, TRUE));
|
|---|
| 5696 | if (h != (struct aout_link_hash_entry *) NULL
|
|---|
| 5697 | && h->indx >= 0)
|
|---|
| 5698 | r_index = h->indx;
|
|---|
| 5699 | else if (h != NULL)
|
|---|
| 5700 | {
|
|---|
| 5701 | /* We decided to strip this symbol, but it turns out that we
|
|---|
| 5702 | can't. Note that we lose the other and desc information
|
|---|
| 5703 | here. I don't think that will ever matter for a global
|
|---|
| 5704 | symbol. */
|
|---|
| 5705 | h->indx = -2;
|
|---|
| 5706 | h->written = FALSE;
|
|---|
| 5707 | if (! aout_link_write_other_symbol (h, (PTR) finfo))
|
|---|
| 5708 | return FALSE;
|
|---|
| 5709 | r_index = h->indx;
|
|---|
| 5710 | }
|
|---|
| 5711 | else
|
|---|
| 5712 | {
|
|---|
| 5713 | if (! ((*finfo->info->callbacks->unattached_reloc)
|
|---|
| 5714 | (finfo->info, pr->u.name, (bfd *) NULL,
|
|---|
| 5715 | (asection *) NULL, (bfd_vma) 0)))
|
|---|
| 5716 | return FALSE;
|
|---|
| 5717 | r_index = 0;
|
|---|
| 5718 | }
|
|---|
| 5719 | }
|
|---|
| 5720 |
|
|---|
| 5721 | howto = bfd_reloc_type_lookup (finfo->output_bfd, pr->reloc);
|
|---|
| 5722 | if (howto == 0)
|
|---|
| 5723 | {
|
|---|
| 5724 | bfd_set_error (bfd_error_bad_value);
|
|---|
| 5725 | return FALSE;
|
|---|
| 5726 | }
|
|---|
| 5727 |
|
|---|
| 5728 | if (o == obj_textsec (finfo->output_bfd))
|
|---|
| 5729 | reloff_ptr = &finfo->treloff;
|
|---|
| 5730 | else if (o == obj_datasec (finfo->output_bfd))
|
|---|
| 5731 | reloff_ptr = &finfo->dreloff;
|
|---|
| 5732 | else
|
|---|
| 5733 | abort ();
|
|---|
| 5734 |
|
|---|
| 5735 | if (obj_reloc_entry_size (finfo->output_bfd) == RELOC_STD_SIZE)
|
|---|
| 5736 | {
|
|---|
| 5737 | #ifdef MY_put_reloc
|
|---|
| 5738 | MY_put_reloc (finfo->output_bfd, r_extern, r_index, p->offset, howto,
|
|---|
| 5739 | &srel);
|
|---|
| 5740 | #else
|
|---|
| 5741 | {
|
|---|
| 5742 | int r_pcrel;
|
|---|
| 5743 | int r_baserel;
|
|---|
| 5744 | int r_jmptable;
|
|---|
| 5745 | int r_relative;
|
|---|
| 5746 | int r_length;
|
|---|
| 5747 |
|
|---|
| 5748 | r_pcrel = (int) howto->pc_relative;
|
|---|
| 5749 | r_baserel = (howto->type & 8) != 0;
|
|---|
| 5750 | r_jmptable = (howto->type & 16) != 0;
|
|---|
| 5751 | r_relative = (howto->type & 32) != 0;
|
|---|
| 5752 | r_length = howto->size;
|
|---|
| 5753 |
|
|---|
| 5754 | PUT_WORD (finfo->output_bfd, p->offset, srel.r_address);
|
|---|
| 5755 | if (bfd_header_big_endian (finfo->output_bfd))
|
|---|
| 5756 | {
|
|---|
| 5757 | srel.r_index[0] = r_index >> 16;
|
|---|
| 5758 | srel.r_index[1] = r_index >> 8;
|
|---|
| 5759 | srel.r_index[2] = r_index;
|
|---|
| 5760 | srel.r_type[0] =
|
|---|
| 5761 | ((r_extern ? RELOC_STD_BITS_EXTERN_BIG : 0)
|
|---|
| 5762 | | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG : 0)
|
|---|
| 5763 | | (r_baserel ? RELOC_STD_BITS_BASEREL_BIG : 0)
|
|---|
| 5764 | | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_BIG : 0)
|
|---|
| 5765 | | (r_relative ? RELOC_STD_BITS_RELATIVE_BIG : 0)
|
|---|
| 5766 | | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG));
|
|---|
| 5767 | }
|
|---|
| 5768 | else
|
|---|
| 5769 | {
|
|---|
| 5770 | srel.r_index[2] = r_index >> 16;
|
|---|
| 5771 | srel.r_index[1] = r_index >> 8;
|
|---|
| 5772 | srel.r_index[0] = r_index;
|
|---|
| 5773 | srel.r_type[0] =
|
|---|
| 5774 | ((r_extern ? RELOC_STD_BITS_EXTERN_LITTLE : 0)
|
|---|
| 5775 | | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE : 0)
|
|---|
| 5776 | | (r_baserel ? RELOC_STD_BITS_BASEREL_LITTLE : 0)
|
|---|
| 5777 | | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_LITTLE : 0)
|
|---|
| 5778 | | (r_relative ? RELOC_STD_BITS_RELATIVE_LITTLE : 0)
|
|---|
| 5779 | | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE));
|
|---|
| 5780 | }
|
|---|
| 5781 | }
|
|---|
| 5782 | #endif
|
|---|
| 5783 | rel_ptr = (PTR) &srel;
|
|---|
| 5784 |
|
|---|
| 5785 | /* We have to write the addend into the object file, since
|
|---|
| 5786 | standard a.out relocs are in place. It would be more
|
|---|
| 5787 | reliable if we had the current contents of the file here,
|
|---|
| 5788 | rather than assuming zeroes, but we can't read the file since
|
|---|
| 5789 | it was opened using bfd_openw. */
|
|---|
| 5790 | if (pr->addend != 0)
|
|---|
| 5791 | {
|
|---|
| 5792 | bfd_size_type size;
|
|---|
| 5793 | bfd_reloc_status_type r;
|
|---|
| 5794 | bfd_byte *buf;
|
|---|
| 5795 | bfd_boolean ok;
|
|---|
| 5796 |
|
|---|
| 5797 | size = bfd_get_reloc_size (howto);
|
|---|
| 5798 | buf = (bfd_byte *) bfd_zmalloc (size);
|
|---|
| 5799 | if (buf == (bfd_byte *) NULL)
|
|---|
| 5800 | return FALSE;
|
|---|
| 5801 | r = MY_relocate_contents (howto, finfo->output_bfd,
|
|---|
| 5802 | (bfd_vma) pr->addend, buf);
|
|---|
| 5803 | switch (r)
|
|---|
| 5804 | {
|
|---|
| 5805 | case bfd_reloc_ok:
|
|---|
| 5806 | break;
|
|---|
| 5807 | default:
|
|---|
| 5808 | case bfd_reloc_outofrange:
|
|---|
| 5809 | abort ();
|
|---|
| 5810 | case bfd_reloc_overflow:
|
|---|
| 5811 | if (! ((*finfo->info->callbacks->reloc_overflow)
|
|---|
| 5812 | (finfo->info,
|
|---|
| 5813 | (p->type == bfd_section_reloc_link_order
|
|---|
| 5814 | ? bfd_section_name (finfo->output_bfd,
|
|---|
| 5815 | pr->u.section)
|
|---|
| 5816 | : pr->u.name),
|
|---|
| 5817 | howto->name, pr->addend, (bfd *) NULL,
|
|---|
| 5818 | (asection *) NULL, (bfd_vma) 0)))
|
|---|
| 5819 | {
|
|---|
| 5820 | free (buf);
|
|---|
| 5821 | return FALSE;
|
|---|
| 5822 | }
|
|---|
| 5823 | break;
|
|---|
| 5824 | }
|
|---|
| 5825 | ok = bfd_set_section_contents (finfo->output_bfd, o, (PTR) buf,
|
|---|
| 5826 | (file_ptr) p->offset, size);
|
|---|
| 5827 | free (buf);
|
|---|
| 5828 | if (! ok)
|
|---|
| 5829 | return FALSE;
|
|---|
| 5830 | }
|
|---|
| 5831 | }
|
|---|
| 5832 | else
|
|---|
| 5833 | {
|
|---|
| 5834 | #ifdef MY_put_ext_reloc
|
|---|
| 5835 | MY_put_ext_reloc (finfo->output_bfd, r_extern, r_index, p->offset,
|
|---|
| 5836 | howto, &erel, pr->addend);
|
|---|
| 5837 | #else
|
|---|
| 5838 | PUT_WORD (finfo->output_bfd, p->offset, erel.r_address);
|
|---|
| 5839 |
|
|---|
| 5840 | if (bfd_header_big_endian (finfo->output_bfd))
|
|---|
| 5841 | {
|
|---|
| 5842 | erel.r_index[0] = r_index >> 16;
|
|---|
| 5843 | erel.r_index[1] = r_index >> 8;
|
|---|
| 5844 | erel.r_index[2] = r_index;
|
|---|
| 5845 | erel.r_type[0] =
|
|---|
| 5846 | ((r_extern ? RELOC_EXT_BITS_EXTERN_BIG : 0)
|
|---|
| 5847 | | (howto->type << RELOC_EXT_BITS_TYPE_SH_BIG));
|
|---|
| 5848 | }
|
|---|
| 5849 | else
|
|---|
| 5850 | {
|
|---|
| 5851 | erel.r_index[2] = r_index >> 16;
|
|---|
| 5852 | erel.r_index[1] = r_index >> 8;
|
|---|
| 5853 | erel.r_index[0] = r_index;
|
|---|
| 5854 | erel.r_type[0] =
|
|---|
| 5855 | (r_extern ? RELOC_EXT_BITS_EXTERN_LITTLE : 0)
|
|---|
| 5856 | | (howto->type << RELOC_EXT_BITS_TYPE_SH_LITTLE);
|
|---|
| 5857 | }
|
|---|
| 5858 |
|
|---|
| 5859 | PUT_WORD (finfo->output_bfd, (bfd_vma) pr->addend, erel.r_addend);
|
|---|
| 5860 | #endif /* MY_put_ext_reloc */
|
|---|
| 5861 |
|
|---|
| 5862 | rel_ptr = (PTR) &erel;
|
|---|
| 5863 | }
|
|---|
| 5864 |
|
|---|
| 5865 | amt = obj_reloc_entry_size (finfo->output_bfd);
|
|---|
| 5866 | if (bfd_seek (finfo->output_bfd, *reloff_ptr, SEEK_SET) != 0
|
|---|
| 5867 | || bfd_bwrite (rel_ptr, amt, finfo->output_bfd) != amt)
|
|---|
| 5868 | return FALSE;
|
|---|
| 5869 |
|
|---|
| 5870 | *reloff_ptr += obj_reloc_entry_size (finfo->output_bfd);
|
|---|
| 5871 |
|
|---|
| 5872 | /* Assert that the relocs have not run into the symbols, and that n
|
|---|
| 5873 | the text relocs have not run into the data relocs. */
|
|---|
| 5874 | BFD_ASSERT (*reloff_ptr <= obj_sym_filepos (finfo->output_bfd)
|
|---|
| 5875 | && (reloff_ptr != &finfo->treloff
|
|---|
| 5876 | || (*reloff_ptr
|
|---|
| 5877 | <= obj_datasec (finfo->output_bfd)->rel_filepos)));
|
|---|
| 5878 |
|
|---|
| 5879 | return TRUE;
|
|---|
| 5880 | }
|
|---|