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