Deleted Added
full compact
link_elf_obj.c (77642) link_elf_obj.c (78161)
1/*-
2 * Copyright (c) 1998-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 unchanged lines hidden (view full) ---

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 *
1/*-
2 * Copyright (c) 1998-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 unchanged lines hidden (view full) ---

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: head/sys/kern/link_elf_obj.c 77642 2001-06-03 02:19:07Z dd $
26 * $FreeBSD: head/sys/kern/link_elf_obj.c 78161 2001-06-13 10:58:39Z peter $
27 */
28
29#include "opt_ddb.h"
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/lock.h>

--- 68 unchanged lines hidden (view full) ---

103static int link_elf_lookup_symbol(linker_file_t, const char*,
104 c_linker_sym_t*);
105static int link_elf_symbol_values(linker_file_t, c_linker_sym_t, linker_symval_t*);
106static int link_elf_search_symbol(linker_file_t, caddr_t value,
107 c_linker_sym_t* sym, long* diffp);
108
109static void link_elf_unload_file(linker_file_t);
110static void link_elf_unload_preload(linker_file_t);
27 */
28
29#include "opt_ddb.h"
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/lock.h>

--- 68 unchanged lines hidden (view full) ---

103static int link_elf_lookup_symbol(linker_file_t, const char*,
104 c_linker_sym_t*);
105static int link_elf_symbol_values(linker_file_t, c_linker_sym_t, linker_symval_t*);
106static int link_elf_search_symbol(linker_file_t, caddr_t value,
107 c_linker_sym_t* sym, long* diffp);
108
109static void link_elf_unload_file(linker_file_t);
110static void link_elf_unload_preload(linker_file_t);
111static int link_elf_lookup_set(linker_file_t, const char *,
112 void ***, void ***, int *);
111
112static kobj_method_t link_elf_methods[] = {
113 KOBJMETHOD(linker_lookup_symbol, link_elf_lookup_symbol),
114 KOBJMETHOD(linker_symbol_values, link_elf_symbol_values),
115 KOBJMETHOD(linker_search_symbol, link_elf_search_symbol),
116 KOBJMETHOD(linker_unload, link_elf_unload_file),
117 KOBJMETHOD(linker_load_file, link_elf_load_file),
118 KOBJMETHOD(linker_link_preload, link_elf_link_preload),
119 KOBJMETHOD(linker_link_preload_finish, link_elf_link_preload_finish),
113
114static kobj_method_t link_elf_methods[] = {
115 KOBJMETHOD(linker_lookup_symbol, link_elf_lookup_symbol),
116 KOBJMETHOD(linker_symbol_values, link_elf_symbol_values),
117 KOBJMETHOD(linker_search_symbol, link_elf_search_symbol),
118 KOBJMETHOD(linker_unload, link_elf_unload_file),
119 KOBJMETHOD(linker_load_file, link_elf_load_file),
120 KOBJMETHOD(linker_link_preload, link_elf_link_preload),
121 KOBJMETHOD(linker_link_preload_finish, link_elf_link_preload_finish),
122 KOBJMETHOD(linker_lookup_set, link_elf_lookup_set),
120 { 0, 0 }
121};
122
123static struct linker_class link_elf_class = {
124#if ELF_TARG_CLASS == ELFCLASS32
125 "elf32",
126#else
127 "elf64",

--- 942 unchanged lines hidden (view full) ---

1070 if (best == 0)
1071 *diffp = off;
1072 else
1073 *diffp = diff;
1074 *sym = (c_linker_sym_t) best;
1075
1076 return 0;
1077}
123 { 0, 0 }
124};
125
126static struct linker_class link_elf_class = {
127#if ELF_TARG_CLASS == ELFCLASS32
128 "elf32",
129#else
130 "elf64",

--- 942 unchanged lines hidden (view full) ---

1073 if (best == 0)
1074 *diffp = off;
1075 else
1076 *diffp = diff;
1077 *sym = (c_linker_sym_t) best;
1078
1079 return 0;
1080}
1081
1082/*
1083 * Look up a linker set on an ELF system.
1084 */
1085static int
1086link_elf_lookup_set(linker_file_t lf, const char *name,
1087 void ***startp, void ***stopp, int *countp)
1088{
1089 c_linker_sym_t sym;
1090 linker_symval_t symval;
1091 char *setsym;
1092 void **start, **stop;
1093 int len, error = 0, count;
1094
1095 len = strlen(name) + sizeof("__start_set_"); /* sizeof includes \0 */
1096 setsym = malloc(len, M_LINKER, M_WAITOK);
1097 if (setsym == NULL)
1098 return ENOMEM;
1099
1100 /* get address of first entry */
1101 snprintf(setsym, len, "%s%s", "__start_set_", name);
1102 error = link_elf_lookup_symbol(lf, setsym, &sym);
1103 if (error)
1104 goto out;
1105 link_elf_symbol_values(lf, sym, &symval);
1106 if (symval.value == 0) {
1107 error = ESRCH;
1108 goto out;
1109 }
1110 start = (void **)symval.value;
1111
1112 /* get address of last entry */
1113 snprintf(setsym, len, "%s%s", "__stop_set_", name);
1114 error = link_elf_lookup_symbol(lf, setsym, &sym);
1115 if (error)
1116 goto out;
1117 link_elf_symbol_values(lf, sym, &symval);
1118 if (symval.value == 0) {
1119 error = ESRCH;
1120 goto out;
1121 }
1122 stop = (void **)symval.value;
1123
1124 /* and the number of entries */
1125 count = stop - start;
1126
1127 /* and copy out */
1128 if (startp)
1129 *startp = start;
1130 if (stopp)
1131 *stopp = stop;
1132 if (countp)
1133 *countp = count;
1134
1135out:
1136 free(setsym, M_LINKER);
1137 return error;
1138}