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