]> git.ipfire.org Git - pakfire.git/commitdiff
ELF: Add a function to fetch the SONAME
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Jan 2025 12:08:34 +0000 (12:08 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Jan 2025 12:08:34 +0000 (12:08 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/elf.c
src/pakfire/elf.h

index c9c1dadd71b1ed86a3fc6516fd11feee3ad742ca..8f4670815ddb2b3bc3d9f1fec799aec117697f1e 100644 (file)
@@ -58,6 +58,9 @@ struct pakfire_elf {
        // Interpreter
        const char* interpreter;
 
+       // SONAME
+       const char* soname;
+
        // GNU Build ID
        char* build_id;
 
@@ -460,6 +463,31 @@ const char* pakfire_elf_interpreter(struct pakfire_elf* self) {
        return self->interpreter;
 }
 
+static int pakfire_elf_fetch_soname(struct pakfire_elf* self,
+               const GElf_Shdr* shdr, const GElf_Dyn* dyn, void* data) {
+       switch (dyn->d_tag) {
+               case DT_SONAME:
+                       self->soname = elf_strptr(self->elf, shdr->sh_link, dyn->d_un.d_val);
+
+                       return 1;
+       }
+
+       return 0;
+}
+
+const char* pakfire_elf_soname(struct pakfire_elf* self) {
+       int r;
+
+       // Fetch the SONAME if not available
+       if (!self->soname) {
+               r = pakfire_elf_dyn_walk(self, pakfire_elf_fetch_soname, NULL);
+               if (r < 0)
+                       return NULL;
+       }
+
+       return self->soname;
+}
+
 int pakfire_elf_is_pie(struct pakfire_elf* self) {
        switch (pakfire_elf_type(self)) {
                // Shared Object files are good
index 450e7c481ff2aadb143200576cd90007a7b16014..d6f3ef99e83c558ff224f808f8cf97601738fd36 100644 (file)
@@ -45,6 +45,7 @@ int pakfire_elf_endianess(struct pakfire_elf* self);
 const char* pakfire_elf_build_id(struct pakfire_elf* self);
 const char* pakfire_elf_debuglink(struct pakfire_elf* self);
 const char* pakfire_elf_interpreter(struct pakfire_elf* elf);
+const char* pakfire_elf_soname(struct pakfire_elf* self);
 
 int pakfire_elf_is_pie(struct pakfire_elf* self);
 int pakfire_elf_has_ssp(struct pakfire_elf* self);