10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*9900SAli.Bahrami@Sun.COM * Common Development and Distribution License (the "License").
6*9900SAli.Bahrami@Sun.COM * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*9900SAli.Bahrami@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #include <string.h>
270Sstevel@tonic-gate #include <gelf.h>
280Sstevel@tonic-gate #include <decl.h>
290Sstevel@tonic-gate #include <msg.h>
300Sstevel@tonic-gate
31*9900SAli.Bahrami@Sun.COM /*
32*9900SAli.Bahrami@Sun.COM * Return section header array string table index, taking
33*9900SAli.Bahrami@Sun.COM * extended headers into account.
34*9900SAli.Bahrami@Sun.COM *
35*9900SAli.Bahrami@Sun.COM * elf_getshstrndx() returns 0 for failure, and 1 for success.
36*9900SAli.Bahrami@Sun.COM *
37*9900SAli.Bahrami@Sun.COM * elf_getshdrstrndx() supercedes elf_getshstrndx(), which is now considered
38*9900SAli.Bahrami@Sun.COM * obsolete. It returns -1 for failure and 0 for success, bringing us into
39*9900SAli.Bahrami@Sun.COM * alignment with the interface agreed to in the 2002 gABI meeting.
40*9900SAli.Bahrami@Sun.COM *
41*9900SAli.Bahrami@Sun.COM * See the comment in getshnum.c for additional information.
42*9900SAli.Bahrami@Sun.COM */
43*9900SAli.Bahrami@Sun.COM
440Sstevel@tonic-gate int
elf_getshdrstrndx(Elf * elf,size_t * shstrndx)45*9900SAli.Bahrami@Sun.COM elf_getshdrstrndx(Elf *elf, size_t *shstrndx)
460Sstevel@tonic-gate {
470Sstevel@tonic-gate GElf_Ehdr ehdr;
480Sstevel@tonic-gate Elf_Scn *scn;
490Sstevel@tonic-gate GElf_Shdr shdr0;
500Sstevel@tonic-gate
510Sstevel@tonic-gate if (gelf_getehdr(elf, &ehdr) == 0)
52*9900SAli.Bahrami@Sun.COM return (-1);
530Sstevel@tonic-gate if (ehdr.e_shstrndx != SHN_XINDEX) {
540Sstevel@tonic-gate *shstrndx = ehdr.e_shstrndx;
55*9900SAli.Bahrami@Sun.COM return (0);
560Sstevel@tonic-gate }
570Sstevel@tonic-gate if ((scn = elf_getscn(elf, 0)) == 0)
58*9900SAli.Bahrami@Sun.COM return (-1);
590Sstevel@tonic-gate if (gelf_getshdr(scn, &shdr0) == 0)
60*9900SAli.Bahrami@Sun.COM return (-1);
610Sstevel@tonic-gate *shstrndx = shdr0.sh_link;
62*9900SAli.Bahrami@Sun.COM return (0);
630Sstevel@tonic-gate }
64*9900SAli.Bahrami@Sun.COM
65*9900SAli.Bahrami@Sun.COM int
elf_getshstrndx(Elf * elf,size_t * shstrndx)66*9900SAli.Bahrami@Sun.COM elf_getshstrndx(Elf *elf, size_t *shstrndx)
67*9900SAli.Bahrami@Sun.COM {
68*9900SAli.Bahrami@Sun.COM return (elf_getshdrstrndx(elf, shstrndx) == 0);
69*9900SAli.Bahrami@Sun.COM }
70