Browse Source

fesvr: format `LOAD_ELF` macro (NFC)

This simply uses clang-format to reflow the text of the macro, which
makes it easier to read and edit.
pull/781/head
Saleem Abdulrasool 5 years ago
parent
commit
fe7a62599b
  1. 93
      fesvr/elfloader.cc

93
fesvr/elfloader.cc

@ -40,49 +40,56 @@ std::map<std::string, uint64_t> load_elf(const char* fn, memif_t* memif, reg_t*
std::vector<uint8_t> zeros; std::vector<uint8_t> zeros;
std::map<std::string, uint64_t> symbols; std::map<std::string, uint64_t> symbols;
#define LOAD_ELF(ehdr_t, phdr_t, shdr_t, sym_t, bswap) do { \ #define LOAD_ELF(ehdr_t, phdr_t, shdr_t, sym_t, bswap) \
ehdr_t* eh = (ehdr_t*)buf; \ do { \
phdr_t* ph = (phdr_t*)(buf + bswap(eh->e_phoff)); \ ehdr_t* eh = (ehdr_t*)buf; \
*entry = bswap(eh->e_entry); \ phdr_t* ph = (phdr_t*)(buf + bswap(eh->e_phoff)); \
assert(size >= bswap(eh->e_phoff) + bswap(eh->e_phnum)*sizeof(*ph)); \ *entry = bswap(eh->e_entry); \
for (unsigned i = 0; i < bswap(eh->e_phnum); i++) { \ assert(size >= bswap(eh->e_phoff) + bswap(eh->e_phnum) * sizeof(*ph)); \
if(bswap(ph[i].p_type) == PT_LOAD && bswap(ph[i].p_memsz)) { \ for (unsigned i = 0; i < bswap(eh->e_phnum); i++) { \
if (bswap(ph[i].p_filesz)) { \ if (bswap(ph[i].p_type) == PT_LOAD && bswap(ph[i].p_memsz)) { \
assert(size >= bswap(ph[i].p_offset) + bswap(ph[i].p_filesz)); \ if (bswap(ph[i].p_filesz)) { \
memif->write(bswap(ph[i].p_paddr), bswap(ph[i].p_filesz), (uint8_t*)buf + bswap(ph[i].p_offset)); \ assert(size >= bswap(ph[i].p_offset) + bswap(ph[i].p_filesz)); \
} \ memif->write(bswap(ph[i].p_paddr), bswap(ph[i].p_filesz), \
zeros.resize(bswap(ph[i].p_memsz) - bswap(ph[i].p_filesz)); \ (uint8_t*)buf + bswap(ph[i].p_offset)); \
memif->write(bswap(ph[i].p_paddr) + bswap(ph[i].p_filesz), bswap(ph[i].p_memsz) - bswap(ph[i].p_filesz), &zeros[0]); \ } \
} \ zeros.resize(bswap(ph[i].p_memsz) - bswap(ph[i].p_filesz)); \
} \ memif->write(bswap(ph[i].p_paddr) + bswap(ph[i].p_filesz), \
shdr_t* sh = (shdr_t*)(buf + bswap(eh->e_shoff)); \ bswap(ph[i].p_memsz) - bswap(ph[i].p_filesz), &zeros[0]); \
assert(size >= bswap(eh->e_shoff) + bswap(eh->e_shnum)*sizeof(*sh)); \ } \
assert(bswap(eh->e_shstrndx) < bswap(eh->e_shnum)); \ } \
assert(size >= bswap(sh[bswap(eh->e_shstrndx)].sh_offset) + bswap(sh[bswap(eh->e_shstrndx)].sh_size)); \ shdr_t* sh = (shdr_t*)(buf + bswap(eh->e_shoff)); \
char *shstrtab = buf + bswap(sh[bswap(eh->e_shstrndx)].sh_offset); \ assert(size >= bswap(eh->e_shoff) + bswap(eh->e_shnum) * sizeof(*sh)); \
unsigned strtabidx = 0, symtabidx = 0; \ assert(bswap(eh->e_shstrndx) < bswap(eh->e_shnum)); \
for (unsigned i = 0; i < bswap(eh->e_shnum); i++) { \ assert(size >= bswap(sh[bswap(eh->e_shstrndx)].sh_offset) + \
unsigned max_len = bswap(sh[bswap(eh->e_shstrndx)].sh_size) - bswap(sh[i].sh_name); \ bswap(sh[bswap(eh->e_shstrndx)].sh_size)); \
assert(bswap(sh[i].sh_name) < bswap(sh[bswap(eh->e_shstrndx)].sh_size)); \ char* shstrtab = buf + bswap(sh[bswap(eh->e_shstrndx)].sh_offset); \
assert(strnlen(shstrtab + bswap(sh[i].sh_name), max_len) < max_len); \ unsigned strtabidx = 0, symtabidx = 0; \
if (bswap(sh[i].sh_type) & SHT_NOBITS) continue; \ for (unsigned i = 0; i < bswap(eh->e_shnum); i++) { \
assert(size >= bswap(sh[i].sh_offset) + bswap(sh[i].sh_size)); \ unsigned max_len = \
if (strcmp(shstrtab + bswap(sh[i].sh_name), ".strtab") == 0) \ bswap(sh[bswap(eh->e_shstrndx)].sh_size) - bswap(sh[i].sh_name); \
strtabidx = i; \ assert(bswap(sh[i].sh_name) < bswap(sh[bswap(eh->e_shstrndx)].sh_size)); \
if (strcmp(shstrtab + bswap(sh[i].sh_name), ".symtab") == 0) \ assert(strnlen(shstrtab + bswap(sh[i].sh_name), max_len) < max_len); \
symtabidx = i; \ if (bswap(sh[i].sh_type) & SHT_NOBITS) continue; \
} \ assert(size >= bswap(sh[i].sh_offset) + bswap(sh[i].sh_size)); \
if (strtabidx && symtabidx) { \ if (strcmp(shstrtab + bswap(sh[i].sh_name), ".strtab") == 0) \
char* strtab = buf + bswap(sh[strtabidx].sh_offset); \ strtabidx = i; \
sym_t* sym = (sym_t*)(buf + bswap(sh[symtabidx].sh_offset)); \ if (strcmp(shstrtab + bswap(sh[i].sh_name), ".symtab") == 0) \
for (unsigned i = 0; i < bswap(sh[symtabidx].sh_size)/sizeof(sym_t); i++) { \ symtabidx = i; \
unsigned max_len = bswap(sh[strtabidx].sh_size) - bswap(sym[i].st_name); \ } \
assert(bswap(sym[i].st_name) < bswap(sh[strtabidx].sh_size)); \ if (strtabidx && symtabidx) { \
assert(strnlen(strtab + bswap(sym[i].st_name), max_len) < max_len); \ char* strtab = buf + bswap(sh[strtabidx].sh_offset); \
symbols[strtab + bswap(sym[i].st_name)] = bswap(sym[i].st_value); \ sym_t* sym = (sym_t*)(buf + bswap(sh[symtabidx].sh_offset)); \
} \ for (unsigned i = 0; i < bswap(sh[symtabidx].sh_size) / sizeof(sym_t); \
} \ i++) { \
} while(0) unsigned max_len = \
bswap(sh[strtabidx].sh_size) - bswap(sym[i].st_name); \
assert(bswap(sym[i].st_name) < bswap(sh[strtabidx].sh_size)); \
assert(strnlen(strtab + bswap(sym[i].st_name), max_len) < max_len); \
symbols[strtab + bswap(sym[i].st_name)] = bswap(sym[i].st_value); \
} \
} \
} while (0)
if (IS_ELFLE(*eh64)) { if (IS_ELFLE(*eh64)) {
memif->set_target_endianness(memif_endianness_little); memif->set_target_endianness(memif_endianness_little);

Loading…
Cancel
Save