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