Changeset 609 for branches/GNU/src/binutils/bfd/coff-stgo32.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/coff-stgo32.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* BFD back-end for Intel 386 COFF files (DJGPP variant with a stub). 2 Copyright 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.2 Copyright 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. 3 3 Written by Robert Hoehne. 4 4 … … 33 33 34 34 To be compatible with any existing executables I have fixed this 35 here and NOT in the DJGPP startup code. 36 */ 35 here and NOT in the DJGPP startup code. */ 37 36 38 37 #define TARGET_SYM go32stubbedcoff_vec … … 48 47 COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \ 49 48 { COFF_SECTION_NAME_EXACT_MATCH (".text"), \ 50 COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 } 49 COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \ 50 { COFF_SECTION_NAME_PARTIAL_MATCH (".debug"), \ 51 COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, \ 52 { COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.wi"), \ 53 COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 } 51 54 52 55 #include "bfd.h" 53 56 54 /* At first the prototypes */ 55 56 static void 57 adjust_filehdr_in_post PARAMS ((bfd * abfd, PTR src, PTR dst)); 58 static void 59 adjust_filehdr_out_pre PARAMS ((bfd * abfd, PTR in, PTR out)); 60 static void 61 adjust_filehdr_out_post PARAMS ((bfd * abfd, PTR in, PTR out)); 62 63 static void 64 adjust_scnhdr_in_post PARAMS ((bfd * abfd, PTR ext, PTR in)); 65 static void 66 adjust_scnhdr_out_pre PARAMS ((bfd * abfd, PTR in, PTR out)); 67 static void 68 adjust_scnhdr_out_post PARAMS ((bfd * abfd, PTR in, PTR out)); 69 70 static void 71 adjust_aux_in_post PARAMS ((bfd * abfd, PTR ext1, int type, int class, int indx, 72 int numaux, PTR in1)); 73 static void 74 adjust_aux_out_pre PARAMS ((bfd * abfd, PTR inp, int type, int class, int indx, 75 int numaux, PTR extp)); 76 static void 77 adjust_aux_out_post PARAMS ((bfd * abfd, PTR inp, int type, int class, int indx, 78 int numaux, PTR extp)); 79 80 static void 81 create_go32_stub PARAMS ((bfd * abfd)); 82 83 /* 84 All that ..._PRE and ...POST functions are called from the corresponding 57 /* At first the prototypes. */ 58 59 static void 60 adjust_filehdr_in_post PARAMS ((bfd *, PTR, PTR)); 61 static void 62 adjust_filehdr_out_pre PARAMS ((bfd *, PTR, PTR)); 63 static void 64 adjust_filehdr_out_post PARAMS ((bfd *, PTR, PTR)); 65 static void 66 adjust_scnhdr_in_post PARAMS ((bfd *, PTR, PTR)); 67 static void 68 adjust_scnhdr_out_pre PARAMS ((bfd *, PTR, PTR)); 69 static void 70 adjust_scnhdr_out_post PARAMS ((bfd *, PTR, PTR)); 71 static void 72 adjust_aux_in_post PARAMS ((bfd *, PTR, int, int, int, int, PTR)); 73 static void 74 adjust_aux_out_pre PARAMS ((bfd *, PTR, int, int, int, int, PTR)); 75 static void 76 adjust_aux_out_post PARAMS ((bfd *, PTR, int, int, int, int, PTR)); 77 static void 78 create_go32_stub PARAMS ((bfd *)); 79 80 /* All that ..._PRE and ...POST functions are called from the corresponding 85 81 coff_swap... functions. The ...PRE functions are called at the beginning 86 of the function and the ...POST functions at the end of the swap routines. 87 */ 82 of the function and the ...POST functions at the end of the swap routines. */ 88 83 89 84 #define COFF_ADJUST_FILEHDR_IN_POST adjust_filehdr_in_post … … 99 94 #define COFF_ADJUST_AUX_OUT_POST adjust_aux_out_post 100 95 101 static b oolean102 go32_stubbed_coff_bfd_copy_private_bfd_data PARAMS ((bfd * ibfd, bfd * obfd));96 static bfd_boolean 97 go32_stubbed_coff_bfd_copy_private_bfd_data PARAMS ((bfd *, bfd *)); 103 98 104 99 #define coff_bfd_copy_private_bfd_data go32_stubbed_coff_bfd_copy_private_bfd_data … … 106 101 #include "coff-i386.c" 107 102 108 /* I hold in the usrdata the stub */103 /* I hold in the usrdata the stub. */ 109 104 #define bfd_coff_go32stub bfd_usrdata 110 105 111 106 /* This macro is used, because I cannot assume the endianess of the 112 host system */113 #define _H(index) ( bfd_h_get_16(abfd, (bfd_byte *)(header+index*2)))107 host system. */ 108 #define _H(index) (H_GET_16 (abfd, (header+index*2))) 114 109 115 110 /* These bytes are a 2048-byte DOS executable, which loads the COFF 116 image into memory and then runs it. It is called 'stub' */117 118 static unsigned char stub_bytes[STUBSIZE] =111 image into memory and then runs it. It is called 'stub'. */ 112 113 static const unsigned char stub_bytes[STUBSIZE] = 119 114 { 120 115 #include "go32stub.h" … … 126 121 all the pointers are adjusted by adding STUBSIZE and for the 127 122 ...out function, it is subtracted first and after calling the 128 standard swap function it is reset to the old value */123 standard swap function it is reset to the old value. */ 129 124 130 125 /* This macro is used for adjusting the filepointers, which 131 is done only, if the pointer is nonzero */126 is done only, if the pointer is nonzero. */ 132 127 133 128 #define ADJUST_VAL(val,diff) \ … … 145 140 ADJUST_VAL (filehdr_dst->f_symptr, STUBSIZE); 146 141 147 /* Save now the stub to be used later */148 bfd_coff_go32stub (abfd) = (PTR) bfd_alloc (abfd, STUBSIZE);142 /* Save now the stub to be used later. */ 143 bfd_coff_go32stub (abfd) = (PTR) bfd_alloc (abfd, (bfd_size_type) STUBSIZE); 149 144 150 145 /* Since this function returns no status, I do not set here 151 146 any bfd_error_... 152 147 That means, before the use of bfd_coff_go32stub (), this value 153 should be checked if it is != NULL */148 should be checked if it is != NULL. */ 154 149 if (bfd_coff_go32stub (abfd) == NULL) 155 150 return; … … 166 161 FILHDR *filehdr_out = (FILHDR *) out; 167 162 168 /* Generate the stub */163 /* Generate the stub. */ 169 164 create_go32_stub (abfd); 170 165 171 /* Copy the stub to the file header */166 /* Copy the stub to the file header. */ 172 167 if (bfd_coff_go32stub (abfd) != NULL) 173 168 memcpy (filehdr_out->stub, bfd_coff_go32stub (abfd), STUBSIZE); 174 169 else 175 /* use the default*/170 /* Use the default. */ 176 171 memcpy (filehdr_out->stub, stub_bytes, STUBSIZE); 177 172 … … 186 181 { 187 182 struct internal_filehdr *filehdr_in = (struct internal_filehdr *) in; 188 /* undo the above change*/183 /* Undo the above change. */ 189 184 ADJUST_VAL (filehdr_in->f_symptr, STUBSIZE); 190 185 } … … 283 278 } 284 279 285 /* 286 That's the function, which creates the stub. There are 280 /* That's the function, which creates the stub. There are 287 281 different cases from where the stub is taken. 288 282 At first the environment variable $(GO32STUB) is checked and then … … 294 288 295 289 If there was any error, the standard stub (compiled in this file) 296 is taken. 297 */ 290 is taken. */ 298 291 299 292 static void … … 301 294 bfd *abfd; 302 295 { 303 /* Do it only once */296 /* Do it only once. */ 304 297 if (bfd_coff_go32stub (abfd) == NULL) 305 298 { … … 309 302 unsigned char header[10]; 310 303 char magic[8]; 311 unsigned long coff_start, exe_start; 312 313 /* Check at first the environment variable $(GO32STUB) */ 304 unsigned long coff_start; 305 long exe_start; 306 307 /* Check at first the environment variable $(GO32STUB). */ 314 308 stub = getenv ("GO32STUB"); 315 /* Now check the environment variable $(STUB) */309 /* Now check the environment variable $(STUB). */ 316 310 if (stub == NULL) 317 311 stub = getenv ("STUB"); … … 332 326 goto stub_end; 333 327 } 334 if (_H (0) != 0x5a4d) /* it is not an exe file*/328 if (_H (0) != 0x5a4d) /* It is not an exe file. */ 335 329 { 336 330 close (f); … … 338 332 } 339 333 /* Compute the size of the stub (it is every thing up 340 to the beginning of the coff image) */334 to the beginning of the coff image). */ 341 335 coff_start = (long) _H (2) * 512L; 342 336 if (_H (1)) … … 344 338 345 339 /* Currently there is only a fixed stub size of 2048 bytes 346 supported */340 supported. */ 347 341 if (coff_start != 2048) 348 342 { … … 351 345 } 352 346 exe_start = _H (4) * 16; 353 if (( unsignedlong) lseek (f, exe_start, SEEK_SET) != exe_start)347 if ((long) lseek (f, exe_start, SEEK_SET) != exe_start) 354 348 { 355 349 close (f); … … 366 360 goto stub_end; 367 361 } 368 /* Now we found a correct stub (hopefully) */ 369 bfd_coff_go32stub (abfd) = (PTR) bfd_alloc (abfd, coff_start); 362 /* Now we found a correct stub (hopefully). */ 363 bfd_coff_go32stub (abfd) 364 = (PTR) bfd_alloc (abfd, (bfd_size_type) coff_start); 370 365 if (bfd_coff_go32stub (abfd) == NULL) 371 366 { … … 384 379 stub_end: 385 380 /* There was something wrong above, so use now the standard builtin 386 stub */381 stub. */ 387 382 if (bfd_coff_go32stub (abfd) == NULL) 388 383 { 389 bfd_coff_go32stub (abfd) = (PTR) bfd_alloc (abfd, STUBSIZE); 384 bfd_coff_go32stub (abfd) 385 = (PTR) bfd_alloc (abfd, (bfd_size_type) STUBSIZE); 390 386 if (bfd_coff_go32stub (abfd) == NULL) 391 { 392 return; 393 } 394 387 return; 395 388 memcpy (bfd_coff_go32stub (abfd), stub_bytes, STUBSIZE); 396 389 } … … 398 391 399 392 /* If ibfd was a stubbed coff image, copy the stub from that bfd 400 to the new obfd. 401 */ 402 403 static boolean 393 to the new obfd. */ 394 395 static bfd_boolean 404 396 go32_stubbed_coff_bfd_copy_private_bfd_data (ibfd, obfd) 405 397 bfd *ibfd; 406 398 bfd *obfd; 407 399 { 408 /* check if both are the same targets*/400 /* Check if both are the same targets. */ 409 401 if (ibfd->xvec != obfd->xvec) 410 return true;411 412 /* check if both have a valid stub*/402 return TRUE; 403 404 /* Check if both have a valid stub. */ 413 405 if (bfd_coff_go32stub (ibfd) == NULL 414 406 || bfd_coff_go32stub (obfd) == NULL) 415 return true;416 417 /* Now copy the stub */407 return TRUE; 408 409 /* Now copy the stub. */ 418 410 memcpy (bfd_coff_go32stub (obfd), bfd_coff_go32stub (ibfd), STUBSIZE); 419 411 420 return true;421 } 412 return TRUE; 413 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.