1 1.1 christos /* BFD back-end for ALPHA Extended-Coff files. 2 1.1.1.11 christos Copyright (C) 1993-2025 Free Software Foundation, Inc. 3 1.1 christos Modified from coff-mips.c by Steve Chamberlain <sac (at) cygnus.com> and 4 1.1 christos Ian Lance Taylor <ian (at) cygnus.com>. 5 1.1 christos 6 1.1 christos This file is part of BFD, the Binary File Descriptor library. 7 1.1 christos 8 1.1 christos This program is free software; you can redistribute it and/or modify 9 1.1 christos it under the terms of the GNU General Public License as published by 10 1.1 christos the Free Software Foundation; either version 3 of the License, or 11 1.1 christos (at your option) any later version. 12 1.1 christos 13 1.1 christos This program is distributed in the hope that it will be useful, 14 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 15 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 1.1 christos GNU General Public License for more details. 17 1.1 christos 18 1.1 christos You should have received a copy of the GNU General Public License 19 1.1 christos along with this program; if not, write to the Free Software 20 1.1 christos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 21 1.1 christos MA 02110-1301, USA. */ 22 1.1 christos 23 1.1 christos #include "sysdep.h" 24 1.1 christos #include "bfd.h" 25 1.1 christos #include "bfdlink.h" 26 1.1 christos #include "libbfd.h" 27 1.1 christos #include "coff/internal.h" 28 1.1 christos #include "coff/sym.h" 29 1.1 christos #include "coff/symconst.h" 30 1.1 christos #include "coff/ecoff.h" 31 1.1 christos #include "coff/alpha.h" 32 1.1 christos #include "aout/ar.h" 33 1.1 christos #include "libcoff.h" 34 1.1 christos #include "libecoff.h" 35 1.1 christos 36 1.1 christos /* Prototypes for static functions. */ 38 1.1.1.2 christos 39 1.1 christos 40 1.1 christos 41 1.1 christos /* ECOFF has COFF sections, but the debugging information is stored in 43 1.1 christos a completely different format. ECOFF targets use some of the 44 1.1 christos swapping routines from coffswap.h, and some of the generic COFF 45 1.1 christos routines in coffgen.c, but, unlike the real COFF targets, do not 46 1.1 christos use coffcode.h itself. 47 1.1 christos 48 1.1 christos Get the generic COFF swapping routines, except for the reloc, 49 1.1 christos symbol, and lineno ones. Give them ecoff names. Define some 50 1.1 christos accessor macros for the large sizes used for Alpha ECOFF. */ 51 1.1 christos 52 1.1 christos #define GET_FILEHDR_SYMPTR H_GET_64 53 1.1 christos #define PUT_FILEHDR_SYMPTR H_PUT_64 54 1.1 christos #define GET_AOUTHDR_TSIZE H_GET_64 55 1.1 christos #define PUT_AOUTHDR_TSIZE H_PUT_64 56 1.1 christos #define GET_AOUTHDR_DSIZE H_GET_64 57 1.1 christos #define PUT_AOUTHDR_DSIZE H_PUT_64 58 1.1 christos #define GET_AOUTHDR_BSIZE H_GET_64 59 1.1 christos #define PUT_AOUTHDR_BSIZE H_PUT_64 60 1.1 christos #define GET_AOUTHDR_ENTRY H_GET_64 61 1.1 christos #define PUT_AOUTHDR_ENTRY H_PUT_64 62 1.1 christos #define GET_AOUTHDR_TEXT_START H_GET_64 63 1.1 christos #define PUT_AOUTHDR_TEXT_START H_PUT_64 64 1.1 christos #define GET_AOUTHDR_DATA_START H_GET_64 65 1.1 christos #define PUT_AOUTHDR_DATA_START H_PUT_64 66 1.1 christos #define GET_SCNHDR_PADDR H_GET_64 67 1.1 christos #define PUT_SCNHDR_PADDR H_PUT_64 68 1.1 christos #define GET_SCNHDR_VADDR H_GET_64 69 1.1 christos #define PUT_SCNHDR_VADDR H_PUT_64 70 1.1 christos #define GET_SCNHDR_SIZE H_GET_64 71 1.1 christos #define PUT_SCNHDR_SIZE H_PUT_64 72 1.1 christos #define GET_SCNHDR_SCNPTR H_GET_64 73 1.1 christos #define PUT_SCNHDR_SCNPTR H_PUT_64 74 1.1 christos #define GET_SCNHDR_RELPTR H_GET_64 75 1.1 christos #define PUT_SCNHDR_RELPTR H_PUT_64 76 1.1 christos #define GET_SCNHDR_LNNOPTR H_GET_64 77 1.1 christos #define PUT_SCNHDR_LNNOPTR H_PUT_64 78 1.1 christos 79 1.1 christos #define ALPHAECOFF 80 1.1 christos 81 1.1 christos #define NO_COFF_RELOCS 82 1.1 christos #define NO_COFF_SYMBOLS 83 1.1 christos #define NO_COFF_LINENOS 84 1.1 christos #define coff_swap_filehdr_in alpha_ecoff_swap_filehdr_in 85 1.1 christos #define coff_swap_filehdr_out alpha_ecoff_swap_filehdr_out 86 1.1 christos #define coff_swap_aouthdr_in alpha_ecoff_swap_aouthdr_in 87 1.1 christos #define coff_swap_aouthdr_out alpha_ecoff_swap_aouthdr_out 88 1.1 christos #define coff_swap_scnhdr_in alpha_ecoff_swap_scnhdr_in 89 1.1 christos #define coff_swap_scnhdr_out alpha_ecoff_swap_scnhdr_out 90 1.1 christos #include "coffswap.h" 91 1.1 christos 92 1.1 christos /* Get the ECOFF swapping routines. */ 93 1.1 christos #define ECOFF_64 94 1.1 christos #include "ecoffswap.h" 95 1.1 christos 96 1.1 christos /* How to process the various reloc types. */ 98 1.1.1.2 christos 99 1.1.1.2 christos static bfd_reloc_status_type 100 1.1.1.2 christos reloc_nil (bfd *abfd ATTRIBUTE_UNUSED, 101 1.1.1.2 christos arelent *reloc ATTRIBUTE_UNUSED, 102 1.1.1.2 christos asymbol *sym ATTRIBUTE_UNUSED, 103 1.1.1.2 christos void * data ATTRIBUTE_UNUSED, 104 1.1 christos asection *sec ATTRIBUTE_UNUSED, 105 1.1 christos bfd *output_bfd ATTRIBUTE_UNUSED, 106 1.1 christos char **error_message ATTRIBUTE_UNUSED) 107 1.1 christos { 108 1.1 christos return bfd_reloc_ok; 109 1.1 christos } 110 1.1 christos 111 1.1 christos /* In case we're on a 32-bit machine, construct a 64-bit "-1" value 112 1.1 christos from smaller values. Start with zero, widen, *then* decrement. */ 113 1.1 christos #define MINUS_ONE (((bfd_vma)0) - 1) 114 1.1 christos 115 1.1 christos static reloc_howto_type alpha_howto_table[] = 116 1.1 christos { 117 1.1 christos /* Reloc type 0 is ignored by itself. However, it appears after a 118 1.1 christos GPDISP reloc to identify the location where the low order 16 bits 119 1.1.1.8 christos of the gp register are loaded. */ 120 1.1 christos HOWTO (ALPHA_R_IGNORE, /* type */ 121 1.1.1.8 christos 0, /* rightshift */ 122 1.1 christos 1, /* size */ 123 1.1 christos 8, /* bitsize */ 124 1.1 christos true, /* pc_relative */ 125 1.1 christos 0, /* bitpos */ 126 1.1.1.8 christos complain_overflow_dont, /* complain_on_overflow */ 127 1.1 christos reloc_nil, /* special_function */ 128 1.1 christos "IGNORE", /* name */ 129 1.1.1.8 christos true, /* partial_inplace */ 130 1.1 christos 0, /* src_mask */ 131 1.1 christos 0, /* dst_mask */ 132 1.1 christos true), /* pcrel_offset */ 133 1.1 christos 134 1.1.1.8 christos /* A 32 bit reference to a symbol. */ 135 1.1 christos HOWTO (ALPHA_R_REFLONG, /* type */ 136 1.1.1.8 christos 0, /* rightshift */ 137 1.1 christos 4, /* size */ 138 1.1 christos 32, /* bitsize */ 139 1.1 christos false, /* pc_relative */ 140 1.1 christos 0, /* bitpos */ 141 1.1.1.8 christos complain_overflow_bitfield, /* complain_on_overflow */ 142 1.1 christos 0, /* special_function */ 143 1.1 christos "REFLONG", /* name */ 144 1.1.1.8 christos true, /* partial_inplace */ 145 1.1 christos 0xffffffff, /* src_mask */ 146 1.1 christos 0xffffffff, /* dst_mask */ 147 1.1 christos false), /* pcrel_offset */ 148 1.1 christos 149 1.1.1.8 christos /* A 64 bit reference to a symbol. */ 150 1.1 christos HOWTO (ALPHA_R_REFQUAD, /* type */ 151 1.1.1.8 christos 0, /* rightshift */ 152 1.1 christos 8, /* size */ 153 1.1 christos 64, /* bitsize */ 154 1.1 christos false, /* pc_relative */ 155 1.1 christos 0, /* bitpos */ 156 1.1.1.8 christos complain_overflow_bitfield, /* complain_on_overflow */ 157 1.1 christos 0, /* special_function */ 158 1.1 christos "REFQUAD", /* name */ 159 1.1.1.8 christos true, /* partial_inplace */ 160 1.1 christos MINUS_ONE, /* src_mask */ 161 1.1 christos MINUS_ONE, /* dst_mask */ 162 1.1 christos false), /* pcrel_offset */ 163 1.1 christos 164 1.1 christos /* A 32 bit GP relative offset. This is just like REFLONG except 165 1.1 christos that when the value is used the value of the gp register will be 166 1.1.1.8 christos added in. */ 167 1.1 christos HOWTO (ALPHA_R_GPREL32, /* type */ 168 1.1.1.8 christos 0, /* rightshift */ 169 1.1 christos 4, /* size */ 170 1.1 christos 32, /* bitsize */ 171 1.1 christos false, /* pc_relative */ 172 1.1 christos 0, /* bitpos */ 173 1.1.1.8 christos complain_overflow_bitfield, /* complain_on_overflow */ 174 1.1 christos 0, /* special_function */ 175 1.1 christos "GPREL32", /* name */ 176 1.1.1.8 christos true, /* partial_inplace */ 177 1.1 christos 0xffffffff, /* src_mask */ 178 1.1 christos 0xffffffff, /* dst_mask */ 179 1.1 christos false), /* pcrel_offset */ 180 1.1 christos 181 1.1 christos /* Used for an instruction that refers to memory off the GP 182 1.1 christos register. The offset is 16 bits of the 32 bit instruction. This 183 1.1.1.8 christos reloc always seems to be against the .lita section. */ 184 1.1 christos HOWTO (ALPHA_R_LITERAL, /* type */ 185 1.1.1.8 christos 0, /* rightshift */ 186 1.1 christos 4, /* size */ 187 1.1 christos 16, /* bitsize */ 188 1.1 christos false, /* pc_relative */ 189 1.1 christos 0, /* bitpos */ 190 1.1.1.8 christos complain_overflow_signed, /* complain_on_overflow */ 191 1.1 christos 0, /* special_function */ 192 1.1 christos "LITERAL", /* name */ 193 1.1.1.8 christos true, /* partial_inplace */ 194 1.1 christos 0xffff, /* src_mask */ 195 1.1 christos 0xffff, /* dst_mask */ 196 1.1 christos false), /* pcrel_offset */ 197 1.1 christos 198 1.1 christos /* This reloc only appears immediately following a LITERAL reloc. 199 1.1 christos It identifies a use of the literal. It seems that the linker can 200 1.1 christos use this to eliminate a portion of the .lita section. The symbol 201 1.1 christos index is special: 1 means the literal address is in the base 202 1.1 christos register of a memory format instruction; 2 means the literal 203 1.1 christos address is in the byte offset register of a byte-manipulation 204 1.1 christos instruction; 3 means the literal address is in the target 205 1.1 christos register of a jsr instruction. This does not actually do any 206 1.1.1.8 christos relocation. */ 207 1.1 christos HOWTO (ALPHA_R_LITUSE, /* type */ 208 1.1.1.8 christos 0, /* rightshift */ 209 1.1 christos 4, /* size */ 210 1.1 christos 32, /* bitsize */ 211 1.1 christos false, /* pc_relative */ 212 1.1 christos 0, /* bitpos */ 213 1.1.1.8 christos complain_overflow_dont, /* complain_on_overflow */ 214 1.1 christos reloc_nil, /* special_function */ 215 1.1 christos "LITUSE", /* name */ 216 1.1.1.8 christos false, /* partial_inplace */ 217 1.1 christos 0, /* src_mask */ 218 1.1 christos 0, /* dst_mask */ 219 1.1 christos false), /* pcrel_offset */ 220 1.1 christos 221 1.1 christos /* Load the gp register. This is always used for a ldah instruction 222 1.1 christos which loads the upper 16 bits of the gp register. The next reloc 223 1.1 christos will be an IGNORE reloc which identifies the location of the lda 224 1.1 christos instruction which loads the lower 16 bits. The symbol index of 225 1.1 christos the GPDISP instruction appears to actually be the number of bytes 226 1.1 christos between the ldah and lda instructions. This gives two different 227 1.1 christos ways to determine where the lda instruction is; I don't know why 228 1.1 christos both are used. The value to use for the relocation is the 229 1.1 christos difference between the GP value and the current location; the 230 1.1 christos load will always be done against a register holding the current 231 1.1.1.8 christos address. */ 232 1.1 christos HOWTO (ALPHA_R_GPDISP, /* type */ 233 1.1.1.8 christos 16, /* rightshift */ 234 1.1 christos 4, /* size */ 235 1.1 christos 16, /* bitsize */ 236 1.1 christos true, /* pc_relative */ 237 1.1 christos 0, /* bitpos */ 238 1.1.1.8 christos complain_overflow_dont, /* complain_on_overflow */ 239 1.1 christos reloc_nil, /* special_function */ 240 1.1 christos "GPDISP", /* name */ 241 1.1.1.8 christos true, /* partial_inplace */ 242 1.1 christos 0xffff, /* src_mask */ 243 1.1 christos 0xffff, /* dst_mask */ 244 1.1 christos true), /* pcrel_offset */ 245 1.1 christos 246 1.1 christos /* A 21 bit branch. The native assembler generates these for 247 1.1 christos branches within the text segment, and also fills in the PC 248 1.1.1.8 christos relative offset in the instruction. */ 249 1.1 christos HOWTO (ALPHA_R_BRADDR, /* type */ 250 1.1.1.8 christos 2, /* rightshift */ 251 1.1 christos 4, /* size */ 252 1.1 christos 21, /* bitsize */ 253 1.1 christos true, /* pc_relative */ 254 1.1 christos 0, /* bitpos */ 255 1.1.1.8 christos complain_overflow_signed, /* complain_on_overflow */ 256 1.1 christos 0, /* special_function */ 257 1.1 christos "BRADDR", /* name */ 258 1.1.1.8 christos true, /* partial_inplace */ 259 1.1 christos 0x1fffff, /* src_mask */ 260 1.1 christos 0x1fffff, /* dst_mask */ 261 1.1 christos false), /* pcrel_offset */ 262 1.1 christos 263 1.1.1.8 christos /* A hint for a jump to a register. */ 264 1.1 christos HOWTO (ALPHA_R_HINT, /* type */ 265 1.1.1.8 christos 2, /* rightshift */ 266 1.1 christos 4, /* size */ 267 1.1 christos 14, /* bitsize */ 268 1.1 christos true, /* pc_relative */ 269 1.1 christos 0, /* bitpos */ 270 1.1.1.8 christos complain_overflow_dont, /* complain_on_overflow */ 271 1.1 christos 0, /* special_function */ 272 1.1 christos "HINT", /* name */ 273 1.1.1.8 christos true, /* partial_inplace */ 274 1.1 christos 0x3fff, /* src_mask */ 275 1.1 christos 0x3fff, /* dst_mask */ 276 1.1 christos false), /* pcrel_offset */ 277 1.1 christos 278 1.1.1.8 christos /* 16 bit PC relative offset. */ 279 1.1 christos HOWTO (ALPHA_R_SREL16, /* type */ 280 1.1.1.8 christos 0, /* rightshift */ 281 1.1 christos 2, /* size */ 282 1.1 christos 16, /* bitsize */ 283 1.1 christos true, /* pc_relative */ 284 1.1 christos 0, /* bitpos */ 285 1.1.1.8 christos complain_overflow_signed, /* complain_on_overflow */ 286 1.1 christos 0, /* special_function */ 287 1.1 christos "SREL16", /* name */ 288 1.1.1.8 christos true, /* partial_inplace */ 289 1.1 christos 0xffff, /* src_mask */ 290 1.1 christos 0xffff, /* dst_mask */ 291 1.1 christos false), /* pcrel_offset */ 292 1.1 christos 293 1.1.1.8 christos /* 32 bit PC relative offset. */ 294 1.1 christos HOWTO (ALPHA_R_SREL32, /* type */ 295 1.1.1.8 christos 0, /* rightshift */ 296 1.1 christos 4, /* size */ 297 1.1 christos 32, /* bitsize */ 298 1.1 christos true, /* pc_relative */ 299 1.1 christos 0, /* bitpos */ 300 1.1.1.8 christos complain_overflow_signed, /* complain_on_overflow */ 301 1.1 christos 0, /* special_function */ 302 1.1 christos "SREL32", /* name */ 303 1.1.1.8 christos true, /* partial_inplace */ 304 1.1 christos 0xffffffff, /* src_mask */ 305 1.1 christos 0xffffffff, /* dst_mask */ 306 1.1 christos false), /* pcrel_offset */ 307 1.1 christos 308 1.1.1.8 christos /* A 64 bit PC relative offset. */ 309 1.1 christos HOWTO (ALPHA_R_SREL64, /* type */ 310 1.1.1.8 christos 0, /* rightshift */ 311 1.1 christos 8, /* size */ 312 1.1 christos 64, /* bitsize */ 313 1.1 christos true, /* pc_relative */ 314 1.1 christos 0, /* bitpos */ 315 1.1.1.8 christos complain_overflow_signed, /* complain_on_overflow */ 316 1.1 christos 0, /* special_function */ 317 1.1 christos "SREL64", /* name */ 318 1.1.1.8 christos true, /* partial_inplace */ 319 1.1 christos MINUS_ONE, /* src_mask */ 320 1.1 christos MINUS_ONE, /* dst_mask */ 321 1.1 christos false), /* pcrel_offset */ 322 1.1 christos 323 1.1.1.8 christos /* Push a value on the reloc evaluation stack. */ 324 1.1 christos HOWTO (ALPHA_R_OP_PUSH, /* type */ 325 1.1.1.8 christos 0, /* rightshift */ 326 1.1 christos 0, /* size */ 327 1.1 christos 0, /* bitsize */ 328 1.1 christos false, /* pc_relative */ 329 1.1 christos 0, /* bitpos */ 330 1.1.1.8 christos complain_overflow_dont, /* complain_on_overflow */ 331 1.1 christos 0, /* special_function */ 332 1.1 christos "OP_PUSH", /* name */ 333 1.1.1.8 christos false, /* partial_inplace */ 334 1.1 christos 0, /* src_mask */ 335 1.1 christos 0, /* dst_mask */ 336 1.1 christos false), /* pcrel_offset */ 337 1.1 christos 338 1.1 christos /* Store the value from the stack at the given address. Store it in 339 1.1.1.8 christos a bitfield of size r_size starting at bit position r_offset. */ 340 1.1 christos HOWTO (ALPHA_R_OP_STORE, /* type */ 341 1.1.1.8 christos 0, /* rightshift */ 342 1.1 christos 8, /* size */ 343 1.1 christos 64, /* bitsize */ 344 1.1 christos false, /* pc_relative */ 345 1.1 christos 0, /* bitpos */ 346 1.1.1.8 christos complain_overflow_dont, /* complain_on_overflow */ 347 1.1 christos 0, /* special_function */ 348 1.1 christos "OP_STORE", /* name */ 349 1.1.1.8 christos false, /* partial_inplace */ 350 1.1 christos 0, /* src_mask */ 351 1.1 christos MINUS_ONE, /* dst_mask */ 352 1.1 christos false), /* pcrel_offset */ 353 1.1 christos 354 1.1 christos /* Subtract the reloc address from the value on the top of the 355 1.1.1.8 christos relocation stack. */ 356 1.1 christos HOWTO (ALPHA_R_OP_PSUB, /* type */ 357 1.1.1.8 christos 0, /* rightshift */ 358 1.1 christos 0, /* size */ 359 1.1 christos 0, /* bitsize */ 360 1.1 christos false, /* pc_relative */ 361 1.1 christos 0, /* bitpos */ 362 1.1.1.8 christos complain_overflow_dont, /* complain_on_overflow */ 363 1.1 christos 0, /* special_function */ 364 1.1 christos "OP_PSUB", /* name */ 365 1.1.1.8 christos false, /* partial_inplace */ 366 1.1 christos 0, /* src_mask */ 367 1.1 christos 0, /* dst_mask */ 368 1.1 christos false), /* pcrel_offset */ 369 1.1 christos 370 1.1 christos /* Shift the value on the top of the relocation stack right by the 371 1.1.1.8 christos given value. */ 372 1.1 christos HOWTO (ALPHA_R_OP_PRSHIFT, /* type */ 373 1.1.1.8 christos 0, /* rightshift */ 374 1.1 christos 0, /* size */ 375 1.1 christos 0, /* bitsize */ 376 1.1 christos false, /* pc_relative */ 377 1.1 christos 0, /* bitpos */ 378 1.1.1.8 christos complain_overflow_dont, /* complain_on_overflow */ 379 1.1 christos 0, /* special_function */ 380 1.1 christos "OP_PRSHIFT", /* name */ 381 1.1.1.8 christos false, /* partial_inplace */ 382 1.1 christos 0, /* src_mask */ 383 1.1 christos 0, /* dst_mask */ 384 1.1 christos false), /* pcrel_offset */ 385 1.1 christos 386 1.1.1.8 christos /* Adjust the GP value for a new range in the object file. */ 387 1.1 christos HOWTO (ALPHA_R_GPVALUE, /* type */ 388 1.1.1.8 christos 0, /* rightshift */ 389 1.1 christos 0, /* size */ 390 1.1 christos 0, /* bitsize */ 391 1.1 christos false, /* pc_relative */ 392 1.1 christos 0, /* bitpos */ 393 1.1.1.8 christos complain_overflow_dont, /* complain_on_overflow */ 394 1.1 christos 0, /* special_function */ 395 1.1 christos "GPVALUE", /* name */ 396 1.1.1.8 christos false, /* partial_inplace */ 397 1.1 christos 0, /* src_mask */ 398 1.1 christos 0, /* dst_mask */ 399 1.1 christos false) /* pcrel_offset */ 400 1.1 christos }; 401 1.1.1.7 christos 402 1.1.1.2 christos /* Recognize an Alpha ECOFF file. */ 404 1.1.1.7 christos 405 1.1 christos static bfd_cleanup 406 1.1 christos alpha_ecoff_object_p (bfd *abfd) 407 1.1 christos { 408 1.1 christos bfd_cleanup ret; 409 1.1 christos 410 1.1 christos ret = coff_object_p (abfd); 411 1.1 christos 412 1.1 christos if (ret != NULL) 413 1.1 christos { 414 1.1 christos asection *sec; 415 1.1 christos 416 1.1 christos /* Alpha ECOFF has a .pdata section. The lnnoptr field of the 417 1.1 christos .pdata section is the number of entries it contains. Each 418 1.1 christos entry takes up 8 bytes. The number of entries is required 419 1.1 christos since the section is aligned to a 16 byte boundary. When we 420 1.1 christos link .pdata sections together, we do not want to include the 421 1.1 christos alignment bytes. We handle this on input by faking the size 422 1.1 christos of the .pdata section to remove the unwanted alignment bytes. 423 1.1 christos On output we will set the lnnoptr field and force the 424 1.1 christos alignment. */ 425 1.1 christos sec = bfd_get_section_by_name (abfd, _PDATA); 426 1.1.1.7 christos if (sec != (asection *) NULL) 427 1.1 christos { 428 1.1 christos bfd_size_type size; 429 1.1.1.7 christos 430 1.1 christos size = (bfd_size_type) sec->line_filepos * 8; 431 1.1 christos BFD_ASSERT (size == sec->size 432 1.1 christos || size + 8 == sec->size); 433 1.1 christos if (!bfd_set_section_size (sec, size)) 434 1.1 christos return NULL; 435 1.1 christos } 436 1.1 christos } 437 1.1 christos 438 1.1 christos return ret; 439 1.1.1.8 christos } 440 1.1.1.2 christos 441 1.1.1.2 christos /* See whether the magic number matches. */ 442 1.1 christos 443 1.1 christos static bool 444 1.1 christos alpha_ecoff_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, 445 1.1 christos void * filehdr) 446 1.1.1.8 christos { 447 1.1 christos struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; 448 1.1 christos 449 1.1.1.5 christos if (! ALPHA_ECOFF_BADMAG (*internal_f)) 450 1.1.1.6 christos return true; 451 1.1.1.6 christos 452 1.1 christos if (ALPHA_ECOFF_COMPRESSEDMAG (*internal_f)) 453 1.1 christos _bfd_error_handler 454 1.1.1.8 christos (_("%pB: cannot handle compressed Alpha binaries; " 455 1.1 christos "use compiler flags, or objZ, to generate uncompressed binaries"), 456 1.1 christos abfd); 457 1.1 christos 458 1.1 christos return false; 459 1.1 christos } 460 1.1.1.2 christos 461 1.1.1.2 christos /* This is a hook called by coff_real_object_p to create any backend 462 1.1 christos specific information. */ 463 1.1.1.2 christos 464 1.1 christos static void * 465 1.1 christos alpha_ecoff_mkobject_hook (bfd *abfd, void * filehdr, void * aouthdr) 466 1.1 christos { 467 1.1 christos void * ecoff; 468 1.1 christos 469 1.1 christos ecoff = _bfd_ecoff_mkobject_hook (abfd, filehdr, aouthdr); 470 1.1 christos 471 1.1 christos if (ecoff != NULL) 472 1.1 christos { 473 1.1 christos struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; 474 1.1 christos 475 1.1 christos /* Set additional BFD flags according to the object type from the 476 1.1 christos machine specific file header flags. */ 477 1.1 christos switch (internal_f->f_flags & F_ALPHA_OBJECT_TYPE_MASK) 478 1.1 christos { 479 1.1 christos case F_ALPHA_SHARABLE: 480 1.1 christos abfd->flags |= DYNAMIC; 481 1.1 christos break; 482 1.1 christos case F_ALPHA_CALL_SHARED: 483 1.1 christos /* Always executable if using shared libraries as the run time 484 1.1 christos loader might resolve undefined references. */ 485 1.1 christos abfd->flags |= (DYNAMIC | EXEC_P); 486 1.1 christos break; 487 1.1 christos } 488 1.1 christos } 489 1.1 christos return ecoff; 490 1.1 christos } 491 1.1 christos 492 1.1 christos /* Reloc handling. */ 494 1.1.1.2 christos 495 1.1.1.2 christos /* Swap a reloc in. */ 496 1.1 christos 497 1.1 christos static void 498 1.1 christos alpha_ecoff_swap_reloc_in (bfd *abfd, 499 1.1 christos void * ext_ptr, 500 1.1 christos struct internal_reloc *intern) 501 1.1 christos { 502 1.1 christos const RELOC *ext = (RELOC *) ext_ptr; 503 1.1 christos 504 1.1 christos intern->r_vaddr = H_GET_64 (abfd, ext->r_vaddr); 505 1.1 christos intern->r_symndx = H_GET_32 (abfd, ext->r_symndx); 506 1.1 christos 507 1.1 christos BFD_ASSERT (bfd_header_little_endian (abfd)); 508 1.1 christos 509 1.1 christos intern->r_type = ((ext->r_bits[0] & RELOC_BITS0_TYPE_LITTLE) 510 1.1 christos >> RELOC_BITS0_TYPE_SH_LITTLE); 511 1.1 christos intern->r_extern = (ext->r_bits[1] & RELOC_BITS1_EXTERN_LITTLE) != 0; 512 1.1 christos intern->r_offset = ((ext->r_bits[1] & RELOC_BITS1_OFFSET_LITTLE) 513 1.1 christos >> RELOC_BITS1_OFFSET_SH_LITTLE); 514 1.1 christos /* Ignored the reserved bits. */ 515 1.1 christos intern->r_size = ((ext->r_bits[3] & RELOC_BITS3_SIZE_LITTLE) 516 1.1 christos >> RELOC_BITS3_SIZE_SH_LITTLE); 517 1.1 christos 518 1.1 christos if (intern->r_type == ALPHA_R_LITUSE 519 1.1 christos || intern->r_type == ALPHA_R_GPDISP) 520 1.1.1.11 christos { 521 1.1 christos /* Handle the LITUSE and GPDISP relocs specially. Its symndx 522 1.1 christos value is not actually a symbol index, but is instead a 523 1.1 christos special code. We put the code in the r_size field, and 524 1.1 christos clobber the symndx. */ 525 1.1 christos BFD_ASSERT (intern->r_size == 0); 526 1.1 christos intern->r_size = intern->r_symndx; 527 1.1 christos intern->r_symndx = RELOC_SECTION_NONE; 528 1.1.1.11 christos } 529 1.1 christos else if (intern->r_type == ALPHA_R_IGNORE) 530 1.1 christos { 531 1.1 christos /* The IGNORE reloc generally follows a GPDISP reloc, and is 532 1.1.1.11 christos against the .lita section. The section is irrelevant. */ 533 1.1.1.11 christos BFD_ASSERT (intern->r_extern || intern->r_symndx != RELOC_SECTION_ABS); 534 1.1.1.11 christos if (! intern->r_extern && intern->r_symndx == RELOC_SECTION_LITA) 535 1.1.1.11 christos intern->r_symndx = RELOC_SECTION_ABS; 536 1.1.1.11 christos } 537 1.1.1.11 christos else if (intern->r_type == ALPHA_R_OP_STORE) 538 1.1 christos { 539 1.1 christos /* Size of 64 bits is encoded as 0 in this 6-bit field. */ 540 1.1 christos if (intern->r_size == 0) 541 1.1 christos intern->r_size = 64; 542 1.1 christos } 543 1.1.1.2 christos } 544 1.1.1.2 christos 545 1.1.1.2 christos /* Swap a reloc out. */ 546 1.1 christos 547 1.1 christos static void 548 1.1 christos alpha_ecoff_swap_reloc_out (bfd *abfd, 549 1.1 christos const struct internal_reloc *intern, 550 1.1 christos void * dst) 551 1.1 christos { 552 1.1 christos RELOC *ext = (RELOC *) dst; 553 1.1 christos long symndx; 554 1.1 christos unsigned char size; 555 1.1 christos 556 1.1 christos /* Undo the hackery done in swap_reloc_in. */ 557 1.1 christos if (intern->r_type == ALPHA_R_LITUSE 558 1.1 christos || intern->r_type == ALPHA_R_GPDISP) 559 1.1 christos { 560 1.1 christos symndx = intern->r_size; 561 1.1 christos size = 0; 562 1.1 christos } 563 1.1 christos else if (intern->r_type == ALPHA_R_IGNORE 564 1.1 christos && ! intern->r_extern 565 1.1 christos && intern->r_symndx == RELOC_SECTION_ABS) 566 1.1 christos { 567 1.1 christos symndx = RELOC_SECTION_LITA; 568 1.1 christos size = intern->r_size; 569 1.1 christos } 570 1.1 christos else 571 1.1 christos { 572 1.1 christos symndx = intern->r_symndx; 573 1.1 christos size = intern->r_size; 574 1.1 christos } 575 1.1 christos 576 1.1 christos /* XXX FIXME: The maximum symndx value used to be 14 but this 577 1.1 christos fails with object files produced by DEC's C++ compiler. 578 1.1 christos Where does the value 14 (or 15) come from anyway ? */ 579 1.1 christos BFD_ASSERT (intern->r_extern 580 1.1 christos || (intern->r_symndx >= 0 && intern->r_symndx <= 15)); 581 1.1 christos 582 1.1 christos H_PUT_64 (abfd, intern->r_vaddr, ext->r_vaddr); 583 1.1 christos H_PUT_32 (abfd, symndx, ext->r_symndx); 584 1.1 christos 585 1.1 christos BFD_ASSERT (bfd_header_little_endian (abfd)); 586 1.1 christos 587 1.1 christos ext->r_bits[0] = ((intern->r_type << RELOC_BITS0_TYPE_SH_LITTLE) 588 1.1 christos & RELOC_BITS0_TYPE_LITTLE); 589 1.1 christos ext->r_bits[1] = ((intern->r_extern ? RELOC_BITS1_EXTERN_LITTLE : 0) 590 1.1 christos | ((intern->r_offset << RELOC_BITS1_OFFSET_SH_LITTLE) 591 1.1 christos & RELOC_BITS1_OFFSET_LITTLE)); 592 1.1 christos ext->r_bits[2] = 0; 593 1.1 christos ext->r_bits[3] = ((size << RELOC_BITS3_SIZE_SH_LITTLE) 594 1.1 christos & RELOC_BITS3_SIZE_LITTLE); 595 1.1 christos } 596 1.1 christos 597 1.1.1.2 christos /* Finish canonicalizing a reloc. Part of this is generic to all 598 1.1.1.2 christos ECOFF targets, and that part is in ecoff.c. The rest is done in 599 1.1.1.2 christos this backend routine. It must fill in the howto field. */ 600 1.1 christos 601 1.1 christos static void 602 1.1 christos alpha_adjust_reloc_in (bfd *abfd, 603 1.1.1.5 christos const struct internal_reloc *intern, 604 1.1.1.6 christos arelent *rptr) 605 1.1.1.6 christos { 606 1.1 christos if (intern->r_type > ALPHA_R_GPVALUE) 607 1.1 christos { 608 1.1 christos /* xgettext:c-format */ 609 1.1 christos _bfd_error_handler (_("%pB: unsupported relocation type %#x"), 610 1.1 christos abfd, intern->r_type); 611 1.1 christos bfd_set_error (bfd_error_bad_value); 612 1.1 christos rptr->addend = 0; 613 1.1 christos rptr->howto = NULL; 614 1.1 christos return; 615 1.1 christos } 616 1.1 christos 617 1.1 christos switch (intern->r_type) 618 1.1 christos { 619 1.1.1.6 christos case ALPHA_R_BRADDR: 620 1.1.1.6 christos case ALPHA_R_SREL16: 621 1.1 christos case ALPHA_R_SREL32: 622 1.1 christos case ALPHA_R_SREL64: 623 1.1 christos /* This relocs appear to be fully resolved when they are against 624 1.1 christos internal symbols. Against external symbols, BRADDR at least 625 1.1 christos appears to be resolved against the next instruction. */ 626 1.1 christos if (! intern->r_extern) 627 1.1 christos rptr->addend = 0; 628 1.1 christos else 629 1.1 christos rptr->addend = - (intern->r_vaddr + 4); 630 1.1 christos break; 631 1.1 christos 632 1.1 christos case ALPHA_R_GPREL32: 633 1.1 christos case ALPHA_R_LITERAL: 634 1.1 christos /* Copy the gp value for this object file into the addend, to 635 1.1 christos ensure that we are not confused by the linker. */ 636 1.1 christos if (! intern->r_extern) 637 1.1 christos rptr->addend += ecoff_data (abfd)->gp; 638 1.1 christos break; 639 1.1 christos 640 1.1 christos case ALPHA_R_LITUSE: 641 1.1 christos case ALPHA_R_GPDISP: 642 1.1 christos /* The LITUSE and GPDISP relocs do not use a symbol, or an 643 1.1 christos addend, but they do use a special code. Put this code in the 644 1.1 christos addend field. */ 645 1.1 christos rptr->addend = intern->r_size; 646 1.1 christos break; 647 1.1 christos 648 1.1 christos case ALPHA_R_OP_STORE: 649 1.1 christos /* The STORE reloc needs the size and offset fields. We store 650 1.1 christos them in the addend. */ 651 1.1 christos BFD_ASSERT (intern->r_offset <= 256); 652 1.1 christos rptr->addend = (intern->r_offset << 8) + intern->r_size; 653 1.1 christos break; 654 1.1 christos 655 1.1 christos case ALPHA_R_OP_PUSH: 656 1.1 christos case ALPHA_R_OP_PSUB: 657 1.1 christos case ALPHA_R_OP_PRSHIFT: 658 1.1 christos /* The PUSH, PSUB and PRSHIFT relocs do not actually use an 659 1.1 christos address. I believe that the address supplied is really an 660 1.1 christos addend. */ 661 1.1 christos rptr->addend = intern->r_vaddr; 662 1.1 christos break; 663 1.1 christos 664 1.1 christos case ALPHA_R_GPVALUE: 665 1.1 christos /* Set the addend field to the new GP value. */ 666 1.1 christos rptr->addend = intern->r_symndx + ecoff_data (abfd)->gp; 667 1.1 christos break; 668 1.1 christos 669 1.1 christos case ALPHA_R_IGNORE: 670 1.1.1.10 christos /* If the type is ALPHA_R_IGNORE, make sure this is a reference 671 1.1 christos to the absolute section so that the reloc is ignored. For 672 1.1 christos some reason the address of this reloc type is not adjusted by 673 1.1 christos the section vma. We record the gp value for this object file 674 1.1 christos here, for convenience when doing the GPDISP relocation. */ 675 1.1 christos rptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol; 676 1.1 christos rptr->address = intern->r_vaddr; 677 1.1 christos rptr->addend = ecoff_data (abfd)->gp; 678 1.1 christos break; 679 1.1 christos 680 1.1 christos default: 681 1.1 christos break; 682 1.1 christos } 683 1.1 christos 684 1.1 christos rptr->howto = &alpha_howto_table[intern->r_type]; 685 1.1 christos } 686 1.1 christos 687 1.1 christos /* When writing out a reloc we need to pull some values back out of 688 1.1.1.2 christos the addend field into the reloc. This is roughly the reverse of 689 1.1.1.2 christos alpha_adjust_reloc_in, except that there are several changes we do 690 1.1.1.2 christos not need to undo. */ 691 1.1 christos 692 1.1 christos static void 693 1.1 christos alpha_adjust_reloc_out (bfd *abfd ATTRIBUTE_UNUSED, 694 1.1 christos const arelent *rel, 695 1.1 christos struct internal_reloc *intern) 696 1.1 christos { 697 1.1 christos switch (intern->r_type) 698 1.1 christos { 699 1.1 christos case ALPHA_R_LITUSE: 700 1.1 christos case ALPHA_R_GPDISP: 701 1.1 christos intern->r_size = rel->addend; 702 1.1 christos break; 703 1.1 christos 704 1.1 christos case ALPHA_R_OP_STORE: 705 1.1 christos intern->r_size = rel->addend & 0xff; 706 1.1 christos intern->r_offset = (rel->addend >> 8) & 0xff; 707 1.1 christos break; 708 1.1 christos 709 1.1 christos case ALPHA_R_OP_PUSH: 710 1.1 christos case ALPHA_R_OP_PSUB: 711 1.1 christos case ALPHA_R_OP_PRSHIFT: 712 1.1 christos intern->r_vaddr = rel->addend; 713 1.1 christos break; 714 1.1 christos 715 1.1 christos case ALPHA_R_IGNORE: 716 1.1 christos intern->r_vaddr = rel->address; 717 1.1 christos break; 718 1.1 christos 719 1.1.1.11 christos default: 720 1.1.1.11 christos break; 721 1.1.1.11 christos } 722 1.1.1.11 christos } 723 1.1.1.11 christos 724 1.1.1.11 christos /* Write VAL to a little-endian bitfield specified by BITOFFSET and 725 1.1.1.11 christos BITSIZE at CONTENTS + SECOFFSET. Verify that these parameter are 726 1.1.1.11 christos valid for SEC in ABFD. */ 727 1.1.1.11 christos 728 1.1.1.11 christos static bool 729 1.1.1.11 christos write_bit_field (bfd *abfd, asection *sec, 730 1.1.1.11 christos bfd_byte *contents, bfd_size_type secoffset, 731 1.1.1.11 christos unsigned int bitoffset, unsigned int bitsize, uint64_t val) 732 1.1.1.11 christos { 733 1.1.1.11 christos if (bitsize == 0) 734 1.1.1.11 christos return true; 735 1.1.1.11 christos 736 1.1.1.11 christos bfd_size_type secsize = bfd_get_section_limit_octets (abfd, sec); 737 1.1.1.11 christos unsigned int startbyte = bitoffset >> 3; 738 1.1.1.11 christos unsigned int endbyte = (bitoffset + bitsize - 1) >> 3; 739 1.1.1.11 christos 740 1.1.1.11 christos if (secoffset > secsize || secsize - secoffset <= endbyte) 741 1.1.1.11 christos return false; 742 1.1.1.11 christos 743 1.1.1.11 christos unsigned int startbit = bitoffset & 7; 744 1.1.1.11 christos unsigned int endbit = (bitoffset + bitsize - 1) & 7; 745 1.1.1.11 christos unsigned int mask = -1u << startbit; 746 1.1.1.11 christos unsigned char *p = contents + secoffset; 747 1.1.1.11 christos if (startbyte != endbyte) 748 1.1.1.11 christos { 749 1.1.1.11 christos p[startbyte] = (p[startbyte] & ~mask) | ((val << startbit) & mask); 750 1.1.1.11 christos val = val >> (8 - startbit); 751 1.1.1.11 christos 752 1.1.1.11 christos for (unsigned int off = startbyte + 1; off < endbyte; ++off) 753 1.1.1.11 christos { 754 1.1.1.11 christos p[off] = val; 755 1.1.1.11 christos val >>= 8; 756 1.1.1.11 christos } 757 1.1.1.11 christos mask = ~(-1u << (1 + endbit)); 758 1.1.1.11 christos } 759 1.1.1.11 christos else 760 1.1.1.11 christos { 761 1.1.1.11 christos val = val << startbit; 762 1.1.1.11 christos mask = mask & ~(-1u << (1 + endbit)); 763 1.1 christos } 764 1.1 christos p[endbyte] = (p[endbyte] & ~mask) | (val & mask); 765 1.1 christos return true; 766 1.1 christos } 767 1.1 christos 768 1.1 christos /* The size of the stack for the relocation evaluator. */ 769 1.1 christos #define RELOC_STACKSIZE (10) 770 1.1 christos 771 1.1 christos /* Alpha ECOFF relocs have a built in expression evaluator as well as 772 1.1 christos other interdependencies. Rather than use a bunch of special 773 1.1.1.2 christos functions and global variables, we use a single routine to do all 774 1.1.1.2 christos the relocation for a section. I haven't yet worked out how the 775 1.1.1.2 christos assembler is going to handle this. */ 776 1.1.1.2 christos 777 1.1.1.8 christos static bfd_byte * 778 1.1.1.2 christos alpha_ecoff_get_relocated_section_contents (bfd *abfd, 779 1.1 christos struct bfd_link_info *link_info, 780 1.1 christos struct bfd_link_order *link_order, 781 1.1 christos bfd_byte *data, 782 1.1.1.8 christos bool relocatable, 783 1.1.1.8 christos asymbol **symbols) 784 1.1 christos { 785 1.1 christos bfd *input_bfd = link_order->u.indirect.section->owner; 786 1.1 christos asection *input_section = link_order->u.indirect.section; 787 1.1.1.8 christos long reloc_size; 788 1.1 christos arelent **reloc_vector; 789 1.1 christos long reloc_count; 790 1.1 christos bfd *output_bfd = relocatable ? abfd : (bfd *) NULL; 791 1.1.1.8 christos bfd_vma gp; 792 1.1 christos bool gp_undefined; 793 1.1.1.8 christos bfd_vma stack[RELOC_STACKSIZE]; 794 1.1.1.8 christos int tos = 0; 795 1.1.1.8 christos 796 1.1.1.8 christos reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section); 797 1.1.1.8 christos if (reloc_size < 0) 798 1.1.1.8 christos return NULL; 799 1.1.1.8 christos 800 1.1.1.8 christos bfd_byte *orig_data = data; 801 1.1.1.8 christos if (!bfd_get_full_section_contents (input_bfd, input_section, &data)) 802 1.1.1.8 christos return NULL; 803 1.1.1.8 christos 804 1.1 christos if (data == NULL) 805 1.1.1.8 christos return NULL; 806 1.1.1.8 christos 807 1.1 christos if (reloc_size == 0) 808 1.1 christos return data; 809 1.1 christos 810 1.1 christos reloc_vector = (arelent **) bfd_malloc (reloc_size); 811 1.1 christos if (reloc_vector == NULL) 812 1.1 christos goto error_return; 813 1.1 christos 814 1.1 christos reloc_count = bfd_canonicalize_reloc (input_bfd, input_section, 815 1.1 christos reloc_vector, symbols); 816 1.1 christos if (reloc_count < 0) 817 1.1.1.8 christos goto error_return; 818 1.1 christos if (reloc_count == 0) 819 1.1 christos goto successful_return; 820 1.1 christos 821 1.1 christos /* Get the GP value for the output BFD. */ 822 1.1 christos gp_undefined = false; 823 1.1 christos gp = _bfd_get_gp_value (abfd); 824 1.1 christos if (gp == 0) 825 1.1 christos { 826 1.1 christos if (relocatable) 827 1.1 christos { 828 1.1 christos asection *sec; 829 1.1 christos bfd_vma lo; 830 1.1 christos 831 1.1 christos /* Make up a value. */ 832 1.1 christos lo = (bfd_vma) -1; 833 1.1 christos for (sec = abfd->sections; sec != NULL; sec = sec->next) 834 1.1 christos { 835 1.1 christos if (sec->vma < lo 836 1.1 christos && (strcmp (sec->name, ".sbss") == 0 837 1.1 christos || strcmp (sec->name, ".sdata") == 0 838 1.1 christos || strcmp (sec->name, ".lit4") == 0 839 1.1 christos || strcmp (sec->name, ".lit8") == 0 840 1.1 christos || strcmp (sec->name, ".lita") == 0)) 841 1.1 christos lo = sec->vma; 842 1.1 christos } 843 1.1 christos gp = lo + 0x8000; 844 1.1 christos _bfd_set_gp_value (abfd, gp); 845 1.1.1.8 christos } 846 1.1.1.8 christos else 847 1.1 christos { 848 1.1 christos struct bfd_link_hash_entry *h; 849 1.1.1.8 christos 850 1.1 christos h = bfd_link_hash_lookup (link_info->hash, "_gp", false, false, 851 1.1 christos true); 852 1.1 christos if (h == (struct bfd_link_hash_entry *) NULL 853 1.1 christos || h->type != bfd_link_hash_defined) 854 1.1 christos gp_undefined = true; 855 1.1 christos else 856 1.1 christos { 857 1.1 christos gp = (h->u.def.value 858 1.1 christos + h->u.def.section->output_section->vma 859 1.1 christos + h->u.def.section->output_offset); 860 1.1.1.9 christos _bfd_set_gp_value (abfd, gp); 861 1.1 christos } 862 1.1 christos } 863 1.1 christos } 864 1.1 christos 865 1.1.1.9 christos for (arelent **relp = reloc_vector; *relp != NULL; relp++) 866 1.1 christos { 867 1.1.1.9 christos arelent *rel; 868 1.1.1.9 christos bfd_reloc_status_type r; 869 1.1.1.9 christos char *err; 870 1.1.1.9 christos unsigned int r_type; 871 1.1.1.9 christos 872 1.1.1.9 christos rel = *relp; 873 1.1.1.9 christos if (rel->howto == NULL) 874 1.1.1.9 christos { 875 1.1.1.9 christos r = bfd_reloc_notsupported; 876 1.1.1.9 christos r_type = ALPHA_R_IGNORE; 877 1.1.1.9 christos } 878 1.1.1.9 christos else 879 1.1 christos { 880 1.1 christos r = bfd_reloc_ok; 881 1.1 christos r_type = rel->howto->type; 882 1.1 christos } 883 1.1 christos switch (r_type) 884 1.1 christos { 885 1.1 christos case ALPHA_R_IGNORE: 886 1.1 christos rel->address += input_section->output_offset; 887 1.1 christos break; 888 1.1 christos 889 1.1 christos case ALPHA_R_REFLONG: 890 1.1 christos case ALPHA_R_REFQUAD: 891 1.1 christos case ALPHA_R_BRADDR: 892 1.1 christos case ALPHA_R_HINT: 893 1.1 christos case ALPHA_R_SREL16: 894 1.1 christos case ALPHA_R_SREL32: 895 1.1 christos case ALPHA_R_SREL64: 896 1.1 christos if (relocatable 897 1.1 christos && ((*rel->sym_ptr_ptr)->flags & BSF_SECTION_SYM) == 0) 898 1.1 christos { 899 1.1 christos rel->address += input_section->output_offset; 900 1.1 christos break; 901 1.1 christos } 902 1.1 christos r = bfd_perform_relocation (input_bfd, rel, data, input_section, 903 1.1 christos output_bfd, &err); 904 1.1 christos break; 905 1.1 christos 906 1.1 christos case ALPHA_R_GPREL32: 907 1.1 christos /* This relocation is used in a switch table. It is a 32 908 1.1 christos bit offset from the current GP value. We must adjust it 909 1.1 christos by the different between the original GP value and the 910 1.1 christos current GP value. The original GP value is stored in the 911 1.1 christos addend. We adjust the addend and let 912 1.1 christos bfd_perform_relocation finish the job. */ 913 1.1 christos rel->addend -= gp; 914 1.1 christos r = bfd_perform_relocation (input_bfd, rel, data, input_section, 915 1.1 christos output_bfd, &err); 916 1.1 christos if (r == bfd_reloc_ok && gp_undefined) 917 1.1 christos { 918 1.1 christos r = bfd_reloc_dangerous; 919 1.1 christos err = (char *) _("GP relative relocation used when GP not defined"); 920 1.1 christos } 921 1.1 christos break; 922 1.1 christos 923 1.1 christos case ALPHA_R_LITERAL: 924 1.1 christos /* This is a reference to a literal value, generally 925 1.1 christos (always?) in the .lita section. This is a 16 bit GP 926 1.1 christos relative relocation. Sometimes the subsequent reloc is a 927 1.1 christos LITUSE reloc, which indicates how this reloc is used. 928 1.1 christos This sometimes permits rewriting the two instructions 929 1.1 christos referred to by the LITERAL and the LITUSE into different 930 1.1 christos instructions which do not refer to .lita. This can save 931 1.1 christos a memory reference, and permits removing a value from 932 1.1 christos .lita thus saving GP relative space. 933 1.1 christos 934 1.1 christos We do not these optimizations. To do them we would need 935 1.1.1.9 christos to arrange to link the .lita section first, so that by 936 1.1.1.9 christos the time we got here we would know the final values to 937 1.1.1.9 christos use. This would not be particularly difficult, but it is 938 1.1.1.9 christos not currently implemented. */ 939 1.1.1.9 christos 940 1.1.1.9 christos rel->addend -= gp; 941 1.1.1.9 christos r = bfd_perform_relocation (input_bfd, rel, data, input_section, 942 1.1.1.9 christos output_bfd, &err); 943 1.1.1.9 christos if (r == bfd_reloc_ok && gp_undefined) 944 1.1 christos { 945 1.1 christos r = bfd_reloc_dangerous; 946 1.1 christos err = (char *) _("GP relative relocation used" 947 1.1 christos " when GP not defined"); 948 1.1 christos } 949 1.1 christos break; 950 1.1 christos 951 1.1 christos case ALPHA_R_LITUSE: 952 1.1 christos /* See ALPHA_R_LITERAL above for the uses of this reloc. It 953 1.1 christos does not cause anything to happen, itself. */ 954 1.1 christos rel->address += input_section->output_offset; 955 1.1 christos break; 956 1.1 christos 957 1.1 christos case ALPHA_R_GPDISP: 958 1.1.1.9 christos /* This marks the ldah of an ldah/lda pair which loads the 959 1.1.1.9 christos gp register with the difference of the gp value and the 960 1.1.1.9 christos current location. The second of the pair is r_size bytes 961 1.1.1.9 christos ahead; it used to be marked with an ALPHA_R_IGNORE reloc, 962 1.1.1.9 christos but that no longer happens in OSF/1 3.2. */ 963 1.1.1.9 christos if (bfd_reloc_offset_in_range (rel->howto, input_bfd, input_section, 964 1.1.1.9 christos rel->address) 965 1.1.1.9 christos && bfd_reloc_offset_in_range (rel->howto, input_bfd, input_section, 966 1.1.1.9 christos rel->address + rel->addend)) 967 1.1.1.9 christos { 968 1.1.1.9 christos /* Get the two instructions. */ 969 1.1.1.9 christos bfd_byte *p = data + rel->address; 970 1.1.1.9 christos bfd_vma insn1 = bfd_get_32 (input_bfd, p); 971 1.1.1.9 christos bfd_vma insn2 = bfd_get_32 (input_bfd, p + rel->addend); 972 1.1.1.9 christos 973 1.1.1.9 christos BFD_ASSERT (((insn1 >> 26) & 0x3f) == 0x09); /* ldah */ 974 1.1.1.9 christos BFD_ASSERT (((insn2 >> 26) & 0x3f) == 0x08); /* lda */ 975 1.1.1.9 christos 976 1.1.1.9 christos /* Get the existing addend. We must account for the sign 977 1.1.1.9 christos extension done by lda and ldah. */ 978 1.1.1.9 christos bfd_vma addend = (((((insn1 & 0xffff) ^ 0x8000) - 0x8000) << 16) 979 1.1.1.9 christos + ((((insn2 & 0xffff) ^ 0x8000) - 0x8000))); 980 1.1.1.9 christos 981 1.1.1.9 christos /* The existing addend includes the different between the 982 1.1.1.9 christos gp of the input BFD and the address in the input BFD. 983 1.1.1.9 christos Subtract this out. */ 984 1.1.1.9 christos addend -= ecoff_data (input_bfd)->gp - input_section->vma; 985 1.1.1.9 christos 986 1.1.1.9 christos /* Now add in the final gp value, and subtract out the 987 1.1.1.9 christos final address. */ 988 1.1.1.9 christos addend += gp - (input_section->output_section->vma 989 1.1.1.9 christos + input_section->output_offset); 990 1.1 christos 991 1.1.1.9 christos /* Change the instructions, accounting for the sign 992 1.1.1.9 christos extension, and write them out. */ 993 1.1.1.9 christos insn1 = (insn1 & ~0xffff) | (((addend + 0x8000) >> 16) & 0xffff); 994 1.1.1.9 christos insn2 = (insn2 & ~0xffff) | (addend & 0xffff); 995 1.1.1.9 christos 996 1.1 christos bfd_put_32 (input_bfd, insn1, p); 997 1.1.1.9 christos bfd_put_32 (input_bfd, insn2, p + rel->addend); 998 1.1 christos } 999 1.1 christos else 1000 1.1 christos r = bfd_reloc_outofrange; 1001 1.1 christos 1002 1.1 christos rel->address += input_section->output_offset; 1003 1.1 christos break; 1004 1.1 christos 1005 1.1 christos case ALPHA_R_OP_PUSH: 1006 1.1 christos /* Push a value on the reloc evaluation stack. */ 1007 1.1 christos { 1008 1.1 christos asymbol *symbol; 1009 1.1 christos bfd_vma relocation; 1010 1.1 christos 1011 1.1 christos if (relocatable) 1012 1.1 christos { 1013 1.1 christos rel->address += input_section->output_offset; 1014 1.1 christos break; 1015 1.1 christos } 1016 1.1 christos 1017 1.1 christos /* Figure out the relocation of this symbol. */ 1018 1.1 christos symbol = *rel->sym_ptr_ptr; 1019 1.1 christos 1020 1.1 christos if (bfd_is_und_section (symbol->section)) 1021 1.1 christos r = bfd_reloc_undefined; 1022 1.1 christos 1023 1.1 christos if (bfd_is_com_section (symbol->section)) 1024 1.1 christos relocation = 0; 1025 1.1 christos else 1026 1.1 christos relocation = symbol->value; 1027 1.1.1.9 christos relocation += symbol->section->output_section->vma; 1028 1.1.1.9 christos relocation += symbol->section->output_offset; 1029 1.1.1.9 christos relocation += rel->addend; 1030 1.1.1.9 christos 1031 1.1 christos if (tos >= RELOC_STACKSIZE) 1032 1.1 christos { 1033 1.1 christos r = bfd_reloc_notsupported; 1034 1.1 christos break; 1035 1.1 christos } 1036 1.1 christos 1037 1.1 christos stack[tos++] = relocation; 1038 1.1 christos } 1039 1.1 christos break; 1040 1.1 christos 1041 1.1 christos case ALPHA_R_OP_STORE: 1042 1.1 christos /* Store a value from the reloc stack into a bitfield. */ 1043 1.1 christos { 1044 1.1 christos if (relocatable) 1045 1.1 christos { 1046 1.1.1.9 christos rel->address += input_section->output_offset; 1047 1.1.1.9 christos break; 1048 1.1.1.9 christos } 1049 1.1.1.9 christos 1050 1.1.1.9 christos if (tos == 0) 1051 1.1.1.9 christos { 1052 1.1.1.9 christos r = bfd_reloc_notsupported; 1053 1.1.1.9 christos break; 1054 1.1.1.9 christos } 1055 1.1.1.11 christos 1056 1.1.1.11 christos /* The offset and size in bits for this reloc are encoded 1057 1.1.1.11 christos into the addend field by alpha_adjust_reloc_in. */ 1058 1.1.1.11 christos unsigned int offset = (rel->addend >> 8) & 0xff; 1059 1.1.1.9 christos unsigned int size = rel->addend & 0xff; 1060 1.1 christos 1061 1.1 christos if (!write_bit_field (input_bfd, input_section, 1062 1.1 christos data, rel->address, 1063 1.1 christos offset, size, stack[--tos])) 1064 1.1 christos r = bfd_reloc_outofrange; 1065 1.1 christos } 1066 1.1 christos break; 1067 1.1 christos 1068 1.1 christos case ALPHA_R_OP_PSUB: 1069 1.1 christos /* Subtract a value from the top of the stack. */ 1070 1.1 christos { 1071 1.1 christos asymbol *symbol; 1072 1.1 christos bfd_vma relocation; 1073 1.1 christos 1074 1.1 christos if (relocatable) 1075 1.1 christos { 1076 1.1 christos rel->address += input_section->output_offset; 1077 1.1 christos break; 1078 1.1 christos } 1079 1.1 christos 1080 1.1 christos /* Figure out the relocation of this symbol. */ 1081 1.1 christos symbol = *rel->sym_ptr_ptr; 1082 1.1 christos 1083 1.1 christos if (bfd_is_und_section (symbol->section)) 1084 1.1 christos r = bfd_reloc_undefined; 1085 1.1 christos 1086 1.1 christos if (bfd_is_com_section (symbol->section)) 1087 1.1 christos relocation = 0; 1088 1.1 christos else 1089 1.1 christos relocation = symbol->value; 1090 1.1.1.9 christos relocation += symbol->section->output_section->vma; 1091 1.1.1.9 christos relocation += symbol->section->output_offset; 1092 1.1.1.9 christos relocation += rel->addend; 1093 1.1.1.9 christos 1094 1.1 christos if (tos == 0) 1095 1.1 christos { 1096 1.1 christos r = bfd_reloc_notsupported; 1097 1.1 christos break; 1098 1.1 christos } 1099 1.1 christos 1100 1.1 christos stack[tos - 1] -= relocation; 1101 1.1 christos } 1102 1.1 christos break; 1103 1.1 christos 1104 1.1 christos case ALPHA_R_OP_PRSHIFT: 1105 1.1 christos /* Shift the value on the top of the stack. */ 1106 1.1 christos { 1107 1.1 christos asymbol *symbol; 1108 1.1 christos bfd_vma relocation; 1109 1.1 christos 1110 1.1 christos if (relocatable) 1111 1.1 christos { 1112 1.1 christos rel->address += input_section->output_offset; 1113 1.1 christos break; 1114 1.1 christos } 1115 1.1 christos 1116 1.1 christos /* Figure out the relocation of this symbol. */ 1117 1.1 christos symbol = *rel->sym_ptr_ptr; 1118 1.1 christos 1119 1.1 christos if (bfd_is_und_section (symbol->section)) 1120 1.1 christos r = bfd_reloc_undefined; 1121 1.1 christos 1122 1.1 christos if (bfd_is_com_section (symbol->section)) 1123 1.1 christos relocation = 0; 1124 1.1 christos else 1125 1.1 christos relocation = symbol->value; 1126 1.1.1.9 christos relocation += symbol->section->output_section->vma; 1127 1.1.1.9 christos relocation += symbol->section->output_offset; 1128 1.1.1.9 christos relocation += rel->addend; 1129 1.1.1.9 christos 1130 1.1 christos if (tos == 0) 1131 1.1 christos { 1132 1.1 christos r = bfd_reloc_notsupported; 1133 1.1 christos break; 1134 1.1 christos } 1135 1.1 christos 1136 1.1 christos stack[tos - 1] >>= relocation; 1137 1.1 christos } 1138 1.1.1.8 christos break; 1139 1.1 christos 1140 1.1 christos case ALPHA_R_GPVALUE: 1141 1.1 christos /* I really don't know if this does the right thing. */ 1142 1.1.1.9 christos gp = rel->addend; 1143 1.1.1.9 christos gp_undefined = false; 1144 1.1 christos break; 1145 1.1 christos 1146 1.1 christos default: 1147 1.1 christos r = bfd_reloc_notsupported; 1148 1.1 christos break; 1149 1.1 christos } 1150 1.1 christos 1151 1.1 christos if (relocatable) 1152 1.1 christos { 1153 1.1 christos asection *os = input_section->output_section; 1154 1.1 christos 1155 1.1 christos /* A partial link, so keep the relocs. */ 1156 1.1 christos os->orelocation[os->reloc_count] = rel; 1157 1.1 christos os->reloc_count++; 1158 1.1 christos } 1159 1.1 christos 1160 1.1.1.4 christos if (r != bfd_reloc_ok) 1161 1.1.1.4 christos { 1162 1.1.1.8 christos switch (r) 1163 1.1 christos { 1164 1.1 christos case bfd_reloc_undefined: 1165 1.1.1.4 christos (*link_info->callbacks->undefined_symbol) 1166 1.1.1.4 christos (link_info, bfd_asymbol_name (*rel->sym_ptr_ptr), 1167 1.1 christos input_bfd, input_section, rel->address, true); 1168 1.1 christos break; 1169 1.1.1.4 christos case bfd_reloc_dangerous: 1170 1.1.1.4 christos (*link_info->callbacks->reloc_dangerous) 1171 1.1.1.4 christos (link_info, err, input_bfd, input_section, rel->address); 1172 1.1.1.4 christos break; 1173 1.1 christos case bfd_reloc_overflow: 1174 1.1 christos (*link_info->callbacks->reloc_overflow) 1175 1.1.1.9 christos (link_info, NULL, bfd_asymbol_name (*rel->sym_ptr_ptr), 1176 1.1.1.9 christos rel->howto->name, rel->addend, input_bfd, 1177 1.1.1.9 christos input_section, rel->address); 1178 1.1.1.9 christos break; 1179 1.1.1.9 christos case bfd_reloc_outofrange: 1180 1.1.1.9 christos (*link_info->callbacks->einfo) 1181 1.1.1.9 christos /* xgettext:c-format */ 1182 1.1.1.9 christos (_("%X%P: %pB(%pA): relocation \"%pR\" goes out of range\n"), 1183 1.1.1.9 christos input_bfd, input_section, rel); 1184 1.1.1.9 christos goto error_return; 1185 1.1.1.9 christos case bfd_reloc_notsupported: 1186 1.1 christos (*link_info->callbacks->einfo) 1187 1.1.1.9 christos /* xgettext:c-format */ 1188 1.1.1.9 christos (_("%X%P: %pB(%pA): relocation \"%pR\" is not supported\n"), 1189 1.1.1.9 christos input_bfd, input_section, rel); 1190 1.1.1.9 christos goto error_return; 1191 1.1.1.9 christos default: 1192 1.1 christos (*link_info->callbacks->einfo) 1193 1.1 christos /* xgettext:c-format */ 1194 1.1 christos (_("%X%P: %pB(%pA): relocation \"%pR\"" 1195 1.1 christos " returns an unrecognized value %x\n"), 1196 1.1 christos input_bfd, input_section, rel, r); 1197 1.1 christos break; 1198 1.1.1.9 christos } 1199 1.1 christos } 1200 1.1 christos } 1201 1.1.1.7 christos 1202 1.1 christos if (tos != 0) 1203 1.1 christos goto error_return; 1204 1.1 christos 1205 1.1.1.7 christos successful_return: 1206 1.1.1.8 christos free (reloc_vector); 1207 1.1.1.8 christos return data; 1208 1.1 christos 1209 1.1 christos error_return: 1210 1.1 christos free (reloc_vector); 1211 1.1 christos if (orig_data == NULL) 1212 1.1 christos free (data); 1213 1.1 christos return NULL; 1214 1.1.1.2 christos } 1215 1.1.1.2 christos 1216 1.1 christos /* Get the howto structure for a generic reloc type. */ 1217 1.1 christos 1218 1.1 christos static reloc_howto_type * 1219 1.1 christos alpha_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, 1220 1.1 christos bfd_reloc_code_real_type code) 1221 1.1 christos { 1222 1.1 christos int alpha_type; 1223 1.1 christos 1224 1.1 christos switch (code) 1225 1.1 christos { 1226 1.1 christos case BFD_RELOC_32: 1227 1.1 christos alpha_type = ALPHA_R_REFLONG; 1228 1.1 christos break; 1229 1.1 christos case BFD_RELOC_64: 1230 1.1 christos case BFD_RELOC_CTOR: 1231 1.1 christos alpha_type = ALPHA_R_REFQUAD; 1232 1.1 christos break; 1233 1.1 christos case BFD_RELOC_GPREL32: 1234 1.1 christos alpha_type = ALPHA_R_GPREL32; 1235 1.1 christos break; 1236 1.1 christos case BFD_RELOC_ALPHA_LITERAL: 1237 1.1 christos alpha_type = ALPHA_R_LITERAL; 1238 1.1 christos break; 1239 1.1 christos case BFD_RELOC_ALPHA_LITUSE: 1240 1.1 christos alpha_type = ALPHA_R_LITUSE; 1241 1.1 christos break; 1242 1.1 christos case BFD_RELOC_ALPHA_GPDISP_HI16: 1243 1.1 christos alpha_type = ALPHA_R_GPDISP; 1244 1.1 christos break; 1245 1.1 christos case BFD_RELOC_ALPHA_GPDISP_LO16: 1246 1.1 christos alpha_type = ALPHA_R_IGNORE; 1247 1.1 christos break; 1248 1.1 christos case BFD_RELOC_23_PCREL_S2: 1249 1.1 christos alpha_type = ALPHA_R_BRADDR; 1250 1.1 christos break; 1251 1.1 christos case BFD_RELOC_ALPHA_HINT: 1252 1.1 christos alpha_type = ALPHA_R_HINT; 1253 1.1 christos break; 1254 1.1 christos case BFD_RELOC_16_PCREL: 1255 1.1 christos alpha_type = ALPHA_R_SREL16; 1256 1.1 christos break; 1257 1.1 christos case BFD_RELOC_32_PCREL: 1258 1.1 christos alpha_type = ALPHA_R_SREL32; 1259 1.1 christos break; 1260 1.1 christos case BFD_RELOC_64_PCREL: 1261 1.1 christos alpha_type = ALPHA_R_SREL64; 1262 1.1 christos break; 1263 1.1 christos default: 1264 1.1 christos return (reloc_howto_type *) NULL; 1265 1.1 christos } 1266 1.1 christos 1267 1.1 christos return &alpha_howto_table[alpha_type]; 1268 1.1 christos } 1269 1.1 christos 1270 1.1 christos static reloc_howto_type * 1271 1.1 christos alpha_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, 1272 1.1 christos const char *r_name) 1273 1.1 christos { 1274 1.1 christos unsigned int i; 1275 1.1 christos 1276 1.1 christos for (i = 0; 1277 1.1 christos i < sizeof (alpha_howto_table) / sizeof (alpha_howto_table[0]); 1278 1.1 christos i++) 1279 1.1 christos if (alpha_howto_table[i].name != NULL 1280 1.1 christos && strcasecmp (alpha_howto_table[i].name, r_name) == 0) 1281 1.1 christos return &alpha_howto_table[i]; 1282 1.1 christos 1283 1.1 christos return NULL; 1284 1.1 christos } 1285 1.1 christos 1286 1.1.1.2 christos /* A helper routine for alpha_relocate_section which converts an 1288 1.1.1.2 christos external reloc when generating relocatable output. Returns the 1289 1.1.1.2 christos relocation amount. */ 1290 1.1.1.2 christos 1291 1.1 christos static bfd_vma 1292 1.1 christos alpha_convert_external_reloc (bfd *output_bfd ATTRIBUTE_UNUSED, 1293 1.1 christos struct bfd_link_info *info, 1294 1.1 christos bfd *input_bfd, 1295 1.1.1.4 christos struct external_reloc *ext_rel, 1296 1.1 christos struct ecoff_link_hash_entry *h) 1297 1.1 christos { 1298 1.1 christos unsigned long r_symndx; 1299 1.1 christos bfd_vma relocation; 1300 1.1 christos 1301 1.1 christos BFD_ASSERT (bfd_link_relocatable (info)); 1302 1.1 christos 1303 1.1 christos if (h->root.type == bfd_link_hash_defined 1304 1.1 christos || h->root.type == bfd_link_hash_defweak) 1305 1.1 christos { 1306 1.1 christos asection *hsec; 1307 1.1 christos const char *name; 1308 1.1 christos 1309 1.1 christos /* This symbol is defined in the output. Convert the reloc from 1310 1.1 christos being against the symbol to being against the section. */ 1311 1.1.1.7 christos 1312 1.1 christos /* Clear the r_extern bit. */ 1313 1.1 christos ext_rel->r_bits[1] &=~ RELOC_BITS1_EXTERN_LITTLE; 1314 1.1 christos 1315 1.1 christos /* Compute a new r_symndx value. */ 1316 1.1 christos hsec = h->root.u.def.section; 1317 1.1 christos name = bfd_section_name (hsec->output_section); 1318 1.1 christos 1319 1.1 christos r_symndx = (unsigned long) -1; 1320 1.1 christos switch (name[1]) 1321 1.1 christos { 1322 1.1 christos case 'A': 1323 1.1 christos if (strcmp (name, "*ABS*") == 0) 1324 1.1 christos r_symndx = RELOC_SECTION_ABS; 1325 1.1 christos break; 1326 1.1 christos case 'b': 1327 1.1 christos if (strcmp (name, ".bss") == 0) 1328 1.1 christos r_symndx = RELOC_SECTION_BSS; 1329 1.1 christos break; 1330 1.1 christos case 'd': 1331 1.1 christos if (strcmp (name, ".data") == 0) 1332 1.1 christos r_symndx = RELOC_SECTION_DATA; 1333 1.1 christos break; 1334 1.1 christos case 'f': 1335 1.1 christos if (strcmp (name, ".fini") == 0) 1336 1.1 christos r_symndx = RELOC_SECTION_FINI; 1337 1.1 christos break; 1338 1.1 christos case 'i': 1339 1.1 christos if (strcmp (name, ".init") == 0) 1340 1.1 christos r_symndx = RELOC_SECTION_INIT; 1341 1.1 christos break; 1342 1.1 christos case 'l': 1343 1.1 christos if (strcmp (name, ".lita") == 0) 1344 1.1 christos r_symndx = RELOC_SECTION_LITA; 1345 1.1 christos else if (strcmp (name, ".lit8") == 0) 1346 1.1 christos r_symndx = RELOC_SECTION_LIT8; 1347 1.1 christos else if (strcmp (name, ".lit4") == 0) 1348 1.1 christos r_symndx = RELOC_SECTION_LIT4; 1349 1.1 christos break; 1350 1.1 christos case 'p': 1351 1.1 christos if (strcmp (name, ".pdata") == 0) 1352 1.1 christos r_symndx = RELOC_SECTION_PDATA; 1353 1.1 christos break; 1354 1.1 christos case 'r': 1355 1.1 christos if (strcmp (name, ".rdata") == 0) 1356 1.1 christos r_symndx = RELOC_SECTION_RDATA; 1357 1.1 christos else if (strcmp (name, ".rconst") == 0) 1358 1.1 christos r_symndx = RELOC_SECTION_RCONST; 1359 1.1 christos break; 1360 1.1 christos case 's': 1361 1.1 christos if (strcmp (name, ".sdata") == 0) 1362 1.1 christos r_symndx = RELOC_SECTION_SDATA; 1363 1.1 christos else if (strcmp (name, ".sbss") == 0) 1364 1.1 christos r_symndx = RELOC_SECTION_SBSS; 1365 1.1 christos break; 1366 1.1 christos case 't': 1367 1.1 christos if (strcmp (name, ".text") == 0) 1368 1.1 christos r_symndx = RELOC_SECTION_TEXT; 1369 1.1 christos break; 1370 1.1 christos case 'x': 1371 1.1 christos if (strcmp (name, ".xdata") == 0) 1372 1.1 christos r_symndx = RELOC_SECTION_XDATA; 1373 1.1 christos break; 1374 1.1 christos } 1375 1.1 christos 1376 1.1 christos if (r_symndx == (unsigned long) -1) 1377 1.1 christos abort (); 1378 1.1 christos 1379 1.1 christos /* Add the section VMA and the symbol value. */ 1380 1.1 christos relocation = (h->root.u.def.value 1381 1.1 christos + hsec->output_section->vma 1382 1.1 christos + hsec->output_offset); 1383 1.1 christos } 1384 1.1 christos else 1385 1.1 christos { 1386 1.1 christos /* Change the symndx value to the right one for 1387 1.1 christos the output BFD. */ 1388 1.1 christos r_symndx = h->indx; 1389 1.1 christos if (r_symndx == (unsigned long) -1) 1390 1.1 christos { 1391 1.1 christos /* Caller must give an error. */ 1392 1.1 christos r_symndx = 0; 1393 1.1 christos } 1394 1.1 christos relocation = 0; 1395 1.1 christos } 1396 1.1 christos 1397 1.1 christos /* Write out the new r_symndx value. */ 1398 1.1 christos H_PUT_32 (input_bfd, r_symndx, ext_rel->r_symndx); 1399 1.1 christos 1400 1.1 christos return relocation; 1401 1.1.1.8 christos } 1402 1.1.1.2 christos 1403 1.1.1.2 christos /* Relocate a section while linking an Alpha ECOFF file. This is 1404 1.1.1.2 christos quite similar to get_relocated_section_contents. Perhaps they 1405 1.1.1.2 christos could be combined somehow. */ 1406 1.1.1.2 christos 1407 1.1.1.2 christos static bool 1408 1.1 christos alpha_relocate_section (bfd *output_bfd, 1409 1.1 christos struct bfd_link_info *info, 1410 1.1 christos bfd *input_bfd, 1411 1.1 christos asection *input_section, 1412 1.1.1.8 christos bfd_byte *contents, 1413 1.1 christos void * external_relocs) 1414 1.1 christos { 1415 1.1 christos asection **symndx_to_section, *lita_sec; 1416 1.1 christos struct ecoff_link_hash_entry **sym_hashes; 1417 1.1 christos bfd_vma gp; 1418 1.1.1.9 christos bool gp_undefined; 1419 1.1 christos bfd_vma stack[RELOC_STACKSIZE]; 1420 1.1 christos int tos = 0; 1421 1.1 christos struct external_reloc *ext_rel; 1422 1.1 christos struct external_reloc *ext_rel_end; 1423 1.1 christos bfd_size_type amt; 1424 1.1 christos bool ret = true; 1425 1.1 christos 1426 1.1 christos /* We keep a table mapping the symndx found in an internal reloc to 1427 1.1 christos the appropriate section. This is faster than looking up the 1428 1.1 christos section by name each time. */ 1429 1.1.1.8 christos symndx_to_section = ecoff_data (input_bfd)->symndx_to_section; 1430 1.1 christos if (symndx_to_section == (asection **) NULL) 1431 1.1 christos { 1432 1.1 christos amt = NUM_RELOC_SECTIONS * sizeof (asection *); 1433 1.1 christos symndx_to_section = (asection **) bfd_alloc (input_bfd, amt); 1434 1.1 christos if (!symndx_to_section) 1435 1.1 christos return false; 1436 1.1 christos 1437 1.1 christos symndx_to_section[RELOC_SECTION_NONE] = NULL; 1438 1.1 christos symndx_to_section[RELOC_SECTION_TEXT] = 1439 1.1 christos bfd_get_section_by_name (input_bfd, ".text"); 1440 1.1 christos symndx_to_section[RELOC_SECTION_RDATA] = 1441 1.1 christos bfd_get_section_by_name (input_bfd, ".rdata"); 1442 1.1 christos symndx_to_section[RELOC_SECTION_DATA] = 1443 1.1 christos bfd_get_section_by_name (input_bfd, ".data"); 1444 1.1 christos symndx_to_section[RELOC_SECTION_SDATA] = 1445 1.1 christos bfd_get_section_by_name (input_bfd, ".sdata"); 1446 1.1 christos symndx_to_section[RELOC_SECTION_SBSS] = 1447 1.1 christos bfd_get_section_by_name (input_bfd, ".sbss"); 1448 1.1 christos symndx_to_section[RELOC_SECTION_BSS] = 1449 1.1 christos bfd_get_section_by_name (input_bfd, ".bss"); 1450 1.1 christos symndx_to_section[RELOC_SECTION_INIT] = 1451 1.1 christos bfd_get_section_by_name (input_bfd, ".init"); 1452 1.1 christos symndx_to_section[RELOC_SECTION_LIT8] = 1453 1.1 christos bfd_get_section_by_name (input_bfd, ".lit8"); 1454 1.1 christos symndx_to_section[RELOC_SECTION_LIT4] = 1455 1.1 christos bfd_get_section_by_name (input_bfd, ".lit4"); 1456 1.1 christos symndx_to_section[RELOC_SECTION_XDATA] = 1457 1.1 christos bfd_get_section_by_name (input_bfd, ".xdata"); 1458 1.1 christos symndx_to_section[RELOC_SECTION_PDATA] = 1459 1.1 christos bfd_get_section_by_name (input_bfd, ".pdata"); 1460 1.1 christos symndx_to_section[RELOC_SECTION_FINI] = 1461 1.1 christos bfd_get_section_by_name (input_bfd, ".fini"); 1462 1.1 christos symndx_to_section[RELOC_SECTION_LITA] = 1463 1.1 christos bfd_get_section_by_name (input_bfd, ".lita"); 1464 1.1 christos symndx_to_section[RELOC_SECTION_ABS] = bfd_abs_section_ptr; 1465 1.1 christos symndx_to_section[RELOC_SECTION_RCONST] = 1466 1.1 christos bfd_get_section_by_name (input_bfd, ".rconst"); 1467 1.1 christos 1468 1.1 christos ecoff_data (input_bfd)->symndx_to_section = symndx_to_section; 1469 1.1 christos } 1470 1.1 christos 1471 1.1 christos sym_hashes = ecoff_data (input_bfd)->sym_hashes; 1472 1.1 christos 1473 1.1 christos /* On the Alpha, the .lita section must be addressable by the global 1474 1.1 christos pointer. To support large programs, we need to allow multiple 1475 1.1.1.4 christos global pointers. This works as long as each input .lita section 1476 1.1 christos is <64KB big. This implies that when producing relocatable 1477 1.1 christos output, the .lita section is limited to 64KB. . */ 1478 1.1 christos 1479 1.1 christos lita_sec = symndx_to_section[RELOC_SECTION_LITA]; 1480 1.1 christos gp = _bfd_get_gp_value (output_bfd); 1481 1.1 christos if (! bfd_link_relocatable (info) && lita_sec != NULL) 1482 1.1 christos { 1483 1.1 christos struct ecoff_section_tdata *lita_sec_data; 1484 1.1 christos 1485 1.1 christos /* Make sure we have a section data structure to which we can 1486 1.1 christos hang on to the gp value we pick for the section. */ 1487 1.1 christos lita_sec_data = ecoff_section_data (input_bfd, lita_sec); 1488 1.1 christos if (lita_sec_data == NULL) 1489 1.1 christos { 1490 1.1 christos amt = sizeof (struct ecoff_section_tdata); 1491 1.1 christos lita_sec_data = ((struct ecoff_section_tdata *) 1492 1.1 christos bfd_zalloc (input_bfd, amt)); 1493 1.1 christos lita_sec->used_by_bfd = lita_sec_data; 1494 1.1 christos } 1495 1.1 christos 1496 1.1 christos if (lita_sec_data->gp != 0) 1497 1.1 christos { 1498 1.1 christos /* If we already assigned a gp to this section, we better 1499 1.1 christos stick with that value. */ 1500 1.1 christos gp = lita_sec_data->gp; 1501 1.1 christos } 1502 1.1 christos else 1503 1.1 christos { 1504 1.1 christos bfd_vma lita_vma; 1505 1.1 christos bfd_size_type lita_size; 1506 1.1 christos 1507 1.1 christos lita_vma = lita_sec->output_offset + lita_sec->output_section->vma; 1508 1.1 christos lita_size = lita_sec->size; 1509 1.1 christos 1510 1.1 christos if (gp == 0 1511 1.1 christos || lita_vma < gp - 0x8000 1512 1.1 christos || lita_vma + lita_size >= gp + 0x8000) 1513 1.1 christos { 1514 1.1 christos /* Either gp hasn't been set at all or the current gp 1515 1.1 christos cannot address this .lita section. In both cases we 1516 1.1 christos reset the gp to point into the "middle" of the 1517 1.1 christos current input .lita section. */ 1518 1.1.1.8 christos if (gp && !ecoff_data (output_bfd)->issued_multiple_gp_warning) 1519 1.1 christos { 1520 1.1 christos (*info->callbacks->warning) (info, 1521 1.1 christos _("using multiple gp values"), 1522 1.1 christos (char *) NULL, output_bfd, 1523 1.1 christos (asection *) NULL, (bfd_vma) 0); 1524 1.1 christos ecoff_data (output_bfd)->issued_multiple_gp_warning = true; 1525 1.1 christos } 1526 1.1 christos if (lita_vma < gp - 0x8000) 1527 1.1 christos gp = lita_vma + lita_size - 0x8000; 1528 1.1 christos else 1529 1.1 christos gp = lita_vma + 0x8000; 1530 1.1 christos 1531 1.1 christos } 1532 1.1 christos 1533 1.1 christos lita_sec_data->gp = gp; 1534 1.1 christos } 1535 1.1 christos 1536 1.1 christos _bfd_set_gp_value (output_bfd, gp); 1537 1.1 christos } 1538 1.1 christos 1539 1.1 christos gp_undefined = (gp == 0); 1540 1.1 christos 1541 1.1 christos BFD_ASSERT (bfd_header_little_endian (output_bfd)); 1542 1.1 christos BFD_ASSERT (bfd_header_little_endian (input_bfd)); 1543 1.1 christos 1544 1.1 christos ext_rel = (struct external_reloc *) external_relocs; 1545 1.1 christos ext_rel_end = ext_rel + input_section->reloc_count; 1546 1.1 christos for (; ext_rel < ext_rel_end; ext_rel++) 1547 1.1 christos { 1548 1.1.1.8 christos bfd_vma r_vaddr; 1549 1.1.1.8 christos unsigned long r_symndx; 1550 1.1.1.8 christos int r_type; 1551 1.1 christos int r_extern; 1552 1.1.1.9 christos int r_offset; 1553 1.1 christos int r_size; 1554 1.1 christos bool relocatep; 1555 1.1 christos bool adjust_addrp; 1556 1.1 christos bool gp_usedp; 1557 1.1 christos bfd_vma addend; 1558 1.1 christos bfd_reloc_status_type r; 1559 1.1 christos 1560 1.1 christos r_vaddr = H_GET_64 (input_bfd, ext_rel->r_vaddr); 1561 1.1 christos r_symndx = H_GET_32 (input_bfd, ext_rel->r_symndx); 1562 1.1 christos 1563 1.1 christos r_type = ((ext_rel->r_bits[0] & RELOC_BITS0_TYPE_LITTLE) 1564 1.1 christos >> RELOC_BITS0_TYPE_SH_LITTLE); 1565 1.1 christos r_extern = (ext_rel->r_bits[1] & RELOC_BITS1_EXTERN_LITTLE) != 0; 1566 1.1.1.8 christos r_offset = ((ext_rel->r_bits[1] & RELOC_BITS1_OFFSET_LITTLE) 1567 1.1.1.8 christos >> RELOC_BITS1_OFFSET_SH_LITTLE); 1568 1.1.1.8 christos /* Ignored the reserved bits. */ 1569 1.1 christos r_size = ((ext_rel->r_bits[3] & RELOC_BITS3_SIZE_LITTLE) 1570 1.1.1.9 christos >> RELOC_BITS3_SIZE_SH_LITTLE); 1571 1.1 christos 1572 1.1 christos relocatep = false; 1573 1.1 christos adjust_addrp = true; 1574 1.1 christos gp_usedp = false; 1575 1.1.1.9 christos addend = 0; 1576 1.1.1.9 christos r = bfd_reloc_ok; 1577 1.1 christos 1578 1.1 christos switch (r_type) 1579 1.1 christos { 1580 1.1 christos default: 1581 1.1 christos r = bfd_reloc_notsupported; 1582 1.1 christos break; 1583 1.1 christos 1584 1.1 christos case ALPHA_R_IGNORE: 1585 1.1.1.4 christos /* This reloc appears after a GPDISP reloc. On earlier 1586 1.1 christos versions of OSF/1, It marked the position of the second 1587 1.1 christos instruction to be altered by the GPDISP reloc, but it is 1588 1.1.1.8 christos not otherwise used for anything. For some reason, the 1589 1.1 christos address of the relocation does not appear to include the 1590 1.1 christos section VMA, unlike the other relocation types. */ 1591 1.1 christos if (bfd_link_relocatable (info)) 1592 1.1 christos H_PUT_64 (input_bfd, input_section->output_offset + r_vaddr, 1593 1.1 christos ext_rel->r_vaddr); 1594 1.1.1.8 christos adjust_addrp = false; 1595 1.1 christos break; 1596 1.1 christos 1597 1.1 christos case ALPHA_R_REFLONG: 1598 1.1 christos case ALPHA_R_REFQUAD: 1599 1.1 christos case ALPHA_R_HINT: 1600 1.1 christos relocatep = true; 1601 1.1 christos break; 1602 1.1 christos 1603 1.1.1.8 christos case ALPHA_R_BRADDR: 1604 1.1 christos case ALPHA_R_SREL16: 1605 1.1 christos case ALPHA_R_SREL32: 1606 1.1 christos case ALPHA_R_SREL64: 1607 1.1 christos if (r_extern) 1608 1.1 christos addend += - (r_vaddr + 4); 1609 1.1 christos relocatep = true; 1610 1.1 christos break; 1611 1.1.1.8 christos 1612 1.1 christos case ALPHA_R_GPREL32: 1613 1.1.1.8 christos /* This relocation is used in a switch table. It is a 32 1614 1.1 christos bit offset from the current GP value. We must adjust it 1615 1.1 christos by the different between the original GP value and the 1616 1.1 christos current GP value. */ 1617 1.1 christos relocatep = true; 1618 1.1 christos addend = ecoff_data (input_bfd)->gp - gp; 1619 1.1 christos gp_usedp = true; 1620 1.1 christos break; 1621 1.1 christos 1622 1.1 christos case ALPHA_R_LITERAL: 1623 1.1 christos /* This is a reference to a literal value, generally 1624 1.1 christos (always?) in the .lita section. This is a 16 bit GP 1625 1.1 christos relative relocation. Sometimes the subsequent reloc is a 1626 1.1 christos LITUSE reloc, which indicates how this reloc is used. 1627 1.1 christos This sometimes permits rewriting the two instructions 1628 1.1 christos referred to by the LITERAL and the LITUSE into different 1629 1.1 christos instructions which do not refer to .lita. This can save 1630 1.1 christos a memory reference, and permits removing a value from 1631 1.1 christos .lita thus saving GP relative space. 1632 1.1 christos 1633 1.1.1.8 christos We do not these optimizations. To do them we would need 1634 1.1 christos to arrange to link the .lita section first, so that by 1635 1.1.1.8 christos the time we got here we would know the final values to 1636 1.1 christos use. This would not be particularly difficult, but it is 1637 1.1 christos not currently implemented. */ 1638 1.1 christos 1639 1.1 christos relocatep = true; 1640 1.1 christos addend = ecoff_data (input_bfd)->gp - gp; 1641 1.1 christos gp_usedp = true; 1642 1.1 christos break; 1643 1.1 christos 1644 1.1 christos case ALPHA_R_LITUSE: 1645 1.1 christos /* See ALPHA_R_LITERAL above for the uses of this reloc. It 1646 1.1 christos does not cause anything to happen, itself. */ 1647 1.1 christos break; 1648 1.1 christos 1649 1.1.1.9 christos case ALPHA_R_GPDISP: 1650 1.1.1.9 christos /* This marks the ldah of an ldah/lda pair which loads the 1651 1.1.1.9 christos gp register with the difference of the gp value and the 1652 1.1.1.9 christos current location. The second of the pair is r_symndx 1653 1.1.1.9 christos bytes ahead. It used to be marked with an ALPHA_R_IGNORE 1654 1.1.1.9 christos reloc, but OSF/1 3.2 no longer does that. */ 1655 1.1.1.9 christos if (r_vaddr >= input_section->vma 1656 1.1.1.9 christos && r_vaddr - input_section->vma < input_section->size 1657 1.1.1.9 christos && input_section->size - (r_vaddr - input_section->vma) > r_symndx 1658 1.1.1.9 christos && (input_section->size - (r_vaddr - input_section->vma) 1659 1.1.1.9 christos - r_symndx >= 4)) 1660 1.1.1.9 christos { 1661 1.1.1.9 christos /* Get the two instructions. */ 1662 1.1.1.9 christos bfd_byte *p = contents + r_vaddr - input_section->vma; 1663 1.1.1.9 christos bfd_vma insn1 = bfd_get_32 (input_bfd, p); 1664 1.1.1.9 christos bfd_vma insn2 = bfd_get_32 (input_bfd, p + r_symndx); 1665 1.1.1.9 christos 1666 1.1.1.9 christos BFD_ASSERT (((insn1 >> 26) & 0x3f) == 0x09); /* ldah */ 1667 1.1.1.9 christos BFD_ASSERT (((insn2 >> 26) & 0x3f) == 0x08); /* lda */ 1668 1.1.1.9 christos 1669 1.1.1.9 christos /* Get the existing addend. We must account for the sign 1670 1.1.1.9 christos extension done by lda and ldah. */ 1671 1.1.1.9 christos addend = (((((insn1 & 0xffff) ^ 0x8000) - 0x8000) << 16) 1672 1.1.1.9 christos + (((insn2 & 0xffff) ^ 0x8000) - 0x8000)); 1673 1.1.1.9 christos 1674 1.1.1.9 christos /* The existing addend includes the difference between the 1675 1.1.1.9 christos gp of the input BFD and the address in the input BFD. 1676 1.1.1.9 christos We want to change this to the difference between the 1677 1.1.1.9 christos final GP and the final address. */ 1678 1.1.1.9 christos addend -= ecoff_data (input_bfd)->gp - input_section->vma; 1679 1.1.1.9 christos addend += gp - (input_section->output_section->vma 1680 1.1 christos + input_section->output_offset); 1681 1.1.1.9 christos 1682 1.1.1.9 christos /* Change the instructions, accounting for the sign 1683 1.1 christos extension, and write them out. */ 1684 1.1.1.9 christos insn1 = (insn1 & ~0xffff) | (((addend + 0x8000) >> 16) & 0xffff); 1685 1.1.1.9 christos insn2 = (insn2 & ~0xffff) | (addend & 0xffff); 1686 1.1.1.9 christos 1687 1.1.1.9 christos bfd_put_32 (input_bfd, insn1, p); 1688 1.1 christos bfd_put_32 (input_bfd, insn2, p + r_symndx); 1689 1.1 christos 1690 1.1 christos gp_usedp = true; 1691 1.1 christos } 1692 1.1 christos else 1693 1.1 christos r = bfd_reloc_outofrange; 1694 1.1 christos break; 1695 1.1 christos 1696 1.1 christos case ALPHA_R_OP_PUSH: 1697 1.1 christos case ALPHA_R_OP_PSUB: 1698 1.1 christos case ALPHA_R_OP_PRSHIFT: 1699 1.1 christos /* Manipulate values on the reloc evaluation stack. The 1700 1.1 christos r_vaddr field is not an address in input_section, it is 1701 1.1 christos the current value (including any addend) of the object 1702 1.1.1.9 christos being used. */ 1703 1.1.1.9 christos if (! r_extern) 1704 1.1.1.9 christos { 1705 1.1.1.9 christos asection *s; 1706 1.1.1.9 christos 1707 1.1 christos s = symndx_to_section[r_symndx]; 1708 1.1 christos if (s == NULL) 1709 1.1 christos { 1710 1.1 christos r = bfd_reloc_notsupported; 1711 1.1 christos break; 1712 1.1 christos } 1713 1.1 christos addend = s->output_section->vma + s->output_offset - s->vma; 1714 1.1.1.9 christos } 1715 1.1.1.9 christos else 1716 1.1.1.9 christos { 1717 1.1.1.9 christos struct ecoff_link_hash_entry *h; 1718 1.1.1.9 christos 1719 1.1 christos h = sym_hashes[r_symndx]; 1720 1.1.1.4 christos if (h == NULL) 1721 1.1 christos { 1722 1.1 christos r = bfd_reloc_notsupported; 1723 1.1 christos break; 1724 1.1 christos } 1725 1.1 christos 1726 1.1 christos if (! bfd_link_relocatable (info)) 1727 1.1 christos { 1728 1.1 christos if (h->root.type == bfd_link_hash_defined 1729 1.1 christos || h->root.type == bfd_link_hash_defweak) 1730 1.1 christos addend = (h->root.u.def.value 1731 1.1 christos + h->root.u.def.section->output_section->vma 1732 1.1 christos + h->root.u.def.section->output_offset); 1733 1.1.1.4 christos else 1734 1.1.1.4 christos { 1735 1.1.1.8 christos /* Note that we pass the address as 0, since we 1736 1.1 christos do not have a meaningful number for the 1737 1.1 christos location within the section that is being 1738 1.1 christos relocated. */ 1739 1.1 christos (*info->callbacks->undefined_symbol) 1740 1.1 christos (info, h->root.root.string, input_bfd, 1741 1.1 christos input_section, (bfd_vma) 0, true); 1742 1.1 christos addend = 0; 1743 1.1 christos } 1744 1.1 christos } 1745 1.1 christos else 1746 1.1 christos { 1747 1.1 christos if (h->root.type != bfd_link_hash_defined 1748 1.1.1.4 christos && h->root.type != bfd_link_hash_defweak 1749 1.1.1.4 christos && h->indx == -1) 1750 1.1.1.4 christos { 1751 1.1 christos /* This symbol is not being written out. Pass 1752 1.1 christos the address as 0, as with undefined_symbol, 1753 1.1 christos above. */ 1754 1.1 christos (*info->callbacks->unattached_reloc) 1755 1.1 christos (info, h->root.root.string, 1756 1.1 christos input_bfd, input_section, (bfd_vma) 0); 1757 1.1 christos } 1758 1.1 christos 1759 1.1 christos addend = alpha_convert_external_reloc (output_bfd, info, 1760 1.1 christos input_bfd, 1761 1.1.1.4 christos ext_rel, h); 1762 1.1 christos } 1763 1.1 christos } 1764 1.1 christos 1765 1.1 christos addend += r_vaddr; 1766 1.1 christos 1767 1.1 christos if (bfd_link_relocatable (info)) 1768 1.1 christos { 1769 1.1 christos /* Adjust r_vaddr by the addend. */ 1770 1.1 christos H_PUT_64 (input_bfd, addend, ext_rel->r_vaddr); 1771 1.1 christos } 1772 1.1.1.9 christos else 1773 1.1.1.9 christos { 1774 1.1.1.9 christos switch (r_type) 1775 1.1.1.9 christos { 1776 1.1 christos case ALPHA_R_OP_PUSH: 1777 1.1 christos if (tos >= RELOC_STACKSIZE) 1778 1.1 christos { 1779 1.1 christos r = bfd_reloc_notsupported; 1780 1.1 christos break; 1781 1.1.1.9 christos } 1782 1.1.1.9 christos stack[tos++] = addend; 1783 1.1.1.9 christos break; 1784 1.1.1.9 christos 1785 1.1 christos case ALPHA_R_OP_PSUB: 1786 1.1 christos if (tos == 0) 1787 1.1 christos { 1788 1.1 christos r = bfd_reloc_notsupported; 1789 1.1 christos break; 1790 1.1.1.9 christos } 1791 1.1.1.9 christos stack[tos - 1] -= addend; 1792 1.1.1.9 christos break; 1793 1.1.1.9 christos 1794 1.1 christos case ALPHA_R_OP_PRSHIFT: 1795 1.1 christos if (tos == 0) 1796 1.1 christos { 1797 1.1 christos r = bfd_reloc_notsupported; 1798 1.1 christos break; 1799 1.1.1.8 christos } 1800 1.1 christos stack[tos - 1] >>= addend; 1801 1.1 christos break; 1802 1.1 christos } 1803 1.1 christos } 1804 1.1 christos 1805 1.1 christos adjust_addrp = false; 1806 1.1.1.4 christos break; 1807 1.1 christos 1808 1.1.1.11 christos case ALPHA_R_OP_STORE: 1809 1.1.1.11 christos /* Store a value from the reloc stack into a bitfield. If 1810 1.1.1.11 christos we are generating relocatable output, all we do is 1811 1.1.1.11 christos adjust the address of the reloc. */ 1812 1.1.1.11 christos if (! bfd_link_relocatable (info)) 1813 1.1.1.11 christos { 1814 1.1.1.9 christos if (tos == 0) 1815 1.1 christos r = bfd_reloc_notsupported; 1816 1.1 christos else if (!write_bit_field (input_bfd, input_section, 1817 1.1 christos contents, 1818 1.1 christos r_vaddr - input_section->vma, 1819 1.1 christos r_offset, r_size, stack[--tos])) 1820 1.1 christos r = bfd_reloc_outofrange; 1821 1.1.1.8 christos } 1822 1.1 christos break; 1823 1.1 christos 1824 1.1 christos case ALPHA_R_GPVALUE: 1825 1.1.1.9 christos /* I really don't know if this does the right thing. */ 1826 1.1 christos gp = ecoff_data (input_bfd)->gp + r_symndx; 1827 1.1 christos gp_undefined = false; 1828 1.1 christos break; 1829 1.1 christos } 1830 1.1 christos 1831 1.1 christos if (relocatep && r == bfd_reloc_ok) 1832 1.1 christos { 1833 1.1 christos reloc_howto_type *howto; 1834 1.1 christos struct ecoff_link_hash_entry *h = NULL; 1835 1.1 christos asection *s = NULL; 1836 1.1 christos bfd_vma relocation; 1837 1.1 christos 1838 1.1 christos /* Perform a relocation. */ 1839 1.1 christos 1840 1.1 christos howto = &alpha_howto_table[r_type]; 1841 1.1 christos 1842 1.1.1.9 christos if (r_extern) 1843 1.1.1.9 christos { 1844 1.1 christos h = sym_hashes[r_symndx]; 1845 1.1 christos /* If h is NULL, that means that there is a reloc 1846 1.1 christos against an external symbol which we thought was just 1847 1.1 christos a debugging symbol. This should not happen. */ 1848 1.1 christos if (h == NULL) 1849 1.1 christos r = bfd_reloc_notsupported; 1850 1.1 christos } 1851 1.1 christos else 1852 1.1.1.9 christos { 1853 1.1.1.9 christos if (r_symndx >= NUM_RELOC_SECTIONS) 1854 1.1.1.9 christos s = NULL; 1855 1.1 christos else 1856 1.1 christos s = symndx_to_section[r_symndx]; 1857 1.1.1.9 christos 1858 1.1.1.9 christos if (s == NULL) 1859 1.1.1.9 christos r = bfd_reloc_notsupported; 1860 1.1 christos 1861 1.1 christos } 1862 1.1 christos 1863 1.1 christos if (r != bfd_reloc_ok) 1864 1.1 christos ; 1865 1.1 christos else if (bfd_link_relocatable (info)) 1866 1.1 christos { 1867 1.1 christos /* We are generating relocatable output, and must 1868 1.1 christos convert the existing reloc. */ 1869 1.1 christos if (r_extern) 1870 1.1.1.4 christos { 1871 1.1.1.4 christos if (h->root.type != bfd_link_hash_defined 1872 1.1.1.4 christos && h->root.type != bfd_link_hash_defweak 1873 1.1 christos && h->indx == -1) 1874 1.1 christos { 1875 1.1 christos /* This symbol is not being written out. */ 1876 1.1 christos (*info->callbacks->unattached_reloc) 1877 1.1 christos (info, h->root.root.string, input_bfd, 1878 1.1 christos input_section, r_vaddr - input_section->vma); 1879 1.1 christos } 1880 1.1 christos 1881 1.1 christos relocation = alpha_convert_external_reloc (output_bfd, 1882 1.1 christos info, 1883 1.1 christos input_bfd, 1884 1.1 christos ext_rel, 1885 1.1 christos h); 1886 1.1 christos } 1887 1.1 christos else 1888 1.1 christos { 1889 1.1 christos /* This is a relocation against a section. Adjust 1890 1.1 christos the value by the amount the section moved. */ 1891 1.1 christos relocation = (s->output_section->vma 1892 1.1 christos + s->output_offset 1893 1.1 christos - s->vma); 1894 1.1 christos } 1895 1.1 christos 1896 1.1 christos /* If this is PC relative, the existing object file 1897 1.1 christos appears to already have the reloc worked out. We 1898 1.1 christos must subtract out the old value and add in the new 1899 1.1 christos one. */ 1900 1.1 christos if (howto->pc_relative) 1901 1.1 christos relocation -= (input_section->output_section->vma 1902 1.1 christos + input_section->output_offset 1903 1.1 christos - input_section->vma); 1904 1.1 christos 1905 1.1 christos /* Put in any addend. */ 1906 1.1 christos relocation += addend; 1907 1.1 christos 1908 1.1 christos /* Adjust the contents. */ 1909 1.1 christos r = _bfd_relocate_contents (howto, input_bfd, relocation, 1910 1.1 christos (contents 1911 1.1 christos + r_vaddr 1912 1.1 christos - input_section->vma)); 1913 1.1 christos } 1914 1.1 christos else 1915 1.1 christos { 1916 1.1 christos /* We are producing a final executable. */ 1917 1.1 christos if (r_extern) 1918 1.1 christos { 1919 1.1 christos /* This is a reloc against a symbol. */ 1920 1.1 christos if (h->root.type == bfd_link_hash_defined 1921 1.1 christos || h->root.type == bfd_link_hash_defweak) 1922 1.1 christos { 1923 1.1 christos asection *hsec; 1924 1.1 christos 1925 1.1.1.9 christos hsec = h->root.u.def.section; 1926 1.1 christos relocation = (h->root.u.def.value 1927 1.1 christos + hsec->output_section->vma 1928 1.1 christos + hsec->output_offset); 1929 1.1 christos } 1930 1.1 christos else 1931 1.1 christos r = bfd_reloc_undefined; 1932 1.1 christos } 1933 1.1 christos else 1934 1.1 christos { 1935 1.1 christos /* This is a reloc against a section. */ 1936 1.1 christos relocation = (s->output_section->vma 1937 1.1 christos + s->output_offset 1938 1.1 christos - s->vma); 1939 1.1 christos 1940 1.1.1.9 christos /* Adjust a PC relative relocation by removing the 1941 1.1.1.9 christos reference to the original source section. */ 1942 1.1.1.9 christos if (howto->pc_relative) 1943 1.1.1.9 christos relocation += input_section->vma; 1944 1.1.1.9 christos } 1945 1.1.1.9 christos 1946 1.1.1.9 christos if (r == bfd_reloc_ok) 1947 1.1.1.9 christos r = _bfd_final_link_relocate (howto, 1948 1.1 christos input_bfd, 1949 1.1 christos input_section, 1950 1.1 christos contents, 1951 1.1.1.4 christos r_vaddr - input_section->vma, 1952 1.1 christos relocation, 1953 1.1 christos addend); 1954 1.1 christos } 1955 1.1 christos } 1956 1.1 christos 1957 1.1 christos if (bfd_link_relocatable (info) && adjust_addrp) 1958 1.1 christos { 1959 1.1 christos /* Change the address of the relocation. */ 1960 1.1 christos H_PUT_64 (input_bfd, 1961 1.1 christos (input_section->output_section->vma 1962 1.1 christos + input_section->output_offset 1963 1.1 christos - input_section->vma 1964 1.1.1.9 christos + r_vaddr), 1965 1.1 christos ext_rel->r_vaddr); 1966 1.1 christos } 1967 1.1 christos 1968 1.1.1.8 christos if (gp_usedp && gp_undefined) 1969 1.1 christos { 1970 1.1.1.9 christos r = bfd_reloc_dangerous; 1971 1.1.1.9 christos /* Only give the error once per link. */ 1972 1.1.1.9 christos gp = 4; 1973 1.1.1.9 christos _bfd_set_gp_value (output_bfd, gp); 1974 1.1.1.9 christos gp_undefined = false; 1975 1.1.1.9 christos } 1976 1.1.1.9 christos 1977 1.1.1.9 christos if (r != bfd_reloc_ok) 1978 1.1.1.9 christos { 1979 1.1.1.9 christos switch (r) 1980 1.1.1.9 christos { 1981 1.1.1.9 christos case bfd_reloc_overflow: 1982 1.1.1.9 christos { 1983 1.1.1.9 christos const char *name; 1984 1.1.1.9 christos 1985 1.1.1.9 christos if (r_extern) 1986 1.1.1.9 christos name = sym_hashes[r_symndx]->root.root.string; 1987 1.1.1.9 christos else 1988 1.1.1.9 christos name = bfd_section_name (symndx_to_section[r_symndx]); 1989 1.1.1.9 christos (*info->callbacks->reloc_overflow) 1990 1.1.1.9 christos (info, NULL, name, alpha_howto_table[r_type].name, 1991 1.1.1.9 christos (bfd_vma) 0, input_bfd, input_section, 1992 1.1.1.9 christos r_vaddr - input_section->vma); 1993 1.1.1.9 christos } 1994 1.1.1.9 christos break; 1995 1.1.1.9 christos case bfd_reloc_outofrange: 1996 1.1.1.9 christos (*info->callbacks->einfo) 1997 1.1.1.9 christos /* xgettext:c-format */ 1998 1.1.1.9 christos (_("%X%P: %pB(%pA): relocation out of range\n"), 1999 1.1.1.9 christos input_bfd, input_section); 2000 1.1.1.9 christos break; 2001 1.1.1.9 christos case bfd_reloc_undefined: 2002 1.1.1.9 christos (*info->callbacks->undefined_symbol) 2003 1.1.1.9 christos (info, sym_hashes[r_symndx]->root.root.string, 2004 1.1.1.9 christos input_bfd, input_section, 2005 1.1.1.9 christos r_vaddr - input_section->vma, true); 2006 1.1.1.9 christos break; 2007 1.1.1.9 christos case bfd_reloc_notsupported: 2008 1.1.1.9 christos (*info->callbacks->einfo) 2009 1.1.1.9 christos /* xgettext:c-format */ 2010 1.1.1.9 christos (_("%X%P: %pB(%pA): relocation is not supported\n"), 2011 1.1.1.9 christos input_bfd, input_section); 2012 1.1.1.9 christos break; 2013 1.1.1.9 christos case bfd_reloc_dangerous: 2014 1.1.1.9 christos (*info->callbacks->reloc_dangerous) 2015 1.1.1.9 christos (info, _("GP relative relocation used when GP not defined"), 2016 1.1.1.9 christos input_bfd, input_section, r_vaddr - input_section->vma); 2017 1.1 christos break; 2018 1.1 christos default: 2019 1.1 christos abort (); 2020 1.1.1.9 christos } 2021 1.1 christos ret = false; 2022 1.1.1.9 christos } 2023 1.1 christos } 2024 1.1 christos 2025 1.1 christos if (tos != 0) 2026 1.1 christos ret = false; 2027 1.1 christos 2028 1.1.1.8 christos return ret; 2029 1.1.1.2 christos } 2030 1.1.1.2 christos 2031 1.1.1.2 christos /* Do final adjustments to the filehdr and the aouthdr. This routine 2033 1.1 christos sets the dynamic bits in the file header. */ 2034 1.1 christos 2035 1.1 christos static bool 2036 1.1 christos alpha_adjust_headers (bfd *abfd, 2037 1.1.1.8 christos struct internal_filehdr *fhdr, 2038 1.1 christos struct internal_aouthdr *ahdr ATTRIBUTE_UNUSED) 2039 1.1 christos { 2040 1.1 christos if ((abfd->flags & (DYNAMIC | EXEC_P)) == (DYNAMIC | EXEC_P)) 2041 1.1 christos fhdr->f_flags |= F_ALPHA_CALL_SHARED; 2042 1.1 christos else if ((abfd->flags & DYNAMIC) != 0) 2043 1.1 christos fhdr->f_flags |= F_ALPHA_SHARABLE; 2044 1.1 christos return true; 2045 1.1 christos } 2046 1.1 christos 2047 1.1 christos /* Archive handling. In OSF/1 (or Digital Unix) v3.2, Digital 2049 1.1 christos introduced archive packing, in which the elements in an archive are 2050 1.1 christos optionally compressed using a simple dictionary scheme. We know 2051 1.1 christos how to read such archives, but we don't write them. */ 2052 1.1 christos 2053 1.1 christos #define alpha_ecoff_slurp_armap _bfd_ecoff_slurp_armap 2054 1.1 christos #define alpha_ecoff_slurp_extended_name_table \ 2055 1.1 christos _bfd_ecoff_slurp_extended_name_table 2056 1.1 christos #define alpha_ecoff_construct_extended_name_table \ 2057 1.1 christos _bfd_ecoff_construct_extended_name_table 2058 1.1 christos #define alpha_ecoff_truncate_arname _bfd_ecoff_truncate_arname 2059 1.1 christos #define alpha_ecoff_write_armap _bfd_ecoff_write_armap 2060 1.1 christos #define alpha_ecoff_write_ar_hdr _bfd_generic_write_ar_hdr 2061 1.1 christos #define alpha_ecoff_generic_stat_arch_elt _bfd_ecoff_generic_stat_arch_elt 2062 1.1 christos #define alpha_ecoff_update_armap_timestamp _bfd_ecoff_update_armap_timestamp 2063 1.1.1.2 christos 2064 1.1.1.2 christos /* A compressed file uses this instead of ARFMAG. */ 2065 1.1 christos 2066 1.1 christos #define ARFZMAG "Z\012" 2067 1.1 christos 2068 1.1 christos /* Read an archive header. This is like the standard routine, but it 2069 1.1 christos also accepts ARFZMAG. */ 2070 1.1 christos 2071 1.1 christos static void * 2072 1.1 christos alpha_ecoff_read_ar_hdr (bfd *abfd) 2073 1.1 christos { 2074 1.1 christos struct areltdata *ret; 2075 1.1 christos struct ar_hdr *h; 2076 1.1 christos 2077 1.1 christos ret = (struct areltdata *) _bfd_generic_read_ar_hdr_mag (abfd, ARFZMAG); 2078 1.1 christos if (ret == NULL) 2079 1.1.1.6 christos return NULL; 2080 1.1.1.9 christos 2081 1.1.1.9 christos h = (struct ar_hdr *) ret->arch_header; 2082 1.1.1.9 christos if (strncmp (h->ar_fmag, ARFZMAG, 2) == 0) 2083 1.1.1.7 christos { 2084 1.1.1.7 christos bfd_byte ab[8]; 2085 1.1.1.7 christos 2086 1.1.1.7 christos /* This is a compressed file. We must set the size correctly. 2087 1.1 christos The size is the eight bytes after the dummy file header. */ 2088 1.1 christos if (bfd_seek (abfd, FILHSZ, SEEK_CUR) != 0 2089 1.1 christos || bfd_read (ab, 8, abfd) != 8 2090 1.1 christos || bfd_seek (abfd, -(FILHSZ + 8), SEEK_CUR) != 0) 2091 1.1.1.2 christos { 2092 1.1 christos free (ret); 2093 1.1 christos return NULL; 2094 1.1 christos } 2095 1.1 christos 2096 1.1 christos ret->parsed_size = H_GET_64 (abfd, ab); 2097 1.1 christos } 2098 1.1.1.8 christos 2099 1.1.1.8 christos return ret; 2100 1.1 christos } 2101 1.1 christos 2102 1.1 christos /* Get an archive element at a specified file position. This is where 2103 1.1 christos we uncompress the archive element if necessary. */ 2104 1.1 christos 2105 1.1 christos static bfd * 2106 1.1 christos alpha_ecoff_get_elt_at_filepos (bfd *archive, file_ptr filepos, 2107 1.1 christos struct bfd_link_info *info) 2108 1.1.1.7 christos { 2109 1.1 christos bfd *nbfd = NULL; 2110 1.1 christos struct areltdata *tdata; 2111 1.1.1.8 christos struct ar_hdr *hdr; 2112 1.1 christos bfd_byte ab[8]; 2113 1.1 christos bfd_size_type size; 2114 1.1 christos bfd_byte *buf, *p; 2115 1.1 christos struct bfd_in_memory *bim; 2116 1.1 christos ufile_ptr filesize; 2117 1.1 christos 2118 1.1 christos buf = NULL; 2119 1.1 christos nbfd = _bfd_get_elt_at_filepos (archive, filepos, info); 2120 1.1 christos if (nbfd == NULL) 2121 1.1 christos goto error_return; 2122 1.1 christos 2123 1.1 christos if ((nbfd->flags & BFD_IN_MEMORY) != 0) 2124 1.1 christos { 2125 1.1 christos /* We have already expanded this BFD. */ 2126 1.1 christos return nbfd; 2127 1.1.1.9 christos } 2128 1.1 christos 2129 1.1 christos tdata = (struct areltdata *) nbfd->arelt_data; 2130 1.1 christos hdr = (struct ar_hdr *) tdata->arch_header; 2131 1.1 christos if (strncmp (hdr->ar_fmag, ARFZMAG, 2) != 0) 2132 1.1 christos return nbfd; 2133 1.1 christos 2134 1.1.1.9 christos /* We must uncompress this element. We do this by copying it into a 2135 1.1 christos memory buffer, and making bfd_read and bfd_seek use that buffer. 2136 1.1 christos This can use a lot of memory, but it's simpler than getting a 2137 1.1 christos temporary file, making that work with the file descriptor caching 2138 1.1.1.9 christos code, and making sure that it is deleted at all appropriate 2139 1.1 christos times. It can be changed if it ever becomes important. */ 2140 1.1 christos 2141 1.1 christos /* The compressed file starts with a dummy ECOFF file header. */ 2142 1.1.1.7 christos if (bfd_seek (nbfd, FILHSZ, SEEK_SET) != 0) 2143 1.1.1.7 christos goto error_return; 2144 1.1.1.7 christos 2145 1.1.1.7 christos /* The next eight bytes are the real file size. */ 2146 1.1.1.7 christos if (bfd_read (ab, 8, nbfd) != 8) 2147 1.1.1.7 christos goto error_return; 2148 1.1.1.7 christos size = H_GET_64 (nbfd, ab); 2149 1.1.1.7 christos 2150 1.1 christos /* The decompression algorithm will at most expand by eight times. */ 2151 1.1 christos filesize = bfd_get_file_size (archive); 2152 1.1 christos if (filesize != 0 && size / 8 > filesize) 2153 1.1 christos { 2154 1.1 christos bfd_set_error (bfd_error_malformed_archive); 2155 1.1 christos goto error_return; 2156 1.1 christos } 2157 1.1 christos 2158 1.1 christos if (size != 0) 2159 1.1 christos { 2160 1.1 christos bfd_size_type left; 2161 1.1 christos bfd_byte dict[4096]; 2162 1.1 christos unsigned int h; 2163 1.1 christos bfd_byte b; 2164 1.1 christos 2165 1.1.1.9 christos buf = (bfd_byte *) bfd_malloc (size); 2166 1.1 christos if (buf == NULL) 2167 1.1 christos goto error_return; 2168 1.1 christos p = buf; 2169 1.1 christos 2170 1.1 christos left = size; 2171 1.1 christos 2172 1.1 christos /* I don't know what the next eight bytes are for. */ 2173 1.1 christos if (bfd_read (ab, 8, nbfd) != 8) 2174 1.1 christos goto error_return; 2175 1.1 christos 2176 1.1.1.9 christos /* This is the uncompression algorithm. It's a simple 2177 1.1 christos dictionary based scheme in which each character is predicted 2178 1.1 christos by a hash of the previous three characters. A control byte 2179 1.1 christos indicates whether the character is predicted or whether it 2180 1.1 christos appears in the input stream; each control byte manages the 2181 1.1 christos next eight bytes in the output stream. */ 2182 1.1 christos memset (dict, 0, sizeof dict); 2183 1.1 christos h = 0; 2184 1.1 christos while (bfd_read (&b, 1, nbfd) == 1) 2185 1.1 christos { 2186 1.1 christos unsigned int i; 2187 1.1 christos 2188 1.1.1.9 christos for (i = 0; i < 8; i++, b >>= 1) 2189 1.1 christos { 2190 1.1 christos bfd_byte n; 2191 1.1 christos 2192 1.1 christos if ((b & 1) == 0) 2193 1.1 christos n = dict[h]; 2194 1.1 christos else 2195 1.1 christos { 2196 1.1 christos if (bfd_read (&n, 1, nbfd) != 1) 2197 1.1 christos goto error_return; 2198 1.1 christos dict[h] = n; 2199 1.1 christos } 2200 1.1 christos 2201 1.1 christos *p++ = n; 2202 1.1 christos 2203 1.1 christos --left; 2204 1.1 christos if (left == 0) 2205 1.1 christos break; 2206 1.1 christos 2207 1.1 christos h <<= 4; 2208 1.1 christos h ^= n; 2209 1.1 christos h &= sizeof dict - 1; 2210 1.1 christos } 2211 1.1 christos 2212 1.1 christos if (left == 0) 2213 1.1 christos break; 2214 1.1 christos } 2215 1.1 christos } 2216 1.1 christos 2217 1.1.1.8 christos /* Now the uncompressed file contents are in buf. */ 2218 1.1 christos bim = ((struct bfd_in_memory *) 2219 1.1 christos bfd_malloc ((bfd_size_type) sizeof (struct bfd_in_memory))); 2220 1.1 christos if (bim == NULL) 2221 1.1.1.2 christos goto error_return; 2222 1.1 christos bim->size = size; 2223 1.1 christos bim->buffer = buf; 2224 1.1.1.9 christos 2225 1.1 christos nbfd->mtime_set = true; 2226 1.1 christos nbfd->mtime = strtol (hdr->ar_date, (char **) NULL, 10); 2227 1.1 christos 2228 1.1 christos nbfd->flags |= BFD_IN_MEMORY; 2229 1.1 christos nbfd->iostream = bim; 2230 1.1.1.7 christos nbfd->iovec = &_bfd_memory_iovec; 2231 1.1 christos nbfd->origin = 0; 2232 1.1 christos nbfd->size = 0; 2233 1.1 christos BFD_ASSERT (! nbfd->cacheable); 2234 1.1 christos 2235 1.1 christos return nbfd; 2236 1.1 christos 2237 1.1 christos error_return: 2238 1.1 christos free (buf); 2239 1.1.1.2 christos if (nbfd != NULL) 2240 1.1 christos bfd_close (nbfd); 2241 1.1.1.4 christos return NULL; 2242 1.1 christos } 2243 1.1 christos 2244 1.1 christos /* Open the next archived file. */ 2245 1.1 christos 2246 1.1 christos static bfd * 2247 1.1 christos alpha_ecoff_openr_next_archived_file (bfd *archive, bfd *last_file) 2248 1.1 christos { 2249 1.1 christos ufile_ptr filestart; 2250 1.1 christos 2251 1.1 christos if (last_file == NULL) 2252 1.1.1.6 christos filestart = bfd_ardata (archive)->first_file_filepos; 2253 1.1 christos else 2254 1.1 christos { 2255 1.1 christos struct areltdata *t; 2256 1.1 christos struct ar_hdr *h; 2257 1.1 christos bfd_size_type size; 2258 1.1 christos 2259 1.1 christos /* We can't use arelt_size here, because that uses parsed_size, 2260 1.1 christos which is the uncompressed size. We need the compressed size. */ 2261 1.1 christos t = (struct areltdata *) last_file->arelt_data; 2262 1.1.1.4 christos h = (struct ar_hdr *) t->arch_header; 2263 1.1.1.4 christos size = strtol (h->ar_size, (char **) NULL, 10); 2264 1.1.1.4 christos 2265 1.1.1.4 christos /* Pad to an even boundary... 2266 1.1.1.4 christos Note that last_file->origin can be odd in the case of 2267 1.1.1.4 christos BSD-4.4-style element with a long odd size. */ 2268 1.1 christos filestart = last_file->proxy_origin + size; 2269 1.1 christos filestart += filestart % 2; 2270 1.1.1.8 christos if (filestart < last_file->proxy_origin) 2271 1.1 christos { 2272 1.1 christos /* Prevent looping. See PR19256. */ 2273 1.1 christos bfd_set_error (bfd_error_malformed_archive); 2274 1.1 christos return NULL; 2275 1.1 christos } 2276 1.1 christos } 2277 1.1 christos 2278 1.1 christos return alpha_ecoff_get_elt_at_filepos (archive, filestart, NULL); 2279 1.1 christos } 2280 1.1 christos 2281 1.1.1.8 christos /* Open the archive file given an index into the armap. */ 2282 1.1.1.8 christos 2283 1.1 christos static bfd * 2284 1.1.1.6 christos alpha_ecoff_get_elt_at_index (bfd *abfd, symindex sym_index) 2285 1.1.1.6 christos { 2286 1.1.1.6 christos carsym *entry; 2287 1.1.1.6 christos 2288 1.1.1.6 christos entry = bfd_ardata (abfd)->symdefs + sym_index; 2289 1.1.1.6 christos return alpha_ecoff_get_elt_at_filepos (abfd, entry->file_offset, 2290 1.1.1.6 christos NULL); 2291 1.1.1.6 christos } 2292 1.1.1.6 christos 2293 1.1.1.6 christos static void 2294 1.1.1.6 christos alpha_ecoff_swap_coff_aux_in (bfd *abfd ATTRIBUTE_UNUSED, 2295 1.1.1.6 christos void *ext1 ATTRIBUTE_UNUSED, 2296 1.1.1.6 christos int type ATTRIBUTE_UNUSED, 2297 1.1.1.6 christos int in_class ATTRIBUTE_UNUSED, 2298 1.1.1.6 christos int indx ATTRIBUTE_UNUSED, 2299 1.1.1.6 christos int numaux ATTRIBUTE_UNUSED, 2300 1.1.1.6 christos void *in1 ATTRIBUTE_UNUSED) 2301 1.1.1.6 christos { 2302 1.1.1.6 christos } 2303 1.1.1.6 christos 2304 1.1.1.6 christos static void 2305 1.1.1.6 christos alpha_ecoff_swap_coff_sym_in (bfd *abfd ATTRIBUTE_UNUSED, 2306 1.1.1.6 christos void *ext1 ATTRIBUTE_UNUSED, 2307 1.1.1.6 christos void *in1 ATTRIBUTE_UNUSED) 2308 1.1.1.6 christos { 2309 1.1.1.6 christos } 2310 1.1.1.6 christos 2311 1.1.1.6 christos static void 2312 1.1.1.6 christos alpha_ecoff_swap_coff_lineno_in (bfd *abfd ATTRIBUTE_UNUSED, 2313 1.1.1.6 christos void *ext1 ATTRIBUTE_UNUSED, 2314 1.1.1.6 christos void *in1 ATTRIBUTE_UNUSED) 2315 1.1.1.6 christos { 2316 1.1.1.6 christos } 2317 1.1.1.6 christos 2318 1.1.1.6 christos static unsigned int 2319 1.1.1.6 christos alpha_ecoff_swap_coff_aux_out (bfd *abfd ATTRIBUTE_UNUSED, 2320 1.1.1.6 christos void *inp ATTRIBUTE_UNUSED, 2321 1.1.1.6 christos int type ATTRIBUTE_UNUSED, 2322 1.1.1.6 christos int in_class ATTRIBUTE_UNUSED, 2323 1.1.1.6 christos int indx ATTRIBUTE_UNUSED, 2324 1.1.1.6 christos int numaux ATTRIBUTE_UNUSED, 2325 1.1.1.6 christos void *extp ATTRIBUTE_UNUSED) 2326 1.1.1.6 christos { 2327 1.1.1.6 christos return 0; 2328 1.1.1.6 christos } 2329 1.1.1.6 christos 2330 1.1.1.6 christos static unsigned int 2331 1.1.1.6 christos alpha_ecoff_swap_coff_sym_out (bfd *abfd ATTRIBUTE_UNUSED, 2332 1.1.1.6 christos void *inp ATTRIBUTE_UNUSED, 2333 1.1.1.6 christos void *extp ATTRIBUTE_UNUSED) 2334 1.1.1.6 christos { 2335 1.1.1.6 christos return 0; 2336 1.1.1.6 christos } 2337 1.1.1.6 christos 2338 1.1.1.6 christos static unsigned int 2339 1.1.1.6 christos alpha_ecoff_swap_coff_lineno_out (bfd *abfd ATTRIBUTE_UNUSED, 2340 1.1.1.6 christos void *inp ATTRIBUTE_UNUSED, 2341 1.1.1.6 christos void *extp ATTRIBUTE_UNUSED) 2342 1.1.1.6 christos { 2343 1.1.1.6 christos return 0; 2344 1.1.1.6 christos } 2345 1.1 christos 2346 1.1 christos static unsigned int 2347 1.1 christos alpha_ecoff_swap_coff_reloc_out (bfd *abfd ATTRIBUTE_UNUSED, 2348 1.1 christos void *inp ATTRIBUTE_UNUSED, 2349 1.1 christos void *extp ATTRIBUTE_UNUSED) 2350 1.1 christos { 2351 1.1 christos return 0; 2352 1.1 christos } 2353 1.1.1.6 christos 2354 1.1.1.6 christos /* This is the ECOFF backend structure. The backend field of the 2356 1.1.1.6 christos target vector points to this. */ 2357 1.1 christos 2358 1.1 christos static const struct ecoff_backend_data alpha_ecoff_backend_data = 2359 1.1.1.8 christos { 2360 1.1.1.8 christos /* COFF backend structure. */ 2361 1.1 christos { 2362 1.1 christos alpha_ecoff_swap_coff_aux_in, alpha_ecoff_swap_coff_sym_in, 2363 1.1 christos alpha_ecoff_swap_coff_lineno_in, alpha_ecoff_swap_coff_aux_out, 2364 1.1 christos alpha_ecoff_swap_coff_sym_out, alpha_ecoff_swap_coff_lineno_out, 2365 1.1 christos alpha_ecoff_swap_coff_reloc_out, 2366 1.1 christos alpha_ecoff_swap_filehdr_out, alpha_ecoff_swap_aouthdr_out, 2367 1.1.1.11 christos alpha_ecoff_swap_scnhdr_out, 2368 1.1 christos FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, 0, FILNMLEN, true, 2369 1.1 christos ECOFF_NO_LONG_SECTION_NAMES, 4, false, 2, 32768, 2370 1.1 christos alpha_ecoff_swap_filehdr_in, alpha_ecoff_swap_aouthdr_in, 2371 1.1 christos alpha_ecoff_swap_scnhdr_in, NULL, 2372 1.1 christos alpha_ecoff_bad_format_hook, _bfd_ecoff_set_arch_mach_hook, 2373 1.1 christos alpha_ecoff_mkobject_hook, _bfd_ecoff_styp_to_sec_flags, 2374 1.1 christos _bfd_ecoff_set_alignment_hook, _bfd_ecoff_slurp_symbol_table, 2375 1.1 christos NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 2376 1.1 christos NULL, NULL, NULL, 2377 1.1 christos }, 2378 1.1 christos /* Supported architecture. */ 2379 1.1.1.8 christos bfd_arch_alpha, 2380 1.1 christos /* Initial portion of armap string. */ 2381 1.1 christos "________64", 2382 1.1 christos /* The page boundary used to align sections in a demand-paged 2383 1.1 christos executable file. E.g., 0x1000. */ 2384 1.1 christos 0x2000, 2385 1.1 christos /* TRUE if the .rdata section is part of the text segment, as on the 2386 1.1 christos Alpha. FALSE if .rdata is part of the data segment, as on the 2387 1.1 christos MIPS. */ 2388 1.1 christos true, 2389 1.1 christos /* Bitsize of constructor entries. */ 2390 1.1 christos 64, 2391 1.1 christos /* Reloc to use for constructor entries. */ 2392 1.1 christos &alpha_howto_table[ALPHA_R_REFQUAD], 2393 1.1 christos { 2394 1.1 christos /* Symbol table magic number. */ 2395 1.1 christos magicSym2, 2396 1.1 christos /* Alignment of debugging information. E.g., 4. */ 2397 1.1 christos 8, 2398 1.1 christos /* Sizes of external symbolic information. */ 2399 1.1 christos sizeof (struct hdr_ext), 2400 1.1 christos sizeof (struct dnr_ext), 2401 1.1 christos sizeof (struct pdr_ext), 2402 1.1 christos sizeof (struct sym_ext), 2403 1.1 christos sizeof (struct opt_ext), 2404 1.1 christos sizeof (struct fdr_ext), 2405 1.1 christos sizeof (struct rfd_ext), 2406 1.1 christos sizeof (struct ext_ext), 2407 1.1 christos /* Functions to swap in external symbolic data. */ 2408 1.1 christos ecoff_swap_hdr_in, 2409 1.1 christos ecoff_swap_dnr_in, 2410 1.1 christos ecoff_swap_pdr_in, 2411 1.1 christos ecoff_swap_sym_in, 2412 1.1 christos ecoff_swap_opt_in, 2413 1.1 christos ecoff_swap_fdr_in, 2414 1.1 christos ecoff_swap_rfd_in, 2415 1.1 christos ecoff_swap_ext_in, 2416 1.1 christos _bfd_ecoff_swap_tir_in, 2417 1.1 christos _bfd_ecoff_swap_rndx_in, 2418 1.1 christos /* Functions to swap out external symbolic data. */ 2419 1.1 christos ecoff_swap_hdr_out, 2420 1.1 christos ecoff_swap_dnr_out, 2421 1.1 christos ecoff_swap_pdr_out, 2422 1.1 christos ecoff_swap_sym_out, 2423 1.1 christos ecoff_swap_opt_out, 2424 1.1 christos ecoff_swap_fdr_out, 2425 1.1 christos ecoff_swap_rfd_out, 2426 1.1 christos ecoff_swap_ext_out, 2427 1.1 christos _bfd_ecoff_swap_tir_out, 2428 1.1 christos _bfd_ecoff_swap_rndx_out, 2429 1.1 christos /* Function to read in symbolic data. */ 2430 1.1 christos _bfd_ecoff_slurp_symbolic_info 2431 1.1 christos }, 2432 1.1 christos /* External reloc size. */ 2433 1.1 christos RELSZ, 2434 1.1 christos /* Reloc swapping functions. */ 2435 1.1 christos alpha_ecoff_swap_reloc_in, 2436 1.1 christos alpha_ecoff_swap_reloc_out, 2437 1.1 christos /* Backend reloc tweaking. */ 2438 1.1 christos alpha_adjust_reloc_in, 2439 1.1 christos alpha_adjust_reloc_out, 2440 1.1 christos /* Relocate section contents while linking. */ 2441 1.1 christos alpha_relocate_section, 2442 1.1 christos /* Do final adjustments to filehdr and aouthdr. */ 2443 1.1 christos alpha_adjust_headers, 2444 1.1 christos /* Read an element from an archive at a given file position. */ 2445 1.1 christos alpha_ecoff_get_elt_at_filepos 2446 1.1 christos }; 2447 1.1 christos 2448 1.1.1.2 christos /* Looking up a reloc type is Alpha specific. */ 2449 1.1.1.2 christos #define _bfd_ecoff_bfd_reloc_type_lookup alpha_bfd_reloc_type_lookup 2450 1.1.1.2 christos #define _bfd_ecoff_bfd_reloc_name_lookup \ 2451 1.1 christos alpha_bfd_reloc_name_lookup 2452 1.1 christos 2453 1.1 christos /* So is getting relocated section contents. */ 2454 1.1 christos #define _bfd_ecoff_bfd_get_relocated_section_contents \ 2455 1.1 christos alpha_ecoff_get_relocated_section_contents 2456 1.1.1.7 christos 2457 1.1 christos /* Input section flag lookup is generic. */ 2458 1.1 christos #define _bfd_ecoff_bfd_lookup_section_flags bfd_generic_lookup_section_flags 2459 1.1.1.2 christos 2460 1.1 christos /* Relaxing sections is generic. */ 2461 1.1.1.6 christos #define _bfd_ecoff_bfd_relax_section bfd_generic_relax_section 2462 1.1.1.6 christos #define _bfd_ecoff_bfd_gc_sections bfd_generic_gc_sections 2463 1.1.1.4 christos #define _bfd_ecoff_bfd_merge_sections bfd_generic_merge_sections 2464 1.1 christos #define _bfd_ecoff_bfd_is_group_section bfd_generic_is_group_section 2465 1.1.1.6 christos #define _bfd_ecoff_bfd_group_name bfd_generic_group_name 2466 1.1.1.6 christos #define _bfd_ecoff_bfd_discard_group bfd_generic_discard_group 2467 1.1.1.6 christos #define _bfd_ecoff_section_already_linked \ 2468 1.1.1.3 christos _bfd_coff_section_already_linked 2469 1.1 christos #define _bfd_ecoff_bfd_define_common_symbol bfd_generic_define_common_symbol 2470 1.1 christos #define _bfd_ecoff_bfd_link_hide_symbol _bfd_generic_link_hide_symbol 2471 1.1 christos #define _bfd_ecoff_bfd_define_start_stop bfd_generic_define_start_stop 2472 1.1 christos #define _bfd_ecoff_bfd_link_check_relocs _bfd_generic_link_check_relocs 2473 1.1 christos 2474 1.1 christos /* Installing internal relocations in a section is also generic. */ 2475 1.1.1.6 christos #define _bfd_ecoff_set_reloc _bfd_generic_set_reloc 2476 1.1.1.6 christos 2477 1.1.1.6 christos const bfd_target alpha_ecoff_le_vec = 2478 1.1 christos { 2479 1.1.1.7 christos "ecoff-littlealpha", /* name */ 2480 1.1.1.7 christos bfd_target_ecoff_flavour, 2481 1.1 christos BFD_ENDIAN_LITTLE, /* data byte order is little */ 2482 1.1 christos BFD_ENDIAN_LITTLE, /* header byte order is little */ 2483 1.1 christos 2484 1.1.1.2 christos (HAS_RELOC | EXEC_P /* object flags */ 2485 1.1.1.8 christos | HAS_LINENO | HAS_DEBUG 2486 1.1 christos | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED), 2487 1.1 christos 2488 1.1 christos (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE 2489 1.1 christos | SEC_DATA | SEC_SMALL_DATA), 2490 1.1 christos 0, /* leading underscore */ 2491 1.1 christos ' ', /* ar_pad_char */ 2492 1.1 christos 15, /* ar_max_namelen */ 2493 1.1.1.6 christos 0, /* match priority. */ 2494 1.1.1.6 christos TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ 2495 1.1.1.6 christos bfd_getl64, bfd_getl_signed_64, bfd_putl64, 2496 1.1.1.6 christos bfd_getl32, bfd_getl_signed_32, bfd_putl32, 2497 1.1.1.6 christos bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ 2498 1.1.1.6 christos bfd_getl64, bfd_getl_signed_64, bfd_putl64, 2499 1.1.1.6 christos bfd_getl32, bfd_getl_signed_32, bfd_putl32, 2500 1.1.1.6 christos bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */ 2501 1.1.1.6 christos 2502 1.1.1.6 christos { /* bfd_check_format */ 2503 1.1.1.6 christos _bfd_dummy_target, 2504 1.1.1.6 christos alpha_ecoff_object_p, 2505 1.1.1.6 christos bfd_generic_archive_p, 2506 1.1.1.6 christos _bfd_dummy_target 2507 1.1.1.6 christos }, 2508 1.1.1.6 christos { /* bfd_set_format */ 2509 1.1.1.6 christos _bfd_bool_bfd_false_error, 2510 1.1.1.6 christos _bfd_ecoff_mkobject, 2511 1.1.1.6 christos _bfd_generic_mkarchive, 2512 1.1.1.6 christos _bfd_bool_bfd_false_error 2513 1.1.1.6 christos }, 2514 1.1.1.6 christos { /* bfd_write_contents */ 2515 1.1.1.6 christos _bfd_bool_bfd_false_error, 2516 1.1.1.6 christos _bfd_ecoff_write_object_contents, 2517 1.1.1.6 christos _bfd_write_archive_contents, 2518 1.1.1.6 christos _bfd_bool_bfd_false_error 2519 1.1.1.6 christos }, 2520 1.1.1.6 christos 2521 1.1 christos BFD_JUMP_TABLE_GENERIC (_bfd_ecoff), 2522 1.1 christos BFD_JUMP_TABLE_COPY (_bfd_ecoff), 2523 1.1 christos BFD_JUMP_TABLE_CORE (_bfd_nocore), 2524 1.1.1.6 christos BFD_JUMP_TABLE_ARCHIVE (alpha_ecoff), 2525 1.1 christos BFD_JUMP_TABLE_SYMBOLS (_bfd_ecoff), 2526 BFD_JUMP_TABLE_RELOCS (_bfd_ecoff), 2527 BFD_JUMP_TABLE_WRITE (_bfd_ecoff), 2528 BFD_JUMP_TABLE_LINK (_bfd_ecoff), 2529 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), 2530 2531 NULL, 2532 2533 &alpha_ecoff_backend_data 2534 }; 2535