1 /* Map in a shared object's segments from the file.
2 Copyright (C) 1995,96,97,98,99,2000 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. */
29 #include <sys/param.h>
31 #include <sys/types.h>
32 #include "dynamic-link.h"
33 #include <stdio-common/_itoa.h>
37 /* On some systems, no flag bits are given to specify file mapping. */
42 /* The right way to map in the shared library files is MAP_COPY, which
43 makes a virtual copy of the data at the time of the mmap call; this
44 guarantees the mapped pages will be consistent even if the file is
45 overwritten. Some losing VM systems like Linux's lack MAP_COPY. All we
46 get is MAP_PRIVATE, which copies each page when it is modified; this
47 means if the file is overwritten, we may at some point get some pages
48 from the new version after starting with pages from the old version. */
50 # define MAP_COPY MAP_PRIVATE
53 /* Some systems link their relocatable objects for another base address
54 than 0. We want to know the base address for these such that we can
55 subtract this address from the segment addresses during mapping.
56 This results in a more efficient address space usage. Defaults to
57 zero for almost all systems. */
59 # define MAP_BASE_ADDR(l) 0
64 #if BYTE_ORDER == BIG_ENDIAN
65 # define byteorder ELFDATA2MSB
66 #elif BYTE_ORDER == LITTLE_ENDIAN
67 # define byteorder ELFDATA2LSB
69 # error "Unknown BYTE_ORDER " BYTE_ORDER
70 # define byteorder ELFDATANONE
73 #define STRING(x) __STRING (x)
76 /* The fd is not examined when using MAP_ANON. */
80 # define ANONFD _dl_zerofd
83 /* Handle situations where we have a preferred location in memory for
84 the shared objects. */
85 #ifdef ELF_PREFERRED_ADDRESS_DATA
86 ELF_PREFERRED_ADDRESS_DATA
;
88 #ifndef ELF_PREFERRED_ADDRESS
89 # define ELF_PREFERRED_ADDRESS(loader, maplength, mapstartpref) (mapstartpref)
91 #ifndef ELF_FIXED_ADDRESS
92 # define ELF_FIXED_ADDRESS(loader, mapstart) ((void) 0)
97 extern const char *_dl_platform
;
98 extern size_t _dl_platformlen
;
100 /* This is the decomposed LD_LIBRARY_PATH search path. */
101 static struct r_search_path_struct env_path_list
;
103 /* List of the hardware capabilities we might end up using. */
104 static const struct r_strlenpair
*capstr
;
105 static size_t ncapstr
;
106 static size_t max_capstrlen
;
108 const unsigned char _dl_pf_to_prot
[8] =
113 [PF_R
| PF_W
] = PROT_READ
| PROT_WRITE
,
115 [PF_R
| PF_X
] = PROT_READ
| PROT_EXEC
,
116 [PF_W
| PF_X
] = PROT_WRITE
| PROT_EXEC
,
117 [PF_R
| PF_W
| PF_X
] = PROT_READ
| PROT_WRITE
| PROT_EXEC
121 /* Get the generated information about the trusted directories. */
122 #include "trusted-dirs.h"
124 static const char system_dirs
[] = SYSTEM_DIRS
;
125 static const size_t system_dirs_len
[] =
129 #define nsystem_dirs_len \
130 (sizeof (system_dirs_len) / sizeof (system_dirs_len[0]))
133 /* Local version of `strdup' function. */
135 local_strdup (const char *s
)
137 size_t len
= strlen (s
) + 1;
138 void *new = malloc (len
);
143 return (char *) memcpy (new, s
, len
);
148 _dl_dst_count (const char *name
, int is_path
)
150 const char *const start
= name
;
157 /* $ORIGIN is not expanded for SUID/GUID programs.
159 Note that it is no bug that the strings in the first two `strncmp'
160 calls are longer than the sequence which is actually tested. */
161 if ((((strncmp (&name
[1], "ORIGIN}", 6) == 0
162 && (!__libc_enable_secure
163 || ((name
[7] == '\0' || (is_path
&& name
[7] == ':'))
164 && (name
== start
|| (is_path
&& name
[-1] == ':'))))
166 || (strncmp (&name
[1], "PLATFORM}", 8) == 0 && (len
= 9) != 0))
167 && (name
[len
] == '\0' || name
[len
] == '/'
168 || (is_path
&& name
[len
] == ':')))
170 && ((strncmp (&name
[2], "ORIGIN}", 7) == 0
171 && (!__libc_enable_secure
172 || ((name
[9] == '\0' || (is_path
&& name
[9] == ':'))
173 && (name
== start
|| (is_path
&& name
[-1] == ':'))))
175 || (strncmp (&name
[2], "PLATFORM}", 9) == 0
176 && (len
= 11) != 0))))
179 name
= strchr (name
+ len
, '$');
181 while (name
!= NULL
);
188 _dl_dst_substitute (struct link_map
*l
, const char *name
, char *result
,
191 const char *const start
= name
;
192 char *last_elem
, *wp
;
194 /* Now fill the result path. While copying over the string we keep
195 track of the start of the last path element. When we come accross
196 a DST we copy over the value or (if the value is not available)
197 leave the entire path element out. */
198 last_elem
= wp
= result
;
207 /* Note that it is no bug that the strings in the first two `strncmp'
208 calls are longer than the sequence which is actually tested. */
209 if ((((strncmp (&name
[1], "ORIGIN}", 6) == 0 && (len
= 7) != 0)
210 || (strncmp (&name
[1], "PLATFORM}", 8) == 0 && (len
= 9) != 0))
211 && (name
[len
] == '\0' || name
[len
] == '/'
212 || (is_path
&& name
[len
] == ':')))
214 && ((strncmp (&name
[2], "ORIGIN}", 7) == 0 && (len
= 9) != 0)
215 || (strncmp (&name
[2], "PLATFORM}", 9) == 0
216 && (len
= 11) != 0))))
218 repl
= ((len
== 7 || name
[2] == 'O')
219 ? (__libc_enable_secure
220 && ((name
[len
] != '\0'
221 && (!is_path
|| name
[len
] != ':'))
223 && (!is_path
|| name
[-1] != ':')))
224 ? NULL
: l
->l_origin
)
227 if (repl
!= NULL
&& repl
!= (const char *) -1)
229 wp
= __stpcpy (wp
, repl
);
234 /* We cannot use this path element, the value of the
235 replacement is unknown. */
238 while (*name
!= '\0' && (!is_path
|| *name
!= ':'))
243 /* No DST we recognize. */
246 else if (is_path
&& *name
== ':')
254 while (*name
!= '\0');
262 /* Return copy of argument with all recognized dynamic string tokens
263 ($ORIGIN and $PLATFORM for now) replaced. On some platforms it
264 might not be possible to determine the path from which the object
265 belonging to the map is loaded. In this case the path element
266 containing $ORIGIN is left out. */
268 expand_dynamic_string_token (struct link_map
*l
, const char *s
)
270 /* We make two runs over the string. First we determine how large the
271 resulting string is and then we copy it over. Since this is now
272 frequently executed operation we are looking here not for performance
273 but rather for code size. */
278 /* Determine the number of DST elements. */
279 cnt
= DL_DST_COUNT (s
, 1);
281 /* If we do not have to replace anything simply copy the string. */
283 return local_strdup (s
);
285 /* Determine the length of the substituted string. */
286 total
= DL_DST_REQUIRED (l
, s
, strlen (s
), cnt
);
288 /* Allocate the necessary memory. */
289 result
= (char *) malloc (total
+ 1);
293 return DL_DST_SUBSTITUTE (l
, s
, result
, 1);
297 /* Add `name' to the list of names for a particular shared object.
298 `name' is expected to have been allocated with malloc and will
299 be freed if the shared object already has this name.
300 Returns false if the object already had this name. */
303 add_name_to_object (struct link_map
*l
, const char *name
)
305 struct libname_list
*lnp
, *lastp
;
306 struct libname_list
*newname
;
310 for (lnp
= l
->l_libname
; lnp
!= NULL
; lastp
= lnp
, lnp
= lnp
->next
)
311 if (strcmp (name
, lnp
->name
) == 0)
314 name_len
= strlen (name
) + 1;
315 newname
= (struct libname_list
*) malloc (sizeof *newname
+ name_len
);
318 /* No more memory. */
319 _dl_signal_error (ENOMEM
, name
, N_("cannot allocate name record"));
322 /* The object should have a libname set from _dl_new_object. */
323 assert (lastp
!= NULL
);
325 newname
->name
= memcpy (newname
+ 1, name
, name_len
);
326 newname
->next
= NULL
;
327 newname
->dont_free
= 0;
328 lastp
->next
= newname
;
331 /* All known directories in sorted order. */
332 struct r_search_path_elem
*_dl_all_dirs
;
334 /* All directories after startup. */
335 struct r_search_path_elem
*_dl_init_all_dirs
;
337 /* Standard search directories. */
338 static struct r_search_path_struct rtld_search_dirs
;
340 static size_t max_dirnamelen
;
342 static inline struct r_search_path_elem
**
343 fillin_rpath (char *rpath
, struct r_search_path_elem
**result
, const char *sep
,
344 int check_trusted
, const char *what
, const char *where
)
349 while ((cp
= __strsep (&rpath
, sep
)) != NULL
)
351 struct r_search_path_elem
*dirp
;
352 size_t len
= strlen (cp
);
354 /* `strsep' can pass an empty string. This has to be
355 interpreted as `use the current directory'. */
358 static const char curwd
[] = "./";
362 /* Remove trailing slashes (except for "/"). */
363 while (len
> 1 && cp
[len
- 1] == '/')
366 /* Now add one if there is none so far. */
367 if (len
> 0 && cp
[len
- 1] != '/')
370 /* See if this directory is already known. */
371 for (dirp
= _dl_all_dirs
; dirp
!= NULL
; dirp
= dirp
->next
)
372 if (dirp
->dirnamelen
== len
&& memcmp (cp
, dirp
->dirname
, len
) == 0)
377 /* It is available, see whether it's on our own list. */
379 for (cnt
= 0; cnt
< nelems
; ++cnt
)
380 if (result
[cnt
] == dirp
)
384 result
[nelems
++] = dirp
;
389 enum r_dir_status init_val
;
390 size_t where_len
= where
? strlen (where
) + 1 : 0;
392 /* It's a new directory. Create an entry and add it. */
393 dirp
= (struct r_search_path_elem
*)
394 malloc (sizeof (*dirp
) + ncapstr
* sizeof (enum r_dir_status
)
395 + where_len
+ len
+ 1);
397 _dl_signal_error (ENOMEM
, NULL
,
398 N_("cannot create cache for search path"));
400 dirp
->dirname
= ((char *) dirp
+ sizeof (*dirp
)
401 + ncapstr
* sizeof (enum r_dir_status
));
402 memcpy ((char *) dirp
->dirname
, cp
, len
+ 1);
403 dirp
->dirnamelen
= len
;
405 if (len
> max_dirnamelen
)
406 max_dirnamelen
= len
;
408 /* Make sure we don't use untrusted directories if we run SUID. */
409 if (__builtin_expect (check_trusted
, 0))
411 const char *trun
= system_dirs
;
414 /* By default we don't trust anything. */
415 init_val
= nonexisting
;
417 /* All trusted directories must be complete names. */
420 for (idx
= 0; idx
< nsystem_dirs_len
; ++idx
)
422 if (len
== system_dirs_len
[idx
]
423 && memcmp (trun
, cp
, len
) == 0)
427 trun
+= system_dirs_len
[idx
] + 1;
430 if (idx
< nsystem_dirs_len
)
431 /* It's a trusted directory so allow checking for it. */
436 /* We don't have to check for trusted directories and can
437 accept everything. We have to make sure all the
438 relative directories are never ignored. The current
439 directory might change and all our saved information
441 init_val
= cp
[0] != '/' ? existing
: unknown
;
443 for (cnt
= 0; cnt
< ncapstr
; ++cnt
)
444 dirp
->status
[cnt
] = init_val
;
447 if (__builtin_expect (where
!= NULL
, 1))
448 dirp
->where
= memcpy ((char *) dirp
+ sizeof (*dirp
) + len
+ 1
449 + ncapstr
* sizeof (enum r_dir_status
),
454 dirp
->next
= _dl_all_dirs
;
457 /* Put it in the result array. */
458 result
[nelems
++] = dirp
;
462 /* Terminate the array. */
463 result
[nelems
] = NULL
;
471 decompose_rpath (struct r_search_path_struct
*sps
,
472 const char *rpath
, struct link_map
*l
, const char *what
)
474 /* Make a copy we can work with. */
475 const char *where
= l
->l_name
;
478 struct r_search_path_elem
**result
;
481 /* First see whether we must forget the RUNPATH and RPATH from this
483 if (__builtin_expect (_dl_inhibit_rpath
!= NULL
, 0) && !__libc_enable_secure
)
485 const char *found
= strstr (_dl_inhibit_rpath
, where
);
488 size_t len
= strlen (where
);
489 if ((found
== _dl_inhibit_rpath
|| found
[-1] == ':')
490 && (found
[len
] == '\0' || found
[len
] == ':'))
492 /* This object is on the list of objects for which the
493 RUNPATH and RPATH must not be used. */
494 result
= (struct r_search_path_elem
**)
495 malloc (sizeof (*result
));
497 _dl_signal_error (ENOMEM
, NULL
,
498 N_("cannot create cache for search path"));
509 /* Make a writable copy. At the same time expand possible dynamic
511 copy
= expand_dynamic_string_token (l
, rpath
);
513 _dl_signal_error (ENOMEM
, NULL
, N_("cannot create RUNPATH/RPATH copy"));
515 /* Count the number of necessary elements in the result array. */
517 for (cp
= copy
; *cp
!= '\0'; ++cp
)
521 /* Allocate room for the result. NELEMS + 1 is an upper limit for the
522 number of necessary entries. */
523 result
= (struct r_search_path_elem
**) malloc ((nelems
+ 1 + 1)
526 _dl_signal_error (ENOMEM
, NULL
, N_("cannot create cache for search path"));
528 fillin_rpath (copy
, result
, ":", 0, what
, where
);
530 /* Free the copied RPATH string. `fillin_rpath' make own copies if
535 /* The caller will change this value if we haven't used a real malloc. */
542 _dl_init_paths (const char *llp
)
546 struct r_search_path_elem
*pelem
, **aelem
;
552 /* Fill in the information about the application's RPATH and the
553 directories addressed by the LD_LIBRARY_PATH environment variable. */
555 /* Get the capabilities. */
556 capstr
= _dl_important_hwcaps (_dl_platform
, _dl_platformlen
,
557 &ncapstr
, &max_capstrlen
);
559 /* First set up the rest of the default search directory entries. */
560 aelem
= rtld_search_dirs
.dirs
= (struct r_search_path_elem
**)
561 malloc ((nsystem_dirs_len
+ 1) * sizeof (struct r_search_path_elem
*));
562 if (rtld_search_dirs
.dirs
== NULL
)
563 _dl_signal_error (ENOMEM
, NULL
, N_("cannot create search path array"));
565 round_size
= ((2 * sizeof (struct r_search_path_elem
) - 1
566 + ncapstr
* sizeof (enum r_dir_status
))
567 / sizeof (struct r_search_path_elem
));
569 rtld_search_dirs
.dirs
[0] = (struct r_search_path_elem
*)
570 malloc ((sizeof (system_dirs
) / sizeof (system_dirs
[0]))
571 * round_size
* sizeof (struct r_search_path_elem
));
572 if (rtld_search_dirs
.dirs
[0] == NULL
)
573 _dl_signal_error (ENOMEM
, NULL
, N_("cannot create cache for search path"));
575 rtld_search_dirs
.malloced
= 0;
576 pelem
= _dl_all_dirs
= rtld_search_dirs
.dirs
[0];
586 pelem
->what
= "system search path";
589 pelem
->dirname
= strp
;
590 pelem
->dirnamelen
= system_dirs_len
[idx
];
591 strp
+= system_dirs_len
[idx
] + 1;
593 /* System paths must be absolute. */
594 assert (pelem
->dirname
[0] == '/');
595 for (cnt
= 0; cnt
< ncapstr
; ++cnt
)
596 pelem
->status
[cnt
] = unknown
;
598 pelem
->next
= (++idx
== nsystem_dirs_len
? NULL
: (pelem
+ round_size
));
602 while (idx
< nsystem_dirs_len
);
604 max_dirnamelen
= SYSTEM_DIRS_MAX_LEN
;
608 /* This points to the map of the main object. */
612 assert (l
->l_type
!= lt_loaded
);
614 if (l
->l_info
[DT_RUNPATH
])
616 /* Allocate room for the search path and fill in information
618 decompose_rpath (&l
->l_runpath_dirs
,
619 (const void *) (D_PTR (l
, l_info
[DT_STRTAB
])
620 + l
->l_info
[DT_RUNPATH
]->d_un
.d_val
),
623 /* The RPATH is ignored. */
624 l
->l_rpath_dirs
.dirs
= (void *) -1;
628 l
->l_runpath_dirs
.dirs
= (void *) -1;
630 if (l
->l_info
[DT_RPATH
])
632 /* Allocate room for the search path and fill in information
634 decompose_rpath (&l
->l_rpath_dirs
,
635 (const void *) (D_PTR (l
, l_info
[DT_STRTAB
])
636 + l
->l_info
[DT_RPATH
]->d_un
.d_val
),
638 l
->l_rpath_dirs
.malloced
= 0;
641 l
->l_rpath_dirs
.dirs
= (void *) -1;
646 if (llp
!= NULL
&& *llp
!= '\0')
649 const char *cp
= llp
;
651 /* Decompose the LD_LIBRARY_PATH contents. First determine how many
656 if (*cp
== ':' || *cp
== ';')
661 env_path_list
.dirs
= (struct r_search_path_elem
**)
662 malloc ((nllp
+ 1) * sizeof (struct r_search_path_elem
*));
663 if (env_path_list
.dirs
== NULL
)
664 _dl_signal_error (ENOMEM
, NULL
,
665 N_("cannot create cache for search path"));
667 (void) fillin_rpath (strdupa (llp
), env_path_list
.dirs
, ":;",
668 __libc_enable_secure
, "LD_LIBRARY_PATH", NULL
);
670 if (env_path_list
.dirs
[0] == NULL
)
672 free (env_path_list
.dirs
);
673 env_path_list
.dirs
= (void *) -1;
676 env_path_list
.malloced
= 0;
679 env_path_list
.dirs
= (void *) -1;
681 /* Remember the last search directory added at startup. */
682 _dl_init_all_dirs
= _dl_all_dirs
;
686 /* Think twice before changing anything in this function. It is placed
687 here and prepared using the `alloca' magic to prevent it from being
688 inlined. The function is only called in case of an error. But then
689 performance does not count. The function used to be "inlinable" and
690 the compiled did so all the time. This increased the code size for
691 absolutely no good reason. */
692 #define LOSE(code, s) lose (code, fd, name, realname, l, s)
694 __attribute__ ((noreturn
))
695 lose (int code
, int fd
, const char *name
, char *realname
, struct link_map
*l
,
698 /* The use of `alloca' here looks ridiculous but it helps. The goal
699 is to avoid the function from being inlined. There is no official
700 way to do this so we use this trick. gcc never inlines functions
701 which use `alloca'. */
702 int *a
= alloca (sizeof (int));
704 (void) __close (a
[0]);
707 /* Remove the stillborn object from the list and free it. */
709 l
->l_prev
->l_next
= l
->l_next
;
711 l
->l_next
->l_prev
= l
->l_prev
;
716 _dl_signal_error (code
, name
, msg
);
720 /* Map in the shared object NAME, actually located in REALNAME, and already
723 #ifndef EXTERNAL_MAP_FROM_FD
727 _dl_map_object_from_fd (const char *name
, int fd
, char *realname
,
728 struct link_map
*loader
, int l_type
, int mode
)
730 /* This is the expected ELF header. */
731 #define ELF32_CLASS ELFCLASS32
732 #define ELF64_CLASS ELFCLASS64
733 #ifndef VALID_ELF_HEADER
734 # define VALID_ELF_HEADER(hdr,exp,size) (memcmp (hdr, exp, size) == 0)
735 # define VALID_ELF_OSABI(osabi) (osabi == ELFOSABI_SYSV)
736 # define VALID_ELF_ABIVERSION(ver) (ver == 0)
738 static const unsigned char expected
[EI_PAD
] =
744 [EI_CLASS
] = ELFW(CLASS
),
745 [EI_DATA
] = byteorder
,
746 [EI_VERSION
] = EV_CURRENT
,
747 [EI_OSABI
] = ELFOSABI_SYSV
,
750 struct link_map
*l
= NULL
;
752 inline caddr_t
map_segment (ElfW(Addr
) mapstart
, size_t len
,
753 int prot
, int fixed
, off_t offset
)
755 caddr_t mapat
= __mmap ((caddr_t
) mapstart
, len
, prot
,
756 fixed
|MAP_COPY
|MAP_FILE
,
758 if (mapat
== MAP_FAILED
)
759 LOSE (errno
, N_("failed to map segment from shared object"));
763 const ElfW(Ehdr
) *header
;
764 const ElfW(Phdr
) *phdr
;
765 const ElfW(Phdr
) *ph
;
772 /* Get file information. */
773 if (__fxstat64 (_STAT_VER
, fd
, &st
) < 0)
774 LOSE (errno
, N_("cannot stat shared object"));
776 /* Look again to see if the real name matched another already loaded. */
777 for (l
= _dl_loaded
; l
; l
= l
->l_next
)
778 if (l
->l_ino
== st
.st_ino
&& l
->l_dev
== st
.st_dev
)
782 /* The object is already loaded.
783 Just bump its reference count and return it. */
786 /* If the name is not in the list of names for this object add
789 add_name_to_object (l
, name
);
791 if (l
->l_initfini
!= NULL
)
792 for (i
= 1; l
->l_initfini
[i
] != NULL
; ++i
)
793 ++l
->l_initfini
[i
]->l_opencount
;
798 if (mode
& RTLD_NOLOAD
)
799 /* We are not supposed to load the object unless it is already
800 loaded. So return now. */
803 /* Print debugging message. */
804 if (__builtin_expect (_dl_debug_files
, 0))
805 _dl_debug_message (1, "file=", name
, "; generating link map\n", NULL
);
807 /* Read the header directly. */
808 readbuf
= alloca (_dl_pagesize
);
809 readlength
= __libc_read (fd
, readbuf
, _dl_pagesize
);
810 if (readlength
< (ssize_t
) sizeof (*header
))
811 LOSE (errno
, N_("cannot read file data"));
812 header
= (void *) readbuf
;
814 /* Check the header for basic validity. */
815 if (__builtin_expect (!VALID_ELF_HEADER (header
->e_ident
, expected
, EI_PAD
),
818 /* Something is wrong. */
819 if (*(Elf32_Word
*) &header
->e_ident
!=
820 #if BYTE_ORDER == LITTLE_ENDIAN
821 ((ELFMAG0
<< (EI_MAG0
* 8)) |
822 (ELFMAG1
<< (EI_MAG1
* 8)) |
823 (ELFMAG2
<< (EI_MAG2
* 8)) |
824 (ELFMAG3
<< (EI_MAG3
* 8)))
826 ((ELFMAG0
<< (EI_MAG3
* 8)) |
827 (ELFMAG1
<< (EI_MAG2
* 8)) |
828 (ELFMAG2
<< (EI_MAG1
* 8)) |
829 (ELFMAG3
<< (EI_MAG0
* 8)))
832 LOSE (0, N_("invalid ELF header"));
833 if (header
->e_ident
[EI_CLASS
] != ELFW(CLASS
))
835 if (__ELF_NATIVE_CLASS
== 32)
836 LOSE (0, N_("ELF file class not 32-bit"));
838 LOSE (0, N_("ELF file class not 64-bit"));
840 if (header
->e_ident
[EI_DATA
] != byteorder
)
842 if (BYTE_ORDER
== BIG_ENDIAN
)
843 LOSE (0, "ELF file data encoding not big-endian");
845 LOSE (0, "ELF file data encoding not little-endian");
847 if (header
->e_ident
[EI_VERSION
] != EV_CURRENT
)
848 LOSE (0, N_("ELF file version ident does not match current one"));
849 /* XXX We should be able so set system specific versions which are
851 if (!VALID_ELF_OSABI (header
->e_ident
[EI_OSABI
]))
852 LOSE (0, N_("ELF file OS ABI invalid."));
853 if (!VALID_ELF_ABIVERSION (header
->e_ident
[EI_ABIVERSION
]))
854 LOSE (0, N_("ELF file ABI version invalid."));
855 LOSE (0, N_("internal error"));
858 if (__builtin_expect (header
->e_version
, EV_CURRENT
) != EV_CURRENT
)
859 LOSE (0, N_("ELF file version does not match current one"));
860 if (! __builtin_expect (elf_machine_matches_host (header
), 1))
861 LOSE (0, N_("ELF file machine architecture does not match"));
862 if (__builtin_expect (header
->e_phentsize
, sizeof (ElfW(Phdr
)))
863 != sizeof (ElfW(Phdr
)))
864 LOSE (0, N_("ELF file's phentsize not the expected size"));
868 if (_dl_zerofd
== -1)
870 _dl_zerofd
= _dl_sysdep_open_zero_fill ();
871 if (_dl_zerofd
== -1)
874 _dl_signal_error (errno
, NULL
, N_("cannot open zero fill device"));
879 /* Enter the new object in the list of loaded objects. */
880 l
= _dl_new_object (realname
, name
, l_type
, loader
);
881 if (__builtin_expect (! l
, 0))
882 LOSE (ENOMEM
, N_("cannot create shared object descriptor"));
885 /* Extract the remaining details we need from the ELF header
886 and then read in the program header table. */
887 l
->l_entry
= header
->e_entry
;
888 type
= header
->e_type
;
889 l
->l_phnum
= header
->e_phnum
;
891 maplength
= header
->e_phnum
* sizeof (ElfW(Phdr
));
892 if (header
->e_phoff
+ maplength
<= readlength
)
893 phdr
= (void *) (readbuf
+ header
->e_phoff
);
896 phdr
= alloca (maplength
);
897 __lseek (fd
, SEEK_SET
, header
->e_phoff
);
898 if (__libc_read (fd
, (void *) phdr
, maplength
) != maplength
)
899 LOSE (errno
, N_("cannot read file data"));
903 /* Scan the program header table, collecting its load commands. */
906 ElfW(Addr
) mapstart
, mapend
, dataend
, allocend
;
909 } loadcmds
[l
->l_phnum
], *c
;
910 size_t nloadcmds
= 0;
912 /* The struct is initialized to zero so this is not necessary:
916 for (ph
= phdr
; ph
< &phdr
[l
->l_phnum
]; ++ph
)
919 /* These entries tell us where to find things once the file's
920 segments are mapped in. We record the addresses it says
921 verbatim, and later correct for the run-time load address. */
923 l
->l_ld
= (void *) ph
->p_vaddr
;
924 l
->l_ldnum
= ph
->p_memsz
/ sizeof (ElfW(Dyn
));
927 l
->l_phdr
= (void *) ph
->p_vaddr
;
931 /* A load command tells us to map in part of the file.
932 We record the load commands and process them all later. */
933 if (ph
->p_align
% _dl_pagesize
!= 0)
934 LOSE (0, N_("ELF load command alignment not page-aligned"));
935 if ((ph
->p_vaddr
- ph
->p_offset
) % ph
->p_align
)
937 N_("ELF load command address/offset not properly aligned"));
939 struct loadcmd
*c
= &loadcmds
[nloadcmds
++];
940 c
->mapstart
= ph
->p_vaddr
& ~(ph
->p_align
- 1);
941 c
->mapend
= ((ph
->p_vaddr
+ ph
->p_filesz
+ _dl_pagesize
- 1)
942 & ~(_dl_pagesize
- 1));
943 c
->dataend
= ph
->p_vaddr
+ ph
->p_filesz
;
944 c
->allocend
= ph
->p_vaddr
+ ph
->p_memsz
;
945 c
->mapoff
= ph
->p_offset
& ~(ph
->p_align
- 1);
947 /* Optimize a common case. */
948 if ((PF_R
| PF_W
| PF_X
) == 7
949 && (PROT_READ
| PROT_WRITE
| PROT_EXEC
) == 7)
950 c
->prot
= _dl_pf_to_prot
[ph
->p_flags
& (PF_R
| PF_W
| PF_X
)];
954 if (ph
->p_flags
& PF_R
)
955 c
->prot
|= PROT_READ
;
956 if (ph
->p_flags
& PF_W
)
957 c
->prot
|= PROT_WRITE
;
958 if (ph
->p_flags
& PF_X
)
959 c
->prot
|= PROT_EXEC
;
965 /* Now process the load commands and map segments into memory. */
968 /* Length of the sections to be loaded. */
969 maplength
= loadcmds
[nloadcmds
- 1].allocend
- c
->mapstart
;
971 if (type
== ET_DYN
|| type
== ET_REL
)
973 /* This is a position-independent shared object. We can let the
974 kernel map it anywhere it likes, but we must have space for all
975 the segments in their specified positions relative to the first.
976 So we map the first segment without MAP_FIXED, but with its
977 extent increased to cover all the segments. Then we remove
978 access from excess portion, and there is known sufficient space
979 there to remap from the later segments.
981 As a refinement, sometimes we have an address that we would
982 prefer to map such objects at; but this is only a preference,
983 the OS can do whatever it likes. */
985 mappref
= (ELF_PREFERRED_ADDRESS (loader
, maplength
, c
->mapstart
)
986 - MAP_BASE_ADDR (l
));
988 /* Remember which part of the address space this object uses. */
989 l
->l_map_start
= (ElfW(Addr
)) map_segment (mappref
, maplength
, c
->prot
,
991 l
->l_map_end
= l
->l_map_start
+ maplength
;
992 l
->l_addr
= l
->l_map_start
- c
->mapstart
;
994 /* Change protection on the excess portion to disallow all access;
995 the portions we do not remap later will be inaccessible as if
996 unallocated. Then jump into the normal segment-mapping loop to
997 handle the portion of the segment past the end of the file
999 __mprotect ((caddr_t
) (l
->l_addr
+ c
->mapend
),
1000 loadcmds
[nloadcmds
- 1].allocend
- c
->mapend
,
1007 /* This object is loaded at a fixed address. This must never
1008 happen for objects loaded with dlopen(). */
1009 if (mode
& __RTLD_DLOPEN
)
1011 LOSE (0, N_("cannot dynamically load executable"));
1014 /* Notify ELF_PREFERRED_ADDRESS that we have to load this one
1016 ELF_FIXED_ADDRESS (loader
, c
->mapstart
);
1019 /* Remember which part of the address space this object uses. */
1020 l
->l_map_start
= c
->mapstart
+ l
->l_addr
;
1021 l
->l_map_end
= l
->l_map_start
+ maplength
;
1023 while (c
< &loadcmds
[nloadcmds
])
1025 if (c
->mapend
> c
->mapstart
)
1026 /* Map the segment contents from the file. */
1027 map_segment (l
->l_addr
+ c
->mapstart
, c
->mapend
- c
->mapstart
,
1028 c
->prot
, MAP_FIXED
, c
->mapoff
);
1032 && c
->mapoff
<= header
->e_phoff
1033 && (c
->mapend
- c
->mapstart
+ c
->mapoff
1034 >= header
->e_phoff
+ header
->e_phnum
* sizeof (ElfW(Phdr
))))
1035 /* Found the program header in this segment. */
1036 l
->l_phdr
= (void *) (c
->mapstart
+ header
->e_phoff
- c
->mapoff
);
1038 if (c
->allocend
> c
->dataend
)
1040 /* Extra zero pages should appear at the end of this segment,
1041 after the data mapped from the file. */
1042 ElfW(Addr
) zero
, zeroend
, zeropage
;
1044 zero
= l
->l_addr
+ c
->dataend
;
1045 zeroend
= l
->l_addr
+ c
->allocend
;
1046 zeropage
= (zero
+ _dl_pagesize
- 1) & ~(_dl_pagesize
- 1);
1048 if (zeroend
< zeropage
)
1049 /* All the extra data is in the last page of the segment.
1050 We can just zero it. */
1053 if (zeropage
> zero
)
1055 /* Zero the final part of the last page of the segment. */
1056 if ((c
->prot
& PROT_WRITE
) == 0)
1059 if (__mprotect ((caddr_t
) (zero
& ~(_dl_pagesize
- 1)),
1060 _dl_pagesize
, c
->prot
|PROT_WRITE
) < 0)
1061 LOSE (errno
, N_("cannot change memory protections"));
1063 memset ((void *) zero
, 0, zeropage
- zero
);
1064 if ((c
->prot
& PROT_WRITE
) == 0)
1065 __mprotect ((caddr_t
) (zero
& ~(_dl_pagesize
- 1)),
1066 _dl_pagesize
, c
->prot
);
1069 if (zeroend
> zeropage
)
1071 /* Map the remaining zero pages in from the zero fill FD. */
1073 mapat
= __mmap ((caddr_t
) zeropage
, zeroend
- zeropage
,
1074 c
->prot
, MAP_ANON
|MAP_PRIVATE
|MAP_FIXED
,
1076 if (mapat
== MAP_FAILED
)
1077 LOSE (errno
, N_("cannot map zero-fill pages"));
1084 if (l
->l_phdr
== NULL
)
1086 /* The program header is not contained in any of the segmenst.
1087 We have to allocate memory ourself and copy it over from
1088 out temporary place. */
1089 ElfW(Phdr
) *newp
= (ElfW(Phdr
) *) malloc (header
->e_phnum
1090 * sizeof (ElfW(Phdr
)));
1092 LOSE (ENOMEM
, N_("cannot allocate memory for program header"));
1094 l
->l_phdr
= memcpy (newp
, phdr
,
1095 (header
->e_phnum
* sizeof (ElfW(Phdr
))));
1096 l
->l_phdr_allocated
= 1;
1099 /* Adjust the PT_PHDR value by the runtime load address. */
1100 (ElfW(Addr
)) l
->l_phdr
+= l
->l_addr
;
1103 /* We are done mapping in the file. We no longer need the descriptor. */
1106 if (l
->l_type
== lt_library
&& type
== ET_EXEC
)
1107 l
->l_type
= lt_executable
;
1112 LOSE (0, N_("object file has no dynamic section"));
1115 (ElfW(Addr
)) l
->l_ld
+= l
->l_addr
;
1117 l
->l_entry
+= l
->l_addr
;
1119 if (__builtin_expect (_dl_debug_files
, 0))
1121 const size_t nibbles
= sizeof (void *) * 2;
1122 char buf1
[nibbles
+ 1];
1123 char buf2
[nibbles
+ 1];
1124 char buf3
[nibbles
+ 1];
1126 buf1
[nibbles
] = '\0';
1127 buf2
[nibbles
] = '\0';
1128 buf3
[nibbles
] = '\0';
1130 memset (buf1
, '0', nibbles
);
1131 memset (buf2
, '0', nibbles
);
1132 memset (buf3
, '0', nibbles
);
1133 _itoa_word ((unsigned long int) l
->l_ld
, &buf1
[nibbles
], 16, 0);
1134 _itoa_word ((unsigned long int) l
->l_addr
, &buf2
[nibbles
], 16, 0);
1135 _itoa_word (maplength
, &buf3
[nibbles
], 16, 0);
1137 _dl_debug_message (1, " dynamic: 0x", buf1
, " base: 0x", buf2
,
1138 " size: 0x", buf3
, "\n", NULL
);
1139 memset (buf1
, '0', nibbles
);
1140 memset (buf2
, '0', nibbles
);
1141 memset (buf3
, ' ', nibbles
);
1142 _itoa_word ((unsigned long int) l
->l_entry
, &buf1
[nibbles
], 16, 0);
1143 _itoa_word ((unsigned long int) l
->l_phdr
, &buf2
[nibbles
], 16, 0);
1144 _itoa_word (l
->l_phnum
, &buf3
[nibbles
], 10, 0);
1145 _dl_debug_message (1, " entry: 0x", buf1
, " phdr: 0x", buf2
,
1146 " phnum: ", buf3
, "\n\n", NULL
);
1149 elf_get_dynamic_info (l
);
1151 /* Make sure we are dlopen()ing an object which has the DF_1_NOOPEN
1153 if (__builtin_expect (l
->l_flags_1
& DF_1_NOOPEN
, 0)
1154 && (mode
& __RTLD_DLOPEN
))
1156 /* Remove from the module list. */
1157 assert (l
->l_next
== NULL
);
1159 if (l
->l_prev
== NULL
)
1160 /* No other module loaded. */
1164 l
->l_prev
->l_next
= NULL
;
1167 /* We are not supposed to load this object. Free all resources. */
1168 __munmap ((void *) l
->l_map_start
, l
->l_map_end
- l
->l_map_start
);
1170 free (l
->l_libname
);
1172 if (l
->l_phdr_allocated
)
1173 free ((void *) l
->l_phdr
);
1177 _dl_signal_error (0, name
, N_("shared object cannot be dlopen()ed"));
1180 if (l
->l_info
[DT_HASH
])
1183 /* If this object has DT_SYMBOLIC set modify now its scope. We don't
1184 have to do this for the main map. */
1185 if (__builtin_expect (l
->l_info
[DT_SYMBOLIC
] != NULL
, 0)
1186 && &l
->l_searchlist
!= l
->l_scope
[0])
1188 /* Create an appropriate searchlist. It contains only this map.
1190 XXX This is the definition of DT_SYMBOLIC in SysVr4. The old
1191 GNU ld.so implementation had a different interpretation which
1192 is more reasonable. We are prepared to add this possibility
1193 back as part of a GNU extension of the ELF format. */
1194 l
->l_symbolic_searchlist
.r_list
=
1195 (struct link_map
**) malloc (sizeof (struct link_map
*));
1197 if (l
->l_symbolic_searchlist
.r_list
== NULL
)
1198 LOSE (ENOMEM
, N_("cannot create searchlist"));
1200 l
->l_symbolic_searchlist
.r_list
[0] = l
;
1201 l
->l_symbolic_searchlist
.r_nlist
= 1;
1202 l
->l_symbolic_searchlist
.r_duplist
= l
->l_symbolic_searchlist
.r_list
;
1203 l
->l_symbolic_searchlist
.r_nduplist
= 1;
1205 /* Now move the existing entries one back. */
1206 memmove (&l
->l_scope
[1], &l
->l_scope
[0],
1207 sizeof (l
->l_scope
) - sizeof (l
->l_scope
[0]));
1209 /* Now add the new entry. */
1210 l
->l_scope
[0] = &l
->l_symbolic_searchlist
;
1213 /* Finally the file information. */
1214 l
->l_dev
= st
.st_dev
;
1215 l
->l_ino
= st
.st_ino
;
1220 /* Print search path. */
1222 print_search_path (struct r_search_path_elem
**list
,
1223 const char *what
, const char *name
)
1225 char buf
[max_dirnamelen
+ max_capstrlen
];
1228 _dl_debug_message (1, " search path=", NULL
);
1230 while (*list
!= NULL
&& (*list
)->what
== what
) /* Yes, ==. */
1232 char *endp
= __mempcpy (buf
, (*list
)->dirname
, (*list
)->dirnamelen
);
1235 for (cnt
= 0; cnt
< ncapstr
; ++cnt
)
1236 if ((*list
)->status
[cnt
] != nonexisting
)
1238 char *cp
= __mempcpy (endp
, capstr
[cnt
].str
, capstr
[cnt
].len
);
1239 if (cp
== buf
|| (cp
== buf
+ 1 && buf
[0] == '/'))
1243 _dl_debug_message (0, first
? "" : ":", buf
, NULL
);
1251 _dl_debug_message (0, "\t\t(", what
, " from file ",
1252 name
[0] ? name
: _dl_argv
[0], ")\n", NULL
);
1254 _dl_debug_message (0, "\t\t(", what
, ")\n", NULL
);
1257 /* Try to open NAME in one of the directories in *DIRSP.
1258 Return the fd, or -1. If successful, fill in *REALNAME
1259 with the malloc'd full directory name. If it turns out
1260 that none of the directories in *DIRSP exists, *DIRSP is
1261 replaced with (void *) -1, and the old value is free()d
1262 if MAY_FREE_DIRS is true. */
1265 open_path (const char *name
, size_t namelen
, int preloaded
,
1266 struct r_search_path_struct
*sps
, char **realname
)
1268 struct r_search_path_elem
**dirs
= sps
->dirs
;
1271 const char *current_what
= NULL
;
1274 buf
= alloca (max_dirnamelen
+ max_capstrlen
+ namelen
);
1277 struct r_search_path_elem
*this_dir
= *dirs
;
1282 /* If we are debugging the search for libraries print the path
1283 now if it hasn't happened now. */
1284 if (__builtin_expect (_dl_debug_libs
, 0)
1285 && current_what
!= this_dir
->what
)
1287 current_what
= this_dir
->what
;
1288 print_search_path (dirs
, current_what
, this_dir
->where
);
1291 edp
= (char *) __mempcpy (buf
, this_dir
->dirname
, this_dir
->dirnamelen
);
1292 for (cnt
= 0; fd
== -1 && cnt
< ncapstr
; ++cnt
)
1294 /* Skip this directory if we know it does not exist. */
1295 if (this_dir
->status
[cnt
] == nonexisting
)
1299 ((char *) __mempcpy (__mempcpy (edp
,
1300 capstr
[cnt
].str
, capstr
[cnt
].len
),
1304 /* Print name we try if this is wanted. */
1305 if (__builtin_expect (_dl_debug_libs
, 0))
1306 _dl_debug_message (1, " trying file=", buf
, "\n", NULL
);
1308 fd
= __open (buf
, O_RDONLY
);
1309 if (this_dir
->status
[cnt
] == unknown
)
1312 this_dir
->status
[cnt
] = existing
;
1315 /* We failed to open machine dependent library. Let's
1316 test whether there is any directory at all. */
1319 buf
[buflen
- namelen
- 1] = '\0';
1321 if (__xstat64 (_STAT_VER
, buf
, &st
) != 0
1322 || ! S_ISDIR (st
.st_mode
))
1323 /* The directory does not exist or it is no directory. */
1324 this_dir
->status
[cnt
] = nonexisting
;
1326 this_dir
->status
[cnt
] = existing
;
1330 /* Remember whether we found any existing directory. */
1331 any
|= this_dir
->status
[cnt
] == existing
;
1333 if (fd
!= -1 && preloaded
&& __libc_enable_secure
)
1335 /* This is an extra security effort to make sure nobody can
1336 preload broken shared objects which are in the trusted
1337 directories and so exploit the bugs. */
1340 if (__fxstat64 (_STAT_VER
, fd
, &st
) != 0
1341 || (st
.st_mode
& S_ISUID
) == 0)
1343 /* The shared object cannot be tested for being SUID
1344 or this bit is not set. In this case we must not
1348 /* We simply ignore the file, signal this by setting
1349 the error value which would have been set by `open'. */
1357 *realname
= malloc (buflen
);
1358 if (*realname
!= NULL
)
1360 memcpy (*realname
, buf
, buflen
);
1365 /* No memory for the name, we certainly won't be able
1366 to load and link it. */
1371 if (errno
!= ENOENT
&& errno
!= EACCES
)
1372 /* The file exists and is readable, but something went wrong. */
1375 while (*++dirs
!= NULL
);
1377 /* Remove the whole path if none of the directories exists. */
1380 /* Paths which were allocated using the minimal malloc() in ld.so
1381 must not be freed using the general free() in libc. */
1384 sps
->dirs
= (void *) -1;
1390 /* Map in the shared object file NAME. */
1394 _dl_map_object (struct link_map
*loader
, const char *name
, int preloaded
,
1395 int type
, int trace_mode
, int mode
)
1402 /* Look for this name among those already loaded. */
1403 for (l
= _dl_loaded
; l
; l
= l
->l_next
)
1407 /* If the requested name matches the soname of a loaded object,
1408 use that object. Elide this check for names that have not
1410 if (l
->l_opencount
<= 0)
1412 if (!_dl_name_match_p (name
, l
))
1416 if (l
->l_info
[DT_SONAME
] == NULL
)
1419 soname
= ((const char *) D_PTR (l
, l_info
[DT_STRTAB
])
1420 + l
->l_info
[DT_SONAME
]->d_un
.d_val
);
1421 if (strcmp (name
, soname
) != 0)
1424 /* We have a match on a new name -- cache it. */
1425 add_name_to_object (l
, soname
);
1428 /* We have a match -- bump the reference count and return it. */
1429 if (l
->l_initfini
!= NULL
)
1430 for (i
= 1; l
->l_initfini
[i
] != NULL
; ++i
)
1431 ++l
->l_initfini
[i
]->l_opencount
;
1436 /* Display information if we are debugging. */
1437 if (__builtin_expect (_dl_debug_files
, 0) && loader
!= NULL
)
1438 _dl_debug_message (1, "\nfile=", name
, "; needed by ",
1439 loader
->l_name
[0] ? loader
->l_name
: _dl_argv
[0],
1442 if (strchr (name
, '/') == NULL
)
1444 /* Search for NAME in several places. */
1446 size_t namelen
= strlen (name
) + 1;
1448 if (__builtin_expect (_dl_debug_libs
, 0))
1449 _dl_debug_message (1, "find library=", name
, "; searching\n", NULL
);
1453 /* When the object has the RUNPATH information we don't use any
1455 if (loader
== NULL
|| loader
->l_info
[DT_RUNPATH
] == NULL
)
1457 /* First try the DT_RPATH of the dependent object that caused NAME
1458 to be loaded. Then that object's dependent, and on up. */
1459 for (l
= loader
; fd
== -1 && l
; l
= l
->l_loader
)
1461 if (l
->l_rpath_dirs
.dirs
== NULL
)
1463 if (l
->l_info
[DT_RPATH
] == NULL
)
1464 /* There is no path. */
1465 l
->l_rpath_dirs
.dirs
= (void *) -1;
1468 /* Make sure the cache information is available. */
1469 size_t ptrval
= (D_PTR (l
, l_info
[DT_STRTAB
])
1470 + l
->l_info
[DT_RPATH
]->d_un
.d_val
);
1471 decompose_rpath (&l
->l_rpath_dirs
,
1472 (const char *) ptrval
, l
, "RPATH");
1474 if (l
->l_rpath_dirs
.dirs
!= (void *) -1)
1475 fd
= open_path (name
, namelen
, preloaded
,
1476 &l
->l_rpath_dirs
, &realname
);
1479 else if (l
->l_rpath_dirs
.dirs
!= (void *) -1)
1480 fd
= open_path (name
, namelen
, preloaded
, &l
->l_rpath_dirs
,
1484 /* If dynamically linked, try the DT_RPATH of the executable
1487 if (fd
== -1 && l
&& l
->l_type
!= lt_loaded
&& l
!= loader
1488 && l
->l_rpath_dirs
.dirs
!= (void *) -1)
1489 fd
= open_path (name
, namelen
, preloaded
, &l
->l_rpath_dirs
,
1493 /* Try the LD_LIBRARY_PATH environment variable. */
1494 if (fd
== -1 && env_path_list
.dirs
!= (void *) -1)
1495 fd
= open_path (name
, namelen
, preloaded
, &env_path_list
,
1498 /* Look at the RUNPATH informaiton for this binary. */
1499 if (loader
!= NULL
&& loader
->l_runpath_dirs
.dirs
!= (void *) -1)
1501 if (loader
->l_runpath_dirs
.dirs
== NULL
)
1503 if (loader
->l_info
[DT_RUNPATH
] == NULL
)
1505 loader
->l_runpath_dirs
.dirs
= (void *) -1;
1508 /* Make sure the cache information is available. */
1509 size_t ptrval
= (D_PTR (loader
, l_info
[DT_STRTAB
])
1510 + loader
->l_info
[DT_RUNPATH
]->d_un
.d_val
);
1511 decompose_rpath (&loader
->l_runpath_dirs
,
1512 (const char *) ptrval
, loader
, "RUNPATH");
1514 if (loader
->l_runpath_dirs
.dirs
!= (void *) -1)
1515 fd
= open_path (name
, namelen
, preloaded
,
1516 &loader
->l_runpath_dirs
, &realname
);
1519 else if (loader
->l_runpath_dirs
.dirs
!= (void *) -1)
1520 fd
= open_path (name
, namelen
, preloaded
,
1521 &loader
->l_runpath_dirs
, &realname
);
1526 /* Check the list of libraries in the file /etc/ld.so.cache,
1527 for compatibility with Linux's ldconfig program. */
1528 extern const char *_dl_load_cache_lookup (const char *name
);
1529 const char *cached
= _dl_load_cache_lookup (name
);
1532 l
= loader
?: _dl_loaded
;
1539 /* If the loader has the DF_1_NODEFLIB flag set we must not
1540 use a cache entry from any of these directories. */
1541 if (l
&& __builtin_expect (l
->l_flags_1
& DF_1_NODEFLIB
, 0))
1543 const char *dirp
= system_dirs
;
1548 if (memcmp (cached
, dirp
, system_dirs_len
[cnt
]) == 0)
1550 /* The prefix matches. Don't use the entry. */
1555 dirp
+= system_dirs_len
[cnt
] + 1;
1558 while (cnt
< nsystem_dirs_len
);
1563 fd
= __open (cached
, O_RDONLY
);
1566 realname
= local_strdup (cached
);
1567 if (realname
== NULL
)
1577 /* Finally, try the default path. */
1580 __builtin_expect (!(l
->l_flags_1
& DF_1_NODEFLIB
), 1))
1581 && rtld_search_dirs
.dirs
!= (void *) -1)
1582 fd
= open_path (name
, namelen
, preloaded
, &rtld_search_dirs
,
1585 /* Add another newline when we a tracing the library loading. */
1586 if (__builtin_expect (_dl_debug_libs
, 0))
1587 _dl_debug_message (1, "\n", NULL
);
1591 /* The path may contain dynamic string tokens. */
1593 ? expand_dynamic_string_token (loader
, name
)
1594 : local_strdup (name
));
1595 if (realname
== NULL
)
1599 fd
= __open (realname
, O_RDONLY
);
1609 /* We haven't found an appropriate library. But since we
1610 are only interested in the list of libraries this isn't
1611 so severe. Fake an entry with all the information we
1613 static const Elf_Symndx dummy_bucket
= STN_UNDEF
;
1615 /* Enter the new object in the list of loaded objects. */
1616 if ((name_copy
= local_strdup (name
)) == NULL
1617 || (l
= _dl_new_object (name_copy
, name
, type
, loader
)) == NULL
)
1618 _dl_signal_error (ENOMEM
, name
,
1619 N_("cannot create shared object descriptor"));
1620 /* We use an opencount of 0 as a sign for the faked entry.
1621 Since the descriptor is initialized with zero we do not
1624 l->l_reserved = 0; */
1625 l
->l_buckets
= &dummy_bucket
;
1632 _dl_signal_error (errno
, name
, N_("cannot open shared object file"));
1635 return _dl_map_object_from_fd (name
, fd
, realname
, loader
, type
, mode
);