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