+/**
+ * Initialize the ELF file for a given executable.
+ *
+ * @param so so_info instance
+ * @returns 0 on success, -1 on failure
+ */
+static
+int so_info_set_elf_file(struct so_info *so)
+{
+ int elf_fd;
+ Elf *elf_file;
+
+ if (!so) {
+ goto error;
+ }
+
+ elf_fd = open(so->elf_path, O_RDONLY);
+ if (elf_fd < 0) {
+ fprintf(stderr, "Failed to open %s\n", so->elf_path);
+ goto error;
+ }
+
+ elf_file = elf_begin(elf_fd, ELF_C_READ, NULL);
+ if (!elf_file) {
+ fprintf(stderr, "elf_begin failed: %s\n", elf_errmsg(-1));
+ goto error;
+ }
+
+ if (elf_kind(elf_file) != ELF_K_ELF) {
+ fprintf(stderr, "Error: %s is not an ELF object\n",
+ so->elf_path);
+ goto error;
+ }
+
+ so->elf_fd = elf_fd;
+ so->elf_file = elf_file;
+ return 0;
+
+error:
+ close(elf_fd);
+ elf_end(elf_file);
+ return -1;
+}
+
+