elfinterp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. /* vi: set sw=4 ts=4: */
  2. /* powerpc shared library loader suppport
  3. *
  4. * Copyright (C) 2001-2002, David A. Schleef
  5. * Copyright (C) 2003, Erik Andersen
  6. *
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. The name of the above contributors may not be
  15. * used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. */
  30. #if defined (__SUPPORT_LD_DEBUG__)
  31. static const char *_dl_reltypes_tab[] =
  32. { "R_PPC_NONE", "R_PPC_ADDR32", "R_PPC_ADDR24", "R_PPC_ADDR16",
  33. "R_PPC_ADDR16_LO", "R_PPC_ADDR16_HI", "R_PPC_ADDR16_HA",
  34. "R_PPC_ADDR14", "R_PPC_ADDR14_BRTAKEN", "R_PPC_ADDR14_BRNTAKEN",
  35. "R_PPC_REL24", "R_PPC_REL14", "R_PPC_REL14_BRTAKEN",
  36. "R_PPC_REL14_BRNTAKEN", "R_PPC_GOT16", "R_PPC_GOT16_LO",
  37. "R_PPC_GOT16_HI", "R_PPC_GOT16_HA", "R_PPC_PLTREL24",
  38. "R_PPC_COPY", "R_PPC_GLOB_DAT", "R_PPC_JMP_SLOT", "R_PPC_RELATIVE",
  39. "R_PPC_LOCAL24PC", "R_PPC_UADDR32", "R_PPC_UADDR16", "R_PPC_REL32",
  40. "R_PPC_PLT32", "R_PPC_PLTREL32", "R_PPC_PLT16_LO", "R_PPC_PLT16_HI",
  41. "R_PPC_PLT16_HA", "R_PPC_SDAREL16", "R_PPC_SECTOFF",
  42. "R_PPC_SECTOFF_LO", "R_PPC_SECTOFF_HI", "R_PPC_SECTOFF_HA",
  43. };
  44. static const char *
  45. _dl_reltypes(int type)
  46. {
  47. static char buf[22];
  48. const char *str;
  49. if (type >= (int)(sizeof (_dl_reltypes_tab)/sizeof(_dl_reltypes_tab[0])) ||
  50. NULL == (str = _dl_reltypes_tab[type]))
  51. {
  52. str =_dl_simple_ltoa( buf, (unsigned long)(type));
  53. }
  54. return str;
  55. }
  56. static
  57. void debug_sym(Elf32_Sym *symtab,char *strtab,int symtab_index)
  58. {
  59. if(_dl_debug_symbols)
  60. {
  61. if(symtab_index){
  62. _dl_dprintf(_dl_debug_file, "\n%s\n\tvalue=%x\tsize=%x\tinfo=%x\tother=%x\tshndx=%x",
  63. strtab + symtab[symtab_index].st_name,
  64. symtab[symtab_index].st_value,
  65. symtab[symtab_index].st_size,
  66. symtab[symtab_index].st_info,
  67. symtab[symtab_index].st_other,
  68. symtab[symtab_index].st_shndx);
  69. }
  70. }
  71. }
  72. static
  73. void debug_reloc(Elf32_Sym *symtab,char *strtab, ELF_RELOC *rpnt)
  74. {
  75. if(_dl_debug_reloc)
  76. {
  77. int symtab_index;
  78. const char *sym;
  79. symtab_index = ELF32_R_SYM(rpnt->r_info);
  80. sym = symtab_index ? strtab + symtab[symtab_index].st_name : "sym=0x0";
  81. if(_dl_debug_symbols)
  82. _dl_dprintf(_dl_debug_file, "\n\t");
  83. else
  84. _dl_dprintf(_dl_debug_file, "\n%s\n\t", sym);
  85. #ifdef ELF_USES_RELOCA
  86. _dl_dprintf(_dl_debug_file, "%s\toffset=%x\taddend=%x",
  87. _dl_reltypes(ELF32_R_TYPE(rpnt->r_info)),
  88. rpnt->r_offset,
  89. rpnt->r_addend);
  90. #else
  91. _dl_dprintf(_dl_debug_file, "%s\toffset=%x\n",
  92. _dl_reltypes(ELF32_R_TYPE(rpnt->r_info)),
  93. rpnt->r_offset);
  94. #endif
  95. }
  96. }
  97. #endif
  98. extern int _dl_linux_resolve(void);
  99. void _dl_init_got(unsigned long *plt,struct elf_resolve *tpnt)
  100. {
  101. Elf32_Word *tramp;
  102. Elf32_Word num_plt_entries;
  103. Elf32_Word data_words;
  104. Elf32_Word rel_offset_words;
  105. Elf32_Word dlrr = (Elf32_Word) _dl_linux_resolve;
  106. num_plt_entries = tpnt->dynamic_info[DT_PLTRELSZ] / sizeof(ELF_RELOC);
  107. rel_offset_words = PLT_DATA_START_WORDS(num_plt_entries);
  108. data_words = (Elf32_Word) (plt + rel_offset_words);
  109. tpnt->data_words = data_words;
  110. plt[PLT_LONGBRANCH_ENTRY_WORDS] = OPCODE_ADDIS_HI(11, 11, data_words);
  111. plt[PLT_LONGBRANCH_ENTRY_WORDS+1] = OPCODE_LWZ(11,data_words,11);
  112. plt[PLT_LONGBRANCH_ENTRY_WORDS+2] = OPCODE_MTCTR(11);
  113. plt[PLT_LONGBRANCH_ENTRY_WORDS+3] = OPCODE_BCTR();
  114. /* [4] */
  115. /* [5] */
  116. tramp = (Elf32_Word *) (plt + PLT_TRAMPOLINE_ENTRY_WORDS);
  117. /* For the long entries, subtract off data_words. */
  118. tramp[0] = OPCODE_ADDIS_HI(11,11,-data_words);
  119. tramp[1] = OPCODE_ADDI(11,11,-data_words);
  120. /* Multiply index of entry by 3 (in r11). */
  121. tramp[2] = OPCODE_SLWI(12,11,1);
  122. tramp[3] = OPCODE_ADD(11,12,11);
  123. if (dlrr <= 0x01fffffc || dlrr >= 0xfe000000) {
  124. /* Load address of link map in r12. */
  125. tramp[4] = OPCODE_LI (12, (Elf32_Word) tpnt);
  126. tramp[5] = OPCODE_ADDIS_HI (12, 12, (Elf32_Word) tpnt);
  127. /* Call _dl_linux_resolve . */
  128. tramp[6] = OPCODE_BA (dlrr);
  129. } else {
  130. /* Get address of _dl_linux_resolve in CTR. */
  131. tramp[4] = OPCODE_LI(12,dlrr);
  132. tramp[5] = OPCODE_ADDIS_HI(12,12,dlrr);
  133. tramp[6] = OPCODE_MTCTR(12);
  134. /* Load address of link map in r12. */
  135. tramp[7] = OPCODE_LI(12,(Elf32_Word) tpnt);
  136. tramp[8] = OPCODE_ADDIS_HI(12,12,(Elf32_Word) tpnt);
  137. /* Call _dl_linux_resolve. */
  138. tramp[9] = OPCODE_BCTR();
  139. }
  140. /* [16] unused */
  141. /* [17] unused */
  142. PPC_DCBST(plt);
  143. PPC_DCBST(plt+4);
  144. PPC_DCBST(plt+8);
  145. PPC_DCBST(plt+12);
  146. PPC_DCBST(plt+16-1);
  147. PPC_SYNC;
  148. PPC_ICBI(plt);
  149. PPC_ICBI(plt+16-1);
  150. PPC_ISYNC;
  151. }
  152. unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
  153. {
  154. ELF_RELOC *this_reloc;
  155. char *strtab;
  156. Elf32_Sym *symtab;
  157. ELF_RELOC *rel_addr;
  158. int symtab_index;
  159. char *symname;
  160. Elf32_Addr *reloc_addr;
  161. Elf32_Addr finaladdr;
  162. Elf32_Sword delta;
  163. rel_addr = (ELF_RELOC *) (tpnt->dynamic_info[DT_JMPREL] + tpnt->loadaddr);
  164. this_reloc = (void *)rel_addr + reloc_entry;
  165. symtab_index = ELF32_R_SYM(this_reloc->r_info);
  166. symtab = (Elf32_Sym *) (tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr);
  167. strtab = (char *) (tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr);
  168. symname = strtab + symtab[symtab_index].st_name;
  169. #if defined (__SUPPORT_LD_DEBUG__)
  170. debug_sym(symtab,strtab,symtab_index);
  171. debug_reloc(symtab,strtab,this_reloc);
  172. if (ELF32_R_TYPE(this_reloc->r_info) != R_PPC_JMP_SLOT) {
  173. _dl_dprintf(2, "%s: Incorrect relocation type in jump relocation\n", _dl_progname);
  174. _dl_exit(1);
  175. };
  176. #endif
  177. /* Address of dump instruction to fix up */
  178. reloc_addr = (Elf32_Addr *) (tpnt->loadaddr + this_reloc->r_offset);
  179. #if defined (__SUPPORT_LD_DEBUG__)
  180. if(_dl_debug_reloc && _dl_debug_detail)
  181. _dl_dprintf(_dl_debug_file, "\n\tResolving symbol %s %x --> ", symname, (Elf32_Addr)reloc_addr);
  182. #endif
  183. /* Get the address of the GOT entry */
  184. finaladdr = (Elf32_Addr) _dl_find_hash(strtab + symtab[symtab_index].st_name,
  185. tpnt->symbol_scope, tpnt, resolver);
  186. if (!finaladdr) {
  187. _dl_dprintf(2, "%s: can't resolve symbol '%s'\n", _dl_progname, symname);
  188. _dl_exit(1);
  189. };
  190. #if defined (__SUPPORT_LD_DEBUG__)
  191. if(_dl_debug_reloc && _dl_debug_detail)
  192. _dl_dprintf(_dl_debug_file, "%x\n", finaladdr);
  193. #endif
  194. delta = finaladdr - (Elf32_Word)reloc_addr;
  195. if (delta<<6>>6 == delta) {
  196. *reloc_addr = OPCODE_B(delta);
  197. #if 0
  198. /* this will almost never be true */
  199. } else if (finaladdr <= 0x01fffffc || finaladdr >= 0xfe000000) {
  200. *reloc_addr = OPCODE_BA (finaladdr);
  201. #endif
  202. } else {
  203. /* Warning: we don't handle double-sized PLT entries */
  204. Elf32_Word *plt, *data_words, index, offset;
  205. plt = (Elf32_Word *)(tpnt->dynamic_info[DT_PLTGOT] + tpnt->loadaddr);
  206. offset = reloc_addr - plt;
  207. index = (offset - PLT_INITIAL_ENTRY_WORDS)/2;
  208. data_words = (Elf32_Word *)tpnt->data_words;
  209. reloc_addr += 1;
  210. data_words[index] = finaladdr;
  211. PPC_SYNC;
  212. *reloc_addr = OPCODE_B ((PLT_LONGBRANCH_ENTRY_WORDS - (offset+1)) * 4);
  213. }
  214. /* instructions were modified */
  215. PPC_DCBST(reloc_addr);
  216. PPC_SYNC;
  217. PPC_ICBI(reloc_addr);
  218. PPC_ISYNC;
  219. return finaladdr;
  220. }
  221. static int
  222. _dl_parse(struct elf_resolve *tpnt, struct dyn_elf *scope,
  223. unsigned long rel_addr, unsigned long rel_size,
  224. int (*reloc_fnc) (struct elf_resolve *tpnt, struct dyn_elf *scope,
  225. ELF_RELOC *rpnt, Elf32_Sym *symtab, char *strtab))
  226. {
  227. unsigned int i;
  228. char *strtab;
  229. Elf32_Sym *symtab;
  230. ELF_RELOC *rpnt;
  231. int symtab_index;
  232. /* Now parse the relocation information */
  233. rpnt = (ELF_RELOC *)(intptr_t) (rel_addr + tpnt->loadaddr);
  234. rel_size = rel_size / sizeof(ELF_RELOC);
  235. symtab = (Elf32_Sym *)(intptr_t) (tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr);
  236. strtab = (char *) (tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr);
  237. for (i = 0; i < rel_size; i++, rpnt++) {
  238. int res;
  239. symtab_index = ELF32_R_SYM(rpnt->r_info);
  240. /* When the dynamic linker bootstrapped itself, it resolved some symbols.
  241. Make sure we do not do them again */
  242. if (!symtab_index && tpnt->libtype == program_interpreter)
  243. continue;
  244. if (symtab_index && tpnt->libtype == program_interpreter &&
  245. _dl_symbol(strtab + symtab[symtab_index].st_name))
  246. continue;
  247. #if defined (__SUPPORT_LD_DEBUG__)
  248. debug_sym(symtab,strtab,symtab_index);
  249. debug_reloc(symtab,strtab,rpnt);
  250. #endif
  251. res = reloc_fnc (tpnt, scope, rpnt, symtab, strtab);
  252. if (res==0) continue;
  253. _dl_dprintf(2, "\n%s: ",_dl_progname);
  254. if (symtab_index)
  255. _dl_dprintf(2, "symbol '%s': ", strtab + symtab[symtab_index].st_name);
  256. if (res <0)
  257. {
  258. int reloc_type = ELF32_R_TYPE(rpnt->r_info);
  259. #if defined (__SUPPORT_LD_DEBUG__)
  260. _dl_dprintf(2, "can't handle reloc type %s\n ", _dl_reltypes(reloc_type));
  261. #else
  262. _dl_dprintf(2, "can't handle reloc type %x\n", reloc_type);
  263. #endif
  264. _dl_exit(-res);
  265. }
  266. else if (res >0)
  267. {
  268. _dl_dprintf(2, "can't resolve symbol\n");
  269. return res;
  270. }
  271. }
  272. return 0;
  273. }
  274. static int
  275. _dl_do_reloc (struct elf_resolve *tpnt,struct dyn_elf *scope,
  276. ELF_RELOC *rpnt, Elf32_Sym *symtab, char *strtab)
  277. {
  278. int reloc_type;
  279. int symtab_index;
  280. char *symname;
  281. Elf32_Addr *reloc_addr;
  282. Elf32_Addr finaladdr;
  283. unsigned long symbol_addr;
  284. #if defined (__SUPPORT_LD_DEBUG__)
  285. unsigned long old_val;
  286. #endif
  287. reloc_addr = (Elf32_Addr *)(intptr_t) (tpnt->loadaddr + (unsigned long) rpnt->r_offset);
  288. reloc_type = ELF32_R_TYPE(rpnt->r_info);
  289. if (reloc_type == R_PPC_RELATIVE) {
  290. *reloc_addr = tpnt->loadaddr + rpnt->r_addend;
  291. return 0;
  292. }
  293. if (reloc_type == R_PPC_NONE || reloc_type == R_PPC_COPY) /* R_PPC_COPY is handled later */
  294. return 0;
  295. symtab_index = ELF32_R_SYM(rpnt->r_info);
  296. symname = strtab + symtab[symtab_index].st_name;
  297. symbol_addr = (unsigned long) _dl_find_hash(symname, scope,
  298. (reloc_type == R_PPC_JMP_SLOT ? tpnt : NULL), symbolrel);
  299. /*
  300. * We want to allow undefined references to weak symbols - this might
  301. * have been intentional. We should not be linking local symbols
  302. * here, so all bases should be covered.
  303. */
  304. if (!symbol_addr && ELF32_ST_BIND(symtab[symtab_index].st_info) == STB_GLOBAL) {
  305. #if defined (__SUPPORT_LD_DEBUG__)
  306. _dl_dprintf(2, "\tglobal symbol '%s' already defined in '%s', rel type: %s\n",
  307. symname, tpnt->libname, _dl_reltypes(reloc_type));
  308. #endif
  309. return 0;
  310. }
  311. #if defined (__SUPPORT_LD_DEBUG__)
  312. old_val = *reloc_addr;
  313. #endif
  314. finaladdr = (Elf32_Addr) (symbol_addr + rpnt->r_addend);
  315. switch (reloc_type) {
  316. case R_PPC_ADDR32:
  317. case R_PPC_GLOB_DAT:
  318. *reloc_addr = finaladdr;
  319. return 0; /* No code code modified */
  320. break;
  321. case R_PPC_JMP_SLOT:
  322. {
  323. Elf32_Sword delta = finaladdr - (Elf32_Word)reloc_addr;
  324. if (delta<<6>>6 == delta) {
  325. *reloc_addr = OPCODE_B(delta);
  326. #if 0
  327. /* this will almost never be true */
  328. } else if (finaladdr <= 0x01fffffc || finaladdr >= 0xfe000000) {
  329. *reloc_addr = OPCODE_BA (finaladdr);
  330. #endif
  331. } else {
  332. /* Warning: we don't handle double-sized PLT entries */
  333. Elf32_Word *plt, *data_words, index, offset;
  334. plt = (Elf32_Word *)(tpnt->dynamic_info[DT_PLTGOT] + tpnt->loadaddr);
  335. offset = reloc_addr - plt;
  336. index = (offset - PLT_INITIAL_ENTRY_WORDS)/2;
  337. data_words = (Elf32_Word *)tpnt->data_words;
  338. data_words[index] = finaladdr;
  339. reloc_addr[0] = OPCODE_LI(11,index*4);
  340. reloc_addr[1] = OPCODE_B((PLT_LONGBRANCH_ENTRY_WORDS - (offset+1)) * 4);
  341. /* instructions were modified */
  342. PPC_DCBST(reloc_addr+1);
  343. PPC_SYNC;
  344. PPC_ICBI(reloc_addr+1);
  345. }
  346. break;
  347. }
  348. case R_PPC_COPY:
  349. /* This does not work yet, R_PPC_COPY is handled later, see if statemet above */
  350. if (symbol_addr) {
  351. #if defined (__SUPPORT_LD_DEBUG__)
  352. if(_dl_debug_move)
  353. _dl_dprintf(_dl_debug_file,"\n%s move %x bytes from %x to %x",
  354. symname, symtab[symtab_index].st_size,
  355. symbol_addr, symtab[symtab_index].st_value);
  356. #endif
  357. _dl_memcpy((char *) reloc_addr, (char *) finaladdr, symtab[symtab_index].st_size);
  358. }
  359. return 0; /* No code code modified */
  360. break;
  361. case R_PPC_ADDR16_HA:
  362. *(short *)reloc_addr = (finaladdr + 0x8000)>>16;
  363. break;
  364. case R_PPC_ADDR16_HI:
  365. *(short *)reloc_addr = finaladdr >> 16;
  366. break;
  367. case R_PPC_ADDR16_LO:
  368. *(short *)reloc_addr = finaladdr;
  369. break;
  370. case R_PPC_REL24:
  371. {
  372. Elf32_Sword delta = finaladdr - (Elf32_Word)reloc_addr;
  373. if(delta<<6>>6 != delta){
  374. _dl_dprintf(2, "%s: symbol '%s' R_PPC_REL24 is out of range.\n\tCompile shared libraries with -fPIC!\n",
  375. _dl_progname, symname);
  376. _dl_exit(1);
  377. }
  378. *reloc_addr = (*reloc_addr & 0xfc000003) | (delta & 0x3fffffc);
  379. break;
  380. }
  381. default:
  382. _dl_dprintf(2, "%s: can't handle reloc type ", _dl_progname);
  383. #if defined (__SUPPORT_LD_DEBUG__)
  384. _dl_dprintf(2, "%s ", _dl_reltypes(reloc_type));
  385. #endif
  386. if (symtab_index)
  387. _dl_dprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name);
  388. return -1;
  389. };
  390. /* instructions were modified */
  391. PPC_DCBST(reloc_addr);
  392. PPC_SYNC;
  393. PPC_ICBI(reloc_addr);
  394. PPC_ISYNC;
  395. #if defined (__SUPPORT_LD_DEBUG__)
  396. if(_dl_debug_reloc && _dl_debug_detail)
  397. _dl_dprintf(_dl_debug_file, "\tpatched: %x ==> %x @ %x", old_val, *reloc_addr, reloc_addr);
  398. #endif
  399. return 0;
  400. }
  401. /* This is done as a separate step, because there are cases where
  402. information is first copied and later initialized. This results in
  403. the wrong information being copied. Someone at Sun was complaining about
  404. a bug in the handling of _COPY by SVr4, and this may in fact be what he
  405. was talking about. Sigh. */
  406. static int
  407. _dl_do_copy (struct elf_resolve *tpnt, struct dyn_elf *scope,
  408. ELF_RELOC *rpnt, Elf32_Sym *symtab, char *strtab)
  409. {
  410. int reloc_type;
  411. int symtab_index;
  412. unsigned long *reloc_addr;
  413. unsigned long symbol_addr;
  414. int goof = 0;
  415. char *symname;
  416. reloc_addr = (unsigned long *)(intptr_t) (tpnt->loadaddr + (unsigned long) rpnt->r_offset);
  417. reloc_type = ELF32_R_TYPE(rpnt->r_info);
  418. if (reloc_type != R_PPC_COPY)
  419. return 0;
  420. symtab_index = ELF32_R_SYM(rpnt->r_info);
  421. symbol_addr = 0;
  422. symname = strtab + symtab[symtab_index].st_name;
  423. if (symtab_index) {
  424. symbol_addr = (unsigned long) _dl_find_hash(symname, scope, NULL, copyrel);
  425. if (!symbol_addr) goof++;
  426. }
  427. if (!goof) {
  428. #if defined (__SUPPORT_LD_DEBUG__)
  429. if(_dl_debug_move)
  430. _dl_dprintf(_dl_debug_file,"\n%s move %x bytes from %x to %x",
  431. symname, symtab[symtab_index].st_size,
  432. symbol_addr, symtab[symtab_index].st_value);
  433. #endif
  434. _dl_memcpy((char *) reloc_addr,
  435. (char *) (symbol_addr + (unsigned long)rpnt->r_addend), symtab[symtab_index].st_size);
  436. }
  437. return goof;
  438. }
  439. void _dl_parse_lazy_relocation_information(struct elf_resolve *tpnt,
  440. unsigned long rel_addr, unsigned long rel_size, int type)
  441. {
  442. Elf32_Word *plt, offset, i, num_plt_entries, rel_offset_words;
  443. (void) type;
  444. num_plt_entries = rel_size / sizeof(ELF_RELOC);
  445. /* When the dynamic linker bootstrapped itself, it resolved some symbols.
  446. Make sure we do not do them again */
  447. if (tpnt->libtype == program_interpreter)
  448. return;
  449. rel_offset_words = PLT_DATA_START_WORDS(num_plt_entries);
  450. plt = (Elf32_Word *)(tpnt->dynamic_info[DT_PLTGOT] + tpnt->loadaddr);
  451. /* Set up the lazy PLT entries. */
  452. offset = PLT_INITIAL_ENTRY_WORDS;
  453. i = 0;
  454. /* Warning: we don't handle double-sized PLT entries */
  455. while (i < num_plt_entries) {
  456. plt[offset ] = OPCODE_LI(11, i * 4);
  457. plt[offset+1] = OPCODE_B((PLT_TRAMPOLINE_ENTRY_WORDS + 2 - (offset+1)) * 4);
  458. i++;
  459. offset += 2;
  460. }
  461. /* Now, we've modified code. We need to write the changes from
  462. the data cache to a second-level unified cache, then make
  463. sure that stale data in the instruction cache is removed.
  464. (In a multiprocessor system, the effect is more complex.)
  465. Most of the PLT shouldn't be in the instruction cache, but
  466. there may be a little overlap at the start and the end.
  467. Assumes that dcbst and icbi apply to lines of 16 bytes or
  468. more. Current known line sizes are 16, 32, and 128 bytes. */
  469. for (i = 0; i < rel_offset_words; i += 4)
  470. PPC_DCBST (plt + i);
  471. PPC_DCBST (plt + rel_offset_words - 1);
  472. PPC_SYNC;
  473. PPC_ICBI (plt);
  474. PPC_ICBI (plt + rel_offset_words - 1);
  475. PPC_ISYNC;
  476. }
  477. int _dl_parse_relocation_information(struct elf_resolve *tpnt,
  478. unsigned long rel_addr, unsigned long rel_size, int type)
  479. {
  480. (void) type;
  481. return _dl_parse(tpnt, tpnt->symbol_scope, rel_addr, rel_size, _dl_do_reloc);
  482. }
  483. int _dl_parse_copy_information(struct dyn_elf *xpnt, unsigned long rel_addr,
  484. unsigned long rel_size, int type)
  485. {
  486. (void) type;
  487. return _dl_parse(xpnt->dyn, xpnt->next, rel_addr, rel_size, _dl_do_copy);
  488. }