4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
38 findelfsym(Elf
*elf
, uintptr_t addr
, char **symnamep
, offset_t
*offp
)
43 int symtabidx
, nent
, i
;
45 if ((symtabidx
= findelfsecidx(elf
, ".symtab")) < 0)
46 elfdie("failed to find .symtab\n");
48 if ((scn
= elf_getscn(elf
, symtabidx
)) == NULL
||
49 gelf_getshdr(scn
, &shdr
) == NULL
||
50 (symtab
= elf_getdata(scn
, NULL
)) == NULL
)
51 elfdie("failed to read .symtab");
53 nent
= shdr
.sh_size
/ shdr
.sh_entsize
;
55 for (i
= 0; i
< nent
; i
++) {
58 if (gelf_getsym(symtab
, i
, &sym
) == NULL
)
59 elfdie("failed to get symbol at idx %d", i
);
61 if ((GELF_ST_TYPE(sym
.st_info
) != STT_FUNC
&&
62 GELF_ST_TYPE(sym
.st_info
) != STT_OBJECT
) ||
63 sym
.st_shndx
== SHN_UNDEF
)
66 if (addr
- sym
.st_value
< sym
.st_size
) {
68 if ((*symnamep
= elf_strptr(elf
, shdr
.sh_link
,
69 sym
.st_name
)) == NULL
)
70 elfdie("failed to get name for sym %d", i
);
71 *offp
= addr
- sym
.st_value
;