xref: /openbsd-src/gnu/usr.bin/binutils/bfd/doc/archive.texi (revision cf2f2c5620d6d9a4fd01930983c4b9a1f76d7aa3)
1fddef416Sniklas@section Archives
2fddef416Sniklas
3f7cc78ecSespie
4fddef416Sniklas@strong{Description}@*
5fddef416SniklasAn archive (or library) is just another BFD.  It has a symbol
6fddef416Sniklastable, although there's not much a user program will do with it.
7fddef416Sniklas
8fddef416SniklasThe big difference between an archive BFD and an ordinary BFD
9fddef416Sniklasis that the archive doesn't have sections.  Instead it has a
10fddef416Sniklaschain of BFDs that are considered its contents.  These BFDs can
11fddef416Sniklasbe manipulated like any other.  The BFDs contained in an
12fddef416Sniklasarchive opened for reading will all be opened for reading.  You
13fddef416Sniklasmay put either input or output BFDs into an archive opened for
14fddef416Sniklasoutput; they will be handled correctly when the archive is closed.
15fddef416Sniklas
16fddef416SniklasUse @code{bfd_openr_next_archived_file} to step through
17fddef416Sniklasthe contents of an archive opened for input.  You don't
18fddef416Sniklashave to read the entire archive if you don't want
19fddef416Sniklasto!  Read it until you find what you want.
20fddef416Sniklas
21fddef416SniklasArchive contents of output BFDs are chained through the
22fddef416Sniklas@code{next} pointer in a BFD.  The first one is findable through
23fddef416Sniklasthe @code{archive_head} slot of the archive.  Set it with
24fddef416Sniklas@code{bfd_set_archive_head} (q.v.).  A given BFD may be in only one
25fddef416Sniklasopen output archive at a time.
26fddef416Sniklas
27fddef416SniklasAs expected, the BFD archive code is more general than the
28fddef416Sniklasarchive code of any given environment.  BFD archives may
29fddef416Sniklascontain files of different formats (e.g., a.out and coff) and
30fddef416Sniklaseven different architectures.  You may even place archives
31fddef416Sniklasrecursively into archives!
32fddef416Sniklas
33fddef416SniklasThis can cause unexpected confusion, since some archive
34fddef416Sniklasformats are more expressive than others.  For instance, Intel
35fddef416SniklasCOFF archives can preserve long filenames; SunOS a.out archives
36fddef416Sniklascannot.  If you move a file from the first to the second
37fddef416Sniklasformat and back again, the filename may be truncated.
38fddef416SniklasLikewise, different a.out environments have different
39fddef416Sniklasconventions as to how they truncate filenames, whether they
40fddef416Sniklaspreserve directory names in filenames, etc.  When
41fddef416Sniklasinteroperating with native tools, be sure your files are
42fddef416Sniklashomogeneous.
43fddef416Sniklas
44fddef416SniklasBeware: most of these formats do not react well to the
45fddef416Sniklaspresence of spaces in filenames.  We do the best we can, but
46fddef416Sniklascan't always handle this case due to restrictions in the format of
47fddef416Sniklasarchives.  Many Unix utilities are braindead in regards to
48fddef416Sniklasspaces and such in filenames anyway, so this shouldn't be much
49fddef416Sniklasof a restriction.
50fddef416Sniklas
51fddef416SniklasArchives are supported in BFD in @code{archive.c}.
52f7cc78ecSespie
53fddef416Sniklas@findex bfd_get_next_mapent
54fddef416Sniklas@subsubsection @code{bfd_get_next_mapent}
55fddef416Sniklas@strong{Synopsis}
56fddef416Sniklas@example
57*cf2f2c56Smiodsymindex bfd_get_next_mapent
58*cf2f2c56Smiod   (bfd *abfd, symindex previous, carsym **sym);
59fddef416Sniklas@end example
60fddef416Sniklas@strong{Description}@*
61fddef416SniklasStep through archive @var{abfd}'s symbol table (if it
62fddef416Sniklashas one).  Successively update @var{sym} with the next symbol's
63fddef416Sniklasinformation, returning that symbol's (internal) index into the
64fddef416Sniklassymbol table.
65fddef416Sniklas
66fddef416SniklasSupply @code{BFD_NO_MORE_SYMBOLS} as the @var{previous} entry to get
67fddef416Sniklasthe first one; returns @code{BFD_NO_MORE_SYMBOLS} when you've already
68fddef416Sniklasgot the last one.
69fddef416Sniklas
70fddef416SniklasA @code{carsym} is a canonical archive symbol.  The only
71fddef416Sniklasuser-visible element is its name, a null-terminated string.
72f7cc78ecSespie
73fddef416Sniklas@findex bfd_set_archive_head
74fddef416Sniklas@subsubsection @code{bfd_set_archive_head}
75fddef416Sniklas@strong{Synopsis}
76fddef416Sniklas@example
77d2201f2fSdrahnbfd_boolean bfd_set_archive_head (bfd *output, bfd *new_head);
78fddef416Sniklas@end example
79fddef416Sniklas@strong{Description}@*
80fddef416SniklasSet the head of the chain of
81fddef416SniklasBFDs contained in the archive @var{output} to @var{new_head}.
82f7cc78ecSespie
83fddef416Sniklas@findex bfd_openr_next_archived_file
84fddef416Sniklas@subsubsection @code{bfd_openr_next_archived_file}
85fddef416Sniklas@strong{Synopsis}
86fddef416Sniklas@example
87fddef416Sniklasbfd *bfd_openr_next_archived_file (bfd *archive, bfd *previous);
88fddef416Sniklas@end example
89fddef416Sniklas@strong{Description}@*
90fddef416SniklasProvided a BFD, @var{archive}, containing an archive and NULL, open
91fddef416Sniklasan input BFD on the first contained element and returns that.
92fddef416SniklasSubsequent calls should pass
93fddef416Sniklasthe archive and the previous return value to return a created
94fddef416SniklasBFD to the next contained element. NULL is returned when there
95fddef416Sniklasare no more.
96f7cc78ecSespie
97