Added new method to ELFObjectFileBase to check whether the ELF image used to construct it is actually an ELF image (i.e. it has ELF magic word).
Details
Diff Detail
Event Timeline
git-clang-format HEAD^ may be useful for reformatting the already changed parts. LGTM, @jhenderson?
Thanks! I was not aware of this code. How about adding something like static inline is_any_elf(file_magic) method in Magic.h? If you agree, then I will abandon this change-set and add the new method in D103545.
I'm assuming this would be to avoid having to write something like if (objectType == elf || objectType == elf_relocatable || /*all the other elf_* types*/ ...) (or an equivalent switch statement)? Is this something you'd use in more than one place within your code?
Exactly! I could add the same helper in the plugin code, but I'd rather keep it close to the file_magic enum definition. Do you suggest adding it in the plugin code?
It is rare that an application can process all of elf_relocatable, elf_executable, and elf_shared_object. llvm-objcopy is such a tool, but most others either only handle elf_relocatable or elf_executable+elf_shared_object.