Check whether ABI is supported before we execute the binary

- this is fallout of the reorganization of open_program/execute_program.
  I still think it makes better sense this wey, even though we need to
  do the additional checking step now.
diff --git a/libltrace.c b/libltrace.c
index e731fe1..19bfafd 100644
--- a/libltrace.c
+++ b/libltrace.c
@@ -107,6 +107,11 @@
 		}
 	}
 	if (command) {
+		/* Check that the binary ABI is supported before
+		 * calling execute_program.  */
+		struct ltelf lte = {};
+		open_elf(&lte, command);
+
 		open_program(command, execute_program(command, argv), 0);
 	}
 	opt_p_tmp = opt_p;
diff --git a/ltrace-elf.c b/ltrace-elf.c
index cc27e17..f24c2a1 100644
--- a/ltrace-elf.c
+++ b/ltrace-elf.c
@@ -136,18 +136,14 @@
 }
 
 int
-do_init_elf(struct ltelf *lte, const char *filename) {
-	int i;
-	GElf_Addr relplt_addr = 0;
-	size_t relplt_size = 0;
-
-	debug(DEBUG_FUNCTION, "do_init_elf(filename=%s)", filename);
-	debug(1, "Reading ELF from %s...", filename);
-
+open_elf(struct ltelf *lte, const char *filename)
+{
 	lte->fd = open(filename, O_RDONLY);
 	if (lte->fd == -1)
 		return 1;
 
+	elf_version(EV_CURRENT);
+
 #ifdef HAVE_ELF_C_READ_MMAP
 	lte->elf = elf_begin(lte->fd, ELF_C_READ_MMAP, NULL);
 #else
@@ -180,6 +176,21 @@
 		error(EXIT_FAILURE, 0,
 		      "\"%s\" is ELF from incompatible architecture", filename);
 
+	return 0;
+}
+
+int
+do_init_elf(struct ltelf *lte, const char *filename) {
+	int i;
+	GElf_Addr relplt_addr = 0;
+	size_t relplt_size = 0;
+
+	debug(DEBUG_FUNCTION, "do_init_elf(filename=%s)", filename);
+	debug(1, "Reading ELF from %s...", filename);
+
+	if (open_elf(lte, filename) < 0)
+		return -1;
+
 	Elf_Data *plt_data = NULL;
 	GElf_Addr ppcgot = 0;
 
@@ -621,8 +632,6 @@
 	library_num = 0;
 	proc->libdl_hooked = 0;
 
-	elf_version(EV_CURRENT);
-
 	if (do_init_elf(lte, proc->filename))
 		return NULL;
 
diff --git a/ltrace-elf.h b/ltrace-elf.h
index a29fe2c..3b675c5 100644
--- a/ltrace-elf.h
+++ b/ltrace-elf.h
@@ -44,6 +44,7 @@
 extern size_t library_num;
 extern char *library[MAX_LIBRARIES];
 
+extern int open_elf(struct ltelf *lte, const char *filename);
 extern struct library_symbol *read_elf(Process *);
 
 extern GElf_Addr arch_plt_sym_val(struct ltelf *, size_t, GElf_Rela *);