archive.c (107492) | archive.c (130561) |
---|---|
1/* BFD back-end for archive files (libraries). 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, | 1/* BFD back-end for archive files (libraries). 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
3 2000, 2001, 2002 | 3 2000, 2001, 2002, 2003 |
4 Free Software Foundation, Inc. 5 Written by Cygnus Support. Mostly Gumby Henkel-Wallace's fault. 6 7This file is part of BFD, the Binary File Descriptor library. 8 9This program is free software; you can redistribute it and/or modify 10it under the terms of the GNU General Public License as published by 11the Free Software Foundation; either version 2 of the License, or --- 141 unchanged lines hidden (view full) --- 153 bfd *arelt; 154 struct ar_cache *next; 155}; 156 157#define ar_padchar(abfd) ((abfd)->xvec->ar_pad_char) 158#define ar_maxnamelen(abfd) ((abfd)->xvec->ar_max_namelen) 159 160#define arch_eltdata(bfd) ((struct areltdata *) ((bfd)->arelt_data)) | 4 Free Software Foundation, Inc. 5 Written by Cygnus Support. Mostly Gumby Henkel-Wallace's fault. 6 7This file is part of BFD, the Binary File Descriptor library. 8 9This program is free software; you can redistribute it and/or modify 10it under the terms of the GNU General Public License as published by 11the Free Software Foundation; either version 2 of the License, or --- 141 unchanged lines hidden (view full) --- 153 bfd *arelt; 154 struct ar_cache *next; 155}; 156 157#define ar_padchar(abfd) ((abfd)->xvec->ar_pad_char) 158#define ar_maxnamelen(abfd) ((abfd)->xvec->ar_max_namelen) 159 160#define arch_eltdata(bfd) ((struct areltdata *) ((bfd)->arelt_data)) |
161#define arch_hdr(bfd) ((struct ar_hdr *)arch_eltdata(bfd)->arch_header) | 161#define arch_hdr(bfd) ((struct ar_hdr *) arch_eltdata(bfd)->arch_header) |
162 | 162 |
163static char *get_extended_arelt_filename PARAMS ((bfd *arch, 164 const char *name)); 165static boolean do_slurp_bsd_armap PARAMS ((bfd *abfd)); 166static boolean do_slurp_coff_armap PARAMS ((bfd *abfd)); 167boolean bfd_elf64_archive_slurp_armap PARAMS ((bfd *abfd)); 168static const char *normalize PARAMS ((bfd *, const char *file)); 169static struct areltdata *bfd_ar_hdr_from_filesystem PARAMS ((bfd *abfd, 170 const char *, 171 bfd *member)); | |
172 | 163 |
173boolean 174_bfd_generic_mkarchive (abfd) 175 bfd *abfd; | 164bfd_boolean 165_bfd_generic_mkarchive (bfd *abfd) |
176{ 177 bfd_size_type amt = sizeof (struct artdata); 178 | 166{ 167 bfd_size_type amt = sizeof (struct artdata); 168 |
179 abfd->tdata.aout_ar_data = (struct artdata *) bfd_zalloc (abfd, amt); | 169 abfd->tdata.aout_ar_data = bfd_zalloc (abfd, amt); |
180 if (bfd_ardata (abfd) == NULL) | 170 if (bfd_ardata (abfd) == NULL) |
181 return false; | 171 return FALSE; |
182 183 bfd_ardata (abfd)->cache = NULL; 184 bfd_ardata (abfd)->archive_head = NULL; 185 bfd_ardata (abfd)->symdefs = NULL; 186 bfd_ardata (abfd)->extended_names = NULL; 187 bfd_ardata (abfd)->tdata = NULL; 188 | 172 173 bfd_ardata (abfd)->cache = NULL; 174 bfd_ardata (abfd)->archive_head = NULL; 175 bfd_ardata (abfd)->symdefs = NULL; 176 bfd_ardata (abfd)->extended_names = NULL; 177 bfd_ardata (abfd)->tdata = NULL; 178 |
189 return true; | 179 return TRUE; |
190} 191 192/* 193FUNCTION 194 bfd_get_next_mapent 195 196SYNOPSIS | 180} 181 182/* 183FUNCTION 184 bfd_get_next_mapent 185 186SYNOPSIS |
197 symindex bfd_get_next_mapent(bfd *abfd, symindex previous, carsym **sym); | 187 symindex bfd_get_next_mapent 188 (bfd *abfd, symindex previous, carsym **sym); |
198 199DESCRIPTION 200 Step through archive @var{abfd}'s symbol table (if it 201 has one). Successively update @var{sym} with the next symbol's 202 information, returning that symbol's (internal) index into the 203 symbol table. 204 205 Supply <<BFD_NO_MORE_SYMBOLS>> as the @var{previous} entry to get 206 the first one; returns <<BFD_NO_MORE_SYMBOLS>> when you've already 207 got the last one. 208 209 A <<carsym>> is a canonical archive symbol. The only 210 user-visible element is its name, a null-terminated string. 211*/ 212 213symindex | 189 190DESCRIPTION 191 Step through archive @var{abfd}'s symbol table (if it 192 has one). Successively update @var{sym} with the next symbol's 193 information, returning that symbol's (internal) index into the 194 symbol table. 195 196 Supply <<BFD_NO_MORE_SYMBOLS>> as the @var{previous} entry to get 197 the first one; returns <<BFD_NO_MORE_SYMBOLS>> when you've already 198 got the last one. 199 200 A <<carsym>> is a canonical archive symbol. The only 201 user-visible element is its name, a null-terminated string. 202*/ 203 204symindex |
214bfd_get_next_mapent (abfd, prev, entry) 215 bfd *abfd; 216 symindex prev; 217 carsym **entry; | 205bfd_get_next_mapent (bfd *abfd, symindex prev, carsym **entry) |
218{ 219 if (!bfd_has_map (abfd)) 220 { 221 bfd_set_error (bfd_error_invalid_operation); 222 return BFD_NO_MORE_SYMBOLS; 223 } 224 225 if (prev == BFD_NO_MORE_SYMBOLS) --- 5 unchanged lines hidden (view full) --- 231 232 *entry = (bfd_ardata (abfd)->symdefs + prev); 233 return prev; 234} 235 236/* To be called by backends only */ 237 238bfd * | 206{ 207 if (!bfd_has_map (abfd)) 208 { 209 bfd_set_error (bfd_error_invalid_operation); 210 return BFD_NO_MORE_SYMBOLS; 211 } 212 213 if (prev == BFD_NO_MORE_SYMBOLS) --- 5 unchanged lines hidden (view full) --- 219 220 *entry = (bfd_ardata (abfd)->symdefs + prev); 221 return prev; 222} 223 224/* To be called by backends only */ 225 226bfd * |
239_bfd_create_empty_archive_element_shell (obfd) 240 bfd *obfd; | 227_bfd_create_empty_archive_element_shell (bfd *obfd) |
241{ 242 return _bfd_new_bfd_contained_in (obfd); 243} 244 245/* 246FUNCTION 247 bfd_set_archive_head 248 249SYNOPSIS | 228{ 229 return _bfd_new_bfd_contained_in (obfd); 230} 231 232/* 233FUNCTION 234 bfd_set_archive_head 235 236SYNOPSIS |
250 boolean bfd_set_archive_head(bfd *output, bfd *new_head); | 237 bfd_boolean bfd_set_archive_head (bfd *output, bfd *new_head); |
251 252DESCRIPTION 253 Set the head of the chain of 254 BFDs contained in the archive @var{output} to @var{new_head}. 255*/ 256 | 238 239DESCRIPTION 240 Set the head of the chain of 241 BFDs contained in the archive @var{output} to @var{new_head}. 242*/ 243 |
257boolean 258bfd_set_archive_head (output_archive, new_head) 259 bfd *output_archive; 260 bfd *new_head; | 244bfd_boolean 245bfd_set_archive_head (bfd *output_archive, bfd *new_head) |
261{ | 246{ |
262 | |
263 output_archive->archive_head = new_head; | 247 output_archive->archive_head = new_head; |
264 return true; | 248 return TRUE; |
265} 266 267bfd * | 249} 250 251bfd * |
268_bfd_look_for_bfd_in_cache (arch_bfd, filepos) 269 bfd *arch_bfd; 270 file_ptr filepos; | 252_bfd_look_for_bfd_in_cache (bfd *arch_bfd, file_ptr filepos) |
271{ 272 struct ar_cache *current; 273 274 for (current = bfd_ardata (arch_bfd)->cache; current != NULL; 275 current = current->next) 276 if (current->ptr == filepos) 277 return current->arelt; 278 279 return NULL; 280} 281 282/* Kind of stupid to call cons for each one, but we don't do too many */ | 253{ 254 struct ar_cache *current; 255 256 for (current = bfd_ardata (arch_bfd)->cache; current != NULL; 257 current = current->next) 258 if (current->ptr == filepos) 259 return current->arelt; 260 261 return NULL; 262} 263 264/* Kind of stupid to call cons for each one, but we don't do too many */ |
283boolean 284_bfd_add_bfd_to_archive_cache (arch_bfd, filepos, new_elt) 285 bfd *arch_bfd, *new_elt; 286 file_ptr filepos; | 265bfd_boolean 266_bfd_add_bfd_to_archive_cache (bfd *arch_bfd, file_ptr filepos, bfd *new_elt) |
287{ 288 bfd_size_type amt = sizeof (struct ar_cache); 289 | 267{ 268 bfd_size_type amt = sizeof (struct ar_cache); 269 |
290 struct ar_cache *new_cache = (struct ar_cache *) bfd_zalloc (arch_bfd, amt); | 270 struct ar_cache *new_cache = bfd_zalloc (arch_bfd, amt); |
291 if (new_cache == NULL) | 271 if (new_cache == NULL) |
292 return false; | 272 return FALSE; |
293 294 new_cache->ptr = filepos; 295 new_cache->arelt = new_elt; | 273 274 new_cache->ptr = filepos; 275 new_cache->arelt = new_elt; |
296 new_cache->next = (struct ar_cache *) NULL; | 276 new_cache->next = NULL; |
297 if (bfd_ardata (arch_bfd)->cache == NULL) 298 bfd_ardata (arch_bfd)->cache = new_cache; 299 else 300 { 301 struct ar_cache *current = bfd_ardata (arch_bfd)->cache; 302 303 while (current->next != NULL) 304 current = current->next; 305 current->next = new_cache; 306 } 307 | 277 if (bfd_ardata (arch_bfd)->cache == NULL) 278 bfd_ardata (arch_bfd)->cache = new_cache; 279 else 280 { 281 struct ar_cache *current = bfd_ardata (arch_bfd)->cache; 282 283 while (current->next != NULL) 284 current = current->next; 285 current->next = new_cache; 286 } 287 |
308 return true; | 288 return TRUE; |
309} 310 311/* The name begins with space. Hence the rest of the name is an index into 312 the string table. */ 313 314static char * | 289} 290 291/* The name begins with space. Hence the rest of the name is an index into 292 the string table. */ 293 294static char * |
315get_extended_arelt_filename (arch, name) 316 bfd *arch; 317 const char *name; | 295get_extended_arelt_filename (bfd *arch, const char *name) |
318{ 319 unsigned long index = 0; 320 321 /* Should extract string so that I can guarantee not to overflow into 322 the next region, but I'm too lazy. */ 323 errno = 0; 324 /* Skip first char, which is '/' in SVR4 or ' ' in some other variants. */ 325 index = strtol (name + 1, NULL, 10); --- 10 unchanged lines hidden (view full) --- 336 NULL on error. 337 338 Presumes the file pointer is already in the right place (ie pointing 339 to the ar_hdr in the file). Moves the file pointer; on success it 340 should be pointing to the front of the file contents; on failure it 341 could have been moved arbitrarily. 342*/ 343 | 296{ 297 unsigned long index = 0; 298 299 /* Should extract string so that I can guarantee not to overflow into 300 the next region, but I'm too lazy. */ 301 errno = 0; 302 /* Skip first char, which is '/' in SVR4 or ' ' in some other variants. */ 303 index = strtol (name + 1, NULL, 10); --- 10 unchanged lines hidden (view full) --- 314 NULL on error. 315 316 Presumes the file pointer is already in the right place (ie pointing 317 to the ar_hdr in the file). Moves the file pointer; on success it 318 should be pointing to the front of the file contents; on failure it 319 could have been moved arbitrarily. 320*/ 321 |
344PTR 345_bfd_generic_read_ar_hdr (abfd) 346 bfd *abfd; | 322void * 323_bfd_generic_read_ar_hdr (bfd *abfd) |
347{ | 324{ |
348 return _bfd_generic_read_ar_hdr_mag (abfd, (const char *) NULL); | 325 return _bfd_generic_read_ar_hdr_mag (abfd, NULL); |
349} 350 351/* Alpha ECOFF uses an optional different ARFMAG value, so we have a 352 variant of _bfd_generic_read_ar_hdr which accepts a magic string. */ 353 | 326} 327 328/* Alpha ECOFF uses an optional different ARFMAG value, so we have a 329 variant of _bfd_generic_read_ar_hdr which accepts a magic string. */ 330 |
354PTR 355_bfd_generic_read_ar_hdr_mag (abfd, mag) 356 bfd *abfd; 357 const char *mag; | 331void * 332_bfd_generic_read_ar_hdr_mag (bfd *abfd, const char *mag) |
358{ 359 struct ar_hdr hdr; 360 char *hdrp = (char *) &hdr; 361 size_t parsed_size; 362 struct areltdata *ared; 363 char *filename = NULL; 364 bfd_size_type namelen = 0; 365 bfd_size_type allocsize = sizeof (struct areltdata) + sizeof (struct ar_hdr); 366 char *allocptr = 0; 367 | 333{ 334 struct ar_hdr hdr; 335 char *hdrp = (char *) &hdr; 336 size_t parsed_size; 337 struct areltdata *ared; 338 char *filename = NULL; 339 bfd_size_type namelen = 0; 340 bfd_size_type allocsize = sizeof (struct areltdata) + sizeof (struct ar_hdr); 341 char *allocptr = 0; 342 |
368 if (bfd_bread ((PTR) hdrp, (bfd_size_type) sizeof (struct ar_hdr), abfd) 369 != sizeof (struct ar_hdr)) | 343 if (bfd_bread (hdrp, sizeof (struct ar_hdr), abfd) != sizeof (struct ar_hdr)) |
370 { 371 if (bfd_get_error () != bfd_error_system_call) 372 bfd_set_error (bfd_error_no_more_archived_files); 373 return NULL; 374 } 375 if (strncmp (hdr.ar_fmag, ARFMAG, 2) != 0 376 && (mag == NULL 377 || strncmp (hdr.ar_fmag, mag, 2) != 0)) --- 53 unchanged lines hidden (view full) --- 431 } 432 else 433 { 434 /* We judge the end of the name by looking for '/' or ' '. 435 Note: The SYSV format (terminated by '/') allows embedded 436 spaces, so only look for ' ' if we don't find '/'. */ 437 438 char *e; | 344 { 345 if (bfd_get_error () != bfd_error_system_call) 346 bfd_set_error (bfd_error_no_more_archived_files); 347 return NULL; 348 } 349 if (strncmp (hdr.ar_fmag, ARFMAG, 2) != 0 350 && (mag == NULL 351 || strncmp (hdr.ar_fmag, mag, 2) != 0)) --- 53 unchanged lines hidden (view full) --- 405 } 406 else 407 { 408 /* We judge the end of the name by looking for '/' or ' '. 409 Note: The SYSV format (terminated by '/') allows embedded 410 spaces, so only look for ' ' if we don't find '/'. */ 411 412 char *e; |
439 e = (char *) memchr (hdr.ar_name, '\0', ar_maxnamelen (abfd)); | 413 e = memchr (hdr.ar_name, '\0', ar_maxnamelen (abfd)); |
440 if (e == NULL) 441 { | 414 if (e == NULL) 415 { |
442 e = (char *) memchr (hdr.ar_name, '/', ar_maxnamelen (abfd)); | 416 e = memchr (hdr.ar_name, '/', ar_maxnamelen (abfd)); |
443 if (e == NULL) | 417 if (e == NULL) |
444 e = (char *) memchr (hdr.ar_name, ' ', ar_maxnamelen (abfd)); | 418 e = memchr (hdr.ar_name, ' ', ar_maxnamelen (abfd)); |
445 } 446 447 if (e != NULL) 448 namelen = e - hdr.ar_name; 449 else 450 { 451 /* If we didn't find a termination character, then the name 452 must be the entire field. */ --- 8 unchanged lines hidden (view full) --- 461 allocptr = bfd_zalloc (abfd, allocsize); 462 if (allocptr == NULL) 463 return NULL; 464 } 465 466 ared = (struct areltdata *) allocptr; 467 468 ared->arch_header = allocptr + sizeof (struct areltdata); | 419 } 420 421 if (e != NULL) 422 namelen = e - hdr.ar_name; 423 else 424 { 425 /* If we didn't find a termination character, then the name 426 must be the entire field. */ --- 8 unchanged lines hidden (view full) --- 435 allocptr = bfd_zalloc (abfd, allocsize); 436 if (allocptr == NULL) 437 return NULL; 438 } 439 440 ared = (struct areltdata *) allocptr; 441 442 ared->arch_header = allocptr + sizeof (struct areltdata); |
469 memcpy ((char *) ared->arch_header, (char *) &hdr, sizeof (struct ar_hdr)); | 443 memcpy (ared->arch_header, &hdr, sizeof (struct ar_hdr)); |
470 ared->parsed_size = parsed_size; 471 472 if (filename != NULL) 473 ared->filename = filename; 474 else 475 { 476 ared->filename = allocptr + (sizeof (struct areltdata) + 477 sizeof (struct ar_hdr)); 478 if (namelen) | 444 ared->parsed_size = parsed_size; 445 446 if (filename != NULL) 447 ared->filename = filename; 448 else 449 { 450 ared->filename = allocptr + (sizeof (struct areltdata) + 451 sizeof (struct ar_hdr)); 452 if (namelen) |
479 memcpy (ared->filename, hdr.ar_name, (size_t) namelen); | 453 memcpy (ared->filename, hdr.ar_name, namelen); |
480 ared->filename[namelen] = '\0'; 481 } 482 | 454 ared->filename[namelen] = '\0'; 455 } 456 |
483 return (PTR) ared; | 457 return ared; |
484} 485 486/* This is an internal function; it's mainly used when indexing 487 through the archive symbol table, but also used to get the next 488 element, since it handles the bookkeeping so nicely for us. */ 489 490bfd * | 458} 459 460/* This is an internal function; it's mainly used when indexing 461 through the archive symbol table, but also used to get the next 462 element, since it handles the bookkeeping so nicely for us. */ 463 464bfd * |
491_bfd_get_elt_at_filepos (archive, filepos) 492 bfd *archive; 493 file_ptr filepos; | 465_bfd_get_elt_at_filepos (bfd *archive, file_ptr filepos) |
494{ 495 struct areltdata *new_areldata; 496 bfd *n_nfd; 497 498 n_nfd = _bfd_look_for_bfd_in_cache (archive, filepos); 499 if (n_nfd) 500 return n_nfd; 501 502 if (0 > bfd_seek (archive, filepos, SEEK_SET)) 503 return NULL; 504 | 466{ 467 struct areltdata *new_areldata; 468 bfd *n_nfd; 469 470 n_nfd = _bfd_look_for_bfd_in_cache (archive, filepos); 471 if (n_nfd) 472 return n_nfd; 473 474 if (0 > bfd_seek (archive, filepos, SEEK_SET)) 475 return NULL; 476 |
505 if ((new_areldata = (struct areltdata *) _bfd_read_ar_hdr (archive)) == NULL) | 477 if ((new_areldata = _bfd_read_ar_hdr (archive)) == NULL) |
506 return NULL; 507 508 n_nfd = _bfd_create_empty_archive_element_shell (archive); 509 if (n_nfd == NULL) 510 { | 478 return NULL; 479 480 n_nfd = _bfd_create_empty_archive_element_shell (archive); 481 if (n_nfd == NULL) 482 { |
511 bfd_release (archive, (PTR) new_areldata); | 483 bfd_release (archive, new_areldata); |
512 return NULL; 513 } 514 515 n_nfd->origin = bfd_tell (archive); | 484 return NULL; 485 } 486 487 n_nfd->origin = bfd_tell (archive); |
516 n_nfd->arelt_data = (PTR) new_areldata; | 488 n_nfd->arelt_data = new_areldata; |
517 n_nfd->filename = new_areldata->filename; 518 519 if (_bfd_add_bfd_to_archive_cache (archive, filepos, n_nfd)) 520 return n_nfd; 521 522 /* Huh? */ | 489 n_nfd->filename = new_areldata->filename; 490 491 if (_bfd_add_bfd_to_archive_cache (archive, filepos, n_nfd)) 492 return n_nfd; 493 494 /* Huh? */ |
523 bfd_release (archive, (PTR) n_nfd); 524 bfd_release (archive, (PTR) new_areldata); | 495 bfd_release (archive, n_nfd); 496 bfd_release (archive, new_areldata); |
525 return NULL; 526} 527 528/* Return the BFD which is referenced by the symbol in ABFD indexed by 529 INDEX. INDEX should have been returned by bfd_get_next_mapent. */ 530 531bfd * | 497 return NULL; 498} 499 500/* Return the BFD which is referenced by the symbol in ABFD indexed by 501 INDEX. INDEX should have been returned by bfd_get_next_mapent. */ 502 503bfd * |
532_bfd_generic_get_elt_at_index (abfd, index) 533 bfd *abfd; 534 symindex index; | 504_bfd_generic_get_elt_at_index (bfd *abfd, symindex index) |
535{ 536 carsym *entry; 537 538 entry = bfd_ardata (abfd)->symdefs + index; 539 return _bfd_get_elt_at_filepos (abfd, entry->file_offset); 540} 541 542/* 543FUNCTION 544 bfd_openr_next_archived_file 545 546SYNOPSIS | 505{ 506 carsym *entry; 507 508 entry = bfd_ardata (abfd)->symdefs + index; 509 return _bfd_get_elt_at_filepos (abfd, entry->file_offset); 510} 511 512/* 513FUNCTION 514 bfd_openr_next_archived_file 515 516SYNOPSIS |
547 bfd *bfd_openr_next_archived_file(bfd *archive, bfd *previous); | 517 bfd *bfd_openr_next_archived_file (bfd *archive, bfd *previous); |
548 549DESCRIPTION 550 Provided a BFD, @var{archive}, containing an archive and NULL, open 551 an input BFD on the first contained element and returns that. 552 Subsequent calls should pass 553 the archive and the previous return value to return a created 554 BFD to the next contained element. NULL is returned when there 555 are no more. 556*/ 557 558bfd * | 518 519DESCRIPTION 520 Provided a BFD, @var{archive}, containing an archive and NULL, open 521 an input BFD on the first contained element and returns that. 522 Subsequent calls should pass 523 the archive and the previous return value to return a created 524 BFD to the next contained element. NULL is returned when there 525 are no more. 526*/ 527 528bfd * |
559bfd_openr_next_archived_file (archive, last_file) 560 bfd *archive; 561 bfd *last_file; | 529bfd_openr_next_archived_file (bfd *archive, bfd *last_file) |
562{ 563 if ((bfd_get_format (archive) != bfd_archive) || 564 (archive->direction == write_direction)) 565 { 566 bfd_set_error (bfd_error_invalid_operation); 567 return NULL; 568 } 569 570 return BFD_SEND (archive, | 530{ 531 if ((bfd_get_format (archive) != bfd_archive) || 532 (archive->direction == write_direction)) 533 { 534 bfd_set_error (bfd_error_invalid_operation); 535 return NULL; 536 } 537 538 return BFD_SEND (archive, |
571 openr_next_archived_file, 572 (archive, 573 last_file)); | 539 openr_next_archived_file, (archive, last_file)); |
574} 575 576bfd * | 540} 541 542bfd * |
577bfd_generic_openr_next_archived_file (archive, last_file) 578 bfd *archive; 579 bfd *last_file; | 543bfd_generic_openr_next_archived_file (bfd *archive, bfd *last_file) |
580{ 581 file_ptr filestart; 582 583 if (!last_file) 584 filestart = bfd_ardata (archive)->first_file_filepos; 585 else 586 { 587 unsigned int size = arelt_size (last_file); 588 /* Pad to an even boundary... 589 Note that last_file->origin can be odd in the case of 590 BSD-4.4-style element with a long odd size. */ 591 filestart = last_file->origin + size; 592 filestart += filestart % 2; 593 } 594 595 return _bfd_get_elt_at_filepos (archive, filestart); 596} 597 598const bfd_target * | 544{ 545 file_ptr filestart; 546 547 if (!last_file) 548 filestart = bfd_ardata (archive)->first_file_filepos; 549 else 550 { 551 unsigned int size = arelt_size (last_file); 552 /* Pad to an even boundary... 553 Note that last_file->origin can be odd in the case of 554 BSD-4.4-style element with a long odd size. */ 555 filestart = last_file->origin + size; 556 filestart += filestart % 2; 557 } 558 559 return _bfd_get_elt_at_filepos (archive, filestart); 560} 561 562const bfd_target * |
599bfd_generic_archive_p (abfd) 600 bfd *abfd; | 563bfd_generic_archive_p (bfd *abfd) |
601{ 602 struct artdata *tdata_hold; 603 char armag[SARMAG + 1]; 604 bfd_size_type amt; 605 | 564{ 565 struct artdata *tdata_hold; 566 char armag[SARMAG + 1]; 567 bfd_size_type amt; 568 |
606 if (bfd_bread ((PTR) armag, (bfd_size_type) SARMAG, abfd) != SARMAG) | 569 if (bfd_bread (armag, SARMAG, abfd) != SARMAG) |
607 { 608 if (bfd_get_error () != bfd_error_system_call) 609 bfd_set_error (bfd_error_wrong_format); 610 return NULL; 611 } 612 613#ifdef GNU960 614 if (strncmp (armag, BFD_GNU960_ARMAG (abfd), SARMAG) != 0) 615 return 0; 616#else 617 if (strncmp (armag, ARMAG, SARMAG) != 0 && 618 strncmp (armag, ARMAGB, SARMAG) != 0) 619 return 0; 620#endif 621 622 tdata_hold = bfd_ardata (abfd); 623 624 amt = sizeof (struct artdata); | 570 { 571 if (bfd_get_error () != bfd_error_system_call) 572 bfd_set_error (bfd_error_wrong_format); 573 return NULL; 574 } 575 576#ifdef GNU960 577 if (strncmp (armag, BFD_GNU960_ARMAG (abfd), SARMAG) != 0) 578 return 0; 579#else 580 if (strncmp (armag, ARMAG, SARMAG) != 0 && 581 strncmp (armag, ARMAGB, SARMAG) != 0) 582 return 0; 583#endif 584 585 tdata_hold = bfd_ardata (abfd); 586 587 amt = sizeof (struct artdata); |
625 bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt); | 588 bfd_ardata (abfd) = bfd_zalloc (abfd, amt); |
626 if (bfd_ardata (abfd) == NULL) 627 { 628 bfd_ardata (abfd) = tdata_hold; 629 return NULL; 630 } 631 632 bfd_ardata (abfd)->first_file_filepos = SARMAG; 633 bfd_ardata (abfd)->cache = NULL; --- 22 unchanged lines hidden (view full) --- 656 target. If not, assume that this is the wrong format. If 657 the first file is not an object file, somebody is doing 658 something weird, and we permit it so that ar -t will work. 659 660 This is done because any normal format will recognize any 661 normal archive, regardless of the format of the object files. 662 We do accept an empty archive. */ 663 | 589 if (bfd_ardata (abfd) == NULL) 590 { 591 bfd_ardata (abfd) = tdata_hold; 592 return NULL; 593 } 594 595 bfd_ardata (abfd)->first_file_filepos = SARMAG; 596 bfd_ardata (abfd)->cache = NULL; --- 22 unchanged lines hidden (view full) --- 619 target. If not, assume that this is the wrong format. If 620 the first file is not an object file, somebody is doing 621 something weird, and we permit it so that ar -t will work. 622 623 This is done because any normal format will recognize any 624 normal archive, regardless of the format of the object files. 625 We do accept an empty archive. */ 626 |
664 first = bfd_openr_next_archived_file (abfd, (bfd *) NULL); | 627 first = bfd_openr_next_archived_file (abfd, NULL); |
665 if (first != NULL) 666 { | 628 if (first != NULL) 629 { |
667 boolean fail; | 630 bfd_boolean fail; |
668 | 631 |
669 first->target_defaulted = false; 670 fail = false; | 632 first->target_defaulted = FALSE; 633 fail = FALSE; |
671 if (bfd_check_format (first, bfd_object) 672 && first->xvec != abfd->xvec) 673 { 674#if 0 675 /* We ought to close `first' here, but we can't, because 676 we have no way to remove it from the archive cache. 677 It's close to impossible to figure out when we can 678 release bfd_ardata. FIXME. */ | 634 if (bfd_check_format (first, bfd_object) 635 && first->xvec != abfd->xvec) 636 { 637#if 0 638 /* We ought to close `first' here, but we can't, because 639 we have no way to remove it from the archive cache. 640 It's close to impossible to figure out when we can 641 release bfd_ardata. FIXME. */ |
679 (void) bfd_close (first); | 642 bfd_close (first); |
680 bfd_release (abfd, bfd_ardata (abfd)); 681#endif 682 bfd_set_error (bfd_error_wrong_object_format); 683 bfd_ardata (abfd) = tdata_hold; 684 return NULL; 685 } 686 /* And we ought to close `first' here too. */ 687 } --- 14 unchanged lines hidden (view full) --- 702#define BSD_SYMDEF_OFFSET_SIZE 4 703 704/* The size of the symdef count. */ 705#define BSD_SYMDEF_COUNT_SIZE 4 706 707/* The size of the string count. */ 708#define BSD_STRING_COUNT_SIZE 4 709 | 643 bfd_release (abfd, bfd_ardata (abfd)); 644#endif 645 bfd_set_error (bfd_error_wrong_object_format); 646 bfd_ardata (abfd) = tdata_hold; 647 return NULL; 648 } 649 /* And we ought to close `first' here too. */ 650 } --- 14 unchanged lines hidden (view full) --- 665#define BSD_SYMDEF_OFFSET_SIZE 4 666 667/* The size of the symdef count. */ 668#define BSD_SYMDEF_COUNT_SIZE 4 669 670/* The size of the string count. */ 671#define BSD_STRING_COUNT_SIZE 4 672 |
710/* Returns false on error, true otherwise */ | 673/* Returns FALSE on error, TRUE otherwise */ |
711 | 674 |
712static boolean 713do_slurp_bsd_armap (abfd) 714 bfd *abfd; | 675static bfd_boolean 676do_slurp_bsd_armap (bfd *abfd) |
715{ 716 struct areltdata *mapdata; 717 unsigned int counter; 718 bfd_byte *raw_armap, *rbase; 719 struct artdata *ardata = bfd_ardata (abfd); 720 char *stringbase; 721 bfd_size_type parsed_size, amt; 722 carsym *set; 723 | 677{ 678 struct areltdata *mapdata; 679 unsigned int counter; 680 bfd_byte *raw_armap, *rbase; 681 struct artdata *ardata = bfd_ardata (abfd); 682 char *stringbase; 683 bfd_size_type parsed_size, amt; 684 carsym *set; 685 |
724 mapdata = (struct areltdata *) _bfd_read_ar_hdr (abfd); | 686 mapdata = _bfd_read_ar_hdr (abfd); |
725 if (mapdata == NULL) | 687 if (mapdata == NULL) |
726 return false; | 688 return FALSE; |
727 parsed_size = mapdata->parsed_size; | 689 parsed_size = mapdata->parsed_size; |
728 bfd_release (abfd, (PTR) mapdata); /* Don't need it any more. */ | 690 bfd_release (abfd, mapdata); /* Don't need it any more. */ |
729 | 691 |
730 raw_armap = (bfd_byte *) bfd_zalloc (abfd, parsed_size); 731 if (raw_armap == (bfd_byte *) NULL) 732 return false; | 692 raw_armap = bfd_zalloc (abfd, parsed_size); 693 if (raw_armap == NULL) 694 return FALSE; |
733 | 695 |
734 if (bfd_bread ((PTR) raw_armap, parsed_size, abfd) != parsed_size) | 696 if (bfd_bread (raw_armap, parsed_size, abfd) != parsed_size) |
735 { 736 if (bfd_get_error () != bfd_error_system_call) 737 bfd_set_error (bfd_error_malformed_archive); 738 byebye: | 697 { 698 if (bfd_get_error () != bfd_error_system_call) 699 bfd_set_error (bfd_error_malformed_archive); 700 byebye: |
739 bfd_release (abfd, (PTR) raw_armap); 740 return false; | 701 bfd_release (abfd, raw_armap); 702 return FALSE; |
741 } 742 743 ardata->symdef_count = H_GET_32 (abfd, raw_armap) / BSD_SYMDEF_SIZE; 744 745 if (ardata->symdef_count * BSD_SYMDEF_SIZE > 746 parsed_size - BSD_SYMDEF_COUNT_SIZE) 747 { 748 /* Probably we're using the wrong byte ordering. */ 749 bfd_set_error (bfd_error_wrong_format); 750 goto byebye; 751 } 752 753 ardata->cache = 0; 754 rbase = raw_armap + BSD_SYMDEF_COUNT_SIZE; 755 stringbase = ((char *) rbase 756 + ardata->symdef_count * BSD_SYMDEF_SIZE 757 + BSD_STRING_COUNT_SIZE); | 703 } 704 705 ardata->symdef_count = H_GET_32 (abfd, raw_armap) / BSD_SYMDEF_SIZE; 706 707 if (ardata->symdef_count * BSD_SYMDEF_SIZE > 708 parsed_size - BSD_SYMDEF_COUNT_SIZE) 709 { 710 /* Probably we're using the wrong byte ordering. */ 711 bfd_set_error (bfd_error_wrong_format); 712 goto byebye; 713 } 714 715 ardata->cache = 0; 716 rbase = raw_armap + BSD_SYMDEF_COUNT_SIZE; 717 stringbase = ((char *) rbase 718 + ardata->symdef_count * BSD_SYMDEF_SIZE 719 + BSD_STRING_COUNT_SIZE); |
758 amt = (bfd_size_type) ardata->symdef_count * sizeof (carsym); 759 ardata->symdefs = (carsym *) bfd_alloc (abfd, amt); | 720 amt = ardata->symdef_count * sizeof (carsym); 721 ardata->symdefs = bfd_alloc (abfd, amt); |
760 if (!ardata->symdefs) | 722 if (!ardata->symdefs) |
761 return false; | 723 return FALSE; |
762 763 for (counter = 0, set = ardata->symdefs; 764 counter < ardata->symdef_count; 765 counter++, set++, rbase += BSD_SYMDEF_SIZE) 766 { 767 set->name = H_GET_32 (abfd, rbase) + stringbase; 768 set->file_offset = H_GET_32 (abfd, rbase + BSD_SYMDEF_OFFSET_SIZE); 769 } 770 771 ardata->first_file_filepos = bfd_tell (abfd); 772 /* Pad to an even boundary if you have to. */ 773 ardata->first_file_filepos += (ardata->first_file_filepos) % 2; 774 /* FIXME, we should provide some way to free raw_ardata when 775 we are done using the strings from it. For now, it seems 776 to be allocated on an objalloc anyway... */ | 724 725 for (counter = 0, set = ardata->symdefs; 726 counter < ardata->symdef_count; 727 counter++, set++, rbase += BSD_SYMDEF_SIZE) 728 { 729 set->name = H_GET_32 (abfd, rbase) + stringbase; 730 set->file_offset = H_GET_32 (abfd, rbase + BSD_SYMDEF_OFFSET_SIZE); 731 } 732 733 ardata->first_file_filepos = bfd_tell (abfd); 734 /* Pad to an even boundary if you have to. */ 735 ardata->first_file_filepos += (ardata->first_file_filepos) % 2; 736 /* FIXME, we should provide some way to free raw_ardata when 737 we are done using the strings from it. For now, it seems 738 to be allocated on an objalloc anyway... */ |
777 bfd_has_map (abfd) = true; 778 return true; | 739 bfd_has_map (abfd) = TRUE; 740 return TRUE; |
779} 780 | 741} 742 |
781/* Returns false on error, true otherwise. */ | 743/* Returns FALSE on error, TRUE otherwise. */ |
782 | 744 |
783static boolean 784do_slurp_coff_armap (abfd) 785 bfd *abfd; | 745static bfd_boolean 746do_slurp_coff_armap (bfd *abfd) |
786{ 787 struct areltdata *mapdata; 788 int *raw_armap, *rawptr; 789 struct artdata *ardata = bfd_ardata (abfd); 790 char *stringbase; 791 bfd_size_type stringsize; 792 unsigned int parsed_size; 793 carsym *carsyms; 794 bfd_size_type nsymz; /* Number of symbols in armap. */ | 747{ 748 struct areltdata *mapdata; 749 int *raw_armap, *rawptr; 750 struct artdata *ardata = bfd_ardata (abfd); 751 char *stringbase; 752 bfd_size_type stringsize; 753 unsigned int parsed_size; 754 carsym *carsyms; 755 bfd_size_type nsymz; /* Number of symbols in armap. */ |
795 bfd_vma (*swap) PARAMS ((const bfd_byte *)); | 756 bfd_vma (*swap) (const void *); |
796 char int_buf[sizeof (long)]; 797 bfd_size_type carsym_size, ptrsize; 798 unsigned int i; 799 | 757 char int_buf[sizeof (long)]; 758 bfd_size_type carsym_size, ptrsize; 759 unsigned int i; 760 |
800 mapdata = (struct areltdata *) _bfd_read_ar_hdr (abfd); | 761 mapdata = _bfd_read_ar_hdr (abfd); |
801 if (mapdata == NULL) | 762 if (mapdata == NULL) |
802 return false; | 763 return FALSE; |
803 parsed_size = mapdata->parsed_size; | 764 parsed_size = mapdata->parsed_size; |
804 bfd_release (abfd, (PTR) mapdata); /* Don't need it any more. */ | 765 bfd_release (abfd, mapdata); /* Don't need it any more. */ |
805 | 766 |
806 if (bfd_bread ((PTR) int_buf, (bfd_size_type) 4, abfd) != 4) | 767 if (bfd_bread (int_buf, 4, abfd) != 4) |
807 { 808 if (bfd_get_error () != bfd_error_system_call) 809 bfd_set_error (bfd_error_malformed_archive); | 768 { 769 if (bfd_get_error () != bfd_error_system_call) 770 bfd_set_error (bfd_error_malformed_archive); |
810 return false; | 771 return FALSE; |
811 } 812 /* It seems that all numeric information in a coff archive is always 813 in big endian format, nomatter the host or target. */ 814 swap = bfd_getb32; | 772 } 773 /* It seems that all numeric information in a coff archive is always 774 in big endian format, nomatter the host or target. */ 775 swap = bfd_getb32; |
815 nsymz = bfd_getb32 ((PTR) int_buf); | 776 nsymz = bfd_getb32 (int_buf); |
816 stringsize = parsed_size - (4 * nsymz) - 4; 817 818#if 1 819 /* ... except that some archive formats are broken, and it may be our 820 fault - the i960 little endian coff sometimes has big and sometimes 821 little, because our tools changed. Here's a horrible hack to clean 822 up the crap. */ 823 824 if (stringsize > 0xfffff 825 && bfd_get_arch (abfd) == bfd_arch_i960 826 && bfd_get_flavour (abfd) == bfd_target_coff_flavour) 827 { 828 /* This looks dangerous, let's do it the other way around. */ | 777 stringsize = parsed_size - (4 * nsymz) - 4; 778 779#if 1 780 /* ... except that some archive formats are broken, and it may be our 781 fault - the i960 little endian coff sometimes has big and sometimes 782 little, because our tools changed. Here's a horrible hack to clean 783 up the crap. */ 784 785 if (stringsize > 0xfffff 786 && bfd_get_arch (abfd) == bfd_arch_i960 787 && bfd_get_flavour (abfd) == bfd_target_coff_flavour) 788 { 789 /* This looks dangerous, let's do it the other way around. */ |
829 nsymz = bfd_getl32 ((PTR) int_buf); | 790 nsymz = bfd_getl32 (int_buf); |
830 stringsize = parsed_size - (4 * nsymz) - 4; 831 swap = bfd_getl32; 832 } 833#endif 834 835 /* The coff armap must be read sequentially. So we construct a 836 bsd-style one in core all at once, for simplicity. */ 837 838 carsym_size = (nsymz * sizeof (carsym)); 839 ptrsize = (4 * nsymz); 840 | 791 stringsize = parsed_size - (4 * nsymz) - 4; 792 swap = bfd_getl32; 793 } 794#endif 795 796 /* The coff armap must be read sequentially. So we construct a 797 bsd-style one in core all at once, for simplicity. */ 798 799 carsym_size = (nsymz * sizeof (carsym)); 800 ptrsize = (4 * nsymz); 801 |
841 ardata->symdefs = (carsym *) bfd_zalloc (abfd, carsym_size + stringsize + 1); | 802 ardata->symdefs = bfd_zalloc (abfd, carsym_size + stringsize + 1); |
842 if (ardata->symdefs == NULL) | 803 if (ardata->symdefs == NULL) |
843 return false; | 804 return FALSE; |
844 carsyms = ardata->symdefs; 845 stringbase = ((char *) ardata->symdefs) + carsym_size; 846 847 /* Allocate and read in the raw offsets. */ | 805 carsyms = ardata->symdefs; 806 stringbase = ((char *) ardata->symdefs) + carsym_size; 807 808 /* Allocate and read in the raw offsets. */ |
848 raw_armap = (int *) bfd_alloc (abfd, ptrsize); | 809 raw_armap = bfd_alloc (abfd, ptrsize); |
849 if (raw_armap == NULL) 850 goto release_symdefs; | 810 if (raw_armap == NULL) 811 goto release_symdefs; |
851 if (bfd_bread ((PTR) raw_armap, ptrsize, abfd) != ptrsize 852 || (bfd_bread ((PTR) stringbase, stringsize, abfd) != stringsize)) | 812 if (bfd_bread (raw_armap, ptrsize, abfd) != ptrsize 813 || (bfd_bread (stringbase, stringsize, abfd) != stringsize)) |
853 { 854 if (bfd_get_error () != bfd_error_system_call) 855 bfd_set_error (bfd_error_malformed_archive); 856 goto release_raw_armap; 857 } 858 859 /* OK, build the carsyms. */ 860 for (i = 0; i < nsymz; i++) 861 { 862 rawptr = raw_armap + i; | 814 { 815 if (bfd_get_error () != bfd_error_system_call) 816 bfd_set_error (bfd_error_malformed_archive); 817 goto release_raw_armap; 818 } 819 820 /* OK, build the carsyms. */ 821 for (i = 0; i < nsymz; i++) 822 { 823 rawptr = raw_armap + i; |
863 carsyms->file_offset = swap ((PTR) rawptr); | 824 carsyms->file_offset = swap ((bfd_byte *) rawptr); |
864 carsyms->name = stringbase; 865 stringbase += strlen (stringbase) + 1; 866 carsyms++; 867 } 868 *stringbase = 0; 869 870 ardata->symdef_count = nsymz; 871 ardata->first_file_filepos = bfd_tell (abfd); 872 /* Pad to an even boundary if you have to. */ 873 ardata->first_file_filepos += (ardata->first_file_filepos) % 2; 874 | 825 carsyms->name = stringbase; 826 stringbase += strlen (stringbase) + 1; 827 carsyms++; 828 } 829 *stringbase = 0; 830 831 ardata->symdef_count = nsymz; 832 ardata->first_file_filepos = bfd_tell (abfd); 833 /* Pad to an even boundary if you have to. */ 834 ardata->first_file_filepos += (ardata->first_file_filepos) % 2; 835 |
875 bfd_has_map (abfd) = true; 876 bfd_release (abfd, (PTR) raw_armap); | 836 bfd_has_map (abfd) = TRUE; 837 bfd_release (abfd, raw_armap); |
877 878 /* Check for a second archive header (as used by PE). */ 879 { 880 struct areltdata *tmp; 881 882 bfd_seek (abfd, ardata->first_file_filepos, SEEK_SET); | 838 839 /* Check for a second archive header (as used by PE). */ 840 { 841 struct areltdata *tmp; 842 843 bfd_seek (abfd, ardata->first_file_filepos, SEEK_SET); |
883 tmp = (struct areltdata *) _bfd_read_ar_hdr (abfd); | 844 tmp = _bfd_read_ar_hdr (abfd); |
884 if (tmp != NULL) 885 { 886 if (tmp->arch_header[0] == '/' 887 && tmp->arch_header[1] == ' ') 888 { 889 ardata->first_file_filepos += 890 (tmp->parsed_size + sizeof (struct ar_hdr) + 1) & ~(unsigned) 1; 891 } 892 bfd_release (abfd, tmp); 893 } 894 } 895 | 845 if (tmp != NULL) 846 { 847 if (tmp->arch_header[0] == '/' 848 && tmp->arch_header[1] == ' ') 849 { 850 ardata->first_file_filepos += 851 (tmp->parsed_size + sizeof (struct ar_hdr) + 1) & ~(unsigned) 1; 852 } 853 bfd_release (abfd, tmp); 854 } 855 } 856 |
896 return true; | 857 return TRUE; |
897 898release_raw_armap: | 858 859release_raw_armap: |
899 bfd_release (abfd, (PTR) raw_armap); | 860 bfd_release (abfd, raw_armap); |
900release_symdefs: | 861release_symdefs: |
901 bfd_release (abfd, (PTR) (ardata)->symdefs); 902 return false; | 862 bfd_release (abfd, (ardata)->symdefs); 863 return FALSE; |
903} 904 905/* This routine can handle either coff-style or bsd-style armaps. | 864} 865 866/* This routine can handle either coff-style or bsd-style armaps. |
906 Returns false on error, true otherwise */ | 867 Returns FALSE on error, TRUE otherwise */ |
907 | 868 |
908boolean 909bfd_slurp_armap (abfd) 910 bfd *abfd; | 869bfd_boolean 870bfd_slurp_armap (bfd *abfd) |
911{ 912 char nextname[17]; | 871{ 872 char nextname[17]; |
913 int i = bfd_bread ((PTR) nextname, (bfd_size_type) 16, abfd); | 873 int i = bfd_bread (nextname, 16, abfd); |
914 915 if (i == 0) | 874 875 if (i == 0) |
916 return true; | 876 return TRUE; |
917 if (i != 16) | 877 if (i != 16) |
918 return false; | 878 return FALSE; |
919 920 if (bfd_seek (abfd, (file_ptr) -16, SEEK_CUR) != 0) | 879 880 if (bfd_seek (abfd, (file_ptr) -16, SEEK_CUR) != 0) |
921 return false; | 881 return FALSE; |
922 923 if (!strncmp (nextname, "__.SYMDEF ", 16) 924 || !strncmp (nextname, "__.SYMDEF/ ", 16)) /* old Linux archives */ 925 return do_slurp_bsd_armap (abfd); 926 else if (!strncmp (nextname, "/ ", 16)) 927 return do_slurp_coff_armap (abfd); 928 else if (!strncmp (nextname, "/SYM64/ ", 16)) 929 { 930 /* 64bit ELF (Irix 6) archive. */ 931#ifdef BFD64 | 882 883 if (!strncmp (nextname, "__.SYMDEF ", 16) 884 || !strncmp (nextname, "__.SYMDEF/ ", 16)) /* old Linux archives */ 885 return do_slurp_bsd_armap (abfd); 886 else if (!strncmp (nextname, "/ ", 16)) 887 return do_slurp_coff_armap (abfd); 888 else if (!strncmp (nextname, "/SYM64/ ", 16)) 889 { 890 /* 64bit ELF (Irix 6) archive. */ 891#ifdef BFD64 |
892 extern bfd_boolean bfd_elf64_archive_slurp_armap (bfd *); |
|
932 return bfd_elf64_archive_slurp_armap (abfd); 933#else 934 bfd_set_error (bfd_error_wrong_format); | 893 return bfd_elf64_archive_slurp_armap (abfd); 894#else 895 bfd_set_error (bfd_error_wrong_format); |
935 return false; | 896 return FALSE; |
936#endif 937 } 938 | 897#endif 898 } 899 |
939 bfd_has_map (abfd) = false; 940 return true; | 900 bfd_has_map (abfd) = FALSE; 901 return TRUE; |
941} 942 | 902} 903 |
943/* Returns false on error, true otherwise */ | 904/* Returns FALSE on error, TRUE otherwise */ |
944/* flavor 2 of a bsd armap, similar to bfd_slurp_bsd_armap except the 945 header is in a slightly different order and the map name is '/'. 946 This flavour is used by hp300hpux. */ 947 948#define HPUX_SYMDEF_COUNT_SIZE 2 949 | 905/* flavor 2 of a bsd armap, similar to bfd_slurp_bsd_armap except the 906 header is in a slightly different order and the map name is '/'. 907 This flavour is used by hp300hpux. */ 908 909#define HPUX_SYMDEF_COUNT_SIZE 2 910 |
950boolean 951bfd_slurp_bsd_armap_f2 (abfd) 952 bfd *abfd; | 911bfd_boolean 912bfd_slurp_bsd_armap_f2 (bfd *abfd) |
953{ 954 struct areltdata *mapdata; 955 char nextname[17]; 956 unsigned int counter; 957 bfd_byte *raw_armap, *rbase; 958 struct artdata *ardata = bfd_ardata (abfd); 959 char *stringbase; 960 unsigned int stringsize; 961 bfd_size_type amt; 962 carsym *set; | 913{ 914 struct areltdata *mapdata; 915 char nextname[17]; 916 unsigned int counter; 917 bfd_byte *raw_armap, *rbase; 918 struct artdata *ardata = bfd_ardata (abfd); 919 char *stringbase; 920 unsigned int stringsize; 921 bfd_size_type amt; 922 carsym *set; |
963 int i = bfd_bread ((PTR) nextname, (bfd_size_type) 16, abfd); | 923 int i = bfd_bread (nextname, 16, abfd); |
964 965 if (i == 0) | 924 925 if (i == 0) |
966 return true; | 926 return TRUE; |
967 if (i != 16) | 927 if (i != 16) |
968 return false; | 928 return FALSE; |
969 970 /* The archive has at least 16 bytes in it. */ 971 if (bfd_seek (abfd, (file_ptr) -16, SEEK_CUR) != 0) | 929 930 /* The archive has at least 16 bytes in it. */ 931 if (bfd_seek (abfd, (file_ptr) -16, SEEK_CUR) != 0) |
972 return false; | 932 return FALSE; |
973 974 if (!strncmp (nextname, "__.SYMDEF ", 16) 975 || !strncmp (nextname, "__.SYMDEF/ ", 16)) /* old Linux archives */ 976 return do_slurp_bsd_armap (abfd); 977 978 if (strncmp (nextname, "/ ", 16)) 979 { | 933 934 if (!strncmp (nextname, "__.SYMDEF ", 16) 935 || !strncmp (nextname, "__.SYMDEF/ ", 16)) /* old Linux archives */ 936 return do_slurp_bsd_armap (abfd); 937 938 if (strncmp (nextname, "/ ", 16)) 939 { |
980 bfd_has_map (abfd) = false; 981 return true; | 940 bfd_has_map (abfd) = FALSE; 941 return TRUE; |
982 } 983 | 942 } 943 |
984 mapdata = (struct areltdata *) _bfd_read_ar_hdr (abfd); | 944 mapdata = _bfd_read_ar_hdr (abfd); |
985 if (mapdata == NULL) | 945 if (mapdata == NULL) |
986 return false; | 946 return FALSE; |
987 988 amt = mapdata->parsed_size; | 947 948 amt = mapdata->parsed_size; |
989 raw_armap = (bfd_byte *) bfd_zalloc (abfd, amt); | 949 raw_armap = bfd_zalloc (abfd, amt); |
990 if (raw_armap == NULL) 991 { 992 byebye: | 950 if (raw_armap == NULL) 951 { 952 byebye: |
993 bfd_release (abfd, (PTR) mapdata); 994 return false; | 953 bfd_release (abfd, mapdata); 954 return FALSE; |
995 } 996 | 955 } 956 |
997 if (bfd_bread ((PTR) raw_armap, amt, abfd) != amt) | 957 if (bfd_bread (raw_armap, amt, abfd) != amt) |
998 { 999 if (bfd_get_error () != bfd_error_system_call) 1000 bfd_set_error (bfd_error_malformed_archive); 1001 byebyebye: | 958 { 959 if (bfd_get_error () != bfd_error_system_call) 960 bfd_set_error (bfd_error_malformed_archive); 961 byebyebye: |
1002 bfd_release (abfd, (PTR) raw_armap); | 962 bfd_release (abfd, raw_armap); |
1003 goto byebye; 1004 } 1005 | 963 goto byebye; 964 } 965 |
1006 ardata->symdef_count = H_GET_16 (abfd, (PTR) raw_armap); | 966 ardata->symdef_count = H_GET_16 (abfd, raw_armap); |
1007 1008 if (ardata->symdef_count * BSD_SYMDEF_SIZE 1009 > mapdata->parsed_size - HPUX_SYMDEF_COUNT_SIZE) 1010 { 1011 /* Probably we're using the wrong byte ordering. */ 1012 bfd_set_error (bfd_error_wrong_format); 1013 goto byebyebye; 1014 } 1015 1016 ardata->cache = 0; 1017 1018 stringsize = H_GET_32 (abfd, raw_armap + HPUX_SYMDEF_COUNT_SIZE); 1019 /* Skip sym count and string sz. */ 1020 stringbase = ((char *) raw_armap 1021 + HPUX_SYMDEF_COUNT_SIZE 1022 + BSD_STRING_COUNT_SIZE); 1023 rbase = (bfd_byte *) stringbase + stringsize; | 967 968 if (ardata->symdef_count * BSD_SYMDEF_SIZE 969 > mapdata->parsed_size - HPUX_SYMDEF_COUNT_SIZE) 970 { 971 /* Probably we're using the wrong byte ordering. */ 972 bfd_set_error (bfd_error_wrong_format); 973 goto byebyebye; 974 } 975 976 ardata->cache = 0; 977 978 stringsize = H_GET_32 (abfd, raw_armap + HPUX_SYMDEF_COUNT_SIZE); 979 /* Skip sym count and string sz. */ 980 stringbase = ((char *) raw_armap 981 + HPUX_SYMDEF_COUNT_SIZE 982 + BSD_STRING_COUNT_SIZE); 983 rbase = (bfd_byte *) stringbase + stringsize; |
1024 amt = (bfd_size_type) ardata->symdef_count * BSD_SYMDEF_SIZE; 1025 ardata->symdefs = (carsym *) bfd_alloc (abfd, amt); | 984 amt = ardata->symdef_count * BSD_SYMDEF_SIZE; 985 ardata->symdefs = bfd_alloc (abfd, amt); |
1026 if (!ardata->symdefs) | 986 if (!ardata->symdefs) |
1027 return false; | 987 return FALSE; |
1028 1029 for (counter = 0, set = ardata->symdefs; 1030 counter < ardata->symdef_count; 1031 counter++, set++, rbase += BSD_SYMDEF_SIZE) 1032 { 1033 set->name = H_GET_32 (abfd, rbase) + stringbase; 1034 set->file_offset = H_GET_32 (abfd, rbase + BSD_SYMDEF_OFFSET_SIZE); 1035 } 1036 1037 ardata->first_file_filepos = bfd_tell (abfd); 1038 /* Pad to an even boundary if you have to. */ 1039 ardata->first_file_filepos += (ardata->first_file_filepos) % 2; 1040 /* FIXME, we should provide some way to free raw_ardata when 1041 we are done using the strings from it. For now, it seems 1042 to be allocated on an objalloc anyway... */ | 988 989 for (counter = 0, set = ardata->symdefs; 990 counter < ardata->symdef_count; 991 counter++, set++, rbase += BSD_SYMDEF_SIZE) 992 { 993 set->name = H_GET_32 (abfd, rbase) + stringbase; 994 set->file_offset = H_GET_32 (abfd, rbase + BSD_SYMDEF_OFFSET_SIZE); 995 } 996 997 ardata->first_file_filepos = bfd_tell (abfd); 998 /* Pad to an even boundary if you have to. */ 999 ardata->first_file_filepos += (ardata->first_file_filepos) % 2; 1000 /* FIXME, we should provide some way to free raw_ardata when 1001 we are done using the strings from it. For now, it seems 1002 to be allocated on an objalloc anyway... */ |
1043 bfd_has_map (abfd) = true; 1044 return true; | 1003 bfd_has_map (abfd) = TRUE; 1004 return TRUE; |
1045} 1046 1047/** Extended name table. 1048 1049 Normally archives support only 14-character filenames. 1050 1051 Intel has extended the format: longer names are stored in a special 1052 element (the first in the archive, or second if there is an armap); 1053 the name in the ar_hdr is replaced by <space><index into filename 1054 element>. Index is the P.R. of an int (decimal). Data General have 1055 extended the format by using the prefix // for the special element. */ 1056 | 1005} 1006 1007/** Extended name table. 1008 1009 Normally archives support only 14-character filenames. 1010 1011 Intel has extended the format: longer names are stored in a special 1012 element (the first in the archive, or second if there is an armap); 1013 the name in the ar_hdr is replaced by <space><index into filename 1014 element>. Index is the P.R. of an int (decimal). Data General have 1015 extended the format by using the prefix // for the special element. */ 1016 |
1057/* Returns false on error, true otherwise. */ | 1017/* Returns FALSE on error, TRUE otherwise. */ |
1058 | 1018 |
1059boolean 1060_bfd_slurp_extended_name_table (abfd) 1061 bfd *abfd; | 1019bfd_boolean 1020_bfd_slurp_extended_name_table (bfd *abfd) |
1062{ 1063 char nextname[17]; 1064 struct areltdata *namedata; 1065 bfd_size_type amt; 1066 1067 /* FIXME: Formatting sucks here, and in case of failure of BFD_READ, | 1021{ 1022 char nextname[17]; 1023 struct areltdata *namedata; 1024 bfd_size_type amt; 1025 1026 /* FIXME: Formatting sucks here, and in case of failure of BFD_READ, |
1068 we probably don't want to return true. */ | 1027 we probably don't want to return TRUE. */ |
1069 bfd_seek (abfd, bfd_ardata (abfd)->first_file_filepos, SEEK_SET); | 1028 bfd_seek (abfd, bfd_ardata (abfd)->first_file_filepos, SEEK_SET); |
1070 if (bfd_bread ((PTR) nextname, (bfd_size_type) 16, abfd) == 16) | 1029 if (bfd_bread (nextname, 16, abfd) == 16) |
1071 { 1072 if (bfd_seek (abfd, (file_ptr) -16, SEEK_CUR) != 0) | 1030 { 1031 if (bfd_seek (abfd, (file_ptr) -16, SEEK_CUR) != 0) |
1073 return false; | 1032 return FALSE; |
1074 1075 if (strncmp (nextname, "ARFILENAMES/ ", 16) != 0 && 1076 strncmp (nextname, "// ", 16) != 0) 1077 { 1078 bfd_ardata (abfd)->extended_names = NULL; | 1033 1034 if (strncmp (nextname, "ARFILENAMES/ ", 16) != 0 && 1035 strncmp (nextname, "// ", 16) != 0) 1036 { 1037 bfd_ardata (abfd)->extended_names = NULL; |
1079 return true; | 1038 return TRUE; |
1080 } 1081 | 1039 } 1040 |
1082 namedata = (struct areltdata *) _bfd_read_ar_hdr (abfd); | 1041 namedata = _bfd_read_ar_hdr (abfd); |
1083 if (namedata == NULL) | 1042 if (namedata == NULL) |
1084 return false; | 1043 return FALSE; |
1085 1086 amt = namedata->parsed_size; 1087 bfd_ardata (abfd)->extended_names = bfd_zalloc (abfd, amt); 1088 if (bfd_ardata (abfd)->extended_names == NULL) 1089 { 1090 byebye: | 1044 1045 amt = namedata->parsed_size; 1046 bfd_ardata (abfd)->extended_names = bfd_zalloc (abfd, amt); 1047 if (bfd_ardata (abfd)->extended_names == NULL) 1048 { 1049 byebye: |
1091 bfd_release (abfd, (PTR) namedata); 1092 return false; | 1050 bfd_release (abfd, namedata); 1051 return FALSE; |
1093 } 1094 | 1052 } 1053 |
1095 if (bfd_bread ((PTR) bfd_ardata (abfd)->extended_names, amt, abfd) != amt) | 1054 if (bfd_bread (bfd_ardata (abfd)->extended_names, amt, abfd) != amt) |
1096 { 1097 if (bfd_get_error () != bfd_error_system_call) 1098 bfd_set_error (bfd_error_malformed_archive); | 1055 { 1056 if (bfd_get_error () != bfd_error_system_call) 1057 bfd_set_error (bfd_error_malformed_archive); |
1099 bfd_release (abfd, (PTR) (bfd_ardata (abfd)->extended_names)); | 1058 bfd_release (abfd, (bfd_ardata (abfd)->extended_names)); |
1100 bfd_ardata (abfd)->extended_names = NULL; 1101 goto byebye; 1102 } 1103 1104 /* Since the archive is supposed to be printable if it contains 1105 text, the entries in the list are newline-padded, not null 1106 padded. In SVR4-style archives, the names also have a 1107 trailing '/'. DOS/NT created archive often have \ in them --- 16 unchanged lines hidden (view full) --- 1124 (bfd_ardata (abfd)->first_file_filepos) % 2; 1125 1126 /* FIXME, we can't release namedata here because it was allocated 1127 below extended_names on the objalloc... */ 1128#if 0 1129 bfd_release (abfd, namedata); 1130#endif 1131 } | 1059 bfd_ardata (abfd)->extended_names = NULL; 1060 goto byebye; 1061 } 1062 1063 /* Since the archive is supposed to be printable if it contains 1064 text, the entries in the list are newline-padded, not null 1065 padded. In SVR4-style archives, the names also have a 1066 trailing '/'. DOS/NT created archive often have \ in them --- 16 unchanged lines hidden (view full) --- 1083 (bfd_ardata (abfd)->first_file_filepos) % 2; 1084 1085 /* FIXME, we can't release namedata here because it was allocated 1086 below extended_names on the objalloc... */ 1087#if 0 1088 bfd_release (abfd, namedata); 1089#endif 1090 } |
1132 return true; | 1091 return TRUE; |
1133} 1134 1135#ifdef VMS 1136 1137/* Return a copy of the stuff in the filename between any :]> and a 1138 semicolon. */ 1139 1140static const char * | 1092} 1093 1094#ifdef VMS 1095 1096/* Return a copy of the stuff in the filename between any :]> and a 1097 semicolon. */ 1098 1099static const char * |
1141normalize (abfd, file) 1142 bfd *abfd; 1143 const char *file; | 1100normalize (bfd *abfd, const char *file) |
1144{ 1145 const char *first; 1146 const char *last; 1147 char *copy; 1148 1149 first = file + strlen (file) - 1; 1150 last = first + 1; 1151 --- 4 unchanged lines hidden (view full) --- 1156 if (*first == ':' || *first == ']' || *first == '>') 1157 { 1158 first++; 1159 break; 1160 } 1161 first--; 1162 } 1163 | 1101{ 1102 const char *first; 1103 const char *last; 1104 char *copy; 1105 1106 first = file + strlen (file) - 1; 1107 last = first + 1; 1108 --- 4 unchanged lines hidden (view full) --- 1113 if (*first == ':' || *first == ']' || *first == '>') 1114 { 1115 first++; 1116 break; 1117 } 1118 first--; 1119 } 1120 |
1164 copy = (char *) bfd_alloc (abfd, (bfd_size_type) (last - first + 1)); | 1121 copy = bfd_alloc (abfd, last - first + 1); |
1165 if (copy == NULL) 1166 return NULL; 1167 1168 memcpy (copy, first, last - first); 1169 copy[last - first] = 0; 1170 1171 return copy; 1172} 1173 1174#else 1175static const char * | 1122 if (copy == NULL) 1123 return NULL; 1124 1125 memcpy (copy, first, last - first); 1126 copy[last - first] = 0; 1127 1128 return copy; 1129} 1130 1131#else 1132static const char * |
1176normalize (abfd, file) 1177 bfd *abfd ATTRIBUTE_UNUSED; 1178 const char *file; | 1133normalize (bfd *abfd ATTRIBUTE_UNUSED, const char *file) |
1179{ 1180 const char *filename = strrchr (file, '/'); 1181 1182#ifdef HAVE_DOS_BASED_FILE_SYSTEM 1183 { 1184 /* We could have foo/bar\\baz, or foo\\bar, or d:bar. */ 1185 char *bslash = strrchr (file, '\\'); 1186 if (filename == NULL || (bslash != NULL && bslash > filename)) 1187 filename = bslash; 1188 if (filename == NULL && file[0] != '\0' && file[1] == ':') 1189 filename = file + 1; 1190 } 1191#endif | 1134{ 1135 const char *filename = strrchr (file, '/'); 1136 1137#ifdef HAVE_DOS_BASED_FILE_SYSTEM 1138 { 1139 /* We could have foo/bar\\baz, or foo\\bar, or d:bar. */ 1140 char *bslash = strrchr (file, '\\'); 1141 if (filename == NULL || (bslash != NULL && bslash > filename)) 1142 filename = bslash; 1143 if (filename == NULL && file[0] != '\0' && file[1] == ':') 1144 filename = file + 1; 1145 } 1146#endif |
1192 if (filename != (char *) NULL) | 1147 if (filename != NULL) |
1193 filename++; 1194 else 1195 filename = file; 1196 return filename; 1197} 1198#endif 1199 1200/* Build a BFD style extended name table. */ 1201 | 1148 filename++; 1149 else 1150 filename = file; 1151 return filename; 1152} 1153#endif 1154 1155/* Build a BFD style extended name table. */ 1156 |
1202boolean 1203_bfd_archive_bsd_construct_extended_name_table (abfd, tabloc, tablen, name) 1204 bfd *abfd; 1205 char **tabloc; 1206 bfd_size_type *tablen; 1207 const char **name; | 1157bfd_boolean 1158_bfd_archive_bsd_construct_extended_name_table (bfd *abfd, 1159 char **tabloc, 1160 bfd_size_type *tablen, 1161 const char **name) |
1208{ 1209 *name = "ARFILENAMES/"; | 1162{ 1163 *name = "ARFILENAMES/"; |
1210 return _bfd_construct_extended_name_table (abfd, false, tabloc, tablen); | 1164 return _bfd_construct_extended_name_table (abfd, FALSE, tabloc, tablen); |
1211} 1212 1213/* Build an SVR4 style extended name table. */ 1214 | 1165} 1166 1167/* Build an SVR4 style extended name table. */ 1168 |
1215boolean 1216_bfd_archive_coff_construct_extended_name_table (abfd, tabloc, tablen, name) 1217 bfd *abfd; 1218 char **tabloc; 1219 bfd_size_type *tablen; 1220 const char **name; | 1169bfd_boolean 1170_bfd_archive_coff_construct_extended_name_table (bfd *abfd, 1171 char **tabloc, 1172 bfd_size_type *tablen, 1173 const char **name) |
1221{ 1222 *name = "//"; | 1174{ 1175 *name = "//"; |
1223 return _bfd_construct_extended_name_table (abfd, true, tabloc, tablen); | 1176 return _bfd_construct_extended_name_table (abfd, TRUE, tabloc, tablen); |
1224} 1225 1226/* Follows archive_head and produces an extended name table if 1227 necessary. Returns (in tabloc) a pointer to an extended name 1228 table, and in tablen the length of the table. If it makes an entry 1229 it clobbers the filename so that the element may be written without | 1177} 1178 1179/* Follows archive_head and produces an extended name table if 1180 necessary. Returns (in tabloc) a pointer to an extended name 1181 table, and in tablen the length of the table. If it makes an entry 1182 it clobbers the filename so that the element may be written without |
1230 further massage. Returns true if it ran successfully, false if | 1183 further massage. Returns TRUE if it ran successfully, FALSE if |
1231 something went wrong. A successful return may still involve a 1232 zero-length tablen! */ 1233 | 1184 something went wrong. A successful return may still involve a 1185 zero-length tablen! */ 1186 |
1234boolean 1235_bfd_construct_extended_name_table (abfd, trailing_slash, tabloc, tablen) 1236 bfd *abfd; 1237 boolean trailing_slash; 1238 char **tabloc; 1239 bfd_size_type *tablen; | 1187bfd_boolean 1188_bfd_construct_extended_name_table (bfd *abfd, 1189 bfd_boolean trailing_slash, 1190 char **tabloc, 1191 bfd_size_type *tablen) |
1240{ 1241 unsigned int maxname = abfd->xvec->ar_max_namelen; 1242 bfd_size_type total_namelen = 0; 1243 bfd *current; 1244 char *strptr; 1245 1246 *tablen = 0; 1247 1248 /* Figure out how long the table should be. */ 1249 for (current = abfd->archive_head; current != NULL; current = current->next) 1250 { 1251 const char *normal; 1252 unsigned int thislen; 1253 1254 normal = normalize (current, current->filename); 1255 if (normal == NULL) | 1192{ 1193 unsigned int maxname = abfd->xvec->ar_max_namelen; 1194 bfd_size_type total_namelen = 0; 1195 bfd *current; 1196 char *strptr; 1197 1198 *tablen = 0; 1199 1200 /* Figure out how long the table should be. */ 1201 for (current = abfd->archive_head; current != NULL; current = current->next) 1202 { 1203 const char *normal; 1204 unsigned int thislen; 1205 1206 normal = normalize (current, current->filename); 1207 if (normal == NULL) |
1256 return false; | 1208 return FALSE; |
1257 1258 thislen = strlen (normal); 1259 1260 if (thislen > maxname 1261 && (bfd_get_file_flags (abfd) & BFD_TRADITIONAL_FORMAT) != 0) 1262 thislen = maxname; 1263 1264 if (thislen > maxname) --- 19 unchanged lines hidden (view full) --- 1284 if (thislen < maxname 1285 || (thislen == maxname && thislen < sizeof hdr->ar_name)) 1286 hdr->ar_name[thislen] = ar_padchar (current); 1287 } 1288 } 1289 } 1290 1291 if (total_namelen == 0) | 1209 1210 thislen = strlen (normal); 1211 1212 if (thislen > maxname 1213 && (bfd_get_file_flags (abfd) & BFD_TRADITIONAL_FORMAT) != 0) 1214 thislen = maxname; 1215 1216 if (thislen > maxname) --- 19 unchanged lines hidden (view full) --- 1236 if (thislen < maxname 1237 || (thislen == maxname && thislen < sizeof hdr->ar_name)) 1238 hdr->ar_name[thislen] = ar_padchar (current); 1239 } 1240 } 1241 } 1242 1243 if (total_namelen == 0) |
1292 return true; | 1244 return TRUE; |
1293 1294 *tabloc = bfd_zalloc (abfd, total_namelen); 1295 if (*tabloc == NULL) | 1245 1246 *tabloc = bfd_zalloc (abfd, total_namelen); 1247 if (*tabloc == NULL) |
1296 return false; | 1248 return FALSE; |
1297 1298 *tablen = total_namelen; 1299 strptr = *tabloc; 1300 1301 for (current = abfd->archive_head; current != NULL; current = 1302 current->next) 1303 { 1304 const char *normal; 1305 unsigned int thislen; 1306 1307 normal = normalize (current, current->filename); 1308 if (normal == NULL) | 1249 1250 *tablen = total_namelen; 1251 strptr = *tabloc; 1252 1253 for (current = abfd->archive_head; current != NULL; current = 1254 current->next) 1255 { 1256 const char *normal; 1257 unsigned int thislen; 1258 1259 normal = normalize (current, current->filename); 1260 if (normal == NULL) |
1309 return false; | 1261 return FALSE; |
1310 1311 thislen = strlen (normal); 1312 if (thislen > maxname) 1313 { 1314 /* Works for now; may need to be re-engineered if we 1315 encounter an oddball archive format and want to 1316 generalise this hack. */ 1317 struct ar_hdr *hdr = arch_hdr (current); --- 18 unchanged lines hidden (view full) --- 1336 *temp = ' '; 1337 } 1338 strptr += thislen + 1; 1339 if (trailing_slash) 1340 ++strptr; 1341 } 1342 } 1343 | 1262 1263 thislen = strlen (normal); 1264 if (thislen > maxname) 1265 { 1266 /* Works for now; may need to be re-engineered if we 1267 encounter an oddball archive format and want to 1268 generalise this hack. */ 1269 struct ar_hdr *hdr = arch_hdr (current); --- 18 unchanged lines hidden (view full) --- 1288 *temp = ' '; 1289 } 1290 strptr += thislen + 1; 1291 if (trailing_slash) 1292 ++strptr; 1293 } 1294 } 1295 |
1344 return true; | 1296 return TRUE; |
1345} 1346 1347/** A couple of functions for creating ar_hdrs */ 1348 1349#ifdef HPUX_LARGE_AR_IDS 1350/* Function to encode large UID/GID values according to HP. */ 1351 1352static void | 1297} 1298 1299/** A couple of functions for creating ar_hdrs */ 1300 1301#ifdef HPUX_LARGE_AR_IDS 1302/* Function to encode large UID/GID values according to HP. */ 1303 1304static void |
1353hpux_uid_gid_encode (str, id) 1354 char str[6]; 1355 long int id; | 1305hpux_uid_gid_encode (char str[6], long int id) |
1356{ 1357 int cnt; 1358 1359 str[5] = '@' + (id & 3); 1360 id >>= 2; 1361 1362 for (cnt = 4; cnt >= 0; ++cnt, id >>= 6) 1363 str[cnt] = ' ' + (id & 0x3f); --- 9 unchanged lines hidden (view full) --- 1373#endif 1374 1375/* Takes a filename, returns an arelt_data for it, or NULL if it can't 1376 make one. The filename must refer to a filename in the filesystem. 1377 The filename field of the ar_hdr will NOT be initialized. If member 1378 is set, and it's an in-memory bfd, we fake it. */ 1379 1380static struct areltdata * | 1306{ 1307 int cnt; 1308 1309 str[5] = '@' + (id & 3); 1310 id >>= 2; 1311 1312 for (cnt = 4; cnt >= 0; ++cnt, id >>= 6) 1313 str[cnt] = ' ' + (id & 0x3f); --- 9 unchanged lines hidden (view full) --- 1323#endif 1324 1325/* Takes a filename, returns an arelt_data for it, or NULL if it can't 1326 make one. The filename must refer to a filename in the filesystem. 1327 The filename field of the ar_hdr will NOT be initialized. If member 1328 is set, and it's an in-memory bfd, we fake it. */ 1329 1330static struct areltdata * |
1381bfd_ar_hdr_from_filesystem (abfd, filename, member) 1382 bfd *abfd; 1383 const char *filename; 1384 bfd *member; | 1331bfd_ar_hdr_from_filesystem (bfd *abfd, const char *filename, bfd *member) |
1385{ 1386 struct stat status; 1387 struct areltdata *ared; 1388 struct ar_hdr *hdr; 1389 char *temp, *temp1; 1390 bfd_size_type amt; 1391 1392 if (member && (member->flags & BFD_IN_MEMORY) != 0) 1393 { 1394 /* Assume we just "made" the member, and fake it. */ | 1332{ 1333 struct stat status; 1334 struct areltdata *ared; 1335 struct ar_hdr *hdr; 1336 char *temp, *temp1; 1337 bfd_size_type amt; 1338 1339 if (member && (member->flags & BFD_IN_MEMORY) != 0) 1340 { 1341 /* Assume we just "made" the member, and fake it. */ |
1395 struct bfd_in_memory *bim = (struct bfd_in_memory *) member->iostream; | 1342 struct bfd_in_memory *bim = member->iostream; |
1396 time (&status.st_mtime); 1397 status.st_uid = getuid (); 1398 status.st_gid = getgid (); 1399 status.st_mode = 0644; 1400 status.st_size = bim->size; 1401 } 1402 else if (stat (filename, &status) != 0) 1403 { 1404 bfd_set_error (bfd_error_system_call); 1405 return NULL; 1406 } 1407 1408 amt = sizeof (struct ar_hdr) + sizeof (struct areltdata); | 1343 time (&status.st_mtime); 1344 status.st_uid = getuid (); 1345 status.st_gid = getgid (); 1346 status.st_mode = 0644; 1347 status.st_size = bim->size; 1348 } 1349 else if (stat (filename, &status) != 0) 1350 { 1351 bfd_set_error (bfd_error_system_call); 1352 return NULL; 1353 } 1354 1355 amt = sizeof (struct ar_hdr) + sizeof (struct areltdata); |
1409 ared = (struct areltdata *) bfd_zalloc (abfd, amt); | 1356 ared = bfd_zalloc (abfd, amt); |
1410 if (ared == NULL) 1411 return NULL; 1412 hdr = (struct ar_hdr *) (((char *) ared) + sizeof (struct areltdata)); 1413 1414 /* ar headers are space padded, not null padded! */ | 1357 if (ared == NULL) 1358 return NULL; 1359 hdr = (struct ar_hdr *) (((char *) ared) + sizeof (struct areltdata)); 1360 1361 /* ar headers are space padded, not null padded! */ |
1415 memset ((PTR) hdr, ' ', sizeof (struct ar_hdr)); | 1362 memset (hdr, ' ', sizeof (struct ar_hdr)); |
1416 1417 strncpy (hdr->ar_fmag, ARFMAG, 2); 1418 1419 /* Goddamned sprintf doesn't permit MAXIMUM field lengths. */ 1420 sprintf ((hdr->ar_date), "%-12ld", (long) status.st_mtime); 1421#ifdef HPUX_LARGE_AR_IDS 1422 /* HP has a very "special" way to handle UID/GID's with numeric values 1423 > 99999. */ --- 29 unchanged lines hidden (view full) --- 1453 return ared; 1454} 1455 1456/* This is magic required by the "ar" program. Since it's 1457 undocumented, it's undocumented. You may think that it would take 1458 a strong stomach to write this, and it does, but it takes even a 1459 stronger stomach to try to code around such a thing! */ 1460 | 1363 1364 strncpy (hdr->ar_fmag, ARFMAG, 2); 1365 1366 /* Goddamned sprintf doesn't permit MAXIMUM field lengths. */ 1367 sprintf ((hdr->ar_date), "%-12ld", (long) status.st_mtime); 1368#ifdef HPUX_LARGE_AR_IDS 1369 /* HP has a very "special" way to handle UID/GID's with numeric values 1370 > 99999. */ --- 29 unchanged lines hidden (view full) --- 1400 return ared; 1401} 1402 1403/* This is magic required by the "ar" program. Since it's 1404 undocumented, it's undocumented. You may think that it would take 1405 a strong stomach to write this, and it does, but it takes even a 1406 stronger stomach to try to code around such a thing! */ 1407 |
1461struct ar_hdr *bfd_special_undocumented_glue PARAMS ((bfd *, const char *)); | 1408struct ar_hdr *bfd_special_undocumented_glue (bfd *, const char *); |
1462 1463struct ar_hdr * | 1409 1410struct ar_hdr * |
1464bfd_special_undocumented_glue (abfd, filename) 1465 bfd *abfd; 1466 const char *filename; | 1411bfd_special_undocumented_glue (bfd *abfd, const char *filename) |
1467{ 1468 struct areltdata *ar_elt = bfd_ar_hdr_from_filesystem (abfd, filename, 0); 1469 if (ar_elt == NULL) 1470 return NULL; 1471 return (struct ar_hdr *) ar_elt->arch_header; 1472} 1473 1474/* Analogous to stat call. */ 1475 1476int | 1412{ 1413 struct areltdata *ar_elt = bfd_ar_hdr_from_filesystem (abfd, filename, 0); 1414 if (ar_elt == NULL) 1415 return NULL; 1416 return (struct ar_hdr *) ar_elt->arch_header; 1417} 1418 1419/* Analogous to stat call. */ 1420 1421int |
1477bfd_generic_stat_arch_elt (abfd, buf) 1478 bfd *abfd; 1479 struct stat *buf; | 1422bfd_generic_stat_arch_elt (bfd *abfd, struct stat *buf) |
1480{ 1481 struct ar_hdr *hdr; 1482 char *aloser; 1483 1484 if (abfd->arelt_data == NULL) 1485 { 1486 bfd_set_error (bfd_error_invalid_operation); 1487 return -1; --- 38 unchanged lines hidden (view full) --- 1526 foo (ar_mode, st_mode, 8); 1527 1528 buf->st_size = arch_eltdata (abfd)->parsed_size; 1529 1530 return 0; 1531} 1532 1533void | 1423{ 1424 struct ar_hdr *hdr; 1425 char *aloser; 1426 1427 if (abfd->arelt_data == NULL) 1428 { 1429 bfd_set_error (bfd_error_invalid_operation); 1430 return -1; --- 38 unchanged lines hidden (view full) --- 1469 foo (ar_mode, st_mode, 8); 1470 1471 buf->st_size = arch_eltdata (abfd)->parsed_size; 1472 1473 return 0; 1474} 1475 1476void |
1534bfd_dont_truncate_arname (abfd, pathname, arhdr) 1535 bfd *abfd; 1536 const char *pathname; 1537 char *arhdr; | 1477bfd_dont_truncate_arname (bfd *abfd, const char *pathname, char *arhdr) |
1538{ 1539 /* FIXME: This interacts unpleasantly with ar's quick-append option. 1540 Fortunately ic960 users will never use that option. Fixing this 1541 is very hard; fortunately I know how to do it and will do so once 1542 intel's release is out the door. */ 1543 1544 struct ar_hdr *hdr = (struct ar_hdr *) arhdr; 1545 size_t length; --- 20 unchanged lines hidden (view full) --- 1566 1567 /* Add the padding character if there is room for it. */ 1568 if (length < maxlen 1569 || (length == maxlen && length < sizeof hdr->ar_name)) 1570 (hdr->ar_name)[length] = ar_padchar (abfd); 1571} 1572 1573void | 1478{ 1479 /* FIXME: This interacts unpleasantly with ar's quick-append option. 1480 Fortunately ic960 users will never use that option. Fixing this 1481 is very hard; fortunately I know how to do it and will do so once 1482 intel's release is out the door. */ 1483 1484 struct ar_hdr *hdr = (struct ar_hdr *) arhdr; 1485 size_t length; --- 20 unchanged lines hidden (view full) --- 1506 1507 /* Add the padding character if there is room for it. */ 1508 if (length < maxlen 1509 || (length == maxlen && length < sizeof hdr->ar_name)) 1510 (hdr->ar_name)[length] = ar_padchar (abfd); 1511} 1512 1513void |
1574bfd_bsd_truncate_arname (abfd, pathname, arhdr) 1575 bfd *abfd; 1576 const char *pathname; 1577 char *arhdr; | 1514bfd_bsd_truncate_arname (bfd *abfd, const char *pathname, char *arhdr) |
1578{ 1579 struct ar_hdr *hdr = (struct ar_hdr *) arhdr; 1580 size_t length; 1581 const char *filename = strrchr (pathname, '/'); 1582 size_t maxlen = ar_maxnamelen (abfd); 1583 1584#ifdef HAVE_DOS_BASED_FILE_SYSTEM 1585 { --- 31 unchanged lines hidden (view full) --- 1617 2> if it's short enuf to fit, stuff it in. 1618 3> If it doesn't end with .o, truncate it to fit 1619 4> truncate it before the .o, append .o, stuff THAT in. */ 1620 1621/* This is what gnu ar does. It's better but incompatible with the 1622 bsd ar. */ 1623 1624void | 1515{ 1516 struct ar_hdr *hdr = (struct ar_hdr *) arhdr; 1517 size_t length; 1518 const char *filename = strrchr (pathname, '/'); 1519 size_t maxlen = ar_maxnamelen (abfd); 1520 1521#ifdef HAVE_DOS_BASED_FILE_SYSTEM 1522 { --- 31 unchanged lines hidden (view full) --- 1554 2> if it's short enuf to fit, stuff it in. 1555 3> If it doesn't end with .o, truncate it to fit 1556 4> truncate it before the .o, append .o, stuff THAT in. */ 1557 1558/* This is what gnu ar does. It's better but incompatible with the 1559 bsd ar. */ 1560 1561void |
1625bfd_gnu_truncate_arname (abfd, pathname, arhdr) 1626 bfd *abfd; 1627 const char *pathname; 1628 char *arhdr; | 1562bfd_gnu_truncate_arname (bfd *abfd, const char *pathname, char *arhdr) |
1629{ 1630 struct ar_hdr *hdr = (struct ar_hdr *) arhdr; 1631 size_t length; 1632 const char *filename = strrchr (pathname, '/'); 1633 size_t maxlen = ar_maxnamelen (abfd); 1634 1635#ifdef HAVE_DOS_BASED_FILE_SYSTEM 1636 { --- 27 unchanged lines hidden (view full) --- 1664 } 1665 1666 if (length < 16) 1667 (hdr->ar_name)[length] = ar_padchar (abfd); 1668} 1669 1670/* The BFD is open for write and has its format set to bfd_archive. */ 1671 | 1563{ 1564 struct ar_hdr *hdr = (struct ar_hdr *) arhdr; 1565 size_t length; 1566 const char *filename = strrchr (pathname, '/'); 1567 size_t maxlen = ar_maxnamelen (abfd); 1568 1569#ifdef HAVE_DOS_BASED_FILE_SYSTEM 1570 { --- 27 unchanged lines hidden (view full) --- 1598 } 1599 1600 if (length < 16) 1601 (hdr->ar_name)[length] = ar_padchar (abfd); 1602} 1603 1604/* The BFD is open for write and has its format set to bfd_archive. */ 1605 |
1672boolean 1673_bfd_write_archive_contents (arch) 1674 bfd *arch; | 1606bfd_boolean 1607_bfd_write_archive_contents (bfd *arch) |
1675{ 1676 bfd *current; 1677 char *etable = NULL; 1678 bfd_size_type elength = 0; 1679 const char *ename = NULL; | 1608{ 1609 bfd *current; 1610 char *etable = NULL; 1611 bfd_size_type elength = 0; 1612 const char *ename = NULL; |
1680 boolean makemap = bfd_has_map (arch); 1681 boolean hasobjects = false; /* If no .o's, don't bother to make a map. */ | 1613 bfd_boolean makemap = bfd_has_map (arch); 1614 /* If no .o's, don't bother to make a map. */ 1615 bfd_boolean hasobjects = FALSE; |
1682 bfd_size_type wrote; 1683 unsigned int i; 1684 int tries; 1685 1686 /* Verify the viability of all entries; if any of them live in the 1687 filesystem (as opposed to living in an archive open for input) 1688 then construct a fresh ar_hdr for them. */ 1689 for (current = arch->archive_head; current; current = current->next) 1690 { 1691 /* This check is checking the bfds for the objects we're reading 1692 from (which are usually either an object file or archive on 1693 disk), not the archive entries we're writing to. We don't 1694 actually create bfds for the archive members, we just copy 1695 them byte-wise when we write out the archive. */ 1696 if (bfd_write_p (current)) 1697 { 1698 bfd_set_error (bfd_error_invalid_operation); | 1616 bfd_size_type wrote; 1617 unsigned int i; 1618 int tries; 1619 1620 /* Verify the viability of all entries; if any of them live in the 1621 filesystem (as opposed to living in an archive open for input) 1622 then construct a fresh ar_hdr for them. */ 1623 for (current = arch->archive_head; current; current = current->next) 1624 { 1625 /* This check is checking the bfds for the objects we're reading 1626 from (which are usually either an object file or archive on 1627 disk), not the archive entries we're writing to. We don't 1628 actually create bfds for the archive members, we just copy 1629 them byte-wise when we write out the archive. */ 1630 if (bfd_write_p (current)) 1631 { 1632 bfd_set_error (bfd_error_invalid_operation); |
1699 return false; | 1633 return FALSE; |
1700 } 1701 if (!current->arelt_data) 1702 { 1703 current->arelt_data = | 1634 } 1635 if (!current->arelt_data) 1636 { 1637 current->arelt_data = |
1704 (PTR) bfd_ar_hdr_from_filesystem (arch, current->filename, current); | 1638 bfd_ar_hdr_from_filesystem (arch, current->filename, current); |
1705 if (!current->arelt_data) | 1639 if (!current->arelt_data) |
1706 return false; | 1640 return FALSE; |
1707 1708 /* Put in the file name. */ | 1641 1642 /* Put in the file name. */ |
1709 BFD_SEND (arch, _bfd_truncate_arname, (arch, 1710 current->filename, 1711 (char *) arch_hdr (current))); | 1643 BFD_SEND (arch, _bfd_truncate_arname, 1644 (arch, current->filename, (char *) arch_hdr (current))); |
1712 } 1713 1714 if (makemap && ! hasobjects) 1715 { /* Don't bother if we won't make a map! */ 1716 if ((bfd_check_format (current, bfd_object)) 1717#if 0 /* FIXME -- these are not set correctly */ 1718 && ((bfd_get_file_flags (current) & HAS_SYMS)) 1719#endif 1720 ) | 1645 } 1646 1647 if (makemap && ! hasobjects) 1648 { /* Don't bother if we won't make a map! */ 1649 if ((bfd_check_format (current, bfd_object)) 1650#if 0 /* FIXME -- these are not set correctly */ 1651 && ((bfd_get_file_flags (current) & HAS_SYMS)) 1652#endif 1653 ) |
1721 hasobjects = true; | 1654 hasobjects = TRUE; |
1722 } 1723 } 1724 1725 if (!BFD_SEND (arch, _bfd_construct_extended_name_table, 1726 (arch, &etable, &elength, &ename))) | 1655 } 1656 } 1657 1658 if (!BFD_SEND (arch, _bfd_construct_extended_name_table, 1659 (arch, &etable, &elength, &ename))) |
1727 return false; | 1660 return FALSE; |
1728 1729 if (bfd_seek (arch, (file_ptr) 0, SEEK_SET) != 0) | 1661 1662 if (bfd_seek (arch, (file_ptr) 0, SEEK_SET) != 0) |
1730 return false; | 1663 return FALSE; |
1731#ifdef GNU960 | 1664#ifdef GNU960 |
1732 wrote = bfd_bwrite (BFD_GNU960_ARMAG (arch), (bfd_size_type) SARMAG, arch); | 1665 wrote = bfd_bwrite (BFD_GNU960_ARMAG (arch), SARMAG, arch); |
1733#else | 1666#else |
1734 wrote = bfd_bwrite (ARMAG, (bfd_size_type) SARMAG, arch); | 1667 wrote = bfd_bwrite (ARMAG, SARMAG, arch); |
1735#endif 1736 if (wrote != SARMAG) | 1668#endif 1669 if (wrote != SARMAG) |
1737 return false; | 1670 return FALSE; |
1738 1739 if (makemap && hasobjects) 1740 { 1741 if (! _bfd_compute_and_write_armap (arch, (unsigned int) elength)) | 1671 1672 if (makemap && hasobjects) 1673 { 1674 if (! _bfd_compute_and_write_armap (arch, (unsigned int) elength)) |
1742 return false; | 1675 return FALSE; |
1743 } 1744 1745 if (elength != 0) 1746 { 1747 struct ar_hdr hdr; 1748 | 1676 } 1677 1678 if (elength != 0) 1679 { 1680 struct ar_hdr hdr; 1681 |
1749 memset ((char *) (&hdr), 0, sizeof (struct ar_hdr)); | 1682 memset (&hdr, 0, sizeof (struct ar_hdr)); |
1750 strcpy (hdr.ar_name, ename); 1751 /* Round size up to even number in archive header. */ 1752 sprintf (&(hdr.ar_size[0]), "%-10d", 1753 (int) ((elength + 1) & ~(bfd_size_type) 1)); 1754 strncpy (hdr.ar_fmag, ARFMAG, 2); 1755 for (i = 0; i < sizeof (struct ar_hdr); i++) 1756 if (((char *) (&hdr))[i] == '\0') 1757 (((char *) (&hdr))[i]) = ' '; | 1683 strcpy (hdr.ar_name, ename); 1684 /* Round size up to even number in archive header. */ 1685 sprintf (&(hdr.ar_size[0]), "%-10d", 1686 (int) ((elength + 1) & ~(bfd_size_type) 1)); 1687 strncpy (hdr.ar_fmag, ARFMAG, 2); 1688 for (i = 0; i < sizeof (struct ar_hdr); i++) 1689 if (((char *) (&hdr))[i] == '\0') 1690 (((char *) (&hdr))[i]) = ' '; |
1758 if ((bfd_bwrite ((PTR) &hdr, (bfd_size_type) sizeof (struct ar_hdr), arch) | 1691 if ((bfd_bwrite (&hdr, sizeof (struct ar_hdr), arch) |
1759 != sizeof (struct ar_hdr)) 1760 || bfd_bwrite (etable, elength, arch) != elength) | 1692 != sizeof (struct ar_hdr)) 1693 || bfd_bwrite (etable, elength, arch) != elength) |
1761 return false; | 1694 return FALSE; |
1762 if ((elength % 2) == 1) 1763 { | 1695 if ((elength % 2) == 1) 1696 { |
1764 if (bfd_bwrite ("\012", (bfd_size_type) 1, arch) != 1) 1765 return false; | 1697 if (bfd_bwrite ("\012", 1, arch) != 1) 1698 return FALSE; |
1766 } 1767 } 1768 1769 for (current = arch->archive_head; current; current = current->next) 1770 { 1771 char buffer[DEFAULT_BUFFERSIZE]; 1772 unsigned int remaining = arelt_size (current); 1773 struct ar_hdr *hdr = arch_hdr (current); 1774 1775 /* Write ar header. */ | 1699 } 1700 } 1701 1702 for (current = arch->archive_head; current; current = current->next) 1703 { 1704 char buffer[DEFAULT_BUFFERSIZE]; 1705 unsigned int remaining = arelt_size (current); 1706 struct ar_hdr *hdr = arch_hdr (current); 1707 1708 /* Write ar header. */ |
1776 if (bfd_bwrite ((PTR) hdr, (bfd_size_type) sizeof (*hdr), arch) | 1709 if (bfd_bwrite (hdr, sizeof (*hdr), arch) |
1777 != sizeof (*hdr)) | 1710 != sizeof (*hdr)) |
1778 return false; | 1711 return FALSE; |
1779 if (bfd_seek (current, (file_ptr) 0, SEEK_SET) != 0) | 1712 if (bfd_seek (current, (file_ptr) 0, SEEK_SET) != 0) |
1780 return false; | 1713 return FALSE; |
1781 while (remaining) 1782 { 1783 unsigned int amt = DEFAULT_BUFFERSIZE; 1784 if (amt > remaining) 1785 amt = remaining; 1786 errno = 0; | 1714 while (remaining) 1715 { 1716 unsigned int amt = DEFAULT_BUFFERSIZE; 1717 if (amt > remaining) 1718 amt = remaining; 1719 errno = 0; |
1787 if (bfd_bread (buffer, (bfd_size_type) amt, current) != amt) | 1720 if (bfd_bread (buffer, amt, current) != amt) |
1788 { 1789 if (bfd_get_error () != bfd_error_system_call) 1790 bfd_set_error (bfd_error_malformed_archive); | 1721 { 1722 if (bfd_get_error () != bfd_error_system_call) 1723 bfd_set_error (bfd_error_malformed_archive); |
1791 return false; | 1724 return FALSE; |
1792 } | 1725 } |
1793 if (bfd_bwrite (buffer, (bfd_size_type) amt, arch) != amt) 1794 return false; | 1726 if (bfd_bwrite (buffer, amt, arch) != amt) 1727 return FALSE; |
1795 remaining -= amt; 1796 } 1797 if ((arelt_size (current) % 2) == 1) 1798 { | 1728 remaining -= amt; 1729 } 1730 if ((arelt_size (current) % 2) == 1) 1731 { |
1799 if (bfd_bwrite ("\012", (bfd_size_type) 1, arch) != 1) 1800 return false; | 1732 if (bfd_bwrite ("\012", 1, arch) != 1) 1733 return FALSE; |
1801 } 1802 } 1803 1804 if (makemap && hasobjects) 1805 { 1806 /* Verify the timestamp in the archive file. If it would not be 1807 accepted by the linker, rewrite it until it would be. If 1808 anything odd happens, break out and just return. (The --- 6 unchanged lines hidden (view full) --- 1815 if (bfd_update_armap_timestamp (arch)) 1816 break; 1817 (*_bfd_error_handler) 1818 (_("Warning: writing archive was slow: rewriting timestamp\n")); 1819 } 1820 while (++tries < 6); 1821 } 1822 | 1734 } 1735 } 1736 1737 if (makemap && hasobjects) 1738 { 1739 /* Verify the timestamp in the archive file. If it would not be 1740 accepted by the linker, rewrite it until it would be. If 1741 anything odd happens, break out and just return. (The --- 6 unchanged lines hidden (view full) --- 1748 if (bfd_update_armap_timestamp (arch)) 1749 break; 1750 (*_bfd_error_handler) 1751 (_("Warning: writing archive was slow: rewriting timestamp\n")); 1752 } 1753 while (++tries < 6); 1754 } 1755 |
1823 return true; | 1756 return TRUE; |
1824} 1825 1826/* Note that the namidx for the first symbol is 0. */ 1827 | 1757} 1758 1759/* Note that the namidx for the first symbol is 0. */ 1760 |
1828boolean 1829_bfd_compute_and_write_armap (arch, elength) 1830 bfd *arch; 1831 unsigned int elength; | 1761bfd_boolean 1762_bfd_compute_and_write_armap (bfd *arch, unsigned int elength) |
1832{ 1833 char *first_name = NULL; 1834 bfd *current; 1835 file_ptr elt_no = 0; 1836 struct orl *map = NULL; 1837 unsigned int orl_max = 1024; /* fine initial default */ 1838 unsigned int orl_count = 0; 1839 int stridx = 0; /* string index */ 1840 asymbol **syms = NULL; 1841 long syms_max = 0; | 1763{ 1764 char *first_name = NULL; 1765 bfd *current; 1766 file_ptr elt_no = 0; 1767 struct orl *map = NULL; 1768 unsigned int orl_max = 1024; /* fine initial default */ 1769 unsigned int orl_count = 0; 1770 int stridx = 0; /* string index */ 1771 asymbol **syms = NULL; 1772 long syms_max = 0; |
1842 boolean ret; | 1773 bfd_boolean ret; |
1843 bfd_size_type amt; 1844 1845 /* Dunno if this is the best place for this info... */ 1846 if (elength != 0) 1847 elength += sizeof (struct ar_hdr); 1848 elength += elength % 2; 1849 | 1774 bfd_size_type amt; 1775 1776 /* Dunno if this is the best place for this info... */ 1777 if (elength != 0) 1778 elength += sizeof (struct ar_hdr); 1779 elength += elength % 2; 1780 |
1850 amt = (bfd_size_type) orl_max * sizeof (struct orl); 1851 map = (struct orl *) bfd_malloc (amt); | 1781 amt = orl_max * sizeof (struct orl); 1782 map = bfd_malloc (amt); |
1852 if (map == NULL) 1853 goto error_return; 1854 1855 /* We put the symbol names on the arch objalloc, and then discard 1856 them when done. */ | 1783 if (map == NULL) 1784 goto error_return; 1785 1786 /* We put the symbol names on the arch objalloc, and then discard 1787 them when done. */ |
1857 first_name = bfd_alloc (arch, (bfd_size_type) 1); | 1788 first_name = bfd_alloc (arch, 1); |
1858 if (first_name == NULL) 1859 goto error_return; 1860 1861 /* Drop all the files called __.SYMDEF, we're going to make our own. */ 1862 while (arch->archive_head && 1863 strcmp (arch->archive_head->filename, "__.SYMDEF") == 0) 1864 arch->archive_head = arch->archive_head->next; 1865 1866 /* Map over each element. */ 1867 for (current = arch->archive_head; | 1789 if (first_name == NULL) 1790 goto error_return; 1791 1792 /* Drop all the files called __.SYMDEF, we're going to make our own. */ 1793 while (arch->archive_head && 1794 strcmp (arch->archive_head->filename, "__.SYMDEF") == 0) 1795 arch->archive_head = arch->archive_head->next; 1796 1797 /* Map over each element. */ 1798 for (current = arch->archive_head; |
1868 current != (bfd *) NULL; | 1799 current != NULL; |
1869 current = current->next, elt_no++) 1870 { 1871 if (bfd_check_format (current, bfd_object) 1872 && (bfd_get_file_flags (current) & HAS_SYMS) != 0) 1873 { 1874 long storage; 1875 long symcount; 1876 long src_count; --- 4 unchanged lines hidden (view full) --- 1881 1882 if (storage != 0) 1883 { 1884 if (storage > syms_max) 1885 { 1886 if (syms_max > 0) 1887 free (syms); 1888 syms_max = storage; | 1800 current = current->next, elt_no++) 1801 { 1802 if (bfd_check_format (current, bfd_object) 1803 && (bfd_get_file_flags (current) & HAS_SYMS) != 0) 1804 { 1805 long storage; 1806 long symcount; 1807 long src_count; --- 4 unchanged lines hidden (view full) --- 1812 1813 if (storage != 0) 1814 { 1815 if (storage > syms_max) 1816 { 1817 if (syms_max > 0) 1818 free (syms); 1819 syms_max = storage; |
1889 syms = (asymbol **) bfd_malloc ((bfd_size_type) syms_max); | 1820 syms = bfd_malloc (syms_max); |
1890 if (syms == NULL) 1891 goto error_return; 1892 } 1893 symcount = bfd_canonicalize_symtab (current, syms); 1894 if (symcount < 0) 1895 goto error_return; 1896 1897 /* Now map over all the symbols, picking out the ones we --- 11 unchanged lines hidden (view full) --- 1909 { 1910 bfd_size_type namelen; 1911 struct orl *new_map; 1912 1913 /* This symbol will go into the archive header. */ 1914 if (orl_count == orl_max) 1915 { 1916 orl_max *= 2; | 1821 if (syms == NULL) 1822 goto error_return; 1823 } 1824 symcount = bfd_canonicalize_symtab (current, syms); 1825 if (symcount < 0) 1826 goto error_return; 1827 1828 /* Now map over all the symbols, picking out the ones we --- 11 unchanged lines hidden (view full) --- 1840 { 1841 bfd_size_type namelen; 1842 struct orl *new_map; 1843 1844 /* This symbol will go into the archive header. */ 1845 if (orl_count == orl_max) 1846 { 1847 orl_max *= 2; |
1917 amt = (bfd_size_type) orl_max * sizeof (struct orl); 1918 new_map = (struct orl *) bfd_realloc (map, amt); 1919 if (new_map == (struct orl *) NULL) | 1848 amt = orl_max * sizeof (struct orl); 1849 new_map = bfd_realloc (map, amt); 1850 if (new_map == NULL) |
1920 goto error_return; 1921 1922 map = new_map; 1923 } 1924 1925 namelen = strlen (syms[src_count]->name); 1926 amt = sizeof (char *); | 1851 goto error_return; 1852 1853 map = new_map; 1854 } 1855 1856 namelen = strlen (syms[src_count]->name); 1857 amt = sizeof (char *); |
1927 map[orl_count].name = (char **) bfd_alloc (arch, amt); | 1858 map[orl_count].name = bfd_alloc (arch, amt); |
1928 if (map[orl_count].name == NULL) 1929 goto error_return; 1930 *(map[orl_count].name) = bfd_alloc (arch, namelen + 1); 1931 if (*(map[orl_count].name) == NULL) 1932 goto error_return; 1933 strcpy (*(map[orl_count].name), syms[src_count]->name); 1934 map[orl_count].u.abfd = current; 1935 map[orl_count].namidx = stridx; --- 27 unchanged lines hidden (view full) --- 1963 error_return: 1964 if (syms_max > 0) 1965 free (syms); 1966 if (map != NULL) 1967 free (map); 1968 if (first_name != NULL) 1969 bfd_release (arch, first_name); 1970 | 1859 if (map[orl_count].name == NULL) 1860 goto error_return; 1861 *(map[orl_count].name) = bfd_alloc (arch, namelen + 1); 1862 if (*(map[orl_count].name) == NULL) 1863 goto error_return; 1864 strcpy (*(map[orl_count].name), syms[src_count]->name); 1865 map[orl_count].u.abfd = current; 1866 map[orl_count].namidx = stridx; --- 27 unchanged lines hidden (view full) --- 1894 error_return: 1895 if (syms_max > 0) 1896 free (syms); 1897 if (map != NULL) 1898 free (map); 1899 if (first_name != NULL) 1900 bfd_release (arch, first_name); 1901 |
1971 return false; | 1902 return FALSE; |
1972} 1973 | 1903} 1904 |
1974boolean 1975bsd_write_armap (arch, elength, map, orl_count, stridx) 1976 bfd *arch; 1977 unsigned int elength; 1978 struct orl *map; 1979 unsigned int orl_count; 1980 int stridx; | 1905bfd_boolean 1906bsd_write_armap (bfd *arch, 1907 unsigned int elength, 1908 struct orl *map, 1909 unsigned int orl_count, 1910 int stridx) |
1981{ 1982 int padit = stridx & 1; 1983 unsigned int ranlibsize = orl_count * BSD_SYMDEF_SIZE; 1984 unsigned int stringsize = stridx + padit; 1985 /* Include 8 bytes to store ranlibsize and stringsize in output. */ 1986 unsigned int mapsize = ranlibsize + stringsize + 8; 1987 file_ptr firstreal; 1988 bfd *current = arch->archive_head; 1989 bfd *last_elt = current; /* last element arch seen */ 1990 bfd_byte temp[4]; 1991 unsigned int count; 1992 struct ar_hdr hdr; 1993 struct stat statbuf; 1994 unsigned int i; 1995 1996 firstreal = mapsize + elength + sizeof (struct ar_hdr) + SARMAG; 1997 1998 stat (arch->filename, &statbuf); | 1911{ 1912 int padit = stridx & 1; 1913 unsigned int ranlibsize = orl_count * BSD_SYMDEF_SIZE; 1914 unsigned int stringsize = stridx + padit; 1915 /* Include 8 bytes to store ranlibsize and stringsize in output. */ 1916 unsigned int mapsize = ranlibsize + stringsize + 8; 1917 file_ptr firstreal; 1918 bfd *current = arch->archive_head; 1919 bfd *last_elt = current; /* last element arch seen */ 1920 bfd_byte temp[4]; 1921 unsigned int count; 1922 struct ar_hdr hdr; 1923 struct stat statbuf; 1924 unsigned int i; 1925 1926 firstreal = mapsize + elength + sizeof (struct ar_hdr) + SARMAG; 1927 1928 stat (arch->filename, &statbuf); |
1999 memset ((char *) (&hdr), 0, sizeof (struct ar_hdr)); | 1929 memset (&hdr, 0, sizeof (struct ar_hdr)); |
2000 sprintf (hdr.ar_name, RANLIBMAG); 2001 /* Remember the timestamp, to keep it holy. But fudge it a little. */ 2002 bfd_ardata (arch)->armap_timestamp = statbuf.st_mtime + ARMAP_TIME_OFFSET; 2003 bfd_ardata (arch)->armap_datepos = (SARMAG 2004 + offsetof (struct ar_hdr, ar_date[0])); 2005 sprintf (hdr.ar_date, "%ld", bfd_ardata (arch)->armap_timestamp); 2006 sprintf (hdr.ar_uid, "%ld", (long) getuid ()); 2007 sprintf (hdr.ar_gid, "%ld", (long) getgid ()); 2008 sprintf (hdr.ar_size, "%-10d", (int) mapsize); 2009 strncpy (hdr.ar_fmag, ARFMAG, 2); 2010 for (i = 0; i < sizeof (struct ar_hdr); i++) 2011 if (((char *) (&hdr))[i] == '\0') 2012 (((char *) (&hdr))[i]) = ' '; | 1930 sprintf (hdr.ar_name, RANLIBMAG); 1931 /* Remember the timestamp, to keep it holy. But fudge it a little. */ 1932 bfd_ardata (arch)->armap_timestamp = statbuf.st_mtime + ARMAP_TIME_OFFSET; 1933 bfd_ardata (arch)->armap_datepos = (SARMAG 1934 + offsetof (struct ar_hdr, ar_date[0])); 1935 sprintf (hdr.ar_date, "%ld", bfd_ardata (arch)->armap_timestamp); 1936 sprintf (hdr.ar_uid, "%ld", (long) getuid ()); 1937 sprintf (hdr.ar_gid, "%ld", (long) getgid ()); 1938 sprintf (hdr.ar_size, "%-10d", (int) mapsize); 1939 strncpy (hdr.ar_fmag, ARFMAG, 2); 1940 for (i = 0; i < sizeof (struct ar_hdr); i++) 1941 if (((char *) (&hdr))[i] == '\0') 1942 (((char *) (&hdr))[i]) = ' '; |
2013 if (bfd_bwrite ((PTR) &hdr, (bfd_size_type) sizeof (struct ar_hdr), arch) | 1943 if (bfd_bwrite (&hdr, sizeof (struct ar_hdr), arch) |
2014 != sizeof (struct ar_hdr)) | 1944 != sizeof (struct ar_hdr)) |
2015 return false; | 1945 return FALSE; |
2016 H_PUT_32 (arch, ranlibsize, temp); | 1946 H_PUT_32 (arch, ranlibsize, temp); |
2017 if (bfd_bwrite (temp, (bfd_size_type) sizeof (temp), arch) != sizeof (temp)) 2018 return false; | 1947 if (bfd_bwrite (temp, sizeof (temp), arch) != sizeof (temp)) 1948 return FALSE; |
2019 2020 for (count = 0; count < orl_count; count++) 2021 { 2022 bfd_byte buf[BSD_SYMDEF_SIZE]; 2023 2024 if (map[count].u.abfd != last_elt) 2025 { 2026 do 2027 { 2028 firstreal += arelt_size (current) + sizeof (struct ar_hdr); 2029 firstreal += firstreal % 2; 2030 current = current->next; 2031 } 2032 while (current != map[count].u.abfd); 2033 } /* if new archive element */ 2034 2035 last_elt = current; 2036 H_PUT_32 (arch, map[count].namidx, buf); 2037 H_PUT_32 (arch, firstreal, buf + BSD_SYMDEF_OFFSET_SIZE); | 1949 1950 for (count = 0; count < orl_count; count++) 1951 { 1952 bfd_byte buf[BSD_SYMDEF_SIZE]; 1953 1954 if (map[count].u.abfd != last_elt) 1955 { 1956 do 1957 { 1958 firstreal += arelt_size (current) + sizeof (struct ar_hdr); 1959 firstreal += firstreal % 2; 1960 current = current->next; 1961 } 1962 while (current != map[count].u.abfd); 1963 } /* if new archive element */ 1964 1965 last_elt = current; 1966 H_PUT_32 (arch, map[count].namidx, buf); 1967 H_PUT_32 (arch, firstreal, buf + BSD_SYMDEF_OFFSET_SIZE); |
2038 if (bfd_bwrite (buf, (bfd_size_type) BSD_SYMDEF_SIZE, arch) | 1968 if (bfd_bwrite (buf, BSD_SYMDEF_SIZE, arch) |
2039 != BSD_SYMDEF_SIZE) | 1969 != BSD_SYMDEF_SIZE) |
2040 return false; | 1970 return FALSE; |
2041 } 2042 2043 /* Now write the strings themselves. */ 2044 H_PUT_32 (arch, stringsize, temp); | 1971 } 1972 1973 /* Now write the strings themselves. */ 1974 H_PUT_32 (arch, stringsize, temp); |
2045 if (bfd_bwrite (temp, (bfd_size_type) sizeof (temp), arch) != sizeof (temp)) 2046 return false; | 1975 if (bfd_bwrite (temp, sizeof (temp), arch) != sizeof (temp)) 1976 return FALSE; |
2047 for (count = 0; count < orl_count; count++) 2048 { 2049 size_t len = strlen (*map[count].name) + 1; 2050 | 1977 for (count = 0; count < orl_count; count++) 1978 { 1979 size_t len = strlen (*map[count].name) + 1; 1980 |
2051 if (bfd_bwrite (*map[count].name, (bfd_size_type) len, arch) != len) 2052 return false; | 1981 if (bfd_bwrite (*map[count].name, len, arch) != len) 1982 return FALSE; |
2053 } 2054 2055 /* The spec sez this should be a newline. But in order to be 2056 bug-compatible for sun's ar we use a null. */ 2057 if (padit) 2058 { | 1983 } 1984 1985 /* The spec sez this should be a newline. But in order to be 1986 bug-compatible for sun's ar we use a null. */ 1987 if (padit) 1988 { |
2059 if (bfd_bwrite ("", (bfd_size_type) 1, arch) != 1) 2060 return false; | 1989 if (bfd_bwrite ("", 1, arch) != 1) 1990 return FALSE; |
2061 } 2062 | 1991 } 1992 |
2063 return true; | 1993 return TRUE; |
2064} 2065 2066/* At the end of archive file handling, update the timestamp in the 2067 file, so the linker will accept it. 2068 | 1994} 1995 1996/* At the end of archive file handling, update the timestamp in the 1997 file, so the linker will accept it. 1998 |
2069 Return true if the timestamp was OK, or an unusual problem happened. 2070 Return false if we updated the timestamp. */ | 1999 Return TRUE if the timestamp was OK, or an unusual problem happened. 2000 Return FALSE if we updated the timestamp. */ |
2071 | 2001 |
2072boolean 2073_bfd_archive_bsd_update_armap_timestamp (arch) 2074 bfd *arch; | 2002bfd_boolean 2003_bfd_archive_bsd_update_armap_timestamp (bfd *arch) |
2075{ 2076 struct stat archstat; 2077 struct ar_hdr hdr; 2078 unsigned int i; 2079 2080 /* Flush writes, get last-write timestamp from file, and compare it 2081 to the timestamp IN the file. */ 2082 bfd_flush (arch); 2083 if (bfd_stat (arch, &archstat) == -1) 2084 { | 2004{ 2005 struct stat archstat; 2006 struct ar_hdr hdr; 2007 unsigned int i; 2008 2009 /* Flush writes, get last-write timestamp from file, and compare it 2010 to the timestamp IN the file. */ 2011 bfd_flush (arch); 2012 if (bfd_stat (arch, &archstat) == -1) 2013 { |
2085 perror (_("Reading archive file mod timestamp")); | 2014 bfd_perror (_("Reading archive file mod timestamp")); |
2086 2087 /* Can't read mod time for some reason. */ | 2015 2016 /* Can't read mod time for some reason. */ |
2088 return true; | 2017 return TRUE; |
2089 } 2090 if (archstat.st_mtime <= bfd_ardata (arch)->armap_timestamp) 2091 /* OK by the linker's rules. */ | 2018 } 2019 if (archstat.st_mtime <= bfd_ardata (arch)->armap_timestamp) 2020 /* OK by the linker's rules. */ |
2092 return true; | 2021 return TRUE; |
2093 2094 /* Update the timestamp. */ 2095 bfd_ardata (arch)->armap_timestamp = archstat.st_mtime + ARMAP_TIME_OFFSET; 2096 2097 /* Prepare an ASCII version suitable for writing. */ 2098 memset (hdr.ar_date, 0, sizeof (hdr.ar_date)); 2099 sprintf (hdr.ar_date, "%ld", bfd_ardata (arch)->armap_timestamp); 2100 for (i = 0; i < sizeof (hdr.ar_date); i++) 2101 if (hdr.ar_date[i] == '\0') 2102 (hdr.ar_date)[i] = ' '; 2103 2104 /* Write it into the file. */ 2105 bfd_ardata (arch)->armap_datepos = (SARMAG 2106 + offsetof (struct ar_hdr, ar_date[0])); 2107 if (bfd_seek (arch, bfd_ardata (arch)->armap_datepos, SEEK_SET) != 0 | 2022 2023 /* Update the timestamp. */ 2024 bfd_ardata (arch)->armap_timestamp = archstat.st_mtime + ARMAP_TIME_OFFSET; 2025 2026 /* Prepare an ASCII version suitable for writing. */ 2027 memset (hdr.ar_date, 0, sizeof (hdr.ar_date)); 2028 sprintf (hdr.ar_date, "%ld", bfd_ardata (arch)->armap_timestamp); 2029 for (i = 0; i < sizeof (hdr.ar_date); i++) 2030 if (hdr.ar_date[i] == '\0') 2031 (hdr.ar_date)[i] = ' '; 2032 2033 /* Write it into the file. */ 2034 bfd_ardata (arch)->armap_datepos = (SARMAG 2035 + offsetof (struct ar_hdr, ar_date[0])); 2036 if (bfd_seek (arch, bfd_ardata (arch)->armap_datepos, SEEK_SET) != 0 |
2108 || (bfd_bwrite (hdr.ar_date, (bfd_size_type) sizeof (hdr.ar_date), arch) | 2037 || (bfd_bwrite (hdr.ar_date, sizeof (hdr.ar_date), arch) |
2109 != sizeof (hdr.ar_date))) 2110 { | 2038 != sizeof (hdr.ar_date))) 2039 { |
2111 /* FIXME: bfd can't call perror. */ 2112 perror (_("Writing updated armap timestamp")); | 2040 bfd_perror (_("Writing updated armap timestamp")); |
2113 2114 /* Some error while writing. */ | 2041 2042 /* Some error while writing. */ |
2115 return true; | 2043 return TRUE; |
2116 } 2117 2118 /* We updated the timestamp successfully. */ | 2044 } 2045 2046 /* We updated the timestamp successfully. */ |
2119 return false; | 2047 return FALSE; |
2120} 2121 2122/* A coff armap looks like : 2123 lARMAG 2124 struct ar_hdr with name = '/' 2125 number of symbols 2126 offset of file for symbol 0 2127 offset of file for symbol 1 2128 2129 offset of file for symbol n-1 2130 symbol name 0 2131 symbol name 1 2132 2133 symbol name n-1 2134*/ 2135 | 2048} 2049 2050/* A coff armap looks like : 2051 lARMAG 2052 struct ar_hdr with name = '/' 2053 number of symbols 2054 offset of file for symbol 0 2055 offset of file for symbol 1 2056 2057 offset of file for symbol n-1 2058 symbol name 0 2059 symbol name 1 2060 2061 symbol name n-1 2062*/ 2063 |
2136boolean 2137coff_write_armap (arch, elength, map, symbol_count, stridx) 2138 bfd *arch; 2139 unsigned int elength; 2140 struct orl *map; 2141 unsigned int symbol_count; 2142 int stridx; | 2064bfd_boolean 2065coff_write_armap (bfd *arch, 2066 unsigned int elength, 2067 struct orl *map, 2068 unsigned int symbol_count, 2069 int stridx) |
2143{ 2144 /* The size of the ranlib is the number of exported symbols in the 2145 archive * the number of bytes in an int, + an int for the count. */ 2146 unsigned int ranlibsize = (symbol_count * 4) + 4; 2147 unsigned int stringsize = stridx; 2148 unsigned int mapsize = stringsize + ranlibsize; 2149 unsigned int archive_member_file_ptr; 2150 bfd *current = arch->archive_head; --- 6 unchanged lines hidden (view full) --- 2157 mapsize++; 2158 2159 /* Work out where the first object file will go in the archive. */ 2160 archive_member_file_ptr = (mapsize 2161 + elength 2162 + sizeof (struct ar_hdr) 2163 + SARMAG); 2164 | 2070{ 2071 /* The size of the ranlib is the number of exported symbols in the 2072 archive * the number of bytes in an int, + an int for the count. */ 2073 unsigned int ranlibsize = (symbol_count * 4) + 4; 2074 unsigned int stringsize = stridx; 2075 unsigned int mapsize = stringsize + ranlibsize; 2076 unsigned int archive_member_file_ptr; 2077 bfd *current = arch->archive_head; --- 6 unchanged lines hidden (view full) --- 2084 mapsize++; 2085 2086 /* Work out where the first object file will go in the archive. */ 2087 archive_member_file_ptr = (mapsize 2088 + elength 2089 + sizeof (struct ar_hdr) 2090 + SARMAG); 2091 |
2165 memset ((char *) (&hdr), 0, sizeof (struct ar_hdr)); | 2092 memset (&hdr, 0, sizeof (struct ar_hdr)); |
2166 hdr.ar_name[0] = '/'; 2167 sprintf (hdr.ar_size, "%-10d", (int) mapsize); 2168 sprintf (hdr.ar_date, "%ld", (long) time (NULL)); 2169 /* This, at least, is what Intel coff sets the values to. */ 2170 sprintf ((hdr.ar_uid), "%d", 0); 2171 sprintf ((hdr.ar_gid), "%d", 0); 2172 sprintf ((hdr.ar_mode), "%-7o", (unsigned) 0); 2173 strncpy (hdr.ar_fmag, ARFMAG, 2); 2174 2175 for (i = 0; i < sizeof (struct ar_hdr); i++) 2176 if (((char *) (&hdr))[i] == '\0') 2177 (((char *) (&hdr))[i]) = ' '; 2178 2179 /* Write the ar header for this item and the number of symbols. */ 2180 | 2093 hdr.ar_name[0] = '/'; 2094 sprintf (hdr.ar_size, "%-10d", (int) mapsize); 2095 sprintf (hdr.ar_date, "%ld", (long) time (NULL)); 2096 /* This, at least, is what Intel coff sets the values to. */ 2097 sprintf ((hdr.ar_uid), "%d", 0); 2098 sprintf ((hdr.ar_gid), "%d", 0); 2099 sprintf ((hdr.ar_mode), "%-7o", (unsigned) 0); 2100 strncpy (hdr.ar_fmag, ARFMAG, 2); 2101 2102 for (i = 0; i < sizeof (struct ar_hdr); i++) 2103 if (((char *) (&hdr))[i] == '\0') 2104 (((char *) (&hdr))[i]) = ' '; 2105 2106 /* Write the ar header for this item and the number of symbols. */ 2107 |
2181 if (bfd_bwrite ((PTR) &hdr, (bfd_size_type) sizeof (struct ar_hdr), arch) | 2108 if (bfd_bwrite (&hdr, sizeof (struct ar_hdr), arch) |
2182 != sizeof (struct ar_hdr)) | 2109 != sizeof (struct ar_hdr)) |
2183 return false; | 2110 return FALSE; |
2184 2185 if (!bfd_write_bigendian_4byte_int (arch, symbol_count)) | 2111 2112 if (!bfd_write_bigendian_4byte_int (arch, symbol_count)) |
2186 return false; | 2113 return FALSE; |
2187 2188 /* Two passes, first write the file offsets for each symbol - 2189 remembering that each offset is on a two byte boundary. */ 2190 2191 /* Write out the file offset for the file associated with each 2192 symbol, and remember to keep the offsets padded out. */ 2193 2194 current = arch->archive_head; 2195 count = 0; | 2114 2115 /* Two passes, first write the file offsets for each symbol - 2116 remembering that each offset is on a two byte boundary. */ 2117 2118 /* Write out the file offset for the file associated with each 2119 symbol, and remember to keep the offsets padded out. */ 2120 2121 current = arch->archive_head; 2122 count = 0; |
2196 while (current != (bfd *) NULL && count < symbol_count) | 2123 while (current != NULL && count < symbol_count) |
2197 { 2198 /* For each symbol which is used defined in this object, write 2199 out the object file's address in the archive. */ 2200 2201 while (count < symbol_count && map[count].u.abfd == current) 2202 { 2203 if (!bfd_write_bigendian_4byte_int (arch, archive_member_file_ptr)) | 2124 { 2125 /* For each symbol which is used defined in this object, write 2126 out the object file's address in the archive. */ 2127 2128 while (count < symbol_count && map[count].u.abfd == current) 2129 { 2130 if (!bfd_write_bigendian_4byte_int (arch, archive_member_file_ptr)) |
2204 return false; | 2131 return FALSE; |
2205 count++; 2206 } 2207 /* Add size of this archive entry. */ | 2132 count++; 2133 } 2134 /* Add size of this archive entry. */ |
2208 archive_member_file_ptr += (arelt_size (current) 2209 + sizeof (struct ar_hdr)); | 2135 archive_member_file_ptr += arelt_size (current) + sizeof (struct ar_hdr); |
2210 /* Remember aboout the even alignment. */ 2211 archive_member_file_ptr += archive_member_file_ptr % 2; 2212 current = current->next; 2213 } 2214 2215 /* Now write the strings themselves. */ 2216 for (count = 0; count < symbol_count; count++) 2217 { 2218 size_t len = strlen (*map[count].name) + 1; 2219 | 2136 /* Remember aboout the even alignment. */ 2137 archive_member_file_ptr += archive_member_file_ptr % 2; 2138 current = current->next; 2139 } 2140 2141 /* Now write the strings themselves. */ 2142 for (count = 0; count < symbol_count; count++) 2143 { 2144 size_t len = strlen (*map[count].name) + 1; 2145 |
2220 if (bfd_bwrite (*map[count].name, (bfd_size_type) len, arch) != len) 2221 return false; | 2146 if (bfd_bwrite (*map[count].name, len, arch) != len) 2147 return FALSE; |
2222 } 2223 2224 /* The spec sez this should be a newline. But in order to be 2225 bug-compatible for arc960 we use a null. */ 2226 if (padit) 2227 { | 2148 } 2149 2150 /* The spec sez this should be a newline. But in order to be 2151 bug-compatible for arc960 we use a null. */ 2152 if (padit) 2153 { |
2228 if (bfd_bwrite ("", (bfd_size_type) 1, arch) != 1) 2229 return false; | 2154 if (bfd_bwrite ("", 1, arch) != 1) 2155 return FALSE; |
2230 } 2231 | 2156 } 2157 |
2232 return true; | 2158 return TRUE; |
2233} | 2159} |