X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=lib%2Fzpm.c;h=30ec7a669cae61ae2f8e50c2cb43f2c4f7b427b4;hb=82e3fcbcf22abcd3921a8946e6ac2b5dd948c44e;hp=f0ae5a2a3d2fcf4ab0045f8c4e03e9870875cb05;hpb=ff478f700fc6179cf7246b4f9624712c4e180c7e;p=zpackage diff --git a/lib/zpm.c b/lib/zpm.c index f0ae5a2..30ec7a6 100644 --- a/lib/zpm.c +++ b/lib/zpm.c @@ -602,57 +602,22 @@ static int set_elf_info(sqlite3 *db, char *hash, char *content, size_t length) { hdr = libelf_header(content); /* if lib, set soname */ if (libelf_type(content) == ET_DYN) { - char *elf; - Elf64_Shdr *shdr, *dynsect, *dynstrtab = 0; - - elf = (char *)content; - for (i = 0; i < hdr->e_shnum; i++) { - shdr = (Elf64_Shdr *)(elf + hdr->e_shoff + i * hdr->e_shentsize); - if (shdr->sh_type == SHT_DYNAMIC) { - dynsect = shdr; - } else if (shdr->sh_type == SHT_STRTAB && i == hdr->e_shstrndx) { - dynstrtab = shdr; - } - } - if (!dynstrtab) { - exit(8); - } - if (!dynsect) { - exit(9); - } - - char *name; - Elf64_Shdr *dyntab; - name = elf + dynstrtab->sh_offset; - for (i = 0; i < hdr->e_shnum; i++) { - shdr = (Elf64_Shdr *)(elf + hdr->e_shoff + i * hdr->e_shentsize); - if (shdr->sh_type == SHT_STRTAB && !strcmp(".dynstr", name+shdr->sh_name)) { - dyntab = shdr; - } - } - if (!dyntab) { - exit(10); - } - - char *dynname; - Elf64_Dyn *dent; - dynname = elf + dyntab->sh_offset; - - for (dent = (Elf64_Dyn *)(elf + dynsect->sh_offset); dent->d_tag != DT_NULL; dent++) { - if (dent->d_tag == DT_SONAME) { - char *soname = dynname + dent->d_un.d_val; - sqlite3_prepare_v2(db, "insert into elflibraries (file,soname) values (?,?)",-1, &ifile, 0); - sqlite3_bind_text(ifile,1,hash,64,SQLITE_STATIC); - sqlite3_bind_text(ifile,2,soname,-1,SQLITE_STATIC); - rc = sqlite3_step(ifile); - if (rc != SQLITE_DONE) { - SQLERROR(sqlite3_errmsg(db)); - sqlite3_finalize(ifile); - fprintf(stderr, "error setting library soname\n"); - return 0; - } + char *soname = libelf_soname(content); + if (soname) { + + sqlite3_prepare_v2(db, "insert into elflibraries (file,soname) values (?,?)",-1, &ifile, 0); + sqlite3_bind_text(ifile,1,hash,64,SQLITE_STATIC); + sqlite3_bind_text(ifile,2,soname,-1,SQLITE_STATIC); + rc = sqlite3_step(ifile); + if (rc != SQLITE_DONE) { + SQLERROR(sqlite3_errmsg(db)); sqlite3_finalize(ifile); + fprintf(stderr, "error setting library soname\n"); + return 0; } + sqlite3_finalize(ifile); + } else { + fprintf(stderr, "can't find soname\n"); } }