]> git.ipfire.org Git - pakfire.git/commitdiff
linter: Remove the unused ELF stuff
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Jan 2025 15:45:20 +0000 (15:45 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Jan 2025 15:45:20 +0000 (15:45 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/linter-file.c

index 340823080dab8bd2ff9383d83ed2f01509b82a8d..b611fdcca56f18dcbc698f57f8974a8ec6a926e1 100644 (file)
@@ -24,7 +24,6 @@
 
 // libelf
 #include <gelf.h>
-#include <elfutils/libdwelf.h>
 
 #include <pakfire/ctx.h>
 #include <pakfire/elf.h>
@@ -45,7 +44,7 @@ struct pakfire_linter_file {
        struct pakfire_file* file;
 
        // ELF Object
-       struct pakfire_elf* _elf;
+       struct pakfire_elf* elf;
 
        // File Descriptor
        int fd;
@@ -58,9 +57,6 @@ struct pakfire_linter_file {
 
        // Path
        const char* path;
-
-       // ELF
-       Elf* elf;
 };
 
 #define pakfire_linter_file_info(lfile, format, ...) \
@@ -70,32 +66,6 @@ struct pakfire_linter_file {
 #define pakfire_linter_file_error(lfile, format, ...) \
        pakfire_linter_result(lfile->linter, lfile->file, PAKFIRE_LINTER_ERROR, format, ## __VA_ARGS__)
 
-static int pakfire_linter_file_init_libelf(struct pakfire_linter_file* lfile) {
-       // Initialize libelf
-       if (elf_version(EV_CURRENT) == EV_NONE) {
-               ERROR(lfile->ctx, "Could not initialize libelf: %s\n", elf_errmsg(-1));
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
-static int pakfire_linter_file_open_elf(struct pakfire_linter_file* lfile) {
-       int r;
-
-       // Initialize libelf
-       r = pakfire_linter_file_init_libelf(lfile);
-       if (r < 0)
-               return r;
-
-       // Parse the ELF header
-       lfile->elf = elf_memory(lfile->data, lfile->length);
-       if (!lfile->elf)
-               return -errno;
-
-       return 0;
-}
-
 /*
        Maps the file into memory
 */
@@ -162,7 +132,7 @@ int pakfire_linter_file_create(struct pakfire_linter_file** lfile,
        }
 
        // Open an ELF object
-       r = pakfire_elf_open(&l->_elf, l->ctx, l->path, l->fd);
+       r = pakfire_elf_open(&l->elf, l->ctx, l->path, l->fd);
        if (r < 0) {
                switch (-r) {
                        // This does not seem to be an ELF file
@@ -175,13 +145,6 @@ int pakfire_linter_file_create(struct pakfire_linter_file** lfile,
                }
        }
 
-       // Initialize libelf
-       r = pakfire_linter_file_open_elf(l);
-       if (r < 0) {
-               ERROR(l->ctx, "Could not initialize libelf: %s\n", strerror(-r));
-               goto ERROR;
-       }
-
        // Return the pointer
        *lfile = pakfire_linter_file_ref(l);
 
@@ -195,11 +158,8 @@ ERROR:
 static void pakfire_linter_file_free(struct pakfire_linter_file* lfile) {
        int r;
 
-       if (lfile->_elf)
-               pakfire_elf_unref(lfile->_elf);
-
        if (lfile->elf)
-               elf_end(lfile->elf);
+               pakfire_elf_unref(lfile->elf);
 
        if (lfile->data) {
                r = munmap(lfile->data, lfile->length);
@@ -347,7 +307,7 @@ static int pakfire_linter_check_script_interpreter(struct pakfire_linter_file* l
 }
 
 static int pakfire_linter_file_check_pie(struct pakfire_linter_file* lfile) {
-       if (!pakfire_elf_is_pie(lfile->_elf))
+       if (!pakfire_elf_is_pie(lfile->elf))
                return pakfire_linter_file_error(lfile, "Missing PIE");
 
        return 0;
@@ -374,14 +334,14 @@ static int pakfire_linter_file_check_ssp(struct pakfire_linter_file* lfile) {
        }
 
        // Report an error if there is not SSP
-       if (!pakfire_elf_has_ssp(lfile->_elf))
+       if (!pakfire_elf_has_ssp(lfile->elf))
                return pakfire_linter_file_error(lfile, "Missing Stack Smashing Protection");
 
        return 0;
 }
 
 static int pakfire_linter_file_check_execstack(struct pakfire_linter_file* lfile) {
-       if (pakfire_elf_has_execstack(lfile->_elf))
+       if (pakfire_elf_has_execstack(lfile->elf))
                return pakfire_linter_file_error(lfile, "Executable Stack");
 
        return 0;
@@ -389,11 +349,11 @@ static int pakfire_linter_file_check_execstack(struct pakfire_linter_file* lfile
 
 static int pakfire_linter_file_check_relro(struct pakfire_linter_file* lfile) {
        // If the file is fully RELRO, everything is good
-       if (pakfire_elf_is_fully_relro(lfile->_elf))
+       if (pakfire_elf_is_fully_relro(lfile->elf))
                return 0;
 
        // Show a warning if the file is only partially RELRO
-       else if (pakfire_elf_is_partially_relro(lfile->_elf))
+       else if (pakfire_elf_is_partially_relro(lfile->elf))
                return pakfire_linter_file_warning(lfile, "Is partially RELRO");
 
        // Return an error if this file is not RELRO at all
@@ -405,7 +365,7 @@ static int pakfire_linter_file_check_runpath(struct pakfire_linter_file* lfile)
        int r;
 
        // Fetch any runpaths
-       r = pakfire_elf_has_runpaths(lfile->_elf, &runpaths);
+       r = pakfire_elf_has_runpaths(lfile->elf, &runpaths);
        if (r < 0)
                goto ERROR;
 
@@ -440,7 +400,7 @@ static int pakfire_linter_file_check_cf_protection(struct pakfire_linter_file* l
        int r;
 
        // Fetch if CF Protection has been enabled
-       int flags = pakfire_elf_has_cf_protection(lfile->_elf);
+       int flags = pakfire_elf_has_cf_protection(lfile->elf);
 
        // aarch64: Branch Target Identification
        if (flags & PAKFIRE_ELF_MISSING_BTI) {
@@ -474,7 +434,7 @@ static int pakfire_linter_file_check_cf_protection(struct pakfire_linter_file* l
 }
 
 static int pakfire_linter_file_is_stripped(struct pakfire_linter_file* lfile) {
-       switch (pakfire_elf_type(lfile->_elf)) {
+       switch (pakfire_elf_type(lfile->elf)) {
                // Do not check Relocatable Objects
                case ET_REL:
                        return 0;
@@ -484,7 +444,7 @@ static int pakfire_linter_file_is_stripped(struct pakfire_linter_file* lfile) {
                        break;
        }
 
-       if (!pakfire_elf_is_stripped(lfile->_elf))
+       if (!pakfire_elf_is_stripped(lfile->elf))
                return pakfire_linter_file_error(lfile, "Not Stripped");
 
        return 0;
@@ -494,7 +454,7 @@ static int pakfire_linter_file_has_debuglink(struct pakfire_linter_file* lfile)
        const char* debuglink = NULL;
 
        // Fetch the debug link
-       debuglink = pakfire_elf_debuglink(lfile->_elf);
+       debuglink = pakfire_elf_debuglink(lfile->elf);
        if (!debuglink)
                return pakfire_linter_file_error(lfile, "Missing Debug Link");
 
@@ -505,7 +465,7 @@ static int pakfire_linter_file_has_build_id(struct pakfire_linter_file* lfile) {
        const char* build_id = NULL;
 
        // Fetch the build ID
-       build_id = pakfire_elf_build_id(lfile->_elf);
+       build_id = pakfire_elf_build_id(lfile->elf);
        if (!build_id)
                return pakfire_linter_file_error(lfile, "Missing Build ID");
 
@@ -515,11 +475,11 @@ static int pakfire_linter_file_has_build_id(struct pakfire_linter_file* lfile) {
 // Checks if files in /usr/lib/debug are correct
 static int pakfire_linter_file_check_debug(struct pakfire_linter_file* lfile) {
        // Fail if this file is not an ELF file
-       if (!lfile->_elf)
+       if (!lfile->elf)
                return pakfire_linter_file_error(lfile, "File is not in ELF format");
 
        // Fail if there is no debugging information in the file
-       if (pakfire_elf_is_stripped(lfile->_elf))
+       if (pakfire_elf_is_stripped(lfile->elf))
                return pakfire_linter_file_error(lfile, "Has no debug information");
 
        return 0;
@@ -555,7 +515,7 @@ int pakfire_linter_file_lint(struct pakfire_linter_file* lfile) {
                return pakfire_linter_file_check_debug(lfile);
 
        // ELF Checks
-       if (lfile->_elf) {
+       if (lfile->elf) {
                // Check if stripped
                r = pakfire_linter_file_is_stripped(lfile);
                if (r < 0)