dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / sgs / libld / common / args.c
blob58e5907240e1bf767c7e8e6721358917b08d0deb
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright (c) 1988 AT&T
24 * All Rights Reserved
26 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
29 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
33 * Publicly available flags are defined in ld(1). The following flags are
34 * private, and may be removed at any time.
36 * OPTION MEANING
38 * -z dtrace=symbol assigns symbol to PT_SUNWDTRACE segment,
39 * providing scratch area for dtrace processing.
41 * -z noreloc suppress relocation processing. This provides
42 * a mechanism for validating kernel module symbol
43 * resolution that would normally incur fatal
44 * relocation errors.
46 * -z rtldinfo=symbol assigns symbol to SUNW_RTLDINF dynamic tag,
47 * providing pre-initialization specific routines
48 * for TLS initialization.
50 * -z nointerp suppress the addition of an interpreter
51 * section. This is used to generate the kernel,
52 * but makes no sense to be used by anyone else.
54 * -z norelaxreloc suppress the automatic addition of relaxed
55 * relocations to GNU linkonce/COMDAT sections.
57 * -z nosighandler suppress the registration of the signal handler
58 * used to manage SIGBUS.
62 * The following flags are committed, and will not be removed, but are
63 * not publically documented, either because they are obsolete, or because
64 * they exist to work around defects in other software and are not of
65 * sufficient interest otherwise.
67 * OPTION MEANING
69 * -Wl,... compiler drivers and configuration tools
70 * have been known to pass this compiler option
71 * to ld(1). Strip off the "-Wl," prefix and
72 * process the remainder (...) as a normal option.
75 #include <sys/link.h>
76 #include <stdio.h>
77 #include <fcntl.h>
78 #include <string.h>
79 #include <errno.h>
80 #include <elf.h>
81 #include <unistd.h>
82 #include <debug.h>
83 #include "msg.h"
84 #include "_libld.h"
87 * Define a set of local argument flags, the settings of these will be
88 * verified in check_flags() and lead to the appropriate output file flags
89 * being initialized.
91 typedef enum {
92 SET_UNKNOWN = -1,
93 SET_FALSE = 0,
94 SET_TRUE = 1
95 } Setstate;
97 static Setstate dflag = SET_UNKNOWN;
98 static Setstate zdflag = SET_UNKNOWN;
99 static Setstate Qflag = SET_UNKNOWN;
100 static Setstate Bdflag = SET_UNKNOWN;
101 static Setstate zfwflag = SET_UNKNOWN;
103 static Boolean aflag = FALSE;
104 static Boolean bflag = FALSE;
105 static Boolean sflag = FALSE;
106 static Boolean zinflag = FALSE;
107 static Boolean zlflag = FALSE;
108 static Boolean Bgflag = FALSE;
109 static Boolean Blflag = FALSE;
110 static Boolean Beflag = FALSE;
111 static Boolean Bsflag = FALSE;
112 static Boolean Dflag = FALSE;
113 static Boolean Vflag = FALSE;
115 enum output_type {
116 OT_RELOC,
117 OT_SHARED,
118 OT_EXEC,
119 OT_PIE,
122 static enum output_type otype = OT_EXEC;
125 * ztflag's state is set by pointing it to the matching string:
126 * text | textoff | textwarn
128 static const char *ztflag = NULL;
131 * Remember the guidance flags that result from the initial -z guidance
132 * option, so that they can be compared to any that follow. We only want
133 * to issue a warning when they differ.
135 static ofl_guideflag_t initial_guidance_flags = 0;
137 static uintptr_t process_files_com(Ofl_desc *, int, char **);
138 static uintptr_t process_flags_com(Ofl_desc *, int, char **, int *);
141 * Print usage message to stderr - 2 modes, summary message only,
142 * and full usage message.
144 static void
145 usage_mesg(Boolean detail)
147 (void) fprintf(stderr, MSG_INTL(MSG_ARG_USAGE),
148 MSG_ORIG(MSG_STR_OPTIONS));
150 if (detail == FALSE)
151 return;
153 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_3));
154 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_6));
155 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_A));
156 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_B));
157 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBDR));
158 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBDY));
159 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBE));
160 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBG));
161 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBL));
162 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBR));
163 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBS));
164 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_C));
165 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CC));
166 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_D));
167 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CD));
168 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_E));
169 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_F));
170 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CF));
171 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CG));
172 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_H));
173 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_I));
174 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CI));
175 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_L));
176 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CL));
177 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_M));
178 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CM));
179 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CN));
180 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_O));
181 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_P));
182 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CP));
183 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CQ));
184 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_R));
185 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CR));
186 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_S));
187 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CS));
188 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_T));
189 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_U));
190 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CV));
191 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CY));
192 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZA));
193 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZAE));
194 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZAL));
195 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZADLIB));
196 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZC));
197 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZDEF));
198 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZDFS));
199 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZDRS));
200 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZE));
201 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZFATW));
202 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZFA));
203 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZGP));
204 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZGUIDE));
205 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZH));
206 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZIG));
207 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZINA));
208 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZINI));
209 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZINT));
210 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZLAZY));
211 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZLD32));
212 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZLD64));
213 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZLO));
214 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZM));
215 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNC));
216 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNDFS));
217 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNDEF));
218 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNDEL));
219 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNDLO));
220 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNDU));
221 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNLD));
222 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNOW));
223 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNPA));
224 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNV));
225 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZO));
226 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZPIA));
227 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZRL));
228 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZRREL));
229 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZRS));
230 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZRSN));
231 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZRSGRP));
232 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZSCAP));
233 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZTARG));
234 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZT));
235 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZTO));
236 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZTW));
237 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZTY));
238 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZWRAP));
239 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZVER));
243 * Rescan the archives seen on the command line in order
244 * to handle circularly dependent archives, stopping when
245 * no further member extraction occurs.
247 * entry:
248 * ofl - Output file descriptor
249 * isgrp - True if this is a an archive group search, False
250 * to search starting with argv[1] through end_arg_ndx
251 * end_arg_ndx - Index of final argv element to consider.
253 static uintptr_t
254 ld_rescan_archives(Ofl_desc *ofl, int isgrp, int end_arg_ndx)
256 ofl->ofl_flags1 |= FLG_OF1_EXTRACT;
258 while (ofl->ofl_flags1 & FLG_OF1_EXTRACT) {
259 Aliste idx;
260 Ar_desc *adp;
261 Word start_ndx = isgrp ? ofl->ofl_ars_gsndx : 0;
262 Word ndx = 0;
264 ofl->ofl_flags1 &= ~FLG_OF1_EXTRACT;
266 DBG_CALL(Dbg_file_ar_rescan(ofl->ofl_lml,
267 isgrp ? ofl->ofl_ars_gsandx : 1, end_arg_ndx));
269 for (APLIST_TRAVERSE(ofl->ofl_ars, idx, adp)) {
270 /* If not to starting index yet, skip it */
271 if (ndx++ < start_ndx)
272 continue;
275 * If this archive was processed with -z allextract,
276 * then all members have already been extracted.
278 if (adp->ad_elf == NULL)
279 continue;
282 * Reestablish any archive specific command line flags.
284 ofl->ofl_flags1 &= ~MSK_OF1_ARCHIVE;
285 ofl->ofl_flags1 |= (adp->ad_flags & MSK_OF1_ARCHIVE);
288 * Re-process the archive. Note that a file descriptor
289 * is unnecessary, as the file is already available in
290 * memory.
292 if (!ld_process_archive(adp->ad_name, -1, adp, ofl))
293 return (S_ERROR);
294 if (ofl->ofl_flags & FLG_OF_FATAL)
295 return (1);
299 return (1);
303 * Checks the command line option flags for consistency.
305 static uintptr_t
306 check_flags(Ofl_desc * ofl, int argc)
309 * If the user specified -zguidance=noall, then we can safely disable
310 * the entire feature. The purpose of -zguidance=noall is to allow
311 * the user to override guidance specified from a makefile via
312 * the LD_OPTIONS environment variable, and so, we want to behave
313 * in exactly the same manner we would have if no option were present.
315 if ((ofl->ofl_guideflags & (FLG_OFG_ENABLE | FLG_OFG_NO_ALL)) ==
316 (FLG_OFG_ENABLE | FLG_OFG_NO_ALL))
317 ofl->ofl_guideflags &= ~FLG_OFG_ENABLE;
319 if (Plibpath && (Llibdir || Ulibdir))
320 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_YP),
321 Llibdir ? 'L' : 'U');
323 if (otype == OT_RELOC) {
324 if (dflag == SET_UNKNOWN)
325 dflag = SET_FALSE;
327 * Combining relocations when building a relocatable
328 * object isn't allowed. Warn the user, but proceed.
330 if (ofl->ofl_flags & FLG_OF_COMREL)
331 ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_MARG_INCOMP),
332 MSG_INTL(MSG_MARG_REL),
333 MSG_ORIG(MSG_ARG_ZCOMBRELOC));
334 ofl->ofl_flags |= FLG_OF_RELOBJ;
335 } else {
337 * Translating object capabilities to symbol capabilities is
338 * only meaningful when creating a relocatable object.
340 if (ofl->ofl_flags & FLG_OF_OTOSCAP)
341 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_MARG_ONLY),
342 MSG_ORIG(MSG_ARG_ZSYMBOLCAP),
343 MSG_INTL(MSG_MARG_REL));
346 * If the user hasn't explicitly requested that relocations
347 * not be combined, combine them by default.
349 if ((ofl->ofl_flags & FLG_OF_NOCOMREL) == 0)
350 ofl->ofl_flags |= FLG_OF_COMREL;
353 if (zdflag == SET_TRUE)
354 ofl->ofl_flags |= FLG_OF_NOUNDEF;
356 if (zinflag)
357 ofl->ofl_dtflags_1 |= DF_1_INTERPOSE;
359 if (sflag)
360 ofl->ofl_flags |= FLG_OF_STRIP;
362 if (Qflag == SET_TRUE)
363 ofl->ofl_flags |= FLG_OF_ADDVERS;
365 if (Blflag)
366 ofl->ofl_flags |= FLG_OF_AUTOLCL;
368 if (Beflag)
369 ofl->ofl_flags |= FLG_OF_AUTOELM;
371 if (Blflag && Beflag)
372 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_INCOMP),
373 MSG_ORIG(MSG_ARG_BELIMINATE), MSG_ORIG(MSG_ARG_BLOCAL));
375 if (ofl->ofl_interp && (ofl->ofl_flags1 & FLG_OF1_NOINTRP))
376 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_INCOMP),
377 MSG_ORIG(MSG_ARG_CI), MSG_ORIG(MSG_ARG_ZNOINTERP));
379 if ((ofl->ofl_flags1 & (FLG_OF1_NRLXREL | FLG_OF1_RLXREL)) ==
380 (FLG_OF1_NRLXREL | FLG_OF1_RLXREL))
381 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_INCOMP),
382 MSG_ORIG(MSG_ARG_ZRELAXRELOC),
383 MSG_ORIG(MSG_ARG_ZNORELAXRELOC));
385 if (ofl->ofl_filtees && (otype != OT_SHARED))
386 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_MARG_ST_ONLYAVL),
387 ((ofl->ofl_flags & FLG_OF_AUX) ?
388 MSG_INTL(MSG_MARG_FILTER_AUX) : MSG_INTL(MSG_MARG_FILTER)));
390 if (dflag != SET_FALSE) {
392 * Set -Bdynamic on by default, setting is rechecked as input
393 * files are processed.
395 ofl->ofl_flags |=
396 (FLG_OF_DYNAMIC | FLG_OF_DYNLIBS | FLG_OF_PROCRED);
398 if (aflag)
399 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_INCOMP),
400 MSG_ORIG(MSG_ARG_DY), MSG_ORIG(MSG_ARG_A));
402 if (bflag)
403 ofl->ofl_flags |= FLG_OF_BFLAG;
405 if (Bgflag == TRUE) {
406 if (zdflag == SET_FALSE)
407 ld_eprintf(ofl, ERR_FATAL,
408 MSG_INTL(MSG_ARG_INCOMP),
409 MSG_ORIG(MSG_ARG_BGROUP),
410 MSG_ORIG(MSG_ARG_ZNODEF));
411 ofl->ofl_dtflags_1 |= DF_1_GROUP;
412 ofl->ofl_flags |= FLG_OF_NOUNDEF;
416 * If the use of default library searching has been suppressed
417 * but no runpaths have been provided we're going to have a hard
418 * job running this object.
420 if ((ofl->ofl_dtflags_1 & DF_1_NODEFLIB) && !ofl->ofl_rpath)
421 ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_ARG_NODEFLIB),
422 MSG_INTL(MSG_MARG_RPATH));
425 * By default, text relocation warnings are given when building
426 * an executable unless the -b flag is specified. This option
427 * implies that unclean text can be created, so no warnings are
428 * generated unless specifically asked for.
430 if ((ztflag == MSG_ORIG(MSG_ARG_ZTEXTOFF)) ||
431 ((ztflag == NULL) && bflag)) {
432 ofl->ofl_flags1 |= FLG_OF1_TEXTOFF;
433 ofl->ofl_guideflags |= FLG_OFG_NO_TEXT;
434 } else if (ztflag == MSG_ORIG(MSG_ARG_ZTEXT)) {
435 ofl->ofl_flags |= FLG_OF_PURETXT;
436 ofl->ofl_guideflags |= FLG_OFG_NO_TEXT;
439 if ((otype == OT_SHARED) || (otype == OT_EXEC) ||
440 (otype == OT_PIE)) {
442 * Create a dynamic object. -Bdirect indicates that all
443 * references should be bound directly. This also
444 * enables lazyloading. Individual symbols can be
445 * bound directly (or not) using mapfiles and the
446 * DIRECT (NODIRECT) qualifier. With this capability,
447 * each syminfo entry is tagged SYMINFO_FLG_DIRECTBIND.
448 * Prior to this per-symbol direct binding, runtime
449 * direct binding was controlled via the DF_1_DIRECT
450 * flag. This flag affected all references from the
451 * object. -Bdirect continues to set this flag, and
452 * thus provides a means of taking a newly built
453 * direct binding object back to older systems.
455 * NOTE, any use of per-symbol NODIRECT bindings, or
456 * -znodirect, will disable the creation of the
457 * DF_1_DIRECT flag. Older runtime linkers do not
458 * have the capability to do per-symbol direct bindings.
460 if (Bdflag == SET_TRUE) {
461 ofl->ofl_dtflags_1 |= DF_1_DIRECT;
462 ofl->ofl_flags1 |= FLG_OF1_LAZYLD;
463 ofl->ofl_guideflags |= FLG_OFG_NO_LAZY;
464 ofl->ofl_flags |= FLG_OF_SYMINFO;
468 * -Bnodirect disables directly binding to any symbols
469 * exported from the object being created. Individual
470 * references to external objects can still be affected
471 * by -zdirect or mapfile DIRECT directives.
473 if (Bdflag == SET_FALSE) {
474 ofl->ofl_flags1 |= (FLG_OF1_NDIRECT |
475 FLG_OF1_NGLBDIR | FLG_OF1_ALNODIR);
476 ofl->ofl_flags |= FLG_OF_SYMINFO;
480 if (otype == OT_EXEC) {
482 * Dynamically linked executable.
484 ofl->ofl_flags |= FLG_OF_EXEC;
486 if (zdflag != SET_FALSE)
487 ofl->ofl_flags |= FLG_OF_NOUNDEF;
490 * -z textwarn is the default for executables, and
491 * only an explicit -z text* option can change that,
492 * so there's no need to provide additional guidance.
494 ofl->ofl_guideflags |= FLG_OFG_NO_TEXT;
496 if (Bsflag)
497 ld_eprintf(ofl, ERR_FATAL,
498 MSG_INTL(MSG_ARG_DY_INCOMP),
499 MSG_ORIG(MSG_ARG_BSYMBOLIC));
500 if (ofl->ofl_soname)
501 ld_eprintf(ofl, ERR_FATAL,
502 MSG_INTL(MSG_MARG_DY_INCOMP),
503 MSG_INTL(MSG_MARG_SONAME));
504 } else if ((otype == OT_SHARED) || (otype == OT_PIE)) {
506 * Shared Object.
508 if (otype == OT_PIE) {
509 ofl->ofl_flags |= FLG_OF_PIE;
510 } else {
511 ofl->ofl_flags |= FLG_OF_SHAROBJ;
514 * By default, print text relocation warnings
515 * for executables but *not* for shared
516 * objects. However, if -z guidance is on,
517 * issue warnings for shared objects as well.
519 * If -z textwarn is explicitly specified,
520 * also issue guidance messages if -z guidance
521 * is on, but not for -z text or -z textoff.
523 if (ztflag == NULL) {
524 if (!OFL_GUIDANCE(ofl, FLG_OFG_NO_TEXT))
525 ofl->ofl_flags1 |=
526 FLG_OF1_TEXTOFF;
527 } else if ((ofl->ofl_flags & FLG_OF_PURETXT) ||
528 (ofl->ofl_flags1 & FLG_OF1_TEXTOFF)) {
529 ofl->ofl_guideflags |= FLG_OFG_NO_TEXT;
533 if (Bsflag) {
535 * -Bsymbolic, and -Bnodirect make no sense.
537 if (Bdflag == SET_FALSE)
538 ld_eprintf(ofl, ERR_FATAL,
539 MSG_INTL(MSG_ARG_INCOMP),
540 MSG_ORIG(MSG_ARG_BSYMBOLIC),
541 MSG_ORIG(MSG_ARG_BNODIRECT));
542 ofl->ofl_flags |= FLG_OF_SYMBOLIC;
543 ofl->ofl_dtflags |= DF_SYMBOLIC;
545 } else {
547 * Dynamic relocatable object.
549 if (ztflag == NULL)
550 ofl->ofl_flags1 |= FLG_OF1_TEXTOFF;
551 ofl->ofl_guideflags |= FLG_OFG_NO_TEXT;
553 if (ofl->ofl_interp)
554 ld_eprintf(ofl, ERR_FATAL,
555 MSG_INTL(MSG_MARG_INCOMP),
556 MSG_INTL(MSG_MARG_REL),
557 MSG_ORIG(MSG_ARG_CI));
560 assert((ofl->ofl_flags & (FLG_OF_SHAROBJ|FLG_OF_PIE)) !=
561 (FLG_OF_SHAROBJ|FLG_OF_PIE));
562 assert((ofl->ofl_flags & (FLG_OF_SHAROBJ|FLG_OF_EXEC)) !=
563 (FLG_OF_SHAROBJ|FLG_OF_EXEC));
564 assert((ofl->ofl_flags & (FLG_OF_EXEC|FLG_OF_PIE)) !=
565 (FLG_OF_EXEC|FLG_OF_PIE));
566 } else {
567 ofl->ofl_flags |= FLG_OF_STATIC;
569 if (bflag)
570 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_ST_INCOMP),
571 MSG_ORIG(MSG_ARG_B));
572 if (ofl->ofl_soname)
573 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_MARG_ST_INCOMP),
574 MSG_INTL(MSG_MARG_SONAME));
575 if (ofl->ofl_depaudit)
576 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_ST_INCOMP),
577 MSG_ORIG(MSG_ARG_CP));
578 if (ofl->ofl_audit)
579 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_ST_INCOMP),
580 MSG_ORIG(MSG_ARG_P));
581 if (ofl->ofl_config)
582 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_ST_INCOMP),
583 MSG_ORIG(MSG_ARG_C));
584 if (ztflag)
585 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_ST_INCOMP),
586 MSG_ORIG(MSG_ARG_ZTEXTALL));
587 if ((otype == OT_SHARED) || (otype == OT_PIE))
588 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_MARG_ST_INCOMP),
589 MSG_INTL(MSG_MARG_SO));
590 if (aflag && (otype == OT_RELOC))
591 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_MARG_INCOMP),
592 MSG_ORIG(MSG_ARG_A), MSG_INTL(MSG_MARG_REL));
594 if (otype == OT_RELOC) {
596 * We can only strip the symbol table and string table
597 * if no output relocations will refer to them.
599 if (sflag)
600 ld_eprintf(ofl, ERR_WARNING,
601 MSG_INTL(MSG_ARG_STRIP),
602 MSG_INTL(MSG_MARG_REL),
603 MSG_INTL(MSG_MARG_STRIP));
605 if (ztflag == NULL)
606 ofl->ofl_flags1 |= FLG_OF1_TEXTOFF;
607 ofl->ofl_guideflags |= FLG_OFG_NO_TEXT;
609 if (ofl->ofl_interp)
610 ld_eprintf(ofl, ERR_FATAL,
611 MSG_INTL(MSG_MARG_INCOMP),
612 MSG_INTL(MSG_MARG_REL),
613 MSG_ORIG(MSG_ARG_CI));
614 } else {
616 * Static executable.
618 ofl->ofl_flags |= FLG_OF_EXEC | FLG_OF_PROCRED;
620 if (zdflag != SET_FALSE)
621 ofl->ofl_flags |= FLG_OF_NOUNDEF;
626 * If the user didn't supply an output file name supply a default.
628 if (ofl->ofl_name == NULL)
629 ofl->ofl_name = MSG_ORIG(MSG_STR_AOUT);
632 * We set the entrance criteria after all input argument processing as
633 * it is only at this point we're sure what the output image will be
634 * (static or dynamic).
636 if (ld_ent_setup(ofl, ld_targ.t_m.m_segm_align) == S_ERROR)
637 return (S_ERROR);
640 * Does the host currently running the linker have the same
641 * byte order as the target for which the object is being produced?
642 * If not, set FLG_OF1_ENCDIFF so relocation code will know
643 * to check.
645 if (_elf_sys_encoding() != ld_targ.t_m.m_data)
646 ofl->ofl_flags1 |= FLG_OF1_ENCDIFF;
649 * If the target has special executable section filling requirements,
650 * register the fill function with libelf
652 if (ld_targ.t_ff.ff_execfill != NULL)
653 _elf_execfill(ld_targ.t_ff.ff_execfill);
656 * Initialize string tables. Symbol definitions within mapfiles can
657 * result in the creation of input sections.
659 if (ld_init_strings(ofl) == S_ERROR)
660 return (S_ERROR);
663 * Process mapfiles. Mapfile can redefine or add sections/segments,
664 * so this must come after the default entrance criteria are established
665 * (above).
667 if (ofl->ofl_maps) {
668 const char *name;
669 Aliste idx;
671 for (APLIST_TRAVERSE(ofl->ofl_maps, idx, name))
672 if (!ld_map_parse(name, ofl))
673 return (S_ERROR);
675 if (!ld_map_post_process(ofl))
676 return (S_ERROR);
680 * If a mapfile has been used to define a single symbolic scope of
681 * interfaces, -Bsymbolic is established. This global setting goes
682 * beyond individual symbol protection, and ensures all relocations
683 * (even those that reference section symbols) are processed within
684 * the object being built.
686 if (((ofl->ofl_flags &
687 (FLG_OF_MAPSYMB | FLG_OF_MAPGLOB)) == FLG_OF_MAPSYMB) &&
688 (ofl->ofl_flags & (FLG_OF_AUTOLCL | FLG_OF_AUTOELM))) {
689 ofl->ofl_flags |= FLG_OF_SYMBOLIC;
690 ofl->ofl_dtflags |= DF_SYMBOLIC;
694 * If -zloadfltr is set, verify that filtering is in effect. Filters
695 * are either established from the command line, and affect the whole
696 * object, or are set on a per-symbol basis from a mapfile.
698 if (zlflag) {
699 if ((ofl->ofl_filtees == NULL) && (ofl->ofl_dtsfltrs == NULL))
700 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_NOFLTR),
701 MSG_ORIG(MSG_ARG_ZLOADFLTR));
702 ofl->ofl_dtflags_1 |= DF_1_LOADFLTR;
706 * Check that we have something to work with. This check is carried out
707 * after mapfile processing as its possible a mapfile is being used to
708 * define symbols, in which case it would be sufficient to build the
709 * output file purely from the mapfile.
711 if ((ofl->ofl_objscnt == 0) && (ofl->ofl_soscnt == 0)) {
712 if ((Vflag ||
713 (Dflag && (dbg_desc->d_extra & DBG_E_HELP_EXIT))) &&
714 (argc == 2)) {
715 ofl->ofl_flags1 |= FLG_OF1_DONE;
716 } else {
717 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_NOFILES));
718 return (S_ERROR);
721 return (1);
725 * Decompose the string pointed by optarg into argv[][] so that argv[][] can be
726 * used as an argument to getopt().
728 * If the second argument 'usage' is not NULL, then this is called from the
729 * first pass. Else this is called from the second pass.
731 static uintptr_t
732 createargv(Ofl_desc *ofl, int *usage)
734 int argc = 0, idx = 0, ooptind;
735 uintptr_t ret;
736 char **argv, *p0;
739 * The argument being examined is either:
740 * ld32= or
741 * ld64=
743 #if defined(_LP64)
744 if (optarg[2] == '3')
745 return (0);
746 #else
747 if (optarg[2] == '6')
748 return (0);
749 #endif
751 p0 = &optarg[5];
754 * Count the number of arguments.
756 while (*p0) {
758 * Pointing at non-separator character.
760 if (*p0 != ',') {
761 argc++;
762 while (*p0 && (*p0 != ','))
763 p0++;
764 continue;
768 * Pointing at a separator character.
770 if (*p0 == ',') {
771 while (*p0 == ',')
772 p0++;
773 continue;
777 if (argc == 0)
778 return (0);
781 * Allocate argument vector.
783 if ((p0 = (char *)strdup(&optarg[5])) == NULL)
784 return (S_ERROR);
785 if ((argv = libld_malloc((sizeof (char *)) * (argc + 1))) == NULL)
786 return (S_ERROR);
788 while (*p0) {
789 char *p;
792 * Pointing at the beginning of non-separator character string.
794 if (*p0 != ',') {
795 p = p0;
796 while (*p0 && (*p0 != ','))
797 p0++;
798 argv[idx++] = p;
799 if (*p0) {
800 *p0 = '\0';
801 p0++;
803 continue;
807 * Pointing at the beginining of separator character string.
809 if (*p0 == ',') {
810 while (*p0 == ',')
811 p0++;
812 continue;
815 argv[idx] = 0;
816 ooptind = optind;
817 optind = 0;
820 * Dispatch to pass1 or pass2
822 if (usage)
823 ret = process_flags_com(ofl, argc, argv, usage);
824 else
825 ret = process_files_com(ofl, argc, argv);
827 optind = ooptind;
828 return (ret);
832 * Parse the items in a '-z guidance' value, and set the ofl_guideflags.
833 * A guidance option looks like this:
835 * -z guidance[=item1,item2,...]
837 * Where each item specifies categories of guidance messages to suppress,
838 * each starting with the prefix 'no'. We allow arbitrary whitespace between
839 * the items, allow multiple ',' delimiters without an intervening item, and
840 * quietly ignore any items we don't recognize.
842 * - Such items are likely to be known to newer versions of the linker,
843 * and we do not want an older version of the linker to
844 * complain about them.
846 * - Times and standards can change, and so we wish to reserve the
847 * right to make an old item that no longer makes sense go away.
848 * Quietly ignoring unrecognized items facilitates this.
850 * However, we always display unrecognized items in debug output.
852 * entry:
853 * ofl - Output descriptor
854 * optarg - option string to be processed. This will either be a NULL
855 * terminated 'guidance', or it will be 'guidance=' followed
856 * by the item tokens as described above.
858 * exit:
859 * Returns TRUE (1) on success, FALSE (0) on failure.
862 static Boolean
863 guidance_parse(Ofl_desc *ofl, char *optarg)
865 typedef struct {
866 const char *name;
867 ofl_guideflag_t flag;
868 } item_desc;
870 static item_desc items[] = {
871 { MSG_ORIG(MSG_ARG_GUIDE_NO_ALL), FLG_OFG_NO_ALL },
873 { MSG_ORIG(MSG_ARG_GUIDE_NO_DEFS), FLG_OFG_NO_DEFS },
874 { MSG_ORIG(MSG_ARG_GUIDE_NO_DIRECT), FLG_OFG_NO_DB },
875 { MSG_ORIG(MSG_ARG_GUIDE_NO_LAZYLOAD), FLG_OFG_NO_LAZY },
876 { MSG_ORIG(MSG_ARG_GUIDE_NO_MAPFILE), FLG_OFG_NO_MF },
877 { MSG_ORIG(MSG_ARG_GUIDE_NO_TEXT), FLG_OFG_NO_TEXT },
878 { MSG_ORIG(MSG_ARG_GUIDE_NO_UNUSED), FLG_OFG_NO_UNUSED },
879 { NULL, 0 }
882 char *lasts, *name;
883 item_desc *item;
884 ofl_guideflag_t ofl_guideflags = FLG_OFG_ENABLE;
887 * Skip the 'guidance' prefix. If NULL terminated, there are no
888 * item values to parse. Otherwise, skip the '=' and parse the items.
890 optarg += MSG_ARG_GUIDE_SIZE;
891 if (*optarg == '=') {
892 optarg++;
894 if ((name = libld_malloc(strlen(optarg) + 1)) == NULL)
895 return (FALSE);
896 (void) strcpy(name, optarg);
898 if ((name = strtok_r(name, MSG_ORIG(MSG_ARG_GUIDE_DELIM),
899 &lasts)) != NULL) {
900 do {
901 for (item = items; item->name != NULL; item++)
902 if (strcasecmp(name, item->name) == 0)
903 break;
904 if (item->name == NULL) {
905 DBG_CALL(Dbg_args_guidance_unknown(
906 ofl->ofl_lml, name));
907 continue;
909 ofl_guideflags |= item->flag;
910 } while ((name = strtok_r(NULL,
911 MSG_ORIG(MSG_ARG_GUIDE_DELIM), &lasts)) != NULL);
916 * If -zguidance is used more than once, we take the first one. We
917 * do this quietly if they have identical options, and with a warning
918 * otherwise.
920 if ((initial_guidance_flags & FLG_OFG_ENABLE) &&
921 (ofl_guideflags != initial_guidance_flags)) {
922 ld_eprintf(ofl, ERR_WARNING_NF, MSG_INTL(MSG_ARG_MTONCE),
923 MSG_ORIG(MSG_ARG_ZGUIDE));
924 return (TRUE);
928 * First time: Save the flags for comparison to any subsequent
929 * -z guidance that comes along, and OR the resulting flags into
930 * the flags kept in the output descriptor.
932 initial_guidance_flags = ofl_guideflags;
933 ofl->ofl_guideflags |= ofl_guideflags;
934 return (TRUE);
938 * Parse the -z assert-deflib option. This option can appear in two different
939 * forms:
940 * -z assert-deflib
941 * -z assert-deflib=libfred.so
943 * Either form enables this option, the latter form marks libfred.so as an
944 * exempt library from the check. It is valid to have multiple invocations of
945 * the second form. We silently ignore mulitple occurrences of the first form
946 * and multiple invocations of the first form when the second form also occurs.
948 * We only return false when we have an internal error, such as the failure of
949 * aplist_append. Every other time we return true, but we have the appropriate
950 * fatal flags set beacuse of the ld_eprintf.
952 static int
953 assdeflib_parse(Ofl_desc *ofl, char *optarg)
955 size_t olen, mlen;
956 ofl->ofl_flags |= FLG_OF_ADEFLIB;
958 olen = strlen(optarg);
959 /* Minimum size of assert-deflib=lib%s.so */
960 mlen = MSG_ARG_ASSDEFLIB_SIZE + 1 + MSG_STR_LIB_SIZE +
961 MSG_STR_SOEXT_SIZE;
962 if (olen > MSG_ARG_ASSDEFLIB_SIZE) {
963 if (optarg[MSG_ARG_ASSDEFLIB_SIZE] != '=') {
964 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_ILLEGAL),
965 MSG_ORIG(MSG_ARG_ASSDEFLIB), optarg);
966 return (TRUE);
969 if (strncmp(optarg + MSG_ARG_ASSDEFLIB_SIZE + 1,
970 MSG_ORIG(MSG_STR_LIB), MSG_STR_LIB_SIZE) != 0 ||
971 strcmp(optarg + olen - MSG_STR_SOEXT_SIZE,
972 MSG_ORIG(MSG_STR_SOEXT)) != 0 || olen <= mlen) {
973 ld_eprintf(ofl, ERR_FATAL,
974 MSG_INTL(MSG_ARG_ASSDEFLIB_MALFORMED), optarg);
975 return (TRUE);
978 if (aplist_append(&ofl->ofl_assdeflib, optarg +
979 MSG_ARG_ASSDEFLIB_SIZE + 1, AL_CNT_ASSDEFLIB) == NULL)
980 return (FALSE);
983 return (TRUE);
986 static int optitle = 0;
988 * Parsing options pass1 for process_flags().
990 static uintptr_t
991 parseopt_pass1(Ofl_desc *ofl, int argc, char **argv, int *usage)
993 int c, ndx = optind;
996 * The -32, -64 and -ztarget options are special, in that we validate
997 * them, but otherwise ignore them. libld.so (this code) is called
998 * from the ld front end program. ld has already examined the
999 * arguments to determine the output class and machine type of the
1000 * output object, as reflected in the version (32/64) of ld_main()
1001 * that was called and the value of the 'mach' argument passed.
1002 * By time execution reaches this point, these options have already
1003 * been seen and acted on.
1005 while ((c = ld_getopt(ofl->ofl_lml, ndx, argc, argv)) != -1) {
1007 switch (c) {
1008 case '3':
1009 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1012 * -32 is processed by ld to determine the output class.
1013 * Here we sanity check the option incase some other
1014 * -3* option is mistakenly passed to us.
1016 if (optarg[0] != '2')
1017 ld_eprintf(ofl, ERR_FATAL,
1018 MSG_INTL(MSG_ARG_ILLEGAL),
1019 MSG_ORIG(MSG_ARG_3), optarg);
1020 continue;
1022 case '6':
1023 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1026 * -64 is processed by ld to determine the output class.
1027 * Here we sanity check the option incase some other
1028 * -6* option is mistakenly passed to us.
1030 if (optarg[0] != '4')
1031 ld_eprintf(ofl, ERR_FATAL,
1032 MSG_INTL(MSG_ARG_ILLEGAL),
1033 MSG_ORIG(MSG_ARG_6), optarg);
1034 continue;
1036 case 'a':
1037 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL));
1038 aflag = TRUE;
1039 break;
1041 case 'b':
1042 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL));
1043 bflag = TRUE;
1046 * This is a hack, and may be undone later.
1047 * The -b option is only used to build the Unix
1048 * kernel and its related kernel-mode modules.
1049 * We do not want those files to get a .SUNW_ldynsym
1050 * section. At least for now, the kernel makes no
1051 * use of .SUNW_ldynsym, and we do not want to use
1052 * the space to hold it. Therefore, we overload
1053 * the use of -b to also imply -znoldynsym.
1055 ofl->ofl_flags |= FLG_OF_NOLDYNSYM;
1056 break;
1058 case 'c':
1059 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1060 if (ofl->ofl_config)
1061 ld_eprintf(ofl, ERR_WARNING_NF,
1062 MSG_INTL(MSG_ARG_MTONCE),
1063 MSG_ORIG(MSG_ARG_C));
1064 else
1065 ofl->ofl_config = optarg;
1066 break;
1068 case 'C':
1069 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL));
1070 demangle_flag = 1;
1071 break;
1073 case 'd':
1074 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1075 if ((optarg[0] == 'n') && (optarg[1] == '\0')) {
1076 if (dflag != SET_UNKNOWN)
1077 ld_eprintf(ofl, ERR_WARNING_NF,
1078 MSG_INTL(MSG_ARG_MTONCE),
1079 MSG_ORIG(MSG_ARG_D));
1080 else
1081 dflag = SET_FALSE;
1082 } else if ((optarg[0] == 'y') && (optarg[1] == '\0')) {
1083 if (dflag != SET_UNKNOWN)
1084 ld_eprintf(ofl, ERR_WARNING_NF,
1085 MSG_INTL(MSG_ARG_MTONCE),
1086 MSG_ORIG(MSG_ARG_D));
1087 else
1088 dflag = SET_TRUE;
1089 } else {
1090 ld_eprintf(ofl, ERR_FATAL,
1091 MSG_INTL(MSG_ARG_ILLEGAL),
1092 MSG_ORIG(MSG_ARG_D), optarg);
1094 break;
1096 case 'e':
1097 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1098 if (ofl->ofl_entry)
1099 ld_eprintf(ofl, ERR_WARNING_NF,
1100 MSG_INTL(MSG_MARG_MTONCE),
1101 MSG_INTL(MSG_MARG_ENTRY));
1102 else
1103 ofl->ofl_entry = (void *)optarg;
1104 break;
1106 case 'f':
1107 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1108 if (ofl->ofl_filtees &&
1109 (!(ofl->ofl_flags & FLG_OF_AUX))) {
1110 ld_eprintf(ofl, ERR_FATAL,
1111 MSG_INTL(MSG_MARG_INCOMP),
1112 MSG_INTL(MSG_MARG_FILTER_AUX),
1113 MSG_INTL(MSG_MARG_FILTER));
1114 } else {
1115 if ((ofl->ofl_filtees =
1116 add_string(ofl->ofl_filtees, optarg)) ==
1117 (const char *)S_ERROR)
1118 return (S_ERROR);
1119 ofl->ofl_flags |= FLG_OF_AUX;
1121 break;
1123 case 'F':
1124 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1125 if (ofl->ofl_filtees &&
1126 (ofl->ofl_flags & FLG_OF_AUX)) {
1127 ld_eprintf(ofl, ERR_FATAL,
1128 MSG_INTL(MSG_MARG_INCOMP),
1129 MSG_INTL(MSG_MARG_FILTER),
1130 MSG_INTL(MSG_MARG_FILTER_AUX));
1131 } else {
1132 if ((ofl->ofl_filtees =
1133 add_string(ofl->ofl_filtees, optarg)) ==
1134 (const char *)S_ERROR)
1135 return (S_ERROR);
1137 break;
1139 case 'h':
1140 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1141 if (ofl->ofl_soname)
1142 ld_eprintf(ofl, ERR_WARNING_NF,
1143 MSG_INTL(MSG_MARG_MTONCE),
1144 MSG_INTL(MSG_MARG_SONAME));
1145 else
1146 ofl->ofl_soname = (const char *)optarg;
1147 break;
1149 case 'i':
1150 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL));
1151 ofl->ofl_flags |= FLG_OF_IGNENV;
1152 break;
1154 case 'I':
1155 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1156 if (ofl->ofl_interp)
1157 ld_eprintf(ofl, ERR_WARNING_NF,
1158 MSG_INTL(MSG_ARG_MTONCE),
1159 MSG_ORIG(MSG_ARG_CI));
1160 else
1161 ofl->ofl_interp = (const char *)optarg;
1162 break;
1164 case 'l':
1165 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1167 * For now, count any library as a shared object. This
1168 * is used to size the internal symbol cache. This
1169 * value is recalculated later on actual file processing
1170 * to get an accurate shared object count.
1172 ofl->ofl_soscnt++;
1173 break;
1175 case 'm':
1176 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL));
1177 ofl->ofl_flags |= FLG_OF_GENMAP;
1178 break;
1180 case 'o':
1181 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1182 if (ofl->ofl_name)
1183 ld_eprintf(ofl, ERR_WARNING_NF,
1184 MSG_INTL(MSG_MARG_MTONCE),
1185 MSG_INTL(MSG_MARG_OUTFILE));
1186 else
1187 ofl->ofl_name = (const char *)optarg;
1188 break;
1190 case 'p':
1191 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1194 * Multiple instances of this option may occur. Each
1195 * additional instance is effectively concatenated to
1196 * the previous separated by a colon.
1198 if (*optarg != '\0') {
1199 if ((ofl->ofl_audit =
1200 add_string(ofl->ofl_audit,
1201 optarg)) == (const char *)S_ERROR)
1202 return (S_ERROR);
1204 break;
1206 case 'P':
1207 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1210 * Multiple instances of this option may occur. Each
1211 * additional instance is effectively concatenated to
1212 * the previous separated by a colon.
1214 if (*optarg != '\0') {
1215 if ((ofl->ofl_depaudit =
1216 add_string(ofl->ofl_depaudit,
1217 optarg)) == (const char *)S_ERROR)
1218 return (S_ERROR);
1220 break;
1222 case 'r':
1223 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL));
1224 otype = OT_RELOC;
1225 break;
1227 case 'R':
1228 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1231 * Multiple instances of this option may occur. Each
1232 * additional instance is effectively concatenated to
1233 * the previous separated by a colon.
1235 if (*optarg != '\0') {
1236 if ((ofl->ofl_rpath =
1237 add_string(ofl->ofl_rpath,
1238 optarg)) == (const char *)S_ERROR)
1239 return (S_ERROR);
1241 break;
1243 case 's':
1244 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL));
1245 sflag = TRUE;
1246 break;
1248 case 't':
1249 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL));
1250 ofl->ofl_flags |= FLG_OF_NOWARN;
1251 break;
1253 case 'u':
1254 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1255 break;
1257 case 'z':
1258 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1261 * For specific help, print our usage message and exit
1262 * immediately to ensure a 0 return code.
1264 if (strncmp(optarg, MSG_ORIG(MSG_ARG_HELP),
1265 MSG_ARG_HELP_SIZE) == 0) {
1266 usage_mesg(TRUE);
1267 exit(0);
1271 * For some options set a flag - further consistancy
1272 * checks will be carried out in check_flags().
1274 if ((strncmp(optarg, MSG_ORIG(MSG_ARG_LD32),
1275 MSG_ARG_LD32_SIZE) == 0) ||
1276 (strncmp(optarg, MSG_ORIG(MSG_ARG_LD64),
1277 MSG_ARG_LD64_SIZE) == 0)) {
1278 if (createargv(ofl, usage) == S_ERROR)
1279 return (S_ERROR);
1281 } else if (
1282 strcmp(optarg, MSG_ORIG(MSG_ARG_DEFS)) == 0) {
1283 if (zdflag != SET_UNKNOWN)
1284 ld_eprintf(ofl, ERR_WARNING_NF,
1285 MSG_INTL(MSG_ARG_MTONCE),
1286 MSG_ORIG(MSG_ARG_ZDEFNODEF));
1287 else
1288 zdflag = SET_TRUE;
1289 ofl->ofl_guideflags |= FLG_OFG_NO_DEFS;
1290 } else if (strcmp(optarg,
1291 MSG_ORIG(MSG_ARG_NODEFS)) == 0) {
1292 if (zdflag != SET_UNKNOWN)
1293 ld_eprintf(ofl, ERR_WARNING_NF,
1294 MSG_INTL(MSG_ARG_MTONCE),
1295 MSG_ORIG(MSG_ARG_ZDEFNODEF));
1296 else
1297 zdflag = SET_FALSE;
1298 ofl->ofl_guideflags |= FLG_OFG_NO_DEFS;
1299 } else if (strcmp(optarg,
1300 MSG_ORIG(MSG_ARG_TEXT)) == 0) {
1301 if (ztflag &&
1302 (ztflag != MSG_ORIG(MSG_ARG_ZTEXT)))
1303 ld_eprintf(ofl, ERR_FATAL,
1304 MSG_INTL(MSG_ARG_INCOMP),
1305 MSG_ORIG(MSG_ARG_ZTEXT),
1306 ztflag);
1307 ztflag = MSG_ORIG(MSG_ARG_ZTEXT);
1308 } else if (strcmp(optarg,
1309 MSG_ORIG(MSG_ARG_TEXTOFF)) == 0) {
1310 if (ztflag &&
1311 (ztflag != MSG_ORIG(MSG_ARG_ZTEXTOFF)))
1312 ld_eprintf(ofl, ERR_FATAL,
1313 MSG_INTL(MSG_ARG_INCOMP),
1314 MSG_ORIG(MSG_ARG_ZTEXTOFF),
1315 ztflag);
1316 ztflag = MSG_ORIG(MSG_ARG_ZTEXTOFF);
1317 } else if (strcmp(optarg,
1318 MSG_ORIG(MSG_ARG_TEXTWARN)) == 0) {
1319 if (ztflag &&
1320 (ztflag != MSG_ORIG(MSG_ARG_ZTEXTWARN)))
1321 ld_eprintf(ofl, ERR_FATAL,
1322 MSG_INTL(MSG_ARG_INCOMP),
1323 MSG_ORIG(MSG_ARG_ZTEXTWARN),
1324 ztflag);
1325 ztflag = MSG_ORIG(MSG_ARG_ZTEXTWARN);
1328 * For other options simply set the ofl flags directly.
1330 } else if (strcmp(optarg,
1331 MSG_ORIG(MSG_ARG_RESCAN)) == 0) {
1332 ofl->ofl_flags1 |= FLG_OF1_RESCAN;
1333 } else if (strcmp(optarg,
1334 MSG_ORIG(MSG_ARG_ABSEXEC)) == 0) {
1335 ofl->ofl_flags1 |= FLG_OF1_ABSEXEC;
1336 } else if (strcmp(optarg,
1337 MSG_ORIG(MSG_ARG_LOADFLTR)) == 0) {
1338 zlflag = TRUE;
1339 } else if (strcmp(optarg,
1340 MSG_ORIG(MSG_ARG_NORELOC)) == 0) {
1341 ofl->ofl_dtflags_1 |= DF_1_NORELOC;
1342 } else if (strcmp(optarg,
1343 MSG_ORIG(MSG_ARG_NOVERSION)) == 0) {
1344 ofl->ofl_flags |= FLG_OF_NOVERSEC;
1345 } else if (strcmp(optarg,
1346 MSG_ORIG(MSG_ARG_MULDEFS)) == 0) {
1347 ofl->ofl_flags |= FLG_OF_MULDEFS;
1348 } else if (strcmp(optarg,
1349 MSG_ORIG(MSG_ARG_REDLOCSYM)) == 0) {
1350 ofl->ofl_flags |= FLG_OF_REDLSYM;
1351 } else if (strcmp(optarg,
1352 MSG_ORIG(MSG_ARG_INITFIRST)) == 0) {
1353 ofl->ofl_dtflags_1 |= DF_1_INITFIRST;
1354 } else if (strcmp(optarg,
1355 MSG_ORIG(MSG_ARG_NODELETE)) == 0) {
1356 ofl->ofl_dtflags_1 |= DF_1_NODELETE;
1357 } else if (strcmp(optarg,
1358 MSG_ORIG(MSG_ARG_NOPARTIAL)) == 0) {
1359 ofl->ofl_flags1 |= FLG_OF1_NOPARTI;
1360 } else if (strcmp(optarg,
1361 MSG_ORIG(MSG_ARG_NOOPEN)) == 0) {
1362 ofl->ofl_dtflags_1 |= DF_1_NOOPEN;
1363 } else if (strcmp(optarg,
1364 MSG_ORIG(MSG_ARG_NOW)) == 0) {
1365 ofl->ofl_dtflags_1 |= DF_1_NOW;
1366 ofl->ofl_dtflags |= DF_BIND_NOW;
1367 } else if (strcmp(optarg,
1368 MSG_ORIG(MSG_ARG_ORIGIN)) == 0) {
1369 ofl->ofl_dtflags_1 |= DF_1_ORIGIN;
1370 ofl->ofl_dtflags |= DF_ORIGIN;
1371 } else if (strcmp(optarg,
1372 MSG_ORIG(MSG_ARG_NODEFAULTLIB)) == 0) {
1373 ofl->ofl_dtflags_1 |= DF_1_NODEFLIB;
1374 } else if (strcmp(optarg,
1375 MSG_ORIG(MSG_ARG_NODUMP)) == 0) {
1376 ofl->ofl_dtflags_1 |= DF_1_NODUMP;
1377 } else if (strcmp(optarg,
1378 MSG_ORIG(MSG_ARG_ENDFILTEE)) == 0) {
1379 ofl->ofl_dtflags_1 |= DF_1_ENDFILTEE;
1380 } else if (strcmp(optarg,
1381 MSG_ORIG(MSG_ARG_VERBOSE)) == 0) {
1382 ofl->ofl_flags |= FLG_OF_VERBOSE;
1383 } else if (strcmp(optarg,
1384 MSG_ORIG(MSG_ARG_COMBRELOC)) == 0) {
1385 ofl->ofl_flags |= FLG_OF_COMREL;
1386 } else if (strcmp(optarg,
1387 MSG_ORIG(MSG_ARG_NOCOMBRELOC)) == 0) {
1388 ofl->ofl_flags |= FLG_OF_NOCOMREL;
1389 } else if (strcmp(optarg,
1390 MSG_ORIG(MSG_ARG_NOCOMPSTRTAB)) == 0) {
1391 ofl->ofl_flags1 |= FLG_OF1_NCSTTAB;
1392 } else if (strcmp(optarg,
1393 MSG_ORIG(MSG_ARG_NOINTERP)) == 0) {
1394 ofl->ofl_flags1 |= FLG_OF1_NOINTRP;
1395 } else if (strcmp(optarg,
1396 MSG_ORIG(MSG_ARG_INTERPOSE)) == 0) {
1397 zinflag = TRUE;
1398 } else if (strcmp(optarg,
1399 MSG_ORIG(MSG_ARG_IGNORE)) == 0) {
1400 ofl->ofl_flags1 |= FLG_OF1_IGNPRC;
1401 } else if (strcmp(optarg,
1402 MSG_ORIG(MSG_ARG_RELAXRELOC)) == 0) {
1403 ofl->ofl_flags1 |= FLG_OF1_RLXREL;
1404 } else if (strcmp(optarg,
1405 MSG_ORIG(MSG_ARG_NORELAXRELOC)) == 0) {
1406 ofl->ofl_flags1 |= FLG_OF1_NRLXREL;
1407 } else if (strcmp(optarg,
1408 MSG_ORIG(MSG_ARG_NOLDYNSYM)) == 0) {
1409 ofl->ofl_flags |= FLG_OF_NOLDYNSYM;
1410 } else if (strcmp(optarg,
1411 MSG_ORIG(MSG_ARG_GLOBAUDIT)) == 0) {
1412 ofl->ofl_dtflags_1 |= DF_1_GLOBAUDIT;
1413 } else if (strcmp(optarg,
1414 MSG_ORIG(MSG_ARG_NOSIGHANDLER)) == 0) {
1415 ofl->ofl_flags1 |= FLG_OF1_NOSGHND;
1416 } else if (strcmp(optarg,
1417 MSG_ORIG(MSG_ARG_SYMBOLCAP)) == 0) {
1418 ofl->ofl_flags |= FLG_OF_OTOSCAP;
1421 * Check archive group usage
1422 * -z rescan-start ... -z rescan-end
1423 * to ensure they don't overlap and are well formed.
1425 } else if (strcmp(optarg,
1426 MSG_ORIG(MSG_ARG_RESCAN_START)) == 0) {
1427 if (ofl->ofl_ars_gsandx == 0) {
1428 ofl->ofl_ars_gsandx = ndx;
1429 } else if (ofl->ofl_ars_gsandx > 0) {
1430 /* Another group is still open */
1431 ld_eprintf(ofl, ERR_FATAL,
1432 MSG_INTL(MSG_ARG_AR_GRP_OLAP),
1433 MSG_INTL(MSG_MARG_AR_GRPS));
1434 /* Don't report cascading errors */
1435 ofl->ofl_ars_gsandx = -1;
1437 } else if (strcmp(optarg,
1438 MSG_ORIG(MSG_ARG_RESCAN_END)) == 0) {
1439 if (ofl->ofl_ars_gsandx > 0) {
1440 ofl->ofl_ars_gsandx = 0;
1441 } else if (ofl->ofl_ars_gsandx == 0) {
1442 /* There was no matching begin */
1443 ld_eprintf(ofl, ERR_FATAL,
1444 MSG_INTL(MSG_ARG_AR_GRP_BAD),
1445 MSG_INTL(MSG_MARG_AR_GRP_END),
1446 MSG_INTL(MSG_MARG_AR_GRP_START));
1447 /* Don't report cascading errors */
1448 ofl->ofl_ars_gsandx = -1;
1452 * If -z wrap is seen, enter the symbol to be wrapped
1453 * into the wrap AVL tree.
1455 } else if (strncmp(optarg, MSG_ORIG(MSG_ARG_WRAP),
1456 MSG_ARG_WRAP_SIZE) == 0) {
1457 if (ld_wrap_enter(ofl,
1458 optarg + MSG_ARG_WRAP_SIZE) == NULL)
1459 return (S_ERROR);
1460 } else if (strncmp(optarg, MSG_ORIG(MSG_ARG_ASLR),
1461 MSG_ARG_ASLR_SIZE) == 0) {
1462 char *p = optarg + MSG_ARG_ASLR_SIZE;
1463 if (*p == '\0') {
1464 ofl->ofl_aslr = 1;
1465 } else if (*p == '=') {
1466 p++;
1468 if ((strcmp(p,
1469 MSG_ORIG(MSG_ARG_ENABLED)) == 0) ||
1470 (strcmp(p,
1471 MSG_ORIG(MSG_ARG_ENABLE)) == 0)) {
1472 ofl->ofl_aslr = 1;
1473 } else if ((strcmp(p,
1474 MSG_ORIG(MSG_ARG_DISABLED)) == 0) ||
1475 (strcmp(p,
1476 MSG_ORIG(MSG_ARG_DISABLE)) == 0)) {
1477 ofl->ofl_aslr = -1;
1478 } else {
1479 ld_eprintf(ofl, ERR_FATAL,
1480 MSG_INTL(MSG_ARG_ILLEGAL),
1481 MSG_ORIG(MSG_ARG_ZASLR), p);
1482 return (S_ERROR);
1484 } else {
1485 ld_eprintf(ofl, ERR_FATAL,
1486 MSG_INTL(MSG_ARG_ILLEGAL),
1487 MSG_ORIG(MSG_ARG_Z), optarg);
1488 return (S_ERROR);
1490 } else if ((strncmp(optarg, MSG_ORIG(MSG_ARG_GUIDE),
1491 MSG_ARG_GUIDE_SIZE) == 0) &&
1492 ((optarg[MSG_ARG_GUIDE_SIZE] == '=') ||
1493 (optarg[MSG_ARG_GUIDE_SIZE] == '\0'))) {
1494 if (!guidance_parse(ofl, optarg))
1495 return (S_ERROR);
1496 } else if (strcmp(optarg,
1497 MSG_ORIG(MSG_ARG_FATWARN)) == 0) {
1498 if (zfwflag == SET_FALSE) {
1499 ld_eprintf(ofl, ERR_WARNING_NF,
1500 MSG_INTL(MSG_ARG_MTONCE),
1501 MSG_ORIG(MSG_ARG_ZFATWNOFATW));
1502 } else {
1503 zfwflag = SET_TRUE;
1504 ofl->ofl_flags |= FLG_OF_FATWARN;
1506 } else if (strcmp(optarg,
1507 MSG_ORIG(MSG_ARG_NOFATWARN)) == 0) {
1508 if (zfwflag == SET_TRUE)
1509 ld_eprintf(ofl, ERR_WARNING_NF,
1510 MSG_INTL(MSG_ARG_MTONCE),
1511 MSG_ORIG(MSG_ARG_ZFATWNOFATW));
1512 else
1513 zfwflag = SET_FALSE;
1516 * Process everything related to -z assert-deflib. This
1517 * must be done in pass 1 because it gets used in pass
1518 * 2.
1520 } else if (strncmp(optarg, MSG_ORIG(MSG_ARG_ASSDEFLIB),
1521 MSG_ARG_ASSDEFLIB_SIZE) == 0) {
1522 if (assdeflib_parse(ofl, optarg) != TRUE)
1523 return (S_ERROR);
1524 } else if (strncmp(optarg, MSG_ORIG(MSG_ARG_TYPE),
1525 MSG_ARG_TYPE_SIZE) == 0) {
1526 char *p = optarg + MSG_ARG_TYPE_SIZE;
1527 if (*p != '=') {
1528 ld_eprintf(ofl, ERR_FATAL,
1529 MSG_INTL(MSG_ARG_ILLEGAL),
1530 MSG_ORIG(MSG_ARG_Z), optarg);
1531 return (S_ERROR);
1534 p++;
1535 if (strcmp(p,
1536 MSG_ORIG(MSG_ARG_TYPE_RELOC)) == 0) {
1537 otype = OT_RELOC;
1538 } else if (strcmp(p,
1539 MSG_ORIG(MSG_ARG_TYPE_EXEC)) == 0) {
1540 otype = OT_EXEC;
1541 } else if (strcmp(p,
1542 MSG_ORIG(MSG_ARG_TYPE_SHARED)) == 0) {
1543 otype = OT_SHARED;
1544 } else if (strcmp(p,
1545 MSG_ORIG(MSG_ARG_TYPE_PIE)) == 0) {
1546 otype = OT_PIE;
1547 } else {
1548 ld_eprintf(ofl, ERR_FATAL,
1549 MSG_INTL(MSG_ARG_ILLEGAL),
1550 MSG_ORIG(MSG_ARG_Z), optarg);
1551 return (S_ERROR);
1554 * The following options just need validation as they
1555 * are interpreted on the second pass through the
1556 * command line arguments.
1558 } else if (
1559 strncmp(optarg, MSG_ORIG(MSG_ARG_INITARRAY),
1560 MSG_ARG_INITARRAY_SIZE) &&
1561 strncmp(optarg, MSG_ORIG(MSG_ARG_FINIARRAY),
1562 MSG_ARG_FINIARRAY_SIZE) &&
1563 strncmp(optarg, MSG_ORIG(MSG_ARG_PREINITARRAY),
1564 MSG_ARG_PREINITARRAY_SIZE) &&
1565 strncmp(optarg, MSG_ORIG(MSG_ARG_RTLDINFO),
1566 MSG_ARG_RTLDINFO_SIZE) &&
1567 strncmp(optarg, MSG_ORIG(MSG_ARG_DTRACE),
1568 MSG_ARG_DTRACE_SIZE) &&
1569 strcmp(optarg, MSG_ORIG(MSG_ARG_ALLEXTRT)) &&
1570 strcmp(optarg, MSG_ORIG(MSG_ARG_DFLEXTRT)) &&
1571 strcmp(optarg, MSG_ORIG(MSG_ARG_DIRECT)) &&
1572 strcmp(optarg, MSG_ORIG(MSG_ARG_NODIRECT)) &&
1573 strcmp(optarg, MSG_ORIG(MSG_ARG_GROUPPERM)) &&
1574 strcmp(optarg, MSG_ORIG(MSG_ARG_LAZYLOAD)) &&
1575 strcmp(optarg, MSG_ORIG(MSG_ARG_NOGROUPPERM)) &&
1576 strcmp(optarg, MSG_ORIG(MSG_ARG_NOLAZYLOAD)) &&
1577 strcmp(optarg, MSG_ORIG(MSG_ARG_NODEFERRED)) &&
1578 strcmp(optarg, MSG_ORIG(MSG_ARG_RECORD)) &&
1579 strcmp(optarg, MSG_ORIG(MSG_ARG_ALTEXEC64)) &&
1580 strcmp(optarg, MSG_ORIG(MSG_ARG_WEAKEXT)) &&
1581 strncmp(optarg, MSG_ORIG(MSG_ARG_TARGET),
1582 MSG_ARG_TARGET_SIZE) &&
1583 strcmp(optarg, MSG_ORIG(MSG_ARG_RESCAN_NOW)) &&
1584 strcmp(optarg, MSG_ORIG(MSG_ARG_DEFERRED))) {
1585 ld_eprintf(ofl, ERR_FATAL,
1586 MSG_INTL(MSG_ARG_ILLEGAL),
1587 MSG_ORIG(MSG_ARG_Z), optarg);
1590 break;
1592 case 'D':
1594 * If we have not yet read any input files go ahead
1595 * and process any debugging options (this allows any
1596 * argument processing, entrance criteria and library
1597 * initialization to be displayed). Otherwise, if an
1598 * input file has been seen, skip interpretation until
1599 * process_files (this allows debugging to be turned
1600 * on and off around individual groups of files).
1602 Dflag = 1;
1603 if (ofl->ofl_objscnt == 0) {
1604 if (dbg_setup(ofl, optarg, 2) == 0)
1605 return (S_ERROR);
1609 * A diagnostic can only be provided after dbg_setup().
1610 * As this is the first diagnostic that can be produced
1611 * by ld(1), issue a title for timing and basic output.
1613 if ((optitle == 0) && DBG_ENABLED) {
1614 optitle++;
1615 DBG_CALL(Dbg_basic_options(ofl->ofl_lml));
1617 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1618 break;
1620 case 'B':
1621 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1622 if (strcmp(optarg, MSG_ORIG(MSG_ARG_DIRECT)) == 0) {
1623 if (Bdflag == SET_FALSE) {
1624 ld_eprintf(ofl, ERR_FATAL,
1625 MSG_INTL(MSG_ARG_INCOMP),
1626 MSG_ORIG(MSG_ARG_BNODIRECT),
1627 MSG_ORIG(MSG_ARG_BDIRECT));
1628 } else {
1629 Bdflag = SET_TRUE;
1630 ofl->ofl_guideflags |= FLG_OFG_NO_DB;
1632 } else if (strcmp(optarg,
1633 MSG_ORIG(MSG_ARG_NODIRECT)) == 0) {
1634 if (Bdflag == SET_TRUE) {
1635 ld_eprintf(ofl, ERR_FATAL,
1636 MSG_INTL(MSG_ARG_INCOMP),
1637 MSG_ORIG(MSG_ARG_BDIRECT),
1638 MSG_ORIG(MSG_ARG_BNODIRECT));
1639 } else {
1640 Bdflag = SET_FALSE;
1641 ofl->ofl_guideflags |= FLG_OFG_NO_DB;
1643 } else if (strcmp(optarg,
1644 MSG_ORIG(MSG_STR_SYMBOLIC)) == 0)
1645 Bsflag = TRUE;
1646 else if (strcmp(optarg, MSG_ORIG(MSG_ARG_REDUCE)) == 0)
1647 ofl->ofl_flags |= FLG_OF_PROCRED;
1648 else if (strcmp(optarg, MSG_ORIG(MSG_STR_LOCAL)) == 0)
1649 Blflag = TRUE;
1650 else if (strcmp(optarg, MSG_ORIG(MSG_ARG_GROUP)) == 0)
1651 Bgflag = TRUE;
1652 else if (strcmp(optarg,
1653 MSG_ORIG(MSG_STR_ELIMINATE)) == 0)
1654 Beflag = TRUE;
1655 else if (strcmp(optarg,
1656 MSG_ORIG(MSG_ARG_TRANSLATOR)) == 0) {
1657 ld_eprintf(ofl, ERR_WARNING,
1658 MSG_INTL(MSG_ARG_UNSUPPORTED),
1659 MSG_ORIG(MSG_ARG_BTRANSLATOR));
1660 } else if (strcmp(optarg,
1661 MSG_ORIG(MSG_STR_LD_DYNAMIC)) &&
1662 strcmp(optarg, MSG_ORIG(MSG_ARG_STATIC))) {
1663 ld_eprintf(ofl, ERR_FATAL,
1664 MSG_INTL(MSG_ARG_ILLEGAL),
1665 MSG_ORIG(MSG_ARG_CB), optarg);
1667 break;
1669 case 'G':
1670 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL));
1671 otype = OT_SHARED;
1672 break;
1674 case 'L':
1675 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1676 break;
1678 case 'M':
1679 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1680 if (aplist_append(&(ofl->ofl_maps), optarg,
1681 AL_CNT_OFL_MAPFILES) == NULL)
1682 return (S_ERROR);
1683 break;
1685 case 'N':
1686 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1687 break;
1689 case 'Q':
1690 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1691 if ((optarg[0] == 'n') && (optarg[1] == '\0')) {
1692 if (Qflag != SET_UNKNOWN)
1693 ld_eprintf(ofl, ERR_WARNING_NF,
1694 MSG_INTL(MSG_ARG_MTONCE),
1695 MSG_ORIG(MSG_ARG_CQ));
1696 else
1697 Qflag = SET_FALSE;
1698 } else if ((optarg[0] == 'y') && (optarg[1] == '\0')) {
1699 if (Qflag != SET_UNKNOWN)
1700 ld_eprintf(ofl, ERR_WARNING_NF,
1701 MSG_INTL(MSG_ARG_MTONCE),
1702 MSG_ORIG(MSG_ARG_CQ));
1703 else
1704 Qflag = SET_TRUE;
1705 } else {
1706 ld_eprintf(ofl, ERR_FATAL,
1707 MSG_INTL(MSG_ARG_ILLEGAL),
1708 MSG_ORIG(MSG_ARG_CQ), optarg);
1710 break;
1712 case 'S':
1713 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1714 if (aplist_append(&lib_support, optarg,
1715 AL_CNT_SUPPORT) == NULL)
1716 return (S_ERROR);
1717 break;
1719 case 'V':
1720 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL));
1721 if (!Vflag)
1722 (void) fprintf(stderr, MSG_ORIG(MSG_STR_STRNL),
1723 ofl->ofl_sgsid);
1724 Vflag = TRUE;
1725 break;
1727 case 'Y':
1728 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg));
1729 if (strncmp(optarg, MSG_ORIG(MSG_ARG_LCOM), 2) == 0) {
1730 if (Llibdir)
1731 ld_eprintf(ofl, ERR_WARNING_NF,
1732 MSG_INTL(MSG_ARG_MTONCE),
1733 MSG_ORIG(MSG_ARG_CYL));
1734 else
1735 Llibdir = optarg + 2;
1736 } else if (strncmp(optarg,
1737 MSG_ORIG(MSG_ARG_UCOM), 2) == 0) {
1738 if (Ulibdir)
1739 ld_eprintf(ofl, ERR_WARNING_NF,
1740 MSG_INTL(MSG_ARG_MTONCE),
1741 MSG_ORIG(MSG_ARG_CYU));
1742 else
1743 Ulibdir = optarg + 2;
1744 } else if (strncmp(optarg,
1745 MSG_ORIG(MSG_ARG_PCOM), 2) == 0) {
1746 if (Plibpath)
1747 ld_eprintf(ofl, ERR_WARNING_NF,
1748 MSG_INTL(MSG_ARG_MTONCE),
1749 MSG_ORIG(MSG_ARG_CYP));
1750 else
1751 Plibpath = optarg + 2;
1752 } else {
1753 ld_eprintf(ofl, ERR_FATAL,
1754 MSG_INTL(MSG_ARG_ILLEGAL),
1755 MSG_ORIG(MSG_ARG_CY), optarg);
1757 break;
1759 case '?':
1760 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL));
1762 * If the option character is '-', we're looking at a
1763 * long option which couldn't be translated, display a
1764 * more useful error.
1766 if (optopt == '-') {
1767 eprintf(ofl->ofl_lml, ERR_FATAL,
1768 MSG_INTL(MSG_ARG_LONG_UNKNOWN),
1769 argv[optind-1]);
1770 } else {
1771 eprintf(ofl->ofl_lml, ERR_FATAL,
1772 MSG_INTL(MSG_ARG_UNKNOWN), optopt);
1774 (*usage)++;
1775 break;
1777 default:
1778 break;
1782 * Update the argument index for the next getopt() iteration.
1784 ndx = optind;
1786 return (1);
1790 * Parsing options pass2 for
1792 static uintptr_t
1793 parseopt_pass2(Ofl_desc *ofl, int argc, char **argv)
1795 int c, ndx = optind;
1797 while ((c = ld_getopt(ofl->ofl_lml, ndx, argc, argv)) != -1) {
1798 Ifl_desc *ifl;
1799 Sym_desc *sdp;
1801 switch (c) {
1802 case 'l':
1803 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c,
1804 optarg));
1805 if (ld_find_library(optarg, ofl) == S_ERROR)
1806 return (S_ERROR);
1807 break;
1808 case 'B':
1809 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c,
1810 optarg));
1811 if (strcmp(optarg,
1812 MSG_ORIG(MSG_STR_LD_DYNAMIC)) == 0) {
1813 if (ofl->ofl_flags & FLG_OF_DYNAMIC)
1814 ofl->ofl_flags |=
1815 FLG_OF_DYNLIBS;
1816 else {
1817 ld_eprintf(ofl, ERR_FATAL,
1818 MSG_INTL(MSG_ARG_ST_INCOMP),
1819 MSG_ORIG(MSG_ARG_BDYNAMIC));
1821 } else if (strcmp(optarg,
1822 MSG_ORIG(MSG_ARG_STATIC)) == 0)
1823 ofl->ofl_flags &= ~FLG_OF_DYNLIBS;
1824 break;
1825 case 'L':
1826 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c,
1827 optarg));
1828 if (ld_add_libdir(ofl, optarg) == S_ERROR)
1829 return (S_ERROR);
1830 break;
1831 case 'N':
1832 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c,
1833 optarg));
1835 * Record DT_NEEDED string
1837 if (!(ofl->ofl_flags & FLG_OF_DYNAMIC))
1838 ld_eprintf(ofl, ERR_FATAL,
1839 MSG_INTL(MSG_ARG_ST_INCOMP),
1840 MSG_ORIG(MSG_ARG_CN));
1841 if (((ifl = libld_calloc(1,
1842 sizeof (Ifl_desc))) == NULL) ||
1843 (aplist_append(&ofl->ofl_sos, ifl,
1844 AL_CNT_OFL_LIBS) == NULL))
1845 return (S_ERROR);
1847 ifl->ifl_name = MSG_INTL(MSG_STR_COMMAND);
1848 ifl->ifl_soname = optarg;
1849 ifl->ifl_flags = (FLG_IF_NEEDSTR |
1850 FLG_IF_FILEREF | FLG_IF_DEPREQD);
1852 break;
1853 case 'D':
1854 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c,
1855 optarg));
1856 (void) dbg_setup(ofl, optarg, 3);
1857 break;
1858 case 'u':
1859 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c,
1860 optarg));
1861 if (ld_sym_add_u(optarg, ofl,
1862 MSG_STR_COMMAND) == (Sym_desc *)S_ERROR)
1863 return (S_ERROR);
1864 break;
1865 case 'z':
1866 DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c,
1867 optarg));
1868 if ((strncmp(optarg, MSG_ORIG(MSG_ARG_LD32),
1869 MSG_ARG_LD32_SIZE) == 0) ||
1870 (strncmp(optarg, MSG_ORIG(MSG_ARG_LD64),
1871 MSG_ARG_LD64_SIZE) == 0)) {
1872 if (createargv(ofl, 0) == S_ERROR)
1873 return (S_ERROR);
1874 } else if (strcmp(optarg,
1875 MSG_ORIG(MSG_ARG_ALLEXTRT)) == 0) {
1876 ofl->ofl_flags1 |= FLG_OF1_ALLEXRT;
1877 ofl->ofl_flags1 &= ~FLG_OF1_WEAKEXT;
1878 } else if (strcmp(optarg,
1879 MSG_ORIG(MSG_ARG_WEAKEXT)) == 0) {
1880 ofl->ofl_flags1 |= FLG_OF1_WEAKEXT;
1881 ofl->ofl_flags1 &= ~FLG_OF1_ALLEXRT;
1882 } else if (strcmp(optarg,
1883 MSG_ORIG(MSG_ARG_DFLEXTRT)) == 0) {
1884 ofl->ofl_flags1 &=
1885 ~(FLG_OF1_ALLEXRT |
1886 FLG_OF1_WEAKEXT);
1887 } else if (strcmp(optarg,
1888 MSG_ORIG(MSG_ARG_DIRECT)) == 0) {
1889 ofl->ofl_flags1 |= FLG_OF1_ZDIRECT;
1890 ofl->ofl_guideflags |= FLG_OFG_NO_DB;
1891 } else if (strcmp(optarg,
1892 MSG_ORIG(MSG_ARG_NODIRECT)) == 0) {
1893 ofl->ofl_flags1 &= ~FLG_OF1_ZDIRECT;
1894 ofl->ofl_guideflags |= FLG_OFG_NO_DB;
1895 } else if (strcmp(optarg,
1896 MSG_ORIG(MSG_ARG_IGNORE)) == 0) {
1897 ofl->ofl_flags1 |= FLG_OF1_IGNORE;
1898 } else if (strcmp(optarg,
1899 MSG_ORIG(MSG_ARG_RECORD)) == 0) {
1900 ofl->ofl_flags1 &= ~FLG_OF1_IGNORE;
1901 } else if (strcmp(optarg,
1902 MSG_ORIG(MSG_ARG_LAZYLOAD)) == 0) {
1903 ofl->ofl_flags1 |= FLG_OF1_LAZYLD;
1904 ofl->ofl_guideflags |= FLG_OFG_NO_LAZY;
1905 } else if (strcmp(optarg,
1906 MSG_ORIG(MSG_ARG_NOLAZYLOAD)) == 0) {
1907 ofl->ofl_flags1 &= ~ FLG_OF1_LAZYLD;
1908 ofl->ofl_guideflags |= FLG_OFG_NO_LAZY;
1909 } else if (strcmp(optarg,
1910 MSG_ORIG(MSG_ARG_GROUPPERM)) == 0) {
1911 ofl->ofl_flags1 |= FLG_OF1_GRPPRM;
1912 } else if (strcmp(optarg,
1913 MSG_ORIG(MSG_ARG_NOGROUPPERM)) == 0) {
1914 ofl->ofl_flags1 &= ~FLG_OF1_GRPPRM;
1915 } else if (strncmp(optarg,
1916 MSG_ORIG(MSG_ARG_INITARRAY),
1917 MSG_ARG_INITARRAY_SIZE) == 0) {
1918 if (((sdp = ld_sym_add_u(optarg +
1919 MSG_ARG_INITARRAY_SIZE, ofl,
1920 MSG_STR_COMMAND)) ==
1921 (Sym_desc *)S_ERROR) ||
1922 (aplist_append(&ofl->ofl_initarray,
1923 sdp, AL_CNT_OFL_ARRAYS) == NULL))
1924 return (S_ERROR);
1925 } else if (strncmp(optarg,
1926 MSG_ORIG(MSG_ARG_FINIARRAY),
1927 MSG_ARG_FINIARRAY_SIZE) == 0) {
1928 if (((sdp = ld_sym_add_u(optarg +
1929 MSG_ARG_FINIARRAY_SIZE, ofl,
1930 MSG_STR_COMMAND)) ==
1931 (Sym_desc *)S_ERROR) ||
1932 (aplist_append(&ofl->ofl_finiarray,
1933 sdp, AL_CNT_OFL_ARRAYS) == NULL))
1934 return (S_ERROR);
1935 } else if (strncmp(optarg,
1936 MSG_ORIG(MSG_ARG_PREINITARRAY),
1937 MSG_ARG_PREINITARRAY_SIZE) == 0) {
1938 if (((sdp = ld_sym_add_u(optarg +
1939 MSG_ARG_PREINITARRAY_SIZE, ofl,
1940 MSG_STR_COMMAND)) ==
1941 (Sym_desc *)S_ERROR) ||
1942 (aplist_append(&ofl->ofl_preiarray,
1943 sdp, AL_CNT_OFL_ARRAYS) == NULL))
1944 return (S_ERROR);
1945 } else if (strncmp(optarg,
1946 MSG_ORIG(MSG_ARG_RTLDINFO),
1947 MSG_ARG_RTLDINFO_SIZE) == 0) {
1948 if (((sdp = ld_sym_add_u(optarg +
1949 MSG_ARG_RTLDINFO_SIZE, ofl,
1950 MSG_STR_COMMAND)) ==
1951 (Sym_desc *)S_ERROR) ||
1952 (aplist_append(&ofl->ofl_rtldinfo,
1953 sdp, AL_CNT_OFL_ARRAYS) == NULL))
1954 return (S_ERROR);
1955 } else if (strncmp(optarg,
1956 MSG_ORIG(MSG_ARG_DTRACE),
1957 MSG_ARG_DTRACE_SIZE) == 0) {
1958 if ((sdp = ld_sym_add_u(optarg +
1959 MSG_ARG_DTRACE_SIZE, ofl,
1960 MSG_STR_COMMAND)) ==
1961 (Sym_desc *)S_ERROR)
1962 return (S_ERROR);
1963 ofl->ofl_dtracesym = sdp;
1964 } else if (strcmp(optarg,
1965 MSG_ORIG(MSG_ARG_RESCAN_NOW)) == 0) {
1966 if (ld_rescan_archives(ofl, 0, ndx) ==
1967 S_ERROR)
1968 return (S_ERROR);
1969 } else if (strcmp(optarg,
1970 MSG_ORIG(MSG_ARG_RESCAN_START)) == 0) {
1971 ofl->ofl_ars_gsndx = ofl->ofl_arscnt;
1972 ofl->ofl_ars_gsandx = ndx;
1973 } else if (strcmp(optarg,
1974 MSG_ORIG(MSG_ARG_RESCAN_END)) == 0) {
1975 if (ld_rescan_archives(ofl, 1, ndx) ==
1976 S_ERROR)
1977 return (S_ERROR);
1978 } else if (strcmp(optarg,
1979 MSG_ORIG(MSG_ARG_DEFERRED)) == 0) {
1980 ofl->ofl_flags1 |= FLG_OF1_DEFERRED;
1981 } else if (strcmp(optarg,
1982 MSG_ORIG(MSG_ARG_NODEFERRED)) == 0) {
1983 ofl->ofl_flags1 &= ~FLG_OF1_DEFERRED;
1985 default:
1986 break;
1990 * Update the argument index for the next getopt() iteration.
1992 ndx = optind;
1994 return (1);
1999 * Pass 1 -- process_flags: collects all options and sets flags
2001 static uintptr_t
2002 process_flags_com(Ofl_desc *ofl, int argc, char **argv, int *usage)
2004 for (; optind < argc; optind++) {
2006 * If we detect some more options return to getopt().
2007 * Checking argv[optind][1] against null prevents a forever
2008 * loop if an unadorned `-' argument is passed to us.
2010 while ((optind < argc) && (argv[optind][0] == '-')) {
2011 if (argv[optind][1] != '\0') {
2012 if (parseopt_pass1(ofl, argc, argv,
2013 usage) == S_ERROR)
2014 return (S_ERROR);
2015 } else if (++optind < argc)
2016 continue;
2018 if (optind >= argc)
2019 break;
2020 ofl->ofl_objscnt++;
2023 /* Did an unterminated archive group run off the end? */
2024 if (ofl->ofl_ars_gsandx > 0) {
2025 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_AR_GRP_BAD),
2026 MSG_INTL(MSG_MARG_AR_GRP_START),
2027 MSG_INTL(MSG_MARG_AR_GRP_END));
2028 return (S_ERROR);
2031 return (1);
2034 uintptr_t
2035 ld_process_flags(Ofl_desc *ofl, int argc, char **argv)
2037 int usage = 0; /* Collect all argument errors before exit */
2039 if (argc < 2) {
2040 usage_mesg(FALSE);
2041 return (S_ERROR);
2045 * Option handling
2047 opterr = 0;
2048 optind = 1;
2049 if (process_flags_com(ofl, argc, argv, &usage) == S_ERROR)
2050 return (S_ERROR);
2053 * Having parsed everything, did we have any usage errors.
2055 if (usage) {
2056 eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_ARG_USEHELP));
2057 return (S_ERROR);
2060 return (check_flags(ofl, argc));
2064 * Pass 2 -- process_files: skips the flags collected in pass 1 and processes
2065 * files.
2067 static uintptr_t
2068 process_files_com(Ofl_desc *ofl, int argc, char **argv)
2070 for (; optind < argc; optind++) {
2071 int fd;
2072 uintptr_t open_ret;
2073 char *path;
2074 Rej_desc rej = { 0 };
2077 * If we detect some more options return to getopt().
2078 * Checking argv[optind][1] against null prevents a forever
2079 * loop if an unadorned `-' argument is passed to us.
2081 while ((optind < argc) && (argv[optind][0] == '-')) {
2082 if (argv[optind][1] != '\0') {
2083 if (parseopt_pass2(ofl, argc, argv) == S_ERROR)
2084 return (S_ERROR);
2085 } else if (++optind < argc)
2086 continue;
2088 if (optind >= argc)
2089 break;
2091 path = argv[optind];
2092 if ((fd = open(path, O_RDONLY)) == -1) {
2093 int err = errno;
2095 ld_eprintf(ofl, ERR_FATAL,
2096 MSG_INTL(MSG_SYS_OPEN), path, strerror(err));
2097 continue;
2100 DBG_CALL(Dbg_args_file(ofl->ofl_lml, optind, path));
2102 open_ret = ld_process_open(path, path, &fd, ofl,
2103 (FLG_IF_CMDLINE | FLG_IF_NEEDED), &rej, NULL);
2104 if (fd != -1)
2105 (void) close(fd);
2106 if (open_ret == S_ERROR)
2107 return (S_ERROR);
2110 * Check for mismatched input.
2112 if (rej.rej_type) {
2113 Conv_reject_desc_buf_t rej_buf;
2115 ld_eprintf(ofl, ERR_FATAL,
2116 MSG_INTL(reject[rej.rej_type]),
2117 rej.rej_name ? rej.rej_name :
2118 MSG_INTL(MSG_STR_UNKNOWN),
2119 conv_reject_desc(&rej, &rej_buf,
2120 ld_targ.t_m.m_mach));
2121 return (1);
2124 return (1);
2127 uintptr_t
2128 ld_process_files(Ofl_desc *ofl, int argc, char **argv)
2130 DBG_CALL(Dbg_basic_files(ofl->ofl_lml));
2133 * Process command line files (taking into account any applicable
2134 * preceding flags). Return if any fatal errors have occurred.
2136 opterr = 0;
2137 optind = 1;
2138 if (process_files_com(ofl, argc, argv) == S_ERROR)
2139 return (S_ERROR);
2140 if (ofl->ofl_flags & FLG_OF_FATAL)
2141 return (1);
2144 * Guidance: Use -B direct/nodirect or -z direct/nodirect.
2146 * This is a backstop for the case where the link had no dependencies.
2147 * Otherwise, it will get caught by ld_process_ifl(). We need both,
2148 * because -z direct is positional, and its value at the time where
2149 * the first dependency is seen might be different than it is now.
2151 if ((ofl->ofl_flags & FLG_OF_DYNAMIC) &&
2152 OFL_GUIDANCE(ofl, FLG_OFG_NO_DB)) {
2153 ld_eprintf(ofl, ERR_GUIDANCE, MSG_INTL(MSG_GUIDE_DIRECT));
2154 ofl->ofl_guideflags |= FLG_OFG_NO_DB;
2158 * Now that all command line files have been processed see if there are
2159 * any additional `needed' shared object dependencies.
2161 if (ofl->ofl_soneed)
2162 if (ld_finish_libs(ofl) == S_ERROR)
2163 return (S_ERROR);
2166 * If rescanning archives is enabled, do so now to determine whether
2167 * there might still be members extracted to satisfy references from any
2168 * explicit objects. Continue until no new objects are extracted. Note
2169 * that this pass is carried out *after* processing any implicit objects
2170 * (above) as they may already have resolved any undefined references
2171 * from any explicit dependencies.
2173 if (ofl->ofl_flags1 & FLG_OF1_RESCAN) {
2174 if (ld_rescan_archives(ofl, 0, argc) == S_ERROR)
2175 return (S_ERROR);
2176 if (ofl->ofl_flags & FLG_OF_FATAL)
2177 return (1);
2181 * If debugging, provide statistics on each archives extraction, or flag
2182 * any archive that has provided no members. Note that this could be a
2183 * nice place to free up much of the archive infrastructure, as we've
2184 * extracted any members we need. However, as we presently don't free
2185 * anything under ld(1) there's not much point in proceeding further.
2187 DBG_CALL(Dbg_statistics_ar(ofl));
2190 * If any version definitions have been established, either via input
2191 * from a mapfile or from the input relocatable objects, make sure any
2192 * version dependencies are satisfied, and version symbols created.
2194 if (ofl->ofl_verdesc)
2195 if (ld_vers_check_defs(ofl) == S_ERROR)
2196 return (S_ERROR);
2199 * If input section ordering was specified within some segment
2200 * using a mapfile, verify that the expected sections were seen.
2202 if (ofl->ofl_flags & FLG_OF_IS_ORDER)
2203 ld_ent_check(ofl);
2205 return (1);
2208 uintptr_t
2209 ld_init_strings(Ofl_desc *ofl)
2211 uint_t stflags;
2213 if (ofl->ofl_flags1 & FLG_OF1_NCSTTAB)
2214 stflags = 0;
2215 else
2216 stflags = FLG_STNEW_COMPRESS;
2218 if (((ofl->ofl_shdrsttab = st_new(stflags)) == NULL) ||
2219 ((ofl->ofl_strtab = st_new(stflags)) == NULL) ||
2220 ((ofl->ofl_dynstrtab = st_new(stflags)) == NULL))
2221 return (S_ERROR);
2223 return (0);