]> git.ipfire.org Git - pakfire.git/commitdiff
ELF: Implement reading the Debuglink
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 1 Jan 2025 17:22:36 +0000 (17:22 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 1 Jan 2025 17:22:36 +0000 (17:22 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/elf.c
src/libpakfire/include/pakfire/elf.h
src/libpakfire/linter-file.c

index 4ad4b3e127e757ff493aae1bff0894ec5656839b..878d493a3148bfdefdc515fd6944cf1e45787a88 100644 (file)
@@ -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;
index 0ecf6a56b078f907f40255138575aed78bf4927d..c4d2376d9dab1ca70bd08dd32275a47cffc7e24e 100644 (file)
@@ -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);
 
index 2bac4a9f776d64c25317193255c878134762e425..958b6165d787774275d611b6d0493d8321cb5fd6 100644 (file)
@@ -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;
 }