19 using namespace llvm::ELF;
29 *value = data.
GetMaxU64(offset, byte_size);
30 return *offset != saved_offset;
38 for (
uint32_t i = 0; i < count; ++i, ++value) {
39 if (!
GetMaxU64(data, offset, value, byte_size)) {
40 *offset = saved_offset;
51 *value = data.
GetMaxS64(offset, byte_size);
52 return *offset != saved_offset;
60 for (
uint32_t i = 0; i < count; ++i, ++value) {
61 if (!
GetMaxS64(data, offset, value, byte_size)) {
62 *offset = saved_offset;
74 if (e_ident[EI_DATA] == ELFDATA2MSB)
76 if (e_ident[EI_DATA] == ELFDATA2LSB)
85 result |= e_phnum_hdr == 0xFFFF;
86 result |= e_shnum_hdr == SHN_UNDEF;
87 result |= e_shstrndx_hdr == SHN_XINDEX;
90 result &= e_shoff != 0;
101 bool ok = section_zero.
Parse(sh_data, &offset);
105 if (e_phnum_hdr == 0xFFFF)
106 e_phnum = section_zero.
sh_info;
107 if (e_shnum_hdr == SHN_UNDEF)
108 e_shnum = section_zero.
sh_size;
109 if (e_shstrndx_hdr == SHN_XINDEX)
110 e_shstrndx = section_zero.
sh_link;
117 if (data.
GetU8(offset, &e_ident, EI_NIDENT) ==
nullptr)
120 const unsigned byte_size = Is32Bit() ? 4 : 8;
125 if (data.
GetU16(offset, &e_type, 2) ==
nullptr)
129 if (data.
GetU32(offset, &e_version, 1) ==
nullptr)
133 if (!
GetMaxU64(data, offset, &e_entry, byte_size, 3))
137 if (data.
GetU32(offset, &e_flags, 1) ==
nullptr)
141 if (data.
GetU16(offset, &e_ehsize, 6) ==
nullptr)
146 e_phnum = e_phnum_hdr;
147 e_shnum = e_shnum_hdr;
148 e_shstrndx = e_shstrndx_hdr;
151 if (HasHeaderExtension())
152 ParseHeaderExtension(data);
158 return memcmp(magic, ElfMagic, strlen(ElfMagic)) == 0;
162 unsigned address_size = 0;
164 switch (magic[EI_CLASS]) {
181 assert(
false &&
"architecture not supported");
184 slot = R_PPC_JMP_SLOT;
187 slot = R_PPC64_JMP_SLOT;
191 slot = R_386_JUMP_SLOT;
194 slot = R_X86_64_JUMP_SLOT;
197 slot = R_ARM_JUMP_SLOT;
200 slot = R_HEX_JMP_SLOT;
203 slot = R_AARCH64_JUMP_SLOT;
206 slot = R_MIPS_JUMP_SLOT;
209 slot = R_390_JMP_SLOT;
212 slot = R_RISCV_JUMP_SLOT;
230 if (data.
GetU32(offset, &sh_name, 2) ==
nullptr)
234 if (!
GetMaxU64(data, offset, &sh_flags, byte_size))
238 if (!
GetMaxU64(data, offset, &sh_addr, byte_size, 3))
242 if (data.
GetU32(offset, &sh_link, 2) ==
nullptr)
246 if (!
GetMaxU64(data, offset, &sh_addralign, byte_size, 2))
256 #define ENUM_TO_CSTR(e) \
314 s->
Printf(
"[%3u] 0x%16.16" PRIx64
" 0x%16.16" PRIx64
315 " 0x%8.8x 0x%2.2x (%-10s %-13s) 0x%2.2x 0x%4.4x (%-10s) %s\n",
316 idx, st_value, st_size, st_name, st_info,
317 bindingToCString(getBinding()), typeToCString(getType()), st_other,
318 st_shndx, sectionIndexToCString(st_shndx, section_list),
319 strtab_data ? strtab_data->
PeekCStr(st_name) :
"");
325 const bool parsing_32 = byte_size == 4;
328 if (data.
GetU32(offset, &st_name, 1) ==
nullptr)
333 if (!
GetMaxU64(data, offset, &st_value, byte_size, 2))
337 if (data.
GetU8(offset, &st_info, 2) ==
nullptr)
341 if (data.
GetU16(offset, &st_shndx, 1) ==
nullptr)
345 if (data.
GetU8(offset, &st_info, 2) ==
nullptr)
349 if (data.
GetU16(offset, &st_shndx, 1) ==
nullptr)
353 if (data.
GetU64(offset, &st_value, 2) ==
nullptr)
368 const bool parsing_32 = byte_size == 4;
371 if (data.
GetU32(offset, &p_type, 1) ==
nullptr)
376 if (!
GetMaxU64(data, offset, &p_offset, byte_size, 5))
380 if (data.
GetU32(offset, &p_flags, 1) ==
nullptr)
384 if (!
GetMaxU64(data, offset, &p_align, byte_size))
388 if (data.
GetU32(offset, &p_flags, 1) ==
nullptr)
392 if (!
GetMaxU64(data, offset, &p_offset, byte_size, 6))
406 return GetMaxS64(data, offset, &d_tag, byte_size, 2);
418 return GetMaxU64(data, offset, &r_offset, byte_size, 2) !=
false;
430 if (!
GetMaxU64(data, offset, &r_offset, byte_size, 2))
434 if (!
GetMaxS64(data, offset, &r_addend, byte_size))