xref: /illumos-gate/usr/src/cmd/sgs/elfwrap/common/_elfwrap.h (revision d48be21240dfd051b689384ce2b23479d757f2d8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	__ELFWRAP_H
28 #define	__ELFWRAP_H
29 
30 /*
31  * Local include file for elfwrap.
32  */
33 #include <libelf.h>
34 #include <alist.h>
35 #include <_machelf.h>
36 
37 /*
38  * Define a target descriptor to hold target specific information.
39  */
40 typedef struct {
41 	uchar_t		td_class;	/* target class (32-bit/64-bit) */
42 	uchar_t		td_data;	/* target data (LSB/MSB) */
43 	ushort_t	td_mach;	/* target machine (sparc, i386, etc.) */
44 	size_t		td_align;	/* target data buffer alignment */
45 	size_t		td_symsz;	/* target symbol table entry size */
46 } TargDesc_t;
47 
48 /*
49  * Define a descriptor for each ELF section being output to the new file.
50  */
51 typedef struct {
52 	const char	*os_name;	/* section name */
53 	Word		os_type;	/* section type */
54 	Xword		os_flags;	/* section flags */
55 	size_t		os_ndx;		/* section index (input file) */
56 	off_t		os_size;	/* section size (input file) */
57 	void		*os_addr;	/* section address (input file) */
58 	Shdr		*os_shdr;	/* section header (output file) */
59 	Elf_Data	*os_data;	/* section data (output file) */
60 } OutSec_t;
61 
62 #define	AL_CNT_WOSECS	10		/* default number of input sections */
63 
64 /*
65  * Define a standard section descriptor.
66  */
67 typedef struct {
68 	const char	*ss_name;	/* section name */
69 	Word		ss_type;	/* section type */
70 	Xword		ss_flags;	/* section flags */
71 } StdSec_t;
72 
73 /*
74  * Define a descriptor to maintain section information.
75  */
76 typedef struct {
77 	Alist		*od_outsecs;	/* list of output sections */
78 	size_t		od_symtabno;	/* number of symbol table entries */
79 	size_t		od_strtabsz;	/* string table size */
80 	size_t		od_shstrtabsz; 	/* section header string table size */
81 } ObjDesc_t;
82 
83 /*
84  * Define all external interfaces.
85  */
86 extern	int	input32(int, char **, const char *, const char *, ObjDesc_t *);
87 extern	int	input64(int, char **, const char *, const char *, ObjDesc_t *);
88 extern	int	output32(const char *, int, const char *, ushort_t,
89 		    ObjDesc_t *);
90 extern	int	output64(const char *, int, const char *, ushort_t,
91 		    ObjDesc_t *);
92 
93 #if	defined(lint)
94 extern	void	target_init(TargDesc_t *);
95 #else
96 extern	void	target_init_sparc(TargDesc_t *);
97 extern	void	target_init_sparcv9(TargDesc_t *);
98 extern	void	target_init_i386(TargDesc_t *);
99 extern	void	target_init_amd64(TargDesc_t *);
100 #endif
101 
102 #ifdef	__cplusplus
103 extern "C" {
104 #endif
105 
106 #ifdef	__cplusplus
107 }
108 #endif
109 
110 #endif	/* __ELFWRAP_H */
111