dl-elf.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * This file contains the helper routines to load an ELF shared
  4. * library into memory and add the symbol table info to the chain.
  5. *
  6. * Copyright (C) 2000-2006 by Erik Andersen <andersen@codepoet.org>
  7. * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald,
  8. * David Engel, Hongjiu Lu and Mitch D'Souza
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. The name of the above contributors may not be
  16. * used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. */
  31. #include "ldso.h"
  32. #ifdef __LDSO_CACHE_SUPPORT__
  33. static caddr_t _dl_cache_addr = NULL;
  34. static size_t _dl_cache_size = 0;
  35. int _dl_map_cache(void)
  36. {
  37. int fd;
  38. struct stat st;
  39. header_t *header;
  40. libentry_t *libent;
  41. int i, strtabsize;
  42. if (_dl_cache_addr == MAP_FAILED)
  43. return -1;
  44. else if (_dl_cache_addr != NULL)
  45. return 0;
  46. if (_dl_stat(LDSO_CACHE, &st)
  47. || (fd = _dl_open(LDSO_CACHE, O_RDONLY|O_CLOEXEC, 0)) < 0) {
  48. _dl_cache_addr = MAP_FAILED; /* so we won't try again */
  49. return -1;
  50. }
  51. _dl_cache_size = st.st_size;
  52. _dl_cache_addr = _dl_mmap(0, _dl_cache_size, PROT_READ, LDSO_CACHE_MMAP_FLAGS, fd, 0);
  53. _dl_close(fd);
  54. if (_dl_mmap_check_error(_dl_cache_addr)) {
  55. _dl_dprintf(2, "%s:%i: can't map '%s'\n",
  56. _dl_progname, __LINE__, LDSO_CACHE);
  57. return -1;
  58. }
  59. header = (header_t *) _dl_cache_addr;
  60. if (_dl_cache_size < sizeof(header_t) ||
  61. _dl_memcmp(header->magic, LDSO_CACHE_MAGIC, LDSO_CACHE_MAGIC_LEN)
  62. || _dl_memcmp(header->version, LDSO_CACHE_VER, LDSO_CACHE_VER_LEN)
  63. || _dl_cache_size <
  64. (sizeof(header_t) + header->nlibs * sizeof(libentry_t))
  65. || _dl_cache_addr[_dl_cache_size - 1] != '\0')
  66. {
  67. _dl_dprintf(2, "%s: cache '%s' is corrupt\n", _dl_progname,
  68. LDSO_CACHE);
  69. goto fail;
  70. }
  71. strtabsize = _dl_cache_size - sizeof(header_t) -
  72. header->nlibs * sizeof(libentry_t);
  73. libent = (libentry_t *) & header[1];
  74. for (i = 0; i < header->nlibs; i++) {
  75. if (libent[i].sooffset >= strtabsize ||
  76. libent[i].liboffset >= strtabsize)
  77. {
  78. _dl_dprintf(2, "%s: cache '%s' is corrupt\n", _dl_progname, LDSO_CACHE);
  79. goto fail;
  80. }
  81. }
  82. return 0;
  83. fail:
  84. _dl_munmap(_dl_cache_addr, _dl_cache_size);
  85. _dl_cache_addr = MAP_FAILED;
  86. return -1;
  87. }
  88. int _dl_unmap_cache(void)
  89. {
  90. if (_dl_cache_addr == NULL || _dl_cache_addr == MAP_FAILED)
  91. return -1;
  92. #if 1
  93. _dl_munmap(_dl_cache_addr, _dl_cache_size);
  94. _dl_cache_addr = NULL;
  95. #endif
  96. return 0;
  97. }
  98. #endif
  99. void
  100. _dl_protect_relro (struct elf_resolve *l)
  101. {
  102. ElfW(Addr) base = (ElfW(Addr)) DL_RELOC_ADDR(l->loadaddr, l->relro_addr);
  103. ElfW(Addr) start = (base & PAGE_ALIGN);
  104. ElfW(Addr) end = ((base + l->relro_size) & PAGE_ALIGN);
  105. _dl_if_debug_dprint("RELRO protecting %s: start:%x, end:%x\n", l->libname, start, end);
  106. if (start != end &&
  107. _dl_mprotect ((void *) start, end - start, PROT_READ) < 0) {
  108. _dl_dprintf(2, "%s: cannot apply additional memory protection after relocation", l->libname);
  109. _dl_exit(0);
  110. }
  111. }
  112. /* This function's behavior must exactly match that
  113. * in uClibc/ldso/util/ldd.c */
  114. static struct elf_resolve *
  115. search_for_named_library(const char *name, unsigned rflags, const char *path_list,
  116. struct dyn_elf **rpnt)
  117. {
  118. char *path, *path_n, *mylibname;
  119. struct elf_resolve *tpnt;
  120. int done;
  121. if (path_list==NULL)
  122. return NULL;
  123. /* We need a writable copy of this string, but we don't
  124. * need this allocated permanently since we don't want
  125. * to leak memory, so use alloca to put path on the stack */
  126. done = _dl_strlen(path_list);
  127. path = alloca(done + 1);
  128. /* another bit of local storage */
  129. mylibname = alloca(2050);
  130. _dl_memcpy(path, path_list, done+1);
  131. /* Unlike ldd.c, don't bother to eliminate double //s */
  132. /* Replace colons with zeros in path_list */
  133. /* : at the beginning or end of path maps to CWD */
  134. /* :: anywhere maps CWD */
  135. /* "" maps to CWD */
  136. done = 0;
  137. path_n = path;
  138. do {
  139. if (*path == 0) {
  140. *path = ':';
  141. done = 1;
  142. }
  143. if (*path == ':') {
  144. *path = 0;
  145. if (*path_n)
  146. _dl_strcpy(mylibname, path_n);
  147. else
  148. _dl_strcpy(mylibname, "."); /* Assume current dir if empty path */
  149. _dl_strcat(mylibname, "/");
  150. _dl_strcat(mylibname, name);
  151. #ifdef __LDSO_SAFE_RUNPATH__
  152. if (*mylibname == '/')
  153. #endif
  154. if ((tpnt = _dl_load_elf_shared_library(rflags, rpnt, mylibname)) != NULL)
  155. return tpnt;
  156. path_n = path+1;
  157. }
  158. path++;
  159. } while (!done);
  160. return NULL;
  161. }
  162. /* Used to return error codes back to dlopen et. al. */
  163. unsigned long _dl_error_number;
  164. unsigned long _dl_internal_error_number;
  165. struct elf_resolve *_dl_load_shared_library(unsigned rflags, struct dyn_elf **rpnt,
  166. struct elf_resolve *tpnt, char *full_libname, int attribute_unused trace_loaded_objects)
  167. {
  168. char *pnt;
  169. struct elf_resolve *tpnt1;
  170. char *libname;
  171. _dl_internal_error_number = 0;
  172. libname = full_libname;
  173. /* quick hack to ensure mylibname buffer doesn't overflow. don't
  174. allow full_libname or any directory to be longer than 1024. */
  175. if (_dl_strlen(full_libname) > 1024)
  176. goto goof;
  177. /* Skip over any initial initial './' and '/' stuff to
  178. * get the short form libname with no path garbage */
  179. pnt = _dl_strrchr(libname, '/');
  180. if (pnt) {
  181. libname = pnt + 1;
  182. }
  183. _dl_if_debug_dprint("\tfind library='%s'; searching\n", libname);
  184. /* If the filename has any '/', try it straight and leave it at that.
  185. For IBCS2 compatibility under linux, we substitute the string
  186. /usr/i486-sysv4/lib for /usr/lib in library names. */
  187. if (libname != full_libname) {
  188. _dl_if_debug_dprint("\ttrying file='%s'\n", full_libname);
  189. tpnt1 = _dl_load_elf_shared_library(rflags, rpnt, full_libname);
  190. if (tpnt1) {
  191. return tpnt1;
  192. }
  193. }
  194. /*
  195. * The ABI specifies that RPATH is searched before LD_LIBRARY_PATH or
  196. * the default path of /usr/lib. Check in rpath directories.
  197. */
  198. #ifdef __LDSO_RUNPATH__
  199. pnt = (tpnt ? (char *) tpnt->dynamic_info[DT_RPATH] : NULL);
  200. if (pnt) {
  201. pnt += (unsigned long) tpnt->dynamic_info[DT_STRTAB];
  202. _dl_if_debug_dprint("\tsearching RPATH='%s'\n", pnt);
  203. if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt)) != NULL)
  204. return tpnt1;
  205. }
  206. #endif
  207. #ifdef __LDSO_LD_LIBRARY_PATH__
  208. /* Check in LD_{ELF_}LIBRARY_PATH, if specified and allowed */
  209. if (_dl_library_path) {
  210. _dl_if_debug_dprint("\tsearching LD_LIBRARY_PATH='%s'\n", _dl_library_path);
  211. if ((tpnt1 = search_for_named_library(libname, rflags, _dl_library_path, rpnt)) != NULL)
  212. {
  213. return tpnt1;
  214. }
  215. }
  216. #endif
  217. /*
  218. * The ABI specifies that RUNPATH is searched after LD_LIBRARY_PATH.
  219. */
  220. #ifdef __LDSO_RUNPATH__
  221. pnt = (tpnt ? (char *)tpnt->dynamic_info[DT_RUNPATH] : NULL);
  222. if (pnt) {
  223. pnt += (unsigned long) tpnt->dynamic_info[DT_STRTAB];
  224. _dl_if_debug_dprint("\tsearching RUNPATH='%s'\n", pnt);
  225. if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt)) != NULL)
  226. return tpnt1;
  227. }
  228. #endif
  229. /*
  230. * Where should the cache be searched? There is no such concept in the
  231. * ABI, so we have some flexibility here. For now, search it before
  232. * the hard coded paths that follow (i.e before /lib and /usr/lib).
  233. */
  234. #ifdef __LDSO_CACHE_SUPPORT__
  235. if (_dl_cache_addr != NULL && _dl_cache_addr != MAP_FAILED) {
  236. int i;
  237. header_t *header = (header_t *) _dl_cache_addr;
  238. libentry_t *libent = (libentry_t *) & header[1];
  239. char *strs = (char *) &libent[header->nlibs];
  240. _dl_if_debug_dprint("\tsearching cache='%s'\n", LDSO_CACHE);
  241. for (i = 0; i < header->nlibs; i++) {
  242. if ((libent[i].flags == LIB_ELF
  243. || libent[i].flags == LIB_ELF_LIBC0
  244. || libent[i].flags == LIB_ELF_LIBC5)
  245. && _dl_strcmp(libname, strs + libent[i].sooffset) == 0
  246. && (tpnt1 = _dl_load_elf_shared_library(rflags, rpnt, strs + libent[i].liboffset))
  247. ) {
  248. return tpnt1;
  249. }
  250. }
  251. }
  252. #endif
  253. #if defined SHARED && defined __LDSO_SEARCH_INTERP_PATH__
  254. /* Look for libraries wherever the shared library loader
  255. * was installed */
  256. _dl_if_debug_dprint("\tsearching ldso dir='%s'\n", _dl_ldsopath);
  257. tpnt1 = search_for_named_library(libname, rflags, _dl_ldsopath, rpnt);
  258. if (tpnt1 != NULL)
  259. return tpnt1;
  260. #endif
  261. /* Lastly, search the standard list of paths for the library.
  262. This list must exactly match the list in uClibc/ldso/util/ldd.c */
  263. _dl_if_debug_dprint("\tsearching full lib path list\n");
  264. tpnt1 = search_for_named_library(libname, rflags,
  265. UCLIBC_RUNTIME_PREFIX "lib:"
  266. UCLIBC_RUNTIME_PREFIX "usr/lib"
  267. #ifndef __LDSO_CACHE_SUPPORT__
  268. ":" UCLIBC_RUNTIME_PREFIX "usr/X11R6/lib"
  269. #endif
  270. , rpnt);
  271. if (tpnt1 != NULL)
  272. return tpnt1;
  273. goof:
  274. /* Well, we shot our wad on that one. All we can do now is punt */
  275. if (_dl_internal_error_number)
  276. _dl_error_number = _dl_internal_error_number;
  277. else
  278. _dl_error_number = LD_ERROR_NOFILE;
  279. _dl_if_debug_dprint("Bummer: could not find '%s'!\n", libname);
  280. return NULL;
  281. }
  282. /* Define the _dl_library_offset for the architectures that need it */
  283. DL_DEF_LIB_OFFSET;
  284. /*
  285. * Make a writeable mapping of a segment, regardless of whether PF_W is
  286. * set or not.
  287. */
  288. static void *
  289. map_writeable (int infile, ElfW(Phdr) *ppnt, int piclib, int flags,
  290. unsigned long libaddr)
  291. {
  292. int prot_flags = ppnt->p_flags | PF_W;
  293. char *status, *retval;
  294. char *tryaddr;
  295. ssize_t size;
  296. unsigned long map_size;
  297. char *cpnt;
  298. char *piclib2map = NULL;
  299. if (piclib == 2 &&
  300. /* We might be able to avoid this call if memsz doesn't
  301. require an additional page, but this would require mmap
  302. to always return page-aligned addresses and a whole
  303. number of pages allocated. Unfortunately on uClinux
  304. may return misaligned addresses and may allocate
  305. partial pages, so we may end up doing unnecessary mmap
  306. calls.
  307. This is what we could do if we knew mmap would always
  308. return aligned pages:
  309. ((ppnt->p_vaddr + ppnt->p_filesz + ADDR_ALIGN) &
  310. PAGE_ALIGN) < ppnt->p_vaddr + ppnt->p_memsz)
  311. Instead, we have to do this: */
  312. ppnt->p_filesz < ppnt->p_memsz)
  313. {
  314. piclib2map = (char *)
  315. _dl_mmap(0, (ppnt->p_vaddr & ADDR_ALIGN) + ppnt->p_memsz,
  316. LXFLAGS(prot_flags), flags | MAP_ANONYMOUS, -1, 0);
  317. if (_dl_mmap_check_error(piclib2map))
  318. return 0;
  319. }
  320. tryaddr = piclib == 2 ? piclib2map
  321. : ((char *) (piclib ? libaddr : DL_GET_LIB_OFFSET()) +
  322. (ppnt->p_vaddr & PAGE_ALIGN));
  323. size = (ppnt->p_vaddr & ADDR_ALIGN) + ppnt->p_filesz;
  324. /* For !MMU, mmap to fixed address will fail.
  325. So instead of desperately call mmap and fail,
  326. we set status to MAP_FAILED to save a call
  327. to mmap (). */
  328. #ifndef __ARCH_USE_MMU__
  329. if (piclib2map == 0)
  330. #endif
  331. status = (char *) _dl_mmap
  332. (tryaddr, size, LXFLAGS(prot_flags),
  333. flags | (piclib2map ? MAP_FIXED : 0),
  334. infile, ppnt->p_offset & OFFS_ALIGN);
  335. #ifndef __ARCH_USE_MMU__
  336. else
  337. status = MAP_FAILED;
  338. #endif
  339. #ifdef _DL_PREAD
  340. if (_dl_mmap_check_error(status) && piclib2map
  341. && (_DL_PREAD (infile, tryaddr, size,
  342. ppnt->p_offset & OFFS_ALIGN) == size))
  343. status = tryaddr;
  344. #endif
  345. if (_dl_mmap_check_error(status) || (tryaddr && tryaddr != status))
  346. return 0;
  347. if (piclib2map)
  348. retval = piclib2map;
  349. else
  350. retval = status;
  351. /* Now we want to allocate and zero-out any data from the end
  352. of the region we mapped in from the file (filesz) to the
  353. end of the loadable segment (memsz). We may need
  354. additional pages for memsz, that we map in below, and we
  355. can count on the kernel to zero them out, but we have to
  356. zero out stuff in the last page that we mapped in from the
  357. file. However, we can't assume to have actually obtained
  358. full pages from the kernel, since we didn't ask for them,
  359. and uClibc may not give us full pages for small
  360. allocations. So only zero out up to memsz or the end of
  361. the page, whichever comes first. */
  362. /* CPNT is the beginning of the memsz portion not backed by
  363. filesz. */
  364. cpnt = (char *) (status + size);
  365. /* MAP_SIZE is the address of the
  366. beginning of the next page. */
  367. map_size = (ppnt->p_vaddr + ppnt->p_filesz
  368. + ADDR_ALIGN) & PAGE_ALIGN;
  369. _dl_memset (cpnt, 0,
  370. MIN (map_size
  371. - (ppnt->p_vaddr
  372. + ppnt->p_filesz),
  373. ppnt->p_memsz
  374. - ppnt->p_filesz));
  375. if (map_size < ppnt->p_vaddr + ppnt->p_memsz && !piclib2map) {
  376. tryaddr = map_size + (char*)(piclib ? libaddr : 0);
  377. status = (char *) _dl_mmap(tryaddr,
  378. ppnt->p_vaddr + ppnt->p_memsz - map_size,
  379. LXFLAGS(prot_flags),
  380. flags | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
  381. if (_dl_mmap_check_error(status) || tryaddr != status)
  382. return NULL;
  383. }
  384. return retval;
  385. }
  386. /*
  387. * Read one ELF library into memory, mmap it into the correct locations and
  388. * add the symbol info to the symbol chain. Perform any relocations that
  389. * are required.
  390. */
  391. struct elf_resolve *_dl_load_elf_shared_library(unsigned rflags,
  392. struct dyn_elf **rpnt, const char *libname)
  393. {
  394. ElfW(Ehdr) *epnt;
  395. unsigned long dynamic_addr = 0;
  396. ElfW(Dyn) *dpnt;
  397. struct elf_resolve *tpnt;
  398. ElfW(Phdr) *ppnt;
  399. #if defined(USE_TLS) && USE_TLS
  400. ElfW(Phdr) *tlsppnt = NULL;
  401. #endif
  402. char *status, *header;
  403. unsigned long dynamic_info[DYNAMIC_SIZE];
  404. unsigned long *lpnt;
  405. unsigned long libaddr;
  406. unsigned long minvma = 0xffffffff, maxvma = 0;
  407. unsigned int rtld_flags;
  408. int i, flags, piclib, infile;
  409. ElfW(Addr) relro_addr = 0;
  410. size_t relro_size = 0;
  411. struct stat st;
  412. uint32_t *p32;
  413. DL_LOADADDR_TYPE lib_loadaddr;
  414. DL_INIT_LOADADDR_EXTRA_DECLS
  415. libaddr = 0;
  416. infile = _dl_open(libname, O_RDONLY, 0);
  417. if (infile < 0) {
  418. _dl_internal_error_number = LD_ERROR_NOFILE;
  419. return NULL;
  420. }
  421. if (_dl_fstat(infile, &st) < 0) {
  422. _dl_internal_error_number = LD_ERROR_NOFILE;
  423. _dl_close(infile);
  424. return NULL;
  425. }
  426. /* If we are in secure mode (i.e. a setuid/gid binary using LD_PRELOAD),
  427. we don't load the library if it isn't setuid. */
  428. if (rflags & DL_RESOLVE_SECURE) {
  429. if (!(st.st_mode & S_ISUID)) {
  430. _dl_close(infile);
  431. return NULL;
  432. }
  433. }
  434. /* Check if file is already loaded */
  435. for (tpnt = _dl_loaded_modules; tpnt; tpnt = tpnt->next) {
  436. if (tpnt->st_dev == st.st_dev && tpnt->st_ino == st.st_ino) {
  437. /* Already loaded */
  438. tpnt->usage_count++;
  439. _dl_close(infile);
  440. return tpnt;
  441. }
  442. }
  443. if (rflags & DL_RESOLVE_NOLOAD) {
  444. _dl_close(infile);
  445. return NULL;
  446. }
  447. header = _dl_mmap((void *) 0, _dl_pagesize, PROT_READ | PROT_WRITE,
  448. MAP_PRIVATE | MAP_ANONYMOUS | MAP_UNINITIALIZE, -1, 0);
  449. if (_dl_mmap_check_error(header)) {
  450. _dl_dprintf(2, "%s:%i: can't map '%s'\n", _dl_progname, __LINE__, libname);
  451. _dl_internal_error_number = LD_ERROR_MMAP_FAILED;
  452. _dl_close(infile);
  453. return NULL;
  454. }
  455. _dl_read(infile, header, _dl_pagesize);
  456. epnt = (ElfW(Ehdr) *) (intptr_t) header;
  457. p32 = (uint32_t*)&epnt->e_ident;
  458. if (*p32 != ELFMAG_U32) {
  459. _dl_dprintf(2, "%s: '%s' is not an ELF file\n", _dl_progname,
  460. libname);
  461. _dl_internal_error_number = LD_ERROR_NOTELF;
  462. _dl_close(infile);
  463. _dl_munmap(header, _dl_pagesize);
  464. return NULL;
  465. }
  466. if ((epnt->e_type != ET_DYN
  467. #ifdef __LDSO_STANDALONE_SUPPORT__
  468. && epnt->e_type != ET_EXEC
  469. #endif
  470. ) || (epnt->e_machine != MAGIC1
  471. #ifdef MAGIC2
  472. && epnt->e_machine != MAGIC2
  473. #endif
  474. ))
  475. {
  476. _dl_internal_error_number =
  477. (epnt->e_type != ET_DYN ? LD_ERROR_NOTDYN : LD_ERROR_NOTMAGIC);
  478. _dl_dprintf(2, "%s: '%s' is not an ELF executable for " ELF_TARGET
  479. "\n", _dl_progname, libname);
  480. _dl_close(infile);
  481. _dl_munmap(header, _dl_pagesize);
  482. return NULL;
  483. }
  484. ppnt = (ElfW(Phdr) *)(intptr_t) & header[epnt->e_phoff];
  485. piclib = 1;
  486. for (i = 0; i < epnt->e_phnum; i++) {
  487. if (ppnt->p_type == PT_DYNAMIC) {
  488. if (dynamic_addr)
  489. _dl_dprintf(2, "%s: '%s' has more than one dynamic section\n",
  490. _dl_progname, libname);
  491. dynamic_addr = ppnt->p_vaddr;
  492. }
  493. if (ppnt->p_type == PT_LOAD) {
  494. /* See if this is a PIC library. */
  495. if (minvma == 0xffffffff && ppnt->p_vaddr > 0x1000000) {
  496. piclib = 0;
  497. minvma = ppnt->p_vaddr;
  498. }
  499. if (piclib && ppnt->p_vaddr < minvma) {
  500. minvma = ppnt->p_vaddr;
  501. }
  502. if (((unsigned long) ppnt->p_vaddr + ppnt->p_memsz) > maxvma) {
  503. maxvma = ppnt->p_vaddr + ppnt->p_memsz;
  504. }
  505. }
  506. if (ppnt->p_type == PT_TLS) {
  507. #if defined(USE_TLS) && USE_TLS
  508. if (ppnt->p_memsz == 0)
  509. /* Nothing to do for an empty segment. */
  510. continue;
  511. else
  512. /* Save for after 'tpnt' is actually allocated. */
  513. tlsppnt = ppnt;
  514. #else
  515. /*
  516. * Yup, the user was an idiot and tried to sneak in a library with
  517. * TLS in it and we don't support it. Let's fall on our own sword
  518. * and scream at the luser while we die.
  519. */
  520. _dl_dprintf(2, "%s: '%s' library contains unsupported TLS\n",
  521. _dl_progname, libname);
  522. _dl_internal_error_number = LD_ERROR_TLS_FAILED;
  523. _dl_close(infile);
  524. _dl_munmap(header, _dl_pagesize);
  525. return NULL;
  526. #endif
  527. }
  528. ppnt++;
  529. }
  530. #ifdef __LDSO_STANDALONE_SUPPORT__
  531. if (epnt->e_type == ET_EXEC)
  532. piclib = 0;
  533. #endif
  534. DL_CHECK_LIB_TYPE (epnt, piclib, _dl_progname, libname);
  535. maxvma = (maxvma + ADDR_ALIGN) & PAGE_ALIGN;
  536. minvma = minvma & ~ADDR_ALIGN;
  537. flags = MAP_PRIVATE /*| MAP_DENYWRITE */ ;
  538. if (piclib == 0 || piclib == 1) {
  539. status = (char *) _dl_mmap((char *) (piclib ? 0 : minvma),
  540. maxvma - minvma, PROT_NONE, flags | MAP_ANONYMOUS, -1, 0);
  541. if (_dl_mmap_check_error(status)) {
  542. cant_map:
  543. _dl_dprintf(2, "%s:%i: can't map '%s'\n", _dl_progname, __LINE__, libname);
  544. _dl_internal_error_number = LD_ERROR_MMAP_FAILED;
  545. _dl_close(infile);
  546. _dl_munmap(header, _dl_pagesize);
  547. return NULL;
  548. }
  549. libaddr = (unsigned long) status;
  550. flags |= MAP_FIXED;
  551. }
  552. /* Get the memory to store the library */
  553. ppnt = (ElfW(Phdr) *)(intptr_t) & header[epnt->e_phoff];
  554. DL_INIT_LOADADDR(lib_loadaddr, libaddr - minvma, ppnt, epnt->e_phnum);
  555. /* Set _dl_library_offset to lib_loadaddr or 0. */
  556. DL_SET_LIB_OFFSET(lib_loadaddr);
  557. for (i = 0; i < epnt->e_phnum; i++) {
  558. if (DL_IS_SPECIAL_SEGMENT (epnt, ppnt)) {
  559. char *addr;
  560. addr = DL_MAP_SEGMENT (epnt, ppnt, infile, flags);
  561. if (addr == NULL) {
  562. cant_map1:
  563. DL_LOADADDR_UNMAP (lib_loadaddr, maxvma - minvma);
  564. goto cant_map;
  565. }
  566. DL_INIT_LOADADDR_HDR (lib_loadaddr, addr, ppnt);
  567. ppnt++;
  568. continue;
  569. }
  570. if (ppnt->p_type == PT_GNU_RELRO) {
  571. relro_addr = ppnt->p_vaddr;
  572. relro_size = ppnt->p_memsz;
  573. }
  574. if (ppnt->p_type == PT_LOAD) {
  575. char *tryaddr;
  576. ssize_t size;
  577. if (ppnt->p_flags & PF_W) {
  578. status = map_writeable (infile, ppnt, piclib, flags, libaddr);
  579. if (status == NULL)
  580. goto cant_map1;
  581. } else {
  582. tryaddr = (piclib == 2 ? 0
  583. : (char *) (ppnt->p_vaddr & PAGE_ALIGN)
  584. + (piclib ? libaddr : DL_GET_LIB_OFFSET()));
  585. size = (ppnt->p_vaddr & ADDR_ALIGN) + ppnt->p_filesz;
  586. status = (char *) _dl_mmap
  587. (tryaddr, size, LXFLAGS(ppnt->p_flags),
  588. flags | (piclib == 2 ? MAP_EXECUTABLE
  589. | MAP_DENYWRITE : 0),
  590. infile, ppnt->p_offset & OFFS_ALIGN);
  591. if (_dl_mmap_check_error(status)
  592. || (tryaddr && tryaddr != status))
  593. goto cant_map1;
  594. }
  595. DL_INIT_LOADADDR_HDR(lib_loadaddr,
  596. status + (ppnt->p_vaddr & ADDR_ALIGN),
  597. ppnt);
  598. /* if (libaddr == 0 && piclib) {
  599. libaddr = (unsigned long) status;
  600. flags |= MAP_FIXED;
  601. } */
  602. }
  603. ppnt++;
  604. }
  605. /*
  606. * The dynamic_addr must be take into acount lib_loadaddr value, to note
  607. * it is zero when the SO has been mapped to the elf's physical addr
  608. */
  609. #ifdef __LDSO_PRELINK_SUPPORT__
  610. if (DL_GET_LIB_OFFSET()) {
  611. #else
  612. if (piclib) {
  613. #endif
  614. dynamic_addr = (unsigned long) DL_RELOC_ADDR(lib_loadaddr, dynamic_addr);
  615. }
  616. /*
  617. * OK, the ELF library is now loaded into VM in the correct locations
  618. * The next step is to go through and do the dynamic linking (if needed).
  619. */
  620. /* Start by scanning the dynamic section to get all of the pointers */
  621. if (!dynamic_addr) {
  622. _dl_internal_error_number = LD_ERROR_NODYNAMIC;
  623. _dl_dprintf(2, "%s: '%s' is missing a dynamic section\n",
  624. _dl_progname, libname);
  625. _dl_munmap(header, _dl_pagesize);
  626. _dl_close(infile);
  627. return NULL;
  628. }
  629. dpnt = (ElfW(Dyn) *) dynamic_addr;
  630. _dl_memset(dynamic_info, 0, sizeof(dynamic_info));
  631. rtld_flags = _dl_parse_dynamic_info(dpnt, dynamic_info, NULL, lib_loadaddr);
  632. /* If the TEXTREL is set, this means that we need to make the pages
  633. writable before we perform relocations. Do this now. They get set
  634. back again later. */
  635. if (dynamic_info[DT_TEXTREL]) {
  636. #ifndef __FORCE_SHAREABLE_TEXT_SEGMENTS__
  637. ppnt = (ElfW(Phdr) *)(intptr_t) & header[epnt->e_phoff];
  638. for (i = 0; i < epnt->e_phnum; i++, ppnt++) {
  639. if (ppnt->p_type == PT_LOAD && !(ppnt->p_flags & PF_W)) {
  640. #ifdef __ARCH_USE_MMU__
  641. _dl_mprotect((void *) ((piclib ? libaddr : DL_GET_LIB_OFFSET()) +
  642. (ppnt->p_vaddr & PAGE_ALIGN)),
  643. (ppnt->p_vaddr & ADDR_ALIGN) + (unsigned long) ppnt->p_filesz,
  644. PROT_READ | PROT_WRITE | PROT_EXEC);
  645. #else
  646. void *new_addr;
  647. new_addr = map_writeable (infile, ppnt, piclib, flags, libaddr);
  648. if (!new_addr) {
  649. _dl_dprintf(_dl_debug_file, "Can't modify %s's text section.",
  650. libname);
  651. _dl_exit(1);
  652. }
  653. DL_UPDATE_LOADADDR_HDR(lib_loadaddr,
  654. new_addr + (ppnt->p_vaddr & ADDR_ALIGN),
  655. ppnt);
  656. /* This has invalidated all pointers into the previously readonly segment.
  657. Update any them to point into the remapped segment. */
  658. _dl_parse_dynamic_info(dpnt, dynamic_info, NULL, lib_loadaddr);
  659. #endif
  660. }
  661. }
  662. #else
  663. _dl_dprintf(2, "Can't modify %s's text section."
  664. " Use GCC option -fPIC for shared objects, please.\n",
  665. libname);
  666. _dl_exit(1);
  667. #endif
  668. }
  669. _dl_close(infile);
  670. tpnt = _dl_add_elf_hash_table(libname, lib_loadaddr, dynamic_info,
  671. dynamic_addr, 0);
  672. tpnt->mapaddr = libaddr;
  673. tpnt->relro_addr = relro_addr;
  674. tpnt->relro_size = relro_size;
  675. tpnt->st_dev = st.st_dev;
  676. tpnt->st_ino = st.st_ino;
  677. tpnt->ppnt = (ElfW(Phdr) *)
  678. DL_RELOC_ADDR(DL_GET_RUN_ADDR(tpnt->loadaddr, tpnt->mapaddr),
  679. epnt->e_phoff);
  680. tpnt->n_phent = epnt->e_phnum;
  681. tpnt->rtld_flags |= rtld_flags;
  682. #ifdef __LDSO_STANDALONE_SUPPORT__
  683. tpnt->l_entry = epnt->e_entry;
  684. #endif
  685. #if defined(USE_TLS) && USE_TLS
  686. if (tlsppnt) {
  687. _dl_debug_early("Found TLS header for %s\n", libname);
  688. # if NO_TLS_OFFSET != 0
  689. tpnt->l_tls_offset = NO_TLS_OFFSET;
  690. # endif
  691. tpnt->l_tls_blocksize = tlsppnt->p_memsz;
  692. tpnt->l_tls_align = tlsppnt->p_align;
  693. if (tlsppnt->p_align == 0)
  694. tpnt->l_tls_firstbyte_offset = 0;
  695. else
  696. tpnt->l_tls_firstbyte_offset = tlsppnt->p_vaddr &
  697. (tlsppnt->p_align - 1);
  698. tpnt->l_tls_initimage_size = tlsppnt->p_filesz;
  699. tpnt->l_tls_initimage = (void *) tlsppnt->p_vaddr;
  700. /* Assign the next available module ID. */
  701. tpnt->l_tls_modid = _dl_next_tls_modid ();
  702. /* We know the load address, so add it to the offset. */
  703. #ifdef __LDSO_STANDALONE_SUPPORT__
  704. if ((tpnt->l_tls_initimage != NULL) && piclib)
  705. #else
  706. if (tpnt->l_tls_initimage != NULL)
  707. #endif
  708. {
  709. # ifdef __SUPPORT_LD_DEBUG_EARLY__
  710. unsigned int tmp = (unsigned int) tpnt->l_tls_initimage;
  711. tpnt->l_tls_initimage = (char *) tlsppnt->p_vaddr + tpnt->loadaddr;
  712. _dl_debug_early("Relocated TLS initial image from %x to %x (size = %x)\n", tmp, tpnt->l_tls_initimage, tpnt->l_tls_initimage_size);
  713. tmp = 0;
  714. # else
  715. tpnt->l_tls_initimage = (char *) tlsppnt->p_vaddr + tpnt->loadaddr;
  716. # endif
  717. }
  718. }
  719. #endif
  720. /*
  721. * Add this object into the symbol chain
  722. */
  723. if (*rpnt
  724. #ifdef __LDSO_STANDALONE_SUPPORT__
  725. /* Do not create a new chain entry for the main executable */
  726. && (*rpnt)->dyn
  727. #endif
  728. ) {
  729. (*rpnt)->next = _dl_malloc(sizeof(struct dyn_elf));
  730. _dl_memset((*rpnt)->next, 0, sizeof(struct dyn_elf));
  731. (*rpnt)->next->prev = (*rpnt);
  732. *rpnt = (*rpnt)->next;
  733. }
  734. #ifndef SHARED
  735. /* When statically linked, the first time we dlopen a DSO
  736. * the *rpnt is NULL, so we need to allocate memory for it,
  737. * and initialize the _dl_symbol_table.
  738. */
  739. else {
  740. *rpnt = _dl_symbol_tables = _dl_malloc(sizeof(struct dyn_elf));
  741. _dl_memset(*rpnt, 0, sizeof(struct dyn_elf));
  742. }
  743. #endif
  744. (*rpnt)->dyn = tpnt;
  745. tpnt->usage_count++;
  746. #ifdef __LDSO_STANDALONE_SUPPORT__
  747. tpnt->libtype = (epnt->e_type == ET_DYN) ? elf_lib : elf_executable;
  748. #else
  749. tpnt->libtype = elf_lib;
  750. #endif
  751. /*
  752. * OK, the next thing we need to do is to insert the dynamic linker into
  753. * the proper entry in the GOT so that the PLT symbols can be properly
  754. * resolved.
  755. */
  756. lpnt = (unsigned long *) dynamic_info[DT_PLTGOT];
  757. if (lpnt) {
  758. lpnt = (unsigned long *) (dynamic_info[DT_PLTGOT]);
  759. INIT_GOT(lpnt, tpnt);
  760. }
  761. #ifdef __DSBT__
  762. /* Handle DSBT initialization */
  763. {
  764. struct elf_resolve *t, *ref;
  765. int idx = tpnt->dsbt_index;
  766. void **dsbt = tpnt->dsbt_table;
  767. /*
  768. * It is okay (required actually) to have zero idx for an executable.
  769. * This is the case when running ldso standalone and the program
  770. * is being mapped in via _dl_load_shared_library().
  771. */
  772. if (idx == 0 && tpnt->libtype != elf_executable) {
  773. if (!dynamic_info[DT_TEXTREL]) {
  774. /* This DSO has not been assigned an index. */
  775. _dl_dprintf(2, "%s: '%s' is missing a dsbt index assignment!\n",
  776. _dl_progname, libname);
  777. _dl_exit(1);
  778. }
  779. /* Find a dsbt table from another module. */
  780. ref = NULL;
  781. for (t = _dl_loaded_modules; t; t = t->next) {
  782. if (ref == NULL && t != tpnt) {
  783. ref = t;
  784. break;
  785. }
  786. }
  787. idx = tpnt->dsbt_size;
  788. while (idx-- > 0)
  789. if (!ref || ref->dsbt_table[idx] == NULL)
  790. break;
  791. if (idx <= 0) {
  792. _dl_dprintf(2, "%s: '%s' caused DSBT table overflow!\n",
  793. _dl_progname, libname);
  794. _dl_exit(1);
  795. }
  796. _dl_if_debug_dprint("\n\tfile='%s'; assigned index %d\n",
  797. libname, idx);
  798. tpnt->dsbt_index = idx;
  799. }
  800. /* make sure index is not already used */
  801. if (_dl_ldso_dsbt[idx]) {
  802. struct elf_resolve *dup;
  803. const char *dup_name;
  804. for (dup = _dl_loaded_modules; dup; dup = dup->next)
  805. if (dup != tpnt && dup->dsbt_index == idx)
  806. break;
  807. if (dup)
  808. dup_name = dup->libname;
  809. else if (idx == 1)
  810. dup_name = "runtime linker";
  811. else
  812. dup_name = "unknown library";
  813. _dl_dprintf(2, "%s: '%s' dsbt index %d already used by %s!\n",
  814. _dl_progname, libname, idx, dup_name);
  815. _dl_exit(1);
  816. }
  817. /*
  818. * Setup dsbt slot for this module in dsbt of all modules.
  819. */
  820. for (t = _dl_loaded_modules; t; t = t->next)
  821. t->dsbt_table[idx] = dsbt;
  822. _dl_ldso_dsbt[idx] = dsbt;
  823. _dl_memcpy(dsbt, _dl_ldso_dsbt,
  824. tpnt->dsbt_size * sizeof(tpnt->dsbt_table[0]));
  825. }
  826. #endif
  827. _dl_if_debug_dprint("\n\tfile='%s'; generating link map\n", libname);
  828. _dl_if_debug_dprint("\t\tdynamic: %x base: %x\n", dynamic_addr, DL_LOADADDR_BASE(lib_loadaddr));
  829. _dl_if_debug_dprint("\t\t entry: %x phdr: %x phnum: %x\n\n",
  830. DL_RELOC_ADDR(lib_loadaddr, epnt->e_entry), tpnt->ppnt, tpnt->n_phent);
  831. _dl_munmap(header, _dl_pagesize);
  832. return tpnt;
  833. }
  834. /* now_flag must be RTLD_NOW or zero */
  835. int _dl_fixup(struct dyn_elf *rpnt, struct r_scope_elem *scope, int now_flag)
  836. {
  837. int goof = 0;
  838. struct elf_resolve *tpnt;
  839. ElfW(Word) reloc_size, relative_count;
  840. ElfW(Addr) reloc_addr;
  841. if (rpnt->next)
  842. goof = _dl_fixup(rpnt->next, scope, now_flag);
  843. if (goof)
  844. return goof;
  845. tpnt = rpnt->dyn;
  846. if (!(tpnt->init_flag & RELOCS_DONE))
  847. _dl_if_debug_dprint("relocation processing: %s\n", tpnt->libname);
  848. if (unlikely(tpnt->dynamic_info[UNSUPPORTED_RELOC_TYPE])) {
  849. _dl_if_debug_dprint("%s: can't handle %s relocation records\n",
  850. _dl_progname, UNSUPPORTED_RELOC_STR);
  851. goof++;
  852. return goof;
  853. }
  854. reloc_size = tpnt->dynamic_info[DT_RELOC_TABLE_SIZE];
  855. /* On some machines, notably SPARC & PPC, DT_REL* includes DT_JMPREL in its
  856. range. Note that according to the ELF spec, this is completely legal! */
  857. #ifdef ELF_MACHINE_PLTREL_OVERLAP
  858. reloc_size -= tpnt->dynamic_info [DT_PLTRELSZ];
  859. #endif
  860. if (tpnt->dynamic_info[DT_RELOC_TABLE_ADDR] &&
  861. !(tpnt->init_flag & RELOCS_DONE)) {
  862. reloc_addr = tpnt->dynamic_info[DT_RELOC_TABLE_ADDR];
  863. relative_count = tpnt->dynamic_info[DT_RELCONT_IDX];
  864. if (relative_count) { /* Optimize the XX_RELATIVE relocations if possible */
  865. reloc_size -= relative_count * sizeof(ELF_RELOC);
  866. #ifdef __LDSO_PRELINK_SUPPORT__
  867. if (tpnt->loadaddr || (!tpnt->dynamic_info[DT_GNU_PRELINKED_IDX]))
  868. #endif
  869. elf_machine_relative(tpnt->loadaddr, reloc_addr, relative_count);
  870. reloc_addr += relative_count * sizeof(ELF_RELOC);
  871. }
  872. goof += _dl_parse_relocation_information(rpnt, scope,
  873. reloc_addr,
  874. reloc_size);
  875. tpnt->init_flag |= RELOCS_DONE;
  876. }
  877. if (tpnt->dynamic_info[DT_BIND_NOW])
  878. now_flag = RTLD_NOW;
  879. if (tpnt->dynamic_info[DT_JMPREL] &&
  880. (!(tpnt->init_flag & JMP_RELOCS_DONE) ||
  881. (now_flag && !(tpnt->rtld_flags & now_flag)))) {
  882. tpnt->rtld_flags |= now_flag;
  883. if (!(tpnt->rtld_flags & RTLD_NOW)) {
  884. _dl_parse_lazy_relocation_information(rpnt,
  885. tpnt->dynamic_info[DT_JMPREL],
  886. tpnt->dynamic_info [DT_PLTRELSZ]);
  887. } else {
  888. goof += _dl_parse_relocation_information(rpnt, scope,
  889. tpnt->dynamic_info[DT_JMPREL],
  890. tpnt->dynamic_info[DT_PLTRELSZ]);
  891. }
  892. tpnt->init_flag |= JMP_RELOCS_DONE;
  893. }
  894. #if 0
  895. /* _dl_add_to_slotinfo is called by init_tls() for initial DSO
  896. or by dlopen() for dynamically loaded DSO. */
  897. #if defined(USE_TLS) && USE_TLS
  898. /* Add object to slot information data if necessasy. */
  899. if (tpnt->l_tls_blocksize != 0 && tls_init_tp_called)
  900. _dl_add_to_slotinfo ((struct link_map *) tpnt);
  901. #endif
  902. #endif
  903. return goof;
  904. }
  905. #ifdef IS_IN_rtld
  906. /* Minimal printf which handles only %s, %d, and %x */
  907. void _dl_dprintf(int fd, const char *fmt, ...)
  908. {
  909. #if __WORDSIZE > 32
  910. long int num;
  911. #else
  912. int num;
  913. #endif
  914. va_list args;
  915. char *start, *ptr, *string;
  916. char *buf;
  917. if (!fmt)
  918. return;
  919. buf = _dl_mmap((void *) 0, _dl_pagesize, PROT_READ | PROT_WRITE,
  920. MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  921. if (_dl_mmap_check_error(buf)) {
  922. _dl_write(fd, "mmap of a spare page failed!\n", 29);
  923. _dl_exit(20);
  924. }
  925. start = ptr = buf;
  926. if (_dl_strlen(fmt) >= (_dl_pagesize - 1)) {
  927. _dl_write(fd, "overflow\n", 11);
  928. _dl_exit(20);
  929. }
  930. _dl_strcpy(buf, fmt);
  931. va_start(args, fmt);
  932. while (start) {
  933. while (*ptr != '%' && *ptr) {
  934. ptr++;
  935. }
  936. if (*ptr == '%') {
  937. *ptr++ = '\0';
  938. _dl_write(fd, start, _dl_strlen(start));
  939. switch (*ptr++) {
  940. case 's':
  941. string = va_arg(args, char *);
  942. if (!string)
  943. _dl_write(fd, "(null)", 6);
  944. else
  945. _dl_write(fd, string, _dl_strlen(string));
  946. break;
  947. case 'i':
  948. case 'd':
  949. {
  950. char tmp[22];
  951. #if __WORDSIZE > 32
  952. num = va_arg(args, long int);
  953. #else
  954. num = va_arg(args, int);
  955. #endif
  956. string = _dl_simple_ltoa(tmp, num);
  957. _dl_write(fd, string, _dl_strlen(string));
  958. break;
  959. }
  960. case 'x':
  961. case 'p':
  962. {
  963. char tmp[22];
  964. #if __WORDSIZE > 32
  965. num = va_arg(args, long int);
  966. #else
  967. num = va_arg(args, int);
  968. #endif
  969. string = _dl_simple_ltoahex(tmp, num);
  970. _dl_write(fd, string, _dl_strlen(string));
  971. break;
  972. }
  973. default:
  974. _dl_write(fd, "(null)", 6);
  975. break;
  976. }
  977. start = ptr;
  978. } else {
  979. _dl_write(fd, start, _dl_strlen(start));
  980. start = NULL;
  981. }
  982. }
  983. _dl_munmap(buf, _dl_pagesize);
  984. return;
  985. }
  986. char *_dl_strdup(const char *string)
  987. {
  988. char *retval;
  989. int len;
  990. len = _dl_strlen(string);
  991. retval = _dl_malloc(len + 1);
  992. _dl_strcpy(retval, string);
  993. return retval;
  994. }
  995. #endif
  996. unsigned int _dl_parse_dynamic_info(ElfW(Dyn) *dpnt, unsigned long dynamic_info[],
  997. void *debug_addr, DL_LOADADDR_TYPE load_off)
  998. {
  999. return __dl_parse_dynamic_info(dpnt, dynamic_info, debug_addr, load_off);
  1000. }