elf_begin is correctly called gelf_newehdr(elf,gelf_getclass(elf)) might be incorrectly used as elf does not know its own wordsize yet, so it may be returning 64bit always. We might have to manually override the gelf_getclass() call and provide our own wordsize indicator
As suspected, using gelf_getclass() on an empty structure won't work (or magically know what arch size you are on). When creating the Elf Header (and only the Elf Header) with gelf a class has to be specified regarding ELFCLASS32 or ELFCLASS64. We can derive from wordsize which correct value to give to gelf for initial header generation. 2006-10-17 Phil Muldoon <pmuldoon@redhat.com> * Elf.java (createNewEHeader): Require a wordsize. * cni/Elf.cxx (elf_newehdr): Specify wordsize. gelf_getclass() for wordsize won't work on an empty elf struct.