ea77b23ed870ab153644284a6b21a078d3822b18
[platform/upstream/elfutils.git] / src / arlib.h
1 /* Copyright (C) 2007-2012 Red Hat, Inc.
2    Written by Ulrich Drepper <drepper@redhat.com>, 2007.
3
4    Red Hat elfutils is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by the
6    Free Software Foundation; version 2 of the License.
7
8    Red Hat elfutils is distributed in the hope that it will be useful, but
9    WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11    General Public License for more details.
12
13    You should have received a copy of the GNU General Public License along
14    with Red Hat elfutils; if not, write to the Free Software Foundation,
15    Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
16
17    Red Hat elfutils is an included package of the Open Invention Network.
18    An included package of the Open Invention Network is a package for which
19    Open Invention Network licensees cross-license their patents.  No patent
20    license is granted, either expressly or impliedly, by designation as an
21    included package.  Should you wish to participate in the Open Invention
22    Network licensing program, please visit www.openinventionnetwork.com
23    <http://www.openinventionnetwork.com>.  */
24
25 #ifndef _ARLIB_H
26 #define _ARLIB_H        1
27
28 #include <ar.h>
29 #include <argp.h>
30 #include <byteswap.h>
31 #include <endian.h>
32 #include <libelf.h>
33 #include <obstack.h>
34 #include <stdbool.h>
35 #include <stddef.h>
36 #include <stdint.h>
37 #include <sys/types.h>
38
39
40 /* State of -D/-U flags.  */
41 extern bool arlib_deterministic_output;
42
43 /* For options common to ar and ranlib.  */
44 extern const struct argp_child arlib_argp_children[];
45
46
47 /* Maximum length of a file name that fits directly into the ar header.
48    We cannot use the final byte since a / goes there.  */
49 #define MAX_AR_NAME_LEN (sizeof (((struct ar_hdr *) NULL)->ar_name) - 1)
50
51
52 /* Words matching in size to archive header.  */
53 #define AR_HDR_WORDS (sizeof (struct ar_hdr) / sizeof (uint32_t))
54
55
56 #if __BYTE_ORDER == __LITTLE_ENDIAN
57 # define le_bswap_32(val) bswap_32 (val)
58 #else
59 # define le_bswap_32(val) (val)
60 #endif
61
62
63 /* Symbol table type.  */
64 struct arlib_symtab
65 {
66   /* Symbol table handling.  */
67   struct obstack symsoffob;
68   struct obstack symsnameob;
69   size_t symsofflen;
70   uint32_t *symsoff;
71   size_t symsnamelen;
72   char *symsname;
73
74   /* Long filename handling.  */
75   struct obstack longnamesob;
76   size_t longnameslen;
77   char *longnames;
78 };
79
80
81 /* Global variable with symbol table.  */
82 extern struct arlib_symtab symtab;
83
84
85 /* Initialize ARLIB_SYMTAB structure.  */
86 extern void arlib_init (void);
87
88 /* Finalize ARLIB_SYMTAB content.  */
89 extern void arlib_finalize (void);
90
91 /* Free resources for ARLIB_SYMTAB.  */
92 extern void arlib_fini (void);
93
94 /* Add symbols from ELF with value OFFSET to the symbol table SYMTAB.  */
95 extern void arlib_add_symbols (Elf *elf, const char *arfname,
96                                const char *membername, off_t off);
97
98 /* Add name a file offset of a symbol.  */
99 extern void arlib_add_symref (const char *symname, off_t symoff);
100
101 /* Add long file name FILENAME of length FILENAMELEN to the symbol table
102    SYMTAB.  Return the offset into the long file name table.  */
103 extern long int arlib_add_long_name (const char *filename, size_t filenamelen);
104
105 #endif  /* arlib.h */