xref: /freebsd/sys/sys/linker.h (revision f44029e322446469f116bbd26d51ba857083bacb)
1cea6c86cSDoug Rabson /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3c4e20cadSPedro F. Giffuni  *
4326e27d8SDoug Rabson  * Copyright (c) 1997-2000 Doug Rabson
5cea6c86cSDoug Rabson  * All rights reserved.
6cea6c86cSDoug Rabson  *
7cea6c86cSDoug Rabson  * Redistribution and use in source and binary forms, with or without
8cea6c86cSDoug Rabson  * modification, are permitted provided that the following conditions
9cea6c86cSDoug Rabson  * are met:
10cea6c86cSDoug Rabson  * 1. Redistributions of source code must retain the above copyright
11cea6c86cSDoug Rabson  *    notice, this list of conditions and the following disclaimer.
12cea6c86cSDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
13cea6c86cSDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
14cea6c86cSDoug Rabson  *    documentation and/or other materials provided with the distribution.
15cea6c86cSDoug Rabson  *
16cea6c86cSDoug Rabson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17cea6c86cSDoug Rabson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18cea6c86cSDoug Rabson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19cea6c86cSDoug Rabson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20cea6c86cSDoug Rabson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21cea6c86cSDoug Rabson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22cea6c86cSDoug Rabson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23cea6c86cSDoug Rabson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24cea6c86cSDoug Rabson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25cea6c86cSDoug Rabson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26cea6c86cSDoug Rabson  * SUCH DAMAGE.
27cea6c86cSDoug Rabson  */
28cea6c86cSDoug Rabson 
29cea6c86cSDoug Rabson #ifndef _SYS_LINKER_H_
30cea6c86cSDoug Rabson #define _SYS_LINKER_H_
31cea6c86cSDoug Rabson 
32*f44029e3SMark Johnston #include <sys/param.h>
33*f44029e3SMark Johnston 
34664a31e4SPeter Wemm #ifdef _KERNEL
35cea6c86cSDoug Rabson 
3681450045SPeter Wemm #include <machine/elf.h>
37326e27d8SDoug Rabson #include <sys/kobj.h>
3881450045SPeter Wemm 
39452ed6dcSBruce Evans #ifdef MALLOC_DECLARE
40452ed6dcSBruce Evans MALLOC_DECLARE(M_LINKER);
41452ed6dcSBruce Evans #endif
42cea6c86cSDoug Rabson 
4396987c74SBrian Somers struct mod_depend;
4496987c74SBrian Somers 
45cea6c86cSDoug Rabson /*
46cea6c86cSDoug Rabson  * Object representing a file which has been loaded by the linker.
47cea6c86cSDoug Rabson  */
48cea6c86cSDoug Rabson typedef struct linker_file* linker_file_t;
49e3975643SJake Burkholder typedef TAILQ_HEAD(, linker_file) linker_file_list_t;
50cea6c86cSDoug Rabson 
51a2c99e3eSDoug Rabson typedef caddr_t linker_sym_t;		/* opaque symbol */
52d254af07SMatthew Dillon typedef c_caddr_t c_linker_sym_t;	/* const opaque symbol */
53bb9fe9ddSBrian Feldman typedef int (*linker_function_name_callback_t)(const char *, void *);
54a2c99e3eSDoug Rabson 
55a2c99e3eSDoug Rabson /*
56a2c99e3eSDoug Rabson  * expanded out linker_sym_t
57a2c99e3eSDoug Rabson  */
58a2c99e3eSDoug Rabson typedef struct linker_symval {
59a2c99e3eSDoug Rabson     const char*		name;
60a2c99e3eSDoug Rabson     caddr_t		value;
61a2c99e3eSDoug Rabson     size_t		size;
62a2c99e3eSDoug Rabson } linker_symval_t;
63a2c99e3eSDoug Rabson 
64a2024a3eSJohn Birrell typedef int (*linker_function_nameval_callback_t)(linker_file_t, int, linker_symval_t *, void *);
65f6c15301SJohn Birrell 
66cea6c86cSDoug Rabson struct common_symbol {
67e3975643SJake Burkholder     STAILQ_ENTRY(common_symbol) link;
68cea6c86cSDoug Rabson     char*		name;
69cea6c86cSDoug Rabson     caddr_t		address;
70cea6c86cSDoug Rabson };
71cea6c86cSDoug Rabson 
72cea6c86cSDoug Rabson struct linker_file {
73326e27d8SDoug Rabson     KOBJ_FIELDS;
74cea6c86cSDoug Rabson     int			refs;		/* reference count */
7581450045SPeter Wemm     int			userrefs;	/* kldload(2) count */
76149a155cSDoug Rabson     int			flags;
77149a155cSDoug Rabson #define LINKER_FILE_LINKED	0x1	/* file has been fully linked */
78d9ce8a41SConrad Meyer #define LINKER_FILE_MODULES	0x2	/* file has >0 modules at preload */
79e3975643SJake Burkholder     TAILQ_ENTRY(linker_file) link;	/* list of all loaded files */
80cea6c86cSDoug Rabson     char*		filename;	/* file which was loaded */
811676805cSJohn Birrell     char*		pathname;	/* file name with full path */
82cea6c86cSDoug Rabson     int			id;		/* unique id */
83cea6c86cSDoug Rabson     caddr_t		address;	/* load address */
84cea6c86cSDoug Rabson     size_t		size;		/* size of file */
859e575fadSMark Johnston     caddr_t		ctors_addr;	/* address of .ctors/.init_array */
869e575fadSMark Johnston     size_t		ctors_size;	/* size of .ctors/.init_array */
877ef5c19bSMark Johnston     enum {
887ef5c19bSMark Johnston 	    LF_NONE = 0,
897ef5c19bSMark Johnston 	    LF_CTORS,
907ef5c19bSMark Johnston 	    LF_DTORS,
917ef5c19bSMark Johnston     } ctors_invoked;			/* have we run ctors yet? */
929e575fadSMark Johnston     caddr_t		dtors_addr;	/* address of .dtors/.fini_array */
939e575fadSMark Johnston     size_t		dtors_size;	/* size of .dtors/.fini_array */
947b9716baSIan Dowse     int			ndeps;		/* number of dependencies */
957b9716baSIan Dowse     linker_file_t*	deps;		/* list of dependencies */
96e3975643SJake Burkholder     STAILQ_HEAD(, common_symbol) common; /* list of common symbols */
97e3975643SJake Burkholder     TAILQ_HEAD(, module) modules;	/* modules in this file */
98e3975643SJake Burkholder     TAILQ_ENTRY(linker_file) loaded;	/* preload dependency support */
991676805cSJohn Birrell     int			loadcnt;	/* load counter value */
1001676805cSJohn Birrell 
1011676805cSJohn Birrell     /*
1021676805cSJohn Birrell      * Function Boundary Tracing (FBT) or Statically Defined Tracing (SDT)
1031676805cSJohn Birrell      * fields.
1041676805cSJohn Birrell      */
1051676805cSJohn Birrell     int			nenabled;	/* number of enabled probes. */
1061676805cSJohn Birrell     int			fbt_nentries;	/* number of fbt entries created. */
107b19c9deaSIan Lepore 
108b19c9deaSIan Lepore #ifdef __arm__
109b19c9deaSIan Lepore     caddr_t		exidx_addr;	/* Unwind data index table start */
110b19c9deaSIan Lepore     size_t		exidx_size;	/* Unwind data index table size */
111b19c9deaSIan Lepore #endif
112cea6c86cSDoug Rabson };
113cea6c86cSDoug Rabson 
114cea6c86cSDoug Rabson /*
115cea6c86cSDoug Rabson  * Object implementing a class of file (a.out, elf, etc.)
116cea6c86cSDoug Rabson  */
117cea6c86cSDoug Rabson typedef struct linker_class *linker_class_t;
118e3975643SJake Burkholder typedef TAILQ_HEAD(, linker_class) linker_class_list_t;
119cea6c86cSDoug Rabson 
120cea6c86cSDoug Rabson struct linker_class {
121326e27d8SDoug Rabson     KOBJ_CLASS_FIELDS;
122e3975643SJake Burkholder     TAILQ_ENTRY(linker_class) link;	/* list of all file classes */
123cea6c86cSDoug Rabson };
124cea6c86cSDoug Rabson 
125cea6c86cSDoug Rabson /*
12693215106SJohn Baldwin  * Function type used when iterating over the list of linker files.
12793215106SJohn Baldwin  */
12893215106SJohn Baldwin typedef int linker_predicate_t(linker_file_t, void *);
12993215106SJohn Baldwin 
13093215106SJohn Baldwin /*
13184e40f56SPeter Wemm  * The "file" for the kernel.
13284e40f56SPeter Wemm  */
13384e40f56SPeter Wemm extern linker_file_t	linker_kernel_file;
13484e40f56SPeter Wemm 
13584e40f56SPeter Wemm /*
13628a59100SAustin Shafer  * Special symbol which will be replaced by a reference to the linker_file_t
13728a59100SAustin Shafer  * of the module it is used in.
13828a59100SAustin Shafer  */
13928a59100SAustin Shafer extern linker_file_t __this_linker_file;
14028a59100SAustin Shafer 
14128a59100SAustin Shafer /*
14209dbb404SBrian Somers  * Obtain a reference to a module, loading it if required.
14309dbb404SBrian Somers  */
14496987c74SBrian Somers int linker_reference_module(const char* _modname, struct mod_depend *_verinfo,
14596987c74SBrian Somers 			    linker_file_t* _result);
14609dbb404SBrian Somers 
14709dbb404SBrian Somers /*
148aeeb017bSJohn Baldwin  * Release a reference to a module, unloading it if there are no more
149aeeb017bSJohn Baldwin  * references.  Note that one should either provide a module name and
150aeeb017bSJohn Baldwin  * optional version info or a linker file, but not both.
151aeeb017bSJohn Baldwin  */
152aeeb017bSJohn Baldwin int linker_release_module(const char *_modname, struct mod_depend *_verinfo,
153aeeb017bSJohn Baldwin 			  linker_file_t _file);
154aeeb017bSJohn Baldwin 
155aeeb017bSJohn Baldwin /*
15693215106SJohn Baldwin  * Iterate over all of the currently loaded linker files calling the
15793215106SJohn Baldwin  * predicate function while the function returns 0.  Returns the value
15893215106SJohn Baldwin  * returned by the last predicate function.
15993215106SJohn Baldwin  */
16093215106SJohn Baldwin int linker_file_foreach(linker_predicate_t *_predicate, void *_context);
16193215106SJohn Baldwin 
16293215106SJohn Baldwin /*
1637b9716baSIan Dowse  * Lookup a symbol in a file.  If deps is TRUE, look in dependencies
164cea6c86cSDoug Rabson  * if not found in file.
165cea6c86cSDoug Rabson  */
166edf6db62SJohn Baldwin caddr_t linker_file_lookup_symbol(linker_file_t _file, const char* _name,
167edf6db62SJohn Baldwin 				  int _deps);
168cea6c86cSDoug Rabson 
1697ec76718SMike Smith /*
170f41325dbSPeter Wemm  * Lookup a linker set in a file.  Return pointers to the first entry,
171f41325dbSPeter Wemm  * last + 1, and count of entries.  Use: for (p = start; p < stop; p++) {}
172f41325dbSPeter Wemm  * void *start is really: "struct yoursetmember ***start;"
173f41325dbSPeter Wemm  */
174f41325dbSPeter Wemm int linker_file_lookup_set(linker_file_t _file, const char *_name,
175f41325dbSPeter Wemm 			   void *_start, void *_stop, int *_count);
176f41325dbSPeter Wemm 
177f41325dbSPeter Wemm /*
178f6c15301SJohn Birrell  * List all functions in a file.
179f6c15301SJohn Birrell  */
180a2024a3eSJohn Birrell int linker_file_function_listall(linker_file_t,
181a2024a3eSJohn Birrell 				 linker_function_nameval_callback_t, void *);
182f6c15301SJohn Birrell 
183f6c15301SJohn Birrell /*
1847f417bfaSPedro F. Giffuni  * Functions solely for use by the linker class handlers.
18581450045SPeter Wemm  */
186880eb8c1SJohn Baldwin int linker_add_class(linker_class_t _cls);
187880eb8c1SJohn Baldwin int linker_file_unload(linker_file_t _file, int flags);
1887b9716baSIan Dowse int linker_load_dependencies(linker_file_t _lf);
189880eb8c1SJohn Baldwin linker_file_t linker_make_file(const char* _filename, linker_class_t _cls);
19081450045SPeter Wemm 
19181450045SPeter Wemm /*
19281450045SPeter Wemm  * DDB Helpers, tuned specifically for ddb/db_kld.c
19381450045SPeter Wemm  */
194edf6db62SJohn Baldwin int linker_ddb_lookup(const char *_symstr, c_linker_sym_t *_sym);
195edf6db62SJohn Baldwin int linker_ddb_search_symbol(caddr_t _value, c_linker_sym_t *_sym,
196edf6db62SJohn Baldwin 			     long *_diffp);
197edf6db62SJohn Baldwin int linker_ddb_symbol_values(c_linker_sym_t _sym, linker_symval_t *_symval);
198cdd475b3SRobert Watson int linker_ddb_search_symbol_name(caddr_t value, char *buf, u_int buflen,
199cdd475b3SRobert Watson 				  long *offset);
200cdd475b3SRobert Watson 
201cdd475b3SRobert Watson /*
202cdd475b3SRobert Watson  * stack(9) helper for situations where kernel locking is required.
203cdd475b3SRobert Watson  */
204d158fa4aSConrad Meyer int linker_search_symbol_name_flags(caddr_t value, char *buf, u_int buflen,
205d158fa4aSConrad Meyer     long *offset, int flags);
206cdd475b3SRobert Watson int linker_search_symbol_name(caddr_t value, char *buf, u_int buflen,
207cdd475b3SRobert Watson     long *offset);
20881450045SPeter Wemm 
20949874f6eSJoseph Koshy /* HWPMC helper */
21049874f6eSJoseph Koshy void *linker_hwpmc_list_objects(void);
21149874f6eSJoseph Koshy 
212e266a0f7SKonstantin Belousov /* kldload/kldunload syscalls blocking */
213e266a0f7SKonstantin Belousov #define	LINKER_UB_UNLOCK	0x0001	/* busy: unlock kld_sx locked on
214e266a0f7SKonstantin Belousov 					   return */
215e266a0f7SKonstantin Belousov #define	LINKER_UB_LOCKED	0x0002	/* busy/unbusy: kld_sx locked on
216e266a0f7SKonstantin Belousov 					   entry */
217e266a0f7SKonstantin Belousov #define	LINKER_UB_PCATCH	0x0004	/* busy: sleep interruptible */
218e266a0f7SKonstantin Belousov int linker_kldload_busy(int flags);
219e266a0f7SKonstantin Belousov void linker_kldload_unbusy(int flags);
220e266a0f7SKonstantin Belousov 
221664a31e4SPeter Wemm #endif	/* _KERNEL */
22281450045SPeter Wemm 
22381450045SPeter Wemm /*
2247ec76718SMike Smith  * Module information subtypes
2257ec76718SMike Smith  */
22681450045SPeter Wemm #define MODINFO_END		0x0000		/* End of list */
22781450045SPeter Wemm #define MODINFO_NAME		0x0001		/* Name of module (string) */
22881450045SPeter Wemm #define MODINFO_TYPE		0x0002		/* Type of module (string) */
22981450045SPeter Wemm #define MODINFO_ADDR		0x0003		/* Loaded address */
23081450045SPeter Wemm #define MODINFO_SIZE		0x0004		/* Size of module */
23181450045SPeter Wemm #define MODINFO_EMPTY		0x0005		/* Has been deleted */
232445a0357SDaniel C. Sobral #define MODINFO_ARGS		0x0006		/* Parameters string */
23381450045SPeter Wemm #define MODINFO_METADATA	0x8000		/* Module-specfic */
2347ec76718SMike Smith 
2357ec76718SMike Smith #define MODINFOMD_AOUTEXEC	0x0001		/* a.out exec header */
2367ec76718SMike Smith #define MODINFOMD_ELFHDR	0x0002		/* ELF header */
23781450045SPeter Wemm #define MODINFOMD_SSYM		0x0003		/* start of symbols */
23881450045SPeter Wemm #define MODINFOMD_ESYM		0x0004		/* end of symbols */
23981450045SPeter Wemm #define MODINFOMD_DYNAMIC	0x0005		/* _DYNAMIC pointer */
240adda2797SRoger Pau Monné #define MODINFOMD_MB2HDR	0x0006		/* MB2 header info */
24158aa35d4SWarner Losh /* These values are MD on PowerPC */
24258aa35d4SWarner Losh #if !defined(__powerpc__)
2437f476681SPeter Wemm #define MODINFOMD_ENVP		0x0006		/* envp[] */
2447f476681SPeter Wemm #define MODINFOMD_HOWTO		0x0007		/* boothowto */
2457f476681SPeter Wemm #define MODINFOMD_KERNEND	0x0008		/* kernend */
2467f476681SPeter Wemm #endif
2476f2e8645SIan Dowse #define MODINFOMD_SHDR		0x0009		/* section header table */
2480067051fSMarcel Moolenaar #define MODINFOMD_CTORS_ADDR	0x000a		/* address of .ctors */
2490067051fSMarcel Moolenaar #define MODINFOMD_CTORS_SIZE	0x000b		/* size of .ctors */
25088dd7272SWarner Losh #define MODINFOMD_FW_HANDLE	0x000c		/* Firmware dependent handle */
251ec5c0e5bSAllan Jude #define MODINFOMD_KEYBUF	0x000d		/* Crypto key intake buffer */
25293b18e37SToomas Soome #define MODINFOMD_FONT		0x000e		/* Console font */
253966e53a4SEmmanuel Vadot #define MODINFOMD_SPLASH	0x000f		/* Console splash screen */
2547ec76718SMike Smith #define MODINFOMD_NOCOPY	0x8000		/* don't copy this metadata to the kernel */
2557ec76718SMike Smith 
25681450045SPeter Wemm #define MODINFOMD_DEPLIST	(0x4001 | MODINFOMD_NOCOPY)	/* depends on */
25781450045SPeter Wemm 
2587f476681SPeter Wemm #ifdef _KERNEL
2597f476681SPeter Wemm #define MD_FETCH(mdp, info, type) ({ \
2607f476681SPeter Wemm 	type *__p; \
2617f476681SPeter Wemm 	__p = (type *)preload_search_info((mdp), MODINFO_METADATA | (info)); \
2627f476681SPeter Wemm 	__p ? *__p : 0; \
2637f476681SPeter Wemm })
2647f476681SPeter Wemm #endif
2657f476681SPeter Wemm 
266505222d3SPeter Wemm #define	LINKER_HINTS_VERSION	1		/* linker.hints file version */
267fac92ae1SWarner Losh #define	LINKER_HINTS_MAX	(1 << 20)	/* Allow at most 1MB for linker.hints */
268505222d3SPeter Wemm 
269664a31e4SPeter Wemm #ifdef _KERNEL
2707ec76718SMike Smith 
2711d13be33SMike Smith /*
2721d13be33SMike Smith  * Module lookup
2731d13be33SMike Smith  */
274278e7970SMarcel Moolenaar extern vm_offset_t	preload_addr_relocate;
27581450045SPeter Wemm extern caddr_t		preload_metadata;
276278e7970SMarcel Moolenaar 
277278e7970SMarcel Moolenaar extern void *		preload_fetch_addr(caddr_t _mod);
278278e7970SMarcel Moolenaar extern size_t		preload_fetch_size(caddr_t _mod);
279edf6db62SJohn Baldwin extern caddr_t		preload_search_by_name(const char *_name);
280edf6db62SJohn Baldwin extern caddr_t		preload_search_by_type(const char *_type);
281edf6db62SJohn Baldwin extern caddr_t		preload_search_next_name(caddr_t _base);
282edf6db62SJohn Baldwin extern caddr_t		preload_search_info(caddr_t _mod, int _inf);
283edf6db62SJohn Baldwin extern void		preload_delete_name(const char *_name);
284edf6db62SJohn Baldwin extern void		preload_bootstrap_relocate(vm_offset_t _offset);
28522e6a670SMitchell Horne extern void		preload_dump(void);
2861d13be33SMike Smith 
287cea6c86cSDoug Rabson #ifdef KLD_DEBUG
288cea6c86cSDoug Rabson 
289cea6c86cSDoug Rabson extern int kld_debug;
290cea6c86cSDoug Rabson #define KLD_DEBUG_FILE	1	/* file load/unload */
291cea6c86cSDoug Rabson #define KLD_DEBUG_SYM	2	/* symbol lookup */
292cea6c86cSDoug Rabson 
293cea6c86cSDoug Rabson #define KLD_DPF(cat, args)					\
294cea6c86cSDoug Rabson 	do {							\
29581450045SPeter Wemm 		if (kld_debug & KLD_DEBUG_##cat) printf args;	\
296cea6c86cSDoug Rabson 	} while (0)
297cea6c86cSDoug Rabson 
298cea6c86cSDoug Rabson #else
299cea6c86cSDoug Rabson 
300cea6c86cSDoug Rabson #define KLD_DPF(cat, args)
301cea6c86cSDoug Rabson 
302cea6c86cSDoug Rabson #endif
303cea6c86cSDoug Rabson 
304cff8c6f2SKonstantin Belousov typedef int elf_lookup_fn(linker_file_t, Elf_Size, int, Elf_Addr *);
305e8855d4fSPeter Wemm 
30681450045SPeter Wemm /* Support functions */
30736716fe2SMark Johnston bool	elf_is_ifunc_reloc(Elf_Size r_info);
3087035cf14SKonstantin Belousov int	elf_reloc(linker_file_t _lf, Elf_Addr base, const void *_rel,
3097035cf14SKonstantin Belousov 	    int _type, elf_lookup_fn _lu);
3107035cf14SKonstantin Belousov int	elf_reloc_local(linker_file_t _lf, Elf_Addr base, const void *_rel,
3117035cf14SKonstantin Belousov 	    int _type, elf_lookup_fn _lu);
31250c202c5SJeff Roberson Elf_Addr elf_relocaddr(linker_file_t _lf, Elf_Addr addr);
313757686b1SMarcel Moolenaar const Elf_Sym *elf_get_sym(linker_file_t _lf, Elf_Size _symidx);
314757686b1SMarcel Moolenaar const char *elf_get_symname(linker_file_t _lf, Elf_Size _symidx);
3157035cf14SKonstantin Belousov void	link_elf_ireloc(caddr_t kmdp);
316d297ad16SMarcel Moolenaar 
317fcf7a481SAndrew Turner #if defined(__aarch64__) || defined(__amd64__)
318fcf7a481SAndrew Turner int	elf_reloc_late(linker_file_t _lf, Elf_Addr base, const void *_rel,
319fcf7a481SAndrew Turner 	    int _type, elf_lookup_fn _lu);
320fcf7a481SAndrew Turner void	link_elf_late_ireloc(void);
321fcf7a481SAndrew Turner #endif
322fcf7a481SAndrew Turner 
323a2024a3eSJohn Birrell typedef struct linker_ctf {
324a2024a3eSJohn Birrell 	const uint8_t 	*ctftab;	/* Decompressed CTF data. */
325a2024a3eSJohn Birrell 	int 		ctfcnt;		/* Number of CTF data bytes. */
326a2024a3eSJohn Birrell 	const Elf_Sym	*symtab;	/* Ptr to the symbol table. */
327a2024a3eSJohn Birrell 	int		nsym;		/* Number of symbols. */
328a2024a3eSJohn Birrell 	const char	*strtab;	/* Ptr to the string table. */
329a2024a3eSJohn Birrell 	int 		strcnt;		/* Number of string bytes. */
330a2024a3eSJohn Birrell 	uint32_t	**ctfoffp;	/* Ptr to array of obj/fnc offsets. */
331a2024a3eSJohn Birrell 	uint32_t	**typoffp;	/* Ptr to array of type offsets. */
332a2024a3eSJohn Birrell 	long		*typlenp;	/* Ptr to number of type data entries. */
333a2024a3eSJohn Birrell } linker_ctf_t;
334a2024a3eSJohn Birrell 
335a2024a3eSJohn Birrell int	linker_ctf_get(linker_file_t, linker_ctf_t *);
336c21bc6f3SBojan Novković int linker_ctf_lookup_sym_ddb(const char *symname, c_linker_sym_t *sym,
337c21bc6f3SBojan Novković     linker_ctf_t *lc);
338c21bc6f3SBojan Novković int linker_ctf_lookup_typename_ddb(linker_ctf_t *lc, const char *typename);
339a2024a3eSJohn Birrell 
3401aeb23cdSMarcel Moolenaar int elf_cpu_load_file(linker_file_t);
3411aeb23cdSMarcel Moolenaar int elf_cpu_unload_file(linker_file_t);
34230693808SBrandon Bergren int elf_cpu_parse_dynamic(caddr_t, Elf_Dyn *);
3431aeb23cdSMarcel Moolenaar 
344aa855a59SPeter Wemm /* values for type */
345aa855a59SPeter Wemm #define ELF_RELOC_REL	1
346aa855a59SPeter Wemm #define ELF_RELOC_RELA	2
34781450045SPeter Wemm 
3481676805cSJohn Birrell /*
3491676805cSJohn Birrell  * This is version 1 of the KLD file status structure. It is identified
350c9f54e81SRuslan Ermilov  * by its _size_ in the version field.
3511676805cSJohn Birrell  */
3521676805cSJohn Birrell struct kld_file_stat_1 {
353c9f54e81SRuslan Ermilov     int		version;	/* set to sizeof(struct kld_file_stat_1) */
3541676805cSJohn Birrell     char        name[MAXPATHLEN];
3551676805cSJohn Birrell     int		refs;
3561676805cSJohn Birrell     int		id;
3571676805cSJohn Birrell     caddr_t	address;	/* load address */
3581676805cSJohn Birrell     size_t	size;		/* size in bytes */
3591676805cSJohn Birrell };
360664a31e4SPeter Wemm #endif /* _KERNEL */
361cea6c86cSDoug Rabson 
362cea6c86cSDoug Rabson struct kld_file_stat {
363c9f54e81SRuslan Ermilov     int		version;	/* set to sizeof(struct kld_file_stat) */
364cea6c86cSDoug Rabson     char        name[MAXPATHLEN];
365cea6c86cSDoug Rabson     int		refs;
366cea6c86cSDoug Rabson     int		id;
367cea6c86cSDoug Rabson     caddr_t	address;	/* load address */
368cea6c86cSDoug Rabson     size_t	size;		/* size in bytes */
3691676805cSJohn Birrell     char        pathname[MAXPATHLEN];
370cea6c86cSDoug Rabson };
371cea6c86cSDoug Rabson 
372ba031106SPeter Wemm struct kld_sym_lookup {
373ba031106SPeter Wemm     int		version;	/* set to sizeof(struct kld_sym_lookup) */
374ba031106SPeter Wemm     char	*symname;	/* Symbol name we are looking up */
375ba031106SPeter Wemm     u_long	symvalue;
376ba031106SPeter Wemm     size_t	symsize;
377ba031106SPeter Wemm };
378ba031106SPeter Wemm #define KLDSYM_LOOKUP	1
379ba031106SPeter Wemm 
38065a311fcSPoul-Henning Kamp /*
38165a311fcSPoul-Henning Kamp  * Flags for kldunloadf() and linker_file_unload()
38265a311fcSPoul-Henning Kamp  */
38365a311fcSPoul-Henning Kamp #define LINKER_UNLOAD_NORMAL	0
38465a311fcSPoul-Henning Kamp #define LINKER_UNLOAD_FORCE	1
38565a311fcSPoul-Henning Kamp 
386664a31e4SPeter Wemm #ifndef _KERNEL
387cea6c86cSDoug Rabson 
388cea6c86cSDoug Rabson #include <sys/cdefs.h>
389cea6c86cSDoug Rabson 
390cea6c86cSDoug Rabson __BEGIN_DECLS
391edf6db62SJohn Baldwin int	kldload(const char* _file);
392edf6db62SJohn Baldwin int	kldunload(int _fileid);
39365a311fcSPoul-Henning Kamp int	kldunloadf(int _fileid, int flags);
394edf6db62SJohn Baldwin int	kldfind(const char* _file);
395edf6db62SJohn Baldwin int	kldnext(int _fileid);
396edf6db62SJohn Baldwin int	kldstat(int _fileid, struct kld_file_stat* _stat);
397edf6db62SJohn Baldwin int	kldfirstmod(int _fileid);
398ba031106SPeter Wemm int	kldsym(int _fileid, int _cmd, void *_data);
399cea6c86cSDoug Rabson __END_DECLS
400cea6c86cSDoug Rabson 
401cea6c86cSDoug Rabson #endif
402cea6c86cSDoug Rabson 
403452ed6dcSBruce Evans #endif /* !_SYS_LINKER_H_ */
404