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