xref: /freebsd/sys/kern/linker_if.m (revision 7ef62cebc2f965b0f640263e179276928885e33d)
1#-
2# Copyright (c) 2000 Doug Rabson
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright
9#    notice, this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright
11#    notice, this list of conditions and the following disclaimer in the
12#    documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24# SUCH DAMAGE.
25#
26# $FreeBSD$
27#
28
29#include <sys/linker.h>
30
31INTERFACE linker;
32
33#
34# Lookup a symbol in the file's symbol table.  If the symbol is not
35# found then return ENOENT, otherwise zero.
36#
37METHOD int lookup_symbol {
38    linker_file_t	file;
39    const char*		name;
40    c_linker_sym_t*	symp;
41};
42
43METHOD int lookup_debug_symbol {
44    linker_file_t	file;
45    const char*		name;
46    c_linker_sym_t*	symp;
47};
48
49METHOD int symbol_values {
50    linker_file_t	file;
51    c_linker_sym_t	sym;
52    linker_symval_t*	valp;
53};
54
55METHOD int debug_symbol_values {
56    linker_file_t	file;
57    c_linker_sym_t	sym;
58    linker_symval_t*	valp;
59};
60
61METHOD int search_symbol {
62    linker_file_t	file;
63    caddr_t		value;
64    c_linker_sym_t*	symp;
65    long*		diffp;
66};
67
68#
69# Call the callback with each specified function defined in the file.
70# Stop and return the error if the callback returns an error.
71#
72METHOD int each_function_name {
73	linker_file_t	file;
74	linker_function_name_callback_t	callback;
75	void*		opaque;
76};
77
78#
79# Call the callback with each specified function and it's value
80# defined in the file.
81# Stop and return the error if the callback returns an error.
82#
83METHOD int each_function_nameval {
84	linker_file_t	file;
85	linker_function_nameval_callback_t	callback;
86	void*		opaque;
87};
88
89#
90# Search for a linker set in a file.  Return a pointer to the first
91# entry (which is itself a pointer), and the number of entries.
92# "stop" points to the entry beyond the last valid entry.
93# If count, start or stop are NULL, they are not returned.
94#
95METHOD int lookup_set {
96    linker_file_t	file;
97    const char*		name;
98    void***		start;
99    void***		stop;
100    int*		count;
101};
102
103#
104# Unload a file, releasing dependencies and freeing storage.
105#
106METHOD void unload {
107    linker_file_t	file;
108};
109
110#
111# Load CTF data if necessary and if there is a .SUNW_ctf section
112# in the ELF file, returning info in the linker CTF structure.
113#
114METHOD int ctf_get {
115	linker_file_t	file;
116	linker_ctf_t	*lc;
117};
118
119#
120# Get the symbol table, returning it in **symtab.  Return the
121# number of symbols, otherwise zero.
122#
123METHOD long symtab_get {
124	linker_file_t	file;
125	const Elf_Sym	**symtab;
126};
127
128#
129# Get the string table, returning it in *strtab.  Return the
130# size (in bytes) of the string table, otherwise zero.
131#
132METHOD long strtab_get {
133	linker_file_t	file;
134	caddr_t		*strtab;
135};
136
137#
138# Load a file, returning the new linker_file_t in *result.  If
139# the class does not recognise the file type, zero should be
140# returned, without modifying *result.  If the file is
141# recognised, the file should be loaded, *result set to the new
142# file and zero returned.  If some other error is detected an
143# appropriate errno should be returned.
144#
145STATICMETHOD int load_file {
146    linker_class_t	cls;
147    const char*		filename;
148    linker_file_t*	result;
149};
150STATICMETHOD int link_preload {
151    linker_class_t	cls;
152    const char*		filename;
153    linker_file_t*	result;
154};
155METHOD int link_preload_finish {
156    linker_file_t	file;
157};
158