17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
54d232658Sjohnlev * Common Development and Distribution License (the "License").
64d232658Sjohnlev * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
224d232658Sjohnlev * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate * Routines used to read stabs data from a file, and to build a tdata structure
307c478bd9Sstevel@tonic-gate * based on the interesting parts of that data.
317c478bd9Sstevel@tonic-gate */
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate #include <stdio.h>
347c478bd9Sstevel@tonic-gate #include <stdlib.h>
357c478bd9Sstevel@tonic-gate #include <fcntl.h>
367c478bd9Sstevel@tonic-gate #include <unistd.h>
377c478bd9Sstevel@tonic-gate #include <assert.h>
387c478bd9Sstevel@tonic-gate #include <string.h>
397c478bd9Sstevel@tonic-gate #include <libgen.h>
407c478bd9Sstevel@tonic-gate #include <errno.h>
417c478bd9Sstevel@tonic-gate #include <sys/types.h>
427c478bd9Sstevel@tonic-gate #include <sys/param.h>
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate #include "ctftools.h"
457c478bd9Sstevel@tonic-gate #include "list.h"
467c478bd9Sstevel@tonic-gate #include "stack.h"
477c478bd9Sstevel@tonic-gate #include "memory.h"
487c478bd9Sstevel@tonic-gate #include "traverse.h"
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate const char *curhdr;
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate * The stabs generator will sometimes reference types before they've been
547c478bd9Sstevel@tonic-gate * defined. If this is the case, a TYPEDEF_UNRES tdesc will be generated.
557c478bd9Sstevel@tonic-gate * Note that this is different from a forward declaration, in which the
567c478bd9Sstevel@tonic-gate * stab is defined, but is defined as something that doesn't exist yet.
577c478bd9Sstevel@tonic-gate * When we have read all of the stabs from the file, we can go back and
587c478bd9Sstevel@tonic-gate * fix up all of the unresolved types. We should be able to fix all of them.
597c478bd9Sstevel@tonic-gate */
607c478bd9Sstevel@tonic-gate /*ARGSUSED2*/
617c478bd9Sstevel@tonic-gate static int
resolve_tou_node(tdesc_t * node,tdesc_t ** nodep,void * private)627c478bd9Sstevel@tonic-gate resolve_tou_node(tdesc_t *node, tdesc_t **nodep, void *private)
637c478bd9Sstevel@tonic-gate {
647c478bd9Sstevel@tonic-gate tdesc_t *new;
657c478bd9Sstevel@tonic-gate
664d232658Sjohnlev debug(3, "Trying to resolve %s (%d)\n", tdesc_name(node), node->t_id);
677c478bd9Sstevel@tonic-gate new = lookup(node->t_id);
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate if (new == NULL) {
707c478bd9Sstevel@tonic-gate terminate("Couldn't resolve type %d\n", node->t_id);
717c478bd9Sstevel@tonic-gate }
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate debug(3, " Resolving to %d\n", new->t_id);
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate *nodep = new;
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate return (1);
787c478bd9Sstevel@tonic-gate }
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate /*ARGSUSED*/
817c478bd9Sstevel@tonic-gate static int
resolve_fwd_node(tdesc_t * node,tdesc_t ** nodep,void * private)827c478bd9Sstevel@tonic-gate resolve_fwd_node(tdesc_t *node, tdesc_t **nodep, void *private)
837c478bd9Sstevel@tonic-gate {
847c478bd9Sstevel@tonic-gate tdesc_t *new = lookupname(node->t_name);
857c478bd9Sstevel@tonic-gate
864d232658Sjohnlev debug(3, "Trying to unforward %s (%d)\n", tdesc_name(node), node->t_id);
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate if (!new || (new->t_type != STRUCT && new->t_type != UNION))
897c478bd9Sstevel@tonic-gate return (0);
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate debug(3, " Unforwarded to %d\n", new->t_id);
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate *nodep = new;
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate return (1);
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate static tdtrav_cb_f resolve_cbs[] = {
997c478bd9Sstevel@tonic-gate NULL,
1007c478bd9Sstevel@tonic-gate NULL, /* intrinsic */
1017c478bd9Sstevel@tonic-gate NULL, /* pointer */
1027c478bd9Sstevel@tonic-gate NULL, /* array */
1037c478bd9Sstevel@tonic-gate NULL, /* function */
1047c478bd9Sstevel@tonic-gate NULL, /* struct */
1057c478bd9Sstevel@tonic-gate NULL, /* union */
1067c478bd9Sstevel@tonic-gate NULL, /* enum */
1077c478bd9Sstevel@tonic-gate resolve_fwd_node, /* forward */
1087c478bd9Sstevel@tonic-gate NULL, /* typedef */
1097c478bd9Sstevel@tonic-gate resolve_tou_node, /* typedef unres */
1107c478bd9Sstevel@tonic-gate NULL, /* volatile */
1117c478bd9Sstevel@tonic-gate NULL, /* const */
1127c478bd9Sstevel@tonic-gate NULL, /* restrict */
1137c478bd9Sstevel@tonic-gate };
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate static void
resolve_nodes(tdata_t * td)1167c478bd9Sstevel@tonic-gate resolve_nodes(tdata_t *td)
1177c478bd9Sstevel@tonic-gate {
1187c478bd9Sstevel@tonic-gate debug(2, "Resolving unresolved stabs\n");
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate (void) iitraverse_hash(td->td_iihash, &td->td_curvgen, resolve_cbs,
1217c478bd9Sstevel@tonic-gate NULL, NULL, td);
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate static char *
concat(char * s1,char * s2,int s2strip)1257c478bd9Sstevel@tonic-gate concat(char *s1, char *s2, int s2strip)
1267c478bd9Sstevel@tonic-gate {
1277c478bd9Sstevel@tonic-gate int savelen = strlen(s2) - s2strip;
1287c478bd9Sstevel@tonic-gate int newlen = (s1 ? strlen(s1) : 0) + savelen + 1;
1297c478bd9Sstevel@tonic-gate char *out;
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate out = xrealloc(s1, newlen);
1327c478bd9Sstevel@tonic-gate if (s1)
1337c478bd9Sstevel@tonic-gate strncpy(out + strlen(out), s2, savelen);
1347c478bd9Sstevel@tonic-gate else
1357c478bd9Sstevel@tonic-gate strncpy(out, s2, savelen);
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate out[newlen - 1] = '\0';
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate return (out);
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate * N_FUN stabs come with their arguments in promoted form. In order to get the
1447c478bd9Sstevel@tonic-gate * actual arguments, we need to wait for the N_PSYM stabs that will come towards
1457c478bd9Sstevel@tonic-gate * the end of the function. These routines free the arguments (fnarg_free) we
1467c478bd9Sstevel@tonic-gate * got from the N_FUN stab and add (fnarg_add) the ones from the N_PSYM stabs.
1477c478bd9Sstevel@tonic-gate */
1487c478bd9Sstevel@tonic-gate static void
fnarg_add(iidesc_t * curfun,iidesc_t * arg)1497c478bd9Sstevel@tonic-gate fnarg_add(iidesc_t *curfun, iidesc_t *arg)
1507c478bd9Sstevel@tonic-gate {
1517c478bd9Sstevel@tonic-gate curfun->ii_nargs++;
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate if (curfun->ii_nargs == 1)
1547c478bd9Sstevel@tonic-gate curfun->ii_args = xmalloc(sizeof (tdesc_t *) * FUNCARG_DEF);
1557c478bd9Sstevel@tonic-gate else if (curfun->ii_nargs > FUNCARG_DEF) {
1567c478bd9Sstevel@tonic-gate curfun->ii_args = xrealloc(curfun->ii_args,
1577c478bd9Sstevel@tonic-gate sizeof (tdesc_t *) * curfun->ii_nargs);
1587c478bd9Sstevel@tonic-gate }
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate curfun->ii_args[curfun->ii_nargs - 1] = arg->ii_dtype;
1617c478bd9Sstevel@tonic-gate arg->ii_dtype = NULL;
1627c478bd9Sstevel@tonic-gate }
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate static void
fnarg_free(iidesc_t * ii)1657c478bd9Sstevel@tonic-gate fnarg_free(iidesc_t *ii)
1667c478bd9Sstevel@tonic-gate {
1677c478bd9Sstevel@tonic-gate ii->ii_nargs = 0;
1687c478bd9Sstevel@tonic-gate free(ii->ii_args);
1697c478bd9Sstevel@tonic-gate ii->ii_args = NULL;
1707c478bd9Sstevel@tonic-gate }
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate /*
1737c478bd9Sstevel@tonic-gate * Read the stabs from the stab ELF section, and turn them into a tdesc tree,
1747c478bd9Sstevel@tonic-gate * assembled under an iidesc list.
1757c478bd9Sstevel@tonic-gate */
1767c478bd9Sstevel@tonic-gate int
stabs_read(tdata_t * td,Elf * elf,const char * file)177c168da27Sjohnlev stabs_read(tdata_t *td, Elf *elf, const char *file)
1787c478bd9Sstevel@tonic-gate {
1797c478bd9Sstevel@tonic-gate Elf_Scn *scn;
1807c478bd9Sstevel@tonic-gate Elf_Data *data;
1817c478bd9Sstevel@tonic-gate stab_t *stab;
1827c478bd9Sstevel@tonic-gate stk_t *file_stack;
1837c478bd9Sstevel@tonic-gate iidesc_t *iidescp;
1847c478bd9Sstevel@tonic-gate iidesc_t *curfun = NULL;
1857c478bd9Sstevel@tonic-gate char curpath[MAXPATHLEN];
1867c478bd9Sstevel@tonic-gate char *curfile = NULL;
1877c478bd9Sstevel@tonic-gate char *str;
1887c478bd9Sstevel@tonic-gate char *fstr = NULL, *ofstr = NULL;
1897c478bd9Sstevel@tonic-gate int stabidx, stabstridx;
1907c478bd9Sstevel@tonic-gate int nstabs, rc, i;
1917c478bd9Sstevel@tonic-gate int scope = 0;
1927c478bd9Sstevel@tonic-gate
193c168da27Sjohnlev if (!((stabidx = findelfsecidx(elf, file, ".stab.excl")) >= 0 &&
194c168da27Sjohnlev (stabstridx = findelfsecidx(elf, file, ".stab.exclstr")) >= 0) &&
195c168da27Sjohnlev !((stabidx = findelfsecidx(elf, file, ".stab")) >= 0 &&
196c168da27Sjohnlev (stabstridx = findelfsecidx(elf, file, ".stabstr")) >= 0)) {
1977c478bd9Sstevel@tonic-gate errno = ENOENT;
1987c478bd9Sstevel@tonic-gate return (-1);
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate
2017c478bd9Sstevel@tonic-gate file_stack = stack_new(free);
2027c478bd9Sstevel@tonic-gate
203c168da27Sjohnlev stack_push(file_stack, (void *)file);
204c168da27Sjohnlev curhdr = file;
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate debug(3, "Found stabs in %d, strings in %d\n", stabidx, stabstridx);
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate scn = elf_getscn(elf, stabidx);
2097c478bd9Sstevel@tonic-gate data = elf_rawdata(scn, NULL);
2107c478bd9Sstevel@tonic-gate nstabs = data->d_size / sizeof (stab_t);
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate parse_init(td);
2137c478bd9Sstevel@tonic-gate for (i = 0; i < nstabs; i++) {
2147c478bd9Sstevel@tonic-gate stab = &((stab_t *)data->d_buf)[i];
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate /* We don't want any local definitions */
2177c478bd9Sstevel@tonic-gate if (stab->n_type == N_LBRAC) {
2187c478bd9Sstevel@tonic-gate scope++;
2197c478bd9Sstevel@tonic-gate debug(3, "stab %d: opening scope (%d)\n", i + 1, scope);
2207c478bd9Sstevel@tonic-gate continue;
2217c478bd9Sstevel@tonic-gate } else if (stab->n_type == N_RBRAC) {
2227c478bd9Sstevel@tonic-gate scope--;
2237c478bd9Sstevel@tonic-gate debug(3, "stab %d: closing scope (%d)\n", i + 1, scope);
2247c478bd9Sstevel@tonic-gate continue;
2257c478bd9Sstevel@tonic-gate } else if (stab->n_type == N_EINCL) {
2267c478bd9Sstevel@tonic-gate /*
2277c478bd9Sstevel@tonic-gate * There's a bug in the 5.2 (Taz) compilers that causes
2287c478bd9Sstevel@tonic-gate * them to emit an extra N_EINCL if there's no actual
2297c478bd9Sstevel@tonic-gate * text in the file being compiled. To work around this
2307c478bd9Sstevel@tonic-gate * bug, we explicitly check to make sure we're not
2317c478bd9Sstevel@tonic-gate * trying to pop a stack that only has the outer scope
2327c478bd9Sstevel@tonic-gate * on it.
2337c478bd9Sstevel@tonic-gate */
2347c478bd9Sstevel@tonic-gate if (stack_level(file_stack) != 1) {
2357c478bd9Sstevel@tonic-gate str = (char *)stack_pop(file_stack);
2367c478bd9Sstevel@tonic-gate free(str);
2377c478bd9Sstevel@tonic-gate curhdr = (char *)stack_peek(file_stack);
2387c478bd9Sstevel@tonic-gate }
2397c478bd9Sstevel@tonic-gate }
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate /* We only care about a subset of the stabs */
2427c478bd9Sstevel@tonic-gate if (!(stab->n_type == N_FUN || stab->n_type == N_GSYM ||
2437c478bd9Sstevel@tonic-gate stab->n_type == N_LCSYM || stab->n_type == N_LSYM ||
2447c478bd9Sstevel@tonic-gate stab->n_type == N_PSYM || stab->n_type == N_ROSYM ||
2457c478bd9Sstevel@tonic-gate stab->n_type == N_RSYM ||
2467c478bd9Sstevel@tonic-gate stab->n_type == N_STSYM || stab->n_type == N_BINCL ||
2477c478bd9Sstevel@tonic-gate stab->n_type == N_SO || stab->n_type == N_OPT))
2487c478bd9Sstevel@tonic-gate continue;
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate if ((str = elf_strptr(elf, stabstridx,
2517c478bd9Sstevel@tonic-gate (size_t)stab->n_strx)) == NULL) {
252c168da27Sjohnlev terminate("%s: Can't find string at %u for stab %d\n",
253c168da27Sjohnlev file, stab->n_strx, i);
2547c478bd9Sstevel@tonic-gate }
2557c478bd9Sstevel@tonic-gate
2567c478bd9Sstevel@tonic-gate if (stab->n_type == N_BINCL) {
2577c478bd9Sstevel@tonic-gate curhdr = xstrdup(str);
2587c478bd9Sstevel@tonic-gate stack_push(file_stack, (void *)curhdr);
2597c478bd9Sstevel@tonic-gate continue;
2607c478bd9Sstevel@tonic-gate } else if (stab->n_type == N_SO) {
2617c478bd9Sstevel@tonic-gate if (str[strlen(str) - 1] != '/') {
2627c478bd9Sstevel@tonic-gate strcpy(curpath, str);
2637c478bd9Sstevel@tonic-gate curfile = basename(curpath);
2647c478bd9Sstevel@tonic-gate }
2657c478bd9Sstevel@tonic-gate continue;
2667c478bd9Sstevel@tonic-gate } else if (stab->n_type == N_OPT) {
2677c478bd9Sstevel@tonic-gate if (strcmp(str, "gcc2_compiled.") == 0) {
268c168da27Sjohnlev terminate("%s: GCC-generated stabs are "
269c168da27Sjohnlev "unsupported. Use DWARF instead.\n", file);
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate continue;
2727c478bd9Sstevel@tonic-gate }
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gate if (str[strlen(str) - 1] == '\\') {
2757c478bd9Sstevel@tonic-gate int offset = 1;
2767c478bd9Sstevel@tonic-gate /*
2777c478bd9Sstevel@tonic-gate * There's a bug in the compilers that causes them to
2787c478bd9Sstevel@tonic-gate * generate \ for continuations with just -g (this is
2797c478bd9Sstevel@tonic-gate * ok), and \\ for continuations with -g -O (this is
2807c478bd9Sstevel@tonic-gate * broken). This bug is "fixed" in the 6.2 compilers
2817c478bd9Sstevel@tonic-gate * via the elimination of continuation stabs.
2827c478bd9Sstevel@tonic-gate */
2837c478bd9Sstevel@tonic-gate if (str[strlen(str) - 2] == '\\')
2847c478bd9Sstevel@tonic-gate offset = 2;
2857c478bd9Sstevel@tonic-gate fstr = concat(fstr, str, offset);
2867c478bd9Sstevel@tonic-gate continue;
2877c478bd9Sstevel@tonic-gate } else
2887c478bd9Sstevel@tonic-gate fstr = concat(fstr, str, 0);
2897c478bd9Sstevel@tonic-gate
2907c478bd9Sstevel@tonic-gate debug(3, "%4d: .stabs \"%s\", %#x, %d, %hd, %d (from %s)\n", i,
2917c478bd9Sstevel@tonic-gate fstr, stab->n_type, 0, stab->n_desc,
2927c478bd9Sstevel@tonic-gate stab->n_value, curhdr);
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate if (debug_level >= 3)
2957c478bd9Sstevel@tonic-gate check_hash();
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate /*
2987c478bd9Sstevel@tonic-gate * Sometimes the compiler stutters, and emits the same stab
2997c478bd9Sstevel@tonic-gate * twice. This is bad for the parser, which will attempt to
3007c478bd9Sstevel@tonic-gate * redefine the type IDs indicated in the stabs. This is
3017c478bd9Sstevel@tonic-gate * compiler bug 4433511.
3027c478bd9Sstevel@tonic-gate */
3037c478bd9Sstevel@tonic-gate if (ofstr && strcmp(fstr, ofstr) == 0) {
3047c478bd9Sstevel@tonic-gate debug(3, "Stutter stab\n");
3057c478bd9Sstevel@tonic-gate free(fstr);
3067c478bd9Sstevel@tonic-gate fstr = NULL;
3077c478bd9Sstevel@tonic-gate continue;
3087c478bd9Sstevel@tonic-gate }
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate if (ofstr)
3117c478bd9Sstevel@tonic-gate free(ofstr);
3127c478bd9Sstevel@tonic-gate ofstr = fstr;
3137c478bd9Sstevel@tonic-gate
3147c478bd9Sstevel@tonic-gate iidescp = NULL;
315c168da27Sjohnlev
316c168da27Sjohnlev if ((rc = parse_stab(stab, fstr, &iidescp)) < 0) {
317c168da27Sjohnlev terminate("%s: Couldn't parse stab \"%s\" "
318c168da27Sjohnlev "(source file %s)\n", file, str, curhdr);
319c168da27Sjohnlev }
320c168da27Sjohnlev
3217c478bd9Sstevel@tonic-gate if (rc == 0)
3227c478bd9Sstevel@tonic-gate goto parse_loop_end;
3237c478bd9Sstevel@tonic-gate
3247c478bd9Sstevel@tonic-gate /* Make sure the scope tracking is working correctly */
3257c478bd9Sstevel@tonic-gate assert(stab->n_type != N_FUN || (iidescp->ii_type != II_GFUN &&
3267c478bd9Sstevel@tonic-gate iidescp->ii_type != II_SFUN) || scope == 0);
3277c478bd9Sstevel@tonic-gate
3287c478bd9Sstevel@tonic-gate /*
3297c478bd9Sstevel@tonic-gate * The only things we care about that are in local scope are
3307c478bd9Sstevel@tonic-gate * the N_PSYM stabs.
3317c478bd9Sstevel@tonic-gate */
3327c478bd9Sstevel@tonic-gate if (scope && stab->n_type != N_PSYM) {
3337c478bd9Sstevel@tonic-gate if (iidescp)
3347c478bd9Sstevel@tonic-gate iidesc_free(iidescp, NULL);
3357c478bd9Sstevel@tonic-gate goto parse_loop_end;
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate
3387c478bd9Sstevel@tonic-gate switch (iidescp->ii_type) {
3397c478bd9Sstevel@tonic-gate case II_SFUN:
3407c478bd9Sstevel@tonic-gate iidescp->ii_owner = xstrdup(curfile);
3417c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/
3427c478bd9Sstevel@tonic-gate case II_GFUN:
3437c478bd9Sstevel@tonic-gate curfun = iidescp;
3447c478bd9Sstevel@tonic-gate fnarg_free(iidescp);
3457c478bd9Sstevel@tonic-gate iidesc_add(td->td_iihash, iidescp);
3467c478bd9Sstevel@tonic-gate break;
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gate case II_SVAR:
3497c478bd9Sstevel@tonic-gate iidescp->ii_owner = xstrdup(curfile);
3507c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/
3517c478bd9Sstevel@tonic-gate case II_GVAR:
3527c478bd9Sstevel@tonic-gate case II_TYPE:
3537c478bd9Sstevel@tonic-gate case II_SOU:
3547c478bd9Sstevel@tonic-gate iidesc_add(td->td_iihash, iidescp);
3557c478bd9Sstevel@tonic-gate break;
3567c478bd9Sstevel@tonic-gate
3577c478bd9Sstevel@tonic-gate case II_PSYM:
3587c478bd9Sstevel@tonic-gate fnarg_add(curfun, iidescp);
3597c478bd9Sstevel@tonic-gate iidesc_free(iidescp, NULL);
3607c478bd9Sstevel@tonic-gate break;
3617c478bd9Sstevel@tonic-gate default:
362c168da27Sjohnlev aborterr("invalid ii_type %d for stab type %d",
363c168da27Sjohnlev iidescp->ii_type, stab->n_type);
3647c478bd9Sstevel@tonic-gate }
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate parse_loop_end:
3677c478bd9Sstevel@tonic-gate fstr = NULL;
3687c478bd9Sstevel@tonic-gate }
3697c478bd9Sstevel@tonic-gate
3707c478bd9Sstevel@tonic-gate if (ofstr)
3717c478bd9Sstevel@tonic-gate free(ofstr);
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate resolve_nodes(td);
3747c478bd9Sstevel@tonic-gate resolve_typed_bitfields();
3757c478bd9Sstevel@tonic-gate parse_finish(td);
3767c478bd9Sstevel@tonic-gate
377*e824d57fSjohnlev cvt_fixstabs(td);
378*e824d57fSjohnlev cvt_fixups(td, elf_ptrsz(elf));
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate return (0);
3817c478bd9Sstevel@tonic-gate }
382