| 1 | /* Support for 32-bit Alpha NLM (NetWare Loadable Module) | 
|---|
| 2 | Copyright 1993, 1994, 2000, 2001 Free Software Foundation, Inc. | 
|---|
| 3 | Written by Ian Lance Taylor, Cygnus Support. | 
|---|
| 4 |  | 
|---|
| 5 | This file is part of BFD, the Binary File Descriptor library. | 
|---|
| 6 |  | 
|---|
| 7 | This program is free software; you can redistribute it and/or modify | 
|---|
| 8 | it under the terms of the GNU General Public License as published by | 
|---|
| 9 | the Free Software Foundation; either version 2 of the License, or | 
|---|
| 10 | (at your option) any later version. | 
|---|
| 11 |  | 
|---|
| 12 | This program is distributed in the hope that it will be useful, | 
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 15 | GNU General Public License for more details. | 
|---|
| 16 |  | 
|---|
| 17 | You should have received a copy of the GNU General Public License | 
|---|
| 18 | along with this program; if not, write to the Free Software | 
|---|
| 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */ | 
|---|
| 20 |  | 
|---|
| 21 | /* This file describes the 32 bit Alpha NLM format.  You might think | 
|---|
| 22 | that an Alpha chip would use a 64 bit format, but, for some reason, | 
|---|
| 23 | it doesn't.  */ | 
|---|
| 24 |  | 
|---|
| 25 | #include "bfd.h" | 
|---|
| 26 | #include "sysdep.h" | 
|---|
| 27 | #include "libbfd.h" | 
|---|
| 28 |  | 
|---|
| 29 | #define ARCH_SIZE 32 | 
|---|
| 30 |  | 
|---|
| 31 | #include "nlm/alpha-ext.h" | 
|---|
| 32 | #define Nlm_External_Fixed_Header       Nlm32_alpha_External_Fixed_Header | 
|---|
| 33 |  | 
|---|
| 34 | #include "libnlm.h" | 
|---|
| 35 |  | 
|---|
| 36 | static boolean nlm_alpha_backend_object_p | 
|---|
| 37 | PARAMS ((bfd *)); | 
|---|
| 38 | static boolean nlm_alpha_write_prefix | 
|---|
| 39 | PARAMS ((bfd *)); | 
|---|
| 40 | static boolean nlm_alpha_read_reloc | 
|---|
| 41 | PARAMS ((bfd *, nlmNAME(symbol_type) *, asection **, arelent *)); | 
|---|
| 42 | static boolean nlm_alpha_mangle_relocs | 
|---|
| 43 | PARAMS ((bfd *, asection *, PTR, bfd_vma, bfd_size_type)); | 
|---|
| 44 | static boolean nlm_alpha_read_import | 
|---|
| 45 | PARAMS ((bfd *, nlmNAME(symbol_type) *)); | 
|---|
| 46 | static boolean nlm_alpha_write_import | 
|---|
| 47 | PARAMS ((bfd *, asection *, arelent *)); | 
|---|
| 48 | static boolean nlm_alpha_set_public_section | 
|---|
| 49 | PARAMS ((bfd *, nlmNAME(symbol_type) *)); | 
|---|
| 50 | static bfd_vma nlm_alpha_get_public_offset | 
|---|
| 51 | PARAMS ((bfd *, asymbol *)); | 
|---|
| 52 | static boolean nlm_alpha_write_external | 
|---|
| 53 | PARAMS ((bfd *, bfd_size_type, asymbol *, struct reloc_and_sec *)); | 
|---|
| 54 |  | 
|---|
| 55 |  | 
|---|
| 56 | /* Alpha NLM's have a prefix header before the standard NLM.  This | 
|---|
| 57 | function reads it in, verifies the version, and seeks the bfd to | 
|---|
| 58 | the location before the regular NLM header.  */ | 
|---|
| 59 |  | 
|---|
| 60 | static boolean | 
|---|
| 61 | nlm_alpha_backend_object_p (abfd) | 
|---|
| 62 | bfd *abfd; | 
|---|
| 63 | { | 
|---|
| 64 | struct nlm32_alpha_external_prefix_header s; | 
|---|
| 65 | bfd_size_type size; | 
|---|
| 66 |  | 
|---|
| 67 | if (bfd_read ((PTR) &s, sizeof s, 1, abfd) != sizeof s) | 
|---|
| 68 | return false; | 
|---|
| 69 |  | 
|---|
| 70 | if (bfd_h_get_32 (abfd, s.magic) != NLM32_ALPHA_MAGIC) | 
|---|
| 71 | return false; | 
|---|
| 72 |  | 
|---|
| 73 | /* FIXME: Should we check the format number?  */ | 
|---|
| 74 |  | 
|---|
| 75 | /* Skip to the end of the header.  */ | 
|---|
| 76 | size = bfd_h_get_32 (abfd, s.size); | 
|---|
| 77 | if (bfd_seek (abfd, size, SEEK_SET) != 0) | 
|---|
| 78 | return false; | 
|---|
| 79 |  | 
|---|
| 80 | return true; | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 | /* Write out the prefix.  */ | 
|---|
| 84 |  | 
|---|
| 85 | static boolean | 
|---|
| 86 | nlm_alpha_write_prefix (abfd) | 
|---|
| 87 | bfd *abfd; | 
|---|
| 88 | { | 
|---|
| 89 | struct nlm32_alpha_external_prefix_header s; | 
|---|
| 90 |  | 
|---|
| 91 | memset (&s, 0, sizeof s); | 
|---|
| 92 | bfd_h_put_32 (abfd, (bfd_vma) NLM32_ALPHA_MAGIC, s.magic); | 
|---|
| 93 | bfd_h_put_32 (abfd, (bfd_vma) 2, s.format); | 
|---|
| 94 | bfd_h_put_32 (abfd, (bfd_vma) sizeof s, s.size); | 
|---|
| 95 | if (bfd_write ((PTR) &s, sizeof s, 1, abfd) != sizeof s) | 
|---|
| 96 | return false; | 
|---|
| 97 | return true; | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 |  | 
|---|
| 101 | /* How to process the various reloc types.  */ | 
|---|
| 102 |  | 
|---|
| 103 | static reloc_howto_type nlm32_alpha_howto_table[] = | 
|---|
| 104 | { | 
|---|
| 105 | /* Reloc type 0 is ignored by itself.  However, it appears after a | 
|---|
| 106 | GPDISP reloc to identify the location where the low order 16 bits | 
|---|
| 107 | of the gp register are loaded.  */ | 
|---|
| 108 | HOWTO (ALPHA_R_IGNORE,        /* type */ | 
|---|
| 109 | 0,                     /* rightshift */ | 
|---|
| 110 | 0,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 111 | 8,                     /* bitsize */ | 
|---|
| 112 | false,                 /* pc_relative */ | 
|---|
| 113 | 0,                     /* bitpos */ | 
|---|
| 114 | complain_overflow_dont, /* complain_on_overflow */ | 
|---|
| 115 | 0,                     /* special_function */ | 
|---|
| 116 | "IGNORE",              /* name */ | 
|---|
| 117 | false,                 /* partial_inplace */ | 
|---|
| 118 | 0,                     /* src_mask */ | 
|---|
| 119 | 0,                     /* dst_mask */ | 
|---|
| 120 | false),                /* pcrel_offset */ | 
|---|
| 121 |  | 
|---|
| 122 | /* A 32 bit reference to a symbol.  */ | 
|---|
| 123 | HOWTO (ALPHA_R_REFLONG,       /* type */ | 
|---|
| 124 | 0,                     /* rightshift */ | 
|---|
| 125 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 126 | 32,                    /* bitsize */ | 
|---|
| 127 | false,                 /* pc_relative */ | 
|---|
| 128 | 0,                     /* bitpos */ | 
|---|
| 129 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 130 | 0,                     /* special_function */ | 
|---|
| 131 | "REFLONG",             /* name */ | 
|---|
| 132 | true,                  /* partial_inplace */ | 
|---|
| 133 | 0xffffffff,            /* src_mask */ | 
|---|
| 134 | 0xffffffff,            /* dst_mask */ | 
|---|
| 135 | false),                /* pcrel_offset */ | 
|---|
| 136 |  | 
|---|
| 137 | /* A 64 bit reference to a symbol.  */ | 
|---|
| 138 | HOWTO (ALPHA_R_REFQUAD,       /* type */ | 
|---|
| 139 | 0,                     /* rightshift */ | 
|---|
| 140 | 4,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 141 | 64,                    /* bitsize */ | 
|---|
| 142 | false,                 /* pc_relative */ | 
|---|
| 143 | 0,                     /* bitpos */ | 
|---|
| 144 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 145 | 0,                     /* special_function */ | 
|---|
| 146 | "REFQUAD",             /* name */ | 
|---|
| 147 | true,                  /* partial_inplace */ | 
|---|
| 148 | 0xffffffffffffffff,    /* src_mask */ | 
|---|
| 149 | 0xffffffffffffffff,    /* dst_mask */ | 
|---|
| 150 | false),                /* pcrel_offset */ | 
|---|
| 151 |  | 
|---|
| 152 | /* A 32 bit GP relative offset.  This is just like REFLONG except | 
|---|
| 153 | that when the value is used the value of the gp register will be | 
|---|
| 154 | added in.  */ | 
|---|
| 155 | HOWTO (ALPHA_R_GPREL32,       /* type */ | 
|---|
| 156 | 0,                     /* rightshift */ | 
|---|
| 157 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 158 | 32,                    /* bitsize */ | 
|---|
| 159 | false,                 /* pc_relative */ | 
|---|
| 160 | 0,                     /* bitpos */ | 
|---|
| 161 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 162 | 0,                     /* special_function */ | 
|---|
| 163 | "GPREL32",             /* name */ | 
|---|
| 164 | true,                  /* partial_inplace */ | 
|---|
| 165 | 0xffffffff,            /* src_mask */ | 
|---|
| 166 | 0xffffffff,            /* dst_mask */ | 
|---|
| 167 | false),                /* pcrel_offset */ | 
|---|
| 168 |  | 
|---|
| 169 | /* Used for an instruction that refers to memory off the GP | 
|---|
| 170 | register.  The offset is 16 bits of the 32 bit instruction.  This | 
|---|
| 171 | reloc always seems to be against the .lita section.  */ | 
|---|
| 172 | HOWTO (ALPHA_R_LITERAL,       /* type */ | 
|---|
| 173 | 0,                     /* rightshift */ | 
|---|
| 174 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 175 | 16,                    /* bitsize */ | 
|---|
| 176 | false,                 /* pc_relative */ | 
|---|
| 177 | 0,                     /* bitpos */ | 
|---|
| 178 | complain_overflow_signed, /* complain_on_overflow */ | 
|---|
| 179 | 0,                     /* special_function */ | 
|---|
| 180 | "LITERAL",             /* name */ | 
|---|
| 181 | true,                  /* partial_inplace */ | 
|---|
| 182 | 0xffff,                /* src_mask */ | 
|---|
| 183 | 0xffff,                /* dst_mask */ | 
|---|
| 184 | false),                /* pcrel_offset */ | 
|---|
| 185 |  | 
|---|
| 186 | /* This reloc only appears immediately following a LITERAL reloc. | 
|---|
| 187 | It identifies a use of the literal.  It seems that the linker can | 
|---|
| 188 | use this to eliminate a portion of the .lita section.  The symbol | 
|---|
| 189 | index is special: 1 means the literal address is in the base | 
|---|
| 190 | register of a memory format instruction; 2 means the literal | 
|---|
| 191 | address is in the byte offset register of a byte-manipulation | 
|---|
| 192 | instruction; 3 means the literal address is in the target | 
|---|
| 193 | register of a jsr instruction.  This does not actually do any | 
|---|
| 194 | relocation.  */ | 
|---|
| 195 | HOWTO (ALPHA_R_LITUSE,        /* type */ | 
|---|
| 196 | 0,                     /* rightshift */ | 
|---|
| 197 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 198 | 32,                    /* bitsize */ | 
|---|
| 199 | false,                 /* pc_relative */ | 
|---|
| 200 | 0,                     /* bitpos */ | 
|---|
| 201 | complain_overflow_dont, /* complain_on_overflow */ | 
|---|
| 202 | 0,                     /* special_function */ | 
|---|
| 203 | "LITUSE",              /* name */ | 
|---|
| 204 | false,                 /* partial_inplace */ | 
|---|
| 205 | 0,                     /* src_mask */ | 
|---|
| 206 | 0,                     /* dst_mask */ | 
|---|
| 207 | false),                /* pcrel_offset */ | 
|---|
| 208 |  | 
|---|
| 209 | /* Load the gp register.  This is always used for a ldah instruction | 
|---|
| 210 | which loads the upper 16 bits of the gp register.  The next reloc | 
|---|
| 211 | will be an IGNORE reloc which identifies the location of the lda | 
|---|
| 212 | instruction which loads the lower 16 bits.  The symbol index of | 
|---|
| 213 | the GPDISP instruction appears to actually be the number of bytes | 
|---|
| 214 | between the ldah and lda instructions.  This gives two different | 
|---|
| 215 | ways to determine where the lda instruction is; I don't know why | 
|---|
| 216 | both are used.  The value to use for the relocation is the | 
|---|
| 217 | difference between the GP value and the current location; the | 
|---|
| 218 | load will always be done against a register holding the current | 
|---|
| 219 | address.  */ | 
|---|
| 220 | HOWTO (ALPHA_R_GPDISP,        /* type */ | 
|---|
| 221 | 16,                    /* rightshift */ | 
|---|
| 222 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 223 | 16,                    /* bitsize */ | 
|---|
| 224 | true,                  /* pc_relative */ | 
|---|
| 225 | 0,                     /* bitpos */ | 
|---|
| 226 | complain_overflow_dont, /* complain_on_overflow */ | 
|---|
| 227 | 0,                     /* special_function */ | 
|---|
| 228 | "GPDISP",              /* name */ | 
|---|
| 229 | true,                  /* partial_inplace */ | 
|---|
| 230 | 0xffff,                /* src_mask */ | 
|---|
| 231 | 0xffff,                /* dst_mask */ | 
|---|
| 232 | true),                 /* pcrel_offset */ | 
|---|
| 233 |  | 
|---|
| 234 | /* A 21 bit branch.  The native assembler generates these for | 
|---|
| 235 | branches within the text segment, and also fills in the PC | 
|---|
| 236 | relative offset in the instruction.  It seems to me that this | 
|---|
| 237 | reloc, unlike the others, is not partial_inplace.  */ | 
|---|
| 238 | HOWTO (ALPHA_R_BRADDR,        /* type */ | 
|---|
| 239 | 2,                     /* rightshift */ | 
|---|
| 240 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 241 | 21,                    /* bitsize */ | 
|---|
| 242 | true,                  /* pc_relative */ | 
|---|
| 243 | 0,                     /* bitpos */ | 
|---|
| 244 | complain_overflow_signed, /* complain_on_overflow */ | 
|---|
| 245 | 0,                     /* special_function */ | 
|---|
| 246 | "BRADDR",              /* name */ | 
|---|
| 247 | false,                 /* partial_inplace */ | 
|---|
| 248 | 0,                     /* src_mask */ | 
|---|
| 249 | 0x1fffff,              /* dst_mask */ | 
|---|
| 250 | false),                /* pcrel_offset */ | 
|---|
| 251 |  | 
|---|
| 252 | /* A hint for a jump to a register.  */ | 
|---|
| 253 | HOWTO (ALPHA_R_HINT,          /* type */ | 
|---|
| 254 | 2,                     /* rightshift */ | 
|---|
| 255 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 256 | 14,                    /* bitsize */ | 
|---|
| 257 | false,                 /* pc_relative */ | 
|---|
| 258 | 0,                     /* bitpos */ | 
|---|
| 259 | complain_overflow_dont, /* complain_on_overflow */ | 
|---|
| 260 | 0,                     /* special_function */ | 
|---|
| 261 | "HINT",                /* name */ | 
|---|
| 262 | true,                  /* partial_inplace */ | 
|---|
| 263 | 0x3fff,                /* src_mask */ | 
|---|
| 264 | 0x3fff,                /* dst_mask */ | 
|---|
| 265 | false),                /* pcrel_offset */ | 
|---|
| 266 |  | 
|---|
| 267 | /* 16 bit PC relative offset.  */ | 
|---|
| 268 | HOWTO (ALPHA_R_SREL16,        /* type */ | 
|---|
| 269 | 0,                     /* rightshift */ | 
|---|
| 270 | 1,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 271 | 16,                    /* bitsize */ | 
|---|
| 272 | true,                  /* pc_relative */ | 
|---|
| 273 | 0,                     /* bitpos */ | 
|---|
| 274 | complain_overflow_signed, /* complain_on_overflow */ | 
|---|
| 275 | 0,                     /* special_function */ | 
|---|
| 276 | "SREL16",              /* name */ | 
|---|
| 277 | true,                  /* partial_inplace */ | 
|---|
| 278 | 0xffff,                /* src_mask */ | 
|---|
| 279 | 0xffff,                /* dst_mask */ | 
|---|
| 280 | false),                /* pcrel_offset */ | 
|---|
| 281 |  | 
|---|
| 282 | /* 32 bit PC relative offset.  */ | 
|---|
| 283 | HOWTO (ALPHA_R_SREL32,        /* type */ | 
|---|
| 284 | 0,                     /* rightshift */ | 
|---|
| 285 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 286 | 32,                    /* bitsize */ | 
|---|
| 287 | true,                  /* pc_relative */ | 
|---|
| 288 | 0,                     /* bitpos */ | 
|---|
| 289 | complain_overflow_signed, /* complain_on_overflow */ | 
|---|
| 290 | 0,                     /* special_function */ | 
|---|
| 291 | "SREL32",              /* name */ | 
|---|
| 292 | true,                  /* partial_inplace */ | 
|---|
| 293 | 0xffffffff,            /* src_mask */ | 
|---|
| 294 | 0xffffffff,            /* dst_mask */ | 
|---|
| 295 | false),                /* pcrel_offset */ | 
|---|
| 296 |  | 
|---|
| 297 | /* A 64 bit PC relative offset.  */ | 
|---|
| 298 | HOWTO (ALPHA_R_SREL64,        /* type */ | 
|---|
| 299 | 0,                     /* rightshift */ | 
|---|
| 300 | 4,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 301 | 64,                    /* bitsize */ | 
|---|
| 302 | true,                  /* pc_relative */ | 
|---|
| 303 | 0,                     /* bitpos */ | 
|---|
| 304 | complain_overflow_signed, /* complain_on_overflow */ | 
|---|
| 305 | 0,                     /* special_function */ | 
|---|
| 306 | "SREL64",              /* name */ | 
|---|
| 307 | true,                  /* partial_inplace */ | 
|---|
| 308 | 0xffffffffffffffff,    /* src_mask */ | 
|---|
| 309 | 0xffffffffffffffff,    /* dst_mask */ | 
|---|
| 310 | false),                /* pcrel_offset */ | 
|---|
| 311 |  | 
|---|
| 312 | /* Push a value on the reloc evaluation stack.  */ | 
|---|
| 313 | HOWTO (ALPHA_R_OP_PUSH,       /* type */ | 
|---|
| 314 | 0,                     /* rightshift */ | 
|---|
| 315 | 0,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 316 | 0,                     /* bitsize */ | 
|---|
| 317 | false,                 /* pc_relative */ | 
|---|
| 318 | 0,                     /* bitpos */ | 
|---|
| 319 | complain_overflow_dont, /* complain_on_overflow */ | 
|---|
| 320 | 0,                     /* special_function */ | 
|---|
| 321 | "OP_PUSH",             /* name */ | 
|---|
| 322 | false,                 /* partial_inplace */ | 
|---|
| 323 | 0,                     /* src_mask */ | 
|---|
| 324 | 0,                     /* dst_mask */ | 
|---|
| 325 | false),                /* pcrel_offset */ | 
|---|
| 326 |  | 
|---|
| 327 | /* Store the value from the stack at the given address.  Store it in | 
|---|
| 328 | a bitfield of size r_size starting at bit position r_offset.  */ | 
|---|
| 329 | HOWTO (ALPHA_R_OP_STORE,      /* type */ | 
|---|
| 330 | 0,                     /* rightshift */ | 
|---|
| 331 | 4,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 332 | 64,                    /* bitsize */ | 
|---|
| 333 | false,                 /* pc_relative */ | 
|---|
| 334 | 0,                     /* bitpos */ | 
|---|
| 335 | complain_overflow_dont, /* complain_on_overflow */ | 
|---|
| 336 | 0,                     /* special_function */ | 
|---|
| 337 | "OP_STORE",            /* name */ | 
|---|
| 338 | false,                 /* partial_inplace */ | 
|---|
| 339 | 0,                     /* src_mask */ | 
|---|
| 340 | 0xffffffffffffffff,    /* dst_mask */ | 
|---|
| 341 | false),                /* pcrel_offset */ | 
|---|
| 342 |  | 
|---|
| 343 | /* Subtract the reloc address from the value on the top of the | 
|---|
| 344 | relocation stack.  */ | 
|---|
| 345 | HOWTO (ALPHA_R_OP_PSUB,       /* type */ | 
|---|
| 346 | 0,                     /* rightshift */ | 
|---|
| 347 | 0,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 348 | 0,                     /* bitsize */ | 
|---|
| 349 | false,                 /* pc_relative */ | 
|---|
| 350 | 0,                     /* bitpos */ | 
|---|
| 351 | complain_overflow_dont, /* complain_on_overflow */ | 
|---|
| 352 | 0,                     /* special_function */ | 
|---|
| 353 | "OP_PSUB",             /* name */ | 
|---|
| 354 | false,                 /* partial_inplace */ | 
|---|
| 355 | 0,                     /* src_mask */ | 
|---|
| 356 | 0,                     /* dst_mask */ | 
|---|
| 357 | false),                /* pcrel_offset */ | 
|---|
| 358 |  | 
|---|
| 359 | /* Shift the value on the top of the relocation stack right by the | 
|---|
| 360 | given value.  */ | 
|---|
| 361 | HOWTO (ALPHA_R_OP_PRSHIFT,    /* type */ | 
|---|
| 362 | 0,                     /* rightshift */ | 
|---|
| 363 | 0,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 364 | 0,                     /* bitsize */ | 
|---|
| 365 | false,                 /* pc_relative */ | 
|---|
| 366 | 0,                     /* bitpos */ | 
|---|
| 367 | complain_overflow_dont, /* complain_on_overflow */ | 
|---|
| 368 | 0,                      /* special_function */ | 
|---|
| 369 | "OP_PRSHIFT",          /* name */ | 
|---|
| 370 | false,                 /* partial_inplace */ | 
|---|
| 371 | 0,                     /* src_mask */ | 
|---|
| 372 | 0,                     /* dst_mask */ | 
|---|
| 373 | false),                /* pcrel_offset */ | 
|---|
| 374 |  | 
|---|
| 375 | /* Adjust the GP value for a new range in the object file.  */ | 
|---|
| 376 | HOWTO (ALPHA_R_GPVALUE,       /* type */ | 
|---|
| 377 | 0,                     /* rightshift */ | 
|---|
| 378 | 0,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 379 | 0,                     /* bitsize */ | 
|---|
| 380 | false,                 /* pc_relative */ | 
|---|
| 381 | 0,                     /* bitpos */ | 
|---|
| 382 | complain_overflow_dont, /* complain_on_overflow */ | 
|---|
| 383 | 0,                     /* special_function */ | 
|---|
| 384 | "GPVALUE",             /* name */ | 
|---|
| 385 | false,                 /* partial_inplace */ | 
|---|
| 386 | 0,                     /* src_mask */ | 
|---|
| 387 | 0,                     /* dst_mask */ | 
|---|
| 388 | false)                 /* pcrel_offset */ | 
|---|
| 389 | }; | 
|---|
| 390 |  | 
|---|
| 391 | static reloc_howto_type nlm32_alpha_nw_howto = | 
|---|
| 392 | HOWTO (ALPHA_R_NW_RELOC,      /* type */ | 
|---|
| 393 | 0,                     /* rightshift */ | 
|---|
| 394 | 0,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 395 | 0,                     /* bitsize */ | 
|---|
| 396 | false,                 /* pc_relative */ | 
|---|
| 397 | 0,                     /* bitpos */ | 
|---|
| 398 | complain_overflow_dont, /* complain_on_overflow */ | 
|---|
| 399 | 0,                     /* special_function */ | 
|---|
| 400 | "NW_RELOC",            /* name */ | 
|---|
| 401 | false,                 /* partial_inplace */ | 
|---|
| 402 | 0,                     /* src_mask */ | 
|---|
| 403 | 0,                     /* dst_mask */ | 
|---|
| 404 | false);                /* pcrel_offset */ | 
|---|
| 405 |  | 
|---|
| 406 | /* Read an Alpha NLM reloc.  This routine keeps some static data which | 
|---|
| 407 | it uses when handling local relocs.  This only works correctly | 
|---|
| 408 | because all the local relocs are read at once.  */ | 
|---|
| 409 |  | 
|---|
| 410 | static boolean | 
|---|
| 411 | nlm_alpha_read_reloc (abfd, sym, secp, rel) | 
|---|
| 412 | bfd *abfd; | 
|---|
| 413 | nlmNAME(symbol_type) *sym; | 
|---|
| 414 | asection **secp; | 
|---|
| 415 | arelent *rel; | 
|---|
| 416 | { | 
|---|
| 417 | static bfd_vma gp_value; | 
|---|
| 418 | static bfd_vma lita_address; | 
|---|
| 419 | struct nlm32_alpha_external_reloc ext; | 
|---|
| 420 | bfd_vma r_vaddr; | 
|---|
| 421 | long r_symndx; | 
|---|
| 422 | int r_type, r_extern, r_offset, r_size; | 
|---|
| 423 | asection *code_sec, *data_sec; | 
|---|
| 424 |  | 
|---|
| 425 | /* Read the reloc from the file.  */ | 
|---|
| 426 | if (bfd_read (&ext, sizeof ext, 1, abfd) != sizeof ext) | 
|---|
| 427 | return false; | 
|---|
| 428 |  | 
|---|
| 429 | /* Swap in the reloc information.  */ | 
|---|
| 430 | r_vaddr = bfd_h_get_64 (abfd, (bfd_byte *) ext.r_vaddr); | 
|---|
| 431 | r_symndx = bfd_h_get_32 (abfd, (bfd_byte *) ext.r_symndx); | 
|---|
| 432 |  | 
|---|
| 433 | BFD_ASSERT (bfd_little_endian (abfd)); | 
|---|
| 434 |  | 
|---|
| 435 | r_type = ((ext.r_bits[0] & RELOC_BITS0_TYPE_LITTLE) | 
|---|
| 436 | >> RELOC_BITS0_TYPE_SH_LITTLE); | 
|---|
| 437 | r_extern = (ext.r_bits[1] & RELOC_BITS1_EXTERN_LITTLE) != 0; | 
|---|
| 438 | r_offset = ((ext.r_bits[1] & RELOC_BITS1_OFFSET_LITTLE) | 
|---|
| 439 | >> RELOC_BITS1_OFFSET_SH_LITTLE); | 
|---|
| 440 | /* Ignore the reserved bits.  */ | 
|---|
| 441 | r_size = ((ext.r_bits[3] & RELOC_BITS3_SIZE_LITTLE) | 
|---|
| 442 | >> RELOC_BITS3_SIZE_SH_LITTLE); | 
|---|
| 443 |  | 
|---|
| 444 | /* Fill in the BFD arelent structure.  */ | 
|---|
| 445 | code_sec = bfd_get_section_by_name (abfd, NLM_CODE_NAME); | 
|---|
| 446 | data_sec = bfd_get_section_by_name (abfd, NLM_INITIALIZED_DATA_NAME); | 
|---|
| 447 | if (r_extern) | 
|---|
| 448 | { | 
|---|
| 449 | /* External relocations are only used for imports.  */ | 
|---|
| 450 | BFD_ASSERT (sym != NULL); | 
|---|
| 451 | /* We don't need to set sym_ptr_ptr for this case.  It is set in | 
|---|
| 452 | nlm_canonicalize_reloc.  */ | 
|---|
| 453 | rel->sym_ptr_ptr = NULL; | 
|---|
| 454 | rel->addend = 0; | 
|---|
| 455 | } | 
|---|
| 456 | else | 
|---|
| 457 | { | 
|---|
| 458 | /* Internal relocations are only used for local relocation | 
|---|
| 459 | fixups.  If they are not NW_RELOC or GPDISP or IGNORE, they | 
|---|
| 460 | must be against .text or .data.  */ | 
|---|
| 461 | BFD_ASSERT (r_type == ALPHA_R_NW_RELOC || sym == NULL); | 
|---|
| 462 | if (r_type == ALPHA_R_NW_RELOC | 
|---|
| 463 | || r_type == ALPHA_R_GPDISP | 
|---|
| 464 | || r_type == ALPHA_R_IGNORE) | 
|---|
| 465 | { | 
|---|
| 466 | rel->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; | 
|---|
| 467 | rel->addend = 0; | 
|---|
| 468 | } | 
|---|
| 469 | else if (r_symndx == ALPHA_RELOC_SECTION_TEXT) | 
|---|
| 470 | { | 
|---|
| 471 | rel->sym_ptr_ptr = code_sec->symbol_ptr_ptr; | 
|---|
| 472 | BFD_ASSERT (bfd_get_section_vma (abfd, code_sec) == 0); | 
|---|
| 473 | rel->addend = 0; | 
|---|
| 474 | } | 
|---|
| 475 | else if (r_symndx == ALPHA_RELOC_SECTION_DATA) | 
|---|
| 476 | { | 
|---|
| 477 | rel->sym_ptr_ptr = data_sec->symbol_ptr_ptr; | 
|---|
| 478 | rel->addend = - bfd_get_section_vma (abfd, data_sec); | 
|---|
| 479 | } | 
|---|
| 480 | else | 
|---|
| 481 | { | 
|---|
| 482 | BFD_ASSERT (0); | 
|---|
| 483 | rel->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; | 
|---|
| 484 | rel->addend = 0; | 
|---|
| 485 | } | 
|---|
| 486 | } | 
|---|
| 487 |  | 
|---|
| 488 | /* We use the address to determine whether the reloc is in the .text | 
|---|
| 489 | or .data section.  R_NW_RELOC relocs don't really have a section, | 
|---|
| 490 | so we put them in .text.  */ | 
|---|
| 491 | if (r_type == ALPHA_R_NW_RELOC | 
|---|
| 492 | || r_vaddr < bfd_section_size (abfd, code_sec)) | 
|---|
| 493 | { | 
|---|
| 494 | *secp = code_sec; | 
|---|
| 495 | rel->address = r_vaddr; | 
|---|
| 496 | } | 
|---|
| 497 | else | 
|---|
| 498 | { | 
|---|
| 499 | *secp = data_sec; | 
|---|
| 500 | rel->address = r_vaddr - bfd_section_size (abfd, code_sec); | 
|---|
| 501 | } | 
|---|
| 502 |  | 
|---|
| 503 | /* We must adjust the addend based on the type.  */ | 
|---|
| 504 | BFD_ASSERT ((r_type >= 0 && r_type <= ALPHA_R_GPVALUE) | 
|---|
| 505 | || r_type == ALPHA_R_NW_RELOC); | 
|---|
| 506 |  | 
|---|
| 507 | switch (r_type) | 
|---|
| 508 | { | 
|---|
| 509 | case ALPHA_R_BRADDR: | 
|---|
| 510 | case ALPHA_R_SREL16: | 
|---|
| 511 | case ALPHA_R_SREL32: | 
|---|
| 512 | case ALPHA_R_SREL64: | 
|---|
| 513 | /* The PC relative relocs do not seem to use the section VMA as | 
|---|
| 514 | a negative addend.  */ | 
|---|
| 515 | rel->addend = 0; | 
|---|
| 516 | break; | 
|---|
| 517 |  | 
|---|
| 518 | case ALPHA_R_GPREL32: | 
|---|
| 519 | /* Copy the gp value for this object file into the addend, to | 
|---|
| 520 | ensure that we are not confused by the linker.  */ | 
|---|
| 521 | if (! r_extern) | 
|---|
| 522 | rel->addend += gp_value; | 
|---|
| 523 | break; | 
|---|
| 524 |  | 
|---|
| 525 | case ALPHA_R_LITERAL: | 
|---|
| 526 | BFD_ASSERT (! r_extern); | 
|---|
| 527 | rel->addend += lita_address; | 
|---|
| 528 | break; | 
|---|
| 529 |  | 
|---|
| 530 | case ALPHA_R_LITUSE: | 
|---|
| 531 | case ALPHA_R_GPDISP: | 
|---|
| 532 | /* The LITUSE and GPDISP relocs do not use a symbol, or an | 
|---|
| 533 | addend, but they do use a special code.  Put this code in the | 
|---|
| 534 | addend field.  */ | 
|---|
| 535 | rel->addend = r_symndx; | 
|---|
| 536 | rel->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; | 
|---|
| 537 | break; | 
|---|
| 538 |  | 
|---|
| 539 | case ALPHA_R_OP_STORE: | 
|---|
| 540 | /* The STORE reloc needs the size and offset fields.  We store | 
|---|
| 541 | them in the addend.  */ | 
|---|
| 542 | BFD_ASSERT (r_offset < 256 && r_size < 256); | 
|---|
| 543 | rel->addend = (r_offset << 8) + r_size; | 
|---|
| 544 | break; | 
|---|
| 545 |  | 
|---|
| 546 | case ALPHA_R_OP_PUSH: | 
|---|
| 547 | case ALPHA_R_OP_PSUB: | 
|---|
| 548 | case ALPHA_R_OP_PRSHIFT: | 
|---|
| 549 | /* The PUSH, PSUB and PRSHIFT relocs do not actually use an | 
|---|
| 550 | address.  I believe that the address supplied is really an | 
|---|
| 551 | addend.  */ | 
|---|
| 552 | rel->addend = r_vaddr; | 
|---|
| 553 | break; | 
|---|
| 554 |  | 
|---|
| 555 | case ALPHA_R_GPVALUE: | 
|---|
| 556 | /* Record the new gp value.  */ | 
|---|
| 557 | gp_value += r_symndx; | 
|---|
| 558 | rel->addend = gp_value; | 
|---|
| 559 | break; | 
|---|
| 560 |  | 
|---|
| 561 | case ALPHA_R_IGNORE: | 
|---|
| 562 | /* If the type is ALPHA_R_IGNORE, make sure this is a reference | 
|---|
| 563 | to the absolute section so that the reloc is ignored.  For | 
|---|
| 564 | some reason the address of this reloc type is not adjusted by | 
|---|
| 565 | the section vma.  We record the gp value for this object file | 
|---|
| 566 | here, for convenience when doing the GPDISP relocation.  */ | 
|---|
| 567 | rel->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; | 
|---|
| 568 | rel->address = r_vaddr; | 
|---|
| 569 | rel->addend = gp_value; | 
|---|
| 570 | break; | 
|---|
| 571 |  | 
|---|
| 572 | case ALPHA_R_NW_RELOC: | 
|---|
| 573 | /* If this is SETGP, we set the addend to 0.  Otherwise we set | 
|---|
| 574 | the addend to the size of the .lita section (this is | 
|---|
| 575 | r_symndx) plus 1.  We have already set the address of the | 
|---|
| 576 | reloc to r_vaddr.  */ | 
|---|
| 577 | if (r_size == ALPHA_R_NW_RELOC_SETGP) | 
|---|
| 578 | { | 
|---|
| 579 | gp_value = r_vaddr; | 
|---|
| 580 | rel->addend = 0; | 
|---|
| 581 | } | 
|---|
| 582 | else if (r_size == ALPHA_R_NW_RELOC_LITA) | 
|---|
| 583 | { | 
|---|
| 584 | lita_address = r_vaddr; | 
|---|
| 585 | rel->addend = r_symndx + 1; | 
|---|
| 586 | } | 
|---|
| 587 | else | 
|---|
| 588 | BFD_ASSERT (0); | 
|---|
| 589 | rel->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; | 
|---|
| 590 | break; | 
|---|
| 591 |  | 
|---|
| 592 | default: | 
|---|
| 593 | break; | 
|---|
| 594 | } | 
|---|
| 595 |  | 
|---|
| 596 | if (r_type == ALPHA_R_NW_RELOC) | 
|---|
| 597 | rel->howto = &nlm32_alpha_nw_howto; | 
|---|
| 598 | else | 
|---|
| 599 | rel->howto = &nlm32_alpha_howto_table[r_type]; | 
|---|
| 600 |  | 
|---|
| 601 | return true; | 
|---|
| 602 | } | 
|---|
| 603 |  | 
|---|
| 604 | /* Mangle Alpha NLM relocs for output.  */ | 
|---|
| 605 |  | 
|---|
| 606 | static boolean | 
|---|
| 607 | nlm_alpha_mangle_relocs (abfd, sec, data, offset, count) | 
|---|
| 608 | bfd *abfd ATTRIBUTE_UNUSED; | 
|---|
| 609 | asection *sec ATTRIBUTE_UNUSED; | 
|---|
| 610 | PTR data ATTRIBUTE_UNUSED; | 
|---|
| 611 | bfd_vma offset ATTRIBUTE_UNUSED; | 
|---|
| 612 | bfd_size_type count ATTRIBUTE_UNUSED; | 
|---|
| 613 | { | 
|---|
| 614 | return true; | 
|---|
| 615 | } | 
|---|
| 616 |  | 
|---|
| 617 | /* Read an ALPHA NLM import record */ | 
|---|
| 618 |  | 
|---|
| 619 | static boolean | 
|---|
| 620 | nlm_alpha_read_import (abfd, sym) | 
|---|
| 621 | bfd *abfd; | 
|---|
| 622 | nlmNAME(symbol_type) *sym; | 
|---|
| 623 | { | 
|---|
| 624 | struct nlm_relent *nlm_relocs;        /* relocation records for symbol */ | 
|---|
| 625 | bfd_size_type rcount;                 /* number of relocs */ | 
|---|
| 626 | bfd_byte temp[NLM_TARGET_LONG_SIZE];  /* temporary 32-bit value */ | 
|---|
| 627 | unsigned char symlength;              /* length of symbol name */ | 
|---|
| 628 | char *name; | 
|---|
| 629 |  | 
|---|
| 630 | if (bfd_read ((PTR) &symlength, sizeof (symlength), 1, abfd) | 
|---|
| 631 | != sizeof (symlength)) | 
|---|
| 632 | return false; | 
|---|
| 633 | sym -> symbol.the_bfd = abfd; | 
|---|
| 634 | name = bfd_alloc (abfd, symlength + 1); | 
|---|
| 635 | if (name == NULL) | 
|---|
| 636 | return false; | 
|---|
| 637 | if (bfd_read (name, symlength, 1, abfd) != symlength) | 
|---|
| 638 | return false; | 
|---|
| 639 | name[symlength] = '\0'; | 
|---|
| 640 | sym -> symbol.name = name; | 
|---|
| 641 | sym -> symbol.flags = 0; | 
|---|
| 642 | sym -> symbol.value = 0; | 
|---|
| 643 | sym -> symbol.section = bfd_und_section_ptr; | 
|---|
| 644 | if (bfd_read ((PTR) temp, sizeof (temp), 1, abfd) != sizeof (temp)) | 
|---|
| 645 | return false; | 
|---|
| 646 | rcount = bfd_h_get_32 (abfd, temp); | 
|---|
| 647 | nlm_relocs = ((struct nlm_relent *) | 
|---|
| 648 | bfd_alloc (abfd, rcount * sizeof (struct nlm_relent))); | 
|---|
| 649 | if (!nlm_relocs) | 
|---|
| 650 | return false; | 
|---|
| 651 | sym -> relocs = nlm_relocs; | 
|---|
| 652 | sym -> rcnt = 0; | 
|---|
| 653 | while (sym -> rcnt < rcount) | 
|---|
| 654 | { | 
|---|
| 655 | asection *section; | 
|---|
| 656 |  | 
|---|
| 657 | if (nlm_alpha_read_reloc (abfd, sym, §ion, | 
|---|
| 658 | &nlm_relocs -> reloc) | 
|---|
| 659 | == false) | 
|---|
| 660 | return false; | 
|---|
| 661 | nlm_relocs -> section = section; | 
|---|
| 662 | nlm_relocs++; | 
|---|
| 663 | sym -> rcnt++; | 
|---|
| 664 | } | 
|---|
| 665 |  | 
|---|
| 666 | return true; | 
|---|
| 667 | } | 
|---|
| 668 |  | 
|---|
| 669 | /* Write an Alpha NLM reloc.  */ | 
|---|
| 670 |  | 
|---|
| 671 | static boolean | 
|---|
| 672 | nlm_alpha_write_import (abfd, sec, rel) | 
|---|
| 673 | bfd *abfd; | 
|---|
| 674 | asection *sec; | 
|---|
| 675 | arelent *rel; | 
|---|
| 676 | { | 
|---|
| 677 | asymbol *sym; | 
|---|
| 678 | bfd_vma r_vaddr; | 
|---|
| 679 | long r_symndx; | 
|---|
| 680 | int r_type, r_extern, r_offset, r_size; | 
|---|
| 681 | struct nlm32_alpha_external_reloc ext; | 
|---|
| 682 |  | 
|---|
| 683 | sym = *rel->sym_ptr_ptr; | 
|---|
| 684 |  | 
|---|
| 685 | /* Get values for the relocation fields.  */ | 
|---|
| 686 | r_type = rel->howto->type; | 
|---|
| 687 | if (r_type != ALPHA_R_NW_RELOC) | 
|---|
| 688 | { | 
|---|
| 689 | r_vaddr = bfd_get_section_vma (abfd, sec) + rel->address; | 
|---|
| 690 | if ((sec->flags & SEC_CODE) == 0) | 
|---|
| 691 | r_vaddr += bfd_section_size (abfd, | 
|---|
| 692 | bfd_get_section_by_name (abfd, | 
|---|
| 693 | NLM_CODE_NAME)); | 
|---|
| 694 | if (bfd_is_und_section (bfd_get_section (sym))) | 
|---|
| 695 | { | 
|---|
| 696 | r_extern = 1; | 
|---|
| 697 | r_symndx = 0; | 
|---|
| 698 | } | 
|---|
| 699 | else | 
|---|
| 700 | { | 
|---|
| 701 | r_extern = 0; | 
|---|
| 702 | if (bfd_get_section_flags (abfd, bfd_get_section (sym)) & SEC_CODE) | 
|---|
| 703 | r_symndx = ALPHA_RELOC_SECTION_TEXT; | 
|---|
| 704 | else | 
|---|
| 705 | r_symndx = ALPHA_RELOC_SECTION_DATA; | 
|---|
| 706 | } | 
|---|
| 707 | r_offset = 0; | 
|---|
| 708 | r_size = 0; | 
|---|
| 709 |  | 
|---|
| 710 | switch (r_type) | 
|---|
| 711 | { | 
|---|
| 712 | case ALPHA_R_LITUSE: | 
|---|
| 713 | case ALPHA_R_GPDISP: | 
|---|
| 714 | r_symndx = rel->addend; | 
|---|
| 715 | break; | 
|---|
| 716 |  | 
|---|
| 717 | case ALPHA_R_OP_STORE: | 
|---|
| 718 | r_size = rel->addend & 0xff; | 
|---|
| 719 | r_offset = (rel->addend >> 8) & 0xff; | 
|---|
| 720 | break; | 
|---|
| 721 |  | 
|---|
| 722 | case ALPHA_R_OP_PUSH: | 
|---|
| 723 | case ALPHA_R_OP_PSUB: | 
|---|
| 724 | case ALPHA_R_OP_PRSHIFT: | 
|---|
| 725 | r_vaddr = rel->addend; | 
|---|
| 726 | break; | 
|---|
| 727 |  | 
|---|
| 728 | case ALPHA_R_IGNORE: | 
|---|
| 729 | r_vaddr = rel->address; | 
|---|
| 730 | break; | 
|---|
| 731 |  | 
|---|
| 732 | default: | 
|---|
| 733 | break; | 
|---|
| 734 | } | 
|---|
| 735 | } | 
|---|
| 736 | else | 
|---|
| 737 | { | 
|---|
| 738 | /* r_type == ALPHA_R_NW_RELOC */ | 
|---|
| 739 | r_vaddr = rel->address; | 
|---|
| 740 | if (rel->addend == 0) | 
|---|
| 741 | { | 
|---|
| 742 | r_symndx = 0; | 
|---|
| 743 | r_size = ALPHA_R_NW_RELOC_SETGP; | 
|---|
| 744 | } | 
|---|
| 745 | else | 
|---|
| 746 | { | 
|---|
| 747 | r_symndx = rel->addend - 1; | 
|---|
| 748 | r_size = ALPHA_R_NW_RELOC_LITA; | 
|---|
| 749 | } | 
|---|
| 750 | r_extern = 0; | 
|---|
| 751 | r_offset = 0; | 
|---|
| 752 | } | 
|---|
| 753 |  | 
|---|
| 754 | /* Swap out the relocation fields.  */ | 
|---|
| 755 | bfd_h_put_64 (abfd, r_vaddr, (bfd_byte *) ext.r_vaddr); | 
|---|
| 756 | bfd_h_put_32 (abfd, r_symndx, (bfd_byte *) ext.r_symndx); | 
|---|
| 757 |  | 
|---|
| 758 | BFD_ASSERT (bfd_little_endian (abfd)); | 
|---|
| 759 |  | 
|---|
| 760 | ext.r_bits[0] = ((r_type << RELOC_BITS0_TYPE_SH_LITTLE) | 
|---|
| 761 | & RELOC_BITS0_TYPE_LITTLE); | 
|---|
| 762 | ext.r_bits[1] = ((r_extern ? RELOC_BITS1_EXTERN_LITTLE : 0) | 
|---|
| 763 | | ((r_offset << RELOC_BITS1_OFFSET_SH_LITTLE) | 
|---|
| 764 | & RELOC_BITS1_OFFSET_LITTLE)); | 
|---|
| 765 | ext.r_bits[2] = 0; | 
|---|
| 766 | ext.r_bits[3] = ((r_size << RELOC_BITS3_SIZE_SH_LITTLE) | 
|---|
| 767 | & RELOC_BITS3_SIZE_LITTLE); | 
|---|
| 768 |  | 
|---|
| 769 | /* Write out the relocation.  */ | 
|---|
| 770 | if (bfd_write (&ext, sizeof ext, 1, abfd) != sizeof ext) | 
|---|
| 771 | return false; | 
|---|
| 772 |  | 
|---|
| 773 | return true; | 
|---|
| 774 | } | 
|---|
| 775 |  | 
|---|
| 776 |  | 
|---|
| 777 | /* Alpha NetWare does not use the high bit to determine whether a | 
|---|
| 778 | public symbol is in the code segment or the data segment.  Instead, | 
|---|
| 779 | it just uses the address.  The set_public_section and | 
|---|
| 780 | get_public_offset routines override the default code which uses the | 
|---|
| 781 | high bit.  */ | 
|---|
| 782 |  | 
|---|
| 783 | /* Set the section for a public symbol.  */ | 
|---|
| 784 |  | 
|---|
| 785 | static boolean | 
|---|
| 786 | nlm_alpha_set_public_section (abfd, sym) | 
|---|
| 787 | bfd *abfd; | 
|---|
| 788 | nlmNAME(symbol_type) *sym; | 
|---|
| 789 | { | 
|---|
| 790 | asection *code_sec, *data_sec; | 
|---|
| 791 |  | 
|---|
| 792 | code_sec = bfd_get_section_by_name (abfd, NLM_CODE_NAME); | 
|---|
| 793 | data_sec = bfd_get_section_by_name (abfd, NLM_INITIALIZED_DATA_NAME); | 
|---|
| 794 | if (sym->symbol.value < bfd_section_size (abfd, code_sec)) | 
|---|
| 795 | { | 
|---|
| 796 | sym->symbol.section = code_sec; | 
|---|
| 797 | sym->symbol.flags |= BSF_FUNCTION; | 
|---|
| 798 | } | 
|---|
| 799 | else | 
|---|
| 800 | { | 
|---|
| 801 | sym->symbol.section = data_sec; | 
|---|
| 802 | sym->symbol.value -= bfd_section_size (abfd, code_sec); | 
|---|
| 803 | /* The data segment had better be aligned.  */ | 
|---|
| 804 | BFD_ASSERT ((bfd_section_size (abfd, code_sec) & 0xf) == 0); | 
|---|
| 805 | } | 
|---|
| 806 | return true; | 
|---|
| 807 | } | 
|---|
| 808 |  | 
|---|
| 809 | /* Get the offset to write out for a public symbol.  */ | 
|---|
| 810 |  | 
|---|
| 811 | static bfd_vma | 
|---|
| 812 | nlm_alpha_get_public_offset (abfd, sym) | 
|---|
| 813 | bfd *abfd ATTRIBUTE_UNUSED; | 
|---|
| 814 | asymbol *sym; | 
|---|
| 815 | { | 
|---|
| 816 | return bfd_asymbol_value (sym); | 
|---|
| 817 | } | 
|---|
| 818 |  | 
|---|
| 819 |  | 
|---|
| 820 | /* Write an Alpha NLM external symbol.  */ | 
|---|
| 821 |  | 
|---|
| 822 | static boolean | 
|---|
| 823 | nlm_alpha_write_external (abfd, count, sym, relocs) | 
|---|
| 824 | bfd *abfd; | 
|---|
| 825 | bfd_size_type count; | 
|---|
| 826 | asymbol *sym; | 
|---|
| 827 | struct reloc_and_sec *relocs; | 
|---|
| 828 | { | 
|---|
| 829 | int i; | 
|---|
| 830 | bfd_byte len; | 
|---|
| 831 | unsigned char temp[NLM_TARGET_LONG_SIZE]; | 
|---|
| 832 | arelent r; | 
|---|
| 833 |  | 
|---|
| 834 | len = strlen (sym->name); | 
|---|
| 835 | if ((bfd_write (&len, sizeof (bfd_byte), 1, abfd) != sizeof (bfd_byte)) | 
|---|
| 836 | || bfd_write (sym->name, len, 1, abfd) != len) | 
|---|
| 837 | return false; | 
|---|
| 838 |  | 
|---|
| 839 | bfd_put_32 (abfd, count + 2, temp); | 
|---|
| 840 | if (bfd_write (temp, sizeof (temp), 1, abfd) != sizeof (temp)) | 
|---|
| 841 | return false; | 
|---|
| 842 |  | 
|---|
| 843 | /* The first two relocs for each external symbol are the .lita | 
|---|
| 844 | address and the GP value.  */ | 
|---|
| 845 | r.sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; | 
|---|
| 846 | r.howto = &nlm32_alpha_nw_howto; | 
|---|
| 847 |  | 
|---|
| 848 | r.address = nlm_alpha_backend_data (abfd)->lita_address; | 
|---|
| 849 | r.addend = nlm_alpha_backend_data (abfd)->lita_size + 1; | 
|---|
| 850 | if (nlm_alpha_write_import (abfd, (asection *) NULL, &r) == false) | 
|---|
| 851 | return false; | 
|---|
| 852 |  | 
|---|
| 853 | r.address = nlm_alpha_backend_data (abfd)->gp; | 
|---|
| 854 | r.addend = 0; | 
|---|
| 855 | if (nlm_alpha_write_import (abfd, (asection *) NULL, &r) == false) | 
|---|
| 856 | return false; | 
|---|
| 857 |  | 
|---|
| 858 | for (i = 0; i < count; i++) | 
|---|
| 859 | { | 
|---|
| 860 | if (nlm_alpha_write_import (abfd, relocs[i].sec, | 
|---|
| 861 | relocs[i].rel) == false) | 
|---|
| 862 | return false; | 
|---|
| 863 | } | 
|---|
| 864 |  | 
|---|
| 865 | return true; | 
|---|
| 866 | } | 
|---|
| 867 |  | 
|---|
| 868 | #include "nlmswap.h" | 
|---|
| 869 |  | 
|---|
| 870 | static const struct nlm_backend_data nlm32_alpha_backend = | 
|---|
| 871 | { | 
|---|
| 872 | "NetWare Alpha Module   \032", | 
|---|
| 873 | sizeof (Nlm32_alpha_External_Fixed_Header), | 
|---|
| 874 | sizeof (struct nlm32_alpha_external_prefix_header), | 
|---|
| 875 | bfd_arch_alpha, | 
|---|
| 876 | 0, | 
|---|
| 877 | true, /* no uninitialized data permitted by Alpha NetWare.  */ | 
|---|
| 878 | nlm_alpha_backend_object_p, | 
|---|
| 879 | nlm_alpha_write_prefix, | 
|---|
| 880 | nlm_alpha_read_reloc, | 
|---|
| 881 | nlm_alpha_mangle_relocs, | 
|---|
| 882 | nlm_alpha_read_import, | 
|---|
| 883 | nlm_alpha_write_import, | 
|---|
| 884 | nlm_alpha_set_public_section, | 
|---|
| 885 | nlm_alpha_get_public_offset, | 
|---|
| 886 | nlm_swap_fixed_header_in, | 
|---|
| 887 | nlm_swap_fixed_header_out, | 
|---|
| 888 | nlm_alpha_write_external, | 
|---|
| 889 | 0,    /* write_export */ | 
|---|
| 890 | }; | 
|---|
| 891 |  | 
|---|
| 892 | #define TARGET_LITTLE_NAME              "nlm32-alpha" | 
|---|
| 893 | #define TARGET_LITTLE_SYM               nlmNAME(alpha_vec) | 
|---|
| 894 | #define TARGET_BACKEND_DATA             &nlm32_alpha_backend | 
|---|
| 895 |  | 
|---|
| 896 | #include "nlm-target.h" | 
|---|