readelflib1.c 16 KB

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