dl-elf.c 32 KB

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