1 /* Run time dynamic linker.
2 Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
25 #include <sys/mman.h> /* Check if MAP_ANON is defined. */
26 #include <stdio-common/_itoa.h>
29 #include "dynamic-link.h"
32 /* System-specific function to do initial startup for the dynamic linker.
33 After this, file access calls and getenv must work. This is responsible
34 for setting __libc_enable_secure if we need to be secure (e.g. setuid),
35 and for setting _dl_argc and _dl_argv, and then calling _dl_main. */
36 extern ElfW(Addr
) _dl_sysdep_start (void **start_argptr
,
37 void (*dl_main
) (const ElfW(Phdr
) *phdr
,
39 ElfW(Addr
) *user_entry
));
40 extern void _dl_sysdep_start_cleanup (void);
42 /* System-dependent function to read a file's whole contents
43 in the most convenient manner available. */
44 extern void *_dl_sysdep_read_whole_file (const char *filename
,
48 /* Helper function to handle errors while resolving symbols. */
49 static void print_unresolved (int errcode
, const char *objname
,
50 const char *errsting
);
52 /* Helper function to handle errors when a version is missing. */
53 static void print_missing_version (int errcode
, const char *objname
,
54 const char *errsting
);
59 const char *_dl_rpath
;
61 const char *_dl_platform
;
62 size_t _dl_platformlen
;
63 struct r_search_path
*_dl_search_paths
;
64 const char *_dl_profile
;
65 const char *_dl_profile_output
;
66 struct link_map
*_dl_profile_map
;
68 /* Set nonzero during loading and initialization of executable and
69 libraries, cleared before the executable's entry point runs. This
70 must not be initialized to nonzero, because the unused dynamic
71 linker loaded in for libc.so's "ld.so.1" dep will provide the
72 definition seen by libc.so's initializer; that value must be zero,
73 and will be since that dynamic linker's _dl_start and dl_main will
77 static void dl_main (const ElfW(Phdr
) *phdr
,
79 ElfW(Addr
) *user_entry
);
81 struct link_map _dl_rtld_map
;
82 struct libname_list _dl_rtld_libname
;
87 #error "sysdeps/MACHINE/dl-machine.h fails to define RTLD_START"
93 struct link_map bootstrap_map
;
95 /* This #define produces dynamic linking inline functions for
96 bootstrap relocation instead of general-purpose relocation. */
97 #define RTLD_BOOTSTRAP
98 #define RESOLVE(sym, version, flags) bootstrap_map.l_addr
99 #include "dynamic-link.h"
101 /* Figure out the run-time load address of the dynamic linker itself. */
102 bootstrap_map
.l_addr
= elf_machine_load_address ();
104 /* Read our own dynamic section and fill in the info array. */
105 bootstrap_map
.l_ld
= (void *) bootstrap_map
.l_addr
+ elf_machine_dynamic ();
106 elf_get_dynamic_info (bootstrap_map
.l_ld
, bootstrap_map
.l_info
);
108 #ifdef ELF_MACHINE_BEFORE_RTLD_RELOC
109 ELF_MACHINE_BEFORE_RTLD_RELOC (bootstrap_map
.l_info
);
112 /* Relocate ourselves so we can do normal function calls and
113 data access using the global offset table. */
115 ELF_DYNAMIC_RELOCATE (&bootstrap_map
, 0, 0);
117 /* Now life is sane; we can call functions and access global data.
118 Set up to use the operating system facilities, and find out from
119 the operating system's program loader where to find the program
120 header table in core. */
123 /* Transfer data about ourselves to the permanent link_map structure. */
124 _dl_rtld_map
.l_addr
= bootstrap_map
.l_addr
;
125 _dl_rtld_map
.l_ld
= bootstrap_map
.l_ld
;
126 memcpy (_dl_rtld_map
.l_info
, bootstrap_map
.l_info
,
127 sizeof _dl_rtld_map
.l_info
);
128 _dl_setup_hash (&_dl_rtld_map
);
130 /* Cache the DT_RPATH stored in ld.so itself; this will be
131 the default search path. */
132 _dl_rpath
= (void *) (_dl_rtld_map
.l_addr
+
133 _dl_rtld_map
.l_info
[DT_STRTAB
]->d_un
.d_ptr
+
134 _dl_rtld_map
.l_info
[DT_RPATH
]->d_un
.d_val
);
136 /* Call the OS-dependent function to set up life so we can do things like
137 file access. It will call `dl_main' (below) to do all the real work
138 of the dynamic linker, and then unwind our frame and run the user
139 entry point on the same stack we entered on. */
140 return _dl_sysdep_start (arg
, &dl_main
);
144 /* Now life is peachy; we can do all normal operations.
145 On to the real work. */
147 void ENTRY_POINT (void);
149 /* Some helper functions. */
151 /* Arguments to relocate_doit. */
160 /* Argument to map_doit. */
162 /* Return value of map_doit. */
163 struct link_map
*main_map
;
166 /* Arguments to version_check_doit. */
167 struct version_check_args
169 struct link_map
*main_map
;
174 relocate_doit (void *a
)
176 struct relocate_args
*args
= (struct relocate_args
*) a
;
178 _dl_relocate_object (args
->l
, _dl_object_relocation_scope (args
->l
),
185 struct map_args
*args
= (struct map_args
*)a
;
186 args
->main_map
= _dl_map_object (NULL
, args
->str
, lt_library
, 0);
190 version_check_doit (void *a
)
192 struct version_check_args
*args
= (struct version_check_args
*)a
;
193 if (_dl_check_all_versions (args
->main_map
, 1) && args
->doexit
)
194 /* We cannot start the application. Abort now. */
199 static inline struct link_map
*
200 find_needed (const char *name
)
204 for (n
= 0; n
< _dl_loaded
->l_nsearchlist
; ++n
)
205 if (_dl_name_match_p (name
, _dl_loaded
->l_searchlist
[n
]))
206 return _dl_loaded
->l_searchlist
[n
];
208 /* Should never happen. */
213 match_version (const char *string
, struct link_map
*map
)
215 const char *strtab
= (const char *) (map
->l_addr
216 + map
->l_info
[DT_STRTAB
]->d_un
.d_ptr
);
219 #define VERDEFTAG (DT_NUM + DT_PROCNUM + DT_VERSIONTAGIDX (DT_VERDEF))
220 if (map
->l_info
[VERDEFTAG
] == NULL
)
221 /* The file has no symbol versioning. */
224 def
= (ElfW(Verdef
) *) ((char *) map
->l_addr
225 + map
->l_info
[VERDEFTAG
]->d_un
.d_ptr
);
228 ElfW(Verdaux
) *aux
= (ElfW(Verdaux
) *) ((char *) def
+ def
->vd_aux
);
230 /* Compare the version strings. */
231 if (strcmp (string
, strtab
+ aux
->vda_name
) == 0)
235 /* If no more definitions we failed to find what we want. */
236 if (def
->vd_next
== 0)
239 /* Next definition. */
240 def
= (ElfW(Verdef
) *) ((char *) def
+ def
->vd_next
);
246 unsigned int _dl_skip_args
; /* Nonzero if we were run directly. */
249 dl_main (const ElfW(Phdr
) *phdr
,
251 ElfW(Addr
) *user_entry
)
253 const ElfW(Phdr
) *ph
;
254 struct link_map
*main_map
;
256 enum { normal
, list
, verify
, trace
} mode
;
257 struct link_map
**preloads
;
258 unsigned int npreloads
;
259 const char *preloadlist
;
264 mode
= getenv ("LD_TRACE_LOADED_OBJECTS") != NULL
? trace
: normal
;
265 _dl_verbose
= *(getenv ("LD_WARN") ?: "") == '\0' ? 0 : 1;
267 /* LAZY is determined by the environment variable LD_WARN and
268 LD_BIND_NOW if we trace the binary. */
271 ? (*(getenv ("LD_BIND_NOW") ?: "") == '\0' ? 1 : 0) : -1);
273 lazy
= !__libc_enable_secure
&& *(getenv ("LD_BIND_NOW") ?: "") == '\0';
275 /* See whether we want to use profiling. */
276 _dl_profile
= getenv ("LD_PROFILE");
277 if (_dl_profile
!= NULL
)
278 if (_dl_profile
[0] == '\0')
279 /* An empty string is of not much help. Disable profiling. */
283 /* OK, we have the name of a shared object we want to
284 profile. It's up to the user to provide a good name, it
285 must match the file name or soname of one of the loaded
286 objects. Now let's see where we are supposed to place the
288 _dl_profile_output
= getenv ("LD_PROFILE_OUTPUT");
290 if (_dl_profile_output
== NULL
|| _dl_profile_output
[0] == '\0')
291 /* This is the default place. */
292 _dl_profile_output
= "/var/tmp";
295 /* Set up a flag which tells we are just starting. */
298 if (*user_entry
== (ElfW(Addr
)) &ENTRY_POINT
)
300 /* Ho ho. We are not the program interpreter! We are the program
301 itself! This means someone ran ld.so as a command. Well, that
302 might be convenient to do sometimes. We support it by
303 interpreting the args like this:
305 ld.so PROGRAM ARGS...
307 The first argument is the name of a file containing an ELF
308 executable we will load and run with the following arguments.
309 To simplify life here, PROGRAM is searched for using the
310 normal rules for shared objects, rather than $PATH or anything
311 like that. We just load it and use its entry point; we don't
312 pay attention to its PT_INTERP command (we are the interpreter
313 ourselves). This is an easy way to test a new ld.so before
317 Usage: ld.so [--list|--verify] EXECUTABLE-FILE [ARGS-FOR-PROGRAM...]\n\
318 You have invoked `ld.so', the helper program for shared library executables.\n\
319 This program usually lives in the file `/lib/ld.so', and special directives\n\
320 in executable files using ELF shared libraries tell the system's program\n\
321 loader to load the helper program from this file. This helper program loads\n\
322 the shared libraries needed by the program executable, prepares the program\n\
323 to run, and runs it. You may invoke this helper program directly from the\n\
324 command line to load and run an ELF executable file; this is like executing\n\
325 that file itself, but always uses this helper program from the file you\n\
326 specified, instead of the helper program file specified in the executable\n\
327 file you run. This is mostly of use for maintainers to test new versions\n\
328 of this helper program; chances are you did not intend to run this program.\n",
331 /* Note the place where the dynamic linker actually came from. */
332 _dl_rtld_map
.l_name
= _dl_argv
[0];
335 if (! strcmp (_dl_argv
[1], "--list"))
338 lazy
= -1; /* This means do no dependency analysis. */
344 else if (! strcmp (_dl_argv
[1], "--verify"))
361 char *err_str
= NULL
;
362 const char *obj_name
__attribute__ ((unused
));
363 struct map_args args
;
365 args
.str
= _dl_argv
[0];
366 (void) _dl_catch_error (&err_str
, &obj_name
, map_doit
, &args
);
367 main_map
= args
.main_map
;
371 _exit (EXIT_FAILURE
);
375 main_map
= _dl_map_object (NULL
, _dl_argv
[0], lt_library
, 0);
377 phdr
= main_map
->l_phdr
;
378 phent
= main_map
->l_phnum
;
379 main_map
->l_name
= (char *) "";
380 *user_entry
= main_map
->l_entry
;
384 /* Create a link_map for the executable itself.
385 This will be what dlopen on "" returns. */
386 main_map
= _dl_new_object ((char *) "", "", lt_executable
);
387 if (main_map
== NULL
)
388 _dl_sysdep_fatal ("cannot allocate memory for link map\n", NULL
);
389 main_map
->l_phdr
= phdr
;
390 main_map
->l_phnum
= phent
;
391 main_map
->l_entry
= *user_entry
;
392 main_map
->l_opencount
= 1;
395 /* Scan the program header table for the dynamic section. */
396 for (ph
= phdr
; ph
< &phdr
[phent
]; ++ph
)
400 /* This tells us where to find the dynamic section,
401 which tells us everything we need to do. */
402 main_map
->l_ld
= (void *) main_map
->l_addr
+ ph
->p_vaddr
;
405 /* This "interpreter segment" was used by the program loader to
406 find the program interpreter, which is this program itself, the
407 dynamic linker. We note what name finds us, so that a future
408 dlopen call or DT_NEEDED entry, for something that wants to link
409 against the dynamic linker as a shared library, will know that
410 the shared object is already loaded. */
411 _dl_rtld_libname
.name
= (const char *) main_map
->l_addr
+ ph
->p_vaddr
;
412 _dl_rtld_libname
.next
= NULL
;
413 _dl_rtld_map
.l_libname
= &_dl_rtld_libname
;
417 if (! _dl_rtld_map
.l_libname
&& _dl_rtld_map
.l_name
)
419 /* We were invoked directly, so the program might not have a
421 _dl_rtld_libname
.name
= _dl_rtld_map
.l_name
;
422 _dl_rtld_libname
.next
= NULL
;
423 _dl_rtld_map
.l_libname
= &_dl_rtld_libname
;
426 assert (_dl_rtld_map
.l_libname
); /* How else did we get here? */
429 /* We were called just to verify that this is a dynamic executable
430 using us as the program interpreter. */
431 _exit (main_map
->l_ld
== NULL
? 1 : has_interp
? 0 : 2);
433 /* Extract the contents of the dynamic section for easy access. */
434 elf_get_dynamic_info (main_map
->l_ld
, main_map
->l_info
);
435 if (main_map
->l_info
[DT_HASH
])
436 /* Set up our cache of pointers into the hash table. */
437 _dl_setup_hash (main_map
);
439 /* Put the link_map for ourselves on the chain so it can be found by
440 name. Note that at this point the global chain of link maps contains
441 exactly one element, which is pointed to by main_map. */
442 if (! _dl_rtld_map
.l_name
)
443 /* If not invoked directly, the dynamic linker shared object file was
444 found by the PT_INTERP name. */
445 _dl_rtld_map
.l_name
= (char *) _dl_rtld_map
.l_libname
->name
;
446 _dl_rtld_map
.l_type
= lt_library
;
447 main_map
->l_next
= &_dl_rtld_map
;
448 _dl_rtld_map
.l_prev
= main_map
;
450 /* We have two ways to specify objects to preload: via environment
451 variable and via the file /etc/ld.so.preload. The later can also
452 be used when security is enabled. */
456 preloadlist
= getenv ("LD_PRELOAD");
459 /* The LD_PRELOAD environment variable gives a white space
460 separated list of libraries that are loaded before the
461 executable's dependencies and prepended to the global scope
462 list. If the binary is running setuid all elements
463 containing a '/' are ignored since it is insecure. */
464 char *list
= strdupa (preloadlist
);
466 while ((p
= strsep (&list
, " ")) != NULL
)
467 if (! __libc_enable_secure
|| strchr (p
, '/') == NULL
)
469 (void) _dl_map_object (NULL
, p
, lt_library
, 0);
474 /* Read the contents of the file. */
475 file
= _dl_sysdep_read_whole_file ("/etc/ld.so.preload", &file_size
,
476 PROT_READ
| PROT_WRITE
);
479 /* Parse the file. It contains names of libraries to be loaded,
480 separated by white spaces or `:'. It may also contain
481 comments introduced by `#'. */
486 /* Eliminate comments. */
491 char *comment
= memchr (runp
, '#', rest
);
495 rest
-= comment
- runp
;
498 while (--rest
> 0 && *++comment
!= '\n');
501 /* We have one problematic case: if we have a name at the end of
502 the file without a trailing terminating characters, we cannot
503 place the \0. Handle the case separately. */
504 if (file
[file_size
- 1] != ' ' && file
[file_size
] != '\t'
505 && file
[file_size
] != '\n')
507 problem
= &file
[file_size
];
508 while (problem
> file
&& problem
[-1] != ' ' && problem
[-1] != '\t'
509 && problem
[-1] != '\n')
522 while ((p
= strsep (&runp
, ": \t\n")) != NULL
)
524 (void) _dl_map_object (NULL
, p
, lt_library
, 0);
531 char *p
= strndupa (problem
, file_size
- (problem
- file
));
532 (void) _dl_map_object (NULL
, p
, lt_library
, 0);
535 /* We don't need the file anymore. */
536 __munmap (file
, file_size
);
541 /* Set up PRELOADS with a vector of the preloaded libraries. */
544 preloads
= __alloca (npreloads
* sizeof preloads
[0]);
545 l
= _dl_rtld_map
.l_next
; /* End of the chain before preloads. */
552 assert (i
== npreloads
);
555 /* Initialize the data structures for the search paths for shared
559 /* Load all the libraries specified by DT_NEEDED entries. If LD_PRELOAD
560 specified some libraries to load, these are inserted before the actual
561 dependencies in the executable's searchlist for symbol resolution. */
562 _dl_map_object_deps (main_map
, preloads
, npreloads
, mode
== trace
);
565 /* We are done mapping things, so close the zero-fill descriptor. */
566 __close (_dl_zerofd
);
570 /* Remove _dl_rtld_map from the chain. */
571 _dl_rtld_map
.l_prev
->l_next
= _dl_rtld_map
.l_next
;
572 if (_dl_rtld_map
.l_next
)
573 _dl_rtld_map
.l_next
->l_prev
= _dl_rtld_map
.l_prev
;
575 if (_dl_rtld_map
.l_opencount
)
577 /* Some DT_NEEDED entry referred to the interpreter object itself, so
578 put it back in the list of visible objects. We insert it into the
579 chain in symbol search order because gdb uses the chain's order as
580 its symbol search order. */
582 while (main_map
->l_searchlist
[i
] != &_dl_rtld_map
)
584 _dl_rtld_map
.l_prev
= main_map
->l_searchlist
[i
- 1];
585 _dl_rtld_map
.l_next
= (i
+ 1 < main_map
->l_nsearchlist
?
586 main_map
->l_searchlist
[i
+ 1] : NULL
);
587 assert (_dl_rtld_map
.l_prev
->l_next
== _dl_rtld_map
.l_next
);
588 _dl_rtld_map
.l_prev
->l_next
= &_dl_rtld_map
;
589 if (_dl_rtld_map
.l_next
)
591 assert (_dl_rtld_map
.l_next
->l_prev
== _dl_rtld_map
.l_prev
);
592 _dl_rtld_map
.l_next
->l_prev
= &_dl_rtld_map
;
596 /* Now let us see whether all libraries are available in the
599 struct version_check_args args
;
600 args
.doexit
= mode
== normal
;
601 args
.main_map
= main_map
;
602 _dl_receive_error (print_missing_version
, version_check_doit
, &args
);
607 /* We were run just to list the shared libraries. It is
608 important that we do this before real relocation, because the
609 functions we call below for output may no longer work properly
614 if (! _dl_loaded
->l_info
[DT_NEEDED
])
615 _dl_sysdep_message ("\t", "statically linked\n", NULL
);
620 for (l
= _dl_loaded
->l_next
; l
; l
= l
->l_next
)
621 if (l
->l_opencount
== 0)
622 /* The library was not found. */
623 _dl_sysdep_message ("\t", l
->l_libname
->name
, " => not found\n",
628 buf
[sizeof buf
- 1] = '\0';
629 bp
= _itoa (l
->l_addr
, &buf
[sizeof buf
- 1], 16, 0);
630 while ((size_t) (&buf
[sizeof buf
- 1] - bp
)
631 < sizeof l
->l_addr
* 2)
633 _dl_sysdep_message ("\t", l
->l_libname
->name
, " => ",
634 l
->l_name
, " (0x", bp
, ")\n", NULL
);
639 for (i
= 1; i
< _dl_argc
; ++i
)
641 const ElfW(Sym
) *ref
= NULL
;
642 ElfW(Addr
) loadbase
= _dl_lookup_symbol (_dl_argv
[i
], &ref
,
643 &_dl_default_scope
[2],
645 ELF_MACHINE_RELOC_NOPLT
);
647 buf
[sizeof buf
- 1] = '\0';
648 bp
= _itoa (ref
->st_value
, &buf
[sizeof buf
- 1], 16, 0);
649 while ((size_t) (&buf
[sizeof buf
- 1] - bp
) < sizeof loadbase
* 2)
651 _dl_sysdep_message (_dl_argv
[i
], " found at 0x", bp
, NULL
);
652 buf
[sizeof buf
- 1] = '\0';
653 bp
= _itoa (loadbase
, &buf
[sizeof buf
- 1], 16, 0);
654 while ((size_t) (&buf
[sizeof buf
- 1] - bp
) < sizeof loadbase
* 2)
656 _dl_sysdep_message (" in object at 0x", bp
, "\n", NULL
);
662 /* We have to do symbol dependency testing. */
663 struct relocate_args args
;
673 if (l
!= &_dl_rtld_map
&& l
->l_opencount
> 0)
676 _dl_receive_error (print_unresolved
, relocate_doit
,
678 *_dl_global_scope_end
= NULL
;
684 #define VERNEEDTAG (DT_NUM + DT_PROCNUM + DT_VERSIONTAGIDX (DT_VERNEED))
685 if (*(getenv ("LD_VERBOSE") ?: "") != '\0')
687 /* Print more information. This means here, print information
688 about the versions needed. */
690 struct link_map
*map
= _dl_loaded
;
692 for (map
= _dl_loaded
; map
!= NULL
; map
= map
->l_next
)
695 (const char *) (map
->l_addr
696 + map
->l_info
[DT_STRTAB
]->d_un
.d_ptr
);
697 ElfW(Dyn
) *dyn
= map
->l_info
[VERNEEDTAG
];
702 (ElfW(Verneed
) *) (map
->l_addr
+ dyn
->d_un
.d_ptr
);
706 _dl_sysdep_message ("\n\tVersion information:\n",
711 _dl_sysdep_message ("\t", (map
->l_name
[0]
713 : _dl_argv
[0]), ":\n",
719 struct link_map
*needed
;
721 needed
= find_needed (strtab
+ ent
->vn_file
);
722 aux
= (ElfW(Vernaux
) *) ((char *) ent
+ ent
->vn_aux
);
726 const char *fname
= NULL
;
728 _dl_sysdep_message ("\t\t",
729 strtab
+ ent
->vn_file
,
730 " (", strtab
+ aux
->vna_name
,
738 && match_version (strtab
+ aux
->vna_name
,
740 fname
= needed
->l_name
;
742 _dl_sysdep_message (fname
?: "not found", "\n",
745 if (aux
->vna_next
== 0)
746 /* No more symbols. */
750 aux
= (ElfW(Vernaux
) *) ((char *) aux
754 if (ent
->vn_next
== 0)
755 /* No more dependencies. */
758 /* Next dependency. */
759 ent
= (ElfW(Verneed
) *) ((char *) ent
771 /* Now we have all the objects loaded. Relocate them all except for
772 the dynamic linker itself. We do this in reverse order so that copy
773 relocs of earlier objects overwrite the data written by later
774 objects. We do not re-relocate the dynamic linker itself in this
775 loop because that could result in the GOT entries for functions we
776 call being changed, and that would break us. It is safe to relocate
777 the dynamic linker out of order because it has no copy relocs (we
778 know that because it is self-contained). */
786 if (l
!= &_dl_rtld_map
)
788 _dl_relocate_object (l
, _dl_object_relocation_scope (l
), lazy
);
789 *_dl_global_scope_end
= NULL
;
794 /* Do any necessary cleanups for the startup OS interface code.
795 We do these now so that no calls are made after rtld re-relocation
796 which might be resolved to different functions than we expect.
797 We cannot do this before relocating the other objects because
798 _dl_relocate_object might need to call `mprotect' for DT_TEXTREL. */
799 _dl_sysdep_start_cleanup ();
801 if (_dl_rtld_map
.l_opencount
> 0)
802 /* There was an explicit ref to the dynamic linker as a shared lib.
803 Re-relocate ourselves with user-controlled symbol definitions. */
804 _dl_relocate_object (&_dl_rtld_map
, &_dl_default_scope
[2], 0);
808 /* Initialize _r_debug. */
809 struct r_debug
*r
= _dl_debug_initialize (_dl_rtld_map
.l_addr
);
814 #ifdef ELF_MACHINE_DEBUG_SETUP
816 /* Some machines (e.g. MIPS) don't use DT_DEBUG in this way. */
818 ELF_MACHINE_DEBUG_SETUP (l
, r
);
819 ELF_MACHINE_DEBUG_SETUP (&_dl_rtld_map
, r
);
823 if (l
->l_info
[DT_DEBUG
])
824 /* There is a DT_DEBUG entry in the dynamic section. Fill it in
825 with the run-time address of the r_debug structure */
826 l
->l_info
[DT_DEBUG
]->d_un
.d_ptr
= (ElfW(Addr
)) r
;
828 /* Fill in the pointer in the dynamic linker's own dynamic section, in
829 case you run gdb on the dynamic linker directly. */
830 if (_dl_rtld_map
.l_info
[DT_DEBUG
])
831 _dl_rtld_map
.l_info
[DT_DEBUG
]->d_un
.d_ptr
= (ElfW(Addr
)) r
;
835 /* Notify the debugger that all objects are now mapped in. */
840 /* Now enable profiling if needed. */
841 if (_dl_profile_map
!= NULL
)
842 /* We must prepare the profiling. */
843 _dl_start_profile (_dl_profile_map
, _dl_profile_output
);
845 /* Once we return, _dl_sysdep_start will invoke
846 the DT_INIT functions and then *USER_ENTRY. */
849 /* This is a little helper function for resolving symbols while
850 tracing the binary. */
852 print_unresolved (int errcode
__attribute__ ((unused
)), const char *objname
,
853 const char *errstring
)
855 if (objname
[0] == '\0')
856 objname
= _dl_argv
[0] ?: "<main program>";
857 _dl_sysdep_error (errstring
, " (", objname
, ")\n", NULL
);
860 /* This is a little helper function for resolving symbols while
861 tracing the binary. */
863 print_missing_version (int errcode
__attribute__ ((unused
)),
864 const char *objname
, const char *errstring
)
866 _dl_sysdep_error (_dl_argv
[0] ?: "<program name unknown>", ": ",
867 objname
, ": ", errstring
, "\n", NULL
);