bool target_is_suitable(Target* t)
{
  enum { CMP_SIZE = offsetof(TEVWH_ELF_EHDR, e_entry) };
  TEVWH_ELF_PHDR* self_phdr;
  TEVWH_ELF_PHDR* phdr;
  TEVWH_ELF_EHDR* ehdr;

  TRACE(stderr, "target_is_suitable: SELF=%p\n", SELF);

  self_phdr = (TEVWH_ELF_PHDR*)((char*)SELF + SELF->e_phoff);
  phdr = t->phdr = (TEVWH_ELF_PHDR*)(t->p.b + t->p.ehdr->e_phoff);
  ehdr = t->p.ehdr;

  CHECK_EQ(memcmp(&ehdr->e_ident, &SELF->e_ident, CMP_SIZE), 0);
  CHECK_EQ(ehdr->e_phoff, SELF->e_phoff);
  CHECK_EQ(ehdr->e_ehsize, SELF->e_ehsize);
  CHECK_EQ(ehdr->e_phentsize, SELF->e_phentsize);
  CHECK_EQ(ehdr->e_shentsize, SELF->e_shentsize);

  /* the type of these headers must be PT_LOAD */
  CHECK_EQ(phdr[2].p_type, self_phdr[2].p_type);
  CHECK_EQ(phdr[3].p_type, self_phdr[3].p_type);

  /* a code segment with trailing 0-bytes makes no sense, anyway */
  CHECK_EQ(phdr[2].p_filesz, phdr[2].p_memsz);

  t->end_of_cs = phdr[2].p_offset + phdr[2].p_filesz;
  t->aligned_end_of_cs = ALIGN_UP(t->end_of_cs);

  t->target_entry_code = t->p.b + (t->p.ehdr->e_entry - TEVWH_ELF_BASE);

  return true;
}
