| 1 | /* BFD back-end for raw ARM a.out binaries.
|
|---|
| 2 | Copyright 1994, 1995, 1997, 1998, 1999, 2000, 2001, 2002
|
|---|
| 3 | Free Software Foundation, Inc.
|
|---|
| 4 | Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
|
|---|
| 5 |
|
|---|
| 6 | This file is part of BFD, the Binary File Descriptor library.
|
|---|
| 7 |
|
|---|
| 8 | This program is free software; you can redistribute it and/or modify
|
|---|
| 9 | it under the terms of the GNU General Public License as published by
|
|---|
| 10 | the Free Software Foundation; either version 2 of the License, or
|
|---|
| 11 | (at your option) any later version.
|
|---|
| 12 |
|
|---|
| 13 | This program is distributed in the hope that it will be useful,
|
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 16 | GNU General Public License for more details.
|
|---|
| 17 |
|
|---|
| 18 | You should have received a copy of the GNU General Public License
|
|---|
| 19 | along with this program; if not, write to the Free Software
|
|---|
| 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|---|
| 21 |
|
|---|
| 22 | #include "bfd.h"
|
|---|
| 23 | #include "sysdep.h"
|
|---|
| 24 |
|
|---|
| 25 | /* Avoid multiple defininitions from aoutx if supporting standarad a.out
|
|---|
| 26 | as well as our own. */
|
|---|
| 27 | /* Do not "beautify" the CONCAT* macro args. Traditional C will not
|
|---|
| 28 | remove whitespace added here, and thus will fail to concatenate
|
|---|
| 29 | the tokens. */
|
|---|
| 30 | #define NAME(x,y) CONCAT3 (aoutarm,_32_,y)
|
|---|
| 31 |
|
|---|
| 32 | #define N_TXTADDR(x) \
|
|---|
| 33 | ((N_MAGIC (x) == NMAGIC) \
|
|---|
| 34 | ? (bfd_vma) 0x8000 \
|
|---|
| 35 | : ((N_MAGIC (x) != ZMAGIC) \
|
|---|
| 36 | ? (bfd_vma) 0 \
|
|---|
| 37 | : ((N_SHARED_LIB (x)) \
|
|---|
| 38 | ? ((x).a_entry & ~(bfd_vma) (TARGET_PAGE_SIZE - 1)) \
|
|---|
| 39 | : (bfd_vma) TEXT_START_ADDR)))
|
|---|
| 40 |
|
|---|
| 41 | #define TEXT_START_ADDR 0x8000
|
|---|
| 42 | #define TARGET_PAGE_SIZE 0x8000
|
|---|
| 43 | #define SEGMENT_SIZE TARGET_PAGE_SIZE
|
|---|
| 44 | #define DEFAULT_ARCH bfd_arch_arm
|
|---|
| 45 |
|
|---|
| 46 | #define MY(OP) CONCAT2 (aoutarm_,OP)
|
|---|
| 47 | #define N_BADMAG(x) ((((x).a_info & ~007200) != ZMAGIC) && \
|
|---|
| 48 | (((x).a_info & ~006000) != OMAGIC) && \
|
|---|
| 49 | ((x).a_info != NMAGIC))
|
|---|
| 50 | #define N_MAGIC(x) ((x).a_info & ~07200)
|
|---|
| 51 |
|
|---|
| 52 | #define MY_bfd_reloc_type_lookup aoutarm_bfd_reloc_type_lookup
|
|---|
| 53 |
|
|---|
| 54 | #include "libaout.h"
|
|---|
| 55 | #include "aout/aout64.h"
|
|---|
| 56 |
|
|---|
| 57 | static bfd_boolean MY(write_object_contents)
|
|---|
| 58 | PARAMS ((bfd *));
|
|---|
| 59 | static bfd_reloc_status_type MY(fix_pcrel_26_done)
|
|---|
| 60 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
|---|
| 61 | static bfd_reloc_status_type MY(fix_pcrel_26)
|
|---|
| 62 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
|---|
| 63 | static void MY(swap_std_reloc_in)
|
|---|
| 64 | PARAMS ((bfd *, struct reloc_std_external *, arelent *, asymbol **,
|
|---|
| 65 | bfd_size_type));
|
|---|
| 66 | reloc_howto_type *MY(bfd_reloc_type_lookup)
|
|---|
| 67 | PARAMS ((bfd *, bfd_reloc_code_real_type));
|
|---|
| 68 | reloc_howto_type * MY(reloc_howto)
|
|---|
| 69 | PARAMS ((bfd *, struct reloc_std_external *, int *, int *, int *));
|
|---|
| 70 | void MY(put_reloc)
|
|---|
| 71 | PARAMS ((bfd *, int, int, bfd_vma, reloc_howto_type *,
|
|---|
| 72 | struct reloc_std_external *));
|
|---|
| 73 | void MY(relocatable_reloc)
|
|---|
| 74 | PARAMS ((reloc_howto_type *, bfd *, struct reloc_std_external *, bfd_vma *,
|
|---|
| 75 | bfd_vma));
|
|---|
| 76 | void MY(swap_std_reloc_out)
|
|---|
| 77 | PARAMS ((bfd *, arelent *, struct reloc_std_external *));
|
|---|
| 78 | |
|---|
| 79 |
|
|---|
| 80 | reloc_howto_type MY(howto_table)[] =
|
|---|
| 81 | {
|
|---|
| 82 | /* Type rs size bsz pcrel bitpos ovrf sf name part_inpl
|
|---|
| 83 | readmask setmask pcdone. */
|
|---|
| 84 | HOWTO (0, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, 0, "8", TRUE,
|
|---|
| 85 | 0x000000ff, 0x000000ff, FALSE),
|
|---|
| 86 | HOWTO (1, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, 0, "16", TRUE,
|
|---|
| 87 | 0x0000ffff, 0x0000ffff, FALSE),
|
|---|
| 88 | HOWTO (2, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, 0, "32", TRUE,
|
|---|
| 89 | 0xffffffff, 0xffffffff, FALSE),
|
|---|
| 90 | HOWTO (3, 2, 2, 26, TRUE, 0, complain_overflow_signed, MY(fix_pcrel_26),
|
|---|
| 91 | "ARM26", TRUE, 0x00ffffff, 0x00ffffff, TRUE),
|
|---|
| 92 | HOWTO (4, 0, 0, 8, TRUE, 0, complain_overflow_signed, 0, "DISP8", TRUE,
|
|---|
| 93 | 0x000000ff, 0x000000ff, TRUE),
|
|---|
| 94 | HOWTO (5, 0, 1, 16, TRUE, 0, complain_overflow_signed, 0, "DISP16", TRUE,
|
|---|
| 95 | 0x0000ffff, 0x0000ffff, TRUE),
|
|---|
| 96 | HOWTO (6, 0, 2, 32, TRUE, 0, complain_overflow_signed, 0, "DISP32", TRUE,
|
|---|
| 97 | 0xffffffff, 0xffffffff, TRUE),
|
|---|
| 98 | HOWTO (7, 2, 2, 26, FALSE, 0, complain_overflow_signed,
|
|---|
| 99 | MY(fix_pcrel_26_done), "ARM26D", TRUE, 0x0, 0x0,
|
|---|
| 100 | FALSE),
|
|---|
| 101 | EMPTY_HOWTO (-1),
|
|---|
| 102 | HOWTO (9, 0, -1, 16, FALSE, 0, complain_overflow_bitfield, 0, "NEG16", TRUE,
|
|---|
| 103 | 0x0000ffff, 0x0000ffff, FALSE),
|
|---|
| 104 | HOWTO (10, 0, -2, 32, FALSE, 0, complain_overflow_bitfield, 0, "NEG32", TRUE,
|
|---|
| 105 | 0xffffffff, 0xffffffff, FALSE)
|
|---|
| 106 | };
|
|---|
| 107 |
|
|---|
| 108 | #define RELOC_ARM_BITS_NEG_BIG ((unsigned int) 0x08)
|
|---|
| 109 | #define RELOC_ARM_BITS_NEG_LITTLE ((unsigned int) 0x10)
|
|---|
| 110 |
|
|---|
| 111 | reloc_howto_type *
|
|---|
| 112 | MY(reloc_howto) (abfd, rel, r_index, r_extern, r_pcrel)
|
|---|
| 113 | bfd *abfd;
|
|---|
| 114 | struct reloc_std_external *rel;
|
|---|
| 115 | int *r_index;
|
|---|
| 116 | int *r_extern;
|
|---|
| 117 | int *r_pcrel;
|
|---|
| 118 | {
|
|---|
| 119 | unsigned int r_length;
|
|---|
| 120 | unsigned int r_pcrel_done;
|
|---|
| 121 | unsigned int r_neg;
|
|---|
| 122 | int index;
|
|---|
| 123 |
|
|---|
| 124 | *r_pcrel = 0;
|
|---|
| 125 | if (bfd_header_big_endian (abfd))
|
|---|
| 126 | {
|
|---|
| 127 | *r_index = ((rel->r_index[0] << 16)
|
|---|
| 128 | | (rel->r_index[1] << 8)
|
|---|
| 129 | | rel->r_index[2]);
|
|---|
| 130 | *r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
|
|---|
| 131 | r_pcrel_done = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
|
|---|
| 132 | r_neg = (0 != (rel->r_type[0] & RELOC_ARM_BITS_NEG_BIG));
|
|---|
| 133 | r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_BIG)
|
|---|
| 134 | >> RELOC_STD_BITS_LENGTH_SH_BIG);
|
|---|
| 135 | }
|
|---|
| 136 | else
|
|---|
| 137 | {
|
|---|
| 138 | *r_index = ((rel->r_index[2] << 16)
|
|---|
| 139 | | (rel->r_index[1] << 8)
|
|---|
| 140 | | rel->r_index[0]);
|
|---|
| 141 | *r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
|
|---|
| 142 | r_pcrel_done = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
|
|---|
| 143 | r_neg = (0 != (rel->r_type[0] & RELOC_ARM_BITS_NEG_LITTLE));
|
|---|
| 144 | r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE)
|
|---|
| 145 | >> RELOC_STD_BITS_LENGTH_SH_LITTLE);
|
|---|
| 146 | }
|
|---|
| 147 | index = r_length + 4 * r_pcrel_done + 8 * r_neg;
|
|---|
| 148 | if (index == 3)
|
|---|
| 149 | *r_pcrel = 1;
|
|---|
| 150 |
|
|---|
| 151 | return MY(howto_table) + index;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | #define MY_reloc_howto(BFD, REL, IN, EX, PC) \
|
|---|
| 155 | MY(reloc_howto) (BFD, REL, &IN, &EX, &PC)
|
|---|
| 156 |
|
|---|
| 157 | void
|
|---|
| 158 | MY(put_reloc) (abfd, r_extern, r_index, value, howto, reloc)
|
|---|
| 159 | bfd *abfd;
|
|---|
| 160 | int r_extern;
|
|---|
| 161 | int r_index;
|
|---|
| 162 | bfd_vma value;
|
|---|
| 163 | reloc_howto_type *howto;
|
|---|
| 164 | struct reloc_std_external *reloc;
|
|---|
| 165 | {
|
|---|
| 166 | unsigned int r_length;
|
|---|
| 167 | int r_pcrel;
|
|---|
| 168 | int r_neg;
|
|---|
| 169 |
|
|---|
| 170 | PUT_WORD (abfd, value, reloc->r_address);
|
|---|
| 171 | /* Size as a power of two. */
|
|---|
| 172 | r_length = howto->size;
|
|---|
| 173 |
|
|---|
| 174 | /* Special case for branch relocations. */
|
|---|
| 175 | if (howto->type == 3 || howto->type == 7)
|
|---|
| 176 | r_length = 3;
|
|---|
| 177 |
|
|---|
| 178 | r_pcrel = howto->type & 4; /* PC Relative done? */
|
|---|
| 179 | r_neg = howto->type & 8; /* Negative relocation. */
|
|---|
| 180 |
|
|---|
| 181 | if (bfd_header_big_endian (abfd))
|
|---|
| 182 | {
|
|---|
| 183 | reloc->r_index[0] = r_index >> 16;
|
|---|
| 184 | reloc->r_index[1] = r_index >> 8;
|
|---|
| 185 | reloc->r_index[2] = r_index;
|
|---|
| 186 | reloc->r_type[0] =
|
|---|
| 187 | ((r_extern ? RELOC_STD_BITS_EXTERN_BIG : 0)
|
|---|
| 188 | | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG : 0)
|
|---|
| 189 | | (r_neg ? RELOC_ARM_BITS_NEG_BIG : 0)
|
|---|
| 190 | | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG));
|
|---|
| 191 | }
|
|---|
| 192 | else
|
|---|
| 193 | {
|
|---|
| 194 | reloc->r_index[2] = r_index >> 16;
|
|---|
| 195 | reloc->r_index[1] = r_index >> 8;
|
|---|
| 196 | reloc->r_index[0] = r_index;
|
|---|
| 197 | reloc->r_type[0] =
|
|---|
| 198 | ((r_extern ? RELOC_STD_BITS_EXTERN_LITTLE : 0)
|
|---|
| 199 | | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE : 0)
|
|---|
| 200 | | (r_neg ? RELOC_ARM_BITS_NEG_LITTLE : 0)
|
|---|
| 201 | | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE));
|
|---|
| 202 | }
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | #define MY_put_reloc(BFD, EXT, IDX, VAL, HOWTO, RELOC) \
|
|---|
| 206 | MY(put_reloc) (BFD, EXT, IDX, VAL, HOWTO, RELOC)
|
|---|
| 207 |
|
|---|
| 208 | void
|
|---|
| 209 | MY(relocatable_reloc) (howto, abfd, reloc, amount, r_addr)
|
|---|
| 210 | reloc_howto_type *howto;
|
|---|
| 211 | bfd *abfd;
|
|---|
| 212 | struct reloc_std_external *reloc;
|
|---|
| 213 | bfd_vma *amount;
|
|---|
| 214 | bfd_vma r_addr;
|
|---|
| 215 | {
|
|---|
| 216 | if (howto->type == 3)
|
|---|
| 217 | {
|
|---|
| 218 | if (reloc->r_type[0]
|
|---|
| 219 | & (bfd_header_big_endian (abfd)
|
|---|
| 220 | ? RELOC_STD_BITS_EXTERN_BIG : RELOC_STD_BITS_EXTERN_LITTLE))
|
|---|
| 221 | {
|
|---|
| 222 | /* The reloc is still external, so don't modify anything. */
|
|---|
| 223 | *amount = 0;
|
|---|
| 224 | }
|
|---|
| 225 | else
|
|---|
| 226 | {
|
|---|
| 227 | *amount -= r_addr;
|
|---|
| 228 | /* Change the r_pcrel value -- on the ARM, this bit is set once the
|
|---|
| 229 | relocation is done. */
|
|---|
| 230 | if (bfd_header_big_endian (abfd))
|
|---|
| 231 | reloc->r_type[0] |= RELOC_STD_BITS_PCREL_BIG;
|
|---|
| 232 | else
|
|---|
| 233 | reloc->r_type[0] |= RELOC_STD_BITS_PCREL_LITTLE;
|
|---|
| 234 | }
|
|---|
| 235 | }
|
|---|
| 236 | else if (howto->type == 7)
|
|---|
| 237 | *amount = 0;
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | #define MY_relocatable_reloc(HOW, BFD, REL, AMOUNT, ADDR) \
|
|---|
| 241 | MY(relocatable_reloc) (HOW, BFD, REL, &(AMOUNT), ADDR)
|
|---|
| 242 |
|
|---|
| 243 | static bfd_reloc_status_type
|
|---|
| 244 | MY(fix_pcrel_26_done) (abfd, reloc_entry, symbol, data, input_section,
|
|---|
| 245 | output_bfd, error_message)
|
|---|
| 246 | bfd *abfd ATTRIBUTE_UNUSED;
|
|---|
| 247 | arelent *reloc_entry ATTRIBUTE_UNUSED;
|
|---|
| 248 | asymbol *symbol ATTRIBUTE_UNUSED;
|
|---|
| 249 | PTR data ATTRIBUTE_UNUSED;
|
|---|
| 250 | asection *input_section ATTRIBUTE_UNUSED;
|
|---|
| 251 | bfd *output_bfd ATTRIBUTE_UNUSED;
|
|---|
| 252 | char **error_message ATTRIBUTE_UNUSED;
|
|---|
| 253 | {
|
|---|
| 254 | /* This is dead simple at present. */
|
|---|
| 255 | return bfd_reloc_ok;
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | static bfd_reloc_status_type
|
|---|
| 259 | MY(fix_pcrel_26) (abfd, reloc_entry, symbol, data, input_section,
|
|---|
| 260 | output_bfd, error_message)
|
|---|
| 261 | bfd *abfd;
|
|---|
| 262 | arelent *reloc_entry;
|
|---|
| 263 | asymbol *symbol;
|
|---|
| 264 | PTR data;
|
|---|
| 265 | asection *input_section;
|
|---|
| 266 | bfd *output_bfd;
|
|---|
| 267 | char **error_message ATTRIBUTE_UNUSED;
|
|---|
| 268 | {
|
|---|
| 269 | bfd_vma relocation;
|
|---|
| 270 | bfd_size_type addr = reloc_entry->address;
|
|---|
| 271 | bfd_vma target = bfd_get_32 (abfd, (bfd_byte *) data + addr);
|
|---|
| 272 | bfd_reloc_status_type flag = bfd_reloc_ok;
|
|---|
| 273 |
|
|---|
| 274 | /* If this is an undefined symbol, return error. */
|
|---|
| 275 | if (symbol->section == &bfd_und_section
|
|---|
| 276 | && (symbol->flags & BSF_WEAK) == 0)
|
|---|
| 277 | return output_bfd ? bfd_reloc_ok : bfd_reloc_undefined;
|
|---|
| 278 |
|
|---|
| 279 | /* If the sections are different, and we are doing a partial relocation,
|
|---|
| 280 | just ignore it for now. */
|
|---|
| 281 | if (symbol->section->name != input_section->name
|
|---|
| 282 | && output_bfd != (bfd *)NULL)
|
|---|
| 283 | return bfd_reloc_ok;
|
|---|
| 284 |
|
|---|
| 285 | relocation = (target & 0x00ffffff) << 2;
|
|---|
| 286 | relocation = (relocation ^ 0x02000000) - 0x02000000; /* Sign extend. */
|
|---|
| 287 | relocation += symbol->value;
|
|---|
| 288 | relocation += symbol->section->output_section->vma;
|
|---|
| 289 | relocation += symbol->section->output_offset;
|
|---|
| 290 | relocation += reloc_entry->addend;
|
|---|
| 291 | relocation -= input_section->output_section->vma;
|
|---|
| 292 | relocation -= input_section->output_offset;
|
|---|
| 293 | relocation -= addr;
|
|---|
| 294 | if (relocation & 3)
|
|---|
| 295 | return bfd_reloc_overflow;
|
|---|
| 296 |
|
|---|
| 297 | /* Check for overflow. */
|
|---|
| 298 | if (relocation & 0x02000000)
|
|---|
| 299 | {
|
|---|
| 300 | if ((relocation & ~ (bfd_vma) 0x03ffffff) != ~ (bfd_vma) 0x03ffffff)
|
|---|
| 301 | flag = bfd_reloc_overflow;
|
|---|
| 302 | }
|
|---|
| 303 | else if (relocation & ~ (bfd_vma) 0x03ffffff)
|
|---|
| 304 | flag = bfd_reloc_overflow;
|
|---|
| 305 |
|
|---|
| 306 | target &= ~ (bfd_vma) 0x00ffffff;
|
|---|
| 307 | target |= (relocation >> 2) & 0x00ffffff;
|
|---|
| 308 | bfd_put_32 (abfd, target, (bfd_byte *) data + addr);
|
|---|
| 309 |
|
|---|
| 310 | /* Now the ARM magic... Change the reloc type so that it is marked as done.
|
|---|
| 311 | Strictly this is only necessary if we are doing a partial relocation. */
|
|---|
| 312 | reloc_entry->howto = &MY(howto_table)[7];
|
|---|
| 313 |
|
|---|
| 314 | return flag;
|
|---|
| 315 | }
|
|---|
| 316 |
|
|---|
| 317 | reloc_howto_type *
|
|---|
| 318 | MY(bfd_reloc_type_lookup) (abfd,code)
|
|---|
| 319 | bfd *abfd;
|
|---|
| 320 | bfd_reloc_code_real_type code;
|
|---|
| 321 | {
|
|---|
| 322 | #define ASTD(i,j) case i: return &MY(howto_table)[j]
|
|---|
| 323 | if (code == BFD_RELOC_CTOR)
|
|---|
| 324 | switch (bfd_get_arch_info (abfd)->bits_per_address)
|
|---|
| 325 | {
|
|---|
| 326 | case 32:
|
|---|
| 327 | code = BFD_RELOC_32;
|
|---|
| 328 | break;
|
|---|
| 329 | default:
|
|---|
| 330 | return (const struct reloc_howto_struct *) 0;
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | switch (code)
|
|---|
| 334 | {
|
|---|
| 335 | ASTD (BFD_RELOC_16, 1);
|
|---|
| 336 | ASTD (BFD_RELOC_32, 2);
|
|---|
| 337 | ASTD (BFD_RELOC_ARM_PCREL_BRANCH, 3);
|
|---|
| 338 | ASTD (BFD_RELOC_8_PCREL, 4);
|
|---|
| 339 | ASTD (BFD_RELOC_16_PCREL, 5);
|
|---|
| 340 | ASTD (BFD_RELOC_32_PCREL, 6);
|
|---|
| 341 | default:
|
|---|
| 342 | return (const struct reloc_howto_struct *) 0;
|
|---|
| 343 | }
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 | #define MY_swap_std_reloc_in MY(swap_std_reloc_in)
|
|---|
| 347 | #define MY_swap_std_reloc_out MY(swap_std_reloc_out)
|
|---|
| 348 | #define MY_get_section_contents _bfd_generic_get_section_contents
|
|---|
| 349 | /* #define MY_bfd_link_hash_table_create _bfd_generic_link_hash_table_create */
|
|---|
| 350 | /* #define MY_bfd_link_add_symbols _bfd_generic_link_add_symbols */
|
|---|
| 351 | /* #define MY_bfd_final_link _bfd_generic_final_link */
|
|---|
| 352 |
|
|---|
| 353 | #include "aoutx.h"
|
|---|
| 354 |
|
|---|
| 355 | static void
|
|---|
| 356 | MY_swap_std_reloc_in (abfd, bytes, cache_ptr, symbols, symcount)
|
|---|
| 357 | bfd *abfd;
|
|---|
| 358 | struct reloc_std_external *bytes;
|
|---|
| 359 | arelent *cache_ptr;
|
|---|
| 360 | asymbol **symbols;
|
|---|
| 361 | bfd_size_type symcount ATTRIBUTE_UNUSED;
|
|---|
| 362 | {
|
|---|
| 363 | int r_index;
|
|---|
| 364 | int r_extern;
|
|---|
| 365 | int r_pcrel;
|
|---|
| 366 | struct aoutdata *su = &(abfd->tdata.aout_data->a);
|
|---|
| 367 |
|
|---|
| 368 | cache_ptr->address = H_GET_32 (abfd, bytes->r_address);
|
|---|
| 369 |
|
|---|
| 370 | cache_ptr->howto = MY_reloc_howto (abfd, bytes, r_index, r_extern, r_pcrel);
|
|---|
| 371 |
|
|---|
| 372 | MOVE_ADDRESS (0);
|
|---|
| 373 | }
|
|---|
| 374 |
|
|---|
| 375 | void
|
|---|
| 376 | MY_swap_std_reloc_out (abfd, g, natptr)
|
|---|
| 377 | bfd *abfd;
|
|---|
| 378 | arelent *g;
|
|---|
| 379 | struct reloc_std_external *natptr;
|
|---|
| 380 | {
|
|---|
| 381 | int r_index;
|
|---|
| 382 | asymbol *sym = *(g->sym_ptr_ptr);
|
|---|
| 383 | int r_extern;
|
|---|
| 384 | int r_length;
|
|---|
| 385 | int r_pcrel;
|
|---|
| 386 | int r_neg = 0; /* Negative relocs use the BASEREL bit. */
|
|---|
| 387 | asection *output_section = sym->section->output_section;
|
|---|
| 388 |
|
|---|
| 389 | PUT_WORD(abfd, g->address, natptr->r_address);
|
|---|
| 390 |
|
|---|
| 391 | r_length = g->howto->size ; /* Size as a power of two */
|
|---|
| 392 | if (r_length < 0)
|
|---|
| 393 | {
|
|---|
| 394 | r_length = -r_length;
|
|---|
| 395 | r_neg = 1;
|
|---|
| 396 | }
|
|---|
| 397 |
|
|---|
| 398 | r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */
|
|---|
| 399 |
|
|---|
| 400 | /* For RISC iX, in pc-relative relocs the r_pcrel bit means that the
|
|---|
| 401 | relocation has been done already (Only for the 26-bit one I think)???!!!
|
|---|
| 402 | */
|
|---|
| 403 |
|
|---|
| 404 | if (g->howto->type == 3)
|
|---|
| 405 | {
|
|---|
| 406 | r_length = 3;
|
|---|
| 407 | r_pcrel = 0;
|
|---|
| 408 | }
|
|---|
| 409 | else if (g->howto->type == 7)
|
|---|
| 410 | {
|
|---|
| 411 | r_length = 3;
|
|---|
| 412 | r_pcrel = 1;
|
|---|
| 413 | }
|
|---|
| 414 |
|
|---|
| 415 | #if 0
|
|---|
| 416 | /* For a standard reloc, the addend is in the object file. */
|
|---|
| 417 | r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma;
|
|---|
| 418 | #endif
|
|---|
| 419 |
|
|---|
| 420 | /* name was clobbered by aout_write_syms to be symbol index */
|
|---|
| 421 |
|
|---|
| 422 | /* If this relocation is relative to a symbol then set the
|
|---|
| 423 | r_index to the symbols index, and the r_extern bit.
|
|---|
| 424 |
|
|---|
| 425 | Absolute symbols can come in in two ways, either as an offset
|
|---|
| 426 | from the abs section, or as a symbol which has an abs value.
|
|---|
| 427 | check for that here
|
|---|
| 428 | */
|
|---|
| 429 |
|
|---|
| 430 | if (bfd_is_com_section (output_section)
|
|---|
| 431 | || output_section == &bfd_abs_section
|
|---|
| 432 | || output_section == &bfd_und_section)
|
|---|
| 433 | {
|
|---|
| 434 | if (bfd_abs_section.symbol == sym)
|
|---|
| 435 | {
|
|---|
| 436 | /* Whoops, looked like an abs symbol, but is really an offset
|
|---|
| 437 | from the abs section. */
|
|---|
| 438 | r_index = 0;
|
|---|
| 439 | r_extern = 0;
|
|---|
| 440 | }
|
|---|
| 441 | else
|
|---|
| 442 | {
|
|---|
| 443 | /* Fill in symbol. */
|
|---|
| 444 | r_extern = 1;
|
|---|
| 445 | r_index = (*(g->sym_ptr_ptr))->KEEPIT;
|
|---|
| 446 | }
|
|---|
| 447 | }
|
|---|
| 448 | else
|
|---|
| 449 | {
|
|---|
| 450 | /* Just an ordinary section. */
|
|---|
| 451 | r_extern = 0;
|
|---|
| 452 | r_index = output_section->target_index;
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | /* Now the fun stuff. */
|
|---|
| 456 | if (bfd_header_big_endian (abfd))
|
|---|
| 457 | {
|
|---|
| 458 | natptr->r_index[0] = r_index >> 16;
|
|---|
| 459 | natptr->r_index[1] = r_index >> 8;
|
|---|
| 460 | natptr->r_index[2] = r_index;
|
|---|
| 461 | natptr->r_type[0] =
|
|---|
| 462 | ( (r_extern ? RELOC_STD_BITS_EXTERN_BIG: 0)
|
|---|
| 463 | | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG: 0)
|
|---|
| 464 | | (r_neg ? RELOC_ARM_BITS_NEG_BIG: 0)
|
|---|
| 465 | | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG));
|
|---|
| 466 | }
|
|---|
| 467 | else
|
|---|
| 468 | {
|
|---|
| 469 | natptr->r_index[2] = r_index >> 16;
|
|---|
| 470 | natptr->r_index[1] = r_index >> 8;
|
|---|
| 471 | natptr->r_index[0] = r_index;
|
|---|
| 472 | natptr->r_type[0] =
|
|---|
| 473 | ( (r_extern ? RELOC_STD_BITS_EXTERN_LITTLE: 0)
|
|---|
| 474 | | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE: 0)
|
|---|
| 475 | | (r_neg ? RELOC_ARM_BITS_NEG_LITTLE: 0)
|
|---|
| 476 | | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE));
|
|---|
| 477 | }
|
|---|
| 478 | }
|
|---|
| 479 |
|
|---|
| 480 | #define MY_BFD_TARGET
|
|---|
| 481 |
|
|---|
| 482 | #include "aout-target.h"
|
|---|
| 483 |
|
|---|
| 484 | extern const bfd_target aout_arm_big_vec;
|
|---|
| 485 |
|
|---|
| 486 | const bfd_target aout_arm_little_vec =
|
|---|
| 487 | {
|
|---|
| 488 | "a.out-arm-little", /* name */
|
|---|
| 489 | bfd_target_aout_flavour,
|
|---|
| 490 | BFD_ENDIAN_LITTLE, /* target byte order (little) */
|
|---|
| 491 | BFD_ENDIAN_LITTLE, /* target headers byte order (little) */
|
|---|
| 492 | (HAS_RELOC | EXEC_P | /* object flags */
|
|---|
| 493 | HAS_LINENO | HAS_DEBUG |
|
|---|
| 494 | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
|
|---|
| 495 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA),
|
|---|
| 496 | MY_symbol_leading_char,
|
|---|
| 497 | AR_PAD_CHAR, /* ar_pad_char */
|
|---|
| 498 | 15, /* ar_max_namelen */
|
|---|
| 499 | bfd_getl64, bfd_getl_signed_64, bfd_putl64,
|
|---|
| 500 | bfd_getl32, bfd_getl_signed_32, bfd_putl32,
|
|---|
| 501 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
|
|---|
| 502 | bfd_getl64, bfd_getl_signed_64, bfd_putl64,
|
|---|
| 503 | bfd_getl32, bfd_getl_signed_32, bfd_putl32,
|
|---|
| 504 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
|
|---|
| 505 | {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
|
|---|
| 506 | bfd_generic_archive_p, MY_core_file_p},
|
|---|
| 507 | {bfd_false, MY_mkobject, /* bfd_set_format */
|
|---|
| 508 | _bfd_generic_mkarchive, bfd_false},
|
|---|
| 509 | {bfd_false, MY_write_object_contents, /* bfd_write_contents */
|
|---|
| 510 | _bfd_write_archive_contents, bfd_false},
|
|---|
| 511 |
|
|---|
| 512 | BFD_JUMP_TABLE_GENERIC (MY),
|
|---|
| 513 | BFD_JUMP_TABLE_COPY (MY),
|
|---|
| 514 | BFD_JUMP_TABLE_CORE (MY),
|
|---|
| 515 | BFD_JUMP_TABLE_ARCHIVE (MY),
|
|---|
| 516 | BFD_JUMP_TABLE_SYMBOLS (MY),
|
|---|
| 517 | BFD_JUMP_TABLE_RELOCS (MY),
|
|---|
| 518 | BFD_JUMP_TABLE_WRITE (MY),
|
|---|
| 519 | BFD_JUMP_TABLE_LINK (MY),
|
|---|
| 520 | BFD_JUMP_TABLE_DYNAMIC (MY),
|
|---|
| 521 |
|
|---|
| 522 | & aout_arm_big_vec,
|
|---|
| 523 |
|
|---|
| 524 | (PTR) MY_backend_data,
|
|---|
| 525 | };
|
|---|
| 526 |
|
|---|
| 527 | const bfd_target aout_arm_big_vec =
|
|---|
| 528 | {
|
|---|
| 529 | "a.out-arm-big", /* name */
|
|---|
| 530 | bfd_target_aout_flavour,
|
|---|
| 531 | BFD_ENDIAN_BIG, /* target byte order (big) */
|
|---|
| 532 | BFD_ENDIAN_BIG, /* target headers byte order (big) */
|
|---|
| 533 | (HAS_RELOC | EXEC_P | /* object flags */
|
|---|
| 534 | HAS_LINENO | HAS_DEBUG |
|
|---|
| 535 | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
|
|---|
| 536 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA),
|
|---|
| 537 | MY_symbol_leading_char,
|
|---|
| 538 | AR_PAD_CHAR, /* ar_pad_char */
|
|---|
| 539 | 15, /* ar_max_namelen */
|
|---|
| 540 | bfd_getb64, bfd_getb_signed_64, bfd_putb64,
|
|---|
| 541 | bfd_getb32, bfd_getb_signed_32, bfd_putb32,
|
|---|
| 542 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
|
|---|
| 543 | bfd_getb64, bfd_getb_signed_64, bfd_putb64,
|
|---|
| 544 | bfd_getb32, bfd_getb_signed_32, bfd_putb32,
|
|---|
| 545 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
|
|---|
| 546 | {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
|
|---|
| 547 | bfd_generic_archive_p, MY_core_file_p},
|
|---|
| 548 | {bfd_false, MY_mkobject, /* bfd_set_format */
|
|---|
| 549 | _bfd_generic_mkarchive, bfd_false},
|
|---|
| 550 | {bfd_false, MY_write_object_contents, /* bfd_write_contents */
|
|---|
| 551 | _bfd_write_archive_contents, bfd_false},
|
|---|
| 552 |
|
|---|
| 553 | BFD_JUMP_TABLE_GENERIC (MY),
|
|---|
| 554 | BFD_JUMP_TABLE_COPY (MY),
|
|---|
| 555 | BFD_JUMP_TABLE_CORE (MY),
|
|---|
| 556 | BFD_JUMP_TABLE_ARCHIVE (MY),
|
|---|
| 557 | BFD_JUMP_TABLE_SYMBOLS (MY),
|
|---|
| 558 | BFD_JUMP_TABLE_RELOCS (MY),
|
|---|
| 559 | BFD_JUMP_TABLE_WRITE (MY),
|
|---|
| 560 | BFD_JUMP_TABLE_LINK (MY),
|
|---|
| 561 | BFD_JUMP_TABLE_DYNAMIC (MY),
|
|---|
| 562 |
|
|---|
| 563 | & aout_arm_little_vec,
|
|---|
| 564 |
|
|---|
| 565 | (PTR) MY_backend_data,
|
|---|
| 566 | };
|
|---|