readelflib1.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /* Load an ELF sharable library into memory.
  2. Copyright (C) 1993-1996, Eric Youngdale.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  14. /* This file contains the helper routines to load an ELF sharable
  15. library into memory and add the symbol table info to the chain. */
  16. #ifdef USE_CACHE
  17. static caddr_t _dl_cache_addr = NULL;
  18. static size_t _dl_cache_size = 0;
  19. int _dl_map_cache(void)
  20. {
  21. int fd;
  22. struct stat st;
  23. header_t *header;
  24. libentry_t *libent;
  25. int i, strtabsize;
  26. if (_dl_cache_addr == (caddr_t) - 1)
  27. return -1;
  28. else if (_dl_cache_addr != NULL)
  29. return 0;
  30. if (_dl_stat(LDSO_CACHE, &st)
  31. || (fd = _dl_open(LDSO_CACHE, O_RDONLY)) < 0) {
  32. _dl_dprintf(2, "%s: can't open cache '%s'\n", _dl_progname, LDSO_CACHE);
  33. _dl_cache_addr = (caddr_t) - 1; /* so we won't try again */
  34. return -1;
  35. }
  36. _dl_cache_size = st.st_size;
  37. _dl_cache_addr = (caddr_t) _dl_mmap(0, _dl_cache_size, PROT_READ, MAP_SHARED, fd, 0);
  38. _dl_close(fd);
  39. if (_dl_cache_addr == (caddr_t) - 1) {
  40. _dl_dprintf(2, "%s: can't map cache '%s'\n",
  41. _dl_progname, LDSO_CACHE);
  42. return -1;
  43. }
  44. header = (header_t *) _dl_cache_addr;
  45. if (_dl_cache_size < sizeof(header_t) ||
  46. _dl_memcmp(header->magic, LDSO_CACHE_MAGIC, LDSO_CACHE_MAGIC_LEN)
  47. || _dl_memcmp(header->version, LDSO_CACHE_VER, LDSO_CACHE_VER_LEN)
  48. || _dl_cache_size <
  49. (sizeof(header_t) + header->nlibs * sizeof(libentry_t))
  50. || _dl_cache_addr[_dl_cache_size - 1] != '\0')
  51. {
  52. _dl_dprintf(2, "%s: cache '%s' is corrupt\n", _dl_progname,
  53. LDSO_CACHE);
  54. goto fail;
  55. }
  56. strtabsize = _dl_cache_size - sizeof(header_t) -
  57. header->nlibs * sizeof(libentry_t);
  58. libent = (libentry_t *) & header[1];
  59. for (i = 0; i < header->nlibs; i++) {
  60. if (libent[i].sooffset >= strtabsize ||
  61. libent[i].liboffset >= strtabsize)
  62. {
  63. _dl_dprintf(2, "%s: cache '%s' is corrupt\n", _dl_progname, LDSO_CACHE);
  64. goto fail;
  65. }
  66. }
  67. return 0;
  68. fail:
  69. _dl_munmap(_dl_cache_addr, _dl_cache_size);
  70. _dl_cache_addr = (caddr_t) - 1;
  71. return -1;
  72. }
  73. int _dl_unmap_cache(void)
  74. {
  75. if (_dl_cache_addr == NULL || _dl_cache_addr == (caddr_t) - 1)
  76. return -1;
  77. #if 1
  78. _dl_munmap(_dl_cache_addr, _dl_cache_size);
  79. _dl_cache_addr = NULL;
  80. #endif
  81. return 0;
  82. }
  83. #endif
  84. /* This function's behavior must exactly match that
  85. * in uClibc/ldso/util/ldd.c */
  86. static struct elf_resolve *
  87. search_for_named_library(char *name, int secure, const char *path_list,
  88. struct dyn_elf **rpnt)
  89. {
  90. int i, count = 1;
  91. char *path, *path_n;
  92. char mylibname[2050];
  93. struct elf_resolve *tpnt1;
  94. /* We need a writable copy of this string */
  95. path = _dl_strdup(path_list);
  96. if (!path) {
  97. _dl_dprintf(2, "Out of memory!\n");
  98. _dl_exit(0);
  99. }
  100. /* Unlike ldd.c, don't bother to eliminate double //s */
  101. /* Replace colons with zeros in path_list and count them */
  102. for(i=_dl_strlen(path); i > 0; i--) {
  103. if (path[i]==':') {
  104. path[i]=0;
  105. count++;
  106. }
  107. }
  108. path_n = path;
  109. for (i = 0; i < count; i++) {
  110. _dl_strcpy(mylibname, path_n);
  111. _dl_strcat(mylibname, "/");
  112. _dl_strcat(mylibname, name);
  113. if ((tpnt1 = _dl_load_elf_shared_library(secure, rpnt,
  114. mylibname, 0)) != NULL)
  115. {
  116. return tpnt1;
  117. }
  118. path_n += (_dl_strlen(path_n) + 1);
  119. }
  120. return NULL;
  121. }
  122. /*
  123. * Used to return error codes back to dlopen et. al.
  124. */
  125. unsigned long _dl_error_number;
  126. unsigned long _dl_internal_error_number;
  127. extern char *_dl_ldsopath;
  128. struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt,
  129. struct elf_resolve *tpnt, char *full_libname)
  130. {
  131. char *pnt;
  132. struct elf_resolve *tpnt1;
  133. char *libname;
  134. _dl_internal_error_number = 0;
  135. pnt = libname = full_libname;
  136. /* quick hack to ensure mylibname buffer doesn't overflow. don't
  137. allow full_libname or any directory to be longer than 1024. */
  138. if (_dl_strlen(full_libname) > 1024)
  139. goto goof;
  140. while (*pnt) {
  141. if (*pnt == '/')
  142. libname = pnt + 1;
  143. pnt++;
  144. }
  145. #ifdef DL_DEBUG
  146. _dl_dprintf(2, "searching for library: '%s'\n", libname);
  147. #endif
  148. /* If the filename has any '/', try it straight and leave it at that.
  149. For IBCS2 compatibility under linux, we substitute the string
  150. /usr/i486-sysv4/lib for /usr/lib in library names. */
  151. if (libname != full_libname) {
  152. tpnt1 = _dl_load_elf_shared_library(secure, rpnt, full_libname, 0);
  153. if (tpnt1)
  154. return tpnt1;
  155. goto goof;
  156. }
  157. /*
  158. * The ABI specifies that RPATH is searched before LD_*_PATH or
  159. * the default path of /usr/lib. Check in rpath directories.
  160. */
  161. for (tpnt = _dl_loaded_modules; tpnt; tpnt = tpnt->next) {
  162. if (tpnt->libtype == elf_executable) {
  163. pnt = (char *) tpnt->dynamic_info[DT_RPATH];
  164. if (pnt) {
  165. pnt += (unsigned long) tpnt->loadaddr +
  166. tpnt->dynamic_info[DT_STRTAB];
  167. #ifdef DL_DEBUG
  168. _dl_dprintf(2, "searching RPATH: '%s'\n", pnt);
  169. #endif
  170. if ((tpnt1 = search_for_named_library(libname, secure, pnt, rpnt)) != NULL)
  171. {
  172. return tpnt1;
  173. }
  174. }
  175. }
  176. }
  177. /* Check in LD_{ELF_}LIBRARY_PATH, if specified and allowed */
  178. if (_dl_library_path) {
  179. #ifdef DL_DEBUG
  180. _dl_dprintf(2, "searching _dl_library_path: '%s'\n", _dl_library_path);
  181. #endif
  182. if ((tpnt1 = search_for_named_library(libname, secure, _dl_library_path, rpnt)) != NULL)
  183. {
  184. return tpnt1;
  185. }
  186. }
  187. /*
  188. * Where should the cache be searched? There is no such concept in the
  189. * ABI, so we have some flexibility here. For now, search it before
  190. * the hard coded paths that follow (i.e before /lib and /usr/lib).
  191. */
  192. #ifdef USE_CACHE
  193. if (_dl_cache_addr != NULL && _dl_cache_addr != (caddr_t) - 1) {
  194. int i;
  195. header_t *header = (header_t *) _dl_cache_addr;
  196. libentry_t *libent = (libentry_t *) & header[1];
  197. char *strs = (char *) &libent[header->nlibs];
  198. for (i = 0; i < header->nlibs; i++) {
  199. if ((libent[i].flags == LIB_ELF ||
  200. libent[i].flags == LIB_ELF_LIBC5) &&
  201. _dl_strcmp(libname, strs + libent[i].sooffset) == 0 &&
  202. (tpnt1 = _dl_load_elf_shared_library(secure,
  203. rpnt, strs + libent[i].liboffset, 0)))
  204. return tpnt1;
  205. }
  206. }
  207. #endif
  208. /* Look for libraries wherever the shared library loader
  209. * was installed */
  210. #ifdef DL_DEBUG
  211. _dl_dprintf(2, "searching in ldso dir: %s\n", _dl_ldsopath);
  212. #endif
  213. if ((tpnt1 = search_for_named_library(libname, secure, _dl_ldsopath, rpnt)) != NULL)
  214. {
  215. return tpnt1;
  216. }
  217. /* Lastly, search the standard list of paths for the library.
  218. This list must exactly match the list in uClibc/ldso/util/ldd.c */
  219. #ifdef DL_DEBUG
  220. _dl_dprintf(2, "searching full lib path list\n");
  221. #endif
  222. if ((tpnt1 = search_for_named_library(libname, secure,
  223. UCLIBC_TARGET_PREFIX "/usr/lib:"
  224. UCLIBC_TARGET_PREFIX "/lib:"
  225. UCLIBC_DEVEL_PREFIX "/lib:"
  226. UCLIBC_BUILD_DIR "/lib:"
  227. "/usr/lib:"
  228. "/lib", rpnt)
  229. ) != NULL)
  230. {
  231. return tpnt1;
  232. }
  233. goof:
  234. /* Well, we shot our wad on that one. All we can do now is punt */
  235. if (_dl_internal_error_number)
  236. _dl_error_number = _dl_internal_error_number;
  237. else
  238. _dl_error_number = DL_ERROR_NOFILE;
  239. #ifdef DL_DEBUG
  240. _dl_dprintf(2, "Bummer: could not find '%s'!\n", libname);
  241. #endif
  242. return NULL;
  243. }
  244. /*
  245. * Read one ELF library into memory, mmap it into the correct locations and
  246. * add the symbol info to the symbol chain. Perform any relocations that
  247. * are required.
  248. */
  249. struct elf_resolve *_dl_load_elf_shared_library(int secure,
  250. struct dyn_elf **rpnt, char *libname, int flag)
  251. {
  252. elfhdr *epnt;
  253. unsigned long dynamic_addr = 0;
  254. unsigned long dynamic_size = 0;
  255. Elf32_Dyn *dpnt;
  256. struct elf_resolve *tpnt;
  257. elf_phdr *ppnt;
  258. int piclib;
  259. char *status;
  260. int flags;
  261. char header[4096];
  262. unsigned long dynamic_info[24];
  263. unsigned long *lpnt;
  264. unsigned long libaddr;
  265. unsigned long minvma = 0xffffffff, maxvma = 0;
  266. int i;
  267. int infile;
  268. /* If this file is already loaded, skip this step */
  269. tpnt = _dl_check_hashed_files(libname);
  270. if (tpnt) {
  271. (*rpnt)->next = (struct dyn_elf *)
  272. _dl_malloc(sizeof(struct dyn_elf));
  273. _dl_memset((*rpnt)->next, 0, sizeof(*((*rpnt)->next)));
  274. *rpnt = (*rpnt)->next;
  275. tpnt->usage_count++;
  276. tpnt->symbol_scope = _dl_symbol_tables;
  277. tpnt->libtype = elf_lib;
  278. (*rpnt)->dyn = tpnt;
  279. return tpnt;
  280. }
  281. /* If we are in secure mode (i.e. a setu/gid binary using LD_PRELOAD),
  282. we don't load the library if it isn't setuid. */
  283. if (secure) {
  284. struct stat st;
  285. if (_dl_stat(libname, &st) || !(st.st_mode & S_ISUID))
  286. return NULL;
  287. }
  288. libaddr = 0;
  289. infile = _dl_open(libname, O_RDONLY);
  290. if (infile < 0) {
  291. #if 0
  292. /*
  293. * NO! When we open shared libraries we may search several paths.
  294. * it is inappropriate to generate an error here.
  295. */
  296. _dl_dprintf(2, "%s: can't open '%s'\n", _dl_progname, libname);
  297. #endif
  298. _dl_internal_error_number = DL_ERROR_NOFILE;
  299. return NULL;
  300. }
  301. _dl_read(infile, header, sizeof(header));
  302. epnt = (elfhdr *) header;
  303. if (epnt->e_ident[0] != 0x7f ||
  304. epnt->e_ident[1] != 'E' ||
  305. epnt->e_ident[2] != 'L' ||
  306. epnt->e_ident[3] != 'F')
  307. {
  308. _dl_dprintf(2, "%s: '%s' is not an ELF file\n", _dl_progname,
  309. libname);
  310. _dl_internal_error_number = DL_ERROR_NOTELF;
  311. _dl_close(infile);
  312. return NULL;
  313. };
  314. if ((epnt->e_type != ET_DYN) || (epnt->e_machine != MAGIC1
  315. #ifdef MAGIC2
  316. && epnt->e_machine != MAGIC2
  317. #endif
  318. ))
  319. {
  320. _dl_internal_error_number =
  321. (epnt->e_type != ET_DYN ? DL_ERROR_NOTDYN : DL_ERROR_NOTMAGIC);
  322. _dl_dprintf(2, "%s: '%s' is not an ELF executable for " ELF_TARGET
  323. "\n", _dl_progname, libname);
  324. _dl_close(infile);
  325. return NULL;
  326. };
  327. ppnt = (elf_phdr *) & header[epnt->e_phoff];
  328. piclib = 1;
  329. for (i = 0; i < epnt->e_phnum; i++) {
  330. if (ppnt->p_type == PT_DYNAMIC) {
  331. if (dynamic_addr)
  332. _dl_dprintf(2, "%s: '%s' has more than one dynamic section\n",
  333. _dl_progname, libname);
  334. dynamic_addr = ppnt->p_vaddr;
  335. dynamic_size = ppnt->p_filesz;
  336. };
  337. if (ppnt->p_type == PT_LOAD) {
  338. /* See if this is a PIC library. */
  339. if (i == 0 && ppnt->p_vaddr > 0x1000000) {
  340. piclib = 0;
  341. minvma = ppnt->p_vaddr;
  342. }
  343. if (piclib && ppnt->p_vaddr < minvma) {
  344. minvma = ppnt->p_vaddr;
  345. }
  346. if (((unsigned long) ppnt->p_vaddr + ppnt->p_memsz) > maxvma) {
  347. maxvma = ppnt->p_vaddr + ppnt->p_memsz;
  348. }
  349. }
  350. ppnt++;
  351. };
  352. maxvma = (maxvma + 0xfffU) & ~0xfffU;
  353. minvma = minvma & ~0xffffU;
  354. flags = MAP_PRIVATE /*| MAP_DENYWRITE */ ;
  355. if (!piclib)
  356. flags |= MAP_FIXED;
  357. status = (char *) _dl_mmap((char *) (piclib ? 0 : minvma),
  358. maxvma - minvma, PROT_NONE, flags | MAP_ANONYMOUS, -1, 0);
  359. if (_dl_mmap_check_error(status)) {
  360. _dl_dprintf(2, "%s: can't map %s\n", _dl_progname, libname);
  361. _dl_internal_error_number = DL_ERROR_MMAP_FAILED;
  362. _dl_close(infile);
  363. return NULL;
  364. };
  365. libaddr = (unsigned long) status;
  366. flags |= MAP_FIXED;
  367. /* Get the memory to store the library */
  368. ppnt = (elf_phdr *) & header[epnt->e_phoff];
  369. for (i = 0; i < epnt->e_phnum; i++) {
  370. if (ppnt->p_type == PT_LOAD) {
  371. /* See if this is a PIC library. */
  372. if (i == 0 && ppnt->p_vaddr > 0x1000000) {
  373. piclib = 0;
  374. /* flags |= MAP_FIXED; */
  375. }
  376. if (ppnt->p_flags & PF_W) {
  377. unsigned long map_size;
  378. char *cpnt;
  379. status = (char *) _dl_mmap((char *) ((piclib ? libaddr : 0) +
  380. (ppnt->p_vaddr & PAGE_ALIGN)), (ppnt->p_vaddr & ADDR_ALIGN)
  381. + ppnt->p_filesz, LXFLAGS(ppnt->p_flags), flags, infile,
  382. ppnt->p_offset & OFFS_ALIGN);
  383. if (_dl_mmap_check_error(status)) {
  384. _dl_dprintf(2, "%s: can't map '%s'\n",
  385. _dl_progname, libname);
  386. _dl_internal_error_number = DL_ERROR_MMAP_FAILED;
  387. _dl_munmap((char *) libaddr, maxvma - minvma);
  388. _dl_close(infile);
  389. return NULL;
  390. };
  391. /* Pad the last page with zeroes. */
  392. cpnt = (char *) (status + (ppnt->p_vaddr & ADDR_ALIGN) +
  393. ppnt->p_filesz);
  394. while (((unsigned long) cpnt) & ADDR_ALIGN)
  395. *cpnt++ = 0;
  396. /* I am not quite sure if this is completely
  397. * correct to do or not, but the basic way that
  398. * we handle bss segments is that we mmap
  399. * /dev/zero if there are any pages left over
  400. * that are not mapped as part of the file */
  401. map_size = (ppnt->p_vaddr + ppnt->p_filesz + ADDR_ALIGN) & PAGE_ALIGN;
  402. if (map_size < ppnt->p_vaddr + ppnt->p_memsz)
  403. status = (char *) _dl_mmap((char *) map_size +
  404. (piclib ? libaddr : 0),
  405. ppnt->p_vaddr + ppnt->p_memsz - map_size,
  406. LXFLAGS(ppnt->p_flags), flags | MAP_ANONYMOUS, -1, 0);
  407. } else
  408. status = (char *) _dl_mmap((char *) (ppnt->p_vaddr & PAGE_ALIGN)
  409. + (piclib ? libaddr : 0), (ppnt->p_vaddr & ADDR_ALIGN) +
  410. ppnt->p_filesz, LXFLAGS(ppnt->p_flags), flags,
  411. infile, ppnt->p_offset & OFFS_ALIGN);
  412. if (_dl_mmap_check_error(status)) {
  413. _dl_dprintf(2, "%s: can't map '%s'\n", _dl_progname, libname);
  414. _dl_internal_error_number = DL_ERROR_MMAP_FAILED;
  415. _dl_munmap((char *) libaddr, maxvma - minvma);
  416. _dl_close(infile);
  417. return NULL;
  418. };
  419. /* if(libaddr == 0 && piclib) {
  420. libaddr = (unsigned long) status;
  421. flags |= MAP_FIXED;
  422. }; */
  423. };
  424. ppnt++;
  425. };
  426. _dl_close(infile);
  427. /* For a non-PIC library, the addresses are all absolute */
  428. if (piclib) {
  429. dynamic_addr += (unsigned long) libaddr;
  430. }
  431. /*
  432. * OK, the ELF library is now loaded into VM in the correct locations
  433. * The next step is to go through and do the dynamic linking (if needed).
  434. */
  435. /* Start by scanning the dynamic section to get all of the pointers */
  436. if (!dynamic_addr) {
  437. _dl_internal_error_number = DL_ERROR_NODYNAMIC;
  438. _dl_dprintf(2, "%s: '%s' is missing a dynamic section\n",
  439. _dl_progname, libname);
  440. return NULL;
  441. }
  442. dpnt = (Elf32_Dyn *) dynamic_addr;
  443. dynamic_size = dynamic_size / sizeof(Elf32_Dyn);
  444. _dl_memset(dynamic_info, 0, sizeof(dynamic_info));
  445. #if defined(__mips__)
  446. {
  447. int i = 1;
  448. Elf32_Dyn *dpnt = (Elf32_Dyn *) dynamic_addr;
  449. while(dpnt->d_tag) {
  450. dpnt++;
  451. i++;
  452. }
  453. dynamic_size = i;
  454. }
  455. #endif
  456. for (i = 0; i < dynamic_size; i++)
  457. {
  458. if (dpnt->d_tag > DT_JMPREL) {
  459. dpnt++;
  460. continue;
  461. }
  462. dynamic_info[dpnt->d_tag] = dpnt->d_un.d_val;
  463. if (dpnt->d_tag == DT_TEXTREL || SVR4_BUGCOMPAT)
  464. dynamic_info[DT_TEXTREL] = 1;
  465. dpnt++;
  466. };
  467. /* If the TEXTREL is set, this means that we need to make the pages
  468. writable before we perform relocations. Do this now. They get set
  469. back again later. */
  470. if (dynamic_info[DT_TEXTREL]) {
  471. ppnt = (elf_phdr *) & header[epnt->e_phoff];
  472. for (i = 0; i < epnt->e_phnum; i++, ppnt++) {
  473. if (ppnt->p_type == PT_LOAD && !(ppnt->p_flags & PF_W))
  474. _dl_mprotect((void *) ((piclib ? libaddr : 0) +
  475. (ppnt->p_vaddr & PAGE_ALIGN)),
  476. (ppnt->p_vaddr & ADDR_ALIGN) + (unsigned long) ppnt->p_filesz,
  477. PROT_READ | PROT_WRITE | PROT_EXEC);
  478. }
  479. }
  480. tpnt = _dl_add_elf_hash_table(libname, (char *) libaddr, dynamic_info,
  481. dynamic_addr, dynamic_size);
  482. tpnt->ppnt = (elf_phdr *) (tpnt->loadaddr + epnt->e_phoff);
  483. tpnt->n_phent = epnt->e_phnum;
  484. /*
  485. * Add this object into the symbol chain
  486. */
  487. (*rpnt)->next = (struct dyn_elf *)
  488. _dl_malloc(sizeof(struct dyn_elf));
  489. _dl_memset((*rpnt)->next, 0, sizeof(*((*rpnt)->next)));
  490. *rpnt = (*rpnt)->next;
  491. tpnt->usage_count++;
  492. tpnt->symbol_scope = _dl_symbol_tables;
  493. tpnt->libtype = elf_lib;
  494. (*rpnt)->dyn = tpnt;
  495. /*
  496. * OK, the next thing we need to do is to insert the dynamic linker into
  497. * the proper entry in the GOT so that the PLT symbols can be properly
  498. * resolved.
  499. */
  500. lpnt = (unsigned long *) dynamic_info[DT_PLTGOT];
  501. if (lpnt) {
  502. lpnt = (unsigned long *) (dynamic_info[DT_PLTGOT] +
  503. ((int) libaddr));
  504. INIT_GOT(lpnt, tpnt);
  505. };
  506. return tpnt;
  507. }
  508. /* Ugly, ugly. Some versions of the SVr4 linker fail to generate COPY
  509. relocations for global variables that are present both in the image and
  510. the shared library. Go through and do it manually. If the images
  511. are guaranteed to be generated by a trustworthy linker, then this
  512. step can be skipped. */
  513. int _dl_copy_fixups(struct dyn_elf *rpnt)
  514. {
  515. int goof = 0;
  516. struct elf_resolve *tpnt;
  517. if (rpnt->next)
  518. goof += _dl_copy_fixups(rpnt->next);
  519. else
  520. return 0;
  521. tpnt = rpnt->dyn;
  522. if (tpnt->init_flag & COPY_RELOCS_DONE)
  523. return goof;
  524. tpnt->init_flag |= COPY_RELOCS_DONE;
  525. #ifdef ELF_USES_RELOCA
  526. goof += _dl_parse_copy_information(rpnt,
  527. tpnt->dynamic_info[DT_RELA], tpnt->dynamic_info[DT_RELASZ], 0);
  528. #else
  529. goof += _dl_parse_copy_information(rpnt, tpnt->dynamic_info[DT_REL],
  530. tpnt->dynamic_info[DT_RELSZ], 0);
  531. #endif
  532. return goof;
  533. }