if (q != 0 && N_ISWEAK(q) && (lsp->entry->flags & E_SECONDCLASS)) continue; q = p;
digest_pass1(){	/*	 * For each symbol, verify that it is defined globally at most	 * once within relocatable files (except when building a shared lib).	 * and set the `defined' field if there is a definition.	 *	 * Then check the shared object symbol chain for any remaining	 * undefined symbols. Set the `so_defined' field for any	 * definition find this way.	 */	FOR_EACH_SYMBOL(i, sp) {		symbol *spsave;		struct localsymbol *lsp;		int             defs = 0;		if (!(sp->flags & GS_REFERENCED)) {#if 0			/* Check for undefined symbols in shared objects */			int type;			for (lsp = sp->sorefs; lsp; lsp = lsp->next) {				type = lsp->nzlist.nlist.n_type;				if ((type & N_EXT) && type != (N_UNDF | N_EXT))					break;			}			if ((type & N_EXT) && type == (N_UNDF | N_EXT))				undefined_shobj_sym_count++;#endif			/* Superfluous symbol from shared object */			continue;		}		if (sp->so_defined)			/* Already examined; must have been an alias */			continue;		if (sp == got_symbol || sp == dynamic_symbol)			continue;		for (lsp = sp->refs; lsp; lsp = lsp->next) {			register struct nlist *p = &lsp->nzlist.nlist;			register int    type = p->n_type;			if (SET_ELEMENT_P(type)) {				if (relocatable_output)					errx(1,				"internal error: global ref to set el %s with -r",						sp->name);				if (!defs++) {					sp->defined = N_SETV | N_EXT;					sp->value =						setv_fill_count++ * sizeof(long);				} else if ((sp->defined & N_TYPE) != N_SETV) {					sp->mult_defs = 1;					multiple_def_count++;				}				/* Keep count and remember symbol */				sp->setv_count++;				set_vectors[setv_fill_count++] = (long)p;				if (building_shared_object) {					struct relocation_info reloc;					/*					 * Make sure to relocate the contents					 * of this set vector.					 */					bzero(&reloc, sizeof(reloc));					RELOC_INIT_SEGMENT_RELOC(&reloc);					RELOC_ADDRESS(&reloc) =						setv_fill_count * sizeof(long);					alloc_rrs_segment_reloc(NULL, &reloc);				}			} else if ((type & N_EXT) && type != (N_UNDF | N_EXT)						&& (type & N_TYPE) != N_FN						&& (type & N_TYPE) != N_SIZE) {				/* non-common definition */				if (!N_ISWEAK(p))					++defs;				if (defs > 1) {					sp->mult_defs = 1;					multiple_def_count++;				} else if (!N_ISWEAK(p) ||					   (!sp->def_lsp && !sp->common_size)) {					sp->def_lsp = lsp;					lsp->entry->flags |= E_SYMBOLS_USED;					sp->defined = type;					sp->aux = N_AUX(p);				}			}		}		/*		 * If this symbol has acquired final definition, we're done.		 * Commons must be allowed to bind to shared object data		 * definitions.		 */		if (sp->defined &&		    (sp->common_size == 0 ||		     relocatable_output || building_shared_object)) {			if ((sp->defined & N_TYPE) == N_SETV)				/* Allocate zero entry in set vector */				setv_fill_count++;			/*			 * At this stage, we do not know whether an alias			 * is going to be defined for real here, or whether			 * it refers to a shared object symbol. The decision			 * is deferred until digest_pass2().			 */			if (!sp->alias)				defined_global_sym_count++;			continue;		}		if (relocatable_output)			/* We're done */			continue;		/*		 * Still undefined, search the shared object symbols for a		 * definition. This symbol must go into the RRS.		 */		if (building_shared_object) {			/* Just punt for now */			undefined_global_sym_count--;			if (undefined_global_sym_count < 0)				errx(1,	"internal error: digest_pass1,1: %s: undefined_global_sym_count = %d",					sp->name, undefined_global_sym_count);			continue;		}		spsave=sp; /*XXX*/	again:		for (lsp = sp->sorefs; lsp; lsp = lsp->next) {			register struct nlist *p = &lsp->nzlist.nlist;			register int    type = p->n_type;			if ((type & N_EXT) && type != (N_UNDF | N_EXT) &&			    (type & N_TYPE) != N_FN) {				/* non-common definition */				if (sp->common_size) {					/*					 * This common has an so defn; switch					 * to it iff defn is: data, first-class					 * and not weak.					 */					if (N_AUX(p) != AUX_OBJECT ||					    N_ISWEAK(p) ||					    (lsp->entry->flags & E_SECONDCLASS))						continue;					/*					 * Change common to so ref. First,					 * downgrade common to undefined.					 */					sp->common_size = 0;					sp->defined = 0;					common_defined_global_count--;					undefined_global_sym_count++;				}				sp->def_lsp = lsp;				sp->so_defined = type;				sp->aux = N_AUX(p);				if (lsp->entry->flags & E_SECONDCLASS)					/* Keep looking for something better */					continue;				if (N_ISWEAK(p))					/* Keep looking for something better */					continue;				break;			}		}		if (sp->def_lsp) {#ifdef DEBUGprintf("pass1: SO definition for %s, type %x in %s at %#x\n",	sp->name, sp->so_defined, get_file_name(sp->def_lsp->entry),	sp->def_lsp->nzlist.nz_value);#endif			sp->def_lsp->entry->flags |= E_SYMBOLS_USED;			if (sp->flags & GS_REFERENCED) {				undefined_global_sym_count--;			} else				sp->flags |= GS_REFERENCED;			if (undefined_global_sym_count < 0)				errx(1, "internal error: digest_pass1,2: "					"%s: undefined_global_sym_count = %d",					sp->name, undefined_global_sym_count);			if (sp->alias &&			    !(sp->alias->flags & GS_REFERENCED)) {				sp = sp->alias;				goto again;			}		} else if (sp->defined) {			if (sp->common_size == 0)				errx(1, "internal error: digest_pass1,3: "					"%s: not a common: %x",					sp->name, sp->defined);			/*			 * Common not bound to shared object data; treat			 * it now like other defined symbols were above.			 */			if (!sp->alias)				defined_global_sym_count++;		}		sp=spsave; /*XXX*/	} END_EACH_SYMBOL;	if (setv_fill_count != set_sect_size/sizeof(long))		errx(1, "internal error: allocated set symbol space (%d) "			"doesn't match actual (%d)",			set_sect_size/sizeof(long), setv_fill_count);}