1 1.1 christos /* Generic COFF swapping routines, for BFD. 2 1.10 christos Copyright (C) 1990-2025 Free Software Foundation, Inc. 3 1.1 christos Written by Cygnus Support. 4 1.1 christos 5 1.1 christos This file is part of BFD, the Binary File Descriptor library. 6 1.1 christos 7 1.1 christos This program is free software; you can redistribute it and/or modify 8 1.1 christos it under the terms of the GNU General Public License as published by 9 1.1 christos the Free Software Foundation; either version 3 of the License, or 10 1.1 christos (at your option) any later version. 11 1.1 christos 12 1.1 christos This program is distributed in the hope that it will be useful, 13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 1.1 christos GNU General Public License for more details. 16 1.1 christos 17 1.1 christos You should have received a copy of the GNU General Public License 18 1.1 christos along with this program; if not, write to the Free Software 19 1.1 christos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 20 1.1 christos MA 02110-1301, USA. */ 21 1.1 christos 22 1.1 christos /* This file contains routines used to swap COFF data. It is a header 23 1.1 christos file because the details of swapping depend on the details of the 24 1.1 christos structures used by each COFF implementation. This is included by 25 1.1 christos coffcode.h, as well as by the ECOFF backend. 26 1.1 christos 27 1.1 christos Any file which uses this must first include "coff/internal.h" and 28 1.1 christos "coff/CPU.h". The functions will then be correct for that CPU. */ 29 1.1 christos 30 1.1 christos #ifndef GET_FCN_LNNOPTR 31 1.1 christos #define GET_FCN_LNNOPTR(abfd, ext) \ 32 1.1 christos H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr) 33 1.1 christos #endif 34 1.1 christos 35 1.1 christos #ifndef GET_FCN_ENDNDX 36 1.1 christos #define GET_FCN_ENDNDX(abfd, ext) \ 37 1.1 christos H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx) 38 1.1 christos #endif 39 1.1 christos 40 1.1 christos #ifndef PUT_FCN_LNNOPTR 41 1.1 christos #define PUT_FCN_LNNOPTR(abfd, in, ext) \ 42 1.1 christos H_PUT_32 (abfd, in, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr) 43 1.1 christos #endif 44 1.1 christos #ifndef PUT_FCN_ENDNDX 45 1.1 christos #define PUT_FCN_ENDNDX(abfd, in, ext) \ 46 1.1 christos H_PUT_32 (abfd, in, ext->x_sym.x_fcnary.x_fcn.x_endndx) 47 1.1 christos #endif 48 1.1 christos #ifndef GET_LNSZ_LNNO 49 1.1 christos #define GET_LNSZ_LNNO(abfd, ext) \ 50 1.1 christos H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno) 51 1.1 christos #endif 52 1.1 christos #ifndef GET_LNSZ_SIZE 53 1.1 christos #define GET_LNSZ_SIZE(abfd, ext) \ 54 1.1 christos H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size) 55 1.1 christos #endif 56 1.1 christos #ifndef PUT_LNSZ_LNNO 57 1.1 christos #define PUT_LNSZ_LNNO(abfd, in, ext) \ 58 1.1 christos H_PUT_16 (abfd, in, ext->x_sym.x_misc.x_lnsz.x_lnno) 59 1.1 christos #endif 60 1.1 christos #ifndef PUT_LNSZ_SIZE 61 1.1 christos #define PUT_LNSZ_SIZE(abfd, in, ext) \ 62 1.1 christos H_PUT_16 (abfd, in, ext->x_sym.x_misc.x_lnsz.x_size) 63 1.1 christos #endif 64 1.1 christos #ifndef GET_SCN_SCNLEN 65 1.1 christos #define GET_SCN_SCNLEN(abfd, ext) \ 66 1.1 christos H_GET_32 (abfd, ext->x_scn.x_scnlen) 67 1.1 christos #endif 68 1.1 christos #ifndef GET_SCN_NRELOC 69 1.1 christos #define GET_SCN_NRELOC(abfd, ext) \ 70 1.1 christos H_GET_16 (abfd, ext->x_scn.x_nreloc) 71 1.1 christos #endif 72 1.1 christos #ifndef GET_SCN_NLINNO 73 1.1 christos #define GET_SCN_NLINNO(abfd, ext) \ 74 1.1 christos H_GET_16 (abfd, ext->x_scn.x_nlinno) 75 1.1 christos #endif 76 1.1 christos #ifndef PUT_SCN_SCNLEN 77 1.1 christos #define PUT_SCN_SCNLEN(abfd, in, ext) \ 78 1.1 christos H_PUT_32 (abfd, in, ext->x_scn.x_scnlen) 79 1.1 christos #endif 80 1.1 christos #ifndef PUT_SCN_NRELOC 81 1.1 christos #define PUT_SCN_NRELOC(abfd, in, ext) \ 82 1.1 christos H_PUT_16 (abfd, in, ext->x_scn.x_nreloc) 83 1.1 christos #endif 84 1.1 christos #ifndef PUT_SCN_NLINNO 85 1.1 christos #define PUT_SCN_NLINNO(abfd, in, ext) \ 86 1.1 christos H_PUT_16 (abfd, in, ext->x_scn.x_nlinno) 87 1.1 christos #endif 88 1.1 christos #ifndef GET_LINENO_LNNO 89 1.1 christos #define GET_LINENO_LNNO(abfd, ext) \ 90 1.1 christos H_GET_16 (abfd, ext->l_lnno); 91 1.1 christos #endif 92 1.1 christos #ifndef PUT_LINENO_LNNO 93 1.1 christos #define PUT_LINENO_LNNO(abfd, val, ext) \ 94 1.1 christos H_PUT_16 (abfd, val, ext->l_lnno); 95 1.1 christos #endif 96 1.1 christos 97 1.1 christos /* The f_symptr field in the filehdr is sometimes 64 bits. */ 98 1.1 christos #ifndef GET_FILEHDR_SYMPTR 99 1.1 christos #define GET_FILEHDR_SYMPTR H_GET_32 100 1.1 christos #endif 101 1.1 christos #ifndef PUT_FILEHDR_SYMPTR 102 1.1 christos #define PUT_FILEHDR_SYMPTR H_PUT_32 103 1.1 christos #endif 104 1.1 christos 105 1.1 christos /* Some fields in the aouthdr are sometimes 64 bits. */ 106 1.1 christos #ifndef GET_AOUTHDR_TSIZE 107 1.1 christos #define GET_AOUTHDR_TSIZE H_GET_32 108 1.1 christos #endif 109 1.1 christos #ifndef PUT_AOUTHDR_TSIZE 110 1.1 christos #define PUT_AOUTHDR_TSIZE H_PUT_32 111 1.1 christos #endif 112 1.1 christos #ifndef GET_AOUTHDR_DSIZE 113 1.1 christos #define GET_AOUTHDR_DSIZE H_GET_32 114 1.1 christos #endif 115 1.1 christos #ifndef PUT_AOUTHDR_DSIZE 116 1.1 christos #define PUT_AOUTHDR_DSIZE H_PUT_32 117 1.1 christos #endif 118 1.1 christos #ifndef GET_AOUTHDR_BSIZE 119 1.1 christos #define GET_AOUTHDR_BSIZE H_GET_32 120 1.1 christos #endif 121 1.1 christos #ifndef PUT_AOUTHDR_BSIZE 122 1.1 christos #define PUT_AOUTHDR_BSIZE H_PUT_32 123 1.1 christos #endif 124 1.1 christos #ifndef GET_AOUTHDR_ENTRY 125 1.1 christos #define GET_AOUTHDR_ENTRY H_GET_32 126 1.1 christos #endif 127 1.1 christos #ifndef PUT_AOUTHDR_ENTRY 128 1.1 christos #define PUT_AOUTHDR_ENTRY H_PUT_32 129 1.1 christos #endif 130 1.1 christos #ifndef GET_AOUTHDR_TEXT_START 131 1.1 christos #define GET_AOUTHDR_TEXT_START H_GET_32 132 1.1 christos #endif 133 1.1 christos #ifndef PUT_AOUTHDR_TEXT_START 134 1.1 christos #define PUT_AOUTHDR_TEXT_START H_PUT_32 135 1.1 christos #endif 136 1.1 christos #ifndef GET_AOUTHDR_DATA_START 137 1.1 christos #define GET_AOUTHDR_DATA_START H_GET_32 138 1.1 christos #endif 139 1.1 christos #ifndef PUT_AOUTHDR_DATA_START 140 1.1 christos #define PUT_AOUTHDR_DATA_START H_PUT_32 141 1.1 christos #endif 142 1.1 christos 143 1.1 christos /* Some fields in the scnhdr are sometimes 64 bits. */ 144 1.1 christos #ifndef GET_SCNHDR_PADDR 145 1.1 christos #define GET_SCNHDR_PADDR H_GET_32 146 1.1 christos #endif 147 1.1 christos #ifndef PUT_SCNHDR_PADDR 148 1.1 christos #define PUT_SCNHDR_PADDR H_PUT_32 149 1.1 christos #endif 150 1.1 christos #ifndef GET_SCNHDR_VADDR 151 1.1 christos #define GET_SCNHDR_VADDR H_GET_32 152 1.1 christos #endif 153 1.1 christos #ifndef PUT_SCNHDR_VADDR 154 1.1 christos #define PUT_SCNHDR_VADDR H_PUT_32 155 1.1 christos #endif 156 1.1 christos #ifndef GET_SCNHDR_SIZE 157 1.1 christos #define GET_SCNHDR_SIZE H_GET_32 158 1.1 christos #endif 159 1.1 christos #ifndef PUT_SCNHDR_SIZE 160 1.1 christos #define PUT_SCNHDR_SIZE H_PUT_32 161 1.1 christos #endif 162 1.1 christos #ifndef GET_SCNHDR_SCNPTR 163 1.1 christos #define GET_SCNHDR_SCNPTR H_GET_32 164 1.1 christos #endif 165 1.1 christos #ifndef PUT_SCNHDR_SCNPTR 166 1.1 christos #define PUT_SCNHDR_SCNPTR H_PUT_32 167 1.1 christos #endif 168 1.1 christos #ifndef GET_SCNHDR_RELPTR 169 1.1 christos #define GET_SCNHDR_RELPTR H_GET_32 170 1.1 christos #endif 171 1.1 christos #ifndef PUT_SCNHDR_RELPTR 172 1.1 christos #define PUT_SCNHDR_RELPTR H_PUT_32 173 1.1 christos #endif 174 1.1 christos #ifndef GET_SCNHDR_LNNOPTR 175 1.1 christos #define GET_SCNHDR_LNNOPTR H_GET_32 176 1.1 christos #endif 177 1.1 christos #ifndef PUT_SCNHDR_LNNOPTR 178 1.1 christos #define PUT_SCNHDR_LNNOPTR H_PUT_32 179 1.1 christos #endif 180 1.1 christos #ifndef GET_SCNHDR_NRELOC 181 1.1 christos #define GET_SCNHDR_NRELOC H_GET_16 182 1.1 christos #endif 183 1.1 christos #ifndef MAX_SCNHDR_NRELOC 184 1.1 christos #define MAX_SCNHDR_NRELOC 0xffff 185 1.1 christos #endif 186 1.1 christos #ifndef PUT_SCNHDR_NRELOC 187 1.1 christos #define PUT_SCNHDR_NRELOC H_PUT_16 188 1.1 christos #endif 189 1.1 christos #ifndef GET_SCNHDR_NLNNO 190 1.1 christos #define GET_SCNHDR_NLNNO H_GET_16 191 1.1 christos #endif 192 1.1 christos #ifndef MAX_SCNHDR_NLNNO 193 1.1 christos #define MAX_SCNHDR_NLNNO 0xffff 194 1.1 christos #endif 195 1.1 christos #ifndef PUT_SCNHDR_NLNNO 196 1.1 christos #define PUT_SCNHDR_NLNNO H_PUT_16 197 1.1 christos #endif 198 1.1 christos #ifndef GET_SCNHDR_FLAGS 199 1.1 christos #define GET_SCNHDR_FLAGS H_GET_32 200 1.1 christos #endif 201 1.1 christos #ifndef PUT_SCNHDR_FLAGS 202 1.1 christos #define PUT_SCNHDR_FLAGS H_PUT_32 203 1.1 christos #endif 204 1.1 christos 205 1.1 christos #ifndef GET_RELOC_VADDR 206 1.1 christos #define GET_RELOC_VADDR H_GET_32 207 1.1 christos #endif 208 1.1 christos #ifndef PUT_RELOC_VADDR 209 1.1 christos #define PUT_RELOC_VADDR H_PUT_32 210 1.1 christos #endif 211 1.1 christos 212 1.1 christos #ifndef NO_COFF_RELOCS 213 1.1 christos 214 1.1 christos static void 215 1.1 christos coff_swap_reloc_in (bfd * abfd, void * src, void * dst) 216 1.1 christos { 217 1.1 christos RELOC *reloc_src = (RELOC *) src; 218 1.1 christos struct internal_reloc *reloc_dst = (struct internal_reloc *) dst; 219 1.1 christos 220 1.1 christos reloc_dst->r_vaddr = GET_RELOC_VADDR (abfd, reloc_src->r_vaddr); 221 1.1 christos reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx); 222 1.1 christos reloc_dst->r_type = H_GET_16 (abfd, reloc_src->r_type); 223 1.1 christos 224 1.1 christos #ifdef SWAP_IN_RELOC_OFFSET 225 1.1 christos reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset); 226 1.1 christos #endif 227 1.1 christos } 228 1.1 christos 229 1.1 christos static unsigned int 230 1.1 christos coff_swap_reloc_out (bfd * abfd, void * src, void * dst) 231 1.1 christos { 232 1.1 christos struct internal_reloc *reloc_src = (struct internal_reloc *) src; 233 1.1 christos struct external_reloc *reloc_dst = (struct external_reloc *) dst; 234 1.1 christos 235 1.1 christos PUT_RELOC_VADDR (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr); 236 1.1 christos H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx); 237 1.1 christos H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type); 238 1.1 christos 239 1.1 christos #ifdef SWAP_OUT_RELOC_OFFSET 240 1.1 christos SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset); 241 1.1 christos #endif 242 1.1 christos #ifdef SWAP_OUT_RELOC_EXTRA 243 1.1 christos SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst); 244 1.1 christos #endif 245 1.1 christos 246 1.1 christos return bfd_coff_relsz (abfd); 247 1.1 christos } 248 1.1 christos 249 1.8 christos #ifdef TICOFF 250 1.8 christos static void 251 1.8 christos coff_swap_reloc_v0_in (bfd *abfd, void *src, void *dst) 252 1.8 christos { 253 1.8 christos struct external_reloc_v0 *reloc_src = (struct external_reloc_v0 *) src; 254 1.8 christos struct internal_reloc *reloc_dst = (struct internal_reloc *) dst; 255 1.8 christos 256 1.8 christos reloc_dst->r_vaddr = GET_RELOC_VADDR (abfd, reloc_src->r_vaddr); 257 1.8 christos reloc_dst->r_symndx = H_GET_16 (abfd, reloc_src->r_symndx); 258 1.8 christos reloc_dst->r_type = H_GET_16 (abfd, reloc_src->r_type); 259 1.8 christos } 260 1.8 christos 261 1.8 christos static unsigned int 262 1.8 christos coff_swap_reloc_v0_out (bfd *abfd, void *src, void *dst) 263 1.8 christos { 264 1.8 christos struct internal_reloc *reloc_src = (struct internal_reloc *) src; 265 1.8 christos struct external_reloc_v0 *reloc_dst = (struct external_reloc_v0 *) dst; 266 1.8 christos 267 1.8 christos PUT_RELOC_VADDR (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr); 268 1.8 christos H_PUT_16 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx); 269 1.8 christos H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type); 270 1.8 christos SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst); 271 1.8 christos 272 1.8 christos return bfd_coff_relsz (abfd); 273 1.8 christos } 274 1.8 christos #endif 275 1.8 christos 276 1.1 christos #endif /* NO_COFF_RELOCS */ 277 1.1 christos 278 1.1 christos static void 279 1.1 christos coff_swap_filehdr_in (bfd * abfd, void * src, void * dst) 280 1.1 christos { 281 1.1 christos FILHDR *filehdr_src = (FILHDR *) src; 282 1.1 christos struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst; 283 1.1 christos 284 1.1 christos #ifdef COFF_ADJUST_FILEHDR_IN_PRE 285 1.1 christos COFF_ADJUST_FILEHDR_IN_PRE (abfd, src, dst); 286 1.1 christos #endif 287 1.1 christos filehdr_dst->f_magic = H_GET_16 (abfd, filehdr_src->f_magic); 288 1.1 christos filehdr_dst->f_nscns = H_GET_16 (abfd, filehdr_src->f_nscns); 289 1.1 christos filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat); 290 1.1 christos filehdr_dst->f_symptr = GET_FILEHDR_SYMPTR (abfd, filehdr_src->f_symptr); 291 1.1 christos filehdr_dst->f_nsyms = H_GET_32 (abfd, filehdr_src->f_nsyms); 292 1.1 christos filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src->f_opthdr); 293 1.1 christos filehdr_dst->f_flags = H_GET_16 (abfd, filehdr_src->f_flags); 294 1.1 christos 295 1.1 christos #ifdef COFF_ADJUST_FILEHDR_IN_POST 296 1.1 christos COFF_ADJUST_FILEHDR_IN_POST (abfd, src, dst); 297 1.1 christos #endif 298 1.1 christos } 299 1.1 christos 300 1.1 christos static unsigned int 301 1.1 christos coff_swap_filehdr_out (bfd *abfd, void * in, void * out) 302 1.1 christos { 303 1.1 christos struct internal_filehdr *filehdr_in = (struct internal_filehdr *) in; 304 1.1 christos FILHDR *filehdr_out = (FILHDR *) out; 305 1.1 christos 306 1.1 christos #ifdef COFF_ADJUST_FILEHDR_OUT_PRE 307 1.1 christos COFF_ADJUST_FILEHDR_OUT_PRE (abfd, in, out); 308 1.1 christos #endif 309 1.1 christos H_PUT_16 (abfd, filehdr_in->f_magic, filehdr_out->f_magic); 310 1.1 christos H_PUT_16 (abfd, filehdr_in->f_nscns, filehdr_out->f_nscns); 311 1.1 christos H_PUT_32 (abfd, filehdr_in->f_timdat, filehdr_out->f_timdat); 312 1.1 christos PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr, filehdr_out->f_symptr); 313 1.1 christos H_PUT_32 (abfd, filehdr_in->f_nsyms, filehdr_out->f_nsyms); 314 1.1 christos H_PUT_16 (abfd, filehdr_in->f_opthdr, filehdr_out->f_opthdr); 315 1.1 christos H_PUT_16 (abfd, filehdr_in->f_flags, filehdr_out->f_flags); 316 1.1 christos 317 1.1 christos #ifdef COFF_ADJUST_FILEHDR_OUT_POST 318 1.1 christos COFF_ADJUST_FILEHDR_OUT_POST (abfd, in, out); 319 1.1 christos #endif 320 1.1 christos return bfd_coff_filhsz (abfd); 321 1.1 christos } 322 1.1 christos 323 1.1 christos #ifndef NO_COFF_SYMBOLS 324 1.1 christos 325 1.1 christos static void 326 1.1 christos coff_swap_sym_in (bfd * abfd, void * ext1, void * in1) 327 1.1 christos { 328 1.1 christos SYMENT *ext = (SYMENT *) ext1; 329 1.1 christos struct internal_syment *in = (struct internal_syment *) in1; 330 1.1 christos 331 1.1 christos if (ext->e.e_name[0] == 0) 332 1.1 christos { 333 1.1 christos in->_n._n_n._n_zeroes = 0; 334 1.1 christos in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset); 335 1.1 christos } 336 1.1 christos else 337 1.1 christos { 338 1.1 christos #if SYMNMLEN != E_SYMNMLEN 339 1.1 christos #error we need to cope with truncating or extending SYMNMLEN 340 1.1 christos #else 341 1.1 christos memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN); 342 1.1 christos #endif 343 1.1 christos } 344 1.1 christos 345 1.1 christos in->n_value = H_GET_32 (abfd, ext->e_value); 346 1.5 christos in->n_scnum = (short) H_GET_16 (abfd, ext->e_scnum); 347 1.1 christos if (sizeof (ext->e_type) == 2) 348 1.1 christos in->n_type = H_GET_16 (abfd, ext->e_type); 349 1.1 christos else 350 1.1 christos in->n_type = H_GET_32 (abfd, ext->e_type); 351 1.1 christos in->n_sclass = H_GET_8 (abfd, ext->e_sclass); 352 1.1 christos in->n_numaux = H_GET_8 (abfd, ext->e_numaux); 353 1.1 christos #ifdef COFF_ADJUST_SYM_IN_POST 354 1.1 christos COFF_ADJUST_SYM_IN_POST (abfd, ext1, in1); 355 1.1 christos #endif 356 1.1 christos } 357 1.1 christos 358 1.1 christos static unsigned int 359 1.1 christos coff_swap_sym_out (bfd * abfd, void * inp, void * extp) 360 1.1 christos { 361 1.1 christos struct internal_syment *in = (struct internal_syment *) inp; 362 1.1 christos SYMENT *ext =(SYMENT *) extp; 363 1.1 christos 364 1.1 christos #ifdef COFF_ADJUST_SYM_OUT_PRE 365 1.1 christos COFF_ADJUST_SYM_OUT_PRE (abfd, inp, extp); 366 1.1 christos #endif 367 1.1 christos 368 1.1 christos if (in->_n._n_name[0] == 0) 369 1.1 christos { 370 1.1 christos H_PUT_32 (abfd, 0, ext->e.e.e_zeroes); 371 1.1 christos H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset); 372 1.1 christos } 373 1.1 christos else 374 1.1 christos { 375 1.1 christos #if SYMNMLEN != E_SYMNMLEN 376 1.1 christos #error we need to cope with truncating or extending SYMNMLEN 377 1.1 christos #else 378 1.1 christos memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN); 379 1.1 christos #endif 380 1.1 christos } 381 1.1 christos 382 1.1 christos H_PUT_32 (abfd, in->n_value, ext->e_value); 383 1.1 christos H_PUT_16 (abfd, in->n_scnum, ext->e_scnum); 384 1.1 christos 385 1.1 christos if (sizeof (ext->e_type) == 2) 386 1.1 christos H_PUT_16 (abfd, in->n_type, ext->e_type); 387 1.1 christos else 388 1.1 christos H_PUT_32 (abfd, in->n_type, ext->e_type); 389 1.1 christos 390 1.1 christos H_PUT_8 (abfd, in->n_sclass, ext->e_sclass); 391 1.1 christos H_PUT_8 (abfd, in->n_numaux, ext->e_numaux); 392 1.1 christos 393 1.1 christos #ifdef COFF_ADJUST_SYM_OUT_POST 394 1.1 christos COFF_ADJUST_SYM_OUT_POST (abfd, inp, extp); 395 1.1 christos #endif 396 1.1 christos 397 1.1 christos return SYMESZ; 398 1.1 christos } 399 1.1 christos 400 1.1 christos static void 401 1.1 christos coff_swap_aux_in (bfd *abfd, 402 1.1 christos void * ext1, 403 1.1 christos int type, 404 1.1 christos int in_class, 405 1.9 christos int indx ATTRIBUTE_UNUSED, 406 1.9 christos int numaux ATTRIBUTE_UNUSED, 407 1.1 christos void * in1) 408 1.1 christos { 409 1.1 christos AUXENT *ext = (AUXENT *) ext1; 410 1.1 christos union internal_auxent *in = (union internal_auxent *) in1; 411 1.1 christos 412 1.1 christos #ifdef COFF_ADJUST_AUX_IN_PRE 413 1.1 christos COFF_ADJUST_AUX_IN_PRE (abfd, ext1, type, in_class, indx, numaux, in1); 414 1.1 christos #endif 415 1.1 christos 416 1.1 christos switch (in_class) 417 1.1 christos { 418 1.1 christos case C_FILE: 419 1.1 christos if (ext->x_file.x_fname[0] == 0) 420 1.1 christos { 421 1.8 christos in->x_file.x_n.x_n.x_zeroes = 0; 422 1.8 christos in->x_file.x_n.x_n.x_offset = H_GET_32 (abfd, ext->x_file.x_n.x_offset); 423 1.1 christos } 424 1.1 christos else 425 1.1 christos { 426 1.1 christos #if FILNMLEN != E_FILNMLEN 427 1.1 christos #error we need to cope with truncating or extending FILNMLEN 428 1.1 christos #else 429 1.9 christos memcpy (in->x_file.x_n.x_fname, ext->x_file.x_fname, FILNMLEN); 430 1.1 christos #endif 431 1.1 christos } 432 1.1 christos goto end; 433 1.1 christos 434 1.1 christos case C_STAT: 435 1.1 christos #ifdef C_LEAFSTAT 436 1.1 christos case C_LEAFSTAT: 437 1.1 christos #endif 438 1.1 christos case C_HIDDEN: 439 1.1 christos if (type == T_NULL) 440 1.1 christos { 441 1.1 christos in->x_scn.x_scnlen = GET_SCN_SCNLEN (abfd, ext); 442 1.1 christos in->x_scn.x_nreloc = GET_SCN_NRELOC (abfd, ext); 443 1.1 christos in->x_scn.x_nlinno = GET_SCN_NLINNO (abfd, ext); 444 1.1 christos 445 1.1 christos /* PE defines some extra fields; we zero them out for 446 1.6 christos safety. */ 447 1.1 christos in->x_scn.x_checksum = 0; 448 1.1 christos in->x_scn.x_associated = 0; 449 1.1 christos in->x_scn.x_comdat = 0; 450 1.1 christos 451 1.1 christos goto end; 452 1.1 christos } 453 1.1 christos break; 454 1.1 christos } 455 1.1 christos 456 1.9 christos in->x_sym.x_tagndx.u32 = H_GET_32 (abfd, ext->x_sym.x_tagndx); 457 1.1 christos #ifndef NO_TVNDX 458 1.1 christos in->x_sym.x_tvndx = H_GET_16 (abfd, ext->x_sym.x_tvndx); 459 1.1 christos #endif 460 1.1 christos 461 1.1 christos if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type) 462 1.1 christos || ISTAG (in_class)) 463 1.1 christos { 464 1.1 christos in->x_sym.x_fcnary.x_fcn.x_lnnoptr = GET_FCN_LNNOPTR (abfd, ext); 465 1.9 christos in->x_sym.x_fcnary.x_fcn.x_endndx.u32 = GET_FCN_ENDNDX (abfd, ext); 466 1.1 christos } 467 1.1 christos else 468 1.1 christos { 469 1.1 christos #if DIMNUM != E_DIMNUM 470 1.1 christos #error we need to cope with truncating or extending DIMNUM 471 1.1 christos #endif 472 1.1 christos in->x_sym.x_fcnary.x_ary.x_dimen[0] = 473 1.1 christos H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[0]); 474 1.1 christos in->x_sym.x_fcnary.x_ary.x_dimen[1] = 475 1.1 christos H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[1]); 476 1.1 christos in->x_sym.x_fcnary.x_ary.x_dimen[2] = 477 1.1 christos H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[2]); 478 1.1 christos in->x_sym.x_fcnary.x_ary.x_dimen[3] = 479 1.1 christos H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]); 480 1.1 christos } 481 1.1 christos 482 1.1 christos if (ISFCN (type)) 483 1.1 christos in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize); 484 1.1 christos else 485 1.1 christos { 486 1.1 christos in->x_sym.x_misc.x_lnsz.x_lnno = GET_LNSZ_LNNO (abfd, ext); 487 1.1 christos in->x_sym.x_misc.x_lnsz.x_size = GET_LNSZ_SIZE (abfd, ext); 488 1.1 christos } 489 1.1 christos 490 1.1 christos end: ; 491 1.1 christos 492 1.1 christos #ifdef COFF_ADJUST_AUX_IN_POST 493 1.1 christos COFF_ADJUST_AUX_IN_POST (abfd, ext1, type, in_class, indx, numaux, in1); 494 1.1 christos #endif 495 1.1 christos } 496 1.1 christos 497 1.1 christos static unsigned int 498 1.1 christos coff_swap_aux_out (bfd * abfd, 499 1.1 christos void * inp, 500 1.1 christos int type, 501 1.1 christos int in_class, 502 1.1 christos int indx ATTRIBUTE_UNUSED, 503 1.1 christos int numaux ATTRIBUTE_UNUSED, 504 1.1 christos void * extp) 505 1.1 christos { 506 1.1 christos union internal_auxent * in = (union internal_auxent *) inp; 507 1.1 christos AUXENT *ext = (AUXENT *) extp; 508 1.1 christos 509 1.1 christos #ifdef COFF_ADJUST_AUX_OUT_PRE 510 1.1 christos COFF_ADJUST_AUX_OUT_PRE (abfd, inp, type, in_class, indx, numaux, extp); 511 1.1 christos #endif 512 1.1 christos 513 1.1 christos memset (ext, 0, AUXESZ); 514 1.1 christos 515 1.1 christos switch (in_class) 516 1.1 christos { 517 1.1 christos case C_FILE: 518 1.8 christos if (in->x_file.x_n.x_fname[0] == 0) 519 1.1 christos { 520 1.1 christos H_PUT_32 (abfd, 0, ext->x_file.x_n.x_zeroes); 521 1.8 christos H_PUT_32 (abfd, in->x_file.x_n.x_n.x_offset, ext->x_file.x_n.x_offset); 522 1.1 christos } 523 1.1 christos else 524 1.1 christos { 525 1.1 christos #if FILNMLEN != E_FILNMLEN 526 1.1 christos #error we need to cope with truncating or extending FILNMLEN 527 1.1 christos #else 528 1.8 christos memcpy (ext->x_file.x_fname, in->x_file.x_n.x_fname, FILNMLEN); 529 1.1 christos #endif 530 1.1 christos } 531 1.1 christos goto end; 532 1.1 christos 533 1.1 christos case C_STAT: 534 1.1 christos #ifdef C_LEAFSTAT 535 1.1 christos case C_LEAFSTAT: 536 1.1 christos #endif 537 1.1 christos case C_HIDDEN: 538 1.1 christos if (type == T_NULL) 539 1.1 christos { 540 1.1 christos PUT_SCN_SCNLEN (abfd, in->x_scn.x_scnlen, ext); 541 1.1 christos PUT_SCN_NRELOC (abfd, in->x_scn.x_nreloc, ext); 542 1.1 christos PUT_SCN_NLINNO (abfd, in->x_scn.x_nlinno, ext); 543 1.1 christos goto end; 544 1.1 christos } 545 1.1 christos break; 546 1.1 christos } 547 1.1 christos 548 1.9 christos H_PUT_32 (abfd, in->x_sym.x_tagndx.u32, ext->x_sym.x_tagndx); 549 1.1 christos #ifndef NO_TVNDX 550 1.1 christos H_PUT_16 (abfd, in->x_sym.x_tvndx, ext->x_sym.x_tvndx); 551 1.1 christos #endif 552 1.1 christos 553 1.1 christos if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type) 554 1.1 christos || ISTAG (in_class)) 555 1.1 christos { 556 1.1 christos PUT_FCN_LNNOPTR (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr, ext); 557 1.9 christos PUT_FCN_ENDNDX (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.u32, ext); 558 1.1 christos } 559 1.1 christos else 560 1.1 christos { 561 1.1 christos #if DIMNUM != E_DIMNUM 562 1.1 christos #error we need to cope with truncating or extending DIMNUM 563 1.1 christos #endif 564 1.1 christos H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0], 565 1.1 christos ext->x_sym.x_fcnary.x_ary.x_dimen[0]); 566 1.1 christos H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1], 567 1.1 christos ext->x_sym.x_fcnary.x_ary.x_dimen[1]); 568 1.1 christos H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2], 569 1.1 christos ext->x_sym.x_fcnary.x_ary.x_dimen[2]); 570 1.1 christos H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3], 571 1.1 christos ext->x_sym.x_fcnary.x_ary.x_dimen[3]); 572 1.1 christos } 573 1.1 christos 574 1.1 christos if (ISFCN (type)) 575 1.1 christos H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_sym.x_misc.x_fsize); 576 1.1 christos else 577 1.1 christos { 578 1.1 christos PUT_LNSZ_LNNO (abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext); 579 1.1 christos PUT_LNSZ_SIZE (abfd, in->x_sym.x_misc.x_lnsz.x_size, ext); 580 1.1 christos } 581 1.1 christos 582 1.1 christos end: 583 1.1 christos #ifdef COFF_ADJUST_AUX_OUT_POST 584 1.1 christos COFF_ADJUST_AUX_OUT_POST (abfd, inp, type, in_class, indx, numaux, extp); 585 1.1 christos #endif 586 1.1 christos return AUXESZ; 587 1.1 christos } 588 1.1 christos 589 1.1 christos #endif /* NO_COFF_SYMBOLS */ 590 1.1 christos 591 1.1 christos #ifndef NO_COFF_LINENOS 592 1.1 christos 593 1.1 christos static void 594 1.1 christos coff_swap_lineno_in (bfd * abfd, void * ext1, void * in1) 595 1.1 christos { 596 1.1 christos LINENO *ext = (LINENO *) ext1; 597 1.1 christos struct internal_lineno *in = (struct internal_lineno *) in1; 598 1.1 christos 599 1.1 christos in->l_addr.l_symndx = H_GET_32 (abfd, ext->l_addr.l_symndx); 600 1.1 christos in->l_lnno = GET_LINENO_LNNO (abfd, ext); 601 1.1 christos } 602 1.1 christos 603 1.1 christos static unsigned int 604 1.1 christos coff_swap_lineno_out (bfd * abfd, void * inp, void * outp) 605 1.1 christos { 606 1.1 christos struct internal_lineno *in = (struct internal_lineno *) inp; 607 1.1 christos struct external_lineno *ext = (struct external_lineno *) outp; 608 1.1 christos H_PUT_32 (abfd, in->l_addr.l_symndx, ext->l_addr.l_symndx); 609 1.1 christos 610 1.1 christos PUT_LINENO_LNNO (abfd, in->l_lnno, ext); 611 1.1 christos return LINESZ; 612 1.1 christos } 613 1.1 christos 614 1.1 christos #endif /* NO_COFF_LINENOS */ 615 1.1 christos 616 1.1 christos static void 617 1.1 christos coff_swap_aouthdr_in (bfd * abfd, void * aouthdr_ext1, void * aouthdr_int1) 618 1.1 christos { 619 1.1 christos AOUTHDR *aouthdr_ext; 620 1.1 christos struct internal_aouthdr *aouthdr_int; 621 1.1 christos 622 1.1 christos aouthdr_ext = (AOUTHDR *) aouthdr_ext1; 623 1.1 christos aouthdr_int = (struct internal_aouthdr *) aouthdr_int1; 624 1.1 christos aouthdr_int->magic = H_GET_16 (abfd, aouthdr_ext->magic); 625 1.1 christos aouthdr_int->vstamp = H_GET_16 (abfd, aouthdr_ext->vstamp); 626 1.1 christos aouthdr_int->tsize = GET_AOUTHDR_TSIZE (abfd, aouthdr_ext->tsize); 627 1.1 christos aouthdr_int->dsize = GET_AOUTHDR_DSIZE (abfd, aouthdr_ext->dsize); 628 1.1 christos aouthdr_int->bsize = GET_AOUTHDR_BSIZE (abfd, aouthdr_ext->bsize); 629 1.1 christos aouthdr_int->entry = GET_AOUTHDR_ENTRY (abfd, aouthdr_ext->entry); 630 1.1 christos aouthdr_int->text_start = 631 1.1 christos GET_AOUTHDR_TEXT_START (abfd, aouthdr_ext->text_start); 632 1.1 christos aouthdr_int->data_start = 633 1.1 christos GET_AOUTHDR_DATA_START (abfd, aouthdr_ext->data_start); 634 1.1 christos 635 1.1 christos #ifdef RS6000COFF_C 636 1.1 christos #ifdef XCOFF64 637 1.1 christos aouthdr_int->o_toc = H_GET_64 (abfd, aouthdr_ext->o_toc); 638 1.1 christos #else 639 1.1 christos aouthdr_int->o_toc = H_GET_32 (abfd, aouthdr_ext->o_toc); 640 1.1 christos #endif 641 1.1 christos aouthdr_int->o_snentry = H_GET_16 (abfd, aouthdr_ext->o_snentry); 642 1.1 christos aouthdr_int->o_sntext = H_GET_16 (abfd, aouthdr_ext->o_sntext); 643 1.1 christos aouthdr_int->o_sndata = H_GET_16 (abfd, aouthdr_ext->o_sndata); 644 1.1 christos aouthdr_int->o_sntoc = H_GET_16 (abfd, aouthdr_ext->o_sntoc); 645 1.1 christos aouthdr_int->o_snloader = H_GET_16 (abfd, aouthdr_ext->o_snloader); 646 1.1 christos aouthdr_int->o_snbss = H_GET_16 (abfd, aouthdr_ext->o_snbss); 647 1.1 christos aouthdr_int->o_algntext = H_GET_16 (abfd, aouthdr_ext->o_algntext); 648 1.1 christos aouthdr_int->o_algndata = H_GET_16 (abfd, aouthdr_ext->o_algndata); 649 1.1 christos aouthdr_int->o_modtype = H_GET_16 (abfd, aouthdr_ext->o_modtype); 650 1.1 christos aouthdr_int->o_cputype = H_GET_16 (abfd, aouthdr_ext->o_cputype); 651 1.1 christos #ifdef XCOFF64 652 1.1 christos aouthdr_int->o_maxstack = H_GET_64 (abfd, aouthdr_ext->o_maxstack); 653 1.1 christos aouthdr_int->o_maxdata = H_GET_64 (abfd, aouthdr_ext->o_maxdata); 654 1.1 christos #else 655 1.1 christos aouthdr_int->o_maxstack = H_GET_32 (abfd, aouthdr_ext->o_maxstack); 656 1.1 christos aouthdr_int->o_maxdata = H_GET_32 (abfd, aouthdr_ext->o_maxdata); 657 1.1 christos #endif 658 1.1 christos #endif 659 1.1 christos 660 1.1 christos #ifdef MIPSECOFF 661 1.1 christos aouthdr_int->bss_start = H_GET_32 (abfd, aouthdr_ext->bss_start); 662 1.1 christos aouthdr_int->gp_value = H_GET_32 (abfd, aouthdr_ext->gp_value); 663 1.1 christos aouthdr_int->gprmask = H_GET_32 (abfd, aouthdr_ext->gprmask); 664 1.1 christos aouthdr_int->cprmask[0] = H_GET_32 (abfd, aouthdr_ext->cprmask[0]); 665 1.1 christos aouthdr_int->cprmask[1] = H_GET_32 (abfd, aouthdr_ext->cprmask[1]); 666 1.1 christos aouthdr_int->cprmask[2] = H_GET_32 (abfd, aouthdr_ext->cprmask[2]); 667 1.1 christos aouthdr_int->cprmask[3] = H_GET_32 (abfd, aouthdr_ext->cprmask[3]); 668 1.1 christos #endif 669 1.1 christos 670 1.1 christos #ifdef ALPHAECOFF 671 1.1 christos aouthdr_int->bss_start = H_GET_64 (abfd, aouthdr_ext->bss_start); 672 1.1 christos aouthdr_int->gp_value = H_GET_64 (abfd, aouthdr_ext->gp_value); 673 1.1 christos aouthdr_int->gprmask = H_GET_32 (abfd, aouthdr_ext->gprmask); 674 1.1 christos aouthdr_int->fprmask = H_GET_32 (abfd, aouthdr_ext->fprmask); 675 1.1 christos #endif 676 1.1 christos } 677 1.1 christos 678 1.1 christos static unsigned int 679 1.1 christos coff_swap_aouthdr_out (bfd * abfd, void * in, void * out) 680 1.1 christos { 681 1.1 christos struct internal_aouthdr *aouthdr_in = (struct internal_aouthdr *) in; 682 1.1 christos AOUTHDR *aouthdr_out = (AOUTHDR *) out; 683 1.1 christos 684 1.1 christos H_PUT_16 (abfd, aouthdr_in->magic, aouthdr_out->magic); 685 1.1 christos H_PUT_16 (abfd, aouthdr_in->vstamp, aouthdr_out->vstamp); 686 1.1 christos PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, aouthdr_out->tsize); 687 1.1 christos PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, aouthdr_out->dsize); 688 1.1 christos PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, aouthdr_out->bsize); 689 1.1 christos PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, aouthdr_out->entry); 690 1.1 christos PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start, 691 1.1 christos aouthdr_out->text_start); 692 1.1 christos PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start, 693 1.1 christos aouthdr_out->data_start); 694 1.1 christos 695 1.1 christos #ifdef RS6000COFF_C 696 1.1 christos #ifdef XCOFF64 697 1.1 christos H_PUT_64 (abfd, aouthdr_in->o_toc, aouthdr_out->o_toc); 698 1.1 christos #else 699 1.1 christos H_PUT_32 (abfd, aouthdr_in->o_toc, aouthdr_out->o_toc); 700 1.1 christos #endif 701 1.1 christos H_PUT_16 (abfd, aouthdr_in->o_snentry, aouthdr_out->o_snentry); 702 1.1 christos H_PUT_16 (abfd, aouthdr_in->o_sntext, aouthdr_out->o_sntext); 703 1.1 christos H_PUT_16 (abfd, aouthdr_in->o_sndata, aouthdr_out->o_sndata); 704 1.1 christos H_PUT_16 (abfd, aouthdr_in->o_sntoc, aouthdr_out->o_sntoc); 705 1.1 christos H_PUT_16 (abfd, aouthdr_in->o_snloader, aouthdr_out->o_snloader); 706 1.1 christos H_PUT_16 (abfd, aouthdr_in->o_snbss, aouthdr_out->o_snbss); 707 1.1 christos H_PUT_16 (abfd, aouthdr_in->o_algntext, aouthdr_out->o_algntext); 708 1.1 christos H_PUT_16 (abfd, aouthdr_in->o_algndata, aouthdr_out->o_algndata); 709 1.1 christos H_PUT_16 (abfd, aouthdr_in->o_modtype, aouthdr_out->o_modtype); 710 1.1 christos H_PUT_16 (abfd, aouthdr_in->o_cputype, aouthdr_out->o_cputype); 711 1.1 christos #ifdef XCOFF64 712 1.1 christos H_PUT_64 (abfd, aouthdr_in->o_maxstack, aouthdr_out->o_maxstack); 713 1.1 christos H_PUT_64 (abfd, aouthdr_in->o_maxdata, aouthdr_out->o_maxdata); 714 1.1 christos #else 715 1.1 christos H_PUT_32 (abfd, aouthdr_in->o_maxstack, aouthdr_out->o_maxstack); 716 1.1 christos H_PUT_32 (abfd, aouthdr_in->o_maxdata, aouthdr_out->o_maxdata); 717 1.1 christos #endif 718 1.8 christos /* TODO: set o_*psize dynamically */ 719 1.8 christos H_PUT_8 (abfd, 0, aouthdr_out->o_textpsize); 720 1.8 christos H_PUT_8 (abfd, 0, aouthdr_out->o_datapsize); 721 1.8 christos H_PUT_8 (abfd, 0, aouthdr_out->o_stackpsize); 722 1.8 christos H_PUT_8 (abfd, aouthdr_in->o_flags, aouthdr_out->o_flags); 723 1.8 christos H_PUT_16 (abfd, aouthdr_in->o_sntdata, aouthdr_out->o_sntdata); 724 1.8 christos H_PUT_16 (abfd, aouthdr_in->o_sntbss, aouthdr_out->o_sntbss); 725 1.8 christos H_PUT_32 (abfd, 0, aouthdr_out->o_debugger); 726 1.1 christos #ifdef XCOFF64 727 1.8 christos H_PUT_16 (abfd, aouthdr_in->o_x64flags, aouthdr_out->o_x64flags); 728 1.1 christos memset (aouthdr_out->o_resv3, 0, sizeof aouthdr_out->o_resv3); 729 1.1 christos #endif 730 1.1 christos #endif 731 1.1 christos 732 1.1 christos #ifdef MIPSECOFF 733 1.1 christos H_PUT_32 (abfd, aouthdr_in->bss_start, aouthdr_out->bss_start); 734 1.1 christos H_PUT_32 (abfd, aouthdr_in->gp_value, aouthdr_out->gp_value); 735 1.1 christos H_PUT_32 (abfd, aouthdr_in->gprmask, aouthdr_out->gprmask); 736 1.1 christos H_PUT_32 (abfd, aouthdr_in->cprmask[0], aouthdr_out->cprmask[0]); 737 1.1 christos H_PUT_32 (abfd, aouthdr_in->cprmask[1], aouthdr_out->cprmask[1]); 738 1.1 christos H_PUT_32 (abfd, aouthdr_in->cprmask[2], aouthdr_out->cprmask[2]); 739 1.1 christos H_PUT_32 (abfd, aouthdr_in->cprmask[3], aouthdr_out->cprmask[3]); 740 1.1 christos #endif 741 1.1 christos 742 1.1 christos #ifdef ALPHAECOFF 743 1.1 christos /* FIXME: What does bldrev mean? */ 744 1.1 christos H_PUT_16 (abfd, 2, aouthdr_out->bldrev); 745 1.1 christos H_PUT_16 (abfd, 0, aouthdr_out->padding); 746 1.1 christos H_PUT_64 (abfd, aouthdr_in->bss_start, aouthdr_out->bss_start); 747 1.1 christos H_PUT_64 (abfd, aouthdr_in->gp_value, aouthdr_out->gp_value); 748 1.1 christos H_PUT_32 (abfd, aouthdr_in->gprmask, aouthdr_out->gprmask); 749 1.1 christos H_PUT_32 (abfd, aouthdr_in->fprmask, aouthdr_out->fprmask); 750 1.1 christos #endif 751 1.1 christos 752 1.1 christos return AOUTSZ; 753 1.1 christos } 754 1.1 christos 755 1.8 christos ATTRIBUTE_UNUSED 756 1.1 christos static void 757 1.1 christos coff_swap_scnhdr_in (bfd * abfd, void * ext, void * in) 758 1.1 christos { 759 1.1 christos SCNHDR *scnhdr_ext = (SCNHDR *) ext; 760 1.1 christos struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in; 761 1.1 christos 762 1.1 christos #ifdef COFF_ADJUST_SCNHDR_IN_PRE 763 1.1 christos COFF_ADJUST_SCNHDR_IN_PRE (abfd, ext, in); 764 1.1 christos #endif 765 1.1 christos memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name)); 766 1.1 christos 767 1.1 christos scnhdr_int->s_vaddr = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr); 768 1.1 christos scnhdr_int->s_paddr = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr); 769 1.1 christos scnhdr_int->s_size = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size); 770 1.1 christos 771 1.1 christos scnhdr_int->s_scnptr = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr); 772 1.1 christos scnhdr_int->s_relptr = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr); 773 1.1 christos scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr); 774 1.1 christos scnhdr_int->s_flags = GET_SCNHDR_FLAGS (abfd, scnhdr_ext->s_flags); 775 1.1 christos scnhdr_int->s_nreloc = GET_SCNHDR_NRELOC (abfd, scnhdr_ext->s_nreloc); 776 1.1 christos scnhdr_int->s_nlnno = GET_SCNHDR_NLNNO (abfd, scnhdr_ext->s_nlnno); 777 1.1 christos #ifdef COFF_ADJUST_SCNHDR_IN_POST 778 1.1 christos COFF_ADJUST_SCNHDR_IN_POST (abfd, ext, in); 779 1.1 christos #endif 780 1.1 christos } 781 1.1 christos 782 1.8 christos ATTRIBUTE_UNUSED 783 1.1 christos static unsigned int 784 1.1 christos coff_swap_scnhdr_out (bfd * abfd, void * in, void * out) 785 1.1 christos { 786 1.1 christos struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in; 787 1.1 christos SCNHDR *scnhdr_ext = (SCNHDR *) out; 788 1.1 christos unsigned int ret = bfd_coff_scnhsz (abfd); 789 1.1 christos 790 1.1 christos #ifdef COFF_ADJUST_SCNHDR_OUT_PRE 791 1.1 christos COFF_ADJUST_SCNHDR_OUT_PRE (abfd, in, out); 792 1.1 christos #endif 793 1.1 christos memcpy (scnhdr_ext->s_name, scnhdr_int->s_name, sizeof (scnhdr_int->s_name)); 794 1.1 christos 795 1.1 christos PUT_SCNHDR_VADDR (abfd, scnhdr_int->s_vaddr, scnhdr_ext->s_vaddr); 796 1.1 christos PUT_SCNHDR_PADDR (abfd, scnhdr_int->s_paddr, scnhdr_ext->s_paddr); 797 1.1 christos PUT_SCNHDR_SIZE (abfd, scnhdr_int->s_size, scnhdr_ext->s_size); 798 1.1 christos PUT_SCNHDR_SCNPTR (abfd, scnhdr_int->s_scnptr, scnhdr_ext->s_scnptr); 799 1.1 christos PUT_SCNHDR_RELPTR (abfd, scnhdr_int->s_relptr, scnhdr_ext->s_relptr); 800 1.1 christos PUT_SCNHDR_LNNOPTR (abfd, scnhdr_int->s_lnnoptr, scnhdr_ext->s_lnnoptr); 801 1.1 christos PUT_SCNHDR_FLAGS (abfd, scnhdr_int->s_flags, scnhdr_ext->s_flags); 802 1.1 christos if (scnhdr_int->s_nlnno <= MAX_SCNHDR_NLNNO) 803 1.1 christos PUT_SCNHDR_NLNNO (abfd, scnhdr_int->s_nlnno, scnhdr_ext->s_nlnno); 804 1.1 christos else 805 1.1 christos { 806 1.1 christos char buf[sizeof (scnhdr_int->s_name) + 1]; 807 1.1 christos 808 1.1 christos memcpy (buf, scnhdr_int->s_name, sizeof (scnhdr_int->s_name)); 809 1.1 christos buf[sizeof (scnhdr_int->s_name)] = '\0'; 810 1.6 christos _bfd_error_handler 811 1.6 christos /* xgettext:c-format */ 812 1.6 christos (_("%pB: warning: %s: line number overflow: 0x%lx > 0xffff"), 813 1.6 christos abfd, buf, scnhdr_int->s_nlnno); 814 1.1 christos PUT_SCNHDR_NLNNO (abfd, 0xffff, scnhdr_ext->s_nlnno); 815 1.1 christos } 816 1.1 christos 817 1.1 christos if (scnhdr_int->s_nreloc <= MAX_SCNHDR_NRELOC) 818 1.1 christos PUT_SCNHDR_NRELOC (abfd, scnhdr_int->s_nreloc, scnhdr_ext->s_nreloc); 819 1.1 christos else 820 1.1 christos { 821 1.1 christos char buf[sizeof (scnhdr_int->s_name) + 1]; 822 1.1 christos 823 1.1 christos memcpy (buf, scnhdr_int->s_name, sizeof (scnhdr_int->s_name)); 824 1.1 christos buf[sizeof (scnhdr_int->s_name)] = '\0'; 825 1.6 christos /* xgettext:c-format */ 826 1.6 christos _bfd_error_handler (_("%pB: %s: reloc overflow: 0x%lx > 0xffff"), 827 1.6 christos abfd, buf, scnhdr_int->s_nreloc); 828 1.1 christos bfd_set_error (bfd_error_file_truncated); 829 1.1 christos PUT_SCNHDR_NRELOC (abfd, 0xffff, scnhdr_ext->s_nreloc); 830 1.1 christos ret = 0; 831 1.1 christos } 832 1.1 christos 833 1.1 christos #ifdef COFF_ADJUST_SCNHDR_OUT_POST 834 1.1 christos COFF_ADJUST_SCNHDR_OUT_POST (abfd, in, out); 835 1.1 christos #endif 836 1.1 christos return ret; 837 1.1 christos } 838