xref: /illumos-gate/usr/src/head/libelf.h (revision 30da1432)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
237c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
26*30da1432Sahl  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
27*30da1432Sahl  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef _LIBELF_H
317c478bd9Sstevel@tonic-gate #define	_LIBELF_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.9	*/
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <sys/types.h>
367c478bd9Sstevel@tonic-gate #include <sys/elf.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
407c478bd9Sstevel@tonic-gate extern "C" {
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #if defined(_ILP32) && (_FILE_OFFSET_BITS != 32)
457c478bd9Sstevel@tonic-gate #error "large files are not supported by libelf"
467c478bd9Sstevel@tonic-gate #endif
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #undef _
507c478bd9Sstevel@tonic-gate #ifdef __STDC__
517c478bd9Sstevel@tonic-gate typedef void		Elf_Void;
527c478bd9Sstevel@tonic-gate #define	_(a)		a
537c478bd9Sstevel@tonic-gate #else
547c478bd9Sstevel@tonic-gate typedef char		Elf_Void;
557c478bd9Sstevel@tonic-gate #define	_(a)		()
567c478bd9Sstevel@tonic-gate #undef const
577c478bd9Sstevel@tonic-gate #define	const
587c478bd9Sstevel@tonic-gate #endif
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate  * Commands
637c478bd9Sstevel@tonic-gate  */
647c478bd9Sstevel@tonic-gate typedef enum {
657c478bd9Sstevel@tonic-gate 	ELF_C_NULL = 0,	/* must be first, 0 */
667c478bd9Sstevel@tonic-gate 	ELF_C_READ,
677c478bd9Sstevel@tonic-gate 	ELF_C_WRITE,
687c478bd9Sstevel@tonic-gate 	ELF_C_CLR,
697c478bd9Sstevel@tonic-gate 	ELF_C_SET,
707c478bd9Sstevel@tonic-gate 	ELF_C_FDDONE,
717c478bd9Sstevel@tonic-gate 	ELF_C_FDREAD,
727c478bd9Sstevel@tonic-gate 	ELF_C_RDWR,
737c478bd9Sstevel@tonic-gate 	ELF_C_WRIMAGE,
747c478bd9Sstevel@tonic-gate 	ELF_C_IMAGE,
757c478bd9Sstevel@tonic-gate 	ELF_C_NUM	/* must be last */
767c478bd9Sstevel@tonic-gate } Elf_Cmd;
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate  * Flags
817c478bd9Sstevel@tonic-gate  */
827c478bd9Sstevel@tonic-gate #define	ELF_F_DIRTY	0x1
837c478bd9Sstevel@tonic-gate #define	ELF_F_LAYOUT	0x4
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /*
877c478bd9Sstevel@tonic-gate  * File types
887c478bd9Sstevel@tonic-gate  */
897c478bd9Sstevel@tonic-gate typedef enum {
907c478bd9Sstevel@tonic-gate 	ELF_K_NONE = 0,	/* must be first, 0 */
917c478bd9Sstevel@tonic-gate 	ELF_K_AR,
927c478bd9Sstevel@tonic-gate 	ELF_K_COFF,
937c478bd9Sstevel@tonic-gate 	ELF_K_ELF,
947c478bd9Sstevel@tonic-gate 	ELF_K_NUM	/* must be last */
957c478bd9Sstevel@tonic-gate } Elf_Kind;
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate /*
997c478bd9Sstevel@tonic-gate  * Translation types
1007c478bd9Sstevel@tonic-gate  */
1017c478bd9Sstevel@tonic-gate typedef enum {
1027c478bd9Sstevel@tonic-gate 	ELF_T_BYTE = 0,	/* must be first, 0 */
1037c478bd9Sstevel@tonic-gate 	ELF_T_ADDR,
1047c478bd9Sstevel@tonic-gate 	ELF_T_DYN,
1057c478bd9Sstevel@tonic-gate 	ELF_T_EHDR,
1067c478bd9Sstevel@tonic-gate 	ELF_T_HALF,
1077c478bd9Sstevel@tonic-gate 	ELF_T_OFF,
1087c478bd9Sstevel@tonic-gate 	ELF_T_PHDR,
1097c478bd9Sstevel@tonic-gate 	ELF_T_RELA,
1107c478bd9Sstevel@tonic-gate 	ELF_T_REL,
1117c478bd9Sstevel@tonic-gate 	ELF_T_SHDR,
1127c478bd9Sstevel@tonic-gate 	ELF_T_SWORD,
1137c478bd9Sstevel@tonic-gate 	ELF_T_SYM,
1147c478bd9Sstevel@tonic-gate 	ELF_T_WORD,
1157c478bd9Sstevel@tonic-gate 	ELF_T_VDEF,
1167c478bd9Sstevel@tonic-gate 	ELF_T_VNEED,
1177c478bd9Sstevel@tonic-gate 	ELF_T_SXWORD,
1187c478bd9Sstevel@tonic-gate 	ELF_T_XWORD,
1197c478bd9Sstevel@tonic-gate 	ELF_T_SYMINFO,
1207c478bd9Sstevel@tonic-gate 	ELF_T_NOTE,
1217c478bd9Sstevel@tonic-gate 	ELF_T_MOVE,
1227c478bd9Sstevel@tonic-gate 	ELF_T_MOVEP,
1237c478bd9Sstevel@tonic-gate 	ELF_T_CAP,
1247c478bd9Sstevel@tonic-gate 	ELF_T_NUM	/* must be last */
1257c478bd9Sstevel@tonic-gate } Elf_Type;
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate typedef struct Elf	Elf;
1297c478bd9Sstevel@tonic-gate typedef struct Elf_Scn	Elf_Scn;
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate /*
1337c478bd9Sstevel@tonic-gate  * Archive member header
1347c478bd9Sstevel@tonic-gate  */
1357c478bd9Sstevel@tonic-gate typedef struct {
1367c478bd9Sstevel@tonic-gate 	char		*ar_name;
1377c478bd9Sstevel@tonic-gate 	time_t		ar_date;
1387c478bd9Sstevel@tonic-gate 	uid_t		ar_uid;
1397c478bd9Sstevel@tonic-gate 	gid_t 		ar_gid;
1407c478bd9Sstevel@tonic-gate 	mode_t		ar_mode;
1417c478bd9Sstevel@tonic-gate 	off_t		ar_size;
1427c478bd9Sstevel@tonic-gate 	char 		*ar_rawname;
1437c478bd9Sstevel@tonic-gate } Elf_Arhdr;
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate /*
1477c478bd9Sstevel@tonic-gate  * Archive symbol table
1487c478bd9Sstevel@tonic-gate  */
1497c478bd9Sstevel@tonic-gate typedef struct {
1507c478bd9Sstevel@tonic-gate 	char		*as_name;
1517c478bd9Sstevel@tonic-gate 	size_t		as_off;
1527c478bd9Sstevel@tonic-gate 	unsigned long	as_hash;
1537c478bd9Sstevel@tonic-gate } Elf_Arsym;
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate /*
1577c478bd9Sstevel@tonic-gate  * Data descriptor
1587c478bd9Sstevel@tonic-gate  */
1597c478bd9Sstevel@tonic-gate typedef struct {
1607c478bd9Sstevel@tonic-gate 	Elf_Void	*d_buf;
1617c478bd9Sstevel@tonic-gate 	Elf_Type	d_type;
1627c478bd9Sstevel@tonic-gate 	size_t		d_size;
1637c478bd9Sstevel@tonic-gate 	off_t		d_off;		/* offset into section */
1647c478bd9Sstevel@tonic-gate 	size_t		d_align;	/* alignment in section */
1657c478bd9Sstevel@tonic-gate 	unsigned	d_version;	/* elf version */
1667c478bd9Sstevel@tonic-gate } Elf_Data;
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate /*
1707c478bd9Sstevel@tonic-gate  * Function declarations
1717c478bd9Sstevel@tonic-gate  */
1727c478bd9Sstevel@tonic-gate Elf		*elf_begin	_((int, Elf_Cmd, Elf *));
1737c478bd9Sstevel@tonic-gate int		elf_cntl	_((Elf *, Elf_Cmd));
1747c478bd9Sstevel@tonic-gate int		elf_end		_((Elf *));
1757c478bd9Sstevel@tonic-gate const char	*elf_errmsg	_((int));
1767c478bd9Sstevel@tonic-gate int		elf_errno	_((void));
1777c478bd9Sstevel@tonic-gate void		elf_fill	_((int));
1787c478bd9Sstevel@tonic-gate unsigned	elf_flagdata	_((Elf_Data *, Elf_Cmd, unsigned));
1797c478bd9Sstevel@tonic-gate unsigned	elf_flagehdr	_((Elf *, Elf_Cmd,  unsigned));
1807c478bd9Sstevel@tonic-gate unsigned	elf_flagelf	_((Elf *, Elf_Cmd, unsigned));
1817c478bd9Sstevel@tonic-gate unsigned	elf_flagphdr	_((Elf *, Elf_Cmd, unsigned));
1827c478bd9Sstevel@tonic-gate unsigned	elf_flagscn	_((Elf_Scn *, Elf_Cmd, unsigned));
1837c478bd9Sstevel@tonic-gate unsigned	elf_flagshdr	_((Elf_Scn *, Elf_Cmd, unsigned));
1847c478bd9Sstevel@tonic-gate size_t		elf32_fsize	_((Elf_Type, size_t, unsigned));
1857c478bd9Sstevel@tonic-gate Elf_Arhdr	*elf_getarhdr	_((Elf *));
1867c478bd9Sstevel@tonic-gate Elf_Arsym	*elf_getarsym	_((Elf *, size_t *));
1877c478bd9Sstevel@tonic-gate off_t		elf_getbase	_((Elf *));
1887c478bd9Sstevel@tonic-gate Elf_Data	*elf_getdata	_((Elf_Scn *, Elf_Data *));
1897c478bd9Sstevel@tonic-gate Elf32_Ehdr	*elf32_getehdr	_((Elf *));
1907c478bd9Sstevel@tonic-gate char		*elf_getident	_((Elf *, size_t *));
1917c478bd9Sstevel@tonic-gate Elf32_Phdr	*elf32_getphdr	_((Elf *));
1927c478bd9Sstevel@tonic-gate Elf_Scn		*elf_getscn	_((Elf *elf, size_t));
1937c478bd9Sstevel@tonic-gate Elf32_Shdr	*elf32_getshdr	_((Elf_Scn *));
194*30da1432Sahl int		elf_getphnum	_((Elf *, size_t *));
1957c478bd9Sstevel@tonic-gate int		elf_getshnum	_((Elf *, size_t *));
1967c478bd9Sstevel@tonic-gate int		elf_getshstrndx	_((Elf *, size_t *));
1977c478bd9Sstevel@tonic-gate unsigned long	elf_hash	_((const char *));
1987c478bd9Sstevel@tonic-gate long		elf32_checksum	_((Elf *));
1997c478bd9Sstevel@tonic-gate Elf_Kind	elf_kind	_((Elf *));
2007c478bd9Sstevel@tonic-gate Elf		*elf_memory	_((char *, size_t));
2017c478bd9Sstevel@tonic-gate size_t		elf_ndxscn	_((Elf_Scn *));
2027c478bd9Sstevel@tonic-gate Elf_Data	*elf_newdata	_((Elf_Scn *));
2037c478bd9Sstevel@tonic-gate Elf32_Ehdr	*elf32_newehdr	_((Elf *));
2047c478bd9Sstevel@tonic-gate Elf32_Phdr	*elf32_newphdr	_((Elf *, size_t));
2057c478bd9Sstevel@tonic-gate Elf_Scn		*elf_newscn	_((Elf *));
2067c478bd9Sstevel@tonic-gate Elf_Scn		*elf_nextscn	_((Elf *, Elf_Scn *));
2077c478bd9Sstevel@tonic-gate Elf_Cmd		elf_next	_((Elf *));
2087c478bd9Sstevel@tonic-gate size_t		elf_rand	_((Elf *, size_t));
2097c478bd9Sstevel@tonic-gate Elf_Data	*elf_rawdata	_((Elf_Scn *, Elf_Data *));
2107c478bd9Sstevel@tonic-gate char		*elf_rawfile	_((Elf *, size_t *));
2117c478bd9Sstevel@tonic-gate char		*elf_strptr	_((Elf *, size_t, size_t));
2127c478bd9Sstevel@tonic-gate off_t		elf_update	_((Elf *, Elf_Cmd));
2137c478bd9Sstevel@tonic-gate unsigned	elf_version	_((unsigned));
2147c478bd9Sstevel@tonic-gate Elf_Data	*elf32_xlatetof	_((Elf_Data *, const Elf_Data *, unsigned));
2157c478bd9Sstevel@tonic-gate Elf_Data	*elf32_xlatetom	_((Elf_Data *, const Elf_Data *, unsigned));
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(_LONGLONG_TYPE)
2187c478bd9Sstevel@tonic-gate size_t		elf64_fsize	_((Elf_Type, size_t, unsigned));
2197c478bd9Sstevel@tonic-gate Elf64_Ehdr	*elf64_getehdr	_((Elf *));
2207c478bd9Sstevel@tonic-gate Elf64_Phdr	*elf64_getphdr	_((Elf *));
2217c478bd9Sstevel@tonic-gate Elf64_Shdr	*elf64_getshdr	_((Elf_Scn *));
2227c478bd9Sstevel@tonic-gate long		elf64_checksum	_((Elf *));
2237c478bd9Sstevel@tonic-gate Elf64_Ehdr	*elf64_newehdr	_((Elf *));
2247c478bd9Sstevel@tonic-gate Elf64_Phdr	*elf64_newphdr	_((Elf *, size_t));
2257c478bd9Sstevel@tonic-gate Elf_Data	*elf64_xlatetof	_((Elf_Data *, const Elf_Data *, unsigned));
2267c478bd9Sstevel@tonic-gate Elf_Data	*elf64_xlatetom	_((Elf_Data *, const Elf_Data *, unsigned));
2277c478bd9Sstevel@tonic-gate #endif /* (defined(_LP64) || defined(_LONGLONG_TYPE) */
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate #undef	_
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate #endif
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate #endif	/* _LIBELF_H */
236