ELFDynamicObject.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. #include <AK/StringBuilder.h>
  2. #include <LibELF/ELFDynamicObject.h>
  3. #include <assert.h>
  4. #include <mman.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #define DYNAMIC_LOAD_DEBUG
  8. //#define DYNAMIC_LOAD_VERBOSE
  9. #ifdef DYNAMIC_LOAD_VERBOSE
  10. # define VERBOSE(fmt, ...) dbgprintf(fmt, ##__VA_ARGS__)
  11. #else
  12. # define VERBOSE(fmt, ...) \
  13. do { \
  14. } while (0)
  15. #endif
  16. static bool s_always_bind_now = false;
  17. static const char* name_for_dtag(Elf32_Sword tag);
  18. // SYSV ELF hash algorithm
  19. // Note that the GNU HASH algorithm has less collisions
  20. static uint32_t calculate_elf_hash(const char* name)
  21. {
  22. uint32_t hash = 0;
  23. uint32_t top_nibble_of_hash = 0;
  24. while (*name != '\0') {
  25. hash = hash << 4;
  26. hash += *name;
  27. name++;
  28. top_nibble_of_hash = hash & 0xF0000000U;
  29. if (top_nibble_of_hash != 0)
  30. hash ^= top_nibble_of_hash >> 24;
  31. hash &= ~top_nibble_of_hash;
  32. }
  33. return hash;
  34. }
  35. NonnullRefPtr<ELFDynamicObject> ELFDynamicObject::construct(const char* filename, int fd, size_t size)
  36. {
  37. return adopt(*new ELFDynamicObject(filename, fd, size));
  38. }
  39. ELFDynamicObject::ELFDynamicObject(const char* filename, int fd, size_t size)
  40. : m_filename(filename)
  41. , m_file_size(size)
  42. , m_image_fd(fd)
  43. {
  44. String file_mmap_name = String::format("ELF_DYN: %s", m_filename.characters());
  45. m_file_mapping = mmap_with_name(nullptr, size, PROT_READ, MAP_PRIVATE, m_image_fd, 0, file_mmap_name.characters());
  46. if (MAP_FAILED == m_file_mapping) {
  47. m_valid = false;
  48. return;
  49. }
  50. m_image = AK::make<ELFImage>((u8*)m_file_mapping);
  51. m_valid = m_image->is_valid() && m_image->parse() && m_image->is_dynamic();
  52. if (!m_valid) {
  53. return;
  54. }
  55. const ELFImage::DynamicSection probably_dynamic_section = m_image->dynamic_section();
  56. if (StringView(".dynamic") != probably_dynamic_section.name() || probably_dynamic_section.type() != SHT_DYNAMIC) {
  57. m_valid = false;
  58. return;
  59. }
  60. }
  61. ELFDynamicObject::~ELFDynamicObject()
  62. {
  63. if (MAP_FAILED != m_file_mapping)
  64. munmap(m_file_mapping, m_file_size);
  65. }
  66. void* ELFDynamicObject::symbol_for_name(const char* name)
  67. {
  68. // FIXME: If we enable gnu hash in the compiler, we should use that here instead
  69. // The algo is way better with less collisions
  70. uint32_t hash_value = calculate_elf_hash(name);
  71. u8* load_addr = m_text_region->load_address().as_ptr();
  72. // NOTE: We need to use the loaded hash/string/symbol tables here to get the right
  73. // addresses. The ones that are in the ELFImage won't cut it, they aren't relocated
  74. u32* hash_table_begin = (u32*)(load_addr + m_hash_table_offset);
  75. Elf32_Sym* symtab = (Elf32_Sym*)(load_addr + m_symbol_table_offset);
  76. const char* strtab = (const char*)load_addr + m_string_table_offset;
  77. size_t num_buckets = hash_table_begin[0];
  78. // This is here for completeness, but, since we're using the fact that every chain
  79. // will end at chain 0 (which means 'not found'), we don't need to check num_chains.
  80. // Interestingly, num_chains is required to be num_symbols
  81. //size_t num_chains = hash_table_begin[1];
  82. u32* buckets = &hash_table_begin[2];
  83. u32* chains = &buckets[num_buckets];
  84. for (u32 i = buckets[hash_value % num_buckets]; i; i = chains[i]) {
  85. if (strcmp(name, strtab + symtab[i].st_name) == 0) {
  86. void* symbol_address = load_addr + symtab[i].st_value;
  87. #ifdef DYNAMIC_LOAD_DEBUG
  88. dbgprintf("Returning dynamic symbol with index %d for %s: %p\n", i, strtab + symtab[i].st_name, symbol_address);
  89. #endif
  90. return symbol_address;
  91. }
  92. }
  93. return nullptr;
  94. }
  95. void ELFDynamicObject::dump()
  96. {
  97. auto dynamic_section = m_image->dynamic_section();
  98. StringBuilder builder;
  99. builder.append("\nd_tag tag_name value\n");
  100. size_t num_dynamic_sections = 0;
  101. dynamic_section.for_each_dynamic_entry([&](const ELFImage::DynamicSectionEntry& entry) {
  102. String name_field = String::format("(%s)", name_for_dtag(entry.tag()));
  103. builder.appendf("0x%08X %-17s0x%X\n", entry.tag(), name_field.characters(), entry.val());
  104. num_dynamic_sections++;
  105. return IterationDecision::Continue;
  106. });
  107. dbgprintf("Dynamic section at offset 0x%x contains %zu entries:\n", dynamic_section.offset(), num_dynamic_sections);
  108. dbgprintf(builder.to_string().characters());
  109. }
  110. void ELFDynamicObject::parse_dynamic_section()
  111. {
  112. auto dynamic_section = m_image->dynamic_section();
  113. dynamic_section.for_each_dynamic_entry([&](const ELFImage::DynamicSectionEntry& entry) {
  114. switch (entry.tag()) {
  115. case DT_INIT:
  116. m_init_offset = entry.ptr();
  117. break;
  118. case DT_FINI:
  119. m_fini_offset = entry.ptr();
  120. break;
  121. case DT_INIT_ARRAY:
  122. m_init_array_offset = entry.ptr();
  123. break;
  124. case DT_INIT_ARRAYSZ:
  125. m_init_array_size = entry.val();
  126. break;
  127. case DT_HASH:
  128. m_hash_table_offset = entry.ptr();
  129. break;
  130. case DT_SYMTAB:
  131. m_symbol_table_offset = entry.ptr();
  132. break;
  133. case DT_STRTAB:
  134. m_string_table_offset = entry.ptr();
  135. break;
  136. case DT_STRSZ:
  137. m_size_of_string_table = entry.val();
  138. break;
  139. case DT_SYMENT:
  140. m_size_of_symbol_table_entry = entry.val();
  141. break;
  142. case DT_PLTGOT:
  143. m_procedure_linkage_table_offset = entry.ptr();
  144. break;
  145. case DT_PLTRELSZ:
  146. m_size_of_plt_relocation_entry_list = entry.val();
  147. break;
  148. case DT_PLTREL:
  149. m_procedure_linkage_table_relocation_type = entry.val();
  150. ASSERT(m_procedure_linkage_table_relocation_type & (DT_REL | DT_RELA));
  151. break;
  152. case DT_JMPREL:
  153. m_plt_relocation_offset_location = entry.ptr();
  154. break;
  155. case DT_RELA:
  156. case DT_REL:
  157. m_relocation_table_offset = entry.ptr();
  158. break;
  159. case DT_RELASZ:
  160. case DT_RELSZ:
  161. m_size_of_relocation_table = entry.val();
  162. break;
  163. case DT_RELAENT:
  164. case DT_RELENT:
  165. m_size_of_relocation_entry = entry.val();
  166. break;
  167. case DT_RELACOUNT:
  168. case DT_RELCOUNT:
  169. m_number_of_relocations = entry.val();
  170. break;
  171. case DT_FLAGS:
  172. m_must_bind_now = entry.val() & DF_BIND_NOW;
  173. m_has_text_relocations = entry.val() & DF_TEXTREL;
  174. m_should_process_origin = entry.val() & DF_ORIGIN;
  175. m_has_static_thread_local_storage = entry.val() & DF_STATIC_TLS;
  176. m_requires_symbolic_symbol_resolution = entry.val() & DF_SYMBOLIC;
  177. break;
  178. case DT_TEXTREL:
  179. m_has_text_relocations = true; // This tag seems to exist for legacy reasons only?
  180. break;
  181. default:
  182. dbgprintf("ELFDynamicObject: DYNAMIC tag handling not implemented for DT_%s\n", name_for_dtag(entry.tag()));
  183. printf("ELFDynamicObject: DYNAMIC tag handling not implemented for DT_%s\n", name_for_dtag(entry.tag()));
  184. ASSERT_NOT_REACHED(); // FIXME: Maybe just break out here and return false?
  185. break;
  186. }
  187. return IterationDecision::Continue;
  188. });
  189. }
  190. typedef void (*InitFunc)();
  191. bool ELFDynamicObject::load(unsigned flags)
  192. {
  193. ASSERT(flags & RTLD_GLOBAL);
  194. ASSERT(flags & RTLD_LAZY);
  195. #ifdef DYNAMIC_LOAD_DEBUG
  196. dump();
  197. #endif
  198. #ifdef DYNAMIC_LOAD_VERBOSE
  199. m_image->dump();
  200. #endif
  201. parse_dynamic_section();
  202. load_program_headers();
  203. if (m_has_text_relocations) {
  204. if (0 > mprotect(m_text_region->load_address().as_ptr(), m_text_region->required_load_size(), PROT_READ | PROT_WRITE)) {
  205. perror("mprotect"); // FIXME: dlerror?
  206. return false;
  207. }
  208. }
  209. do_relocations();
  210. setup_plt_trampoline();
  211. // Clean up our setting of .text to PROT_READ | PROT_WRITE
  212. if (m_has_text_relocations) {
  213. if (0 > mprotect(m_text_region->load_address().as_ptr(), m_text_region->required_load_size(), PROT_READ | PROT_EXEC)) {
  214. perror("mprotect"); // FIXME: dlerror?
  215. return false;
  216. }
  217. }
  218. call_object_init_functions();
  219. #ifdef DYNAMIC_LOAD_DEBUG
  220. dbgprintf("Loaded %s\n", m_filename.characters());
  221. #endif
  222. // FIXME: return false sometimes? missing symbol etc
  223. return true;
  224. }
  225. void ELFDynamicObject::load_program_headers()
  226. {
  227. size_t total_required_allocation_size = 0;
  228. // FIXME: Can we re-use ELFLoader? This and what follows looks a lot like what's in there...
  229. // With the exception of using desired_load_address().offset(text_segment_begin)
  230. // It seems kinda gross to expect the program headers to be in a specific order..
  231. m_image->for_each_program_header([&](const ELFImage::ProgramHeader& program_header) {
  232. ProgramHeaderRegion new_region(program_header.raw_header());
  233. if (new_region.is_load())
  234. total_required_allocation_size += new_region.required_load_size();
  235. m_program_header_regions.append(move(new_region));
  236. auto& region = m_program_header_regions.last();
  237. if (region.is_tls_template())
  238. m_tls_region = &region;
  239. else if (region.is_load()) {
  240. if (region.is_executable())
  241. m_text_region = &region;
  242. else
  243. m_data_region = &region;
  244. }
  245. });
  246. ASSERT(m_text_region && m_data_region);
  247. // Process regions in order: .text, .data, .tls
  248. auto* region = m_text_region;
  249. void* text_segment_begin = mmap_with_name(nullptr, region->required_load_size(), region->mmap_prot(), MAP_PRIVATE, m_image_fd, region->offset(), String::format(".text: %s", m_filename.characters()).characters());
  250. size_t text_segment_size = region->required_load_size();
  251. region->set_base_address(VirtualAddress { (u32)text_segment_begin });
  252. region->set_load_address(VirtualAddress { (u32)text_segment_begin });
  253. region = m_data_region;
  254. void* data_segment_begin = mmap_with_name((u8*)text_segment_begin + text_segment_size, region->required_load_size(), region->mmap_prot(), MAP_ANONYMOUS | MAP_PRIVATE, 0, 0, String::format(".data: %s", m_filename.characters()).characters());
  255. size_t data_segment_size = region->required_load_size();
  256. VirtualAddress data_segment_actual_addr = region->desired_load_address().offset((u32)text_segment_begin);
  257. region->set_base_address(VirtualAddress { (u32)text_segment_begin });
  258. region->set_load_address(data_segment_actual_addr);
  259. memcpy(data_segment_actual_addr.as_ptr(), (u8*)m_file_mapping + region->offset(), region->size_in_image());
  260. if (m_tls_region) {
  261. region = m_data_region;
  262. VirtualAddress tls_segment_actual_addr = region->desired_load_address().offset((u32)text_segment_begin);
  263. region->set_base_address(VirtualAddress { (u32)text_segment_begin });
  264. region->set_load_address(tls_segment_actual_addr);
  265. memcpy(tls_segment_actual_addr.as_ptr(), (u8*)m_file_mapping + region->offset(), region->size_in_image());
  266. }
  267. // sanity check
  268. u8* end_of_in_memory_image = (u8*)data_segment_begin + data_segment_size;
  269. ASSERT((ptrdiff_t)total_required_allocation_size == (ptrdiff_t)(end_of_in_memory_image - (u8*)text_segment_begin));
  270. }
  271. void ELFDynamicObject::do_relocations()
  272. {
  273. auto dyn_relocation_section = m_image->dynamic_relocation_section();
  274. if (StringView(".rel.dyn") != dyn_relocation_section.name() || SHT_REL != dyn_relocation_section.type()) {
  275. ASSERT_NOT_REACHED();
  276. }
  277. u8* load_base_address = m_text_region->base_address().as_ptr();
  278. int i = -1;
  279. // FIXME: We should really bail on undefined symbols here. (but, there's some TLS vars that are currently undef soooo.... :) )
  280. dyn_relocation_section.for_each_relocation([&](const ELFImage::DynamicRelocation& relocation) {
  281. ++i;
  282. VERBOSE("====== RELOCATION %d: offset 0x%08X, type %d, symidx %08X\n", i, relocation.offset(), relocation.type(), relocation.symbol_index());
  283. u32* patch_ptr = (u32*)(load_base_address + relocation.offset());
  284. switch (relocation.type()) {
  285. case R_386_NONE:
  286. // Apparently most loaders will just skip these?
  287. // Seems if the 'link editor' generates one something is funky with your code
  288. VERBOSE("None relocation. No symbol, no nothin.\n");
  289. break;
  290. case R_386_32: {
  291. auto symbol = relocation.symbol();
  292. VERBOSE("Absolute relocation: name: '%s', value: %p\n", symbol.name(), symbol.value());
  293. if (symbol.bind() == STB_LOCAL) {
  294. u32 symbol_address = symbol.section().address() + symbol.value();
  295. *patch_ptr += symbol_address;
  296. } else if (symbol.bind() == STB_GLOBAL) {
  297. u32 symbol_address = symbol.value() + (u32)load_base_address;
  298. *patch_ptr += symbol_address;
  299. } else if (symbol.bind() == STB_WEAK) {
  300. // FIXME: Handle weak symbols...
  301. dbgprintf("ELFDynamicObject: Ignoring weak symbol %s\n", symbol.name());
  302. } else {
  303. VERBOSE("Found new fun symbol bind value %d\n", symbol.bind());
  304. ASSERT_NOT_REACHED();
  305. }
  306. VERBOSE(" Symbol address: %p\n", *patch_ptr);
  307. break;
  308. }
  309. case R_386_PC32: {
  310. auto symbol = relocation.symbol();
  311. VERBOSE("PC-relative relocation: '%s', value: %p\n", symbol.name(), symbol.value());
  312. u32 relative_offset = (symbol.value() - relocation.offset());
  313. *patch_ptr += relative_offset;
  314. VERBOSE(" Symbol address: %p\n", *patch_ptr);
  315. break;
  316. }
  317. case R_386_GLOB_DAT: {
  318. auto symbol = relocation.symbol();
  319. VERBOSE("Global data relocation: '%s', value: %p\n", symbol.name(), symbol.value());
  320. u32 symbol_location = (u32)(m_data_region->base_address().as_ptr() + symbol.value());
  321. *patch_ptr = symbol_location;
  322. VERBOSE(" Symbol address: %p\n", *patch_ptr);
  323. break;
  324. }
  325. case R_386_RELATIVE: {
  326. // FIXME: According to the spec, R_386_relative ones must be done first.
  327. // We could explicitly do them first using m_number_of_relocatoins from DT_RELCOUNT
  328. // However, our compiler is nice enough to put them at the front of the relocations for us :)
  329. VERBOSE("Load address relocation at offset %X\n", relocation.offset());
  330. VERBOSE(" patch ptr == %p, adding load base address (%p) to it and storing %p\n", *patch_ptr, load_base_address, *patch_ptr + (u32)load_base_address);
  331. *patch_ptr += (u32)load_base_address; // + addend for RelA (addend for Rel is stored at addr)
  332. break;
  333. }
  334. case R_386_TLS_TPOFF: {
  335. VERBOSE("Relocation type: R_386_TLS_TPOFF at offset %X\n", relocation.offset());
  336. // FIXME: this can't be right? I have no idea what "negative offset into TLS storage" means...
  337. // FIXME: Check m_has_static_tls and do something different for dynamic TLS
  338. VirtualAddress tls_region_loctation = m_tls_region->desired_load_address();
  339. *patch_ptr = relocation.offset() - (u32)tls_region_loctation.as_ptr() - *patch_ptr;
  340. break;
  341. }
  342. default:
  343. // Raise the alarm! Someone needs to implement this relocation type
  344. dbgprintf("Found a new exciting relocation type %d\n", relocation.type());
  345. printf("ELFDynamicObject: Found unknown relocation type %d\n", relocation.type());
  346. ASSERT_NOT_REACHED();
  347. break;
  348. }
  349. return IterationDecision::Continue;
  350. });
  351. // Handle PLT Global offset table relocations.
  352. for (size_t idx = 0; idx < m_size_of_plt_relocation_entry_list; idx += m_size_of_relocation_entry) {
  353. // FIXME: Or BIND_NOW flag passed in?
  354. if (m_must_bind_now || s_always_bind_now) {
  355. // Eagerly BIND_NOW the PLT entries, doing all the symbol looking goodness
  356. // The patch method returns the address for the LAZY fixup path, but we don't need it here
  357. (void)patch_plt_entry(idx);
  358. } else {
  359. // LAZY-ily bind the PLT slots by just adding the base address to the offsets stored there
  360. // This avoids doing symbol lookup, which might be expensive
  361. VirtualAddress relocation_vaddr = m_text_region->load_address().offset(m_plt_relocation_offset_location).offset(idx);
  362. Elf32_Rel* jump_slot_relocation = (Elf32_Rel*)relocation_vaddr.as_ptr();
  363. ASSERT(ELF32_R_TYPE(jump_slot_relocation->r_info) == R_386_JMP_SLOT);
  364. auto* image_base_address = m_text_region->base_address().as_ptr();
  365. u8* relocation_address = image_base_address + jump_slot_relocation->r_offset;
  366. *(u32*)relocation_address += (u32)image_base_address;
  367. }
  368. }
  369. #ifdef DYNAMIC_LOAD_DEBUG
  370. dbgprintf("Done relocating!\n");
  371. #endif
  372. }
  373. // Defined in <arch>/plt_trampoline.S
  374. extern "C" void _plt_trampoline(void) __attribute__((visibility("hidden")));
  375. void ELFDynamicObject::setup_plt_trampoline()
  376. {
  377. const ELFImage::Section& got_section = m_image->lookup_section(".got.plt");
  378. VirtualAddress got_address = m_text_region->load_address().offset(got_section.address());
  379. u32* got_u32_ptr = reinterpret_cast<u32*>(got_address.as_ptr());
  380. got_u32_ptr[1] = (u32)this;
  381. got_u32_ptr[2] = (u32)&_plt_trampoline;
  382. #ifdef DYNAMIC_LOAD_DEBUG
  383. dbgprintf("Set GOT PLT entries at %p offset(%p): [0] = %p [1] = %p, [2] = %p\n", got_u32_ptr, got_section.offset(), got_u32_ptr[0], got_u32_ptr[1], got_u32_ptr[2]);
  384. #endif
  385. }
  386. // Called from our ASM routine _plt_trampoline
  387. extern "C" Elf32_Addr _fixup_plt_entry(ELFDynamicObject* object, u32 relocation_idx)
  388. {
  389. return object->patch_plt_entry(relocation_idx);
  390. }
  391. // offset is in PLT relocation table
  392. Elf32_Addr ELFDynamicObject::patch_plt_entry(u32 relocation_idx)
  393. {
  394. VirtualAddress plt_relocation_table_address = m_text_region->load_address().offset(m_plt_relocation_offset_location);
  395. VirtualAddress relocation_entry_address = plt_relocation_table_address.offset(relocation_idx);
  396. Elf32_Rel* jump_slot_relocation = (Elf32_Rel*)relocation_entry_address.as_ptr();
  397. ASSERT(ELF32_R_TYPE(jump_slot_relocation->r_info) == R_386_JMP_SLOT);
  398. auto sym = m_image->dynamic_symbol(ELF32_R_SYM(jump_slot_relocation->r_info));
  399. auto* image_base_address = m_text_region->base_address().as_ptr();
  400. u8* relocation_address = image_base_address + jump_slot_relocation->r_offset;
  401. u32 symbol_location = (u32)(image_base_address + sym.value());
  402. VERBOSE("ELFDynamicObject: Jump slot relocation: putting %s (%p) into PLT at %p\n", sym.name(), symbol_location, relocation_address);
  403. *(u32*)relocation_address = symbol_location;
  404. return symbol_location;
  405. }
  406. void ELFDynamicObject::call_object_init_functions()
  407. {
  408. u8* load_addr = m_text_region->load_address().as_ptr();
  409. InitFunc init_function = (InitFunc)(load_addr + m_init_offset);
  410. #ifdef DYNAMIC_LOAD_DEBUG
  411. dbgprintf("Calling DT_INIT at %p\n", init_function);
  412. #endif
  413. (init_function)();
  414. InitFunc* init_begin = (InitFunc*)(load_addr + m_init_array_offset);
  415. u32 init_end = (u32)((u8*)init_begin + m_init_array_size);
  416. while ((u32)init_begin < init_end) {
  417. // Andriod sources claim that these can be -1, to be ignored.
  418. // 0 definitely shows up. Apparently 0/-1 are valid? Confusing.
  419. if (!*init_begin || ((i32)*init_begin == -1))
  420. continue;
  421. #ifdef DYNAMIC_LOAD_DEBUG
  422. dbgprintf("Calling DT_INITARRAY entry at %p\n", *init_begin);
  423. #endif
  424. (*init_begin)();
  425. ++init_begin;
  426. }
  427. }
  428. u32 ELFDynamicObject::ProgramHeaderRegion::mmap_prot() const
  429. {
  430. int prot = 0;
  431. prot |= is_executable() ? PROT_EXEC : 0;
  432. prot |= is_readable() ? PROT_READ : 0;
  433. prot |= is_writable() ? PROT_WRITE : 0;
  434. return prot;
  435. }
  436. static const char* name_for_dtag(Elf32_Sword d_tag)
  437. {
  438. switch (d_tag) {
  439. case DT_NULL:
  440. return "NULL"; /* marks end of _DYNAMIC array */
  441. case DT_NEEDED:
  442. return "NEEDED"; /* string table offset of needed lib */
  443. case DT_PLTRELSZ:
  444. return "PLTRELSZ"; /* size of relocation entries in PLT */
  445. case DT_PLTGOT:
  446. return "PLTGOT"; /* address PLT/GOT */
  447. case DT_HASH:
  448. return "HASH"; /* address of symbol hash table */
  449. case DT_STRTAB:
  450. return "STRTAB"; /* address of string table */
  451. case DT_SYMTAB:
  452. return "SYMTAB"; /* address of symbol table */
  453. case DT_RELA:
  454. return "RELA"; /* address of relocation table */
  455. case DT_RELASZ:
  456. return "RELASZ"; /* size of relocation table */
  457. case DT_RELAENT:
  458. return "RELAENT"; /* size of relocation entry */
  459. case DT_STRSZ:
  460. return "STRSZ"; /* size of string table */
  461. case DT_SYMENT:
  462. return "SYMENT"; /* size of symbol table entry */
  463. case DT_INIT:
  464. return "INIT"; /* address of initialization func. */
  465. case DT_FINI:
  466. return "FINI"; /* address of termination function */
  467. case DT_SONAME:
  468. return "SONAME"; /* string table offset of shared obj */
  469. case DT_RPATH:
  470. return "RPATH"; /* string table offset of library search path */
  471. case DT_SYMBOLIC:
  472. return "SYMBOLIC"; /* start sym search in shared obj. */
  473. case DT_REL:
  474. return "REL"; /* address of rel. tbl. w addends */
  475. case DT_RELSZ:
  476. return "RELSZ"; /* size of DT_REL relocation table */
  477. case DT_RELENT:
  478. return "RELENT"; /* size of DT_REL relocation entry */
  479. case DT_PLTREL:
  480. return "PLTREL"; /* PLT referenced relocation entry */
  481. case DT_DEBUG:
  482. return "DEBUG"; /* bugger */
  483. case DT_TEXTREL:
  484. return "TEXTREL"; /* Allow rel. mod. to unwritable seg */
  485. case DT_JMPREL:
  486. return "JMPREL"; /* add. of PLT's relocation entries */
  487. case DT_BIND_NOW:
  488. return "BIND_NOW"; /* Bind now regardless of env setting */
  489. case DT_INIT_ARRAY:
  490. return "INIT_ARRAY"; /* address of array of init func */
  491. case DT_FINI_ARRAY:
  492. return "FINI_ARRAY"; /* address of array of term func */
  493. case DT_INIT_ARRAYSZ:
  494. return "INIT_ARRAYSZ"; /* size of array of init func */
  495. case DT_FINI_ARRAYSZ:
  496. return "FINI_ARRAYSZ"; /* size of array of term func */
  497. case DT_RUNPATH:
  498. return "RUNPATH"; /* strtab offset of lib search path */
  499. case DT_FLAGS:
  500. return "FLAGS"; /* Set of DF_* flags */
  501. case DT_ENCODING:
  502. return "ENCODING"; /* further DT_* follow encoding rules */
  503. case DT_PREINIT_ARRAY:
  504. return "PREINIT_ARRAY"; /* address of array of preinit func */
  505. case DT_PREINIT_ARRAYSZ:
  506. return "PREINIT_ARRAYSZ"; /* size of array of preinit func */
  507. case DT_LOOS:
  508. return "LOOS"; /* reserved range for OS */
  509. case DT_HIOS:
  510. return "HIOS"; /* specific dynamic array tags */
  511. case DT_LOPROC:
  512. return "LOPROC"; /* reserved range for processor */
  513. case DT_HIPROC:
  514. return "HIPROC"; /* specific dynamic array tags */
  515. case DT_GNU_HASH:
  516. return "GNU_HASH"; /* address of GNU hash table */
  517. case DT_RELACOUNT:
  518. return "RELACOUNT"; /* if present, number of RELATIVE */
  519. case DT_RELCOUNT:
  520. return "RELCOUNT"; /* relocs, which must come first */
  521. case DT_FLAGS_1:
  522. return "FLAGS_1";
  523. default:
  524. return "??";
  525. }
  526. }