From: Michael Tremer Date: Wed, 1 Jan 2025 17:22:36 +0000 (+0000) Subject: ELF: Implement reading the Debuglink X-Git-Tag: 0.9.30~602 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9de5e710a4ee125eeb199d5dd6c6f2f06ef1038c;p=pakfire.git ELF: Implement reading the Debuglink Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/elf.c b/src/libpakfire/elf.c index 4ad4b3e12..878d493a3 100644 --- a/src/libpakfire/elf.c +++ b/src/libpakfire/elf.c @@ -50,6 +50,9 @@ struct pakfire_elf { // GNU Build ID char* build_id; + + // GNU Debuglink + const char* debuglink; }; static int pakfire_elf_init_libelf(struct pakfire_ctx* ctx) { @@ -233,6 +236,22 @@ const char* pakfire_elf_build_id(struct pakfire_elf* self) { return self->build_id; } +const char* pakfire_elf_debuglink(struct pakfire_elf* self) { + GElf_Word crc32; + + // Fetch the debug link + if (!self->debuglink) { + self->debuglink = dwelf_elf_gnu_debuglink(self->elf, &crc32); + if (!self->debuglink) + return NULL; + + DEBUG(self->ctx, "%s has debug link pointing at %s\n", + self->path, self->debuglink); + } + + return self->debuglink; +} + static int pakfire_elf_get_section(struct pakfire_elf* self, const Elf64_Word type, Elf_Scn** section, GElf_Shdr* header, Elf_Data** data) { Elf_Scn* s = NULL; diff --git a/src/libpakfire/include/pakfire/elf.h b/src/libpakfire/include/pakfire/elf.h index 0ecf6a56b..c4d2376d9 100644 --- a/src/libpakfire/include/pakfire/elf.h +++ b/src/libpakfire/include/pakfire/elf.h @@ -40,6 +40,7 @@ struct pakfire_elf* pakfire_elf_unref(struct pakfire_elf* self); const char* pakfire_elf_path(struct pakfire_elf* self); int pakfire_elf_type(struct pakfire_elf* self); const char* pakfire_elf_build_id(struct pakfire_elf* self); +const char* pakfire_elf_debuglink(struct pakfire_elf* self); int pakfire_elf_is_stripped(struct pakfire_elf* self); diff --git a/src/libpakfire/linter-file.c b/src/libpakfire/linter-file.c index 2bac4a9f7..958b6165d 100644 --- a/src/libpakfire/linter-file.c +++ b/src/libpakfire/linter-file.c @@ -924,16 +924,13 @@ static int pakfire_linter_file_is_stripped(struct pakfire_linter_file* lfile) { } static int pakfire_linter_file_has_debuglink(struct pakfire_linter_file* lfile) { - const char* name = NULL; - GElf_Word crc32; + const char* debuglink = NULL; // Fetch the debug link - name = dwelf_elf_gnu_debuglink(lfile->elf, &crc32); - if (!name) + debuglink = pakfire_elf_debuglink(lfile->_elf); + if (!debuglink) return pakfire_linter_file_error(lfile, "Missing Debug Link"); - DEBUG(lfile->ctx, "%s has debug link pointing at %s\n", lfile->path, name); - return 0; }