xref: /titanic_50/usr/src/lib/libtnfctl/traverse.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1994, by Sun Microsytems, Inc.
24*7c478bd9Sstevel@tonic-gate  */
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate /*
29*7c478bd9Sstevel@tonic-gate  * Generic functions that know how to traverse elf sections in an object.
30*7c478bd9Sstevel@tonic-gate  * Also functions that know how to traverse records in a section.
31*7c478bd9Sstevel@tonic-gate  *
32*7c478bd9Sstevel@tonic-gate  */
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #include <string.h>
35*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
36*7c478bd9Sstevel@tonic-gate #include <unistd.h>
37*7c478bd9Sstevel@tonic-gate #include <errno.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/procfs.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate #include "tnfctl_int.h"
42*7c478bd9Sstevel@tonic-gate #include "dbg.h"
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate /*
46*7c478bd9Sstevel@tonic-gate  * _tnfctl_traverse_object() - traverses all of the elf sections in an object,
47*7c478bd9Sstevel@tonic-gate  * calling the supplied function on each.
48*7c478bd9Sstevel@tonic-gate  */
49*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t
_tnfctl_traverse_object(int objfd,uintptr_t addr,tnfctl_elf_search_t * search_info_p)50*7c478bd9Sstevel@tonic-gate _tnfctl_traverse_object(int objfd, uintptr_t addr,
51*7c478bd9Sstevel@tonic-gate 			tnfctl_elf_search_t *search_info_p)
52*7c478bd9Sstevel@tonic-gate {
53*7c478bd9Sstevel@tonic-gate 	Elf		*elf;
54*7c478bd9Sstevel@tonic-gate 	GElf_Ehdr	*ehdr, ehdr_obj;
55*7c478bd9Sstevel@tonic-gate 	char		*strs;
56*7c478bd9Sstevel@tonic-gate 	GElf_Shdr	*shdr, shdr_obj;
57*7c478bd9Sstevel@tonic-gate 	Elf_Data	*data;
58*7c478bd9Sstevel@tonic-gate 	u_int		idx;
59*7c478bd9Sstevel@tonic-gate 	tnfctl_errcode_t	prexstat = TNFCTL_ERR_NONE;
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate 	DBG_TNF_PROBE_1(_tnfctl_traverse_object_1, "libtnfctl",
62*7c478bd9Sstevel@tonic-gate 			"sunw%verbosity 3",
63*7c478bd9Sstevel@tonic-gate 			tnf_opaque, obj_addr, addr);
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate 	if (elf_version(EV_CURRENT) == EV_NONE)
66*7c478bd9Sstevel@tonic-gate 		return (TNFCTL_ERR_INTERNAL);
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate 	/* open elf descriptor on the fd */
69*7c478bd9Sstevel@tonic-gate 	elf = elf_begin(objfd, ELF_C_READ, NULL);
70*7c478bd9Sstevel@tonic-gate 	if (elf == NULL || elf_kind(elf) != ELF_K_ELF) {
71*7c478bd9Sstevel@tonic-gate 		DBG_TNF_PROBE_0(_tnfctl_traverse_object_2, "libtnfctl",
72*7c478bd9Sstevel@tonic-gate 			"sunw%verbosity 3; sunw%debug 'not elf object'");
73*7c478bd9Sstevel@tonic-gate 		return (TNFCTL_ERR_INTERNAL);
74*7c478bd9Sstevel@tonic-gate 	}
75*7c478bd9Sstevel@tonic-gate 	/* get the elf header */
76*7c478bd9Sstevel@tonic-gate 	if ((ehdr = gelf_getehdr(elf, &ehdr_obj)) == NULL) {
77*7c478bd9Sstevel@tonic-gate 		DBG((void) fprintf(stderr,
78*7c478bd9Sstevel@tonic-gate 			"_tnfctl_traverse_object: gelf_getehdr failed\n"));
79*7c478bd9Sstevel@tonic-gate 		(void) elf_end(elf);
80*7c478bd9Sstevel@tonic-gate 		return (TNFCTL_ERR_INTERNAL);
81*7c478bd9Sstevel@tonic-gate 	}
82*7c478bd9Sstevel@tonic-gate 	if ((ehdr->e_type != ET_EXEC) && (ehdr->e_type != ET_DYN)) {
83*7c478bd9Sstevel@tonic-gate 		DBG((void) fprintf(stderr,
84*7c478bd9Sstevel@tonic-gate 			"_tnfctl_traverse_object: not an "
85*7c478bd9Sstevel@tonic-gate 			"executable or a shared object\n"));
86*7c478bd9Sstevel@tonic-gate 		(void) elf_end(elf);
87*7c478bd9Sstevel@tonic-gate 		return (TNFCTL_ERR_INTERNAL);
88*7c478bd9Sstevel@tonic-gate 	}
89*7c478bd9Sstevel@tonic-gate 	/* if an executable file, the base address is 0 */
90*7c478bd9Sstevel@tonic-gate 	if (ehdr->e_type == ET_EXEC)
91*7c478bd9Sstevel@tonic-gate 		addr = 0;
92*7c478bd9Sstevel@tonic-gate 	/* get a pointer to the elf header string table */
93*7c478bd9Sstevel@tonic-gate 	strs = elf_strptr(elf, ehdr->e_shstrndx, NULL);
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate 	DBG_TNF_PROBE_1(_tnfctl_traverse_object_3, "libtnfctl",
96*7c478bd9Sstevel@tonic-gate 			"sunw%verbosity 3",
97*7c478bd9Sstevel@tonic-gate 			tnf_long, num_sections_found, ehdr->e_shnum);
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate 	for (idx = 1; idx < ehdr->e_shnum; idx++) {
100*7c478bd9Sstevel@tonic-gate 		Elf_Scn		*scn;
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 		if ((scn = elf_getscn(elf, idx)) == NULL) {
103*7c478bd9Sstevel@tonic-gate 			DBG((void) fprintf(stderr,
104*7c478bd9Sstevel@tonic-gate 			    "_tnfctl_traverse_object: elf_getscn failed\n"));
105*7c478bd9Sstevel@tonic-gate 			prexstat = TNFCTL_ERR_INTERNAL;
106*7c478bd9Sstevel@tonic-gate 			break;
107*7c478bd9Sstevel@tonic-gate 		}
108*7c478bd9Sstevel@tonic-gate 		if ((shdr = gelf_getshdr(scn, &shdr_obj)) == NULL) {
109*7c478bd9Sstevel@tonic-gate 			DBG((void) fprintf(stderr,
110*7c478bd9Sstevel@tonic-gate 				"_tnfctl_traverse_obj:gelf_getshdr failed\n"));
111*7c478bd9Sstevel@tonic-gate 			prexstat = TNFCTL_ERR_INTERNAL;
112*7c478bd9Sstevel@tonic-gate 			break;
113*7c478bd9Sstevel@tonic-gate 		}
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate 		if ((data = elf_getdata(scn, NULL)) == NULL) {
116*7c478bd9Sstevel@tonic-gate 			DBG((void) fprintf(stderr,
117*7c478bd9Sstevel@tonic-gate 				"_tnfctl_traverse_obj:gelf_getdata failed\n"));
118*7c478bd9Sstevel@tonic-gate 			prexstat = TNFCTL_ERR_INTERNAL;
119*7c478bd9Sstevel@tonic-gate 			break;
120*7c478bd9Sstevel@tonic-gate 		}
121*7c478bd9Sstevel@tonic-gate 		/* call the supplied function */
122*7c478bd9Sstevel@tonic-gate 		prexstat = search_info_p->section_func(elf,
123*7c478bd9Sstevel@tonic-gate 			strs, scn, shdr, data, addr, search_info_p);
124*7c478bd9Sstevel@tonic-gate 		if (prexstat)
125*7c478bd9Sstevel@tonic-gate 			break;
126*7c478bd9Sstevel@tonic-gate 	}
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	(void) elf_end(elf);
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate 	return (prexstat);
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate }				/* end _tnfctl_traverse_object */
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate /*
136*7c478bd9Sstevel@tonic-gate  * _tnfctl_traverse_rela() - this function traverses a .rela section calling the
137*7c478bd9Sstevel@tonic-gate  * supplied function on each relocation record.
138*7c478bd9Sstevel@tonic-gate  */
139*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
140*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t
_tnfctl_traverse_rela(Elf * elf,char * strs,Elf_Scn * rel_scn,GElf_Shdr * rel_shdr,Elf_Data * rel_data,uintptr_t baseaddr,tnfctl_elf_search_t * search_info_p)141*7c478bd9Sstevel@tonic-gate _tnfctl_traverse_rela(Elf * elf, char *strs, Elf_Scn * rel_scn,
142*7c478bd9Sstevel@tonic-gate 	GElf_Shdr * rel_shdr, Elf_Data * rel_data, uintptr_t baseaddr,
143*7c478bd9Sstevel@tonic-gate 	tnfctl_elf_search_t * search_info_p)
144*7c478bd9Sstevel@tonic-gate {
145*7c478bd9Sstevel@tonic-gate 	Elf_Scn		*sym_scn;
146*7c478bd9Sstevel@tonic-gate 	GElf_Shdr	*sym_shdr, sym_shdr_obj;
147*7c478bd9Sstevel@tonic-gate 	Elf_Data	*sym_data;
148*7c478bd9Sstevel@tonic-gate 	Elf3264_Sym	*sym_table;
149*7c478bd9Sstevel@tonic-gate 	Elf_Scn		*str_scn;
150*7c478bd9Sstevel@tonic-gate 	GElf_Shdr	*str_shdr, str_shdr_obj;
151*7c478bd9Sstevel@tonic-gate 	Elf_Data	*str_data;
152*7c478bd9Sstevel@tonic-gate 	char		*str_table;
153*7c478bd9Sstevel@tonic-gate 	ulong_t		nrels;
154*7c478bd9Sstevel@tonic-gate 	uint_t		i;
155*7c478bd9Sstevel@tonic-gate 	boolean_t	isrela;
156*7c478bd9Sstevel@tonic-gate 	size_t		rela_sz;
157*7c478bd9Sstevel@tonic-gate 	char		*ptr;
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate 	DBG_TNF_PROBE_0(_tnfctl_traverse_rela_1, "libtnfctl",
160*7c478bd9Sstevel@tonic-gate 				"sunw%verbosity 4");
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate 	/* bail if this isn't a rela (or rel) section */
163*7c478bd9Sstevel@tonic-gate 	if (rel_shdr->sh_type == SHT_RELA) {
164*7c478bd9Sstevel@tonic-gate 		isrela = B_TRUE;
165*7c478bd9Sstevel@tonic-gate 	} else if (rel_shdr->sh_type == SHT_REL) {
166*7c478bd9Sstevel@tonic-gate 		isrela = B_FALSE;
167*7c478bd9Sstevel@tonic-gate 	} else
168*7c478bd9Sstevel@tonic-gate 		return (TNFCTL_ERR_NONE);
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate 	/* find the symbol table section associated with this rela section */
171*7c478bd9Sstevel@tonic-gate 	sym_scn = elf_getscn(elf, rel_shdr->sh_link);
172*7c478bd9Sstevel@tonic-gate 	if (sym_scn == NULL) {
173*7c478bd9Sstevel@tonic-gate 		DBG((void) fprintf(stderr,
174*7c478bd9Sstevel@tonic-gate 			"_tnfctl_traverse_rela:elf_getscn (sym) failed\n"));
175*7c478bd9Sstevel@tonic-gate 		return (TNFCTL_ERR_INTERNAL);
176*7c478bd9Sstevel@tonic-gate 	}
177*7c478bd9Sstevel@tonic-gate 	sym_shdr = gelf_getshdr(sym_scn, &sym_shdr_obj);
178*7c478bd9Sstevel@tonic-gate 	if (sym_shdr == NULL) {
179*7c478bd9Sstevel@tonic-gate 		DBG((void) fprintf(stderr,
180*7c478bd9Sstevel@tonic-gate 			"_tnfctl_traverse_rela:gelf_getshdr (sym) failed\n"));
181*7c478bd9Sstevel@tonic-gate 		return (TNFCTL_ERR_INTERNAL);
182*7c478bd9Sstevel@tonic-gate 	}
183*7c478bd9Sstevel@tonic-gate 	sym_data = elf_getdata(sym_scn, NULL);
184*7c478bd9Sstevel@tonic-gate 	if (sym_data == NULL) {
185*7c478bd9Sstevel@tonic-gate 		DBG((void) fprintf(stderr,
186*7c478bd9Sstevel@tonic-gate 			"_tnfctl_traverse_rela:elf_getdata (sym) failed\n"));
187*7c478bd9Sstevel@tonic-gate 		return (TNFCTL_ERR_INTERNAL);
188*7c478bd9Sstevel@tonic-gate 	}
189*7c478bd9Sstevel@tonic-gate 	sym_table = (Elf3264_Sym *) sym_data->d_buf;
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate 	/* find the string table associated with the symbol table */
192*7c478bd9Sstevel@tonic-gate 	str_scn = elf_getscn(elf, sym_shdr->sh_link);
193*7c478bd9Sstevel@tonic-gate 	if (str_scn == NULL) {
194*7c478bd9Sstevel@tonic-gate 		DBG((void) fprintf(stderr,
195*7c478bd9Sstevel@tonic-gate 			"_tnfctl_traverse_rela:elf_getscn (str) failed\n"));
196*7c478bd9Sstevel@tonic-gate 		return (TNFCTL_ERR_INTERNAL);
197*7c478bd9Sstevel@tonic-gate 	}
198*7c478bd9Sstevel@tonic-gate 	str_shdr = gelf_getshdr(str_scn, &str_shdr_obj);
199*7c478bd9Sstevel@tonic-gate 	if (str_shdr == NULL) {
200*7c478bd9Sstevel@tonic-gate 		DBG((void) fprintf(stderr,
201*7c478bd9Sstevel@tonic-gate 			"_tnfctl_traverse_rela:gelf_getshdr (str) failed\n"));
202*7c478bd9Sstevel@tonic-gate 		return (TNFCTL_ERR_INTERNAL);
203*7c478bd9Sstevel@tonic-gate 	}
204*7c478bd9Sstevel@tonic-gate 	str_data = elf_getdata(str_scn, NULL);
205*7c478bd9Sstevel@tonic-gate 	if (str_data == NULL) {
206*7c478bd9Sstevel@tonic-gate 		DBG((void) fprintf(stderr,
207*7c478bd9Sstevel@tonic-gate 			"_tnfctl_traverse_rela: elf_getdata (str) failed\n"));
208*7c478bd9Sstevel@tonic-gate 		return (TNFCTL_ERR_INTERNAL);
209*7c478bd9Sstevel@tonic-gate 	}
210*7c478bd9Sstevel@tonic-gate 	str_table = (char *) str_data->d_buf;
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate 	/* loop over each relocation record */
213*7c478bd9Sstevel@tonic-gate 	nrels = rel_shdr->sh_size / rel_shdr->sh_entsize;
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate 	DBG_TNF_PROBE_1(_tnfctl_traverse_rela_2, "libtnfctl",
216*7c478bd9Sstevel@tonic-gate 			"sunw%verbosity 3",
217*7c478bd9Sstevel@tonic-gate 			tnf_long, relocations_found, nrels);
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate 	ptr = rel_data->d_buf;
220*7c478bd9Sstevel@tonic-gate 	rela_sz = (isrela) ? sizeof (Elf3264_Rela) : sizeof (Elf3264_Rel);
221*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < nrels; i++, ptr += rela_sz) {
222*7c478bd9Sstevel@tonic-gate 		Elf3264_Word	syminfo;
223*7c478bd9Sstevel@tonic-gate 		Elf3264_Sym	*sym;
224*7c478bd9Sstevel@tonic-gate 		Elf3264_Addr	offset;
225*7c478bd9Sstevel@tonic-gate 		char		*name;
226*7c478bd9Sstevel@tonic-gate 		uintptr_t	addr;
227*7c478bd9Sstevel@tonic-gate 		tnfctl_errcode_t	prexstat;
228*7c478bd9Sstevel@tonic-gate 
229*7c478bd9Sstevel@tonic-gate 		/* decode the r_info field of the relocation record */
230*7c478bd9Sstevel@tonic-gate 		if (isrela) {
231*7c478bd9Sstevel@tonic-gate 			Elf3264_Rela	 *rela_p;
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate 			/*LINTED pointer cast may result in improper alignment*/
234*7c478bd9Sstevel@tonic-gate 			rela_p = (Elf3264_Rela *) ptr;
235*7c478bd9Sstevel@tonic-gate 			syminfo = ELF3264_R_SYM(rela_p->r_info);
236*7c478bd9Sstevel@tonic-gate 			offset = rela_p->r_offset;
237*7c478bd9Sstevel@tonic-gate 		} else {
238*7c478bd9Sstevel@tonic-gate 			Elf3264_Rel	  *rel_p;
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate 			/*LINTED pointer cast may result in improper alignment*/
241*7c478bd9Sstevel@tonic-gate 			rel_p = (Elf3264_Rel *) ptr;
242*7c478bd9Sstevel@tonic-gate 			syminfo = ELF3264_R_SYM(rel_p->r_info);
243*7c478bd9Sstevel@tonic-gate 			offset = rel_p->r_offset;
244*7c478bd9Sstevel@tonic-gate 		}
245*7c478bd9Sstevel@tonic-gate 
246*7c478bd9Sstevel@tonic-gate 		/* find the associated symbol table entry */
247*7c478bd9Sstevel@tonic-gate 		if (!syminfo)
248*7c478bd9Sstevel@tonic-gate 			continue;
249*7c478bd9Sstevel@tonic-gate 		sym = sym_table + syminfo;
250*7c478bd9Sstevel@tonic-gate 
251*7c478bd9Sstevel@tonic-gate 		/* find the associated string table entry */
252*7c478bd9Sstevel@tonic-gate 		if (!sym->st_name)
253*7c478bd9Sstevel@tonic-gate 			continue;
254*7c478bd9Sstevel@tonic-gate 		name = str_table + sym->st_name;
255*7c478bd9Sstevel@tonic-gate 		addr = offset + baseaddr;
256*7c478bd9Sstevel@tonic-gate 
257*7c478bd9Sstevel@tonic-gate 		prexstat = search_info_p->record_func(name, addr, ptr,
258*7c478bd9Sstevel@tonic-gate 							search_info_p);
259*7c478bd9Sstevel@tonic-gate 		if (prexstat)
260*7c478bd9Sstevel@tonic-gate 			break;
261*7c478bd9Sstevel@tonic-gate 	}
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate 	return (TNFCTL_ERR_NONE);
264*7c478bd9Sstevel@tonic-gate 
265*7c478bd9Sstevel@tonic-gate }				/* end _tnfctl_traverse_rela */
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate 
268*7c478bd9Sstevel@tonic-gate /*
269*7c478bd9Sstevel@tonic-gate  * _tnfctl_traverse_dynsym() - this function traverses a dynsym section calling
270*7c478bd9Sstevel@tonic-gate  * the supplied function on each symbol.
271*7c478bd9Sstevel@tonic-gate  */
272*7c478bd9Sstevel@tonic-gate 
273*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
274*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t
_tnfctl_traverse_dynsym(Elf * elf,char * elfstrs,Elf_Scn * scn,GElf_Shdr * shdr,Elf_Data * data,uintptr_t baseaddr,tnfctl_elf_search_t * search_info_p)275*7c478bd9Sstevel@tonic-gate _tnfctl_traverse_dynsym(Elf * elf,
276*7c478bd9Sstevel@tonic-gate 			char *elfstrs,
277*7c478bd9Sstevel@tonic-gate 			Elf_Scn * scn,
278*7c478bd9Sstevel@tonic-gate 			GElf_Shdr * shdr,
279*7c478bd9Sstevel@tonic-gate 			Elf_Data * data,
280*7c478bd9Sstevel@tonic-gate 			uintptr_t baseaddr,
281*7c478bd9Sstevel@tonic-gate 			tnfctl_elf_search_t * search_info_p)
282*7c478bd9Sstevel@tonic-gate {
283*7c478bd9Sstevel@tonic-gate 	ulong_t		nsyms;
284*7c478bd9Sstevel@tonic-gate 	int		i;
285*7c478bd9Sstevel@tonic-gate 	char		*strs;
286*7c478bd9Sstevel@tonic-gate 	tnfctl_errcode_t	prexstat;
287*7c478bd9Sstevel@tonic-gate 
288*7c478bd9Sstevel@tonic-gate 	Elf3264_Sym	*syms;
289*7c478bd9Sstevel@tonic-gate 
290*7c478bd9Sstevel@tonic-gate 	/* bail if this isn't a dynsym section */
291*7c478bd9Sstevel@tonic-gate 	if (shdr->sh_type != SHT_DYNSYM)
292*7c478bd9Sstevel@tonic-gate 		return (TNFCTL_ERR_NONE);
293*7c478bd9Sstevel@tonic-gate #if 0
294*7c478bd9Sstevel@tonic-gate 	printf("### entering _tnfctl_traverse_dynsym...\n");
295*7c478bd9Sstevel@tonic-gate #endif
296*7c478bd9Sstevel@tonic-gate 	syms = data->d_buf;
297*7c478bd9Sstevel@tonic-gate 	nsyms = shdr->sh_size / shdr->sh_entsize;
298*7c478bd9Sstevel@tonic-gate 	strs = elf_strptr(elf, shdr->sh_link, 0);
299*7c478bd9Sstevel@tonic-gate 
300*7c478bd9Sstevel@tonic-gate 	DBG_TNF_PROBE_1(_tnfctl_traverse_dynsym_1, "libtnfctl",
301*7c478bd9Sstevel@tonic-gate 			"sunw%verbosity 3",
302*7c478bd9Sstevel@tonic-gate 			tnf_long, symbols_found, nsyms);
303*7c478bd9Sstevel@tonic-gate 
304*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < nsyms; i++) {
305*7c478bd9Sstevel@tonic-gate 		Elf3264_Sym	*sym = &syms[i];
306*7c478bd9Sstevel@tonic-gate 		char		*name;
307*7c478bd9Sstevel@tonic-gate 		uintptr_t	addr;
308*7c478bd9Sstevel@tonic-gate 
309*7c478bd9Sstevel@tonic-gate 		name = strs + sym->st_name;
310*7c478bd9Sstevel@tonic-gate 		addr = baseaddr + sym->st_value;
311*7c478bd9Sstevel@tonic-gate 
312*7c478bd9Sstevel@tonic-gate #if 0
313*7c478bd9Sstevel@tonic-gate 		if (name != 0)
314*7c478bd9Sstevel@tonic-gate 			printf("_tnfctl_traverse_dynsym: name = %s\n", name);
315*7c478bd9Sstevel@tonic-gate 		else
316*7c478bd9Sstevel@tonic-gate 			printf("_tnfctl_traverse_dynsym: name is 0\n");
317*7c478bd9Sstevel@tonic-gate #endif
318*7c478bd9Sstevel@tonic-gate 		prexstat = search_info_p->record_func(name,
319*7c478bd9Sstevel@tonic-gate 			addr, sym, search_info_p);
320*7c478bd9Sstevel@tonic-gate 		if (prexstat)
321*7c478bd9Sstevel@tonic-gate 			break;
322*7c478bd9Sstevel@tonic-gate 	}
323*7c478bd9Sstevel@tonic-gate #if 0
324*7c478bd9Sstevel@tonic-gate 	printf("### leaving _tnfctl_traverse_dynsym...\n");
325*7c478bd9Sstevel@tonic-gate #endif
326*7c478bd9Sstevel@tonic-gate 	return (prexstat);
327*7c478bd9Sstevel@tonic-gate 
328*7c478bd9Sstevel@tonic-gate }				/* end _tnfctl_traverse_dynsym */
329