xref: /illumos-gate/usr/src/cmd/sgs/include/elfedit.h (revision 56726c7e321b6e5ecb2f10215f5386016547e68c)
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 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright 2022 Oxide Computer Company
27  */
28 
29 #ifndef	_ELFEDIT_H
30 #define	_ELFEDIT_H
31 
32 #include	<stdio.h>
33 #include	<stdlib.h>
34 #include	<sys/types.h>
35 #include	<libelf.h>
36 #include	<stdarg.h>
37 
38 /* The following are here to support use of elfedit_msg() */
39 #include	<sys/machelf.h>		/* EC_ macros */
40 #include	<libintl.h>
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 
47 /*
48  * elfedit uses elfedit_printf() to produce generic output to stdout.
49  * elfedit_msg() is used to produce error message, or specific types
50  * of terse informational messages:
51  *
52  *	ELFEDIT_MSG_ERR:
53  *		Issues an error to stderr. elfedit_msg() does not return
54  *		to the caller. Control returns to the outer loop in
55  *		interactive use. elfedit exits in non-interactive use.
56  *
57  *	ELFEDIT_MSG_FATAL:
58  *		Issues an error to stderr. elfedit_msg() exits the process,
59  *		and does not return to the caller.
60  *
61  *	ELFEDIT_MSG_USAGE:
62  *		Issues an elfedit usage message to stderr, and
63  *		returns to the caller.
64  *
65  *	ELFEDIT_MSG_CMDUSAGE
66  *		Issues an elfedit usage message to stderr, and
67  *		does not return to the caller.
68  *
69  *	ELFEDIT_MSG_DEBUG
70  *		If the ELFEDIT_F_DEBUG flag is set, the message
71  *		is printed to stdout, otherwise no output is produced.
72  *		elfedit_msg() returns to the caller.
73  *
74  *	ELFEDIT_MSG_QUIET
75  *		This is a very special case, intended to handle the
76  *		case where the pager subprocess exits before we are
77  *		done producing output (the user presses 'q'). It acts
78  *		just like ELFEDIT_MSG_ERR, except that no message is
79  *		actually printed.
80  *
81  * In the cases where elfedit_msg() does not return to the caller, the
82  * behavior depends on the mode of execution. If running in interactive
83  * mode (reading from a tty), control is returned directly to the outer
84  * elfedit control loop to read another command. If not running in interactive
85  * mode, elfedit exits with a non-zero status.
86  */
87 typedef enum {
88 	ELFEDIT_MSG_ERR = 0,
89 	ELFEDIT_MSG_FATAL = 1,
90 	ELFEDIT_MSG_USAGE = 2,
91 	ELFEDIT_MSG_CMDUSAGE = 3,
92 	ELFEDIT_MSG_DEBUG = 4,
93 	ELFEDIT_MSG_QUIET = 5
94 } elfedit_msg_t;
95 
96 
97 /*
98  * Information for a single ELF section.
99  *
100  * NOTE: sec_xshndx
101  *	A symbol table can have an associated SHT_SYMTAB_SHNDX section. This
102  *	happens when the number of sections is too large to fit in the
103  *	ELF symbol st_shndx field, which is a 16-bit value. The sec_xshndx
104  *	field will be SHN_UNDEF if there is no such section, and will be
105  *	the section index of the extended section index section assocated
106  *	with the symbol table otherwise.
107  *
108  * NOTE: sec_versym
109  *	Symbol table sections can have an SHT_SUNW_VERSYM section that
110  *	contains its version indices. Other types of section will have
111  *	this field set to SHN_UNDEF.
112  */
113 typedef struct {
114 	Elf32_Word	sec_shndx;	/* Section index */
115 	Elf_Scn		*sec_scn;	/* Section descriptor */
116 	Elf32_Shdr	*sec_shdr;	/* Section header */
117 	Elf_Data	*sec_data;	/* Data region of section */
118 	const char	*sec_name;	/* Name of section */
119 } elfedit32_section_t;
120 
121 typedef struct {
122 	Elf64_Word	sec_shndx;
123 	Elf_Scn		*sec_scn;
124 	Elf64_Shdr	*sec_shdr;
125 	Elf_Data	*sec_data;
126 	const char	*sec_name;
127 } elfedit64_section_t;
128 
129 #ifdef _ELF64
130 #define	elfedit_section_t	elfedit64_section_t
131 #else
132 #define	elfedit_section_t	elfedit32_section_t
133 #endif
134 
135 
136 /*
137  * We maintain extra information for symbol tables. We look them
138  * up frequently, so we want to eliminate expensive linear searches
139  * of the entire section header array. Also, symbol tables usually
140  * have associated parallal sections (syminfo, versym, extended indexes, etc)
141  * and we want to eliminate repeated linear lookups for them, as well as
142  * the basic error checking that is necessary to ensure they match the
143  * symbol table they're given.
144  *
145  * This extra information is kept in elfedit_symtab_t structs. Each field
146  * is a section index, with SHN_UNDEF used for those that do not apply.
147  */
148 typedef struct {
149 	Elf32_Word	symt_shndx;	/* Symbol table section index */
150 	Elf32_Word	symt_xshndx;	/* Index of extended index section */
151 	Elf32_Word	symt_syminfo;	/* Index of versym section */
152 	Elf32_Word	symt_versym;	/* Index of versym section */
153 } elfedit32_symtab_t;
154 
155 typedef struct {
156 	Elf64_Word	symt_shndx;
157 	Elf64_Word	symt_xshndx;
158 	Elf64_Word	symt_versym;
159 	Elf64_Word	symt_syminfo;
160 } elfedit64_symtab_t;
161 
162 #ifdef _ELF64
163 #define	elfedit_symtab_t	elfedit64_symtab_t
164 #else
165 #define	elfedit_symtab_t	elfedit32_symtab_t
166 #endif
167 
168 
169 /*
170  * Information for a single ELF object.
171  *
172  * note:
173  *	elfedit is intended to be an expert's tool, capable of modifying
174  *	nearly everything in the file, whether or not such modifications
175  *	are a good idea. At the same time, elfedit, via libelf, relies
176  *	on the contents of the object to properly locate information in
177  *	the file. As this is the same information that elfedit allows the
178  *	user to modify, it should be obvious that the potential exists
179  *	for users to corrupt the file to the degree that elfedit itself
180  *	may fail, or produce spurious results. We allow such changes for
181  *	several reasons:
182  *
183  *	1) Such corruption does not happen in the most obvious and
184  *		useful operations elfedit supports, but comes as a result
185  *		of modifying fields that contain size and offset information
186  *		used to navigate the file. Non-ELF developers have
187  *		little practical reason to change such things.
188  *
189  *	2) Producing a corrupt ELF file can be very useful
190  *		for R&D and/or testing purposes.
191  *
192  *	3) ELF is sufficiently complex that no absolute guarantees can
193  *		be made about "safe" operations, beyond the basic
194  *		and obvious things that are of practical use.
195  *
196  *	One way we protect ourselves is via the information cached in
197  *	the elfedit_obj_state_t structure at startup. By using this
198  *	information, rather than constantly fetching it via libelf,
199  *	we protect ourselves against many user changes, such as changing the
200  *	program or section header offsets, or similar size/position fields.
201  *
202  *	Of course, we make no assurances that that we will be able to
203  *	read the resulting file in a subsequent session.
204  */
205 typedef struct {
206 	const char		*os_file;	/* Path to ELF file */
207 	int			os_fd;		/* Open file descriptor */
208 	Elf			*os_elf;	/* ELF descriptor */
209 	Elf32_Ehdr		*os_ehdr;	/* ELF header */
210 	Elf32_Word		os_dynndx;	/* Index of dynamic section */
211 	size_t			os_shstrndx;	/* Index of section header */
212 						/*	string table section */
213 	size_t			os_shnum;	/* # of sections in file */
214 	elfedit32_section_t	*os_secarr;	/* Section data */
215 	size_t			os_phnum;	/* # of program headers */
216 	Elf32_Phdr		*os_phdr;	/* Program header array */
217 	size_t			os_symtabnum;	/* # items in os_symtab[] */
218 	elfedit32_symtab_t	*os_symtab;	/* Array of symbol tbl info  */
219 } elfedit32_obj_state_t;
220 
221 typedef struct {
222 	const char		*os_file;
223 	int			os_fd;
224 	Elf			*os_elf;
225 	Elf64_Ehdr		*os_ehdr;
226 	Elf64_Word		os_dynndx;
227 	size_t			os_shstrndx;
228 	size_t			os_shnum;
229 	elfedit64_section_t	*os_secarr;
230 	size_t			os_phnum;
231 	Elf64_Phdr		*os_phdr;
232 	size_t			os_symtabnum;
233 	elfedit64_symtab_t	*os_symtab;
234 } elfedit64_obj_state_t;
235 
236 #ifdef _ELF64
237 #define	elfedit_obj_state_t	elfedit64_obj_state_t
238 #else
239 #define	elfedit_obj_state_t	elfedit32_obj_state_t
240 #endif
241 
242 
243 /*
244  * Bit values for editor state.
245  */
246 typedef enum {
247 	ELFEDIT_F_AUTOPRINT = 1, /* Print informational text about edits */
248 	ELFEDIT_F_DEBUG = 2,	/* Print informational text about operations */
249 	ELFEDIT_F_READONLY = 4,	/* File is processed readonly */
250 } elfedit_flag_t;
251 
252 /*
253  * Type used to represent the output style for printing ELF values.
254  *
255  * DEFAULT - Output is in 'elfdump' style, designed for human eyes.
256  *	Headers, and additional information are shown.
257  * SIMPLE - Output is simple, consisting only of the target item.
258  *	Integer values are shown as symbolic constants when possible,
259  *	and integers otherwise.
260  * NUM - Like SIMPLE, except integer values are always shown as
261  *	integer constants, and strings are shown as the integer
262  *	offset into the string table.
263  */
264 typedef enum {
265 	ELFEDIT_OUTSTYLE_DEFAULT = 0,
266 	ELFEDIT_OUTSTYLE_SIMPLE = 1,
267 	ELFEDIT_OUTSTYLE_NUM = 2
268 } elfedit_outstyle_t;
269 
270 
271 /*
272  * The elfedit_module_t, and the types it references, are defined
273  * by loadable elfedit modules, and used by elfedit. These structures
274  * need to communicate internationalized strings for elfedit to print.
275  *
276  * We want to leave the choice of internationalization APIs, as well as
277  * the decision about whether or not to even to it to the individual
278  * modules. Hence, we do not use a simple (const char *) pointer to
279  * communicate potentially internationalized strings. Instead, we define
280  * elfedit_i18nhdl_t, an opaque type guaranteed to be large enough
281  * to hold a pointer. Each module casts the handle needed to access the
282  * string to this type. Each module also supplies a function
283  * (mod_i18nhdl_to_str field of elfedit_module_t) that given one
284  * of these opaque keys, will return a (const char *) pointer to the
285  * actual string, for elfedit to print.
286  *
287  * If the underlying module doesn't want to implement i18n support,
288  * all it has to do is cast the strings to elfedit_i18nhdl_t and
289  * back.
290  */
291 typedef uintptr_t elfedit_i18nhdl_t;
292 
293 
294 
295 /*
296  * Macro to handle casting international string "handles" to the
297  * elfedit_i18nhdl_t opaque type.
298  */
299 #define	ELFEDIT_I18NHDL(_i18n_str_ref) ((elfedit_i18nhdl_t)_i18n_str_ref)
300 
301 
302 /*
303  * Return values from command functions
304  */
305 typedef enum {
306 	ELFEDIT_CMDRET_NONE = 0,	/* Nothing to report */
307 	ELFEDIT_CMDRET_MOD = 1,		/* Command modified output ELF file */
308 	ELFEDIT_CMDRET_MOD_OS_MACH = 2, /* As per _MOD, include ELF header */
309 					/*	osabi or machine change */
310 	ELFEDIT_CMDRET_FLUSH = 3	/* Output file flushed: elf_update() */
311 } elfedit_cmdret_t;
312 
313 /*
314  * Prototype of an implementation function for an edit command. Note that
315  * commands do not return a status:
316  *	- Success is indicated by a normal return.
317  *	- The command indicates a fatal error by calling elfedit_msg() with the
318  *		ELFEDIT_MSG_ERR type, in which case execution does not return
319  *		to the command, and the elfedit command loop knows that an
320  *		error occurred.
321  *	- The command is responsible for using the standard libelf
322  *		mechanisms to indicate when changes have been made to
323  *		the ELF file.
324  */
325 typedef elfedit_cmdret_t elfedit32_cmd_func_t(elfedit32_obj_state_t *state,
326     int argc, const char *argv[]);
327 typedef elfedit_cmdret_t elfedit64_cmd_func_t(elfedit64_obj_state_t *state,
328     int argc, const char *argv[]);
329 #ifdef _ELF64
330 #define	elfedit_cmd_func_t	elfedit64_cmd_func_t
331 #else
332 #define	elfedit_cmd_func_t	elfedit32_cmd_func_t
333 #endif
334 
335 
336 /*
337  * An elfedit command (elfedit_cmd_t) has a cmd_cpl field that
338  * can be set to a command completion function. If such a function
339  * is present (non-NULL), and the user presses the tab key at the
340  * command line while the cursor is at a plain (non option) argument,
341  * elfedit calls the function, passing it all the tokens up through
342  * the one needing completion.  The function can use elfedit_cpl_match()
343  * to enter possible alternatives.  Additionally, there are helper
344  * functions built on top of elfedit_cpl_match() that simplify common cases.
345  *
346  *	elfedit_cpl_ato[iu]() - enter matches from elfedit_ato[iu]_sym_t
347  *		mappings.
348  *	elfedit_cpl_atoconst() - Enter matches for well known constants
349  *	elfedit_cpl_command() - enter matches for all known commands
350  *	elfedit_cpl_mod() - enter matches for all known modules.
351  *	elfedit_cpl_ndx() - enter numeric index as a match
352  *
353  * The completion function is passed the following arguments:
354  *
355  *	obj_state - Object state. Will be NULL if elfedit session does not
356  *		have an active object. The completion function must test
357  *		the pointer before using it.
358  *	cpldata - Completion data, to be passed to elfedit_cpl_match()
359  *		or the helper functions built on it to register alternative
360  *		strings.
361  *	argc, argv - The tokens from the start of the line through
362  *		the one needing completion, which will always
363  *		be cmdcpl_argv[cmdcpl_argc - 1].
364  *	num_opt - A count of the optional arguments (those starting with
365  *		'-' at the beginning of argv. This means that argv[num_opt]
366  *		is the first plain argument, and the 1-based positional
367  *		number of the plain argument for which command completion
368  *		is needed is (argc - num_opt).
369  */
370 typedef void elfedit32_cmdcpl_func_t(elfedit32_obj_state_t *state,
371     void *cpldata, int argc, const char *argv[], int num_opt);
372 typedef void elfedit64_cmdcpl_func_t(elfedit64_obj_state_t *state,
373     void *cpldata, int argc, const char *argv[], int num_opt);
374 #ifdef _ELF64
375 #define	elfedit_cmdcpl_func_t	elfedit64_cmdcpl_func_t
376 #else
377 #define	elfedit_cmdcpl_func_t	elfedit32_cmdcpl_func_t
378 #endif
379 
380 
381 
382 
383 /*
384  * Command option/argument descriptor. These structures
385  * are used to represent each option and plain argument accepted
386  * by a command, via the cmd_opt and cmd_args fields in the
387  * command definition (elfedit_cmd_t). Each descriptor consists
388  * of a name, a help string (formatted for display via sys:help),
389  * and a flags field that conveys extra information about the
390  * item:
391  *
392  *	ELFEDIT_CMDOA_F_OPT
393  *	The item is optional. This flag is implicit for options
394  *	and need only be set for plain arguments.
395  *
396  *	ELFEDIT_CMDOA_F_VALUE
397  *	The item has a value, which is found in the following
398  *	item. This flag only has meaning for options, and should
399  *	not be set for plain arguments. The descriptor for the
400  *	value is found in the next array element, and only the
401  *	oa_name field is used (the other should be set t 0).
402  *
403  *	ELFEDIT_CMDOA_F_MULT
404  *	More than one of the specified items may be specified
405  *
406  *	ELFEDIT_CMDOA_F_INHERIT
407  *	This is an item for which a common definition exists.
408  *	Elfedit will substitute the standard values for the
409  *	name, help text, and flags. This enforces consistency
410  *	in documentation, plus it is easier for the module author.
411  *	When ELFEDIT_CMDOA_F_INHERIT is set:
412  *		- oa_name should be set to one of the ELFEDIT_STDOA_
413  *			values to specifiy which standard item is being
414  *			inherited.
415  *		- oa_help must be set to NULL.
416  *		- It is an error to set any other flags with
417  *			ELFEDIT_CMDOA_F_INHERIT.
418  *		- oa_idmask and oa_excmask are used in the normal way.
419  *
420  * The oa_idmask and oa_excmask fields are used to identify options,
421  * and to support mutual exclusion (when two or more options cannot be
422  * used together). They are ignored for arguments, and should be set to 0.
423  * oa_idmask is used to uniquely identify each item. When elfedit_getopt()
424  * matches an option, it returns the value of oa_idmask to the caller to
425  * indicate which option was matched. elfedit enforces the following rules
426  * for oa_idmask, and will refuse to load a module that does not follow them:
427  *	- The value of oa_idmask must be 0, or have a value that
428  *		is a power of 2 (i.e. only has one bit set).
429  *	- Each item that sets a non-0 value for oa_idmask must have
430  *		a unique value.
431  *	- If oa_idmask is 0, oa_excmask must be 0 also.
432  *	- oa_excmask is set to 0 if an item is not mutually exclusive
433  *		to any other item. Otherwise, it should set the bit
434  *		values representing the items it is mutually exclusive to.
435  *	- An oa_idmask value of 0 can be used for any item that
436  *		the module does not need to identify, and which
437  *		is not mutually exclusive to any other item.
438  * As elfedit_getopt() processes items, it maintains a bitmask combining the
439  * oa_idmask fields of all the options already seen. For each option, it uses
440  * oa_excmask to check for conflicts.
441  *
442  * note: elfedit enforces the rule that options consist of a '-'
443  *	character followed by at least one character when a module
444  *	is loaded.
445  */
446 typedef enum {
447 	ELFEDIT_CMDOA_F_OPT =	1,	/* Item is optional */
448 	ELFEDIT_CMDOA_F_VALUE =	2,	/* Item has a value arg following */
449 	ELFEDIT_CMDOA_F_MULT =	4,	/* More than one are allowed */
450 	ELFEDIT_CMDOA_F_INHERIT = 8,	/* Inherit definition: See above */
451 } elfedit_cmd_oa_flag_t;
452 
453 typedef u_longlong_t elfedit_cmd_oa_mask_t;
454 
455 typedef struct {
456 	const char		*oa_name;	/* Name of option */
457 	elfedit_i18nhdl_t	oa_help;	/* Help text for option */
458 	elfedit_cmd_oa_flag_t	oa_flags;	/* Additional attributes */
459 	elfedit_cmd_oa_mask_t	oa_idmask;	/* Unique id, returned by */
460 						/*	elfedit_getopt */
461 						/*	for use by caller */
462 	elfedit_cmd_oa_mask_t	oa_excmask;	/* Mutual exclusion mask */
463 } elfedit_cmd_optarg_t;
464 
465 
466 
467 /*
468  * These values define the standard options and arguments that a module
469  * can inherit using the ELFEDIT_CMDOA_F_INHERIT flag (described above).
470  * New items must be added at the end --- reordering the list will
471  * require all modules to be rebuilt.
472  *
473  * Note: 0 cannot be used as a ELFEDIT_STDOA_ value, because a NULL
474  *	value of oa_name is used to terminate argument and options lists.
475  *	Therefore, these values start at 1.
476  */
477 #define	ELFEDIT_STDOA_OPT_O		((const char *) 1)	/* -o ostyle */
478 #define	ELFEDIT_STDOA_OPT_AND		((const char *) 2)	/* -and */
479 #define	ELFEDIT_STDOA_OPT_CMP		((const char *) 3)	/* -cmp */
480 #define	ELFEDIT_STDOA_OPT_OR		((const char *) 4)	/* -or */
481 
482 #define	ELFEDIT_NUM_STDOA	4	/* # of ELFEDIT_STDOA_ definitions */
483 
484 
485 
486 /*
487  * Definition of a command
488  *
489  * This structure includes an elfedit_cmd_func_t pointer, which has
490  * different definitions for different ELFCLASS. Rather than needlessly
491  * complicate the code with three versions of this type, and any
492  * type that uses it, we simply use the GenericClass type. elfedit
493  * will always cast this to the correct type before calling a module.
494  *
495  * cmd_name is an array of pointers to the names for the command.
496  * The "primary" name should always be first, followed by any alias
497  * names. The final element of the array must be a NULL pointer,
498  * which terminates the list. Every command is required to have at
499  * least one name, so code is allowed to assume that the first element
500  * of cmd_name is non-NULL, and contains the primary name.
501  *
502  * Many modules provide a "default" command, which is a command
503  * that is run if only the module name is specified, followed
504  * by a colon (i.e. "sym:"). The way this is implemented is to
505  * give the desired default command an empty string as an alias.
506  * Note that the primary name cannot be an empty string, only the
507  * alias name.
508  *
509  * cmd_opts and cmd_args are each an array of elfedit_cmd_argdesc_t
510  * structures, that describe the options and plain arguments accepted
511  * by the command. These arrays are used to general help text for
512  * the commands. The cmd_opts array is also used to provide command
513  * completion for options. Both of these arrays are terminated by
514  * a final NULL element (all fields zero).
515  */
516 typedef struct {
517 	elfedit32_cmd_func_t	*cmd_func;	/* Implementation */
518 	elfedit32_cmdcpl_func_t	*cmd_cplfunc;	/* Completion function */
519 	const char		**cmd_name;	/* Cmd names (null term.) */
520 	elfedit_i18nhdl_t	cmd_desc;	/* Short desc. of cmd purpose */
521 	elfedit_i18nhdl_t	cmd_help;	/* Help text for the command */
522 	elfedit_cmd_optarg_t	*cmd_opt;	/* Options */
523 	elfedit_cmd_optarg_t	*cmd_args;	/* Plain arguments */
524 } elfedit32_cmd_t;
525 
526 typedef struct {
527 	elfedit64_cmd_func_t	*cmd_func;
528 	elfedit64_cmdcpl_func_t	*cmd_cplfunc;
529 	const char		**cmd_name;
530 	elfedit_i18nhdl_t	cmd_desc;
531 	elfedit_i18nhdl_t	cmd_help;
532 	elfedit_cmd_optarg_t	*cmd_opt;
533 	elfedit_cmd_optarg_t	*cmd_args;
534 } elfedit64_cmd_t;
535 
536 #ifdef _ELF64
537 #define	elfedit_cmd_t		elfedit64_cmd_t
538 #else
539 #define	elfedit_cmd_t		elfedit32_cmd_t
540 #endif
541 
542 
543 
544 /*
545  * elfedit modules version themselves so that we can alter the definition
546  * of elfedit_module_t in a backward compatible way.
547  */
548 typedef enum {
549 	ELFEDIT_VER_NONE = 0,
550 	ELFEDIT_VER_CURRENT = 1,
551 	ELFEDIT_VER_NUM = 2
552 } elfedit_module_version_t;
553 
554 
555 /*
556  * Each module returns a pointer to an elfedit_module_t, describing
557  * what commands the module provides.
558  *
559  * Note: mod_cmds is a NULL terminated array of command defs. This
560  * means that the final element in the array should have all of its
561  * fields set to NULL.
562  *
563  * The mod_i18nhdl_to_str function pointer is explained above
564  * with the definition of elfedit_i18nhdl_t.
565  */
566 typedef const char *(* elfedit_mod_i18nhdl_to_str_func_t)(elfedit_i18nhdl_t);
567 
568 typedef struct {
569 	elfedit_module_version_t mod_version;	/* version */
570 	const char		*mod_name;	/* Name of module */
571 	elfedit_i18nhdl_t	mod_desc;	/* Short desc. of mod purpose */
572 	elfedit32_cmd_t		*mod_cmds;	/* Array of command defs */
573 						/* i18n -> (char *) fcn */
574 	elfedit_mod_i18nhdl_to_str_func_t mod_i18nhdl_to_str;
575 } elfedit32_module_t;
576 
577 typedef struct {
578 	elfedit_module_version_t mod_version;
579 	const char		*mod_name;
580 	elfedit_i18nhdl_t	mod_desc;
581 	elfedit64_cmd_t		*mod_cmds;
582 	elfedit_mod_i18nhdl_to_str_func_t mod_i18nhdl_to_str;
583 } elfedit64_module_t;
584 
585 #ifdef _ELF64
586 #define	elfedit_module_t	elfedit64_module_t
587 #else
588 #define	elfedit_module_t	elfedit32_module_t
589 #endif
590 
591 
592 /*
593  * Each module is a sharable library, expected to provide a single global
594  * function, named elfedit_init(), with the following prototype.
595  */
596 typedef elfedit_module_t *elfedit_init_func_t(elfedit_module_version_t version);
597 
598 
599 /*
600  * Prototype for elfedit_write(), and for outfunc argument
601  * to elfedit_str_to_c_literal().
602  */
603 typedef void elfedit_write_func_t(const void *ptr, size_t size);
604 
605 
606 /*
607  * Core elfedit functions exported for use by modules
608  */
609 extern void elfedit_command_usage(void);
610 extern void elfedit_cpl_command(void *cpldata);
611 extern void elfedit_cpl_match(void *cpldata, const char *str, int casefold);
612 extern void elfedit_cpl_ndx(void *cpldata, uint_t ndx);
613 extern void elfedit_elferr(const char *file, const char *libelf_rtn_name);
614 extern elfedit_flag_t elfedit_flags(void);
615 extern void *elfedit_malloc(const char *item_name, size_t size);
616 extern void elfedit_msg(elfedit_msg_t type, const char *format, ...);
617 extern elfedit_outstyle_t elfedit_outstyle(void);
618 extern void elfedit_pager_init(void);
619 extern void elfedit_printf(const char *format, ...);
620 extern void *elfedit_realloc(const char *item_name, void *ptr, size_t size);
621 extern void elfedit_str_to_c_literal(const char *str,
622     elfedit_write_func_t *outfunc);
623 extern elfedit_write_func_t elfedit_write;
624 
625 /*
626  * Core elfedit functions exported for use by sys: module only
627  */
628 extern void elfedit_cpl_module(void *cpldata, int load_all_modules);
629 
630 
631 /*
632  * elfedit modules are expected to define two functions, one for
633  * each ELFCLASS. Define a generic name for this function, based on
634  * the class being supported by the including module.
635  */
636 #ifdef _ELF64
637 #define	elfedit_init		elfedit64_init
638 #else
639 #define	elfedit_init		elfedit32_init
640 #endif
641 
642 
643 
644 /*
645  * It is common to search the dynamic section for specific elements.
646  * Structures of this type are used to represent the contents of such
647  * elements in a systematic way. The elfedit_dyn_elt_init() function
648  * is used to prepare these strucutres for use.
649  */
650 typedef struct {
651 	int		dn_seen;	/* True if this item has been seen */
652 	Elf32_Word	dn_ndx;		/* Index of item in dynamic array */
653 	Elf32_Dyn	dn_dyn;		/* Contents of dynamic item */
654 } elfedit32_dyn_elt_t;
655 
656 typedef struct {
657 	int		dn_seen;
658 	Elf64_Word	dn_ndx;
659 	Elf64_Dyn	dn_dyn;
660 } elfedit64_dyn_elt_t;
661 
662 #ifdef _ELF64
663 #define	elfedit_dyn_elt_t	elfedit64_dyn_elt_t
664 #else
665 #define	elfedit_dyn_elt_t	elfedit32_dyn_elt_t
666 #endif
667 
668 /*
669  * The elfedit_atoi() and elfedit_atoui() functions can optionally
670  * accept an array of these structures, giving symbolic names that
671  * will be accepted instead of numeric codes. If such an array is
672  * present, the supplied string has it's leading and trailing whitespace
673  * removed and is then compared to the list, and if there is a match,
674  * the corresponding integer value is returned.
675  *
676  * The final array element must have its name field set to NULL.
677  */
678 typedef u_longlong_t elfedit_atoui_t;
679 typedef struct {
680 	const char	*sym_name;
681 	elfedit_atoui_t	sym_value;
682 } elfedit_atoui_sym_t;
683 typedef longlong_t elfedit_atoi_t;
684 typedef struct {
685 	const char	*sym_name;
686 	elfedit_atoi_t	sym_value;
687 } elfedit_atoi_sym_t;
688 
689 
690 /*
691  * The elfedit_atoconst*() functions are built on top of the atoui routines.
692  * These routines accept an elfedit_const_t code instead of a
693  * pointer to an elfedit_atoui_sym_t array, and use internally
694  * predefined tables of elfedit_atoui_sym_t in order to do the desired
695  * mappings. elfedit modules are encouraged to use these standard
696  * tables instead of defining their own elfedit_atoui_sym_t arrays.
697  *
698  * note:
699  *	- The values assigned here must be in agreement with the
700  *		sym_table[] array defined in elfconst.c.
701  *	- Once defined, these values must not change. Reordering the
702  *		list will require all modules to be rebuilt, and will
703  *		break backward compatability. New items should be
704  *		added to the end.
705  */
706 typedef enum {
707 	ELFEDIT_CONST_OUTSTYLE =	0,	/* elfedit output styles  */
708 	ELFEDIT_CONST_OUTSTYLE_MO =	1,	/* ostyles with -o prefix */
709 	ELFEDIT_CONST_BOOL =		2,	/* boolean names */
710 	ELFEDIT_CONST_SHT_STRTAB =	3,	/* ELF SHT_STRTAB */
711 	ELFEDIT_CONST_SHT_SYMTAB =	4,	/* ELF SHT_SYMTAB */
712 	ELFEDIT_CONST_SHT_DYNSYM =	5,	/* ELF SHT_DYNSYM */
713 	ELFEDIT_CONST_SHT_LDYNSYM =	6,	/* ELF SHT_SUNW_LDYNSYM */
714 	ELFEDIT_CONST_SHN =		7,	/* ELF SHN_ section indexes  */
715 	ELFEDIT_CONST_SHT =		8,	/* ELF SHT_ section types  */
716 	ELFEDIT_CONST_SHT_ALLSYMTAB =	9,	/* ELF SHT_ symbol table */
717 						/*	section types */
718 	ELFEDIT_CONST_DT =		10,	/* Dynamic tags: DT_ */
719 	ELFEDIT_CONST_DF =		11,	/* DT_FLAGS bits */
720 	ELFEDIT_CONST_DF_P1 =		12,	/* DF_POSFLAG_1 bits */
721 	ELFEDIT_CONST_DF_1 =		13,	/* DT_FLAGS_1 bits */
722 	ELFEDIT_CONST_DTF_1 =		14,	/* DT_FEATURE_1 bits */
723 	ELFEDIT_CONST_EI =		15,	/* ELF header e_ident indexes */
724 	ELFEDIT_CONST_ET =		16,	/* Ehdr obj type */
725 	ELFEDIT_CONST_ELFCLASS =	17,	/* Ehdr wordsize (32,64) */
726 	ELFEDIT_CONST_ELFDATA =		18,	/* Ehdr endian */
727 	ELFEDIT_CONST_EF =		19,	/* Ehdr flags */
728 	ELFEDIT_CONST_EV =		20,	/* Ehdr version */
729 	ELFEDIT_CONST_EM =		21,	/* Ehdr machine */
730 	ELFEDIT_CONST_ELFOSABI =	22,	/* Ehdr ABI */
731 	ELFEDIT_CONST_EAV =		23,	/* Ehdr ABI version */
732 	ELFEDIT_CONST_PT =		24,	/* Phdr type */
733 	ELFEDIT_CONST_PF =		25,	/* Phdr flags */
734 	ELFEDIT_CONST_SHF =		26,	/* Shdr flags */
735 	ELFEDIT_CONST_STB =		27,	/* Sym binding */
736 	ELFEDIT_CONST_STT =		28,	/* Sym type */
737 	ELFEDIT_CONST_STV =		29,	/* Sym visibility */
738 	ELFEDIT_CONST_SYMINFO_BT =	30,	/* Syminfo boundto */
739 	ELFEDIT_CONST_SYMINFO_FLG =	31,	/* Syminfo flags */
740 	ELFEDIT_CONST_CA =		32,	/* Capabilities tags */
741 	ELFEDIT_CONST_HW1_SUNW =	33,	/* hardware capabilities */
742 	ELFEDIT_CONST_SF1_SUNW =	34,	/* software capabilities */
743 	ELFEDIT_CONST_HW2_SUNW =	35,	/* hardware capabilities */
744 	ELFEDIT_CONST_HW3_SUNW =	36,	/* hardware capabilities */
745 
746 	ELFEDIT_CONST_NUM =		37,	/* # of constant types */
747 } elfedit_const_t;
748 
749 /*
750  * Given an elfedit_const_t, return the array of elfedit_atoui_sym_t
751  * entries that it represents.
752  */
753 extern elfedit_atoui_sym_t *elfedit_const_to_atoui(elfedit_const_t const_type);
754 
755 /*
756  * ato[u]i and const routines, used to turn strings into numeric values,
757  * with support for mapping symbol names to numbers, and range checking.
758  */
759 extern elfedit_atoi_t elfedit_atoi(const char *str,
760     const elfedit_atoi_sym_t *sym);
761 extern elfedit_atoui_t elfedit_atoui(const char *str,
762     const elfedit_atoui_sym_t *sym);
763 extern elfedit_atoui_t elfedit_atoconst(const char *str,
764     elfedit_const_t const_type);
765 
766 extern int elfedit_atoi2(const char *str, const elfedit_atoi_sym_t *sym,
767     elfedit_atoi_t *v);
768 extern int elfedit_atoui2(const char *str, const elfedit_atoui_sym_t *sym,
769     elfedit_atoui_t *);
770 extern int elfedit_atoconst2(const char *str, elfedit_const_t const_type,
771     elfedit_atoui_t *);
772 
773 extern elfedit_atoi_t elfedit_atoi_range(const char *str,
774     const char *item_name, elfedit_atoi_t min, elfedit_atoi_t max,
775     const elfedit_atoi_sym_t *sym);
776 extern elfedit_atoui_t elfedit_atoui_range(const char *str,
777     const char *item_name, elfedit_atoui_t min, elfedit_atoui_t max,
778     const elfedit_atoui_sym_t *sym);
779 extern elfedit_atoui_t elfedit_atoconst_range(const char *str,
780     const char *item_name, elfedit_atoui_t min, elfedit_atoui_t max,
781     elfedit_const_t const_type);
782 
783 extern int elfedit_atoi_range2(const char *str, elfedit_atoi_t min,
784     elfedit_atoi_t max, const elfedit_atoi_sym_t *sym, elfedit_atoi_t *v);
785 extern int elfedit_atoui_range2(const char *str, elfedit_atoui_t min,
786     elfedit_atoui_t max, const elfedit_atoui_sym_t *sym, elfedit_atoui_t *v);
787 extern int elfedit_atoconst_range2(const char *str, elfedit_atoui_t min,
788     elfedit_atoui_t max, elfedit_const_t const_type, elfedit_atoui_t *v);
789 
790 extern const char *elfedit_atoi_value_to_str(const elfedit_atoi_sym_t *sym,
791     elfedit_atoi_t value, int required);
792 extern const char *elfedit_atoui_value_to_str(const elfedit_atoui_sym_t *sym,
793     elfedit_atoui_t value, int required);
794 extern const char *elfedit_atoconst_value_to_str(elfedit_const_t const_type,
795     elfedit_atoui_t value, int required);
796 
797 extern void elfedit_cpl_atoi(void *cpldata, const elfedit_atoi_sym_t *sym);
798 extern void elfedit_cpl_atoui(void *cpldata, const elfedit_atoui_sym_t *sym);
799 extern void elfedit_cpl_atoconst(void *cpldata, elfedit_const_t const_type);
800 
801 
802 /*
803  * Convenience functions built on top of the ato[u]i routines.
804  */
805 extern int elfedit_atobool(const char *str, const char *item_name);
806 extern elfedit_atoui_t elfedit_atoshndx(const char *str, size_t shnum);
807 
808 
809 /*
810  * elfedit provides a getopt utility for use by the module commands.
811  * elfedit_getopt_state_t is the state block used by elfedit_getopt().
812  * elfedit_getopt_ret_t is the definition of the values returned to
813  * the user by elfedit_getopt() when an option is matched. Elfedit
814  * getopt processing is done as follows:
815  *
816  * 1) The caller initializes an elfedit_getopt_state_t struct via
817  *	a call to elfedit_getopt_init(). The contents of this structure
818  *	must not be accessed by the caller, as they are all private and
819  *	subject to change.
820  * 2) Repeated calls are made to elfedit_getopt(), as long as it returns
821  *	a non-NULL pointer to an elfedit_getopt_ret_t structure. If the
822  *	matched option has a value (ELFEDIT_CMDOA_F_VALUE), then the gor_value
823  *	field contains the pointer to the string. Otherwise, gor_value is NULL.
824  * 3) As elfedit_getopt() consumes optional arguments from the argc/argv
825  *	passed to elfedit_getopt_init(), it adjusts argc/argc to skip over
826  *	them. Once elfedit_getopt() returns NULL to indicate that there are no
827  *	more options to match, argc/argv have been adjusted so that they
828  *	reference the plain arguments.
829  */
830 typedef struct {
831 	elfedit_cmd_oa_mask_t gor_idmask;	/* oa_idmask from matching */
832 					/*	elfedit_cmd_optarg_t. Can be */
833 					/*	used to quickly identify opt */
834 	const char	*gor_value;	/* Opt value if ELFEDIT_CMDOA_F_VALUE */
835 					/*	Otherwise, NULL */
836 } elfedit_getopt_ret_t;
837 typedef struct {
838 	int			*go_argc;	/* Pointer to # of options */
839 	const char		***go_argv;	/* Ptr to array of opt strs */
840 	elfedit_cmd_optarg_t	*go_optarg;	/* Array of allowed options */
841 	elfedit_cmd_oa_mask_t	go_idmask;	/* Combined id masks of all */
842 						/*	seen options */
843 	int			go_done;	/* True if last option seen */
844 	const char		*go_sglgrp;	/* Group of 1-letter opts */
845 	elfedit_getopt_ret_t	go_ret;		/* Data returned to user */
846 } elfedit_getopt_state_t;
847 
848 
849 
850 /*
851  * getopt related routines
852  */
853 extern void elfedit_getopt_init(elfedit_getopt_state_t *,
854     int *, const char ***);
855 extern elfedit_getopt_ret_t *elfedit_getopt(elfedit_getopt_state_t *);
856 
857 
858 
859 /*
860  * Additional utility functions exported for use by modules
861  */
862 extern void elfedit_array_elts_delete(const char *name_str, void *data_start,
863     size_t entsize, size_t num_ent, size_t start_ndx, size_t cnt);
864 
865 extern void elfedit_array_elts_move(const char *name_str, void *data_start,
866     size_t entsize, size_t num_ent, size_t srcndx,
867     size_t dstndx, size_t cnt, void *scr_item);
868 
869 extern int elfedit_bits_set(u_longlong_t v, int sizeof_orig_v);
870 
871 extern void elfedit32_dyn_elt_init(elfedit32_dyn_elt_t *dyn_elt);
872 extern void elfedit64_dyn_elt_init(elfedit64_dyn_elt_t *dyn_elt);
873 
874 extern void elfedit32_dyn_elt_save(elfedit32_dyn_elt_t *elt, Elf32_Word ndx,
875     Elf32_Dyn *dyn);
876 extern void elfedit64_dyn_elt_save(elfedit64_dyn_elt_t *elt, Elf64_Word ndx,
877     Elf64_Dyn *dyn);
878 
879 const char *elfedit32_dyn_offset_to_str(elfedit32_section_t *strsec,
880     elfedit32_dyn_elt_t *dynelt);
881 const char *elfedit64_dyn_offset_to_str(elfedit64_section_t *strsec,
882     elfedit64_dyn_elt_t *dynelt);
883 
884 extern int elfedit32_dynstr_getpad(elfedit32_obj_state_t *obj_state,
885     elfedit32_section_t *dynsec, elfedit32_dyn_elt_t *dyn_strpad);
886 extern int elfedit64_dynstr_getpad(elfedit64_obj_state_t *obj_state,
887     elfedit64_section_t *dynsec, elfedit64_dyn_elt_t *dyn_strpad);
888 
889 extern Elf32_Word elfedit32_dynstr_insert(elfedit32_section_t *dynsec,
890     elfedit32_section_t *strsec, elfedit32_dyn_elt_t *dyn_strpad,
891     const char *str);
892 extern Elf64_Word elfedit64_dynstr_insert(elfedit64_section_t *dynsec,
893     elfedit64_section_t *strsec, elfedit64_dyn_elt_t *dyn_strpad,
894     const char *str);
895 
896 extern void elfedit32_modified_data(elfedit32_section_t *s);
897 extern void elfedit64_modified_data(elfedit64_section_t *s);
898 
899 extern void elfedit32_modified_ehdr(elfedit32_obj_state_t *obj_state);
900 extern void elfedit64_modified_ehdr(elfedit64_obj_state_t *obj_state);
901 
902 extern void elfedit32_modified_phdr(elfedit32_obj_state_t *obj_state);
903 extern void elfedit64_modified_phdr(elfedit64_obj_state_t *obj_state);
904 
905 extern void elfedit32_modified_shdr(elfedit32_section_t *s);
906 extern void elfedit64_modified_shdr(elfedit64_section_t *s);
907 
908 extern Elf32_Word elfedit32_name_to_shndx(elfedit32_obj_state_t *obj_state,
909     const char *shnam);
910 extern Elf64_Word elfedit64_name_to_shndx(elfedit64_obj_state_t *obj_state,
911     const char *shnam);
912 
913 extern int elfedit32_name_to_symndx(elfedit32_section_t *symsec,
914     elfedit32_section_t *strsec, const char *name, elfedit_msg_t msg_type,
915     Elf32_Word *ret_symndx);
916 extern int elfedit64_name_to_symndx(elfedit64_section_t *symsec,
917     elfedit64_section_t *strsec, const char *name, elfedit_msg_t msg_type,
918     Elf64_Word *ret_symndx);
919 
920 extern const char *elfedit32_offset_to_str(elfedit32_section_t *strsec,
921     Elf32_Word offset, elfedit_msg_t msg_type, int debug_msg);
922 extern const char *elfedit64_offset_to_str(elfedit64_section_t *strsec,
923     Elf64_Word offset, elfedit_msg_t msg_type, int debug_msg);
924 
925 extern int elfedit32_sec_findstr(elfedit32_section_t *sec, Elf32_Word tail_ign,
926     const char *str, Elf32_Word *ret_offset);
927 extern int elfedit64_sec_findstr(elfedit64_section_t *sec, Elf64_Word tail_ign,
928     const char *str, Elf64_Word *ret_offset);
929 
930 extern elfedit32_section_t *elfedit32_sec_get(
931     elfedit32_obj_state_t *obj_state, Elf32_Word shndx);
932 extern elfedit64_section_t *elfedit64_sec_get(
933     elfedit64_obj_state_t *obj_state, Elf64_Word shndx);
934 
935 extern elfedit32_section_t *elfedit32_sec_getcap(
936     elfedit32_obj_state_t *obj_state, Elf32_Cap **cap, Elf32_Word *num);
937 extern elfedit64_section_t *elfedit64_sec_getcap(
938     elfedit64_obj_state_t *obj_state, Elf64_Cap **cap, Elf64_Word *num);
939 
940 extern elfedit32_section_t *elfedit32_sec_getdyn(
941     elfedit32_obj_state_t *obj_state, Elf32_Dyn **dyn, Elf32_Word *num);
942 extern elfedit64_section_t *elfedit64_sec_getdyn(
943     elfedit64_obj_state_t *obj_state, Elf64_Dyn **dyn, Elf64_Word *num);
944 
945 extern elfedit32_section_t *elfedit32_sec_getstr(
946     elfedit32_obj_state_t *obj_state, Elf32_Word shndx, int);
947 extern elfedit64_section_t *elfedit64_sec_getstr(
948     elfedit64_obj_state_t *obj_state, Elf64_Word shndx, int);
949 
950 extern elfedit32_section_t *elfedit32_sec_getsyminfo(
951     elfedit32_obj_state_t *obj_state, Elf32_Syminfo **syminfo, Elf32_Word *num);
952 extern elfedit64_section_t *elfedit64_sec_getsyminfo(
953     elfedit64_obj_state_t *obj_state, Elf64_Syminfo **syminfo, Elf64_Word *num);
954 
955 extern elfedit32_section_t *elfedit32_sec_getsymtab(
956     elfedit32_obj_state_t *obj_state, int by_index, Elf32_Word index,
957     const char *name, Elf32_Sym **sym, Elf32_Word *num,
958     elfedit32_symtab_t **aux_info);
959 extern elfedit64_section_t *elfedit64_sec_getsymtab(
960     elfedit64_obj_state_t *obj_state, int by_index, Elf64_Word index,
961     const char *name, Elf64_Sym **sym, Elf64_Word *num,
962     elfedit64_symtab_t **aux_info);
963 
964 extern elfedit32_section_t *elfedit32_sec_getversym(
965     elfedit32_obj_state_t *obj_state, elfedit32_section_t *symsec,
966     Elf32_Versym **versym, Elf32_Word *num);
967 extern elfedit64_section_t *elfedit64_sec_getversym(
968     elfedit64_obj_state_t *obj_state, elfedit64_section_t *symsec,
969     Elf64_Versym **versym, Elf64_Word *num);
970 
971 extern elfedit32_section_t *elfedit32_sec_getxshndx(
972     elfedit32_obj_state_t *obj_state, elfedit32_section_t *symsec,
973     Elf32_Word **xshndx, Elf32_Word *num);
974 extern elfedit64_section_t *elfedit64_sec_getxshndx(
975     elfedit64_obj_state_t *obj_state, elfedit64_section_t *symsec,
976     Elf64_Word **xshndx, Elf64_Word *num);
977 
978 extern int elfedit32_sec_issymtab(elfedit32_obj_state_t *obj_state,
979     elfedit32_section_t *sec, int issue_err, elfedit_atoui_sym_t **atoui_list);
980 extern int elfedit64_sec_issymtab(elfedit64_obj_state_t *obj_state,
981     elfedit64_section_t *sec, int issue_err, elfedit_atoui_sym_t **atoui_list);
982 
983 extern const char *elfedit32_sec_msgprefix(elfedit32_section_t *sec);
984 extern const char *elfedit64_sec_msgprefix(elfedit64_section_t *sec);
985 
986 extern const char *elfedit32_shndx_to_name(elfedit32_obj_state_t *obj_state,
987     Elf32_Word shndx);
988 extern const char *elfedit64_shndx_to_name(elfedit64_obj_state_t *obj_state,
989     Elf64_Word shndx);
990 
991 extern Elf32_Word elfedit32_strtab_insert(elfedit32_obj_state_t *obj_state,
992     elfedit32_section_t *strsec, elfedit32_section_t *dynsec, const char *str);
993 extern Elf64_Word elfedit64_strtab_insert(elfedit64_obj_state_t *obj_state,
994     elfedit64_section_t *strsec, elfedit64_section_t *dynsec, const char *str);
995 
996 extern void elfedit32_strtab_insert_test(elfedit32_obj_state_t *obj_state,
997     elfedit32_section_t *strsec, elfedit32_section_t *dynsec, const char *str);
998 extern void elfedit64_strtab_insert_test(elfedit64_obj_state_t *obj_state,
999     elfedit64_section_t *strsec, elfedit64_section_t *dynsec, const char *str);
1000 
1001 extern int elfedit32_test_osabi(elfedit32_obj_state_t *obj_state, uchar_t osabi,
1002     int issue_err);
1003 extern int elfedit64_test_osabi(elfedit64_obj_state_t *obj_state, uchar_t osabi,
1004     int issue_err);
1005 
1006 extern Elf32_Word elfedit32_type_to_shndx(elfedit32_obj_state_t *obj_state,
1007     Elf32_Word shtype);
1008 extern Elf64_Word elfedit64_type_to_shndx(elfedit64_obj_state_t *obj_state,
1009     Elf64_Word shtype);
1010 
1011 
1012 
1013 /*
1014  * Map the generic names for each of the ELFCLASS specific routines
1015  * above to reference the proper routine for the current compilation.
1016  */
1017 #ifdef _ELF64
1018 #define	elfedit_dyn_elt_init		elfedit64_dyn_elt_init
1019 #define	elfedit_dyn_elt_save		elfedit64_dyn_elt_save
1020 #define	elfedit_dyn_offset_to_str	elfedit64_dyn_offset_to_str
1021 #define	elfedit_dynstr_getpad		elfedit64_dynstr_getpad
1022 #define	elfedit_dynstr_insert		elfedit64_dynstr_insert
1023 #define	elfedit_modified_data		elfedit64_modified_data
1024 #define	elfedit_modified_ehdr		elfedit64_modified_ehdr
1025 #define	elfedit_modified_phdr		elfedit64_modified_phdr
1026 #define	elfedit_modified_shdr		elfedit64_modified_shdr
1027 #define	elfedit_name_to_shndx		elfedit64_name_to_shndx
1028 #define	elfedit_name_to_symndx		elfedit64_name_to_symndx
1029 #define	elfedit_offset_to_str		elfedit64_offset_to_str
1030 #define	elfedit_sec_findstr		elfedit64_sec_findstr
1031 #define	elfedit_sec_get			elfedit64_sec_get
1032 #define	elfedit_sec_getcap		elfedit64_sec_getcap
1033 #define	elfedit_sec_getdyn		elfedit64_sec_getdyn
1034 #define	elfedit_sec_getstr		elfedit64_sec_getstr
1035 #define	elfedit_sec_getsyminfo		elfedit64_sec_getsyminfo
1036 #define	elfedit_sec_getsymtab		elfedit64_sec_getsymtab
1037 #define	elfedit_sec_getversym		elfedit64_sec_getversym
1038 #define	elfedit_sec_getxshndx		elfedit64_sec_getxshndx
1039 #define	elfedit_sec_issymtab		elfedit64_sec_issymtab
1040 #define	elfedit_shndx_to_name		elfedit64_shndx_to_name
1041 #define	elfedit_sec_msgprefix		elfedit64_sec_msgprefix
1042 #define	elfedit_strtab_insert		elfedit64_strtab_insert
1043 #define	elfedit_strtab_insert_test	elfedit64_strtab_insert_test
1044 #define	elfedit_test_osabi		elfedit64_test_osabi
1045 #define	elfedit_type_to_shndx		elfedit64_type_to_shndx
1046 #else
1047 #define	elfedit_dyn_elt_init		elfedit32_dyn_elt_init
1048 #define	elfedit_dyn_elt_save		elfedit32_dyn_elt_save
1049 #define	elfedit_dyn_offset_to_str	elfedit32_dyn_offset_to_str
1050 #define	elfedit_dynstr_getpad		elfedit32_dynstr_getpad
1051 #define	elfedit_dynstr_insert		elfedit32_dynstr_insert
1052 #define	elfedit_modified_data		elfedit32_modified_data
1053 #define	elfedit_modified_ehdr		elfedit32_modified_ehdr
1054 #define	elfedit_modified_phdr		elfedit32_modified_phdr
1055 #define	elfedit_modified_shdr		elfedit32_modified_shdr
1056 #define	elfedit_name_to_shndx		elfedit32_name_to_shndx
1057 #define	elfedit_name_to_symndx		elfedit32_name_to_symndx
1058 #define	elfedit_offset_to_str		elfedit32_offset_to_str
1059 #define	elfedit_sec_findstr		elfedit32_sec_findstr
1060 #define	elfedit_sec_get			elfedit32_sec_get
1061 #define	elfedit_sec_getcap		elfedit32_sec_getcap
1062 #define	elfedit_sec_getdyn		elfedit32_sec_getdyn
1063 #define	elfedit_sec_getstr		elfedit32_sec_getstr
1064 #define	elfedit_sec_getsyminfo		elfedit32_sec_getsyminfo
1065 #define	elfedit_sec_getsymtab		elfedit32_sec_getsymtab
1066 #define	elfedit_sec_getversym		elfedit32_sec_getversym
1067 #define	elfedit_sec_getxshndx		elfedit32_sec_getxshndx
1068 #define	elfedit_sec_issymtab		elfedit32_sec_issymtab
1069 #define	elfedit_shndx_to_name		elfedit32_shndx_to_name
1070 #define	elfedit_sec_msgprefix		elfedit32_sec_msgprefix
1071 #define	elfedit_strtab_insert		elfedit32_strtab_insert
1072 #define	elfedit_strtab_insert_test	elfedit32_strtab_insert_test
1073 #define	elfedit_test_osabi		elfedit32_test_osabi
1074 #define	elfedit_type_to_shndx		elfedit32_type_to_shndx
1075 #endif
1076 
1077 
1078 #ifdef	__cplusplus
1079 }
1080 #endif
1081 
1082 #endif	/* _ELFEDIT_H */
1083