Print this page
4843 add --as-needed and --no-as-needed to ld
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/sgs/libld/common/util.c
+++ new/usr/src/cmd/sgs/libld/common/util.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) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 */
25 25
26 26 /*
27 27 * Copyright (c) 1988 AT&T
28 28 * All Rights Reserved
29 29 */
30 30
31 31 /*
32 32 * Utility functions
33 33 */
34 34 #include <unistd.h>
35 35 #include <stdio.h>
36 36 #include <stdarg.h>
37 37 #include <string.h>
38 38 #include <fcntl.h>
39 39 #include <sys/types.h>
40 40 #include <sys/mman.h>
41 41 #include <errno.h>
42 42 #include <sgs.h>
43 43 #include <libintl.h>
44 44 #include <debug.h>
45 45 #include "msg.h"
46 46 #include "_libld.h"
47 47
48 48 /*
49 49 * libld_malloc() and dz_map() are used for both performance and for ease of
50 50 * programming:
51 51 *
52 52 * Performance:
53 53 * The link-edit is a short lived process which doesn't really free much
54 54 * of the dynamic memory that it requests. Because of this, it is more
55 55 * important to optimize for quick memory allocations than the
56 56 * re-usability of the memory.
57 57 *
58 58 * By also mmaping blocks of pages in from /dev/zero we don't need to
59 59 * waste the overhead of zeroing out these pages for calloc() requests.
60 60 *
61 61 * Memory Management:
62 62 * By doing all libld memory management through the ld_malloc routine
63 63 * it's much easier to free up all memory at the end by simply unmaping
64 64 * all of the blocks that were mapped in through dz_map(). This is much
65 65 * simpler then trying to track all of the libld structures that were
66 66 * dynamically allocate and are actually pointers into the ELF files.
67 67 *
68 68 * It's important that we can free up all of our dynamic memory because
69 69 * libld is used by ld.so.1 when it performs dlopen()'s of relocatable
70 70 * objects.
71 71 *
72 72 * Format:
73 73 * The memory blocks for each allocation store the size of the allocation
74 74 * in the first 8 bytes of the block. The pointer that is returned by
75 75 * libld_malloc() is actually the address of (block + 8):
76 76 *
77 77 * (addr - 8) block_size
78 78 * (addr) <allocated block>
79 79 *
80 80 * The size is retained in order to implement realloc(), and to perform
81 81 * the required memcpy(). 8 bytes are uses, as the memory area returned
82 82 * by libld_malloc() must be 8 byte-aligned. Even in a 32-bit environment,
83 83 * u_longlog_t pointers are employed.
84 84 *
85 85 * Map anonymous memory via MAP_ANON (added in Solaris 8).
86 86 */
87 87 static void *
88 88 dz_map(size_t size)
89 89 {
90 90 void *addr;
91 91
92 92 if ((addr = mmap(0, size, (PROT_READ | PROT_WRITE | PROT_EXEC),
93 93 (MAP_PRIVATE | MAP_ANON), -1, 0)) == MAP_FAILED) {
94 94 int err = errno;
95 95 eprintf(NULL, ERR_FATAL, MSG_INTL(MSG_SYS_MMAPANON),
96 96 strerror(err));
97 97 return (MAP_FAILED);
98 98 }
99 99 return (addr);
100 100 }
101 101
102 102 void *
103 103 libld_malloc(size_t size)
104 104 {
105 105 Ld_heap *chp = ld_heap;
106 106 void *vptr;
107 107 size_t asize = size + HEAPALIGN;
108 108
109 109 /*
110 110 * If this is the first allocation, or the allocation request is greater
111 111 * than the current free space available, allocate a new heap.
112 112 */
113 113 if ((chp == NULL) ||
114 114 (((size_t)chp->lh_end - (size_t)chp->lh_free) <= asize)) {
115 115 Ld_heap *nhp;
116 116 size_t hsize = (size_t)S_ROUND(sizeof (Ld_heap), HEAPALIGN);
117 117 size_t tsize = (size_t)S_ROUND((asize + hsize), HEAPALIGN);
118 118
119 119 /*
120 120 * Allocate a block that is at minimum 'HEAPBLOCK' size
121 121 */
122 122 if (tsize < HEAPBLOCK)
123 123 tsize = HEAPBLOCK;
124 124
125 125 if ((nhp = dz_map(tsize)) == MAP_FAILED)
126 126 return (NULL);
127 127
128 128 nhp->lh_next = chp;
129 129 nhp->lh_free = (void *)((size_t)nhp + hsize);
130 130 nhp->lh_end = (void *)((size_t)nhp + tsize);
131 131
132 132 ld_heap = chp = nhp;
133 133 }
134 134 vptr = chp->lh_free;
135 135
136 136 /*
137 137 * Assign size to head of allocated block (used by realloc), and
138 138 * memory arena as then next 8-byte aligned offset.
139 139 */
140 140 *((size_t *)vptr) = size;
141 141 vptr = (void *)((size_t)vptr + HEAPALIGN);
142 142
143 143 /*
144 144 * Increment free to point to next available block
145 145 */
146 146 chp->lh_free = (void *)S_ROUND((size_t)chp->lh_free + asize,
147 147 HEAPALIGN);
148 148
149 149 return (vptr);
150 150 }
151 151
152 152 void *
153 153 libld_realloc(void *ptr, size_t size)
154 154 {
155 155 size_t psize;
156 156 void *vptr;
157 157
158 158 if (ptr == NULL)
159 159 return (libld_malloc(size));
160 160
161 161 /*
162 162 * Size of the allocated blocks is stored *just* before the blocks
163 163 * address.
164 164 */
165 165 psize = *((size_t *)((size_t)ptr - HEAPALIGN));
166 166
167 167 /*
168 168 * If the block actually fits then just return.
169 169 */
170 170 if (size <= psize)
171 171 return (ptr);
172 172
173 173 if ((vptr = libld_malloc(size)) != NULL)
174 174 (void) memcpy(vptr, ptr, psize);
175 175
176 176 return (vptr);
177 177 }
178 178
179 179 void
180 180 /* ARGSUSED 0 */
181 181 libld_free(void *ptr)
182 182 {
183 183 }
184 184
185 185 /*
186 186 * Determine if a shared object definition structure already exists and if
187 187 * not create one. These definitions provide for recording information
188 188 * regarding shared objects that are still to be processed. Once processed
189 189 * shared objects are maintained on the ofl_sos list. The information
190 190 * recorded in this structure includes:
191 191 *
192 192 * o DT_USED requirements. In these cases definitions are added during
193 193 * mapfile processing of `-' entries (see map_dash()).
194 194 *
195 195 * o implicit NEEDED entries. As shared objects are processed from the
196 196 * command line so any of their dependencies are recorded in these
197 197 * structures for later processing (see process_dynamic()).
198 198 *
199 199 * o version requirements. Any explicit shared objects that have version
200 200 * dependencies on other objects have their version requirements recorded.
201 201 * In these cases definitions are added during mapfile processing of `-'
202 202 * entries (see map_dash()). Also, shared objects may have versioning
203 203 * requirements on their NEEDED entries. These cases are added during
204 204 * their version processing (see vers_need_process()).
205 205 *
206 206 * Note: Both process_dynamic() and vers_need_process() may generate the
207 207 * initial version definition structure because you can't rely on what
208 208 * section (.dynamic or .SUNW_version) may be processed first from any
209 209 * input file.
210 210 */
211 211 Sdf_desc *
212 212 sdf_find(const char *name, APlist *alp)
213 213 {
214 214 Aliste idx;
215 215 Sdf_desc *sdf;
216 216
217 217 for (APLIST_TRAVERSE(alp, idx, sdf))
218 218 if (strcmp(name, sdf->sdf_name) == 0)
219 219 return (sdf);
220 220
221 221 return (NULL);
222 222 }
223 223
224 224 Sdf_desc *
225 225 sdf_add(const char *name, APlist **alpp)
226 226 {
227 227 Sdf_desc *sdf;
228 228
229 229 if ((sdf = libld_calloc(sizeof (Sdf_desc), 1)) == NULL)
230 230 return ((Sdf_desc *)S_ERROR);
231 231
232 232 sdf->sdf_name = name;
233 233
234 234 if (aplist_append(alpp, sdf, AL_CNT_OFL_LIBS) == NULL)
235 235 return ((Sdf_desc *)S_ERROR);
236 236
237 237 return (sdf);
238 238 }
239 239
240 240 /*
241 241 * Add a string, separated by a colon, to an existing string. Typically used
242 242 * to maintain filter, rpath and audit names, of which there is normally only
243 243 * one string supplied anyway.
244 244 */
245 245 char *
246 246 add_string(char *old, char *str)
247 247 {
248 248 char *new;
249 249
250 250 if (old) {
251 251 char *_str;
252 252 size_t len;
253 253
254 254 /*
255 255 * If an original string exists, make sure this new string
256 256 * doesn't get duplicated.
257 257 */
258 258 if ((_str = strstr(old, str)) != NULL) {
259 259 if (((_str == old) ||
260 260 (*(_str - 1) == *(MSG_ORIG(MSG_STR_COLON)))) &&
261 261 (_str += strlen(str)) &&
262 262 ((*_str == '\0') ||
263 263 (*_str == *(MSG_ORIG(MSG_STR_COLON)))))
264 264 return (old);
265 265 }
266 266
267 267 len = strlen(old) + strlen(str) + 2;
268 268 if ((new = libld_calloc(1, len)) == NULL)
269 269 return ((char *)S_ERROR);
270 270 (void) snprintf(new, len, MSG_ORIG(MSG_FMT_COLPATH), old, str);
271 271 } else {
272 272 if ((new = libld_malloc(strlen(str) + 1)) == NULL)
273 273 return ((char *)S_ERROR);
274 274 (void) strcpy(new, str);
275 275 }
276 276
277 277 return (new);
278 278 }
279 279
280 280 /*
281 281 * The GNU ld '-wrap=XXX' and '--wrap=XXX' options correspond to our
282 282 * '-z wrap=XXX'. When str2chr() does this conversion, we end up with
283 283 * the return character set to 'z' and optarg set to 'XXX'. This callback
284 284 * changes optarg to include the missing wrap= prefix.
285 285 *
286 286 * exit:
287 287 * Returns c on success, or '?' on error.
288 288 */
289 289 static int
290 290 str2chr_wrap_cb(int c)
291 291 {
292 292 char *str;
293 293 size_t len = MSG_ARG_WRAP_SIZE + strlen(optarg) + 1;
294 294
295 295 if ((str = libld_malloc(len)) == NULL)
296 296 return ('?');
297 297 (void) snprintf(str, len, MSG_ORIG(MSG_FMT_STRCAT),
298 298 MSG_ORIG(MSG_ARG_WRAP), optarg);
299 299 optarg = str;
300 300 return (c);
301 301 }
302 302
303 303 /*
304 304 * Determine whether this string, possibly with an associated option, should
305 305 * be translated to an option character. If so, update the optind and optarg
306 306 * and optopt as described for short options in getopt(3c).
307 307 *
308 308 * entry:
309 309 * lml - Link map list for debug messages
310 310 * ndx - Starting optind for current item
311 311 * argc, argv - Command line arguments
312 312 * arg - Option to be examined
313 313 * c, opt - Option character (c) and corresponding long name (opt)
314 314 * optsz - 0 if option does not accept a value. If option does
315 315 * accept a value, strlen(opt), giving the offset to the
316 316 * value if the option and value are combined in one string.
317 317 * cbfunc - NULL, or pointer to function to call if a translation is
318 318 * successful.
319 319 */
320 320 static int
321 321 str2chr(Lm_list *lml, int ndx, int argc, char **argv, char *arg, int c,
322 322 const char *opt, size_t optsz, int cbfunc(int))
323 323 {
324 324 if (optsz == 0) {
325 325 /*
326 326 * Compare a single option (ie. there's no associated option
327 327 * argument).
328 328 */
329 329 if (strcmp(arg, opt) == 0) {
330 330 DBG_CALL(Dbg_args_str2chr(lml, ndx, opt, c));
331 331 optind += 1;
332 332 optopt = c;
333 333 return (c);
334 334 }
335 335 } else if ((strcmp(arg, opt) == 0) ||
336 336 ((arg[optsz] == '=') && strncmp(arg, opt, optsz) == 0)) {
337 337 /*
338 338 * Otherwise, compare the option name, which may be
339 339 * concatenated with the option argument.
340 340 */
341 341 DBG_CALL(Dbg_args_str2chr(lml, ndx, opt, c));
342 342
343 343 if (arg[optsz] == '\0') {
344 344 /*
345 345 * Optarg is the next argument (white space separated).
346 346 * Make sure an optarg is available, and if not return
347 347 * a failure to prevent any fall-through to the generic
348 348 * getopt() processing.
349 349 *
350 350 * Since we'll be completely failing this option we
351 351 * don't want to update optopt with the translation,
352 352 * but also need to set it to _something_. Setting it
353 353 * to the '-' of the argument causes us to behave
354 354 * correctly.
355 355 */
356 356 if ((++optind + 1) > argc) {
357 357 optopt = arg[0];
358 358 return ('?');
359 359 }
360 360 optarg = argv[optind];
361 361 optind++;
362 362 } else {
363 363 /*
364 364 * GNU option/option argument pairs can be represented
365 365 * with a "=" separator. If this is the case, remove
366 366 * the separator.
367 367 */
368 368 optarg = &arg[optsz];
369 369 optind++;
370 370 if (*optarg == '=') {
371 371 if (*(++optarg) == '\0') {
372 372 optopt = arg[0];
373 373 return ('?');
374 374 }
375 375 }
376 376 }
377 377
378 378 if (cbfunc != NULL)
379 379 c = (*cbfunc)(c);
380 380 optopt = c;
381 381 return (c);
382 382 }
383 383 return (0);
384 384 }
385 385
386 386 /*
387 387 * Parse an individual option. The intent of this function is to determine if
388 388 * any known, non-Solaris options have been passed to ld(1). This condition
389 389 * can occur as a result of build configuration tools, because of users
390 390 * familiarity with other systems, or simply the users preferences. If a known
391 391 * non-Solaris option can be determined, translate that option into the Solaris
392 392 * counterpart.
393 393 *
394 394 * This function will probably never be a complete solution, as new, non-Solaris
395 395 * options are discovered, their translation will have to be added. Other
396 396 * non-Solaris options are incompatible with the Solaris link-editor, and will
397 397 * never be recognized. We support what we can.
398 398 */
399 399 int
400 400 ld_getopt(Lm_list *lml, int ndx, int argc, char **argv)
401 401 {
402 402 int c;
403 403
404 404 if ((optind < argc) && argv[optind] && (argv[optind][0] == '-')) {
405 405 char *arg = &argv[optind][1];
406 406
407 407 switch (*arg) {
408 408 case 'r':
409 409 /* Translate -rpath <optarg> to -R <optarg> */
410 410 if ((c = str2chr(lml, ndx, argc, argv, arg, 'R',
411 411 MSG_ORIG(MSG_ARG_T_RPATH),
412 412 MSG_ARG_T_RPATH_SIZE, NULL)) != 0) {
413 413 return (c);
414 414 }
415 415 break;
416 416 case 's':
417 417 /* Translate -shared to -G */
418 418 if ((c = str2chr(lml, ndx, argc, argv, arg, 'G',
419 419 MSG_ORIG(MSG_ARG_T_SHARED), 0, NULL)) != 0) {
420 420 return (c);
421 421
422 422 /* Translate -soname <optarg> to -h <optarg> */
423 423 } else if ((c = str2chr(lml, ndx, argc, argv, arg, 'h',
424 424 MSG_ORIG(MSG_ARG_T_SONAME),
425 425 MSG_ARG_T_SONAME_SIZE, NULL)) != 0) {
426 426 return (c);
427 427 }
428 428 break;
429 429 case 'w':
430 430 /* Translate -wrap to -z wrap= */
431 431 if ((c = str2chr(lml, ndx, argc, argv, arg, 'z',
432 432 MSG_ORIG(MSG_ARG_T_WRAP) + 1,
433 433 MSG_ARG_T_WRAP_SIZE - 1, str2chr_wrap_cb)) != 0) {
434 434 return (c);
435 435 }
436 436 break;
437 437 case '(':
438 438 /*
439 439 * Translate -( to -z rescan-start
440 440 */
441 441 if ((c = str2chr(lml, ndx, argc, argv,
442 442 arg, 'z', MSG_ORIG(MSG_ARG_T_OPAR), 0, NULL)) !=
443 443 0) {
444 444 optarg = (char *)MSG_ORIG(MSG_ARG_RESCAN_START);
445 445 return (c);
446 446 }
447 447 break;
448 448 case ')':
449 449 /*
450 450 * Translate -) to -z rescan-end
451 451 */
452 452 if ((c = str2chr(lml, ndx, argc, argv,
↓ open down ↓ |
452 lines elided |
↑ open up ↑ |
453 453 arg, 'z', MSG_ORIG(MSG_ARG_T_CPAR), 0, NULL)) !=
454 454 0) {
455 455 optarg = (char *)MSG_ORIG(MSG_ARG_RESCAN_END);
456 456 return (c);
457 457 }
458 458 break;
459 459 case '-':
460 460 switch (*(arg + 1)) {
461 461 case 'a':
462 462 /*
463 + * Translate --as-needed to -zignore
464 + */
465 + if ((c = str2chr(lml, ndx, argc, argv, arg, 'z',
466 + MSG_ORIG(MSG_ARG_T_ASNEEDED), 0, NULL)) !=
467 + 0) {
468 + optarg =
469 + (char *)MSG_ORIG(MSG_ARG_IGNORE);
470 + return (c);
471 + }
472 + /*
463 473 * Translate --allow-multiple-definition to
464 474 * -zmuldefs
465 475 */
466 476 if ((c = str2chr(lml, ndx, argc, argv, arg, 'z',
467 477 MSG_ORIG(MSG_ARG_T_MULDEFS), 0, NULL)) !=
468 478 0) {
469 479 optarg =
470 480 (char *)MSG_ORIG(MSG_ARG_MULDEFS);
471 481 return (c);
472 -
482 + }
473 483 /*
474 484 * Translate --auxiliary <optarg> to
475 485 * -f <optarg>
476 486 */
477 - } else if ((c = str2chr(lml, argc, ndx, argv,
487 + if ((c = str2chr(lml, argc, ndx, argv,
478 488 arg, 'f', MSG_ORIG(MSG_ARG_T_AUXFLTR),
479 489 MSG_ARG_T_AUXFLTR_SIZE, NULL)) != 0) {
480 490 return (c);
481 491 }
482 492 break;
483 493 case 'd':
484 494 /*
485 495 * Translate --dynamic-linker <optarg> to
486 496 * -I <optarg>
487 497 */
488 498 if ((c = str2chr(lml, ndx, argc, argv, arg, 'I',
489 499 MSG_ORIG(MSG_ARG_T_INTERP),
490 500 MSG_ARG_T_INTERP_SIZE, NULL)) != 0) {
491 501 return (c);
492 502 }
493 503 break;
494 504 case 'e':
495 505 /* Translate --entry <optarg> to -e <optarg> */
496 506 if ((c = str2chr(lml, ndx, argc, argv, arg, 'e',
497 507 MSG_ORIG(MSG_ARG_T_ENTRY),
498 508 MSG_ARG_T_ENTRY_SIZE, NULL)) != 0) {
499 509 return (c);
500 510 }
501 511 /*
502 512 * Translate --end-group to -z rescan-end
503 513 */
504 514 if ((c = str2chr(lml, ndx, argc, argv,
505 515 arg, 'z', MSG_ORIG(MSG_ARG_T_ENDGROUP),
506 516 0, NULL)) != 0) {
507 517 optarg = (char *)
508 518 MSG_ORIG(MSG_ARG_RESCAN_END);
509 519 return (c);
510 520 }
511 521 break;
512 522 case 'f':
513 523 /*
514 524 * Translate --fatal-warnings to
515 525 * -z fatal-warnings.
516 526 */
517 527 if ((c = str2chr(lml, ndx, argc, argv, arg, 'z',
518 528 MSG_ORIG(MSG_ARG_T_FATWARN),
519 529 0, NULL)) != 0) {
520 530 optarg = (char *)
521 531 MSG_ORIG(MSG_ARG_FATWARN);
522 532 return (c);
523 533 }
524 534 /* Translate --filter <optarg> to -F <optarg> */
525 535 if ((c = str2chr(lml, ndx, argc, argv, arg, 'F',
526 536 MSG_ORIG(MSG_ARG_T_STDFLTR),
527 537 MSG_ARG_T_STDFLTR_SIZE, NULL)) != 0) {
528 538 return (c);
529 539 }
530 540 break;
531 541 case 'h':
532 542 /* Translate --help to -zhelp */
533 543 if ((c = str2chr(lml, ndx, argc, argv, arg, 'z',
534 544 MSG_ORIG(MSG_ARG_T_HELP), 0, NULL)) !=
535 545 0) {
536 546 optarg = (char *)MSG_ORIG(MSG_ARG_HELP);
537 547 return (c);
538 548 }
539 549 break;
540 550 case 'l':
541 551 /*
542 552 * Translate --library <optarg> to -l <optarg>
543 553 */
544 554 if ((c = str2chr(lml, ndx, argc, argv, arg, 'l',
545 555 MSG_ORIG(MSG_ARG_T_LIBRARY),
546 556 MSG_ARG_T_LIBRARY_SIZE, NULL)) != 0) {
547 557 return (c);
548 558
549 559 /*
550 560 * Translate --library-path <optarg> to
↓ open down ↓ |
63 lines elided |
↑ open up ↑ |
551 561 * -L <optarg>
552 562 */
553 563 } else if ((c = str2chr(lml, ndx, argc, argv,
554 564 arg, 'L', MSG_ORIG(MSG_ARG_T_LIBPATH),
555 565 MSG_ARG_T_LIBPATH_SIZE, NULL)) != 0) {
556 566 return (c);
557 567 }
558 568 break;
559 569 case 'n':
560 570 /*
571 + * Translate --no-as-needed to -zrecord
572 + */
573 + if ((c = str2chr(lml, ndx, argc, argv, arg, 'z',
574 + MSG_ORIG(MSG_ARG_T_NOASNEEDED), 0, NULL)) !=
575 + 0) {
576 + optarg =
577 + (char *)MSG_ORIG(MSG_ARG_RECORD);
578 + return (c);
579 + }
580 + /*
561 581 * Translate --no-fatal-warnings to
562 582 * -z nofatal-warnings.
563 583 */
564 584 if ((c = str2chr(lml, ndx, argc, argv, arg, 'z',
565 585 MSG_ORIG(MSG_ARG_T_NOFATWARN),
566 586 0, NULL)) != 0) {
567 587 optarg = (char *)
568 588 MSG_ORIG(MSG_ARG_NOFATWARN);
569 589 return (c);
570 590 }
571 591
572 592 /* Translate --no-undefined to -zdefs */
573 593 if ((c = str2chr(lml, ndx, argc, argv, arg, 'z',
574 594 MSG_ORIG(MSG_ARG_T_NOUNDEF), 0, NULL)) !=
575 595 0) {
576 596 optarg = (char *)MSG_ORIG(MSG_ARG_DEFS);
577 597 return (c);
578 598
579 599 /*
580 600 * Translate --no-whole-archive to
581 601 * -z defaultextract
582 602 */
583 603 } else if ((c = str2chr(lml, ndx, argc, argv,
584 604 arg, 'z', MSG_ORIG(MSG_ARG_T_NOWHOLEARC),
585 605 0, NULL)) != 0) {
586 606 optarg =
587 607 (char *)MSG_ORIG(MSG_ARG_DFLEXTRT);
588 608 return (c);
589 609 }
590 610 break;
591 611 case 'o':
592 612 /* Translate --output <optarg> to -o <optarg> */
593 613 if ((c = str2chr(lml, ndx, argc, argv, arg, 'o',
594 614 MSG_ORIG(MSG_ARG_T_OUTPUT),
595 615 MSG_ARG_T_OUTPUT_SIZE, NULL)) != 0) {
596 616 return (c);
597 617 }
598 618 break;
599 619 case 'r':
600 620 /* Translate --relocatable to -r */
601 621 if ((c = str2chr(lml, ndx, argc, argv, arg, 'r',
602 622 MSG_ORIG(MSG_ARG_T_RELOCATABLE), 0,
603 623 NULL)) != 0) {
604 624 return (c);
605 625 }
606 626 break;
607 627 case 's':
608 628 /* Translate --strip-all to -s */
609 629 if ((c = str2chr(lml, ndx, argc, argv, arg, 's',
610 630 MSG_ORIG(MSG_ARG_T_STRIP), 0, NULL)) !=
611 631 0) {
612 632 return (c);
613 633 }
614 634 /*
615 635 * Translate --start-group to -z rescan-start
616 636 */
617 637 if ((c = str2chr(lml, ndx, argc, argv,
618 638 arg, 'z', MSG_ORIG(MSG_ARG_T_STARTGROUP),
619 639 0, NULL)) != 0) {
620 640 optarg = (char *)
621 641 MSG_ORIG(MSG_ARG_RESCAN_START);
622 642 return (c);
623 643 }
624 644 break;
625 645 case 'u':
626 646 /*
627 647 * Translate --undefined <optarg> to
628 648 * -u <optarg>
629 649 */
630 650 if ((c = str2chr(lml, ndx, argc, argv, arg, 'u',
631 651 MSG_ORIG(MSG_ARG_T_UNDEF),
632 652 MSG_ARG_T_UNDEF_SIZE, NULL)) != 0) {
633 653 return (c);
634 654 }
635 655 break;
636 656 case 'v':
637 657 /* Translate --version to -V */
638 658 if ((c = str2chr(lml, ndx, argc, argv, arg, 'V',
639 659 MSG_ORIG(MSG_ARG_T_VERSION), 0, NULL)) !=
640 660 0) {
641 661 return (c);
642 662 }
643 663 break;
644 664 case 'w':
645 665 /*
646 666 * Translate --whole-archive to -z alltextract
647 667 */
648 668 if ((c = str2chr(lml, ndx, argc, argv,
649 669 arg, 'z', MSG_ORIG(MSG_ARG_T_WHOLEARC),
650 670 0, NULL)) != 0) {
651 671 optarg =
652 672 (char *)MSG_ORIG(MSG_ARG_ALLEXTRT);
653 673 return (c);
654 674 }
655 675 /*
656 676 * Translate --wrap to -z wrap=
657 677 */
658 678 if ((c = str2chr(lml, ndx, argc, argv,
659 679 arg, 'z', MSG_ORIG(MSG_ARG_T_WRAP),
660 680 MSG_ARG_T_WRAP_SIZE, str2chr_wrap_cb)) !=
661 681 0) {
662 682 return (c);
663 683 }
664 684 break;
665 685 }
666 686 break;
667 687 }
668 688 }
669 689
670 690 if ((c = getopt(argc, argv, MSG_ORIG(MSG_STR_OPTIONS))) != -1) {
671 691 /*
672 692 * It is possible that a "-Wl," argument has been used to
673 693 * specify an option. This isn't advertized ld(1) syntax, but
674 694 * compiler drivers and configuration tools, have been known to
675 695 * pass this compiler option to ld(1). Strip off the "-Wl,"
676 696 * prefix and pass the option through.
677 697 */
678 698 if ((c == 'W') && (strncmp(optarg,
679 699 MSG_ORIG(MSG_ARG_T_WL), MSG_ARG_T_WL_SIZE) == 0)) {
680 700 DBG_CALL(Dbg_args_Wldel(lml, ndx, optarg));
681 701 c = optarg[MSG_ARG_T_WL_SIZE];
682 702 optarg += MSG_ARG_T_WL_SIZE + 1;
683 703 }
684 704 }
685 705
686 706 return (c);
687 707 }
688 708
689 709 /*
690 710 * A compare routine for Isd_node AVL trees.
691 711 */
692 712 int
693 713 isdavl_compare(const void *n1, const void *n2)
694 714 {
695 715 uint_t hash1, hash2;
696 716 const char *st1, *st2;
697 717 int rc;
698 718
699 719 hash1 = ((Isd_node *)n1)->isd_hash;
700 720 hash2 = ((Isd_node *)n2)->isd_hash;
701 721
702 722 if (hash1 > hash2)
703 723 return (1);
704 724 if (hash1 < hash2)
705 725 return (-1);
706 726
707 727 st1 = ((Isd_node *)n1)->isd_name;
708 728 st2 = ((Isd_node *)n2)->isd_name;
709 729
710 730 rc = strcmp(st1, st2);
711 731 if (rc > 0)
712 732 return (1);
713 733 if (rc < 0)
714 734 return (-1);
715 735 return (0);
716 736 }
717 737
718 738 /*
719 739 * Messaging support - funnel everything through dgettext().
720 740 */
721 741 const char *
722 742 _libld_msg(Msg mid)
723 743 {
724 744 return (dgettext(MSG_ORIG(MSG_SUNW_OST_SGS), MSG_ORIG(mid)));
725 745 }
726 746
727 747 /*
728 748 * Determine whether a symbol name should be demangled.
729 749 */
730 750 const char *
731 751 demangle(const char *name)
732 752 {
733 753 if (demangle_flag)
734 754 return (Elf_demangle_name(name));
735 755 else
736 756 return (name);
737 757 }
738 758
739 759 /*
740 760 * Compare a series of platform or machine hardware names.
741 761 */
742 762 int
743 763 cap_names_match(Alist *alp1, Alist *alp2)
744 764 {
745 765 Capstr *capstr1;
746 766 Aliste idx1;
747 767 int match = 0;
748 768 Word nitems;
749 769
750 770 if ((nitems = alist_nitems(alp1)) != alist_nitems(alp2))
751 771 return (1);
752 772
753 773 for (ALIST_TRAVERSE(alp1, idx1, capstr1)) {
754 774 Capstr *capstr2;
755 775 Aliste idx2;
756 776
757 777 for (ALIST_TRAVERSE(alp2, idx2, capstr2)) {
758 778 if (strcmp(capstr1->cs_str, capstr2->cs_str))
759 779 continue;
760 780
761 781 match++;
762 782 break;
763 783 }
764 784 }
765 785
766 786 if (nitems == match)
767 787 return (0);
768 788
769 789 return (1);
770 790 }
↓ open down ↓ |
200 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX