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