xref: /dflybsd-src/contrib/gcc-4.7/gcc/collect2-aix.c (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino /* AIX cross support for collect2.
2*e4b17023SJohn Marino    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
3*e4b17023SJohn Marino 
4*e4b17023SJohn Marino This file is part of GCC.
5*e4b17023SJohn Marino 
6*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under
7*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free
8*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later
9*e4b17023SJohn Marino version.
10*e4b17023SJohn Marino 
11*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or
13*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14*e4b17023SJohn Marino for more details.
15*e4b17023SJohn Marino 
16*e4b17023SJohn Marino You should have received a copy of the GNU General Public License
17*e4b17023SJohn Marino along with GCC; see the file COPYING3.  If not see
18*e4b17023SJohn Marino <http://www.gnu.org/licenses/>.  */
19*e4b17023SJohn Marino 
20*e4b17023SJohn Marino #include "config.h"
21*e4b17023SJohn Marino #include "system.h"
22*e4b17023SJohn Marino #include "coretypes.h"
23*e4b17023SJohn Marino #include "tm.h"
24*e4b17023SJohn Marino #include "collect2-aix.h"
25*e4b17023SJohn Marino 
26*e4b17023SJohn Marino #ifdef CROSS_AIX_SUPPORT
27*e4b17023SJohn Marino 
28*e4b17023SJohn Marino /* Read SIZE bytes starting at DATA as a big-endian value.  */
29*e4b17023SJohn Marino 
30*e4b17023SJohn Marino static inline bfd_vma
read_value(char * data,unsigned int size)31*e4b17023SJohn Marino read_value (char *data, unsigned int size)
32*e4b17023SJohn Marino {
33*e4b17023SJohn Marino   bfd_vma value;
34*e4b17023SJohn Marino   unsigned int i;
35*e4b17023SJohn Marino 
36*e4b17023SJohn Marino   value = 0;
37*e4b17023SJohn Marino   for (i = 0; i < size; i++)
38*e4b17023SJohn Marino     {
39*e4b17023SJohn Marino       value <<= 8;
40*e4b17023SJohn Marino       value += (unsigned char) data[i];
41*e4b17023SJohn Marino     }
42*e4b17023SJohn Marino   return value;
43*e4b17023SJohn Marino }
44*e4b17023SJohn Marino 
45*e4b17023SJohn Marino /* FIELD is a char array.  Read the contents as a big-endian integer.  */
46*e4b17023SJohn Marino #define READ_FIELD(FIELD) \
47*e4b17023SJohn Marino   read_value (FIELD, sizeof (FIELD))
48*e4b17023SJohn Marino 
49*e4b17023SJohn Marino /* OBJECT is a char pointer to an in-file object of type struct TYPE.
50*e4b17023SJohn Marino    Return the address of field FIELD.  */
51*e4b17023SJohn Marino #define OBJECT_FIELD(OBJECT, TYPE, FIELD) \
52*e4b17023SJohn Marino   (OBJECT) + offsetof (struct TYPE, FIELD)
53*e4b17023SJohn Marino 
54*e4b17023SJohn Marino /* Return the size of FIELD, which is a field of struct TYPE.  */
55*e4b17023SJohn Marino #define FIELD_SIZE(TYPE, FIELD) \
56*e4b17023SJohn Marino   sizeof (((struct TYPE *) (0))->FIELD)
57*e4b17023SJohn Marino 
58*e4b17023SJohn Marino /* OBJECT is a char pointer to an in-file object of type struct TYPE.
59*e4b17023SJohn Marino    Read the value of field FIELD as a big-endian integer.  */
60*e4b17023SJohn Marino #define READ_OBJECT(OBJECT, TYPE, FIELD) \
61*e4b17023SJohn Marino   read_value (OBJECT_FIELD (OBJECT, TYPE, FIELD), FIELD_SIZE (TYPE, FIELD))
62*e4b17023SJohn Marino 
63*e4b17023SJohn Marino /* Copy FIELD from an external structure of type TYPE at address FROM
64*e4b17023SJohn Marino    to an internal structure pointed to by TO.  */
65*e4b17023SJohn Marino #define COPY_FIELD(TO, FROM, TYPE, FIELD) \
66*e4b17023SJohn Marino   ((TO)->FIELD = READ_OBJECT (FROM, TYPE, FIELD))
67*e4b17023SJohn Marino 
68*e4b17023SJohn Marino /* Return true if STRING is less than SIZE bytes long.  EXTRA_TERMINATOR
69*e4b17023SJohn Marino    is another character (besides '\0') that acts as a terminator,
70*e4b17023SJohn Marino    or '\0' if none.  */
71*e4b17023SJohn Marino 
72*e4b17023SJohn Marino static bool
string_within_bounds_p(const char * string,size_t size,char extra_terminator)73*e4b17023SJohn Marino string_within_bounds_p (const char *string, size_t size, char extra_terminator)
74*e4b17023SJohn Marino {
75*e4b17023SJohn Marino   const char *p;
76*e4b17023SJohn Marino 
77*e4b17023SJohn Marino   for (p = string; p < string + size; p++)
78*e4b17023SJohn Marino     if (*p == '\0' || *p == extra_terminator)
79*e4b17023SJohn Marino       return true;
80*e4b17023SJohn Marino   return false;
81*e4b17023SJohn Marino }
82*e4b17023SJohn Marino 
83*e4b17023SJohn Marino /* STRING is a pointer to a char array.  Try to read its value as an
84*e4b17023SJohn Marino    ASCII-encoded integer.  On success, return true and store the result
85*e4b17023SJohn Marino    in TARGET.  */
86*e4b17023SJohn Marino #define PARSE_INTEGER(TARGET, STRING) \
87*e4b17023SJohn Marino   (string_within_bounds_p (&(STRING)[0], sizeof (STRING), ' ') \
88*e4b17023SJohn Marino    && ((TARGET) = strtoul (STRING, NULL, 0), true))
89*e4b17023SJohn Marino 
90*e4b17023SJohn Marino /* Check that LDFILE's current object has SIZE bytes starting at OFFSET.  */
91*e4b17023SJohn Marino 
92*e4b17023SJohn Marino static inline bool
within_object_p(LDFILE * ldfile,size_t offset,size_t size)93*e4b17023SJohn Marino within_object_p (LDFILE *ldfile, size_t offset, size_t size)
94*e4b17023SJohn Marino {
95*e4b17023SJohn Marino   return offset <= ldfile->object_size && offset + size <= ldfile->object_size;
96*e4b17023SJohn Marino }
97*e4b17023SJohn Marino 
98*e4b17023SJohn Marino /* Try to read the file header for an XCOFF object at OFFSET bytes into
99*e4b17023SJohn Marino    LDFILE.  The object is expected to be OBJECT_SIZE bytes in size.
100*e4b17023SJohn Marino    If the object is a member of an archive, NEXT_MEMBER is the offset
101*e4b17023SJohn Marino    of the next member, otherwise it is -1.
102*e4b17023SJohn Marino 
103*e4b17023SJohn Marino    Return true on success, recording the object information in LDFILE.  */
104*e4b17023SJohn Marino 
105*e4b17023SJohn Marino static bool
read_xcoff_object(LDFILE * ldfile,size_t offset,size_t object_size,off_t next_member)106*e4b17023SJohn Marino read_xcoff_object (LDFILE *ldfile, size_t offset, size_t object_size,
107*e4b17023SJohn Marino 		   off_t next_member)
108*e4b17023SJohn Marino {
109*e4b17023SJohn Marino   struct internal_filehdr *internal;
110*e4b17023SJohn Marino   char *external;
111*e4b17023SJohn Marino   void *map;
112*e4b17023SJohn Marino   size_t page_size;
113*e4b17023SJohn Marino 
114*e4b17023SJohn Marino   /* First try to map the file into memory.  */
115*e4b17023SJohn Marino   page_size = getpagesize ();
116*e4b17023SJohn Marino   ldfile->page_offset = offset & (page_size - 1);
117*e4b17023SJohn Marino   map = mmap (NULL, object_size + ldfile->page_offset, PROT_READ,
118*e4b17023SJohn Marino               MAP_SHARED, ldfile->fd, offset - ldfile->page_offset);
119*e4b17023SJohn Marino   if (map == MAP_FAILED)
120*e4b17023SJohn Marino     return false;
121*e4b17023SJohn Marino 
122*e4b17023SJohn Marino   /* Record the success.  */
123*e4b17023SJohn Marino   ldfile->object = (char *) map + ldfile->page_offset;
124*e4b17023SJohn Marino   ldfile->object_size = object_size;
125*e4b17023SJohn Marino   ldfile->next_member = next_member;
126*e4b17023SJohn Marino 
127*e4b17023SJohn Marino   /* Read the magic value to determine the type of file.  */
128*e4b17023SJohn Marino   if (!within_object_p (ldfile, 0, F_MAGIC_SIZE))
129*e4b17023SJohn Marino     return false;
130*e4b17023SJohn Marino 
131*e4b17023SJohn Marino   internal = &ldfile->filehdr;
132*e4b17023SJohn Marino   external = ldfile->object;
133*e4b17023SJohn Marino   internal->f_magic = read_value (external, F_MAGIC_SIZE);
134*e4b17023SJohn Marino   if (internal->f_magic == U802TOCMAGIC)
135*e4b17023SJohn Marino     {
136*e4b17023SJohn Marino       if (!within_object_p (ldfile, 0, sizeof (struct external_filehdr_32)))
137*e4b17023SJohn Marino 	return false;
138*e4b17023SJohn Marino 
139*e4b17023SJohn Marino       COPY_FIELD (internal, external, external_filehdr_32, f_nscns);
140*e4b17023SJohn Marino       COPY_FIELD (internal, external, external_filehdr_32, f_timdat);
141*e4b17023SJohn Marino       COPY_FIELD (internal, external, external_filehdr_32, f_symptr);
142*e4b17023SJohn Marino       COPY_FIELD (internal, external, external_filehdr_32, f_nsyms);
143*e4b17023SJohn Marino       COPY_FIELD (internal, external, external_filehdr_32, f_opthdr);
144*e4b17023SJohn Marino       COPY_FIELD (internal, external, external_filehdr_32, f_flags);
145*e4b17023SJohn Marino       return true;
146*e4b17023SJohn Marino     }
147*e4b17023SJohn Marino   else if (internal->f_magic == U803XTOCMAGIC
148*e4b17023SJohn Marino 	   || internal->f_magic == U64_TOCMAGIC)
149*e4b17023SJohn Marino     {
150*e4b17023SJohn Marino       if (!within_object_p (ldfile, 0, sizeof (struct external_filehdr_64)))
151*e4b17023SJohn Marino 	return false;
152*e4b17023SJohn Marino 
153*e4b17023SJohn Marino       COPY_FIELD (internal, external, external_filehdr_64, f_nscns);
154*e4b17023SJohn Marino       COPY_FIELD (internal, external, external_filehdr_64, f_timdat);
155*e4b17023SJohn Marino       COPY_FIELD (internal, external, external_filehdr_64, f_symptr);
156*e4b17023SJohn Marino       COPY_FIELD (internal, external, external_filehdr_64, f_nsyms);
157*e4b17023SJohn Marino       COPY_FIELD (internal, external, external_filehdr_64, f_opthdr);
158*e4b17023SJohn Marino       COPY_FIELD (internal, external, external_filehdr_64, f_flags);
159*e4b17023SJohn Marino       return true;
160*e4b17023SJohn Marino     }
161*e4b17023SJohn Marino   return false;
162*e4b17023SJohn Marino }
163*e4b17023SJohn Marino 
164*e4b17023SJohn Marino /* Try to read an archive member at OFFSET bytes into LDFILE.
165*e4b17023SJohn Marino    Return true on success, recording the member and object
166*e4b17023SJohn Marino    information in LDFILE.  */
167*e4b17023SJohn Marino 
168*e4b17023SJohn Marino static bool
read_archive_member(LDFILE * ldfile,size_t offset)169*e4b17023SJohn Marino read_archive_member (LDFILE *ldfile, size_t offset)
170*e4b17023SJohn Marino {
171*e4b17023SJohn Marino   struct external_big_ar_member member;
172*e4b17023SJohn Marino   size_t namlen;
173*e4b17023SJohn Marino   size_t size;
174*e4b17023SJohn Marino   off_t next_member;
175*e4b17023SJohn Marino 
176*e4b17023SJohn Marino   if (lseek (ldfile->fd, offset, SEEK_SET) >= 0
177*e4b17023SJohn Marino       && read (ldfile->fd, &member, sizeof (member)) == sizeof (member)
178*e4b17023SJohn Marino       && PARSE_INTEGER (namlen, member.ar_namlen)
179*e4b17023SJohn Marino       /* Stop once we reach the member table entry, which has a name
180*e4b17023SJohn Marino 	 of length 0.  */
181*e4b17023SJohn Marino       && namlen > 0
182*e4b17023SJohn Marino       && PARSE_INTEGER (size, member.ar_size)
183*e4b17023SJohn Marino       && PARSE_INTEGER (next_member, member.ar_nextoff))
184*e4b17023SJohn Marino     {
185*e4b17023SJohn Marino       /* The archive is followed by an even-padded name, then by
186*e4b17023SJohn Marino 	 a magic string of length SXCOFFARFMAG.  The object itself
187*e4b17023SJohn Marino 	 starts after that. */
188*e4b17023SJohn Marino       offset += sizeof (member) + namlen + SXCOFFARFMAG;
189*e4b17023SJohn Marino       offset += offset & 1;
190*e4b17023SJohn Marino       return read_xcoff_object (ldfile, offset, size, next_member);
191*e4b17023SJohn Marino     }
192*e4b17023SJohn Marino   return false;
193*e4b17023SJohn Marino }
194*e4b17023SJohn Marino 
195*e4b17023SJohn Marino /* Try to treat LDFILE as a non-empty big archive.  Return true
196*e4b17023SJohn Marino    on success, storing the member and object information for
197*e4b17023SJohn Marino    the first member in LDFILE.  */
198*e4b17023SJohn Marino 
199*e4b17023SJohn Marino static bool
read_big_archive(LDFILE * ldfile)200*e4b17023SJohn Marino read_big_archive (LDFILE *ldfile)
201*e4b17023SJohn Marino {
202*e4b17023SJohn Marino   struct external_big_ar_filehdr filehdr;
203*e4b17023SJohn Marino   size_t offset;
204*e4b17023SJohn Marino 
205*e4b17023SJohn Marino   return (lseek (ldfile->fd, 0L, SEEK_SET) == 0
206*e4b17023SJohn Marino 	  && read (ldfile->fd, &filehdr, sizeof (filehdr)) == sizeof (filehdr)
207*e4b17023SJohn Marino 	  && memcmp (filehdr.fl_magic, FL_MAGIC_BIG_AR, FL_MAGIC_SIZE) == 0
208*e4b17023SJohn Marino 	  && PARSE_INTEGER (offset, filehdr.fl_firstmemoff)
209*e4b17023SJohn Marino 	  && read_archive_member (ldfile, offset));
210*e4b17023SJohn Marino }
211*e4b17023SJohn Marino 
212*e4b17023SJohn Marino /* LDFILE is a zero-initialized structure.  Try to open FILENAME,
213*e4b17023SJohn Marino    returning true on success.  */
214*e4b17023SJohn Marino 
215*e4b17023SJohn Marino static bool
open_file(LDFILE * ldfile,const char * filename)216*e4b17023SJohn Marino open_file (LDFILE *ldfile, const char *filename)
217*e4b17023SJohn Marino {
218*e4b17023SJohn Marino   struct stat st;
219*e4b17023SJohn Marino 
220*e4b17023SJohn Marino   ldfile->fd = open (filename, O_RDONLY);
221*e4b17023SJohn Marino   if (ldfile->fd < 0)
222*e4b17023SJohn Marino     return false;
223*e4b17023SJohn Marino 
224*e4b17023SJohn Marino   if (read_big_archive (ldfile))
225*e4b17023SJohn Marino     return true;
226*e4b17023SJohn Marino 
227*e4b17023SJohn Marino   if (fstat (ldfile->fd, &st) < 0)
228*e4b17023SJohn Marino     return false;
229*e4b17023SJohn Marino 
230*e4b17023SJohn Marino   return read_xcoff_object (ldfile, 0, st.st_size, -1);
231*e4b17023SJohn Marino }
232*e4b17023SJohn Marino 
233*e4b17023SJohn Marino /* Release the memory associated with the current object, if one has
234*e4b17023SJohn Marino    been mapped.  */
235*e4b17023SJohn Marino 
236*e4b17023SJohn Marino static void
free_object(LDFILE * ldfile)237*e4b17023SJohn Marino free_object (LDFILE *ldfile)
238*e4b17023SJohn Marino {
239*e4b17023SJohn Marino   if (ldfile->object)
240*e4b17023SJohn Marino     munmap (ldfile->object - ldfile->page_offset,
241*e4b17023SJohn Marino 	    ldfile->object_size + ldfile->page_offset);
242*e4b17023SJohn Marino }
243*e4b17023SJohn Marino 
244*e4b17023SJohn Marino /* Free LDFILE and all resources associated with it.  */
245*e4b17023SJohn Marino 
246*e4b17023SJohn Marino static void
free_ldfile(LDFILE * ldfile)247*e4b17023SJohn Marino free_ldfile (LDFILE *ldfile)
248*e4b17023SJohn Marino {
249*e4b17023SJohn Marino   if (ldfile->fd >= 0)
250*e4b17023SJohn Marino     close (ldfile->fd);
251*e4b17023SJohn Marino   XDELETE (ldfile);
252*e4b17023SJohn Marino }
253*e4b17023SJohn Marino 
254*e4b17023SJohn Marino /* Implement the API-defined ldopen function.  */
255*e4b17023SJohn Marino 
256*e4b17023SJohn Marino LDFILE *
ldopen(char * filename,LDFILE * ldfile)257*e4b17023SJohn Marino ldopen (char *filename, LDFILE *ldfile)
258*e4b17023SJohn Marino {
259*e4b17023SJohn Marino   if (ldfile == NULL)
260*e4b17023SJohn Marino     {
261*e4b17023SJohn Marino       ldfile = XCNEW (LDFILE);
262*e4b17023SJohn Marino       if (!open_file (ldfile, filename))
263*e4b17023SJohn Marino 	{
264*e4b17023SJohn Marino 	  free_object (ldfile);
265*e4b17023SJohn Marino 	  free_ldfile (ldfile);
266*e4b17023SJohn Marino 	  return NULL;
267*e4b17023SJohn Marino 	}
268*e4b17023SJohn Marino     }
269*e4b17023SJohn Marino   return ldfile;
270*e4b17023SJohn Marino }
271*e4b17023SJohn Marino 
272*e4b17023SJohn Marino /* Implement the API-defined ldtbread function.  */
273*e4b17023SJohn Marino 
274*e4b17023SJohn Marino int
ldtbread(LDFILE * ldfile,long index,SYMENT * internal)275*e4b17023SJohn Marino ldtbread (LDFILE *ldfile, long index, SYMENT *internal)
276*e4b17023SJohn Marino {
277*e4b17023SJohn Marino   size_t offset, name_length;
278*e4b17023SJohn Marino   char *external;
279*e4b17023SJohn Marino 
280*e4b17023SJohn Marino   /* Make sure that the symbol index is valid.  */
281*e4b17023SJohn Marino   if (index < 0 || index >= HEADER (ldfile).f_nsyms)
282*e4b17023SJohn Marino     return FAILURE;
283*e4b17023SJohn Marino 
284*e4b17023SJohn Marino   /* Work out the offset of the symbol table entry.  */
285*e4b17023SJohn Marino   offset = HEADER (ldfile).f_symptr + index * sizeof (struct external_syment);
286*e4b17023SJohn Marino   if (!within_object_p (ldfile, offset, sizeof (struct external_syment)))
287*e4b17023SJohn Marino     return FAILURE;
288*e4b17023SJohn Marino 
289*e4b17023SJohn Marino   /* Read all the fields.  The format differs between 32-bit and
290*e4b17023SJohn Marino      64-bit files.  */
291*e4b17023SJohn Marino   external = ldfile->object + offset;
292*e4b17023SJohn Marino   if (HEADER (ldfile).f_magic == U802TOCMAGIC)
293*e4b17023SJohn Marino     {
294*e4b17023SJohn Marino       /* Copy the n_zeroes/n_offset interpretation.  */
295*e4b17023SJohn Marino       internal->n_zeroes = READ_OBJECT (external, external_syment,
296*e4b17023SJohn Marino 					u.xcoff32.u.u.n_zeroes);
297*e4b17023SJohn Marino       internal->n_offset = READ_OBJECT (external, external_syment,
298*e4b17023SJohn Marino 					u.xcoff32.u.u.n_offset);
299*e4b17023SJohn Marino 
300*e4b17023SJohn Marino       /* Copy the n_name interpretation.  The internal version has room
301*e4b17023SJohn Marino 	 for a null terminator.  */
302*e4b17023SJohn Marino       name_length = FIELD_SIZE (external_syment, u.xcoff32.u.n_name);
303*e4b17023SJohn Marino       memcpy (internal->n_name,
304*e4b17023SJohn Marino 	      external + offsetof (struct external_syment, u.xcoff32.u.n_name),
305*e4b17023SJohn Marino 	      name_length);
306*e4b17023SJohn Marino       internal->n_name[name_length] = 0;
307*e4b17023SJohn Marino 
308*e4b17023SJohn Marino       internal->n_value = READ_OBJECT (external, external_syment,
309*e4b17023SJohn Marino 				       u.xcoff32.n_value);
310*e4b17023SJohn Marino     }
311*e4b17023SJohn Marino   else
312*e4b17023SJohn Marino     {
313*e4b17023SJohn Marino       internal->n_zeroes = 0;
314*e4b17023SJohn Marino       internal->n_offset = READ_OBJECT (external, external_syment,
315*e4b17023SJohn Marino 					u.xcoff64.n_offset);
316*e4b17023SJohn Marino       internal->n_value = READ_OBJECT (external, external_syment,
317*e4b17023SJohn Marino 				       u.xcoff64.n_value);
318*e4b17023SJohn Marino     }
319*e4b17023SJohn Marino   COPY_FIELD (internal, external, external_syment, n_scnum);
320*e4b17023SJohn Marino   COPY_FIELD (internal, external, external_syment, n_type);
321*e4b17023SJohn Marino   COPY_FIELD (internal, external, external_syment, n_sclass);
322*e4b17023SJohn Marino   COPY_FIELD (internal, external, external_syment, n_numaux);
323*e4b17023SJohn Marino   return SUCCESS;
324*e4b17023SJohn Marino }
325*e4b17023SJohn Marino 
326*e4b17023SJohn Marino /* Implement the API-defined ldgetname function.  */
327*e4b17023SJohn Marino 
328*e4b17023SJohn Marino char *
ldgetname(LDFILE * ldfile,SYMENT * symbol)329*e4b17023SJohn Marino ldgetname (LDFILE *ldfile, SYMENT *symbol)
330*e4b17023SJohn Marino {
331*e4b17023SJohn Marino   char *name;
332*e4b17023SJohn Marino   size_t offset;
333*e4b17023SJohn Marino 
334*e4b17023SJohn Marino   /* If the zeroes field is nonzero, the name is in the symbol table
335*e4b17023SJohn Marino      entry itself.  */
336*e4b17023SJohn Marino   if (symbol->n_zeroes != 0)
337*e4b17023SJohn Marino     return symbol->n_name;
338*e4b17023SJohn Marino 
339*e4b17023SJohn Marino   /* Otherwise, the symbol table entry contains an offset into the
340*e4b17023SJohn Marino      string table, which starts after the end of the symbol table.  */
341*e4b17023SJohn Marino   offset = (HEADER (ldfile).f_symptr
342*e4b17023SJohn Marino 	    + HEADER (ldfile).f_nsyms * sizeof (struct external_syment)
343*e4b17023SJohn Marino 	    + symbol->n_offset);
344*e4b17023SJohn Marino   if (offset >= ldfile->object_size)
345*e4b17023SJohn Marino     return NULL;
346*e4b17023SJohn Marino 
347*e4b17023SJohn Marino   /* Make sure that the name is entirely contained within the object.  */
348*e4b17023SJohn Marino   name = ldfile->object + offset;
349*e4b17023SJohn Marino   if (!string_within_bounds_p (name, ldfile->object_size - offset, '\0'))
350*e4b17023SJohn Marino     return NULL;
351*e4b17023SJohn Marino 
352*e4b17023SJohn Marino   return name;
353*e4b17023SJohn Marino }
354*e4b17023SJohn Marino 
355*e4b17023SJohn Marino /* Implement the API-defined ldclose function.  */
356*e4b17023SJohn Marino 
357*e4b17023SJohn Marino int
ldclose(LDFILE * ldfile)358*e4b17023SJohn Marino ldclose (LDFILE *ldfile)
359*e4b17023SJohn Marino {
360*e4b17023SJohn Marino   free_object (ldfile);
361*e4b17023SJohn Marino   if (ldfile->next_member >= 0
362*e4b17023SJohn Marino       && read_archive_member (ldfile, ldfile->next_member))
363*e4b17023SJohn Marino     return FAILURE;
364*e4b17023SJohn Marino 
365*e4b17023SJohn Marino   free_ldfile (ldfile);
366*e4b17023SJohn Marino   return SUCCESS;
367*e4b17023SJohn Marino }
368*e4b17023SJohn Marino 
369*e4b17023SJohn Marino #endif
370