dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / sgs / ldd / common / ldd.c
blob07999de2ed1a87fdef9dbac1651420fc2ed7034e
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
21 * Copyright (c) 1988 AT&T
22 * All Rights Reserved
25 * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
29 * Print the list of shared objects required by a dynamic executable or shared
30 * object.
32 * usage is: ldd [-d | -r] [-c] [-D] [-e envar] [-i] [-f] [-L] [-l] [-p] [-s]
33 * [-U | -u] [-v] [-w] file(s)
35 * ldd opens the file and verifies the information in the elf header.
36 * If the file is a dynamic executable, we set up some environment variables
37 * and exec(2) the file. If the file is a shared object, we preload the
38 * file with a dynamic executable stub. The runtime linker (ld.so.1) actually
39 * provides the diagnostic output, according to the environment variables set.
41 * If neither -d nor -r is specified, we set only LD_TRACE_LOADED_OBJECTS_[AE].
42 * The runtime linker will print the pathnames of all dynamic objects it
43 * loads, and then exit. Note that we distiguish between ELF and AOUT objects
44 * when setting this environment variable - AOUT executables cause the mapping
45 * of sbcp, the dependencies of which the user isn't interested in.
47 * If -d or -r is specified, we also set LD_WARN=1; the runtime linker will
48 * perform its normal relocations and issue warning messages for unresolved
49 * references. It will then exit.
50 * If -r is specified, we set LD_BIND_NOW=1, so that the runtime linker
51 * will perform all relocations, otherwise (under -d) the runtime linker
52 * will not perform PLT (function) type relocations.
54 * If -c is specified we also set LD_NOCONFIG=1, thus disabling any
55 * configuration file use.
57 * If -D is specified we skip deferred dependency processing. By default,
58 * ldd loads all deferred dependencies. However, during normal process
59 * execution, deferred dependencies are only loaded when an explicit binding
60 * to an individual deferred reference is made. As no user code is executed
61 * under ldd, explicit references to deferred symbols can't be triggered.
63 * If -e is specified the associated environment variable is set for the
64 * child process that will produce ldd's diagnostics.
66 * If -i is specified, we set LD_INIT=1. The order of inititialization
67 * sections to be executed is printed. We also set LD_WARN=1.
69 * If -f is specified, we will run ldd as root on executables that have
70 * an unsercure runtime linker that does not live under the "/usr/lib"
71 * directory. By default we will not let this happen.
73 * If -l is specified it generates a warning for any auxiliary filter not found.
74 * Prior to 2.8 this forced any filters to load (all) their filtees. This is
75 * now the default, however missing auxiliary filters don't generate any error
76 * diagniostic. See also -L.
78 * If -L is specified we revert to lazy loading, thus any filtee or lazy
79 * dependency loading is deferred until relocations cause loading. Without
80 * this option we set LD_LOADFLTR=1, thus forcing any filters to load (all)
81 * their filtees, and LD_NOLAZYLOAD=1 thus forcing immediate processing of
82 * any lazy loaded dependencies.
84 * If -s is specified we also set LD_TRACE_SEARCH_PATH=1, thus enabling
85 * the runtime linker to indicate the search algorithm used.
87 * If -v is specified we also set LD_VERBOSE=1, thus enabling the runtime
88 * linker to indicate all object dependencies (not just the first object
89 * loaded) together with any versioning requirements.
91 * If -U or -u is specified unused dependencies are detected. -u causes
92 * LD_UNUSED=1 to be set, which causes dependencies that are unused within the
93 * process to be detected. -U causes LD_UNREF=1 to be set, which causes
94 * unreferenced objects, and unreferenced cyclic dependencies to be detected.
95 * These options assert that at least -d is set as relocation references are
96 * what determine an objects use.
98 * If -w is specified, no unresolved weak references are allowed. -w causes
99 * LD_NOUNRESWEAK=1 to be set. By default, an unresolved weak reference is
100 * allowed, and a "0" is written to the relocation offset. The -w option
101 * disables this default. Any weak references that can not be resolved result
102 * in relocation error messages. This option has no use without -r or -d.
104 * If the -p option is specified, no unresolved PARENT or EXTERN references are
105 * allowed. -p causes LD_NOPAREXT=1 to be set. By default, PARENT and EXTERN
106 * references, which have been explicitly assigned via a mapfile when a shared
107 * object was built, imply that a caller will provide the symbols, and hence
108 * these are not reported as relocation errors. Note, the -p option is asserted
109 * by default when either the -r or -d options are used to inspect a dynamic
110 * executable. This option has no use with a shared object without -r or -d.
112 #include <fcntl.h>
113 #include <stdio.h>
114 #include <string.h>
115 #include <_libelf.h>
116 #include <stdlib.h>
117 #include <unistd.h>
118 #include <wait.h>
119 #include <locale.h>
120 #include <errno.h>
121 #include <signal.h>
122 #include "machdep.h"
123 #include "sgs.h"
124 #include "conv.h"
125 #include "a.out.h"
126 #include "msg.h"
128 static int elf_check(int, char *, char *, Elf *, int);
129 static int aout_check(int, char *, char *, int, int);
130 static int run(int, char *, char *, const char *, int);
134 * Define all environment variable strings. The character following the "="
135 * will be written to, to disable or enable the associated feature.
137 static char bind[] = "LD_BIND_NOW= ",
138 load_elf[] = "LD_TRACE_LOADED_OBJECTS_E= ",
139 load_aout[] = "LD_TRACE_LOADED_OBJECTS_A= ",
140 path[] = "LD_TRACE_SEARCH_PATHS= ",
141 verb[] = "LD_VERBOSE= ",
142 warn[] = "LD_WARN= ",
143 conf[] = "LD_NOCONFIG= ",
144 fltr[] = "LD_LOADFLTR= ",
145 lazy[] = "LD_NOLAZYLOAD=1",
146 init[] = "LD_INIT= ",
147 uref[] = "LD_UNREF= ",
148 used[] = "LD_UNUSED= ",
149 weak[] = "LD_NOUNRESWEAK= ",
150 nope[] = "LD_NOPAREXT= ",
151 defr[] = "LD_DEFERRED= ";
152 static char *load;
154 static const char *prefile_32, *prefile_64, *prefile;
155 static APlist *eopts = NULL;
158 main(int argc, char **argv, char **envp)
160 char *str, *cname = argv[0];
162 Elf *elf;
163 int cflag = 0, dflag = 0, fflag = 0, iflag = 0, Lflag = 0;
164 int lflag = 0, rflag = 0, sflag = 0, Uflag = 0, uflag = 0;
165 int Dflag = 0, pflag = 0, vflag = 0, wflag = 0;
166 int nfile, var, error = 0;
167 Aliste idx;
170 * If we're on a 64-bit kernel, try to exec a full 64-bit version of
171 * the binary. If successful, conv_check_native() won't return.
173 * This is done to ensure that ldd can handle objects >2GB.
174 * ldd uses libelf, which is not large file capable. The
175 * 64-bit ldd can handle any sized object.
177 (void) conv_check_native(argv, envp);
180 * Establish locale.
182 (void) setlocale(LC_MESSAGES, MSG_ORIG(MSG_STR_EMPTY));
183 (void) textdomain(MSG_ORIG(MSG_SUNW_OST_SGS));
186 * verify command line syntax and process arguments
188 opterr = 0; /* disable getopt error mesg */
190 while ((var = getopt(argc, argv, MSG_ORIG(MSG_STR_GETOPT))) != EOF) {
191 switch (var) {
192 case 'c' : /* enable config search */
193 cflag = 1;
194 break;
195 case 'D' : /* skip deferred dependencies */
196 Dflag = 1;
197 break;
198 case 'd' : /* perform data relocations */
199 dflag = 1;
200 if (rflag)
201 error++;
202 break;
203 case 'e' :
204 if (aplist_append(&eopts, optarg, 10) == NULL) {
205 (void) fprintf(stderr, MSG_INTL(MSG_SYS_MALLOC),
206 cname);
207 exit(1);
209 break;
210 case 'f' :
211 fflag = 1;
212 break;
213 case 'L' :
214 Lflag = 1;
215 break;
216 case 'l' :
217 lflag = 1;
218 break;
219 case 'i' : /* print the order of .init */
220 iflag = 1;
221 break;
222 case 'p' :
223 pflag = 1; /* expose unreferenced */
224 break; /* parent or externals */
225 case 'r' : /* perform all relocations */
226 rflag = 1;
227 if (dflag)
228 error++;
229 break;
230 case 's' : /* enable search path output */
231 sflag = 1;
232 break;
233 case 'U' : /* list unreferenced */
234 Uflag = 1; /* dependencies */
235 if (uflag)
236 error++;
237 break;
238 case 'u' : /* list unused dependencies */
239 uflag = 1;
240 if (Uflag)
241 error++;
242 break;
243 case 'v' : /* enable verbose output */
244 vflag = 1;
245 break;
246 case 'w' : /* expose unresolved weak */
247 wflag = 1; /* references */
248 break;
249 default :
250 error++;
251 break;
253 if (error)
254 break;
256 if (error) {
257 (void) fprintf(stderr, MSG_INTL(MSG_ARG_USAGE), cname);
258 exit(1);
262 * Determine if any of the LD_PRELOAD family is already set in the
263 * environment, if so we'll continue to analyze each object with the
264 * appropriate setting.
266 if (((prefile_32 = getenv(MSG_ORIG(MSG_LD_PRELOAD_32))) == NULL) ||
267 (*prefile_32 == '\0')) {
268 prefile_32 = MSG_ORIG(MSG_STR_EMPTY);
270 if (((prefile_64 = getenv(MSG_ORIG(MSG_LD_PRELOAD_64))) == NULL) ||
271 (*prefile_64 == '\0')) {
272 prefile_64 = MSG_ORIG(MSG_STR_EMPTY);
274 if (((prefile = getenv(MSG_ORIG(MSG_LD_PRELOAD))) == NULL) ||
275 (*prefile == '\0')) {
276 prefile = MSG_ORIG(MSG_STR_EMPTY);
280 * Determine if any environment requests are for the LD_PRELOAD family,
281 * and if so override any environment settings we've established above.
283 for (APLIST_TRAVERSE(eopts, idx, str)) {
284 if ((strncmp(str, MSG_ORIG(MSG_LD_PRELOAD_32),
285 MSG_LD_PRELOAD_32_SIZE)) == 0) {
286 str += MSG_LD_PRELOAD_32_SIZE;
287 if ((*str++ == '=') && (*str != '\0'))
288 prefile_32 = str;
289 continue;
291 if ((strncmp(str, MSG_ORIG(MSG_LD_PRELOAD_64),
292 MSG_LD_PRELOAD_64_SIZE)) == 0) {
293 str += MSG_LD_PRELOAD_64_SIZE;
294 if ((*str++ == '=') && (*str != '\0'))
295 prefile_64 = str;
296 continue;
298 if ((strncmp(str, MSG_ORIG(MSG_LD_PRELOAD),
299 MSG_LD_PRELOAD_SIZE)) == 0) {
300 str += MSG_LD_PRELOAD_SIZE;
301 if ((*str++ == '=') && (*str != '\0'))
302 prefile = str;
303 continue;
308 * Set the appropriate relocation environment variables (Note unsetting
309 * the environment variables is done just in case the user already
310 * has these in their environment ... sort of thing the test folks
311 * would do :-)
313 warn[sizeof (warn) - 2] = (dflag || rflag || Uflag || uflag) ? '1' :
314 '\0';
315 bind[sizeof (bind) - 2] = (rflag) ? '1' : '\0';
316 path[sizeof (path) - 2] = (sflag) ? '1' : '\0';
317 verb[sizeof (verb) - 2] = (vflag) ? '1' : '\0';
318 fltr[sizeof (fltr) - 2] = (Lflag) ? '\0' : (lflag) ? '2' : '1';
319 init[sizeof (init) - 2] = (iflag) ? '1' : '\0';
320 conf[sizeof (conf) - 2] = (cflag) ? '1' : '\0';
321 lazy[sizeof (lazy) - 2] = (Lflag) ? '\0' : '1';
322 uref[sizeof (uref) - 2] = (Uflag) ? '1' : '\0';
323 used[sizeof (used) - 2] = (uflag) ? '1' : '\0';
324 weak[sizeof (weak) - 2] = (wflag) ? '1' : '\0';
325 nope[sizeof (nope) - 2] = (pflag) ? '1' : '\0';
326 defr[sizeof (defr) - 2] = (Dflag) ? '\0' : '1';
329 * coordinate libelf's version information
331 if (elf_version(EV_CURRENT) == EV_NONE) {
332 (void) fprintf(stderr, MSG_INTL(MSG_ELF_LIBELF), cname,
333 EV_CURRENT);
334 exit(1);
338 * Loop through remaining arguments. Note that from here on there
339 * are no exit conditions so that we can process a list of files,
340 * any error condition is retained for a final exit status.
342 nfile = argc - optind;
343 for (; optind < argc; optind++) {
344 char *fname = argv[optind];
347 * Open file (do this before checking access so that we can
348 * provide the user with better diagnostics).
350 if ((var = open(fname, O_RDONLY)) == -1) {
351 int err = errno;
352 (void) fprintf(stderr, MSG_INTL(MSG_SYS_OPEN), cname,
353 fname, strerror(err));
354 error = 1;
355 continue;
359 * Get the files elf descriptor and process it as an elf or
360 * a.out (4.x) file.
362 elf = elf_begin(var, ELF_C_READ, (Elf *)0);
363 switch (elf_kind(elf)) {
364 case ELF_K_AR :
365 (void) fprintf(stderr, MSG_INTL(MSG_USP_NODYNORSO),
366 cname, fname);
367 error = 1;
368 break;
369 case ELF_K_COFF:
370 (void) fprintf(stderr, MSG_INTL(MSG_USP_UNKNOWN),
371 cname, fname);
372 error = 1;
373 break;
374 case ELF_K_ELF:
375 if (elf_check(nfile, fname, cname, elf, fflag) != 0)
376 error = 1;
377 break;
378 default:
380 * This is either an unknown file or an aout format
382 if (aout_check(nfile, fname, cname, var, fflag) != 0)
383 error = 1;
384 break;
386 (void) elf_end(elf);
387 (void) close(var);
389 return (error);
394 static int
395 elf_check(int nfile, char *fname, char *cname, Elf *elf, int fflag)
397 Conv_inv_buf_t inv_buf;
398 GElf_Ehdr ehdr;
399 GElf_Phdr phdr;
400 int dynamic = 0, interp = 0, cnt, class;
403 * verify information in file header
405 if (gelf_getehdr(elf, &ehdr) == NULL) {
406 (void) fprintf(stderr, MSG_INTL(MSG_ELF_GETEHDR),
407 cname, fname, elf_errmsg(-1));
408 return (1);
412 * Compatible machine
414 if ((ehdr.e_machine != M_MACH_32) && (ehdr.e_machine != M_MACH_64) &&
415 (ehdr.e_machine != M_MACHPLUS)) {
416 (void) fprintf(stderr, MSG_INTL(MSG_ELF_MACHTYPE), cname, fname,
417 conv_ehdr_mach(ehdr.e_machine, 0, &inv_buf));
418 return (1);
422 * Compatible encoding (byte order)
424 if (ehdr.e_ident[EI_DATA] != M_DATA) {
425 (void) fprintf(stderr, MSG_INTL(MSG_ELF_DATA), cname, fname,
426 conv_ehdr_data(ehdr.e_ident[EI_DATA], 0, &inv_buf));
427 return (1);
431 * Compatible class
433 switch (class = ehdr.e_ident[EI_CLASS]) {
434 case ELFCLASS32:
436 * If M_MACH is not the same thing as M_MACHPLUS and this
437 * is an M_MACHPLUS object, then the corresponding header
438 * flag must be set.
440 if ((ehdr.e_machine != M_MACH) &&
441 ((ehdr.e_flags & M_FLAGSPLUS) == 0)) {
442 (void) fprintf(stderr, MSG_INTL(MSG_ELF_MACHFLAGS),
443 cname, fname);
444 return (1);
446 break;
447 case ELFCLASS64:
448 /* Requires 64-bit kernel */
449 if (conv_sys_eclass() == ELFCLASS32) {
450 (void) fprintf(stderr, MSG_INTL(MSG_ELF_KCLASS32),
451 cname, fname, conv_ehdr_class(class, 0, &inv_buf));
452 return (1);
454 break;
455 default:
456 (void) fprintf(stderr, MSG_INTL(MSG_ELF_CLASS), cname, fname,
457 conv_ehdr_class(class, 0, &inv_buf));
458 return (1);
462 * Object type
464 if ((ehdr.e_type != ET_EXEC) && (ehdr.e_type != ET_DYN) &&
465 (ehdr.e_type != ET_REL)) {
466 (void) fprintf(stderr, MSG_INTL(MSG_ELF_BADMAGIC),
467 cname, fname);
468 return (1);
472 * Check that the file is executable. Dynamic executables must be
473 * executable to be exec'ed. Shared objects need not be executable to
474 * be mapped with a dynamic executable.
476 if (access(fname, X_OK) != 0) {
477 if (ehdr.e_type == ET_EXEC) {
478 (void) fprintf(stderr, MSG_INTL(MSG_USP_NOTEXEC_1),
479 cname, fname);
480 return (1);
485 * Determine whether we have a dynamic section or interpretor.
487 for (cnt = 0; cnt < (int)ehdr.e_phnum; cnt++) {
488 if (dynamic && interp)
489 break;
491 if (gelf_getphdr(elf, cnt, &phdr) == NULL) {
492 (void) fprintf(stderr, MSG_INTL(MSG_ELF_GETPHDR),
493 cname, fname, elf_errmsg(-1));
494 return (1);
497 if (phdr.p_type == PT_DYNAMIC) {
498 dynamic = 1;
499 continue;
502 if (phdr.p_type != PT_INTERP)
503 continue;
505 interp = 1;
508 * If fflag is not set, and euid == root, and the interpreter
509 * does not live under /lib, /usr/lib or /etc/lib then don't
510 * allow ldd to execute the image. This prevents someone
511 * creating a `trojan horse' by substituting their own
512 * interpreter that could preform privileged operations
513 * when ldd is against it.
515 if ((fflag == 0) && (geteuid() == 0) &&
516 (strcmp(fname, conv_lddstub(class)) != 0)) {
517 char *interpreter;
520 * Does the interpreter live under a trusted directory.
522 interpreter = elf_getident(elf, 0) + phdr.p_offset;
524 if ((strncmp(interpreter, MSG_ORIG(MSG_PTH_USRLIB),
525 MSG_PTH_USRLIB_SIZE) != 0) &&
526 (strncmp(interpreter, MSG_ORIG(MSG_PTH_LIB),
527 MSG_PTH_LIB_SIZE) != 0) &&
528 (strncmp(interpreter, MSG_ORIG(MSG_PTH_ETCLIB),
529 MSG_PTH_ETCLIB_SIZE) != 0)) {
530 (void) fprintf(stderr, MSG_INTL(MSG_USP_ELFINS),
531 cname, fname, interpreter);
532 return (1);
538 * Catch the case of a static executable (ie, an ET_EXEC that has a set
539 * of program headers but no PT_DYNAMIC).
541 if (ehdr.e_phnum && !dynamic) {
542 (void) fprintf(stderr, MSG_INTL(MSG_USP_NODYNORSO), cname,
543 fname);
544 return (1);
548 * If there is a dynamic section, then check for the DF_1_NOHDR
549 * flag, and bail if it is present. Such objects are created using
550 * a mapfile option (?N in the version 1 syntax, or HDR_NOALLOC
551 * otherwise). The ELF header and program headers are
552 * not mapped as part of the first segment, and virtual addresses
553 * are computed without them. If ldd tries to interpret such
554 * a file, it will become confused and generate bad output or
555 * crash. Such objects are always special purpose files (like an OS
556 * kernel) --- files for which the ldd operation doesn't make sense.
558 if (dynamic && (_gelf_getdyndtflags_1(elf) & DF_1_NOHDR)) {
559 (void) fprintf(stderr, MSG_INTL(MSG_USP_NOHDR), cname,
560 fname);
561 return (1);
564 load = load_elf;
567 * Run the required program (shared and relocatable objects require the
568 * use of lddstub).
570 if ((ehdr.e_type == ET_EXEC) && interp)
571 return (run(nfile, cname, fname, (const char *)fname, class));
572 else
573 return (run(nfile, cname, fname, conv_lddstub(class), class));
576 static int
577 aout_check(int nfile, char *fname, char *cname, int fd, int fflag)
579 struct exec32 aout;
580 int err;
582 if (lseek(fd, 0, SEEK_SET) != 0) {
583 err = errno;
584 (void) fprintf(stderr, MSG_INTL(MSG_SYS_LSEEK), cname, fname,
585 strerror(err));
586 return (1);
588 if (read(fd, (char *)&aout, sizeof (aout)) != sizeof (aout)) {
589 err = errno;
590 (void) fprintf(stderr, MSG_INTL(MSG_SYS_READ), cname, fname,
591 strerror(err));
592 return (1);
594 if (aout.a_machtype != M_SPARC) {
595 (void) fprintf(stderr, MSG_INTL(MSG_USP_UNKNOWN), cname, fname);
596 return (1);
598 if (N_BADMAG(aout) || !aout.a_dynamic) {
599 (void) fprintf(stderr, MSG_INTL(MSG_USP_NODYNORSO), cname,
600 fname);
601 return (1);
603 if (!fflag && (geteuid() == 0)) {
604 (void) fprintf(stderr, MSG_INTL(MSG_USP_AOUTINS), cname, fname);
605 return (1);
609 * Run the required program.
611 if ((aout.a_magic == ZMAGIC) && (aout.a_entry <= sizeof (aout))) {
612 load = load_elf;
613 return (run(nfile, cname, fname, conv_lddstub(ELFCLASS32),
614 ELFCLASS32));
615 } else {
616 load = load_aout;
617 return (run(nfile, cname, fname, (const char *)fname,
618 ELFCLASS32));
624 * Run the required program, setting the preload and trace environment
625 * variables accordingly.
627 static int
628 run(int nfile, char *cname, char *fname, const char *ename, int class)
630 const char *preload = 0;
631 int pid, status;
633 if ((pid = fork()) == -1) {
634 int err = errno;
635 (void) fprintf(stderr, MSG_INTL(MSG_SYS_FORK), cname,
636 strerror(err));
637 return (1);
640 if (pid) { /* parent */
641 while (wait(&status) != pid)
643 if (WIFSIGNALED(status) && ((WSIGMASK & status) != SIGPIPE)) {
644 (void) fprintf(stderr, MSG_INTL(MSG_SYS_EXEC), cname,
645 fname);
646 (void) fprintf(stderr, MSG_INTL(MSG_SYS_EXEC_SIG),
647 (WSIGMASK & status), ((status & WCOREFLG) ?
648 MSG_INTL(MSG_SYS_EXEC_CORE) :
649 MSG_ORIG(MSG_STR_EMPTY)));
650 status = 1;
651 } else if (WHIBYTE(status)) {
652 (void) fprintf(stderr, MSG_INTL(MSG_SYS_EXEC), cname,
653 fname);
654 (void) fprintf(stderr, MSG_INTL(MSG_SYS_EXEC_STAT),
655 WHIBYTE(status));
656 status = 1;
658 } else { /* child */
659 Aliste idx;
660 char *str;
661 size_t size;
664 * When using ldd(1) to analyze a shared object we preload the
665 * shared object with lddstub. Any additional preload
666 * requirements are added after the object being analyzed, this
667 * allows us to skip the first object but produce diagnostics
668 * for each other preloaded object.
670 if (fname != ename) {
671 char *str;
672 const char *files = prefile;
673 const char *format = MSG_ORIG(MSG_STR_FMT1);
675 for (str = fname; *str; str++)
676 if (*str == '/') {
677 format = MSG_ORIG(MSG_STR_FMT2);
678 break;
681 preload = MSG_ORIG(MSG_LD_PRELOAD);
684 * Determine which preload files and preload environment
685 * variable to use.
687 if (class == ELFCLASS64) {
688 if (prefile_64 != MSG_ORIG(MSG_STR_EMPTY)) {
689 files = prefile_64;
690 preload = MSG_ORIG(MSG_LD_PRELOAD_64);
692 } else {
693 if (prefile_32 != MSG_ORIG(MSG_STR_EMPTY)) {
694 files = prefile_32;
695 preload = MSG_ORIG(MSG_LD_PRELOAD_32);
699 if ((str = (char *)malloc(strlen(preload) +
700 strlen(fname) + strlen(files) + 5)) == 0) {
701 (void) fprintf(stderr, MSG_INTL(MSG_SYS_MALLOC),
702 cname);
703 exit(1);
706 (void) sprintf(str, format, preload, fname, files);
707 if (putenv(str) != 0) {
708 (void) fprintf(stderr, MSG_INTL(MSG_ENV_FAILED),
709 cname);
710 exit(1);
714 * The pointer "load" has be assigned to load_elf[] or
715 * load_aout[]. Use the size of load_elf[] as the size
716 * of load_aout[] is the same.
718 load[sizeof (load_elf) - 2] = '2';
719 } else
720 load[sizeof (load_elf) - 2] = '1';
724 * Establish new environment variables to affect the child
725 * process.
727 if ((putenv(warn) != 0) || (putenv(bind) != 0) ||
728 (putenv(path) != 0) || (putenv(verb) != 0) ||
729 (putenv(fltr) != 0) || (putenv(conf) != 0) ||
730 (putenv(init) != 0) || (putenv(lazy) != 0) ||
731 (putenv(uref) != 0) || (putenv(used) != 0) ||
732 (putenv(weak) != 0) || (putenv(load) != 0) ||
733 (putenv(nope) != 0) || (putenv(defr) != 0)) {
734 (void) fprintf(stderr, MSG_INTL(MSG_ENV_FAILED), cname);
735 exit(1);
739 * Establish explicit environment requires (but don't override
740 * any preload request established to process a shared object).
742 size = 0;
743 for (APLIST_TRAVERSE(eopts, idx, str)) {
744 if (preload) {
745 if (size == 0)
746 size = strlen(preload);
747 if ((strncmp(preload, str, size) == 0) &&
748 (str[size] == '=')) {
749 continue;
752 if (putenv(str) != 0) {
753 (void) fprintf(stderr, MSG_INTL(MSG_ENV_FAILED),
754 cname);
755 exit(1);
760 * Execute the object and let ld.so.1 do the rest.
762 if (nfile > 1)
763 (void) printf(MSG_ORIG(MSG_STR_FMT3), fname);
764 (void) fflush(stdout);
765 if ((execl(ename, ename, (char *)0)) == -1) {
766 (void) fprintf(stderr, MSG_INTL(MSG_SYS_EXEC), cname,
767 fname);
768 perror(ename);
769 _exit(0);
770 /* NOTREACHED */
773 return (status);
776 const char *
777 _ldd_msg(Msg mid)
779 return (gettext(MSG_ORIG(mid)));