From: Michael Tremer Date: Fri, 3 Jan 2025 12:08:34 +0000 (+0000) Subject: ELF: Add a function to fetch the SONAME X-Git-Tag: 0.9.30~558 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bc5320e9fe2b18c958d54f63a45da1ab1e4cbbdb;p=pakfire.git ELF: Add a function to fetch the SONAME Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/elf.c b/src/pakfire/elf.c index c9c1dadd7..8f4670815 100644 --- a/src/pakfire/elf.c +++ b/src/pakfire/elf.c @@ -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 diff --git a/src/pakfire/elf.h b/src/pakfire/elf.h index 450e7c481..d6f3ef99e 100644 --- a/src/pakfire/elf.h +++ b/src/pakfire/elf.h @@ -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);