Hi John,
Those assertion tests should work fine on little endian.
e_ident is not even within the portion of the Ehdr struct that differs between ELF32 and ELF64. 1, 2 are the correct values for ELFCLASS32 and ELFCLASS64 and EI_CLASS is 4. it appears from the code that it should work.
#define IS_ELF32(hdr) (IS_ELF(hdr) && (hdr).e_ident[4] == 1)
#define IS_ELF64(hdr) (IS_ELF(hdr) && (hdr).e_ident[4] == 2)
The file is open and the mmap has succeeded otherwise the previous assert would have failed. i.e. stepping though the statements leading up to the failed assertion.
std::map<std::string, uint64_t> load_elf(const char* fn, memif_t* memif)
{
int fd = open(fn, O_RDONLY);
struct stat s;
assert(fd != -1);
if (fstat(fd, &s) < 0)
abort();
size_t size = s.st_size;
char* buf = (char*)mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
assert(buf != MAP_FAILED);
close(fd);
assert(size >= sizeof(Elf64_Ehdr));
const Elf64_Ehdr* eh64 = (const Elf64_Ehdr*)buf;
assert(IS_ELF32(*eh64) || IS_ELF64(*eh64));
I wonder if it is something in hello.c. Can you pastebin the file and I can test locally?
Oh, you passing the .dis file into elf2hex, not the ELF file itself? I just noticed.
Michael.