mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-05 00:04:22 +08:00
* archive.c: Reindented to GNU standards.
This commit is contained in:
parent
364648978f
commit
a927c32d18
@ -1,3 +1,7 @@
|
||||
Tue Jan 25 11:46:46 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com)
|
||||
|
||||
* archive.c: Reindented to GNU standards.
|
||||
|
||||
Mon Jan 24 14:41:23 1994 David J. Mackenzie (djm@thepub.cygnus.com)
|
||||
|
||||
* opncls.c (_bfd_new_bfd, _bfd_new_bfd_contained_in): Add
|
||||
|
429
bfd/archive.c
429
bfd/archive.c
@ -158,7 +158,8 @@ extern int errno;
|
||||
Note that the pointers here point to the front of the ar_hdr, not
|
||||
to the front of the contents!
|
||||
*/
|
||||
struct ar_cache {
|
||||
struct ar_cache
|
||||
{
|
||||
file_ptr ptr;
|
||||
bfd *arelt;
|
||||
struct ar_cache *next;
|
||||
@ -233,12 +234,14 @@ bfd_get_next_mapent (abfd, prev, entry)
|
||||
symindex prev;
|
||||
carsym **entry;
|
||||
{
|
||||
if (!bfd_has_map (abfd)) {
|
||||
if (!bfd_has_map (abfd))
|
||||
{
|
||||
bfd_error = invalid_operation;
|
||||
return BFD_NO_MORE_SYMBOLS;
|
||||
}
|
||||
|
||||
if (prev == BFD_NO_MORE_SYMBOLS) prev = 0;
|
||||
if (prev == BFD_NO_MORE_SYMBOLS)
|
||||
prev = 0;
|
||||
else if (++prev >= bfd_ardata (abfd)->symdef_count)
|
||||
return BFD_NO_MORE_SYMBOLS;
|
||||
|
||||
@ -294,7 +297,8 @@ _bfd_look_for_bfd_in_cache (arch_bfd, filepos)
|
||||
|
||||
for (current = bfd_ardata (arch_bfd)->cache; current != NULL;
|
||||
current = current->next)
|
||||
if (current->ptr == filepos) return current->arelt;
|
||||
if (current->ptr == filepos)
|
||||
return current->arelt;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -305,10 +309,12 @@ _bfd_add_bfd_to_archive_cache (arch_bfd, filepos, new_elt)
|
||||
bfd *arch_bfd, *new_elt;
|
||||
file_ptr filepos;
|
||||
{
|
||||
struct ar_cache *new_cache = (struct ar_cache *)
|
||||
bfd_zalloc(arch_bfd, sizeof (struct ar_cache));
|
||||
struct ar_cache *new_cache = ((struct ar_cache *)
|
||||
bfd_zalloc (arch_bfd,
|
||||
sizeof (struct ar_cache)));
|
||||
|
||||
if (new_cache == NULL) {
|
||||
if (new_cache == NULL)
|
||||
{
|
||||
bfd_error = no_memory;
|
||||
return false;
|
||||
}
|
||||
@ -318,7 +324,8 @@ _bfd_add_bfd_to_archive_cache (arch_bfd, filepos, new_elt)
|
||||
new_cache->next = (struct ar_cache *) NULL;
|
||||
if (bfd_ardata (arch_bfd)->cache == NULL)
|
||||
bfd_ardata (arch_bfd)->cache = new_cache;
|
||||
else {
|
||||
else
|
||||
{
|
||||
struct ar_cache *current = bfd_ardata (arch_bfd)->cache;
|
||||
|
||||
while (current->next != NULL)
|
||||
@ -344,7 +351,8 @@ get_extended_arelt_filename (arch, name)
|
||||
errno = 0;
|
||||
/* Skip first char, which is '/' in SVR4 or ' ' in some other variants. */
|
||||
index = strtol (name + 1, NULL, 10);
|
||||
if (errno != 0) {
|
||||
if (errno != 0)
|
||||
{
|
||||
bfd_error = malformed_archive;
|
||||
return NULL;
|
||||
}
|
||||
@ -379,31 +387,36 @@ _bfd_snarf_ar_hdr (abfd)
|
||||
char *allocptr = 0;
|
||||
|
||||
if (bfd_read ((PTR) hdrp, 1, sizeof (struct ar_hdr), abfd)
|
||||
!= sizeof (struct ar_hdr)) {
|
||||
!= sizeof (struct ar_hdr))
|
||||
{
|
||||
bfd_error = no_more_archived_files;
|
||||
return NULL;
|
||||
}
|
||||
if (strncmp ((hdr.ar_fmag), ARFMAG, 2)) {
|
||||
if (strncmp (hdr.ar_fmag, ARFMAG, 2))
|
||||
{
|
||||
bfd_error = malformed_archive;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
parsed_size = strtol (hdr.ar_size, NULL, 10);
|
||||
if (errno != 0) {
|
||||
if (errno != 0)
|
||||
{
|
||||
bfd_error = malformed_archive;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* extract the filename from the archive - there are two ways to
|
||||
/* Extract the filename from the archive - there are two ways to
|
||||
specify an extendend name table, either the first char of the
|
||||
name is a space, or it's a slash. */
|
||||
if ((hdr.ar_name[0] == '/'
|
||||
|| (hdr.ar_name[0] == ' '
|
||||
&& memchr (hdr.ar_name, '/', ar_maxnamelen (abfd)) == NULL))
|
||||
&& bfd_ardata (abfd)->extended_names != NULL) {
|
||||
&& bfd_ardata (abfd)->extended_names != NULL)
|
||||
{
|
||||
filename = get_extended_arelt_filename (abfd, hdr.ar_name);
|
||||
if (filename == NULL) {
|
||||
if (filename == NULL)
|
||||
{
|
||||
bfd_error = malformed_archive;
|
||||
return NULL;
|
||||
}
|
||||
@ -419,13 +432,16 @@ _bfd_snarf_ar_hdr (abfd)
|
||||
parsed_size -= namelen;
|
||||
|
||||
allocptr = bfd_zalloc (abfd, allocsize);
|
||||
if (allocptr == NULL) {
|
||||
if (allocptr == NULL)
|
||||
{
|
||||
bfd_error = no_memory;
|
||||
return NULL;
|
||||
}
|
||||
filename = allocptr
|
||||
+ (sizeof (struct areltdata) + sizeof (struct ar_hdr));
|
||||
if (bfd_read (filename, 1, namelen, abfd) != namelen) {
|
||||
filename = (allocptr
|
||||
+ sizeof (struct areltdata)
|
||||
+ sizeof (struct ar_hdr));
|
||||
if (bfd_read (filename, 1, namelen, abfd) != namelen)
|
||||
{
|
||||
bfd_error = no_more_archived_files;
|
||||
return NULL;
|
||||
}
|
||||
@ -439,14 +455,15 @@ _bfd_snarf_ar_hdr (abfd)
|
||||
|
||||
namelen = 0;
|
||||
while (hdr.ar_name[namelen] != '\0' &&
|
||||
hdr.ar_name[namelen] != '/') {
|
||||
hdr.ar_name[namelen] != '/')
|
||||
{
|
||||
namelen++;
|
||||
if (namelen == (unsigned)ar_maxnamelen(abfd)) {
|
||||
if (namelen == (unsigned) ar_maxnamelen (abfd))
|
||||
{
|
||||
namelen = 0;
|
||||
while (hdr.ar_name[namelen] != ' '
|
||||
&& namelen < (unsigned)ar_maxnamelen(abfd)) {
|
||||
&& namelen < (unsigned) ar_maxnamelen (abfd))
|
||||
namelen++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -454,9 +471,11 @@ _bfd_snarf_ar_hdr (abfd)
|
||||
allocsize += namelen + 1;
|
||||
}
|
||||
|
||||
if (!allocptr) {
|
||||
if (!allocptr)
|
||||
{
|
||||
allocptr = bfd_zalloc (abfd, allocsize);
|
||||
if (allocptr == NULL) {
|
||||
if (allocptr == NULL)
|
||||
{
|
||||
bfd_error = no_memory;
|
||||
return NULL;
|
||||
}
|
||||
@ -468,8 +487,10 @@ _bfd_snarf_ar_hdr (abfd)
|
||||
memcpy ((char *) ared->arch_header, (char *) &hdr, sizeof (struct ar_hdr));
|
||||
ared->parsed_size = parsed_size;
|
||||
|
||||
if (filename != NULL) ared->filename = filename;
|
||||
else {
|
||||
if (filename != NULL)
|
||||
ared->filename = filename;
|
||||
else
|
||||
{
|
||||
ared->filename = allocptr + (sizeof (struct areltdata) +
|
||||
sizeof (struct ar_hdr));
|
||||
if (namelen)
|
||||
@ -482,8 +503,7 @@ _bfd_snarf_ar_hdr (abfd)
|
||||
|
||||
/* This is an internal function; it's mainly used when indexing
|
||||
through the archive symbol table, but also used to get the next
|
||||
element, since it handles the bookkeeping so nicely for us.
|
||||
*/
|
||||
element, since it handles the bookkeeping so nicely for us. */
|
||||
|
||||
bfd *
|
||||
_bfd_get_elt_at_filepos (archive, filepos)
|
||||
@ -544,10 +564,10 @@ bfd_get_elt_at_index (abfd, index)
|
||||
bfd *abfd;
|
||||
int index;
|
||||
{
|
||||
bfd *result =
|
||||
_bfd_get_elt_at_filepos
|
||||
(abfd, (bfd_ardata (abfd)->symdefs + index)->file_offset);
|
||||
return result;
|
||||
carsym *entry;
|
||||
|
||||
entry = bfd_ardata (abfd)->symdefs + index;
|
||||
return _bfd_get_elt_at_filepos (abfd, entry->file_offset);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -594,7 +614,8 @@ bfd_generic_openr_next_archived_file (archive, last_file)
|
||||
|
||||
if (!last_file)
|
||||
filestart = bfd_ardata (archive)->first_file_filepos;
|
||||
else {
|
||||
else
|
||||
{
|
||||
unsigned int size = arelt_size (last_file);
|
||||
/* Pad to an even boundary...
|
||||
Note that last_file->origin can be odd in the case of
|
||||
@ -682,12 +703,14 @@ do_slurp_bsd_armap (abfd)
|
||||
bfd_release (abfd, (PTR) mapdata); /* Don't need it any more. */
|
||||
|
||||
raw_armap = (int *) bfd_zalloc (abfd, parsed_size);
|
||||
if (raw_armap == NULL) {
|
||||
if (raw_armap == NULL)
|
||||
{
|
||||
bfd_error = no_memory;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bfd_read ((PTR)raw_armap, 1, parsed_size, abfd) != parsed_size) {
|
||||
if (bfd_read ((PTR) raw_armap, 1, parsed_size, abfd) != parsed_size)
|
||||
{
|
||||
bfd_error = malformed_archive;
|
||||
byebye:
|
||||
bfd_release (abfd, (PTR) raw_armap);
|
||||
@ -698,7 +721,8 @@ do_slurp_bsd_armap (abfd)
|
||||
/ sizeof (struct symdef));
|
||||
|
||||
if (ardata->symdef_count * sizeof (struct symdef)
|
||||
> parsed_size - sizeof (*raw_armap)) {
|
||||
> parsed_size - sizeof (*raw_armap))
|
||||
{
|
||||
/* Probably we're using the wrong byte ordering. */
|
||||
bfd_error = wrong_format;
|
||||
goto byebye;
|
||||
@ -709,7 +733,8 @@ do_slurp_bsd_armap (abfd)
|
||||
ardata->symdefs = (carsym *) rbase;
|
||||
stringbase = ((char *) (ardata->symdefs + ardata->symdef_count)) + 4;
|
||||
|
||||
for (;counter < ardata->symdef_count; counter++) {
|
||||
for (; counter < ardata->symdef_count; counter++)
|
||||
{
|
||||
struct symdef *sym = ((struct symdef *) rbase) + counter;
|
||||
sym->s.name = (bfd_h_get_32 (abfd, (bfd_byte *) (&sym->s.string_offset))
|
||||
+ stringbase);
|
||||
@ -750,7 +775,8 @@ do_slurp_coff_armap (abfd)
|
||||
parsed_size = mapdata->parsed_size;
|
||||
bfd_release (abfd, (PTR) mapdata); /* Don't need it any more. */
|
||||
|
||||
if (bfd_read ((PTR)int_buf, 1, 4, abfd) != 4) {
|
||||
if (bfd_read ((PTR) int_buf, 1, 4, abfd) != 4)
|
||||
{
|
||||
bfd_error = malformed_archive;
|
||||
return false;
|
||||
}
|
||||
@ -766,7 +792,8 @@ do_slurp_coff_armap (abfd)
|
||||
little, because our tools changed. Here's a horrible hack to clean
|
||||
up the crap. */
|
||||
|
||||
if (stringsize > 0xfffff) {
|
||||
if (stringsize > 0xfffff)
|
||||
{
|
||||
/* This looks dangerous, let's do it the other way around */
|
||||
nsymz = bfd_getl32 ((PTR) int_buf);
|
||||
stringsize = parsed_size - (4 * nsymz) - 4;
|
||||
@ -774,14 +801,15 @@ do_slurp_coff_armap (abfd)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* The coff armap must be read sequentially. So we construct a bsd-style
|
||||
one in core all at once, for simplicity. */
|
||||
/* The coff armap must be read sequentially. So we construct a
|
||||
bsd-style one in core all at once, for simplicity. */
|
||||
|
||||
carsym_size = (nsymz * sizeof (carsym));
|
||||
ptrsize = (4 * nsymz);
|
||||
|
||||
ardata->symdefs = (carsym *) bfd_zalloc (abfd, carsym_size + stringsize + 1);
|
||||
if (ardata->symdefs == NULL) {
|
||||
if (ardata->symdefs == NULL)
|
||||
{
|
||||
bfd_error = no_memory;
|
||||
return false;
|
||||
}
|
||||
@ -790,18 +818,21 @@ do_slurp_coff_armap (abfd)
|
||||
|
||||
/* Allocate and read in the raw offsets. */
|
||||
raw_armap = (int *) bfd_alloc (abfd, ptrsize);
|
||||
if (raw_armap == NULL) {
|
||||
if (raw_armap == NULL)
|
||||
{
|
||||
bfd_error = no_memory;
|
||||
goto release_symdefs;
|
||||
}
|
||||
if (bfd_read ((PTR) raw_armap, 1, ptrsize, abfd) != ptrsize
|
||||
|| bfd_read ((PTR)stringbase, 1, stringsize, abfd) != stringsize) {
|
||||
|| bfd_read ((PTR) stringbase, 1, stringsize, abfd) != stringsize)
|
||||
{
|
||||
bfd_error = malformed_archive;
|
||||
goto release_raw_armap;
|
||||
}
|
||||
|
||||
/* OK, build the carsyms */
|
||||
for (i = 0; i < nsymz; i++) {
|
||||
for (i = 0; i < nsymz; i++)
|
||||
{
|
||||
rawptr = raw_armap + i;
|
||||
carsyms->file_offset = swap ((PTR) rawptr);
|
||||
carsyms->name = stringbase;
|
||||
@ -929,7 +960,8 @@ bfd_slurp_bsd_armap_f2 (abfd)
|
||||
for (; counter < ardata->symdef_count; counter++)
|
||||
{
|
||||
struct symdef *sym = ((struct symdef *) ardata->symdefs) + counter;
|
||||
sym->s.name = bfd_h_get_32(abfd, (PTR)(&(sym->s.string_offset))) + stringbase;
|
||||
sym->s.name = (bfd_h_get_32 (abfd, (PTR) (&(sym->s.string_offset)))
|
||||
+ stringbase);
|
||||
sym->file_offset = bfd_h_get_32 (abfd, (PTR) (&(sym->file_offset)));
|
||||
}
|
||||
|
||||
@ -963,7 +995,8 @@ _bfd_slurp_extended_name_table (abfd)
|
||||
|
||||
/* FIXME: Formatting sucks here, and in case of failure of BFD_READ,
|
||||
we probably don't want to return true. */
|
||||
if (bfd_read ((PTR)nextname, 1, 16, abfd) == 16) {
|
||||
if (bfd_read ((PTR) nextname, 1, 16, abfd) == 16)
|
||||
{
|
||||
|
||||
bfd_seek (abfd, (file_ptr) - 16, SEEK_CUR);
|
||||
|
||||
@ -978,8 +1011,10 @@ _bfd_slurp_extended_name_table (abfd)
|
||||
if (namedata == NULL)
|
||||
return false;
|
||||
|
||||
bfd_ardata (abfd)->extended_names = bfd_zalloc(abfd,namedata->parsed_size);
|
||||
if (bfd_ardata (abfd)->extended_names == NULL) {
|
||||
bfd_ardata (abfd)->extended_names =
|
||||
bfd_zalloc (abfd, namedata->parsed_size);
|
||||
if (bfd_ardata (abfd)->extended_names == NULL)
|
||||
{
|
||||
bfd_error = no_memory;
|
||||
byebye:
|
||||
bfd_release (abfd, (PTR) namedata);
|
||||
@ -987,7 +1022,8 @@ _bfd_slurp_extended_name_table (abfd)
|
||||
}
|
||||
|
||||
if (bfd_read ((PTR) bfd_ardata (abfd)->extended_names, 1,
|
||||
namedata->parsed_size, abfd) != namedata->parsed_size) {
|
||||
namedata->parsed_size, abfd) != namedata->parsed_size)
|
||||
{
|
||||
bfd_error = malformed_archive;
|
||||
bfd_release (abfd, (PTR) (bfd_ardata (abfd)->extended_names));
|
||||
bfd_ardata (abfd)->extended_names = NULL;
|
||||
@ -1060,22 +1096,22 @@ normalize (file)
|
||||
{
|
||||
CONST char *filename = strrchr (file, '/');
|
||||
|
||||
if (filename != (char *)NULL) {
|
||||
if (filename != (char *) NULL)
|
||||
filename++;
|
||||
}
|
||||
else {
|
||||
else
|
||||
filename = file;
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
#endif
|
||||
/* Follows archive_head and produces an extended name table if necessary.
|
||||
Returns (in tabloc) a pointer to an extended name table, and in tablen
|
||||
the length of the table. If it makes an entry it clobbers the filename
|
||||
so that the element may be written without further massage.
|
||||
Returns true if it ran successfully, false if something went wrong.
|
||||
A successful return may still involve a zero-length tablen!
|
||||
*/
|
||||
|
||||
/* Follows archive_head and produces an extended name table if
|
||||
necessary. Returns (in tabloc) a pointer to an extended name
|
||||
table, and in tablen the length of the table. If it makes an entry
|
||||
it clobbers the filename so that the element may be written without
|
||||
further massage. Returns true if it ran successfully, false if
|
||||
something went wrong. A successful return may still involve a
|
||||
zero-length tablen! */
|
||||
|
||||
static boolean
|
||||
bfd_construct_extended_name_table (abfd, tabloc, tablen)
|
||||
bfd *abfd;
|
||||
@ -1090,15 +1126,19 @@ bfd_construct_extended_name_table (abfd, tabloc, tablen)
|
||||
*tablen = 0;
|
||||
|
||||
/* Figure out how long the table should be */
|
||||
for (current = abfd->archive_head; current != NULL; current = current->next){
|
||||
for (current = abfd->archive_head; current != NULL; current = current->next)
|
||||
{
|
||||
unsigned int thislen = strlen (normalize (current->filename));
|
||||
if (thislen > maxname) total_namelen += thislen + 1; /* leave room for \n */
|
||||
if (thislen > maxname)
|
||||
total_namelen += thislen + 1; /* leave room for \n */
|
||||
}
|
||||
|
||||
if (total_namelen == 0) return true;
|
||||
if (total_namelen == 0)
|
||||
return true;
|
||||
|
||||
*tabloc = bfd_zalloc (abfd, total_namelen);
|
||||
if (*tabloc == NULL) {
|
||||
if (*tabloc == NULL)
|
||||
{
|
||||
bfd_error = no_memory;
|
||||
return false;
|
||||
}
|
||||
@ -1107,25 +1147,29 @@ bfd_construct_extended_name_table (abfd, tabloc, tablen)
|
||||
strptr = *tabloc;
|
||||
|
||||
for (current = abfd->archive_head; current != NULL; current =
|
||||
current->next) {
|
||||
current->next)
|
||||
{
|
||||
CONST char *normal = normalize (current->filename);
|
||||
unsigned int thislen = strlen (normal);
|
||||
if (thislen > maxname) {
|
||||
/* Works for now; may need to be re-engineered if we encounter an oddball
|
||||
archive format and want to generalise this hack. */
|
||||
if (thislen > maxname)
|
||||
{
|
||||
/* Works for now; may need to be re-engineered if we
|
||||
encounter an oddball archive format and want to
|
||||
generalise this hack. */
|
||||
struct ar_hdr *hdr = arch_hdr (current);
|
||||
strcpy (strptr, normal);
|
||||
strptr[thislen] = '\n';
|
||||
hdr->ar_name[0] = ' ';
|
||||
/* We know there will always be enough room (one of the few cases
|
||||
where you may safely use sprintf). */
|
||||
/* We know there will always be enough room (one of the few
|
||||
cases where you may safely use sprintf). */
|
||||
sprintf ((hdr->ar_name) + 1, "%-d", (unsigned) (strptr - *tabloc));
|
||||
/* Kinda Kludgy. We should just use the returned value of sprintf
|
||||
but not all implementations get this right */
|
||||
/* Kinda Kludgy. We should just use the returned value of
|
||||
sprintf but not all implementations get this right */
|
||||
{
|
||||
char *temp = hdr->ar_name + 2;
|
||||
for (; temp < hdr->ar_name + maxname; temp++)
|
||||
if (*temp == '\0') *temp = ' ';
|
||||
if (*temp == '\0')
|
||||
*temp = ' ';
|
||||
}
|
||||
strptr += thislen + 1;
|
||||
}
|
||||
@ -1136,10 +1180,9 @@ bfd_construct_extended_name_table (abfd, tabloc, tablen)
|
||||
|
||||
/** A couple of functions for creating ar_hdrs */
|
||||
|
||||
/* Takes a filename, returns an arelt_data for it, or NULL if it can't make one.
|
||||
The filename must refer to a filename in the filesystem.
|
||||
The filename field of the ar_hdr will NOT be initialized
|
||||
*/
|
||||
/* Takes a filename, returns an arelt_data for it, or NULL if it can't
|
||||
make one. The filename must refer to a filename in the filesystem.
|
||||
The filename field of the ar_hdr will NOT be initialized */
|
||||
|
||||
static struct areltdata *
|
||||
bfd_ar_hdr_from_filesystem (abfd, filename)
|
||||
@ -1151,14 +1194,16 @@ bfd_ar_hdr_from_filesystem (abfd,filename)
|
||||
struct ar_hdr *hdr;
|
||||
char *temp, *temp1;
|
||||
|
||||
if (stat (filename, &status) != 0) {
|
||||
if (stat (filename, &status) != 0)
|
||||
{
|
||||
bfd_error = system_call_error;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ared = (struct areltdata *) bfd_zalloc (abfd, sizeof (struct ar_hdr) +
|
||||
sizeof (struct areltdata));
|
||||
if (ared == NULL) {
|
||||
if (ared == NULL)
|
||||
{
|
||||
bfd_error = no_memory;
|
||||
return NULL;
|
||||
}
|
||||
@ -1180,8 +1225,10 @@ bfd_ar_hdr_from_filesystem (abfd,filename)
|
||||
IO operations */
|
||||
temp = (char *) hdr;
|
||||
temp1 = temp + sizeof (struct ar_hdr) - 2;
|
||||
for (; temp < temp1; temp++) {
|
||||
if (*temp == '\0') *temp = ' ';
|
||||
for (; temp < temp1; temp++)
|
||||
{
|
||||
if (*temp == '\0')
|
||||
*temp = ' ';
|
||||
}
|
||||
strncpy (hdr->ar_fmag, ARFMAG, 2);
|
||||
ared->parsed_size = status.st_size;
|
||||
@ -1191,10 +1238,9 @@ bfd_ar_hdr_from_filesystem (abfd,filename)
|
||||
}
|
||||
|
||||
/* This is magic required by the "ar" program. Since it's
|
||||
undocumented, it's undocumented. You may think that it would
|
||||
take a strong stomach to write this, and it does, but it takes
|
||||
even a stronger stomach to try to code around such a thing!
|
||||
*/
|
||||
undocumented, it's undocumented. You may think that it would take
|
||||
a strong stomach to write this, and it does, but it takes even a
|
||||
stronger stomach to try to code around such a thing! */
|
||||
|
||||
struct ar_hdr *
|
||||
bfd_special_undocumented_glue (abfd, filename)
|
||||
@ -1217,7 +1263,8 @@ bfd_generic_stat_arch_elt (abfd, buf)
|
||||
struct ar_hdr *hdr;
|
||||
char *aloser;
|
||||
|
||||
if (abfd->arelt_data == NULL) {
|
||||
if (abfd->arelt_data == NULL)
|
||||
{
|
||||
bfd_error = invalid_operation;
|
||||
return -1;
|
||||
}
|
||||
@ -1259,9 +1306,8 @@ bfd_dont_truncate_arname (abfd, pathname, arhdr)
|
||||
if (length <= maxlen)
|
||||
memcpy (hdr->ar_name, filename, length);
|
||||
|
||||
if (length < maxlen) (hdr->ar_name)[length] = ar_padchar (abfd);
|
||||
return;
|
||||
|
||||
if (length < maxlen)
|
||||
(hdr->ar_name)[length] = ar_padchar (abfd);
|
||||
}
|
||||
|
||||
void
|
||||
@ -1275,7 +1321,6 @@ bfd_bsd_truncate_arname (abfd, pathname, arhdr)
|
||||
CONST char *filename = strrchr (pathname, '/');
|
||||
int maxlen = ar_maxnamelen (abfd);
|
||||
|
||||
|
||||
if (filename == NULL)
|
||||
filename = pathname;
|
||||
else
|
||||
@ -1285,7 +1330,8 @@ bfd_bsd_truncate_arname (abfd, pathname, arhdr)
|
||||
|
||||
if (length <= maxlen)
|
||||
memcpy (hdr->ar_name, filename, length);
|
||||
else {
|
||||
else
|
||||
{
|
||||
/* pathname: meet procrustes */
|
||||
memcpy (hdr->ar_name, filename, maxlen);
|
||||
length = maxlen;
|
||||
@ -1299,10 +1345,11 @@ bfd_bsd_truncate_arname (abfd, pathname, arhdr)
|
||||
1> strip pathname to be just the basename.
|
||||
2> if it's short enuf to fit, stuff it in.
|
||||
3> If it doesn't end with .o, truncate it to fit
|
||||
4> truncate it before the .o, append .o, stuff THAT in.
|
||||
*/
|
||||
4> truncate it before the .o, append .o, stuff THAT in. */
|
||||
|
||||
/* This is what gnu ar does. It's better but incompatible with the
|
||||
bsd ar. */
|
||||
|
||||
/* This is what gnu ar does. It's better but incompatible with the bsd ar. */
|
||||
void
|
||||
bfd_gnu_truncate_arname (abfd, pathname, arhdr)
|
||||
bfd *abfd;
|
||||
@ -1323,9 +1370,11 @@ bfd_gnu_truncate_arname (abfd, pathname, arhdr)
|
||||
|
||||
if (length <= maxlen)
|
||||
memcpy (hdr->ar_name, filename, length);
|
||||
else { /* pathname: meet procrustes */
|
||||
else
|
||||
{ /* pathname: meet procrustes */
|
||||
memcpy (hdr->ar_name, filename, maxlen);
|
||||
if ((filename[length - 2] == '.') && (filename[length - 1] == 'o')) {
|
||||
if ((filename[length - 2] == '.') && (filename[length - 1] == 'o'))
|
||||
{
|
||||
hdr->ar_name[maxlen - 2] = '.';
|
||||
hdr->ar_name[maxlen - 1] = 'o';
|
||||
}
|
||||
@ -1336,8 +1385,8 @@ bfd_gnu_truncate_arname (abfd, pathname, arhdr)
|
||||
(hdr->ar_name)[length] = ar_padchar (abfd);
|
||||
}
|
||||
|
||||
|
||||
/* The BFD is open for write and has its format set to bfd_archive */
|
||||
|
||||
boolean
|
||||
_bfd_write_archive_contents (arch)
|
||||
bfd *arch;
|
||||
@ -1352,28 +1401,29 @@ _bfd_write_archive_contents (arch)
|
||||
|
||||
/* Verify the viability of all entries; if any of them live in the
|
||||
filesystem (as opposed to living in an archive open for input)
|
||||
then construct a fresh ar_hdr for them.
|
||||
*/
|
||||
for (current = arch->archive_head; current; current = current->next) {
|
||||
if (bfd_write_p (current)) {
|
||||
then construct a fresh ar_hdr for them. */
|
||||
for (current = arch->archive_head; current; current = current->next)
|
||||
{
|
||||
if (bfd_write_p (current))
|
||||
{
|
||||
bfd_error = invalid_operation;
|
||||
return false;
|
||||
}
|
||||
if (!current->arelt_data) {
|
||||
if (!current->arelt_data)
|
||||
{
|
||||
current->arelt_data =
|
||||
(PTR) bfd_ar_hdr_from_filesystem (arch, current->filename);
|
||||
if (!current->arelt_data) return false;
|
||||
if (!current->arelt_data)
|
||||
return false;
|
||||
|
||||
/* Put in the file name */
|
||||
|
||||
BFD_SEND (arch, _bfd_truncate_arname, (arch,
|
||||
current->filename,
|
||||
(char *) arch_hdr (current)));
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (makemap) { /* don't bother if we won't make a map! */
|
||||
if (makemap)
|
||||
{ /* don't bother if we won't make a map! */
|
||||
if ((bfd_check_format (current, bfd_object))
|
||||
#if 0 /* FIXME -- these are not set correctly */
|
||||
&& ((bfd_get_file_flags (current) & HAS_SYMS))
|
||||
@ -1393,68 +1443,77 @@ _bfd_write_archive_contents (arch)
|
||||
bfd_write (ARMAG, 1, SARMAG, arch);
|
||||
#endif
|
||||
|
||||
if (makemap && hasobjects) {
|
||||
|
||||
if (compute_and_write_armap (arch, elength) != true) {
|
||||
if (makemap && hasobjects)
|
||||
{
|
||||
if (compute_and_write_armap (arch, elength) != true)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (elength != 0) {
|
||||
if (elength != 0)
|
||||
{
|
||||
struct ar_hdr hdr;
|
||||
|
||||
memset ((char *) (&hdr), 0, sizeof (struct ar_hdr));
|
||||
sprintf (&(hdr.ar_name[0]), "ARFILENAMES/");
|
||||
sprintf (&(hdr.ar_size[0]), "%-10d", (int) elength);
|
||||
hdr.ar_fmag[0] = '`'; hdr.ar_fmag[1] = '\n';
|
||||
hdr.ar_fmag[0] = '`';
|
||||
hdr.ar_fmag[1] = '\n';
|
||||
for (i = 0; i < sizeof (struct ar_hdr); i++)
|
||||
if (((char *)(&hdr))[i] == '\0') (((char *)(&hdr))[i]) = ' ';
|
||||
if (((char *) (&hdr))[i] == '\0')
|
||||
(((char *) (&hdr))[i]) = ' ';
|
||||
bfd_write ((char *) &hdr, 1, sizeof (struct ar_hdr), arch);
|
||||
bfd_write (etable, 1, elength, arch);
|
||||
if ((elength % 2) == 1) bfd_write ("\n", 1, 1, arch);
|
||||
|
||||
if ((elength % 2) == 1)
|
||||
bfd_write ("\n", 1, 1, arch);
|
||||
}
|
||||
|
||||
for (current = arch->archive_head; current; current = current->next) {
|
||||
for (current = arch->archive_head; current; current = current->next)
|
||||
{
|
||||
char buffer[DEFAULT_BUFFERSIZE];
|
||||
unsigned int remaining = arelt_size (current);
|
||||
struct ar_hdr *hdr = arch_hdr (current);
|
||||
/* write ar header */
|
||||
|
||||
if (bfd_write ((char *)hdr, 1, sizeof(*hdr), arch) != sizeof(*hdr)) {
|
||||
/* write ar header */
|
||||
if (bfd_write ((char *) hdr, 1, sizeof (*hdr), arch) != sizeof (*hdr))
|
||||
{
|
||||
syserr:
|
||||
bfd_error = system_call_error;
|
||||
return false;
|
||||
}
|
||||
if (bfd_seek (current, (file_ptr) 0, SEEK_SET) != 0) goto syserr;
|
||||
if (bfd_seek (current, (file_ptr) 0, SEEK_SET) != 0)
|
||||
goto syserr;
|
||||
while (remaining)
|
||||
{
|
||||
unsigned int amt = DEFAULT_BUFFERSIZE;
|
||||
if (amt > remaining) {
|
||||
if (amt > remaining)
|
||||
amt = remaining;
|
||||
}
|
||||
errno = 0;
|
||||
if (bfd_read (buffer, amt, 1, current) != amt) {
|
||||
if (errno) goto syserr;
|
||||
if (bfd_read (buffer, amt, 1, current) != amt)
|
||||
{
|
||||
if (errno)
|
||||
goto syserr;
|
||||
/* Looks like a truncated archive. */
|
||||
bfd_error = malformed_archive;
|
||||
return false;
|
||||
}
|
||||
if (bfd_write (buffer, amt, 1, arch) != amt) goto syserr;
|
||||
if (bfd_write (buffer, amt, 1, arch) != amt)
|
||||
goto syserr;
|
||||
remaining -= amt;
|
||||
}
|
||||
if ((arelt_size (current) % 2) == 1) bfd_write ("\n", 1, 1, arch);
|
||||
if ((arelt_size (current) % 2) == 1)
|
||||
bfd_write ("\n", 1, 1, arch);
|
||||
}
|
||||
|
||||
/* Verify the timestamp in the archive file. If it would
|
||||
not be accepted by the linker, rewrite it until it would be.
|
||||
If anything odd happens, break out and just return.
|
||||
(The Berkeley linker checks the timestamp and refuses to read the
|
||||
/* Verify the timestamp in the archive file. If it would not be
|
||||
accepted by the linker, rewrite it until it would be. If
|
||||
anything odd happens, break out and just return. (The Berkeley
|
||||
linker checks the timestamp and refuses to read the
|
||||
table-of-contents if it is >60 seconds less than the file's
|
||||
modified-time. That painful hack requires this painful hack. */
|
||||
|
||||
tries = 1;
|
||||
do {
|
||||
do
|
||||
{
|
||||
/* FIXME! This kludge is to avoid adding a member to the xvec,
|
||||
while generating a small patch for Adobe. FIXME! The
|
||||
update_armap_timestamp function call should be in the xvec,
|
||||
@ -1463,7 +1522,8 @@ _bfd_write_archive_contents (arch)
|
||||
if (bfd_update_armap_timestamp (arch) == true) break;
|
||||
^
|
||||
|
||||
Instead, we check whether in a BSD archive, and call directly. */
|
||||
Instead, we check whether in a BSD archive, and call
|
||||
directly. */
|
||||
|
||||
if (arch->xvec->write_armap != bsd_write_armap)
|
||||
break;
|
||||
@ -1472,7 +1532,8 @@ _bfd_write_archive_contents (arch)
|
||||
if (tries > 0)
|
||||
fprintf (stderr,
|
||||
"Warning: writing archive was slow: rewriting timestamp\n");
|
||||
} while (++tries < 6 );
|
||||
}
|
||||
while (++tries < 6);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1492,11 +1553,13 @@ compute_and_write_armap (arch, elength)
|
||||
int stridx = 0; /* string index */
|
||||
|
||||
/* Dunno if this is the best place for this info... */
|
||||
if (elength != 0) elength += sizeof (struct ar_hdr);
|
||||
if (elength != 0)
|
||||
elength += sizeof (struct ar_hdr);
|
||||
elength += elength % 2;
|
||||
|
||||
map = (struct orl *) bfd_zalloc (arch, orl_max * sizeof (struct orl));
|
||||
if (map == NULL) {
|
||||
if (map == NULL)
|
||||
{
|
||||
bfd_error = no_memory;
|
||||
return false;
|
||||
}
|
||||
@ -1505,26 +1568,27 @@ compute_and_write_armap (arch, elength)
|
||||
own */
|
||||
while (arch->archive_head &&
|
||||
strcmp (arch->archive_head->filename, "__.SYMDEF") == 0)
|
||||
{
|
||||
arch->archive_head = arch->archive_head->next;
|
||||
}
|
||||
|
||||
/* Map over each element */
|
||||
for (current = arch->archive_head;
|
||||
current != (bfd *) NULL;
|
||||
current = current->next, elt_no++)
|
||||
{
|
||||
if ((bfd_check_format (current, bfd_object) == true)
|
||||
&& ((bfd_get_file_flags (current) & HAS_SYMS))) {
|
||||
&& ((bfd_get_file_flags (current) & HAS_SYMS)))
|
||||
{
|
||||
asymbol **syms;
|
||||
unsigned int storage;
|
||||
unsigned int symcount;
|
||||
unsigned int src_count;
|
||||
|
||||
storage = get_symtab_upper_bound (current);
|
||||
if (storage != 0) {
|
||||
|
||||
if (storage != 0)
|
||||
{
|
||||
syms = (asymbol **) bfd_zalloc (arch, storage);
|
||||
if (syms == NULL) {
|
||||
if (syms == NULL)
|
||||
{
|
||||
bfd_error = no_memory; /* FIXME -- memory leak */
|
||||
return false;
|
||||
}
|
||||
@ -1532,7 +1596,8 @@ compute_and_write_armap (arch, elength)
|
||||
|
||||
|
||||
/* Now map over all the symbols, picking out the ones we want */
|
||||
for (src_count = 0; src_count <symcount; src_count++) {
|
||||
for (src_count = 0; src_count < symcount; src_count++)
|
||||
{
|
||||
flagword flags =
|
||||
(syms[src_count])->flags;
|
||||
asection *sec =
|
||||
@ -1542,17 +1607,19 @@ compute_and_write_armap (arch, elength)
|
||||
flags & BSF_WEAK ||
|
||||
flags & BSF_INDIRECT ||
|
||||
bfd_is_com_section (sec))
|
||||
&& (sec != &bfd_und_section)) {
|
||||
|
||||
&& (sec != &bfd_und_section))
|
||||
{
|
||||
/* This symbol will go into the archive header */
|
||||
if (orl_count == orl_max)
|
||||
{
|
||||
orl_max *= 2;
|
||||
map = (struct orl *) bfd_realloc (arch, (char *) map,
|
||||
orl_max * sizeof (struct orl));
|
||||
map = ((struct orl *)
|
||||
bfd_realloc (arch, (char *) map,
|
||||
orl_max * sizeof (struct orl)));
|
||||
}
|
||||
|
||||
(map[orl_count]).name = (char **) &((syms[src_count])->name);
|
||||
(map[orl_count]).name =
|
||||
(char **) &((syms[src_count])->name);
|
||||
(map[orl_count]).pos = (file_ptr) current;
|
||||
(map[orl_count]).namidx = stridx;
|
||||
|
||||
@ -1563,13 +1630,11 @@ compute_and_write_armap (arch, elength)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* OK, now we have collected all the data, let's write them out */
|
||||
if (!BFD_SEND (arch, write_armap,
|
||||
(arch, elength, map, orl_count, stridx))) {
|
||||
|
||||
(arch, elength, map, orl_count, stridx)))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1603,29 +1668,35 @@ bsd_write_armap (arch, elength, map, orl_count, stridx)
|
||||
sprintf (hdr.ar_name, RANLIBMAG);
|
||||
/* Remember the timestamp, to keep it holy. But fudge it a little. */
|
||||
bfd_ardata (arch)->armap_timestamp = statbuf.st_mtime + ARMAP_TIME_OFFSET;
|
||||
bfd_ardata(arch)->armap_datepos = SARMAG +
|
||||
offsetof(struct ar_hdr, ar_date[0]);
|
||||
bfd_ardata (arch)->armap_datepos = (SARMAG
|
||||
+ offsetof (struct ar_hdr, ar_date[0]));
|
||||
sprintf (hdr.ar_date, "%ld", bfd_ardata (arch)->armap_timestamp);
|
||||
sprintf (hdr.ar_uid, "%d", getuid ());
|
||||
sprintf (hdr.ar_gid, "%d", getgid ());
|
||||
sprintf (hdr.ar_size, "%-10d", (int) mapsize);
|
||||
hdr.ar_fmag[0] = '`'; hdr.ar_fmag[1] = '\n';
|
||||
hdr.ar_fmag[0] = '`';
|
||||
hdr.ar_fmag[1] = '\n';
|
||||
for (i = 0; i < sizeof (struct ar_hdr); i++)
|
||||
if (((char *)(&hdr))[i] == '\0') (((char *)(&hdr))[i]) = ' ';
|
||||
if (((char *) (&hdr))[i] == '\0')
|
||||
(((char *) (&hdr))[i]) = ' ';
|
||||
bfd_write ((char *) &hdr, 1, sizeof (struct ar_hdr), arch);
|
||||
bfd_h_put_32 (arch, (bfd_vma) ranlibsize, (PTR) & temp);
|
||||
bfd_write (&temp, 1, sizeof (temp), arch);
|
||||
|
||||
for (count = 0; count < orl_count; count++) {
|
||||
for (count = 0; count < orl_count; count++)
|
||||
{
|
||||
struct symdef outs;
|
||||
struct symdef *outp = &outs;
|
||||
|
||||
if (((bfd *)(map[count]).pos) != last_elt) {
|
||||
do {
|
||||
if (((bfd *) (map[count]).pos) != last_elt)
|
||||
{
|
||||
do
|
||||
{
|
||||
firstreal += arelt_size (current) + sizeof (struct ar_hdr);
|
||||
firstreal += firstreal % 2;
|
||||
current = current->next;
|
||||
} while (current != (bfd *)(map[count]).pos);
|
||||
}
|
||||
while (current != (bfd *) (map[count]).pos);
|
||||
} /* if new archive element */
|
||||
|
||||
last_elt = current;
|
||||
@ -1648,7 +1719,6 @@ bsd_write_armap (arch, elength, map, orl_count, stridx)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* At the end of archive file handling, update the timestamp in the
|
||||
file, so the linker will accept it.
|
||||
|
||||
@ -1666,7 +1736,8 @@ bsd_update_armap_timestamp (arch)
|
||||
/* Flush writes, get last-write timestamp from file, and compare it
|
||||
to the timestamp IN the file. */
|
||||
bfd_flush (arch);
|
||||
if (bfd_stat (arch, &archstat) == -1) {
|
||||
if (bfd_stat (arch, &archstat) == -1)
|
||||
{
|
||||
perror ("Reading archive file mod timestamp");
|
||||
return true; /* Can't read mod time for some reason */
|
||||
}
|
||||
@ -1686,7 +1757,8 @@ bsd_update_armap_timestamp (arch)
|
||||
/* Write it into the file. */
|
||||
bfd_seek (arch, bfd_ardata (arch)->armap_datepos, SEEK_SET);
|
||||
if (bfd_write (hdr.ar_date, sizeof (hdr.ar_date), 1, arch)
|
||||
!= sizeof(hdr.ar_date)) {
|
||||
!= sizeof (hdr.ar_date))
|
||||
{
|
||||
perror ("Writing updated armap timestamp");
|
||||
return true; /* Some error while writing */
|
||||
}
|
||||
@ -1694,7 +1766,6 @@ bsd_update_armap_timestamp (arch)
|
||||
return false; /* We updated the timestamp successfully. */
|
||||
}
|
||||
|
||||
|
||||
/* A coff armap looks like :
|
||||
lARMAG
|
||||
struct ar_hdr with name = '/'
|
||||
@ -1707,7 +1778,6 @@ bsd_update_armap_timestamp (arch)
|
||||
symbol name 1
|
||||
|
||||
symbol name n-1
|
||||
|
||||
*/
|
||||
|
||||
boolean
|
||||
@ -1720,7 +1790,6 @@ coff_write_armap (arch, elength, map, symbol_count, stridx)
|
||||
{
|
||||
/* The size of the ranlib is the number of exported symbols in the
|
||||
archive * the number of bytes in a int, + an int for the count */
|
||||
|
||||
unsigned int ranlibsize = (symbol_count * 4) + 4;
|
||||
unsigned int stringsize = stridx;
|
||||
unsigned int mapsize = stringsize + ranlibsize;
|
||||
@ -1731,10 +1800,14 @@ coff_write_armap (arch, elength, map, symbol_count, stridx)
|
||||
unsigned int i;
|
||||
int padit = mapsize & 1;
|
||||
|
||||
if (padit) mapsize ++;
|
||||
if (padit)
|
||||
mapsize++;
|
||||
|
||||
/* work out where the first object file will go in the archive */
|
||||
archive_member_file_ptr = mapsize + elength + sizeof (struct ar_hdr) + SARMAG;
|
||||
archive_member_file_ptr = (mapsize
|
||||
+ elength
|
||||
+ sizeof (struct ar_hdr)
|
||||
+ SARMAG);
|
||||
|
||||
memset ((char *) (&hdr), 0, sizeof (struct ar_hdr));
|
||||
hdr.ar_name[0] = '/';
|
||||
@ -1744,14 +1817,15 @@ coff_write_armap (arch, elength, map, symbol_count, stridx)
|
||||
sprintf ((hdr.ar_uid), "%d", 0);
|
||||
sprintf ((hdr.ar_gid), "%d", 0);
|
||||
sprintf ((hdr.ar_mode), "%-7o", (unsigned) 0);
|
||||
hdr.ar_fmag[0] = '`'; hdr.ar_fmag[1] = '\n';
|
||||
hdr.ar_fmag[0] = '`';
|
||||
hdr.ar_fmag[1] = '\n';
|
||||
|
||||
for (i = 0; i < sizeof (struct ar_hdr); i++)
|
||||
if (((char *)(&hdr))[i] == '\0') (((char *)(&hdr))[i]) = ' ';
|
||||
if (((char *) (&hdr))[i] == '\0')
|
||||
(((char *) (&hdr))[i]) = ' ';
|
||||
|
||||
/* Write the ar header for this item and the number of symbols */
|
||||
|
||||
|
||||
bfd_write ((PTR) & hdr, 1, sizeof (struct ar_hdr), arch);
|
||||
|
||||
bfd_write_bigendian_4byte_int (arch, symbol_count);
|
||||
@ -1764,11 +1838,13 @@ coff_write_armap (arch, elength, map, symbol_count, stridx)
|
||||
|
||||
current = arch->archive_head;
|
||||
count = 0;
|
||||
while (current != (bfd *)NULL && count < symbol_count) {
|
||||
while (current != (bfd *) NULL && count < symbol_count)
|
||||
{
|
||||
/* For each symbol which is used defined in this object, write out
|
||||
the object file's address in the archive */
|
||||
|
||||
while (((bfd *)(map[count]).pos) == current) {
|
||||
while (((bfd *) (map[count]).pos) == current)
|
||||
{
|
||||
bfd_write_bigendian_4byte_int (arch, archive_member_file_ptr);
|
||||
count++;
|
||||
}
|
||||
@ -1780,15 +1856,12 @@ coff_write_armap (arch, elength, map, symbol_count, stridx)
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* now write the strings themselves */
|
||||
for (count = 0; count < symbol_count; count++) {
|
||||
for (count = 0; count < symbol_count; count++)
|
||||
bfd_write ((PTR) * ((map[count]).name),
|
||||
1,
|
||||
strlen (*((map[count]).name)) + 1, arch);
|
||||
|
||||
}
|
||||
/* The spec sez this should be a newline. But in order to be
|
||||
bug-compatible for arc960 we use a null. */
|
||||
if (padit)
|
||||
|
Loading…
Reference in New Issue
Block a user