xref: /titanic_50/usr/src/head/link.h (revision ba3594ba9b5dd4c846c472a8d657edcb7c8109ac)
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
59acbbeafSnn35248  * Common Development and Distribution License (the "License").
69acbbeafSnn35248  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*ba3594baSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
232020b2b6SRod Evans  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _LINK_H
277c478bd9Sstevel@tonic-gate #define	_LINK_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/link.h>
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifndef _ASM
324d1bea1dSRichard Lowe #include <elf.h>
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <dlfcn.h>
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifndef _ASM
427c478bd9Sstevel@tonic-gate /*
434d1bea1dSRichard Lowe  * ld support library calls.
444d1bea1dSRichard Lowe  *
454d1bea1dSRichard Lowe  * These cannot be used in a 32bit large file capable environment because
464d1bea1dSRichard Lowe  * libelf is not large-file safe.  Only define these interfaces if we are not
474d1bea1dSRichard Lowe  * 32bit, or not in the large file environment.
487c478bd9Sstevel@tonic-gate  */
494d1bea1dSRichard Lowe #if !defined(_ILP32) || _FILE_OFFSET_BITS != 64
504d1bea1dSRichard Lowe #include <libelf.h>
517c478bd9Sstevel@tonic-gate extern uint_t	ld_version(uint_t);
523906e0c2Srie extern void	ld_input_done(uint_t *);
533906e0c2Srie 
547c478bd9Sstevel@tonic-gate extern void	ld_start(const char *, const Elf32_Half, const char *);
557c478bd9Sstevel@tonic-gate extern void	ld_atexit(int);
563906e0c2Srie extern void	ld_open(const char **, const char **, int *, int, Elf **,
573906e0c2Srie 			Elf *, size_t, const Elf_Kind);
587c478bd9Sstevel@tonic-gate extern void	ld_file(const char *, const Elf_Kind, int, Elf *);
597c478bd9Sstevel@tonic-gate extern void	ld_input_section(const char *, Elf32_Shdr **, Elf32_Word,
607c478bd9Sstevel@tonic-gate 			Elf_Data *, Elf *, uint_t *);
617c478bd9Sstevel@tonic-gate extern void	ld_section(const char *, Elf32_Shdr *, Elf32_Word,
627c478bd9Sstevel@tonic-gate 			Elf_Data *, Elf *);
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(_LONGLONG_TYPE)
657c478bd9Sstevel@tonic-gate extern void	ld_start64(const char *, const Elf64_Half, const char *);
667c478bd9Sstevel@tonic-gate extern void	ld_atexit64(int);
673906e0c2Srie extern void	ld_open64(const char **, const char **, int *, int, Elf **,
683906e0c2Srie 			Elf *, size_t, const Elf_Kind);
697c478bd9Sstevel@tonic-gate extern void	ld_file64(const char *, const Elf_Kind, int, Elf *);
707c478bd9Sstevel@tonic-gate extern void	ld_input_section64(const char *, Elf64_Shdr **, Elf64_Word,
717c478bd9Sstevel@tonic-gate 			Elf_Data *, Elf *, uint_t *);
727c478bd9Sstevel@tonic-gate extern void	ld_section64(const char *, Elf64_Shdr *, Elf64_Word,
737c478bd9Sstevel@tonic-gate 			Elf_Data *, Elf *);
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate #endif /* (defined(_LP64) || defined(_LONGLONG_TYPE) */
764d1bea1dSRichard Lowe #endif /* !defined(_ILP32) || _FILE_OFFSET_BITS != 64 */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate /*
793906e0c2Srie  * ld_version() version values.
807c478bd9Sstevel@tonic-gate  */
817c478bd9Sstevel@tonic-gate #define	LD_SUP_VNONE	0
827c478bd9Sstevel@tonic-gate #define	LD_SUP_VERSION1	1
837c478bd9Sstevel@tonic-gate #define	LD_SUP_VERSION2	2
843906e0c2Srie #define	LD_SUP_VERSION3	3
853906e0c2Srie #define	LD_SUP_VCURRENT	LD_SUP_VERSION3
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate /*
883906e0c2Srie  * Flags passed to ld support calls.
897c478bd9Sstevel@tonic-gate  */
907c478bd9Sstevel@tonic-gate #define	LD_SUP_DERIVED		0x1	/* derived filename */
917c478bd9Sstevel@tonic-gate #define	LD_SUP_INHERITED	0x2	/* file inherited from .so DT_NEEDED */
927c478bd9Sstevel@tonic-gate #define	LD_SUP_EXTRACTED	0x4	/* file extracted from archive */
937c478bd9Sstevel@tonic-gate #endif
947c478bd9Sstevel@tonic-gate 
953906e0c2Srie /*
963906e0c2Srie  * Runtime link-map identifiers.
973906e0c2Srie  */
987c478bd9Sstevel@tonic-gate #define	LM_ID_BASE		0x00
997c478bd9Sstevel@tonic-gate #define	LM_ID_LDSO		0x01
10022872efbSedp #define	LM_ID_NUM		2
1019acbbeafSnn35248 
10222872efbSedp #define	LM_ID_BRAND		0xfd	/* brand emulation linkmap objs */
10322872efbSedp #define	LM_ID_NONE		0xfe	/* no link map specified */
1047c478bd9Sstevel@tonic-gate #define	LM_ID_NEWLM		0xff	/* create a new link-map */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /*
1073906e0c2Srie  * Runtime Link-Edit Auditing.
1087c478bd9Sstevel@tonic-gate  */
1097c478bd9Sstevel@tonic-gate #define	LAV_NONE		0
1107c478bd9Sstevel@tonic-gate #define	LAV_VERSION1		1
1117c478bd9Sstevel@tonic-gate #define	LAV_VERSION2		2
1127c478bd9Sstevel@tonic-gate #define	LAV_VERSION3		3
1137247f888Srie #define	LAV_VERSION4		4
1142020b2b6SRod Evans #define	LAV_VERSION5		5
1152020b2b6SRod Evans #define	LAV_CURRENT		LAV_VERSION5
1162020b2b6SRod Evans #define	LAV_NUM			6
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate /*
1197c478bd9Sstevel@tonic-gate  * Flags that can be or'd into the la_objopen() return code
1207c478bd9Sstevel@tonic-gate  */
1217c478bd9Sstevel@tonic-gate #define	LA_FLG_BINDTO		0x0001	/* audit symbinds TO this object */
1227c478bd9Sstevel@tonic-gate #define	LA_FLG_BINDFROM		0x0002	/* audit symbinding FROM this object */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate /*
1257c478bd9Sstevel@tonic-gate  * Flags that can be or'd into the 'flags' argument of la_symbind()
1267c478bd9Sstevel@tonic-gate  */
1277c478bd9Sstevel@tonic-gate #define	LA_SYMB_NOPLTENTER	0x0001	/* disable pltenter for this symbol */
1287c478bd9Sstevel@tonic-gate #define	LA_SYMB_NOPLTEXIT	0x0002	/* disable pltexit for this symbol */
1297c478bd9Sstevel@tonic-gate #define	LA_SYMB_STRUCTCALL	0x0004	/* this function call passes a */
1307c478bd9Sstevel@tonic-gate 					/*	structure as it's return code */
1317c478bd9Sstevel@tonic-gate #define	LA_SYMB_DLSYM		0x0008	/* this symbol bindings is due to */
1327c478bd9Sstevel@tonic-gate 					/*	a call to dlsym() */
1337c478bd9Sstevel@tonic-gate #define	LA_SYMB_ALTVALUE	0x0010	/* alternate symbol binding returned */
1347c478bd9Sstevel@tonic-gate 					/*	by la_symbind() */
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * Flags that describe the object passed to la_objsearch()
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate #define	LA_SER_ORIG		0x001	/* original (needed) name */
1407c478bd9Sstevel@tonic-gate #define	LA_SER_LIBPATH		0x002	/* LD_LIBRARY_PATH entry prepended */
1417c478bd9Sstevel@tonic-gate #define	LA_SER_RUNPATH		0x004	/* runpath entry prepended */
1427c478bd9Sstevel@tonic-gate #define	LA_SER_CONFIG		0x008	/* configuration entry prepended */
1437c478bd9Sstevel@tonic-gate #define	LA_SER_DEFAULT		0x040	/* default path prepended */
1447c478bd9Sstevel@tonic-gate #define	LA_SER_SECURE		0x080	/* default (secure) path prepended */
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate #define	LA_SER_MASK		0xfff	/* mask of known flags */
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /*
1497c478bd9Sstevel@tonic-gate  * Flags that describe the la_activity()
1507c478bd9Sstevel@tonic-gate  */
1517c478bd9Sstevel@tonic-gate #define	LA_ACT_CONSISTENT	0x00	/* add/deletion of objects complete */
1527c478bd9Sstevel@tonic-gate #define	LA_ACT_ADD		0x01	/* objects being added */
1537c478bd9Sstevel@tonic-gate #define	LA_ACT_DELETE		0x02	/* objects being deleted */
1542020b2b6SRod Evans #define	LA_ACT_MAX		3
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate #ifndef	_KERNEL
1587c478bd9Sstevel@tonic-gate #ifndef	_ASM
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate #if defined(_LP64)
1617c478bd9Sstevel@tonic-gate typedef long	lagreg_t;
1627c478bd9Sstevel@tonic-gate #else
1637c478bd9Sstevel@tonic-gate typedef int	lagreg_t;
1647c478bd9Sstevel@tonic-gate #endif
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate struct _la_sparc_regs {
1677c478bd9Sstevel@tonic-gate 	lagreg_t	lr_rego0;
1687c478bd9Sstevel@tonic-gate 	lagreg_t	lr_rego1;
1697c478bd9Sstevel@tonic-gate 	lagreg_t	lr_rego2;
1707c478bd9Sstevel@tonic-gate 	lagreg_t	lr_rego3;
1717c478bd9Sstevel@tonic-gate 	lagreg_t	lr_rego4;
1727c478bd9Sstevel@tonic-gate 	lagreg_t	lr_rego5;
1737c478bd9Sstevel@tonic-gate 	lagreg_t	lr_rego6;
1747c478bd9Sstevel@tonic-gate 	lagreg_t	lr_rego7;
1757c478bd9Sstevel@tonic-gate };
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate #if defined(_LP64)
1787c478bd9Sstevel@tonic-gate typedef struct _la_sparc_regs	La_sparcv9_regs;
1797c478bd9Sstevel@tonic-gate typedef struct {
1807c478bd9Sstevel@tonic-gate 	lagreg_t	lr_rsp;
1817c478bd9Sstevel@tonic-gate 	lagreg_t	lr_rbp;
1827c478bd9Sstevel@tonic-gate 	lagreg_t	lr_rdi;	    /* arg1 */
1837c478bd9Sstevel@tonic-gate 	lagreg_t	lr_rsi;	    /* arg2 */
1847c478bd9Sstevel@tonic-gate 	lagreg_t	lr_rdx;	    /* arg3 */
1857c478bd9Sstevel@tonic-gate 	lagreg_t	lr_rcx;	    /* arg4 */
1867c478bd9Sstevel@tonic-gate 	lagreg_t	lr_r8;	    /* arg5 */
1877c478bd9Sstevel@tonic-gate 	lagreg_t	lr_r9;	    /* arg6 */
1887c478bd9Sstevel@tonic-gate } La_amd64_regs;
1897c478bd9Sstevel@tonic-gate #else
1907c478bd9Sstevel@tonic-gate typedef struct _la_sparc_regs	La_sparcv8_regs;
1917c478bd9Sstevel@tonic-gate typedef struct {
1927c478bd9Sstevel@tonic-gate 	lagreg_t	lr_esp;
1937c478bd9Sstevel@tonic-gate 	lagreg_t	lr_ebp;
1947c478bd9Sstevel@tonic-gate } La_i86_regs;
1957c478bd9Sstevel@tonic-gate #endif
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate #if	!defined(_SYS_INT_TYPES_H)
1987c478bd9Sstevel@tonic-gate #if	defined(_LP64) || defined(_I32LPx)
1997c478bd9Sstevel@tonic-gate typedef unsigned long		uintptr_t;
2007c478bd9Sstevel@tonic-gate #else
2017c478bd9Sstevel@tonic-gate typedef	unsigned int		uintptr_t;
2027c478bd9Sstevel@tonic-gate #endif
2037c478bd9Sstevel@tonic-gate #endif
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate extern uint_t		la_version(uint_t);
2077c478bd9Sstevel@tonic-gate extern void		la_activity(uintptr_t *, uint_t);
2087c478bd9Sstevel@tonic-gate extern void		la_preinit(uintptr_t *);
2097c478bd9Sstevel@tonic-gate extern char		*la_objsearch(const char *, uintptr_t *, uint_t);
2107c478bd9Sstevel@tonic-gate extern uint_t		la_objopen(Link_map *, Lmid_t, uintptr_t *);
2117c478bd9Sstevel@tonic-gate extern uint_t		la_objclose(uintptr_t *);
2127c478bd9Sstevel@tonic-gate extern int		la_objfilter(uintptr_t *, const char *, uintptr_t *,
2137c478bd9Sstevel@tonic-gate 				uint_t);
2147c478bd9Sstevel@tonic-gate #if	defined(_LP64)
2157c478bd9Sstevel@tonic-gate extern uintptr_t	la_amd64_pltenter(Elf64_Sym *, uint_t, uintptr_t *,
2167c478bd9Sstevel@tonic-gate 				uintptr_t *, La_amd64_regs *,	uint_t *,
2177c478bd9Sstevel@tonic-gate 				const char *);
2187c478bd9Sstevel@tonic-gate extern uintptr_t	la_symbind64(Elf64_Sym *, uint_t, uintptr_t *,
2197c478bd9Sstevel@tonic-gate 				uintptr_t *, uint_t *, const char *);
2207c478bd9Sstevel@tonic-gate extern uintptr_t	la_sparcv9_pltenter(Elf64_Sym *, uint_t, uintptr_t *,
2217c478bd9Sstevel@tonic-gate 				uintptr_t *, La_sparcv9_regs *,	uint_t *,
2227c478bd9Sstevel@tonic-gate 				const char *);
2237c478bd9Sstevel@tonic-gate extern uintptr_t	la_pltexit64(Elf64_Sym *, uint_t, uintptr_t *,
2247c478bd9Sstevel@tonic-gate 				uintptr_t *, uintptr_t, const char *);
2257c478bd9Sstevel@tonic-gate #else  /* !defined(_LP64) */
2267c478bd9Sstevel@tonic-gate extern uintptr_t	la_symbind32(Elf32_Sym *, uint_t, uintptr_t *,
2277c478bd9Sstevel@tonic-gate 				uintptr_t *, uint_t *);
2287c478bd9Sstevel@tonic-gate extern uintptr_t	la_sparcv8_pltenter(Elf32_Sym *, uint_t, uintptr_t *,
2297c478bd9Sstevel@tonic-gate 				uintptr_t *, La_sparcv8_regs *, uint_t *);
2307c478bd9Sstevel@tonic-gate extern uintptr_t	la_i86_pltenter(Elf32_Sym *, uint_t, uintptr_t *,
2317c478bd9Sstevel@tonic-gate 				uintptr_t *, La_i86_regs *, uint_t *);
2327c478bd9Sstevel@tonic-gate extern uintptr_t	la_pltexit(Elf32_Sym *, uint_t, uintptr_t *,
2337c478bd9Sstevel@tonic-gate 				uintptr_t *, uintptr_t);
2347c478bd9Sstevel@tonic-gate #endif /* _LP64 */
2357c478bd9Sstevel@tonic-gate 
23620272c2eSAli Bahrami /*
23720272c2eSAli Bahrami  * The ElfW() macro is a GNU/Linux feature, provided as support for
23820272c2eSAli Bahrami  * the dl_phdr_info structure used by dl_phdr_iterate(), which also
23920272c2eSAli Bahrami  * originated under Linux. Given an ELF data type, without the ElfXX_
24020272c2eSAli Bahrami  * prefix, it supplies the appropriate prefix (Elf32_ or Elf64_) for
24120272c2eSAli Bahrami  * the ELFCLASS of the code being compiled.
24220272c2eSAli Bahrami  *
24320272c2eSAli Bahrami  * Note that ElfW() is not suitable in situations in which the ELFCLASS
24420272c2eSAli Bahrami  * of the code being compiled does not match that of the objects that
24520272c2eSAli Bahrami  * code is intended to operate on (e.g. a 32-bit link-editor building
24620272c2eSAli Bahrami  * a 64-bit object). The macros defined in <sys/machelf.h> are
24720272c2eSAli Bahrami  * recommended in such cases.
24820272c2eSAli Bahrami  */
24920272c2eSAli Bahrami #ifdef _LP64
25020272c2eSAli Bahrami #define	ElfW(type)	Elf64_ ## type
25120272c2eSAli Bahrami #else
25220272c2eSAli Bahrami #define	ElfW(type)	Elf32_ ## type
25320272c2eSAli Bahrami #endif
25420272c2eSAli Bahrami 
25520272c2eSAli Bahrami /*
25620272c2eSAli Bahrami  * The callback function to dl_interate_phdr() receives a pointer
25720272c2eSAli Bahrami  * to a structure of this type.
25820272c2eSAli Bahrami  *
25920272c2eSAli Bahrami  * dlpi_addr is defined such that the address of any segment in
26020272c2eSAli Bahrami  * the program header array can be calculated as:
26120272c2eSAli Bahrami  *
26220272c2eSAli Bahrami  *	addr == info->dlpi_addr + info->dlpi_phdr[x].p_vaddr;
26320272c2eSAli Bahrami  *
26420272c2eSAli Bahrami  * It is therefore 0 for ET_EXEC objects, and the base address at
26520272c2eSAli Bahrami  * which the object is mapped otherwise.
26620272c2eSAli Bahrami  */
26720272c2eSAli Bahrami struct dl_phdr_info {
26820272c2eSAli Bahrami 	ElfW(Addr)		dlpi_addr;	/* Base address of object */
26920272c2eSAli Bahrami 	const char		*dlpi_name;	/* Null-terminated obj name */
27020272c2eSAli Bahrami 	const ElfW(Phdr)	*dlpi_phdr;	/* Ptr to ELF program hdr arr */
27120272c2eSAli Bahrami 	ElfW(Half)		dlpi_phnum;	/* # of items in dlpi_phdr[] */
27220272c2eSAli Bahrami 
27320272c2eSAli Bahrami 	/*
27420272c2eSAli Bahrami 	 * Note: Following members were introduced after the first version
27520272c2eSAli Bahrami 	 * of this structure was available.  The dl_iterate_phdr() callback
27620272c2eSAli Bahrami 	 * function is passed a 'size' argument giving the size of the info
27720272c2eSAli Bahrami 	 * structure, and must compare that size to the offset of these fields
27820272c2eSAli Bahrami 	 * before accessing them to ensure that they are present.
27920272c2eSAli Bahrami 	 */
28020272c2eSAli Bahrami 
28120272c2eSAli Bahrami 	/* Incremented when a new object is mapped into the process */
28220272c2eSAli Bahrami 	u_longlong_t		dlpi_adds;
28320272c2eSAli Bahrami 	/* Incremented when an object is unmapped from the process */
28420272c2eSAli Bahrami 	u_longlong_t		dlpi_subs;
28520272c2eSAli Bahrami };
28620272c2eSAli Bahrami 
28720272c2eSAli Bahrami extern  int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *),
28820272c2eSAli Bahrami 	    void *);
28920272c2eSAli Bahrami 
2907c478bd9Sstevel@tonic-gate #endif	/* _ASM */
2917c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
2927c478bd9Sstevel@tonic-gate 
29320272c2eSAli Bahrami 
2947c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2957c478bd9Sstevel@tonic-gate }
2967c478bd9Sstevel@tonic-gate #endif
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate #endif	/* _LINK_H */
299