spacepaste

  1.  
  2. $ diff linker.c linker_original.c
  3. 30c30,31
  4. < #include <sys/sysfunc.h>
  5. ---
  6. > #include <sys/mman.h>
  7. > #include "/home/neon/git/CCR/Scripts/Shell/builtins/printfmacro.h"
  8. 32c33,35
  9. < #include <kernel/elf.h>
  10. ---
  11. >
  12. > #include <elf.h>
  13. > #define Elf32_Header Elf32_Ehdr
  14. 57c60
  15. < #define TRACE_APP_NAME "ld.so"
  16. ---
  17. > #define TRACE_APP_NAME "Dynamic Linker"
  18. 62c65
  19. < #include <toaru/trace.h>
  20. ---
  21. > #include "./trace.h"
  22. 69,70c72,73
  23. < #include "../lib/list.c"
  24. < #include "../lib/hashmap.c"
  25. ---
  26. > #include "./list.c"
  27. > #include "./hashmap.c"
  28. 271a275,801
  29. > int prot_from_phdr(const int p_flags)
  30. > {
  31. > int prot = 0;
  32. > if (p_flags & PF_R)
  33. > {
  34. > fprintf(stderr, "PROT_READ|");
  35. > prot |= PROT_READ;
  36. > }
  37. > if (p_flags & PF_W)
  38. > {
  39. > fprintf(stderr, "PROT_WRITE|");
  40. > prot |= PROT_WRITE;
  41. > }
  42. > if (p_flags & PF_X)
  43. > {
  44. > fprintf(stderr, "PROT_EXEC|");
  45. > prot |= PROT_EXEC;
  46. > }
  47. > return prot;
  48. > }
  49. >
  50. > uintptr_t round_down(uintptr_t value, uintptr_t size)
  51. > {
  52. > TRACE_LD("calling %s", __func__);
  53. > uintptr_t result = 0;
  54. > result = (value/size)*size;
  55. > TRACE_LD("returning %014p", result);
  56. > return result;
  57. > }
  58. >
  59. > Elf32_Dyn DYN_EMPTY = {0};
  60. >
  61. > Elf32_Dyn *
  62. > get_dynamic_entry(Elf32_Dyn *dynamic, int field)
  63. > {
  64. > TRACE_LD("called get_dynamic_entry");
  65. >
  66. > // Name Value d_un Executable Shared Object
  67. > // DT_NULL 0 ignored mandatory mandatory
  68. > // DT_NEEDED 1 d_val optional optional
  69. > // DT_PLTRELSZ 2 d_val optional optional
  70. > // DT_PLTGOT 3 d_ptr optional optional
  71. > // DT_HASH 4 d_ptr mandatory mandatory
  72. > // DT_STRTAB 5 d_ptr mandatory mandatory
  73. > // DT_SYMTAB 6 d_ptr mandatory mandatory
  74. > // DT_RELA 7 d_ptr mandatory optional
  75. > // DT_RELASZ 8 d_val mandatory optional
  76. > // DT_RELAENT 9 d_val mandatory optional
  77. > // DT_STRSZ 10 d_val mandatory mandatory
  78. > // DT_SYMENT 11 d_val mandatory mandatory
  79. > // DT_INIT 12 d_ptr optional optional
  80. > // DT_FINI 13 d_ptr optional optional
  81. > // DT_SONAME 14 d_val ignored optional
  82. > // DT_RPATH 15 d_val optional ignored
  83. > // DT_SYMBOLIC 16 ignored ignored optional
  84. > // DT_REL 17 d_ptr mandatory optional
  85. > // DT_RELSZ 18 d_val mandatory optional
  86. > // DT_RELENT 19 d_val mandatory optional
  87. > // DT_PLTREL 20 d_val optional optional
  88. > // DT_DEBUG 21 d_ptr optional ignored
  89. > // DT_TEXTREL 22 ignored optional optional
  90. > // DT_JMPREL 23 d_ptr optional optional
  91. > // DT_BIND_NOW 24 ignored optional optional
  92. > // DT_LOPROC 0x70000000 unspecified unspecified unspecified
  93. > // DT_HIPROC 0x7fffffff unspecified unspecified unspecified
  94. > //
  95. > // DT_NULL An entry with a DT_NULL tag marks the end of the _DYNAMIC array.
  96. > // DT_NEEDED This element holds the string table offset of a null-terminated string, giving
  97. > // the name of a needed library. The offset is an index into the table recorded
  98. > // in the DT_STRTAB entry. See "Shared Object Dependencies'' for more
  99. > // information about these names. The dynamic array may contain multiple
  100. > // entries with this type. These entries' relative order is significant, though
  101. > // their relation to entries of other types is not.
  102. > //
  103. > // DT_PLTRELSZ This element holds the total size, in bytes, of the relocation entries
  104. > // associated with the procedure linkage table. If an entry of type DT_JMPREL
  105. > // is present, a DT_PLTRELSZ must accompany it.
  106. > //
  107. > // DT_PLTGOT This element holds an address associated with the procedure linkage table
  108. > // and/or the global offset table.
  109. > //
  110. > // DT_HASH This element holds the address of the symbol hash table, described in "Hash
  111. > // Table". This hash table refers to the symbol table referenced by the
  112. > // DT_SYMTAB element.
  113. > //
  114. > // DT_STRTAB This element holds the address of the string table, described in Chapter 1.
  115. > // Symbol names, library names, and other strings reside in this table.
  116. > //
  117. > // DT_SYMTAB This element holds the address of the symbol table, described in
  118. > // Chapter 1, with Elf32_Sym entries for the 32-bit class of files.
  119. > //
  120. > // DT_RELA This element holds the address of a relocation table, described in
  121. > // Chapter 1. Entries in the table have explicit addends, such as Elf32_Rela
  122. > // for the 32-bit file class. An object file may have multiple relocation
  123. > // sections. When building the relocation table for an executable or shared
  124. > // object file, the link editor catenates those sections to form a single table.
  125. > // Although the sections remain independent in the object file, the dynamic
  126. > // linker sees a single table. When the dynamic linker creates the process
  127. > // image for an executable file or adds a shared object to the process image,
  128. > // it reads the relocation table and performs the associated actions. If this
  129. > // element is present, the dynamic structure must also have DT_RELASZ and
  130. > // DT_RELAENT elements. When relocation is "mandatory" for a file, either
  131. > // DT_RELA or DT_REL may occur (both are permitted but not required).
  132. > //
  133. > // DT_RELASZ This element holds the total size, in bytes, of the DT_RELA relocation table.
  134. > //
  135. > // DT_RELAENT This element holds the size, in bytes, of the DT_RELA relocation entry.
  136. > //
  137. > // DT_STRSZ This element holds the size, in bytes, of the string table.
  138. > //
  139. > // DT_SYMENT This element holds the size, in bytes, of a symbol table entry.
  140. > //
  141. > // DT_INIT This element holds the address of the initialization function, discussed in
  142. > // "Initialization and Termination Functions" below.
  143. > //
  144. > // DT_FINI This element holds the address of the termination function, discussed in
  145. > // "Initialization and Termination Functions" below.
  146. > //
  147. > // DT_SONAME This element holds the string table offset of a null-terminated string, giving
  148. > // the name of the shared object. The offset is an index into the table recorded
  149. > // in the DT_STRTAB entry. See "Shared Object Dependencies" below for
  150. > // more information about these names.
  151. > //
  152. > // DT_RPATH This element holds the string table offset of a null-terminated search library
  153. > // search path string, discussed in "Shared Object Dependencies". The offset
  154. > // is an index into the table recorded in the DT_STRTAB entry.
  155. > //
  156. > // DT_SYMBOLIC This element's presence in a shared object library alters the dynamic linker's
  157. > // symbol resolution algorithm for references within the library. Instead of
  158. > // starting a symbol search with the executable file, the dynamic linker starts
  159. > // from the shared object itself. If the shared object fails to supply the
  160. > // referenced symbol, the dynamic linker then searches the executable file and
  161. > // other shared objects as usual.
  162. > //
  163. > // DT_REL This element is similar to DT_RELA, except its table has implicit addends,
  164. > // such as Elf32_Rel for the 32-bit file class. If this element is present, the
  165. > // dynamic structure must also have DT_RELSZ and DT_RELENT elements.
  166. > //
  167. > // DT_RELSZ This element holds the total size, in bytes, of the DT_REL relocation table.
  168. > //
  169. > // DT_RELENT This element holds the size, in bytes, of the DT_REL relocation entry.
  170. > //
  171. > // DT_PLTREL This member specifies the type of relocation entry to which the procedure
  172. > // linkage table refers. The d_val member holds DT_REL or DT_RELA , as
  173. > // appropriate. All relocations in a procedure linkage table must use the same
  174. > // relocation.
  175. > //
  176. > // DT_DEBUG This member is used for debugging. Its contents are not specified in this
  177. > // document.
  178. > //
  179. > // DT_TEXTREL This member's absence signifies that no relocation entry should cause a
  180. > // modification to a non-writable segment, as specified by the segment
  181. > // permissions in the program header table. If this member is present, one or
  182. > // more relocation entries might request modifications to a non-writable
  183. > // segment, and the dynamic linker can prepare accordingly.
  184. > //
  185. > // DT_JMPREL If present, this entries d_ptr member holds the address of relocation
  186. > // entries associated solely with the procedure linkage table. Separating these
  187. > // relocation entries lets the dynamic linker ignore them during process
  188. > // initialization, if lazy binding is enabled. If this entry is present, the related
  189. > // entries of types DT_PLTRELSZ and DT_PLTREL must also be present.
  190. > //
  191. > // DT_BIND_NOW If present in a shared object or executable, this entry instructs the dynamic
  192. > // linker to process all relocations for the object containing this entry before
  193. > // transferring control to the program. The presence of this entry takes
  194. > // precedence over a directive to use lazy binding for this object when
  195. > // specified through the environment or via dlopen( BA_LIB).
  196. > //
  197. > // DT_LOPROC through DT_HIPROC
  198. > // Values in this inclusive range are reserved for processor-specific semantics.
  199. > // If meanings are specified, the processor supplement explains them.
  200. > //
  201. > // Except for the DT_NULL element at the end of the library[library_index].array, and the relative order of DT_NEEDED
  202. > // elements, entries may appear in any order. Tag values not appearing in the table are reserved.
  203. >
  204. >
  205. > for (; dynamic->d_tag != DT_NULL; dynamic++) {
  206. > fprintf(stderr, "testing if ");
  207. > /* Legal values for d_tag (dynamic entry type). */
  208. >
  209. > // #define DT_NULL 0 /* Marks end of dynamic section */
  210. > // #define DT_NEEDED 1 /* Name of needed library */
  211. > // #define DT_PLTRELSZ 2 /* Size in bytes of PLT relocs */
  212. > // #define DT_PLTGOT 3 /* Processor defined value */
  213. > // #define DT_HASH 4 /* Address of symbol hash table */
  214. > // #define DT_STRTAB 5 /* Address of string table */
  215. > // #define DT_SYMTAB 6 /* Address of symbol table */
  216. > // #define DT_RELA 7 /* Address of Rela relocs */
  217. > // #define DT_RELASZ 8 /* Total size of Rela relocs */
  218. > // #define DT_RELAENT 9 /* Size of one Rela reloc */
  219. > // #define DT_STRSZ 10 /* Size of string table */
  220. > // #define DT_SYMENT 11 /* Size of one symbol table entry */
  221. > // #define DT_INIT 12 /* Address of init function */
  222. > // #define DT_FINI 13 /* Address of termination function */
  223. > // #define DT_SONAME 14 /* Name of shared object */
  224. > // #define DT_RPATH 15 /* Library search path (deprecated) */
  225. > // #define DT_SYMBOLIC 16 /* Start symbol search here */
  226. > // #define DT_REL 17 /* Address of Rel relocs */
  227. > // #define DT_RELSZ 18 /* Total size of Rel relocs */
  228. > // #define DT_RELENT 19 /* Size of one Rel reloc */
  229. > // #define DT_PLTREL 20 /* Type of reloc in PLT */
  230. > // #define DT_DEBUG 21 /* For debugging; unspecified */
  231. > // #define DT_TEXTREL 22 /* Reloc might modify .text */
  232. > // #define DT_JMPREL 23 /* Address of PLT relocs */
  233. > // #define DT_BIND_NOW 24 /* Process relocations of object */
  234. > // #define DT_INIT_ARRAY 25 /* Array with addresses of init fct */
  235. > // #define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */
  236. > // #define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */
  237. > // #define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */
  238. > // #define DT_RUNPATH 29 /* Library search path */
  239. > // #define DT_FLAGS 30 /* Flags for the object being loaded */
  240. > // #define DT_ENCODING 32 /* Start of encoded range */
  241. > // #define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/
  242. > // #define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */
  243. > // #define DT_NUM 34 /* Number used */
  244. > // #define DT_LOOS 0x6000000d /* Start of OS-specific */
  245. > // #define DT_HIOS 0x6ffff000 /* End of OS-specific */
  246. > // #define DT_LOPROC 0x70000000 /* Start of processor-specific */
  247. > // #define DT_HIPROC 0x7fffffff /* End of processor-specific */
  248. > // #define DT_PROCNUM DT_MIPS_NUM /* Most used by any processor */
  249. > switch (dynamic->d_tag) {
  250. > case DT_NULL:
  251. > fprintf(stderr, "DT_NULL");
  252. > break;
  253. > case DT_NEEDED:
  254. > fprintf(stderr, "DT_NEEDED");
  255. > break;
  256. > case DT_PLTRELSZ:
  257. > fprintf(stderr, "DT_PLTRELSZ");
  258. > break;
  259. > case DT_PLTGOT:
  260. > fprintf(stderr, "DT_PLTGOT");
  261. > break;
  262. > case DT_HASH:
  263. > fprintf(stderr, "DT_HASH");
  264. > break;
  265. > case DT_STRTAB:
  266. > fprintf(stderr, "DT_STRTAB");
  267. > break;
  268. > case DT_SYMTAB:
  269. > fprintf(stderr, "DT_SYMTAB");
  270. > break;
  271. > case DT_RELA:
  272. > fprintf(stderr, "DT_RELA");
  273. > break;
  274. > case DT_RELASZ:
  275. > fprintf(stderr, "DT_RELASZ");
  276. > break;
  277. > case DT_RELAENT:
  278. > fprintf(stderr, "DT_RELAENT");
  279. > break;
  280. > case DT_STRSZ:
  281. > fprintf(stderr, "DT_STRSZ");
  282. > break;
  283. > case DT_SYMENT:
  284. > fprintf(stderr, "DT_SYMENT");
  285. > break;
  286. > case DT_INIT:
  287. > fprintf(stderr, "DT_INIT");
  288. > break;
  289. > case DT_FINI:
  290. > fprintf(stderr, "DT_FINI");
  291. > break;
  292. > case DT_SONAME:
  293. > fprintf(stderr, "DT_SONAME");
  294. > break;
  295. > case DT_RPATH:
  296. > fprintf(stderr, "DT_RPATH");
  297. > break;
  298. > case DT_SYMBOLIC:
  299. > fprintf(stderr, "DT_SYMBOLIC");
  300. > break;
  301. > case DT_REL:
  302. > fprintf(stderr, "DT_REL");
  303. > break;
  304. > case DT_RELSZ:
  305. > fprintf(stderr, "DT_RELSZ");
  306. > break;
  307. > case DT_RELENT:
  308. > fprintf(stderr, "DT_RELENT");
  309. > break;
  310. > case DT_PLTREL:
  311. > fprintf(stderr, "DT_PLTREL");
  312. > break;
  313. > case DT_DEBUG:
  314. > fprintf(stderr, "DT_DEBUG");
  315. > break;
  316. > case DT_TEXTREL:
  317. > fprintf(stderr, "DT_TEXTREL");
  318. > break;
  319. > case DT_JMPREL:
  320. > fprintf(stderr, "DT_JMPREL");
  321. > break;
  322. > case DT_BIND_NOW:
  323. > fprintf(stderr, "DT_BIND_NOW");
  324. > break;
  325. > case DT_INIT_ARRAY:
  326. > fprintf(stderr, "DT_INIT_ARRAY");
  327. > break;
  328. > case DT_FINI_ARRAY:
  329. > fprintf(stderr, "DT_FINI_ARRAY");
  330. > break;
  331. > case DT_INIT_ARRAYSZ:
  332. > fprintf(stderr, "DT_INIT_ARRAYSZ");
  333. > break;
  334. > case DT_FINI_ARRAYSZ:
  335. > fprintf(stderr, "DT_FINI_ARRAYSZ");
  336. > break;
  337. > case DT_RUNPATH:
  338. > fprintf(stderr, "DT_RUNPATH");
  339. > break;
  340. > case DT_FLAGS:
  341. > fprintf(stderr, "DT_FLAGS");
  342. > break;
  343. > case DT_ENCODING:
  344. > fprintf(stderr, "DT_ENCODING (or DT_PREINIT_ARRAY)");
  345. > break;
  346. > case DT_PREINIT_ARRAYSZ:
  347. > fprintf(stderr, "DT_PREINIT_ARRAYSZ");
  348. > break;
  349. > case DT_NUM:
  350. > fprintf(stderr, "DT_NUM");
  351. > break;
  352. > case DT_LOOS:
  353. > fprintf(stderr, "DT_LOOS");
  354. > break;
  355. > case DT_HIOS:
  356. > fprintf(stderr, "DT_HIOS");
  357. > break;
  358. > case DT_LOPROC:
  359. > fprintf(stderr, "DT_LOPROC");
  360. > break;
  361. > case DT_HIPROC:
  362. > fprintf(stderr, "DT_HIPROC (or DT_FILTER)");
  363. > break;
  364. > case DT_PROCNUM:
  365. > fprintf(stderr, "DT_PROCNUM");
  366. > break;
  367. > case DT_VERSYM:
  368. > fprintf(stderr, "DT_VERSYM");
  369. > break;
  370. > case DT_RELACOUNT:
  371. > fprintf(stderr, "DT_RELACOUNT");
  372. > break;
  373. > case DT_RELCOUNT:
  374. > fprintf(stderr, "DT_RELCOUNT");
  375. > break;
  376. > case DT_FLAGS_1:
  377. > fprintf(stderr, "DT_FLAGS_1");
  378. > break;
  379. > case DT_VERDEF:
  380. > fprintf(stderr, "DT_VERDEF");
  381. > break;
  382. > case DT_VERDEFNUM:
  383. > fprintf(stderr, "DT_VERDEFNUM");
  384. > break;
  385. > case DT_VERNEED:
  386. > fprintf(stderr, "DT_VERNEED");
  387. > break;
  388. > case DT_VERNEEDNUM:
  389. > fprintf(stderr, "DT_VERNEEDNUM");
  390. > break;
  391. > case DT_AUXILIARY:
  392. > fprintf(stderr, "DT_AUXILIARY");
  393. > break;
  394. > default:
  395. > fprintf(stderr, "%d", dynamic->d_tag);
  396. > break;
  397. > }
  398. > fprintf(stderr, " == ");
  399. > switch (field) {
  400. > case DT_NULL:
  401. > fprintf(stderr, "DT_NULL");
  402. > break;
  403. > case DT_NEEDED:
  404. > fprintf(stderr, "DT_NEEDED");
  405. > break;
  406. > case DT_PLTRELSZ:
  407. > fprintf(stderr, "DT_PLTRELSZ");
  408. > break;
  409. > case DT_PLTGOT:
  410. > fprintf(stderr, "DT_PLTGOT");
  411. > break;
  412. > case DT_HASH:
  413. > fprintf(stderr, "DT_HASH");
  414. > break;
  415. > case DT_STRTAB:
  416. > fprintf(stderr, "DT_STRTAB");
  417. > break;
  418. > case DT_SYMTAB:
  419. > fprintf(stderr, "DT_SYMTAB");
  420. > break;
  421. > case DT_RELA:
  422. > fprintf(stderr, "DT_RELA");
  423. > break;
  424. > case DT_RELASZ:
  425. > fprintf(stderr, "DT_RELASZ");
  426. > break;
  427. > case DT_RELAENT:
  428. > fprintf(stderr, "DT_RELAENT");
  429. > break;
  430. > case DT_STRSZ:
  431. > fprintf(stderr, "DT_STRSZ");
  432. > break;
  433. > case DT_SYMENT:
  434. > fprintf(stderr, "DT_SYMENT");
  435. > break;
  436. > case DT_INIT:
  437. > fprintf(stderr, "DT_INIT");
  438. > break;
  439. > case DT_FINI:
  440. > fprintf(stderr, "DT_FINI");
  441. > break;
  442. > case DT_SONAME:
  443. > fprintf(stderr, "DT_SONAME");
  444. > break;
  445. > case DT_RPATH:
  446. > fprintf(stderr, "DT_RPATH");
  447. > break;
  448. > case DT_SYMBOLIC:
  449. > fprintf(stderr, "DT_SYMBOLIC");
  450. > break;
  451. > case DT_REL:
  452. > fprintf(stderr, "DT_REL");
  453. > break;
  454. > case DT_RELSZ:
  455. > fprintf(stderr, "DT_RELSZ");
  456. > break;
  457. > case DT_RELENT:
  458. > fprintf(stderr, "DT_RELENT");
  459. > break;
  460. > case DT_PLTREL:
  461. > fprintf(stderr, "DT_PLTREL");
  462. > break;
  463. > case DT_DEBUG:
  464. > fprintf(stderr, "DT_DEBUG");
  465. > break;
  466. > case DT_TEXTREL:
  467. > fprintf(stderr, "DT_TEXTREL");
  468. > break;
  469. > case DT_JMPREL:
  470. > fprintf(stderr, "DT_JMPREL");
  471. > break;
  472. > case DT_BIND_NOW:
  473. > fprintf(stderr, "DT_BIND_NOW");
  474. > break;
  475. > case DT_INIT_ARRAY:
  476. > fprintf(stderr, "DT_INIT_ARRAY");
  477. > break;
  478. > case DT_FINI_ARRAY:
  479. > fprintf(stderr, "DT_FINI_ARRAY");
  480. > break;
  481. > case DT_INIT_ARRAYSZ:
  482. > fprintf(stderr, "DT_INIT_ARRAYSZ");
  483. > break;
  484. > case DT_FINI_ARRAYSZ:
  485. > fprintf(stderr, "DT_FINI_ARRAYSZ");
  486. > break;
  487. > case DT_RUNPATH:
  488. > fprintf(stderr, "DT_RUNPATH");
  489. > break;
  490. > case DT_FLAGS:
  491. > fprintf(stderr, "DT_FLAGS");
  492. > break;
  493. > case DT_ENCODING:
  494. > fprintf(stderr, "DT_ENCODING (or DT_PREINIT_ARRAY)");
  495. > break;
  496. > case DT_PREINIT_ARRAYSZ:
  497. > fprintf(stderr, "DT_PREINIT_ARRAYSZ");
  498. > break;
  499. > case DT_NUM:
  500. > fprintf(stderr, "DT_NUM");
  501. > break;
  502. > case DT_LOOS:
  503. > fprintf(stderr, "DT_LOOS");
  504. > break;
  505. > case DT_HIOS:
  506. > fprintf(stderr, "DT_HIOS");
  507. > break;
  508. > case DT_LOPROC:
  509. > fprintf(stderr, "DT_LOPROC");
  510. > break;
  511. > case DT_HIPROC:
  512. > fprintf(stderr, "DT_HIPROC (or DT_FILTER)");
  513. > break;
  514. > case DT_PROCNUM:
  515. > fprintf(stderr, "DT_PROCNUM");
  516. > break;
  517. > case DT_VERSYM:
  518. > fprintf(stderr, "DT_VERSYM");
  519. > break;
  520. > case DT_RELACOUNT:
  521. > fprintf(stderr, "DT_RELACOUNT");
  522. > break;
  523. > case DT_RELCOUNT:
  524. > fprintf(stderr, "DT_RELCOUNT");
  525. > break;
  526. > case DT_FLAGS_1:
  527. > fprintf(stderr, "DT_FLAGS_1");
  528. > break;
  529. > case DT_VERDEF:
  530. > fprintf(stderr, "DT_VERDEF");
  531. > break;
  532. > case DT_VERDEFNUM:
  533. > fprintf(stderr, "DT_VERDEFNUM");
  534. > break;
  535. > case DT_VERNEED:
  536. > fprintf(stderr, "DT_VERNEED");
  537. > break;
  538. > case DT_VERNEEDNUM:
  539. > fprintf(stderr, "DT_VERNEEDNUM");
  540. > break;
  541. > case DT_AUXILIARY:
  542. > fprintf(stderr, "DT_AUXILIARY");
  543. > break;
  544. > default:
  545. > fprintf(stderr, "%d (unknown)", field);
  546. > break;
  547. > }
  548. > fprintf(stderr, "\n");
  549. > if (dynamic->d_tag == field) return dynamic;
  550. > }
  551. > TRACE_LD("returning 0");
  552. > return &DYN_EMPTY;
  553. > }
  554. >
  555. >
  556. 279a810
  557. > int PT_LOADS_CURRENT = 0;
  558. 289a821,829
  559. > PT_LOADS_CURRENT = PT_LOADS_CURRENT + 1;
  560. > TRACE_LD("mapping PT_LOAD number %d", PT_LOADS_CURRENT);
  561. > TRACE_LD("\t\tp_flags: %014p", phdr.p_flags);
  562. > TRACE_LD("\t\tp_offset: %014p", phdr.p_offset);
  563. > TRACE_LD("\t\tp_vaddr: %014p", phdr.p_vaddr);
  564. > TRACE_LD("\t\tp_paddr: %014p", phdr.p_paddr);
  565. > TRACE_LD("\t\tp_filesz: %014p", phdr.p_filesz);
  566. > TRACE_LD("\t\tp_memsz: %014p", phdr.p_memsz);
  567. > TRACE_LD("\t\tp_align: %014p", phdr.p_align);
  568. 292,293c832,846
  569. < sysfunc(TOARU_SYS_FUNC_MMAP, args);
  570. <
  571. ---
  572. > // sysfunc(TOARU_SYS_FUNC_MMAP, args);
  573. >
  574. > // [22:33] <klange> for args={addr,size}, that requests memory be allocated at virtual address `addr` for `size` bytes
  575. > #include <errno.h>
  576. > Elf32_Addr vaddr = round_down(phdr.p_vaddr, getpagesize());
  577. > char * mem = (char*)(base + vaddr);
  578. > void * m = mmap(mem, phdr.p_memsz, PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
  579. > if (m == MAP_FAILED) {
  580. > int err = errno;
  581. > TRACE_LD("map failed with %d and errno %d: %s", m, err, strerror(err));
  582. > TRACE_LD("aborting");
  583. > abort();
  584. > } else {
  585. > TRACE_LD("map succeded with address: 0x%014x", m);
  586. > }
  587. 294a848
  588. > TRACE_LD("seeking");
  589. 296c850,852
  590. < fread((void *)(base + phdr.p_vaddr), phdr.p_filesz, 1, object->file);
  591. ---
  592. > TRACE_LD("reading");
  593. > fread(mem, 305, 1, object->file);
  594. > TRACE_LD("zeroing");
  595. 301c857
  596. < *(char *)(phdr.p_vaddr + base + r) = 0;
  597. ---
  598. > *(char *)(vaddr + base + r) = 0;
  599. 306,307c862,863
  600. < if (end_addr < phdr.p_vaddr + base + phdr.p_memsz) {
  601. < end_addr = phdr.p_vaddr + base + phdr.p_memsz;
  602. ---
  603. > if (end_addr < vaddr + base + phdr.p_memsz) {
  604. > end_addr = vaddr + base + phdr.p_memsz;
  605. 314c870,872
  606. < object->dynamic = (Elf32_Dyn *)(base + phdr.p_vaddr);
  607. ---
  608. > object->dynamic = (Elf32_Dyn *)(base + round_down(phdr.p_vaddr, getpagesize()));
  609. > TRACE_LD("obtaining list of dynamic entries");
  610. > get_dynamic_entry(object->dynamic, -1);
  611. 323c881
  612. <
  613. ---
  614. > fpp(TRACE_LD, object->base, PRINTF_END_WITHOUT_NEW_LINE)
  615. 339d896
  616. <
  617. 340a898
  618. > fpp(TRACE_LD, object->dynamic, PRINTF_END_WITHOUT_NEW_LINE)
  619. 345a904
  620. > fpi(TRACE_LD, table->d_tag, PRINTF_END_WITHOUT_NEW_LINE)
  621. 346a906
  622. > fpi(TRACE_LD, table->d_tag, PRINTF_END_WITHOUT_NEW_LINE)
  623. 380a941,943
  624. > fpi(TRACE_LD, table->d_tag, PRINTF_END_WITHOUT_NEW_LINE)
  625. > TRACE_LD("obtaining list of dynamic entries");
  626. > get_dynamic_entry(object->dynamic, -1);
  627. 383a947
  628. > TRACE_LD("adding dependancy %s", object->dyn_string_table + table->d_un.d_val);
  629. 384a949
  630. > abort();
  631. 507a1073
  632. > fpp(TRACE_LD, object->base, PRINTF_END_WITHOUT_NEW_LINE)
  633. 508a1075
  634. > fpp(TRACE_LD, table, PRINTF_END_WITHOUT_NEW_LINE)
  635. 720c1287
  636. < uintptr_t end_addr = object_load(main_obj, 0x0);
  637. ---
  638. > uintptr_t end_addr = object_load(main_obj, 0x40000000);
  639. 735a1303
  640. > fpp(TRACE_LD, main_obj->dependencies, PRINTF_END_WITHOUT_NEW_LINE)
  641. 736a1305
  642. > fpp(TRACE_LD, item, PRINTF_END_WITHOUT_NEW_LINE)
  643. 741a1311
  644. > TRACE_LD("Loading dependency %s", lib_name);
  645. 821c1391,1392
  646. < sysfunc(TOARU_SYS_FUNC_SETHEAP, args);
  647. ---
  648. > // sysfunc(TOARU_SYS_FUNC_SETHEAP, args);
  649. > sbrk(end_addr);
  650. 832c1403
  651. < entry(argc-arg_offset,argv+arg_offset,environ);
  652. ---
  653. > entry(argc-arg_offset,argv+arg_offset,__environ);
  654.