199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1997-2000 Doug Rabson
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Object representing a file which has been loaded by the linker.
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef TAILQ_HEAD(, linker_file) linker_file_list_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef caddr_t linker_sym_t; /* opaque symbol */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef c_caddr_t c_linker_sym_t; /* const opaque symbol */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef int (*linker_function_name_callback_t)(const char *, void *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * expanded out linker_sym_t
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef int (*linker_function_nameval_callback_t)(linker_file_t, int, linker_symval_t *, void *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define LINKER_FILE_LINKED 0x1 /* file has been fully linked */
199767f8919635c4928607450d9e0abb932109ceToomas Soome TAILQ_ENTRY(linker_file) link; /* list of all loaded files */
199767f8919635c4928607450d9e0abb932109ceToomas Soome linker_file_t* deps; /* list of dependencies */
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_HEAD(, common_symbol) common; /* list of common symbols */
199767f8919635c4928607450d9e0abb932109ceToomas Soome TAILQ_HEAD(, module) modules; /* modules in this file */
199767f8919635c4928607450d9e0abb932109ceToomas Soome TAILQ_ENTRY(linker_file) loaded; /* preload dependency support */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Function Boundary Tracing (FBT) or Statically Defined Tracing (SDT)
199767f8919635c4928607450d9e0abb932109ceToomas Soome int fbt_nentries; /* number of fbt entries created. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Object implementing a class of file (a.out, elf, etc.)
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef TAILQ_HEAD(, linker_class) linker_class_list_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome TAILQ_ENTRY(linker_class) link; /* list of all file classes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Function type used when iterating over the list of linker files.
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef int linker_predicate_t(linker_file_t, void *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The "file" for the kernel.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Obtain a reference to a module, loading it if required.
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_reference_module(const char* _modname, struct mod_depend *_verinfo,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Release a reference to a module, unloading it if there are no more
199767f8919635c4928607450d9e0abb932109ceToomas Soome * references. Note that one should either provide a module name and
199767f8919635c4928607450d9e0abb932109ceToomas Soome * optional version info or a linker file, but not both.
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_release_module(const char *_modname, struct mod_depend *_verinfo,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Iterate over all of the currently loaded linker files calling the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * predicate function while the function returns 0. Returns the value
199767f8919635c4928607450d9e0abb932109ceToomas Soome * returned by the last predicate function.
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_file_foreach(linker_predicate_t *_predicate, void *_context);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Lookup a symbol in a file. If deps is TRUE, look in dependencies
199767f8919635c4928607450d9e0abb932109ceToomas Soome * if not found in file.
199767f8919635c4928607450d9e0abb932109ceToomas Soomecaddr_t linker_file_lookup_symbol(linker_file_t _file, const char* _name,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Lookup a linker set in a file. Return pointers to the first entry,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * last + 1, and count of entries. Use: for (p = start; p < stop; p++) {}
199767f8919635c4928607450d9e0abb932109ceToomas Soome * void *start is really: "struct yoursetmember ***start;"
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_file_lookup_set(linker_file_t _file, const char *_name,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * List all functions in a file.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Functions soley for use by the linker class handlers.
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_file_unload(linker_file_t _file, int flags);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_load_dependencies(linker_file_t _lf);
199767f8919635c4928607450d9e0abb932109ceToomas Soomelinker_file_t linker_make_file(const char* _filename, linker_class_t _cls);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DDB Helpers, tuned specifically for ddb/db_kld.c
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_ddb_lookup(const char *_symstr, c_linker_sym_t *_sym);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_ddb_search_symbol(caddr_t _value, c_linker_sym_t *_sym,
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_ddb_symbol_values(c_linker_sym_t _sym, linker_symval_t *_symval);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_ddb_search_symbol_name(caddr_t value, char *buf, u_int buflen,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * stack(9) helper for situations where kernel locking is required.
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_search_symbol_name(caddr_t value, char *buf, u_int buflen,
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* HWPMC helper */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* _KERNEL */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Module information subtypes
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFO_NAME 0x0001 /* Name of module (string) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFO_TYPE 0x0002 /* Type of module (string) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFO_ADDR 0x0003 /* Loaded address */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFO_SIZE 0x0004 /* Size of module */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFO_EMPTY 0x0005 /* Has been deleted */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFO_ARGS 0x0006 /* Parameters string */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFO_METADATA 0x8000 /* Module-specfic */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_AOUTEXEC 0x0001 /* a.out exec header */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_ELFHDR 0x0002 /* ELF header */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_SSYM 0x0003 /* start of symbols */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_ESYM 0x0004 /* end of symbols */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_DYNAMIC 0x0005 /* _DYNAMIC pointer */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* These values are MD on these two platforms */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if !defined(__sparc64__) && !defined(__powerpc__)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_SHDR 0x0009 /* section header table */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_CTORS_ADDR 0x000a /* address of .ctors */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_CTORS_SIZE 0x000b /* size of .ctors */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_FW_HANDLE 0x000c /* Firmware dependent handle */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_NOCOPY 0x8000 /* don't copy this metadata to the kernel */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_DEPLIST (0x4001 | MODINFOMD_NOCOPY) /* depends on */
199767f8919635c4928607450d9e0abb932109ceToomas Soome __p = (type *)preload_search_info((mdp), MODINFO_METADATA | (info)); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define LINKER_HINTS_VERSION 1 /* linker.hints file version */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define LINKER_HINTS_MAX (1 << 20) /* Allow at most 1MB for linker.hints */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Module lookup
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern caddr_t preload_search_by_name(const char *_name);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern caddr_t preload_search_by_type(const char *_type);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern caddr_t preload_search_next_name(caddr_t _base);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern caddr_t preload_search_info(caddr_t _mod, int _inf);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern void preload_delete_name(const char *_name);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern void preload_bootstrap_relocate(vm_offset_t _offset);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (kld_debug & KLD_DEBUG_##cat) printf args; \
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef int elf_lookup_fn(linker_file_t, Elf_Size, int, Elf_Addr *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Support functions */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint elf_reloc(linker_file_t _lf, Elf_Addr base, const void *_rel, int _type, elf_lookup_fn _lu);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint elf_reloc_local(linker_file_t _lf, Elf_Addr base, const void *_rel, int _type, elf_lookup_fn _lu);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeElf_Addr elf_relocaddr(linker_file_t _lf, Elf_Addr addr);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeconst Elf_Sym *elf_get_sym(linker_file_t _lf, Elf_Size _symidx);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeconst char *elf_get_symname(linker_file_t _lf, Elf_Size _symidx);
199767f8919635c4928607450d9e0abb932109ceToomas Soome const uint8_t *ctftab; /* Decompressed CTF data. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome const Elf_Sym *symtab; /* Ptr to the symbol table. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char *strtab; /* Ptr to the string table. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t **ctfoffp; /* Ptr to array of obj/fnc offsets. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t **typoffp; /* Ptr to array of type offsets. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome long *typlenp; /* Ptr to number of type data entries. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_ctf_get(linker_file_t, linker_ctf_t *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* values for type */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This is version 1 of the KLD file status structure. It is identified
199767f8919635c4928607450d9e0abb932109ceToomas Soome * by its _size_ in the version field.
199767f8919635c4928607450d9e0abb932109ceToomas Soome int version; /* set to sizeof(struct kld_file_stat_1) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* _KERNEL */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int version; /* set to sizeof(struct kld_file_stat) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int version; /* set to sizeof(struct kld_sym_lookup) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *symname; /* Symbol name we are looking up */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Flags for kldunloadf() and linker_file_unload()
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint kldstat(int _fileid, struct kld_file_stat* _stat);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* !_SYS_LINKER_H_ */