xref: /titanic_50/usr/src/cmd/sgs/libld/common/args.c (revision ccfce1d8e7219e7616d8df1e8cfca8f97febf5b8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  *	Copyright (c) 1988 AT&T
24  *	  All Rights Reserved
25  *
26  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 /*
32  * Publicly available flags are defined in ld(1).   The following flags are
33  * private, and may be removed at any time.
34  *
35  *    OPTION			MEANING
36  *
37  *    -z dtrace=symbol		assigns symbol to PT_SUNWDTRACE segment,
38  *    				providing scratch ares for dtrace processing.
39  *
40  *    -z noreloc		suppress relocation processing.  This provides
41  *				a mechanism for validating kernel module symbol
42  *				resolution that would normally incur fatal
43  *				relocation errors.
44  *
45  *    -z rtldinfo=symbol	assigns symbol to SUNW_RTLDINF dynamic tag,
46  *				providing pre-initialization specific routines
47  *				for TLS initialization.
48  *
49  *    -z nointerp		suppress the addition of an interpreter
50  *				section.  This is used to generate the kernel,
51  *				but makes no sense to be used by anyone else.
52  */
53 #include	<sys/link.h>
54 #include	<stdio.h>
55 #include	<fcntl.h>
56 #include	<string.h>
57 #include	<errno.h>
58 #include	<elf.h>
59 #include	<unistd.h>
60 #include	<debug.h>
61 #include	"msg.h"
62 #include	"_libld.h"
63 
64 /*
65  * Define a set of local argument flags, the settings of these will be
66  * verified in check_flags() and lead to the appropriate output file flags
67  * being initialized.
68  */
69 typedef	enum {
70 	SET_UNKNOWN = -1,
71 	SET_FALSE = 0,
72 	SET_TRUE = 1
73 } Setstate;
74 
75 static Setstate	dflag	= SET_UNKNOWN;
76 static Setstate	zdflag	= SET_UNKNOWN;
77 static Setstate	Qflag	= SET_UNKNOWN;
78 static Setstate	Bdflag	= SET_UNKNOWN;
79 
80 static Boolean	aflag	= FALSE;
81 static Boolean	bflag	= FALSE;
82 static Boolean	rflag	= FALSE;
83 static Boolean	sflag	= FALSE;
84 static Boolean	zinflag = FALSE;
85 static Boolean	zlflag	= FALSE;
86 static Boolean	Bgflag	= FALSE;
87 static Boolean	Blflag	= FALSE;
88 static Boolean	Beflag	= FALSE;
89 static Boolean	Bsflag	= FALSE;
90 static Boolean	Btflag	= FALSE;
91 static Boolean	Gflag	= FALSE;
92 static Boolean	Vflag	= FALSE;
93 
94 /*
95  * ztflag's state is set by pointing it to the matching string:
96  *	text | textoff | textwarn
97  */
98 static const char	*ztflag = 0;
99 
100 static uintptr_t process_files_com(Ofl_desc *, int, char **);
101 static uintptr_t process_flags_com(Ofl_desc *, int, char **, int *);
102 
103 /*
104  * Print usage message to stderr - 2 modes, summary message only,
105  * and full usage message.
106  */
107 static void
108 usage_mesg(Boolean detail)
109 {
110 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_USAGE),
111 	    MSG_ORIG(MSG_STR_OPTIONS));
112 
113 	if (detail == FALSE)
114 		return;
115 
116 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_6));
117 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_A));
118 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_B));
119 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBDR));
120 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBDY));
121 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBE));
122 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBG));
123 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBL));
124 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBR));
125 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBS));
126 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_C));
127 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CC));
128 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_D));
129 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CD));
130 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_E));
131 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_F));
132 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CF));
133 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CG));
134 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_H));
135 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_I));
136 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CI));
137 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_L));
138 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CL));
139 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_M));
140 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CM));
141 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CN));
142 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_O));
143 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_P));
144 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CP));
145 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CQ));
146 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_R));
147 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CR));
148 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_S));
149 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CS));
150 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_T));
151 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_U));
152 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CV));
153 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CY));
154 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZA));
155 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZAE));
156 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZAL));
157 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZC));
158 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZDFS));
159 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZDRS));
160 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZE));
161 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZFA));
162 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZGP));
163 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZH));
164 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZIG));
165 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZINA));
166 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZINI));
167 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZINT));
168 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZLAZY));
169 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZLD32));
170 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZLD64));
171 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZLO));
172 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZM));
173 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNC));
174 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNDFS));
175 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNDEF));
176 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNDEL));
177 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNDLO));
178 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNDU));
179 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNOW));
180 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNPA));
181 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNV));
182 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZO));
183 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZPIA));
184 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZRL));
185 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZRS));
186 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZT));
187 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZTO));
188 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZTW));
189 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZV));
190 }
191 
192 /*
193  * Checks the command line option flags for consistency.
194  */
195 static uintptr_t
196 check_flags(Ofl_desc * ofl, int argc)
197 {
198 	if (Plibpath && (Llibdir || Ulibdir)) {
199 		eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_ARG_YP),
200 		    Llibdir ? 'L' : 'U');
201 		ofl->ofl_flags |= FLG_OF_FATAL;
202 	}
203 
204 	if (rflag) {
205 		if (dflag == SET_UNKNOWN)
206 			dflag = SET_FALSE;
207 		if (ofl->ofl_flags1 & FLG_OF1_RELCNT) {
208 			eprintf(ofl->ofl_lml, ERR_WARNING,
209 			    MSG_INTL(MSG_ARG_INCOMP), MSG_ORIG(MSG_ARG_R),
210 			    MSG_ORIG(MSG_ARG_ZCOMBRELOC));
211 			ofl->ofl_flags1 &= ~FLG_OF1_RELCNT;
212 		}
213 		ofl->ofl_flags |= FLG_OF_RELOBJ;
214 	}
215 
216 	if (zdflag == SET_TRUE)
217 		ofl->ofl_flags |= FLG_OF_NOUNDEF;
218 
219 	if (zinflag)
220 		ofl->ofl_dtflags_1 |= DF_1_INTERPOSE;
221 
222 	if (sflag)
223 		ofl->ofl_flags |= FLG_OF_STRIP;
224 
225 	if (Qflag == SET_TRUE)
226 		ofl->ofl_flags |= FLG_OF_ADDVERS;
227 
228 	if (Blflag)
229 		ofl->ofl_flags |= FLG_OF_AUTOLCL;
230 
231 	if (Beflag)
232 		ofl->ofl_flags1 |= FLG_OF1_AUTOELM;
233 
234 	if (Blflag && Beflag) {
235 		eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_ARG_INCOMP),
236 		    MSG_ORIG(MSG_ARG_BELIMINATE), MSG_ORIG(MSG_ARG_BLOCAL));
237 		ofl->ofl_flags |= FLG_OF_FATAL;
238 	}
239 
240 	if (ofl->ofl_interp && (ofl->ofl_flags1 & FLG_OF1_NOINTRP)) {
241 		eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_ARG_INCOMP),
242 		    MSG_ORIG(MSG_ARG_CI), MSG_ORIG(MSG_ARG_ZNOINTERP));
243 		ofl->ofl_flags |= FLG_OF_FATAL;
244 	}
245 
246 	if (dflag != SET_FALSE) {
247 		/*
248 		 * Set -Bdynamic on by default, setting is rechecked as input
249 		 * files are processed.
250 		 */
251 		ofl->ofl_flags |=
252 		    (FLG_OF_DYNAMIC | FLG_OF_DYNLIBS | FLG_OF_PROCRED);
253 
254 		if (aflag) {
255 			eprintf(ofl->ofl_lml, ERR_FATAL,
256 			    MSG_INTL(MSG_ARG_INCOMP), MSG_ORIG(MSG_ARG_DY),
257 			    MSG_ORIG(MSG_ARG_A));
258 			ofl->ofl_flags |= FLG_OF_FATAL;
259 		}
260 
261 		if (bflag)
262 			ofl->ofl_flags |= FLG_OF_BFLAG;
263 
264 		if (Bgflag == TRUE) {
265 			if (zdflag == SET_FALSE) {
266 				eprintf(ofl->ofl_lml, ERR_FATAL,
267 				    MSG_INTL(MSG_ARG_INCOMP),
268 				    MSG_ORIG(MSG_ARG_BGROUP),
269 				    MSG_ORIG(MSG_ARG_ZNODEF));
270 				ofl->ofl_flags |= FLG_OF_FATAL;
271 			}
272 			ofl->ofl_dtflags_1 |= DF_1_GROUP;
273 			ofl->ofl_flags |= FLG_OF_NOUNDEF;
274 		}
275 
276 		/*
277 		 * If the use of default library searching has been suppressed
278 		 * but no runpaths have been provided we're going to have a hard
279 		 * job running this object.
280 		 */
281 		if ((ofl->ofl_dtflags_1 & DF_1_NODEFLIB) && !ofl->ofl_rpath)
282 			eprintf(ofl->ofl_lml, ERR_WARNING,
283 			    MSG_INTL(MSG_ARG_NODEFLIB));
284 
285 		/*
286 		 * By default, text relocation warnings are given when building
287 		 * an executable unless the -b flag is specified.  This option
288 		 * implies that unclean text can be created, so no warnings are
289 		 * generated unless specifically asked for.
290 		 */
291 		if ((ztflag == MSG_ORIG(MSG_ARG_ZTEXTOFF)) ||
292 		    ((ztflag == 0) && bflag))
293 			ofl->ofl_flags1 |= FLG_OF1_TEXTOFF;
294 		else if (ztflag == MSG_ORIG(MSG_ARG_ZTEXT))
295 			ofl->ofl_flags |= FLG_OF_PURETXT;
296 
297 		if (Gflag || !rflag) {
298 			/*
299 			 * Create a dynamic object.  -Bdirect indicates that all
300 			 * references should be bound directly.  This also
301 			 * enables lazyloading.  Individual symbols can be
302 			 * bound directly (or not) using mapfiles and the
303 			 * DIRECT (NODIRECT) qualifier.  With this capability,
304 			 * each syminfo entry is tagged SYMINFO_FLG_DIRECTBIND.
305 			 * Prior to this per-symbol direct binding, runtime
306 			 * direct binding was controlled via the DF_1_DIRECT
307 			 * flag.  This flag affected all references from the
308 			 * object.  -Bdirect continues to set this flag, and
309 			 * thus provides a means of taking a newly built
310 			 * direct binding object back to older systems.
311 			 *
312 			 * NOTE, any use of per-symbol NODIRECT bindings, or
313 			 * -znodirect, will disable the creation of the
314 			 * DF_1_DIRECT flag.  Older runtime linkers do not
315 			 * have the capability to do per-symbol direct bindings.
316 			 */
317 			if (Bdflag == SET_TRUE) {
318 				ofl->ofl_dtflags_1 |= DF_1_DIRECT;
319 				ofl->ofl_flags1 |= FLG_OF1_LAZYLD;
320 				ofl->ofl_flags |= FLG_OF_SYMINFO;
321 			}
322 
323 			/*
324 			 * -Bnodirect disables directly binding to any symbols
325 			 * exported from the object being created.  Individual
326 			 * references to external objects can still be affected
327 			 * by -zdirect or mapfile DIRECT directives.
328 			 */
329 			if (Bdflag == SET_FALSE) {
330 				ofl->ofl_dtflags_1 |= DF_1_NODIRECT;
331 				ofl->ofl_flags1 |=
332 				    (FLG_OF1_NDIRECT | FLG_OF1_ALNODIR);
333 				ofl->ofl_flags |= FLG_OF_SYMINFO;
334 			}
335 		}
336 
337 		if (!Gflag && !rflag) {
338 			/*
339 			 * Dynamically linked executable.
340 			 */
341 			ofl->ofl_flags |= FLG_OF_EXEC;
342 
343 			if (zdflag != SET_FALSE)
344 				ofl->ofl_flags |= FLG_OF_NOUNDEF;
345 
346 			if (Bsflag) {
347 				eprintf(ofl->ofl_lml, ERR_FATAL,
348 				    MSG_INTL(MSG_ARG_DYNINCOMP),
349 				    MSG_ORIG(MSG_ARG_BSYMBOLIC));
350 				ofl->ofl_flags |= FLG_OF_FATAL;
351 			}
352 			if (ofl->ofl_soname) {
353 				eprintf(ofl->ofl_lml, ERR_FATAL,
354 				    MSG_INTL(MSG_ARG_DYNINCOMP),
355 				    MSG_ORIG(MSG_ARG_H));
356 				ofl->ofl_flags |= FLG_OF_FATAL;
357 			}
358 			if (Btflag) {
359 				eprintf(ofl->ofl_lml, ERR_FATAL,
360 				    MSG_INTL(MSG_ARG_DYNINCOMP),
361 				    MSG_ORIG(MSG_ARG_BTRANS));
362 				ofl->ofl_flags |= FLG_OF_FATAL;
363 			}
364 			if (ofl->ofl_filtees) {
365 				if (ofl->ofl_flags & FLG_OF_AUX) {
366 					eprintf(ofl->ofl_lml, ERR_FATAL,
367 					    MSG_INTL(MSG_ARG_DYNINCOMP),
368 					    MSG_ORIG(MSG_ARG_F));
369 				} else {
370 					eprintf(ofl->ofl_lml, ERR_FATAL,
371 					    MSG_INTL(MSG_ARG_DYNINCOMP),
372 					    MSG_ORIG(MSG_ARG_CF));
373 				}
374 				ofl->ofl_flags |= FLG_OF_FATAL;
375 			}
376 
377 		} else if (!rflag) {
378 			/*
379 			 * Shared library.
380 			 */
381 			ofl->ofl_flags |= FLG_OF_SHAROBJ;
382 
383 			/*
384 			 * By default we print relocation errors for
385 			 * executables but *not* for a shared object
386 			 */
387 			if (ztflag == 0)
388 				ofl->ofl_flags1 |= FLG_OF1_TEXTOFF;
389 
390 			if (Bsflag) {
391 				ofl->ofl_flags |= FLG_OF_SYMBOLIC;
392 				ofl->ofl_dtflags |= DF_SYMBOLIC;
393 			}
394 
395 			if (Btflag) {
396 				ofl->ofl_dtflags_1 |=
397 				    (DF_1_TRANS | DF_1_DIRECT);
398 				ofl->ofl_flags |= FLG_OF_SYMINFO;
399 			}
400 
401 		} else {
402 			/*
403 			 * Dynamic relocatable object
404 			 */
405 			/*
406 			 * By default we print relocation errors for
407 			 * executables but *not* for a shared object
408 			 */
409 			if (ztflag == 0)
410 				ofl->ofl_flags1 |= FLG_OF1_TEXTOFF;
411 		}
412 	} else {
413 		ofl->ofl_flags |= FLG_OF_STATIC;
414 
415 		if (bflag) {
416 			eprintf(ofl->ofl_lml, ERR_FATAL,
417 			    MSG_INTL(MSG_ARG_INCOMP), MSG_ORIG(MSG_ARG_DN),
418 			    MSG_ORIG(MSG_ARG_B));
419 			ofl->ofl_flags |= FLG_OF_FATAL;
420 		}
421 		if (ofl->ofl_soname) {
422 			eprintf(ofl->ofl_lml, ERR_FATAL,
423 			    MSG_INTL(MSG_ARG_INCOMP), MSG_ORIG(MSG_ARG_DN),
424 			    MSG_ORIG(MSG_ARG_H));
425 			ofl->ofl_flags |= FLG_OF_FATAL;
426 		}
427 		if (ofl->ofl_depaudit) {
428 			eprintf(ofl->ofl_lml, ERR_FATAL,
429 			    MSG_INTL(MSG_ARG_INCOMP), MSG_ORIG(MSG_ARG_DN),
430 			    MSG_ORIG(MSG_ARG_P));
431 			ofl->ofl_flags |= FLG_OF_FATAL;
432 		}
433 		if (ofl->ofl_audit) {
434 			eprintf(ofl->ofl_lml, ERR_FATAL,
435 			    MSG_INTL(MSG_ARG_INCOMP), MSG_ORIG(MSG_ARG_DN),
436 			    MSG_ORIG(MSG_ARG_CP));
437 			ofl->ofl_flags |= FLG_OF_FATAL;
438 		}
439 		if (ofl->ofl_config) {
440 			eprintf(ofl->ofl_lml, ERR_FATAL,
441 			    MSG_INTL(MSG_ARG_INCOMP), MSG_ORIG(MSG_ARG_DN),
442 			    MSG_ORIG(MSG_ARG_C));
443 			ofl->ofl_flags |= FLG_OF_FATAL;
444 		}
445 		if (ofl->ofl_filtees) {
446 			if (ofl->ofl_flags & FLG_OF_AUX) {
447 				eprintf(ofl->ofl_lml, ERR_FATAL,
448 				    MSG_INTL(MSG_ARG_INCOMP),
449 				    MSG_ORIG(MSG_ARG_DN), MSG_ORIG(MSG_ARG_F));
450 			} else {
451 				eprintf(ofl->ofl_lml, ERR_FATAL,
452 				    MSG_INTL(MSG_ARG_INCOMP),
453 				    MSG_ORIG(MSG_ARG_DN), MSG_ORIG(MSG_ARG_CF));
454 			}
455 			ofl->ofl_flags |= FLG_OF_FATAL;
456 		}
457 		if (ztflag) {
458 			eprintf(ofl->ofl_lml, ERR_FATAL,
459 			    MSG_INTL(MSG_ARG_INCOMP), MSG_ORIG(MSG_ARG_DN),
460 			    MSG_ORIG(MSG_ARG_ZTEXTALL));
461 			ofl->ofl_flags |= FLG_OF_FATAL;
462 		}
463 		if (Gflag) {
464 			eprintf(ofl->ofl_lml, ERR_FATAL,
465 			    MSG_INTL(MSG_ARG_INCOMP), MSG_ORIG(MSG_ARG_DN),
466 			    MSG_ORIG(MSG_ARG_CG));
467 			ofl->ofl_flags |= FLG_OF_FATAL;
468 		}
469 		if (aflag && rflag) {
470 			eprintf(ofl->ofl_lml, ERR_FATAL,
471 			    MSG_INTL(MSG_ARG_INCOMP), MSG_ORIG(MSG_ARG_A),
472 			    MSG_ORIG(MSG_ARG_R));
473 			ofl->ofl_flags |= FLG_OF_FATAL;
474 		}
475 
476 		if (rflag) {
477 			/*
478 			 * We can only strip the symbol table and string table
479 			 * if no output relocations will refer to them
480 			 */
481 			if (sflag) {
482 				eprintf(ofl->ofl_lml, ERR_WARNING,
483 				    MSG_INTL(MSG_ARG_STRIP));
484 			}
485 
486 			if (ztflag == 0)
487 				ofl->ofl_flags1 |= FLG_OF1_TEXTOFF;
488 
489 			if (ofl->ofl_interp) {
490 				eprintf(ofl->ofl_lml, ERR_FATAL,
491 				    MSG_INTL(MSG_ARG_INCOMP),
492 				    MSG_ORIG(MSG_ARG_R), MSG_ORIG(MSG_ARG_CI));
493 				ofl->ofl_flags |= FLG_OF_FATAL;
494 			}
495 		} else {
496 			/*
497 			 * Static executable.
498 			 */
499 			ofl->ofl_flags |= FLG_OF_EXEC | FLG_OF_PROCRED;
500 
501 			if (zdflag != SET_FALSE)
502 				ofl->ofl_flags |= FLG_OF_NOUNDEF;
503 		}
504 	}
505 
506 	/*
507 	 * If the user didn't supply an output file name supply a default.
508 	 */
509 	if (ofl->ofl_name == NULL)
510 		ofl->ofl_name = MSG_ORIG(MSG_STR_AOUT);
511 
512 	/*
513 	 * We set the entrance criteria after all input argument processing as
514 	 * it is only at this point we're sure what the output image will be
515 	 * (static or dynamic).
516 	 */
517 	if (ld_ent_setup(ofl, M_SEGM_ALIGN) == S_ERROR)
518 		return (S_ERROR);
519 
520 	/*
521 	 * Initialize string tables.  Symbol definitions within mapfiles can
522 	 * result in the creation of input sections.
523 	 */
524 	if (ld_init_strings(ofl) == S_ERROR)
525 		return (S_ERROR);
526 
527 	/*
528 	 * Process any mapfiles after establishing the entrance criteria as
529 	 * the user may be redefining or adding sections/segments.
530 	 */
531 	if (ofl->ofl_maps.head) {
532 		Listnode	*lnp;
533 		const char	*name;
534 
535 		for (LIST_TRAVERSE(&ofl->ofl_maps, lnp, name))
536 			if (ld_map_parse(name, ofl) == S_ERROR)
537 				return (S_ERROR);
538 
539 		if (ofl->ofl_flags & FLG_OF_SEGSORT)
540 			if (ld_sort_seg_list(ofl) == S_ERROR)
541 				return (S_ERROR);
542 	}
543 
544 	/*
545 	 * If -zloadfltr is set, verify that filtering is in effect.  Filters
546 	 * are either established from the command line, and affect the whole
547 	 * object, or are set on a per-symbol basis from a mapfile.
548 	 */
549 	if (zlflag) {
550 		if ((ofl->ofl_filtees == 0) && (ofl->ofl_dtsfltrs == 0)) {
551 			eprintf(ofl->ofl_lml, ERR_FATAL,
552 			    MSG_INTL(MSG_ARG_NOFLTR),
553 			    MSG_ORIG(MSG_ARG_ZLOADFLTR));
554 			ofl->ofl_flags |= FLG_OF_FATAL;
555 		}
556 		ofl->ofl_dtflags_1 |= DF_1_LOADFLTR;
557 	}
558 
559 	/*
560 	 * Check that we have something to work with.  This check is carried out
561 	 * after mapfile processing as its possible a mapfile is being used to
562 	 * define symbols, in which case it would be sufficient to build the
563 	 * output file purely from the mapfile.
564 	 */
565 	if ((ofl->ofl_objscnt == 0) && (ofl->ofl_soscnt == 0)) {
566 		if (Vflag && (argc == 2))
567 			ofl->ofl_flags1 |= FLG_OF1_DONE;
568 		else {
569 			eprintf(ofl->ofl_lml, ERR_FATAL,
570 			    MSG_INTL(MSG_ARG_NOFILES));
571 			return (S_ERROR);
572 		}
573 	}
574 	return (1);
575 }
576 
577 /*
578  * Decompose the string pointed by optarg into argv[][] so that argv[][] can be
579  * used as an argument to getopt().
580  *
581  * If the second argument 'error' is not 0, then this is called from the first
582  * pass. Else this is called from the second pass.
583  */
584 static uintptr_t
585 createargv(Ofl_desc *ofl, int *error)
586 {
587 	int		argc = 0, idx = 0, ooptind;
588 	uintptr_t	ret;
589 	char		**argv, *p0;
590 
591 	/*
592 	 * The argument being examined is either:
593 	 *	ld32= 	or
594 	 *	ld64=
595 	 */
596 #if	defined(_LP64)
597 	if (optarg[2] == '3')
598 		return (0);
599 #else
600 	if (optarg[2] == '6')
601 		return (0);
602 #endif
603 
604 	p0 = &optarg[5];
605 
606 	/*
607 	 * Count the number of arguments.
608 	 */
609 	while (*p0) {
610 		/*
611 		 * Pointing at non-separator character.
612 		 */
613 		if (*p0 != ',') {
614 			argc++;
615 			while (*p0 && (*p0 != ','))
616 				p0++;
617 			continue;
618 		}
619 
620 		/*
621 		 * Pointing at a separator character.
622 		 */
623 		if (*p0 == ',') {
624 			while (*p0 == ',')
625 				p0++;
626 			continue;
627 		}
628 	}
629 
630 	if (argc == 0)
631 		return (0);
632 
633 	/*
634 	 * Allocate argument vector.
635 	 */
636 	if ((p0 = (char *)strdup(&optarg[5])) == 0)
637 		return (S_ERROR);
638 	if ((argv = libld_malloc((sizeof (char *)) * (argc + 1))) == 0)
639 		return (S_ERROR);
640 
641 	while (*p0) {
642 		char *p;
643 
644 		/*
645 		 * Pointing at the beginning of non-separator character string.
646 		 */
647 		if (*p0 != ',') {
648 			p = p0;
649 			while (*p0 && (*p0 != ','))
650 				p0++;
651 			argv[idx++] = p;
652 			if (*p0) {
653 				*p0 = '\0';
654 				p0++;
655 			}
656 			continue;
657 		}
658 
659 		/*
660 		 * Pointing at the beginining of separator character string.
661 		 */
662 		if (*p0 == ',') {
663 			while (*p0 == ',')
664 				p0++;
665 			continue;
666 		}
667 	}
668 	argv[idx] = 0;
669 	ooptind = optind;
670 	optind = 0;
671 
672 	/*
673 	 * Dispatch to pass1 or pass2
674 	 */
675 	if (error)
676 		ret = process_flags_com(ofl, argc, argv, error);
677 	else
678 		ret = process_files_com(ofl, argc, argv);
679 
680 	optind = ooptind;
681 
682 	if (ret == S_ERROR)
683 		return (S_ERROR);
684 
685 	return (argc);
686 }
687 
688 /*
689  * Parsing options pass1 for process_flags().
690  */
691 static uintptr_t
692 parseopt_pass1(Ofl_desc *ofl, int argc, char **argv, int *error)
693 {
694 	int	c;
695 
696 	while ((c = getopt(argc, argv, MSG_ORIG(MSG_STR_OPTIONS))) != -1) {
697 		DBG_CALL(Dbg_args_flags(ofl->ofl_lml, (optind - 1), c));
698 
699 		switch (c) {
700 		case '6':			/* Processed by ld to */
701 			/*
702 			 * -64 is processed by ld to determine the output class.
703 			 * Here we sanity check the option incase some other
704 			 * -6* option is mistakenly passed to us.
705 			 */
706 			if (optarg[0] != '4') {
707 				eprintf(ofl->ofl_lml, ERR_FATAL,
708 				    MSG_INTL(MSG_ARG_ILLEGAL),
709 				    MSG_ORIG(MSG_ARG_6), optarg);
710 				ofl->ofl_flags |= FLG_OF_FATAL;
711 			}
712 			continue;
713 
714 		case 'a':
715 			aflag = TRUE;
716 			break;
717 
718 		case 'b':
719 			bflag = TRUE;
720 			break;
721 
722 		case 'c':
723 			if (ofl->ofl_config)
724 				eprintf(ofl->ofl_lml, ERR_WARNING,
725 				    MSG_INTL(MSG_ARG_MTONCE),
726 				    MSG_ORIG(MSG_ARG_C));
727 			else
728 				ofl->ofl_config = optarg;
729 			break;
730 
731 		case 'C':
732 			demangle_flag = 1;
733 			break;
734 
735 		case 'd':
736 			if ((optarg[0] == 'n') && (optarg[1] == '\0')) {
737 				if (dflag != SET_UNKNOWN)
738 					eprintf(ofl->ofl_lml, ERR_WARNING,
739 					    MSG_INTL(MSG_ARG_MTONCE),
740 					    MSG_ORIG(MSG_ARG_D));
741 				else
742 					dflag = SET_FALSE;
743 			} else if ((optarg[0] == 'y') && (optarg[1] == '\0')) {
744 				if (dflag != SET_UNKNOWN)
745 					eprintf(ofl->ofl_lml, ERR_WARNING,
746 					    MSG_INTL(MSG_ARG_MTONCE),
747 					    MSG_ORIG(MSG_ARG_D));
748 				else
749 					dflag = SET_TRUE;
750 			} else {
751 				eprintf(ofl->ofl_lml, ERR_FATAL,
752 				    MSG_INTL(MSG_ARG_ILLEGAL),
753 				    MSG_ORIG(MSG_ARG_D), optarg);
754 				ofl->ofl_flags |= FLG_OF_FATAL;
755 			}
756 			break;
757 
758 		case 'e':
759 			if (ofl->ofl_entry)
760 				eprintf(ofl->ofl_lml, ERR_WARNING,
761 				    MSG_INTL(MSG_ARG_MTONCE),
762 				    MSG_ORIG(MSG_ARG_E));
763 			else
764 				ofl->ofl_entry = (void *)optarg;
765 			break;
766 
767 		case 'f':
768 			if (ofl->ofl_filtees &&
769 			    (!(ofl->ofl_flags & FLG_OF_AUX))) {
770 				eprintf(ofl->ofl_lml, ERR_FATAL,
771 				    MSG_INTL(MSG_ARG_INCOMP),
772 				    MSG_ORIG(MSG_ARG_F), MSG_ORIG(MSG_ARG_CF));
773 				ofl->ofl_flags |= FLG_OF_FATAL;
774 			} else {
775 				if ((ofl->ofl_filtees =
776 				    add_string(ofl->ofl_filtees, optarg)) ==
777 				    (const char *)S_ERROR)
778 					return (S_ERROR);
779 				ofl->ofl_flags |= FLG_OF_AUX;
780 			}
781 			break;
782 
783 		case 'F':
784 			if (ofl->ofl_filtees &&
785 			    (ofl->ofl_flags & FLG_OF_AUX)) {
786 				eprintf(ofl->ofl_lml, ERR_FATAL,
787 				    MSG_INTL(MSG_ARG_INCOMP),
788 				    MSG_ORIG(MSG_ARG_CF), MSG_ORIG(MSG_ARG_F));
789 				ofl->ofl_flags |= FLG_OF_FATAL;
790 			} else {
791 				if ((ofl->ofl_filtees =
792 				    add_string(ofl->ofl_filtees, optarg)) ==
793 				    (const char *)S_ERROR)
794 					return (S_ERROR);
795 			}
796 			break;
797 
798 		case 'h':
799 			if (ofl->ofl_soname)
800 				eprintf(ofl->ofl_lml, ERR_WARNING,
801 				    MSG_INTL(MSG_ARG_MTONCE),
802 				    MSG_ORIG(MSG_ARG_H));
803 			else
804 				ofl->ofl_soname = (const char *)optarg;
805 			break;
806 
807 		case 'i':
808 			ofl->ofl_flags |= FLG_OF_IGNENV;
809 			break;
810 
811 		case 'I':
812 			if (ofl->ofl_interp)
813 				eprintf(ofl->ofl_lml, ERR_WARNING,
814 				    MSG_INTL(MSG_ARG_MTONCE),
815 				    MSG_ORIG(MSG_ARG_CI));
816 			else
817 				ofl->ofl_interp = (const char *)optarg;
818 			break;
819 
820 		case 'l':
821 			/*
822 			 * For now, count any library as a shared object.  This
823 			 * is used to size the internal symbol cache.  This
824 			 * value is recalculated later on actual file processing
825 			 * to get an accurate shared object count.
826 			 */
827 			ofl->ofl_soscnt++;
828 			break;
829 
830 		case 'm':
831 			ofl->ofl_flags |= FLG_OF_GENMAP;
832 			break;
833 
834 		case 'o':
835 			if (ofl->ofl_name)
836 				eprintf(ofl->ofl_lml, ERR_WARNING,
837 				    MSG_INTL(MSG_ARG_MTONCE),
838 				    MSG_ORIG(MSG_ARG_O));
839 			else
840 				ofl->ofl_name = (const char *)optarg;
841 			break;
842 
843 		case 'p':
844 			/*
845 			 * Multiple instances of this option may occur.  Each
846 			 * additional instance is effectively concatenated to
847 			 * the previous separated by a colon.
848 			 */
849 			if (*optarg != '\0') {
850 				if ((ofl->ofl_audit =
851 				    add_string(ofl->ofl_audit,
852 				    optarg)) == (const char *)S_ERROR)
853 					return (S_ERROR);
854 			}
855 			break;
856 
857 		case 'P':
858 			/*
859 			 * Multiple instances of this option may occur.  Each
860 			 * additional instance is effectively concatenated to
861 			 * the previous separated by a colon.
862 			 */
863 			if (*optarg != '\0') {
864 				if ((ofl->ofl_depaudit =
865 				    add_string(ofl->ofl_depaudit,
866 				    optarg)) == (const char *)S_ERROR)
867 					return (S_ERROR);
868 			}
869 			break;
870 
871 		case 'r':
872 			rflag = TRUE;
873 			break;
874 
875 		case 'R':
876 			/*
877 			 * Multiple instances of this option may occur.  Each
878 			 * additional instance is effectively concatenated to
879 			 * the previous separated by a colon.
880 			 */
881 			if (*optarg != '\0') {
882 				if ((ofl->ofl_rpath =
883 				    add_string(ofl->ofl_rpath,
884 				    optarg)) == (const char *)S_ERROR)
885 					return (S_ERROR);
886 			}
887 			break;
888 
889 		case 's':
890 			sflag = TRUE;
891 			break;
892 
893 		case 't':
894 			ofl->ofl_flags |= FLG_OF_NOWARN;
895 			break;
896 
897 		case 'u':
898 			break;
899 
900 		case 'z':
901 			/*
902 			 * For specific help, print our usage message and exit
903 			 * immediately to ensure a 0 return code.
904 			 */
905 			if (strncmp(optarg, MSG_ORIG(MSG_ARG_HELP),
906 			    MSG_ARG_HELP_SIZE) == 0) {
907 				usage_mesg(1);
908 				exit(0);
909 			}
910 
911 			/*
912 			 * For some options set a flag - further consistancy
913 			 * checks will be carried out in check_flags().
914 			 */
915 			if ((strncmp(optarg, MSG_ORIG(MSG_ARG_LD32),
916 			    MSG_ARG_LD32_SIZE) == 0) ||
917 			    (strncmp(optarg, MSG_ORIG(MSG_ARG_LD64),
918 			    MSG_ARG_LD64_SIZE) == 0)) {
919 				if (createargv(ofl, error) == S_ERROR)
920 					return (S_ERROR);
921 
922 			} else if (
923 			    strcmp(optarg, MSG_ORIG(MSG_ARG_DEFS)) == 0) {
924 				if (zdflag != SET_UNKNOWN)
925 					eprintf(ofl->ofl_lml, ERR_WARNING,
926 					    MSG_INTL(MSG_ARG_MTONCE),
927 					    MSG_ORIG(MSG_ARG_ZDEFNODEF));
928 				else
929 					zdflag = SET_TRUE;
930 			} else if (strcmp(optarg,
931 			    MSG_ORIG(MSG_ARG_NODEFS)) == 0) {
932 				if (zdflag != SET_UNKNOWN)
933 					eprintf(ofl->ofl_lml, ERR_WARNING,
934 					    MSG_INTL(MSG_ARG_MTONCE),
935 					    MSG_ORIG(MSG_ARG_ZDEFNODEF));
936 				else
937 					zdflag = SET_FALSE;
938 			} else if (strcmp(optarg,
939 			    MSG_ORIG(MSG_ARG_TEXT)) == 0) {
940 				if (ztflag &&
941 				    (ztflag != MSG_ORIG(MSG_ARG_ZTEXT))) {
942 					eprintf(ofl->ofl_lml, ERR_FATAL,
943 					    MSG_INTL(MSG_ARG_INCOMP),
944 					    MSG_ORIG(MSG_ARG_ZTEXT),
945 					    ztflag);
946 					ofl->ofl_flags |= FLG_OF_FATAL;
947 				}
948 				ztflag = MSG_ORIG(MSG_ARG_ZTEXT);
949 			} else if (strcmp(optarg,
950 			    MSG_ORIG(MSG_ARG_TEXTOFF)) == 0) {
951 				if (ztflag &&
952 				    (ztflag != MSG_ORIG(MSG_ARG_ZTEXTOFF))) {
953 					eprintf(ofl->ofl_lml, ERR_FATAL,
954 					    MSG_INTL(MSG_ARG_INCOMP),
955 					    MSG_ORIG(MSG_ARG_ZTEXTOFF),
956 					    ztflag);
957 					ofl->ofl_flags |= FLG_OF_FATAL;
958 				}
959 				ztflag = MSG_ORIG(MSG_ARG_ZTEXTOFF);
960 			} else if (strcmp(optarg,
961 			    MSG_ORIG(MSG_ARG_TEXTWARN)) == 0) {
962 				if (ztflag &&
963 				    (ztflag != MSG_ORIG(MSG_ARG_ZTEXTWARN))) {
964 					eprintf(ofl->ofl_lml, ERR_FATAL,
965 					    MSG_INTL(MSG_ARG_INCOMP),
966 					    MSG_ORIG(MSG_ARG_ZTEXTWARN),
967 					    ztflag);
968 					ofl->ofl_flags |= FLG_OF_FATAL;
969 				}
970 				ztflag = MSG_ORIG(MSG_ARG_ZTEXTWARN);
971 
972 			/*
973 			 * For other options simply set the ofl flags directly.
974 			 */
975 			} else if (strcmp(optarg,
976 			    MSG_ORIG(MSG_ARG_RESCAN)) == 0) {
977 				ofl->ofl_flags1 |= FLG_OF1_RESCAN;
978 			} else if (strcmp(optarg,
979 			    MSG_ORIG(MSG_ARG_ABSEXEC)) == 0) {
980 				ofl->ofl_flags1 |= FLG_OF1_ABSEXEC;
981 			} else if (strcmp(optarg,
982 			    MSG_ORIG(MSG_ARG_LOADFLTR)) == 0) {
983 				zlflag = TRUE;
984 			} else if (strcmp(optarg,
985 			    MSG_ORIG(MSG_ARG_NORELOC)) == 0) {
986 				ofl->ofl_dtflags_1 |= DF_1_NORELOC;
987 			} else if (strcmp(optarg,
988 			    MSG_ORIG(MSG_ARG_NOVERSION)) == 0) {
989 				ofl->ofl_flags |= FLG_OF_NOVERSEC;
990 			} else if (strcmp(optarg,
991 			    MSG_ORIG(MSG_ARG_MULDEFS)) == 0) {
992 				ofl->ofl_flags |= FLG_OF_MULDEFS;
993 			} else if (strcmp(optarg,
994 			    MSG_ORIG(MSG_ARG_REDLOCSYM)) == 0) {
995 				ofl->ofl_flags1 |= FLG_OF1_REDLSYM;
996 			} else if (strcmp(optarg,
997 			    MSG_ORIG(MSG_ARG_INITFIRST)) == 0) {
998 				ofl->ofl_dtflags_1 |= DF_1_INITFIRST;
999 			} else if (strcmp(optarg,
1000 			    MSG_ORIG(MSG_ARG_NODELETE)) == 0) {
1001 				ofl->ofl_dtflags_1 |= DF_1_NODELETE;
1002 			} else if (strcmp(optarg,
1003 			    MSG_ORIG(MSG_ARG_NOPARTIAL)) == 0) {
1004 				ofl->ofl_flags1 |= FLG_OF1_NOPARTI;
1005 			} else if (strcmp(optarg,
1006 			    MSG_ORIG(MSG_ARG_NOOPEN)) == 0) {
1007 				ofl->ofl_dtflags_1 |= DF_1_NOOPEN;
1008 			} else if (strcmp(optarg,
1009 			    MSG_ORIG(MSG_ARG_NOW)) == 0) {
1010 				ofl->ofl_dtflags_1 |= DF_1_NOW;
1011 				ofl->ofl_dtflags |= DF_BIND_NOW;
1012 			} else if (strcmp(optarg,
1013 			    MSG_ORIG(MSG_ARG_ORIGIN)) == 0) {
1014 				ofl->ofl_dtflags_1 |= DF_1_ORIGIN;
1015 				ofl->ofl_dtflags |= DF_ORIGIN;
1016 			} else if (strcmp(optarg,
1017 			    MSG_ORIG(MSG_ARG_NODEFAULTLIB)) == 0) {
1018 				ofl->ofl_dtflags_1 |= DF_1_NODEFLIB;
1019 			} else if (strcmp(optarg,
1020 			    MSG_ORIG(MSG_ARG_NODUMP)) == 0) {
1021 				ofl->ofl_dtflags_1 |= DF_1_NODUMP;
1022 			} else if (strcmp(optarg,
1023 			    MSG_ORIG(MSG_ARG_ENDFILTEE)) == 0) {
1024 				ofl->ofl_dtflags_1 |= DF_1_ENDFILTEE;
1025 			} else if (strcmp(optarg,
1026 			    MSG_ORIG(MSG_ARG_VERBOSE)) == 0) {
1027 				ofl->ofl_flags |= FLG_OF_VERBOSE;
1028 			} else if (strcmp(optarg,
1029 			    MSG_ORIG(MSG_ARG_COMBRELOC)) == 0) {
1030 				ofl->ofl_flags1 |= FLG_OF1_RELCNT;
1031 			} else if (strcmp(optarg,
1032 			    MSG_ORIG(MSG_ARG_NOCOMPSTRTAB)) == 0) {
1033 				ofl->ofl_flags1 |= FLG_OF1_NCSTTAB;
1034 			} else if (strcmp(optarg,
1035 			    MSG_ORIG(MSG_ARG_NOINTERP)) == 0) {
1036 				ofl->ofl_flags1 |= FLG_OF1_NOINTRP;
1037 			} else if (strcmp(optarg,
1038 			    MSG_ORIG(MSG_ARG_INTERPOSE)) == 0) {
1039 				zinflag = TRUE;
1040 			} else if (strcmp(optarg,
1041 			    MSG_ORIG(MSG_ARG_IGNORE)) == 0) {
1042 				ofl->ofl_flags1 |= FLG_OF1_IGNPRC;
1043 
1044 			/*
1045 			 * The following options just need validation as they
1046 			 * are interpreted on the second pass through the
1047 			 * command line arguments.
1048 			 */
1049 			} else if (
1050 			    strncmp(optarg, MSG_ORIG(MSG_ARG_INITARRAY),
1051 				MSG_ARG_INITARRAY_SIZE) &&
1052 			    strncmp(optarg, MSG_ORIG(MSG_ARG_FINIARRAY),
1053 				MSG_ARG_FINIARRAY_SIZE) &&
1054 			    strncmp(optarg, MSG_ORIG(MSG_ARG_PREINITARRAY),
1055 				MSG_ARG_PREINITARRAY_SIZE) &&
1056 			    strncmp(optarg, MSG_ORIG(MSG_ARG_RTLDINFO),
1057 				MSG_ARG_RTLDINFO_SIZE) &&
1058 			    strncmp(optarg, MSG_ORIG(MSG_ARG_DTRACE),
1059 				MSG_ARG_DTRACE_SIZE) &&
1060 			    strcmp(optarg, MSG_ORIG(MSG_ARG_ALLEXTRT)) &&
1061 			    strcmp(optarg, MSG_ORIG(MSG_ARG_DFLEXTRT)) &&
1062 			    strcmp(optarg, MSG_ORIG(MSG_ARG_DIRECT)) &&
1063 			    strcmp(optarg, MSG_ORIG(MSG_ARG_NODIRECT)) &&
1064 			    strcmp(optarg, MSG_ORIG(MSG_ARG_GROUPPERM)) &&
1065 			    strcmp(optarg, MSG_ORIG(MSG_ARG_LAZYLOAD)) &&
1066 			    strcmp(optarg, MSG_ORIG(MSG_ARG_NOGROUPPERM)) &&
1067 			    strcmp(optarg, MSG_ORIG(MSG_ARG_NOLAZYLOAD)) &&
1068 			    strcmp(optarg, MSG_ORIG(MSG_ARG_RECORD)) &&
1069 			    strcmp(optarg, MSG_ORIG(MSG_ARG_ALTEXEC64)) &&
1070 			    strcmp(optarg, MSG_ORIG(MSG_ARG_WEAKEXT))) {
1071 				eprintf(ofl->ofl_lml, ERR_FATAL,
1072 				    MSG_INTL(MSG_ARG_ILLEGAL),
1073 				    MSG_ORIG(MSG_ARG_Z), optarg);
1074 				ofl->ofl_flags |= FLG_OF_FATAL;
1075 
1076 			}
1077 
1078 			break;
1079 
1080 		case 'D':
1081 			/*
1082 			 * If we have not yet read any input files go ahead
1083 			 * and process any debugging options (this allows any
1084 			 * argument processing, entrance criteria and library
1085 			 * initialization to be displayed).  Otherwise, if an
1086 			 * input file has been seen, skip interpretation until
1087 			 * process_files (this allows debugging to be turned
1088 			 * on and off around individual groups of files).
1089 			 */
1090 			if (ofl->ofl_objscnt == 0) {
1091 				if (dbg_setup(optarg, dbg_desc,
1092 				    &ofl->ofl_name, 1) == S_ERROR)
1093 					return (S_ERROR);
1094 			}
1095 			break;
1096 
1097 		case 'B':
1098 			if (strcmp(optarg, MSG_ORIG(MSG_ARG_DIRECT)) == 0) {
1099 				if (Bdflag == SET_FALSE) {
1100 					eprintf(ofl->ofl_lml, ERR_FATAL,
1101 					    MSG_INTL(MSG_ARG_INCOMP),
1102 					    MSG_ORIG(MSG_ARG_BNODIRECT),
1103 					    MSG_ORIG(MSG_ARG_BDIRECT));
1104 					ofl->ofl_flags |= FLG_OF_FATAL;
1105 				} else
1106 					Bdflag = SET_TRUE;
1107 			} else if (strcmp(optarg,
1108 			    MSG_ORIG(MSG_ARG_NODIRECT)) == 0) {
1109 				if (Bdflag == SET_TRUE) {
1110 					eprintf(ofl->ofl_lml, ERR_FATAL,
1111 					    MSG_INTL(MSG_ARG_INCOMP),
1112 					    MSG_ORIG(MSG_ARG_BDIRECT),
1113 					    MSG_ORIG(MSG_ARG_BNODIRECT));
1114 					ofl->ofl_flags |= FLG_OF_FATAL;
1115 				} else
1116 					Bdflag = SET_FALSE;
1117 			} else if (strcmp(optarg,
1118 			    MSG_ORIG(MSG_STR_SYMBOLIC)) == 0)
1119 				Bsflag = TRUE;
1120 			else if (strcmp(optarg, MSG_ORIG(MSG_ARG_REDUCE)) == 0)
1121 				ofl->ofl_flags |= FLG_OF_PROCRED;
1122 			else if (strcmp(optarg, MSG_ORIG(MSG_STR_LOCAL)) == 0)
1123 				Blflag = TRUE;
1124 			else if (strcmp(optarg,
1125 			    MSG_ORIG(MSG_ARG_TRANSLATOR)) == 0)
1126 				Btflag = TRUE;
1127 			else if (strcmp(optarg, MSG_ORIG(MSG_ARG_GROUP)) == 0)
1128 				Bgflag = TRUE;
1129 			else if (strcmp(optarg,
1130 			    MSG_ORIG(MSG_STR_ELIMINATE)) == 0)
1131 				Beflag = TRUE;
1132 			else if (strcmp(optarg, MSG_ORIG(MSG_STR_LD_DYNAMIC)) &&
1133 			    strcmp(optarg, MSG_ORIG(MSG_ARG_STATIC))) {
1134 				eprintf(ofl->ofl_lml, ERR_FATAL,
1135 				    MSG_INTL(MSG_ARG_ILLEGAL),
1136 				    MSG_ORIG(MSG_ARG_CB), optarg);
1137 				ofl->ofl_flags |= FLG_OF_FATAL;
1138 			}
1139 			break;
1140 
1141 		case 'G':
1142 			Gflag = TRUE;
1143 			break;
1144 
1145 		case 'L':
1146 			break;
1147 
1148 		case 'M':
1149 			if (list_appendc(&(ofl->ofl_maps), optarg) == 0)
1150 				return (S_ERROR);
1151 			break;
1152 
1153 		case 'N':
1154 			break;
1155 
1156 		case 'Q':
1157 			if ((optarg[0] == 'n') && (optarg[1] == '\0')) {
1158 				if (Qflag != SET_UNKNOWN)
1159 					eprintf(ofl->ofl_lml, ERR_WARNING,
1160 					    MSG_INTL(MSG_ARG_MTONCE),
1161 					    MSG_ORIG(MSG_ARG_CQ));
1162 				else
1163 					Qflag = SET_FALSE;
1164 			} else if ((optarg[0] == 'y') && (optarg[1] == '\0')) {
1165 				if (Qflag != SET_UNKNOWN)
1166 					eprintf(ofl->ofl_lml, ERR_WARNING,
1167 					    MSG_INTL(MSG_ARG_MTONCE),
1168 					    MSG_ORIG(MSG_ARG_CQ));
1169 				else
1170 					Qflag = SET_TRUE;
1171 			} else {
1172 				eprintf(ofl->ofl_lml, ERR_FATAL,
1173 				    MSG_INTL(MSG_ARG_ILLEGAL),
1174 				    MSG_ORIG(MSG_ARG_CQ), optarg);
1175 				ofl->ofl_flags |= FLG_OF_FATAL;
1176 			}
1177 			break;
1178 
1179 		case 'S':
1180 			if (list_appendc(&lib_support, optarg) == 0)
1181 				return (S_ERROR);
1182 			break;
1183 
1184 		case 'V':
1185 			if (!Vflag)
1186 				(void) fprintf(stderr, MSG_ORIG(MSG_STR_STRNL),
1187 				    ofl->ofl_sgsid);
1188 			Vflag = TRUE;
1189 			break;
1190 
1191 		case 'Y':
1192 			if (strncmp(optarg, MSG_ORIG(MSG_ARG_LCOM), 2) == 0) {
1193 				if (Llibdir)
1194 				    eprintf(ofl->ofl_lml, ERR_WARNING,
1195 					MSG_INTL(MSG_ARG_MTONCE),
1196 					MSG_ORIG(MSG_ARG_CYL));
1197 				else
1198 					Llibdir = optarg + 2;
1199 			} else if (strncmp(optarg,
1200 			    MSG_ORIG(MSG_ARG_UCOM), 2) == 0) {
1201 				if (Ulibdir)
1202 					eprintf(ofl->ofl_lml, ERR_WARNING,
1203 					    MSG_INTL(MSG_ARG_MTONCE),
1204 					    MSG_ORIG(MSG_ARG_CYU));
1205 				else
1206 					Ulibdir = optarg + 2;
1207 			} else if (strncmp(optarg,
1208 			    MSG_ORIG(MSG_ARG_PCOM), 2) == 0) {
1209 				if (Plibpath)
1210 					eprintf(ofl->ofl_lml, ERR_WARNING,
1211 					    MSG_INTL(MSG_ARG_MTONCE),
1212 					    MSG_ORIG(MSG_ARG_CYP));
1213 				else
1214 					Plibpath = optarg + 2;
1215 			} else {
1216 				eprintf(ofl->ofl_lml, ERR_FATAL,
1217 				    MSG_INTL(MSG_ARG_ILLEGAL),
1218 				    MSG_ORIG(MSG_ARG_CY), optarg);
1219 				ofl->ofl_flags |= FLG_OF_FATAL;
1220 			}
1221 			break;
1222 
1223 		case '?':
1224 			(*error)++;
1225 			break;
1226 
1227 		default:
1228 			break;
1229 		}
1230 	}
1231 	return (1);
1232 }
1233 
1234 /*
1235  * Parsing options pass2 for
1236  */
1237 static uintptr_t
1238 parseopt_pass2(Ofl_desc *ofl, int argc, char **argv)
1239 {
1240 	int	c;
1241 
1242 	while ((c = getopt(argc, argv, MSG_ORIG(MSG_STR_OPTIONS))) != -1) {
1243 		Ifl_desc	*ifl;
1244 		Sym_desc	*sdp;
1245 
1246 		DBG_CALL(Dbg_args_flags(ofl->ofl_lml, (optind - 1), c));
1247 		switch (c) {
1248 			case 'l':
1249 				if (ld_find_library(optarg, ofl) == S_ERROR)
1250 					return (S_ERROR);
1251 				break;
1252 			case 'B':
1253 				if (strcmp(optarg,
1254 				    MSG_ORIG(MSG_STR_LD_DYNAMIC)) == 0) {
1255 					if (ofl->ofl_flags & FLG_OF_DYNAMIC)
1256 						ofl->ofl_flags |=
1257 							FLG_OF_DYNLIBS;
1258 					else {
1259 						eprintf(ofl->ofl_lml, ERR_FATAL,
1260 						    MSG_INTL(MSG_ARG_INCOMP),
1261 						    MSG_ORIG(MSG_ARG_DN),
1262 						    MSG_ORIG(MSG_ARG_BDYNAMIC));
1263 						ofl->ofl_flags |= FLG_OF_FATAL;
1264 					}
1265 				} else if (strcmp(optarg,
1266 				    MSG_ORIG(MSG_ARG_STATIC)) == 0)
1267 					ofl->ofl_flags &= ~FLG_OF_DYNLIBS;
1268 				break;
1269 			case 'L':
1270 				if (ld_add_libdir(ofl, optarg) == S_ERROR)
1271 					return (S_ERROR);
1272 				break;
1273 			case 'N':
1274 				/*
1275 				 * Record DT_NEEDED string
1276 				 */
1277 				if (!(ofl->ofl_flags & FLG_OF_DYNAMIC)) {
1278 					eprintf(ofl->ofl_lml, ERR_FATAL,
1279 					    MSG_INTL(MSG_ARG_INCOMP),
1280 					    MSG_ORIG(MSG_ARG_DN),
1281 					    MSG_ORIG(MSG_ARG_CN));
1282 					ofl->ofl_flags |= FLG_OF_FATAL;
1283 				}
1284 				if (((ifl =
1285 				    libld_calloc(1, sizeof (Ifl_desc))) == 0) ||
1286 				    (list_appendc(&ofl->ofl_sos, ifl) == 0))
1287 					return (S_ERROR);
1288 
1289 				ifl->ifl_name = MSG_INTL(MSG_STR_COMMAND);
1290 				ifl->ifl_soname = optarg;
1291 				ifl->ifl_flags = (FLG_IF_NEEDSTR |
1292 				    FLG_IF_FILEREF | FLG_IF_DEPREQD);
1293 
1294 				break;
1295 			case 'D':
1296 				(void) dbg_setup(optarg, dbg_desc,
1297 				    &ofl->ofl_name, 2);
1298 				break;
1299 			case 'u':
1300 				if (ld_sym_add_u(optarg, ofl) ==
1301 				    (Sym_desc *)S_ERROR)
1302 					return (S_ERROR);
1303 				break;
1304 			case 'z':
1305 				if ((strncmp(optarg, MSG_ORIG(MSG_ARG_LD32),
1306 				    MSG_ARG_LD32_SIZE) == 0) ||
1307 				    (strncmp(optarg, MSG_ORIG(MSG_ARG_LD64),
1308 				    MSG_ARG_LD64_SIZE) == 0)) {
1309 					if (createargv(ofl, 0) == S_ERROR)
1310 						return (S_ERROR);
1311 				} else if (strcmp(optarg,
1312 				    MSG_ORIG(MSG_ARG_ALLEXTRT)) == 0) {
1313 					ofl->ofl_flags1 |= FLG_OF1_ALLEXRT;
1314 					ofl->ofl_flags1 &= ~FLG_OF1_WEAKEXT;
1315 				} else if (strcmp(optarg,
1316 				    MSG_ORIG(MSG_ARG_WEAKEXT)) == 0) {
1317 					ofl->ofl_flags1 |= FLG_OF1_WEAKEXT;
1318 					ofl->ofl_flags1 &= ~FLG_OF1_ALLEXRT;
1319 				} else if (strcmp(optarg,
1320 				    MSG_ORIG(MSG_ARG_DFLEXTRT)) == 0) {
1321 					ofl->ofl_flags1 &=
1322 					~(FLG_OF1_ALLEXRT | FLG_OF1_WEAKEXT);
1323 				} else if (strcmp(optarg,
1324 				    MSG_ORIG(MSG_ARG_DIRECT)) == 0) {
1325 					ofl->ofl_flags1 |= FLG_OF1_ZDIRECT;
1326 				} else if (strcmp(optarg,
1327 				    MSG_ORIG(MSG_ARG_NODIRECT)) == 0) {
1328 					ofl->ofl_flags1 &= ~FLG_OF1_ZDIRECT;
1329 					ofl->ofl_flags1 |= FLG_OF1_NDIRECT;
1330 				} else if (strcmp(optarg,
1331 				    MSG_ORIG(MSG_ARG_IGNORE)) == 0) {
1332 					ofl->ofl_flags1 |= FLG_OF1_IGNORE;
1333 				} else if (strcmp(optarg,
1334 				    MSG_ORIG(MSG_ARG_RECORD)) == 0) {
1335 					ofl->ofl_flags1 &= ~FLG_OF1_IGNORE;
1336 				} else if (strcmp(optarg,
1337 				    MSG_ORIG(MSG_ARG_LAZYLOAD)) == 0) {
1338 					ofl->ofl_flags1 |= FLG_OF1_LAZYLD;
1339 				} else if (strcmp(optarg,
1340 				    MSG_ORIG(MSG_ARG_NOLAZYLOAD)) == 0) {
1341 					ofl->ofl_flags1 &= ~ FLG_OF1_LAZYLD;
1342 				} else if (strcmp(optarg,
1343 				    MSG_ORIG(MSG_ARG_GROUPPERM)) == 0) {
1344 					ofl->ofl_flags1 |= FLG_OF1_GRPPRM;
1345 				} else if (strcmp(optarg,
1346 				    MSG_ORIG(MSG_ARG_NOGROUPPERM)) == 0) {
1347 					ofl->ofl_flags1 &= ~FLG_OF1_GRPPRM;
1348 				} else if (strncmp(optarg,
1349 				    MSG_ORIG(MSG_ARG_INITARRAY),
1350 				    MSG_ARG_INITARRAY_SIZE) == 0) {
1351 					if (((sdp = ld_sym_add_u(optarg +
1352 					    MSG_ARG_INITARRAY_SIZE, ofl)) ==
1353 					    (Sym_desc *)S_ERROR) ||
1354 					    (list_appendc(&ofl->ofl_initarray,
1355 					    sdp) == 0))
1356 						return (S_ERROR);
1357 				} else if (strncmp(optarg,
1358 				    MSG_ORIG(MSG_ARG_FINIARRAY),
1359 				    MSG_ARG_FINIARRAY_SIZE) == 0) {
1360 					if (((sdp = ld_sym_add_u(optarg +
1361 					    MSG_ARG_FINIARRAY_SIZE, ofl)) ==
1362 					    (Sym_desc *)S_ERROR) ||
1363 					    (list_appendc(&ofl->ofl_finiarray,
1364 					    sdp) == 0))
1365 						return (S_ERROR);
1366 				} else if (strncmp(optarg,
1367 				    MSG_ORIG(MSG_ARG_PREINITARRAY),
1368 				    MSG_ARG_PREINITARRAY_SIZE) == 0) {
1369 					if (((sdp = ld_sym_add_u(optarg +
1370 					    MSG_ARG_PREINITARRAY_SIZE, ofl)) ==
1371 					    (Sym_desc *)S_ERROR) ||
1372 					    (list_appendc(&ofl->ofl_preiarray,
1373 					    sdp) == 0))
1374 						return (S_ERROR);
1375 				} else if (strncmp(optarg,
1376 				    MSG_ORIG(MSG_ARG_RTLDINFO),
1377 				    MSG_ARG_RTLDINFO_SIZE) == 0) {
1378 					if (((sdp = ld_sym_add_u(optarg +
1379 					    MSG_ARG_RTLDINFO_SIZE, ofl)) ==
1380 					    (Sym_desc *)S_ERROR) ||
1381 					    (list_appendc(&ofl->ofl_rtldinfo,
1382 					    sdp) == 0))
1383 						return (S_ERROR);
1384 				} else if (strncmp(optarg,
1385 				    MSG_ORIG(MSG_ARG_DTRACE),
1386 				    MSG_ARG_DTRACE_SIZE) == 0) {
1387 					if ((sdp = ld_sym_add_u(optarg +
1388 					    MSG_ARG_DTRACE_SIZE, ofl)) ==
1389 					    (Sym_desc *)S_ERROR)
1390 						return (S_ERROR);
1391 					ofl->ofl_dtracesym = sdp;
1392 				}
1393 			default:
1394 				break;
1395 		}
1396 	}
1397 	return (1);
1398 }
1399 
1400 /*
1401  *
1402  * Pass 1 -- process_flags: collects all options and sets flags
1403  */
1404 static uintptr_t
1405 process_flags_com(Ofl_desc *ofl, int argc, char **argv, int *e)
1406 {
1407 	for (; optind < argc; optind++) {
1408 		/*
1409 		 * If we detect some more options return to getopt().
1410 		 * Checking argv[optind][1] against null prevents a forever
1411 		 * loop if an unadorned `-' argument is passed to us.
1412 		 */
1413 		while ((optind < argc) && (argv[optind][0] == '-')) {
1414 			if (argv[optind][1] != '\0') {
1415 				if (parseopt_pass1(ofl, argc, argv, e) ==
1416 				    S_ERROR)
1417 					return (S_ERROR);
1418 			} else if (++optind < argc)
1419 				continue;
1420 		}
1421 		if (optind >= argc)
1422 			break;
1423 		ofl->ofl_objscnt++;
1424 	}
1425 	return (1);
1426 }
1427 
1428 uintptr_t
1429 ld_process_flags(Ofl_desc *ofl, int argc, char **argv)
1430 {
1431 	int	error = 0;	/* Collect all argument errors before exit */
1432 
1433 	if (argc < 2) {
1434 		usage_mesg(FALSE);
1435 		return (S_ERROR);
1436 	}
1437 
1438 	/*
1439 	 * Option handling
1440 	 */
1441 	if (process_flags_com(ofl, argc, argv, &error) == S_ERROR)
1442 		return (S_ERROR);
1443 
1444 	/*
1445 	 * Having parsed everything, did we have any errors.
1446 	 */
1447 	if (error) {
1448 		usage_mesg(TRUE);
1449 		return (S_ERROR);
1450 	}
1451 
1452 	return (check_flags(ofl, argc));
1453 }
1454 
1455 /*
1456  * Pass 2 -- process_files: skips the flags collected in pass 1 and processes
1457  * files.
1458  */
1459 static uintptr_t
1460 process_files_com(Ofl_desc *ofl, int argc, char **argv)
1461 {
1462 	for (; optind < argc; optind++) {
1463 		int		fd;
1464 		Ifl_desc	*ifl;
1465 		Rej_desc	rej = { 0 };
1466 
1467 		/*
1468 		 * If we detect some more options return to getopt().
1469 		 * Checking argv[optind][1] against null prevents a forever
1470 		 * loop if an unadorned `-' argument is passed to us.
1471 		 */
1472 		while ((optind < argc) && (argv[optind][0] == '-')) {
1473 			if (argv[optind][1] != '\0') {
1474 				if (parseopt_pass2(ofl, argc, argv) == S_ERROR)
1475 					return (S_ERROR);
1476 			} else if (++optind < argc)
1477 				continue;
1478 		}
1479 		if (optind >= argc)
1480 			break;
1481 
1482 		if ((fd = open(argv[optind], O_RDONLY)) == -1) {
1483 			int err = errno;
1484 
1485 			eprintf(ofl->ofl_lml, ERR_FATAL,
1486 			    MSG_INTL(MSG_SYS_OPEN), argv[optind],
1487 			    strerror(err));
1488 			ofl->ofl_flags |= FLG_OF_FATAL;
1489 			continue;
1490 		}
1491 
1492 		DBG_CALL(Dbg_args_files(ofl->ofl_lml, optind, argv[optind]));
1493 
1494 		ifl = ld_process_open(argv[optind], 0, fd, ofl,
1495 		    (FLG_IF_CMDLINE | FLG_IF_NEEDED), &rej);
1496 		(void) close(fd);
1497 		if (ifl == (Ifl_desc *)S_ERROR)
1498 			return (S_ERROR);
1499 
1500 		/*
1501 		 * Check for mismatched input.
1502 		 */
1503 		if (rej.rej_type) {
1504 			eprintf(ofl->ofl_lml, ERR_FATAL,
1505 			    MSG_INTL(reject[rej.rej_type]),
1506 			    rej.rej_name ? rej.rej_name :
1507 			    MSG_INTL(MSG_STR_UNKNOWN), conv_reject_desc(&rej));
1508 			ofl->ofl_flags |= FLG_OF_FATAL;
1509 			return (1);
1510 		}
1511 	}
1512 	return (1);
1513 }
1514 
1515 uintptr_t
1516 ld_process_files(Ofl_desc *ofl, int argc, char **argv)
1517 {
1518 	optind = 1;		/* reinitialize optind */
1519 
1520 	/*
1521 	 * Process command line files (taking into account any applicable
1522 	 * preseeding flags).  Return if any fatal errors have occurred.
1523 	 */
1524 	if (process_files_com(ofl, argc, argv) == S_ERROR)
1525 		return (S_ERROR);
1526 	if (ofl->ofl_flags & FLG_OF_FATAL)
1527 		return (1);
1528 
1529 	/*
1530 	 * Now that all command line files have been processed see if there are
1531 	 * any additional `needed' shared object dependencies.
1532 	 */
1533 	if (ofl->ofl_soneed.head)
1534 		if (ld_finish_libs(ofl) == S_ERROR)
1535 			return (S_ERROR);
1536 
1537 	/*
1538 	 * If rescanning archives is enabled, do so now to determine whether
1539 	 * there might still be members extracted to satisfy references from any
1540 	 * explicit objects.  Continue until no new objects are extracted.  Note
1541 	 * that this pass is carried out *after* processing any implicit objects
1542 	 * (above) as they may already have resolved any undefined references
1543 	 * from any explicit dependencies.
1544 	 */
1545 	if (ofl->ofl_flags1 & FLG_OF1_RESCAN)
1546 		ofl->ofl_flags1 |= FLG_OF1_EXTRACT;
1547 	while ((ofl->ofl_flags1 & (FLG_OF1_RESCAN | FLG_OF1_EXTRACT)) ==
1548 	    (FLG_OF1_RESCAN | FLG_OF1_EXTRACT)) {
1549 		Listnode	*lnp;
1550 		Ar_desc		*adp;
1551 
1552 		ofl->ofl_flags1 &= ~FLG_OF1_EXTRACT;
1553 
1554 		DBG_CALL(Dbg_file_ar_rescan(ofl->ofl_lml));
1555 
1556 		for (LIST_TRAVERSE(&ofl->ofl_ars, lnp, adp)) {
1557 			const char	*name = adp->ad_name;
1558 			uintptr_t	error;
1559 			int		fd;
1560 
1561 			/*
1562 			 * If this archive was processed with -z allextract,
1563 			 * then all members have already been extracted.
1564 			 */
1565 			if (adp->ad_elf == (Elf *)NULL)
1566 				continue;
1567 
1568 			/*
1569 			 * Reopen the file.
1570 			 */
1571 			if ((fd = open(name, O_RDONLY)) == -1) {
1572 				int err = errno;
1573 
1574 				eprintf(ofl->ofl_lml, ERR_FATAL,
1575 				    MSG_INTL(MSG_SYS_OPEN), name,
1576 				    strerror(err));
1577 				ofl->ofl_flags |= FLG_OF_FATAL;
1578 				return (S_ERROR);
1579 			}
1580 
1581 			/*
1582 			 * Reestablish any archive specific command line flags.
1583 			 */
1584 			ofl->ofl_flags1 &= ~MSK_OF1_ARCHIVE;
1585 			ofl->ofl_flags1 |= (adp->ad_flags & MSK_OF1_ARCHIVE);
1586 
1587 			error = ld_process_archive(adp->ad_name, fd, adp, ofl);
1588 			(void) close(fd);
1589 
1590 			if (error == S_ERROR)
1591 				return (S_ERROR);
1592 			if (ofl->ofl_flags & FLG_OF_FATAL)
1593 				return (1);
1594 		}
1595 	}
1596 
1597 	/*
1598 	 * If debugging, provide statistics on each archives extraction, or flag
1599 	 * any archive that has provided no members.  Note that this could be a
1600 	 * nice place to free up much of the archive infrastructure, as we've
1601 	 * extracted any members we need.  However, as we presently don't free
1602 	 * anything under ld(1) there's not much point in proceeding further.
1603 	 */
1604 	DBG_CALL(Dbg_statistics_ar(ofl));
1605 
1606 	/*
1607 	 * If any version definitions have been established, either via input
1608 	 * from a mapfile or from the input relocatable objects, make sure any
1609 	 * version dependencies are satisfied, and version symbols created.
1610 	 */
1611 	if (ofl->ofl_verdesc.head)
1612 		if (ld_vers_check_defs(ofl) == S_ERROR)
1613 			return (S_ERROR);
1614 
1615 	/*
1616 	 * If segment ordering was specified (using mapfile) verify things
1617 	 * are ok.
1618 	 */
1619 	if (ofl->ofl_flags & FLG_OF_SEGORDER)
1620 		ld_ent_check(ofl);
1621 
1622 	return (1);
1623 }
1624 
1625 uintptr_t
1626 ld_init_strings(Ofl_desc *ofl)
1627 {
1628 	uint_t	stflags;
1629 
1630 	if (ofl->ofl_flags1 & FLG_OF1_NCSTTAB)
1631 		stflags = 0;
1632 	else
1633 		stflags = FLG_STNEW_COMPRESS;
1634 
1635 	if (((ofl->ofl_shdrsttab = st_new(stflags)) == 0) ||
1636 	    ((ofl->ofl_strtab = st_new(stflags)) == 0) ||
1637 	    ((ofl->ofl_dynstrtab = st_new(stflags)) == 0))
1638 		return (S_ERROR);
1639 
1640 	return (0);
1641 }
1642