]> git.ipfire.org Git - people/ric9/pakfire.git/commitdiff
stripper: Don't try to extract debuginfo from *.o files
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 8 Jan 2025 15:02:28 +0000 (15:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 8 Jan 2025 15:04:17 +0000 (15:04 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/stripper.c

index 4297c351ac3ece682d908fbb0562b840db7bac0a..4a21c1e2a6893f490a78f20c4f40842832414c2b 100644 (file)
@@ -24,6 +24,8 @@
 #include <sys/sendfile.h>
 #include <sys/stat.h>
 
+#include <elf.h>
+
 #include <pakfire/elf.h>
 #include <pakfire/filelist.h>
 #include <pakfire/hex.h>
@@ -323,6 +325,44 @@ ERROR:
        return r;
 }
 
+static int pakfire_stripper_extract_debug_sections(struct pakfire_stripper* self,
+               struct pakfire_file* file, struct pakfire_elf* elf, const char* build_id_path) {
+       int r;
+
+       const char* path =  pakfire_file_get_abspath(file);
+
+       const char* argv[] = {
+               "objcopy",
+               "--only-keep-debug",
+
+               // (Re-)compress everything using Zstandard
+               "--compress-debug-sections=zstd",
+
+               // Source File
+               path,
+
+               // Debug Info File
+               build_id_path,
+               NULL,
+       };
+
+       // Run the command
+       r = pakfire_jail_exec_command(self->jail, argv, NULL, 0);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not extract debug sections from %s: %s\n",
+                       pakfire_file_get_path(file), strerror(-r));
+               return r;
+
+       // The command returned an error
+       } else if (r > 0) {
+               ERROR(self->ctx, "Could not extract debug sections from %s: %d\n",
+                       pakfire_file_get_path(file), r);
+               return -ENOTSUP;
+       }
+
+       return 0;
+}
+
 static int pakfire_stripper_strip_debug_sections(struct pakfire_stripper* self,
                struct pakfire_file* file, struct pakfire_elf* elf) {
        const char* build_id = NULL;
@@ -332,6 +372,20 @@ static int pakfire_stripper_strip_debug_sections(struct pakfire_stripper* self,
        FILE* f = NULL;
        int r;
 
+       int extract_debuginfo = 1;
+
+       // Check whether we should extract debug information
+       switch (pakfire_elf_type(elf)) {
+               // Relocatable objects
+               case ET_REL:
+                       if (pakfire_file_matches(file, "**.o"))
+                               extract_debuginfo = 0;
+                       break;
+
+               default:
+                       break;
+       }
+
        // Fetch the path
        path = pakfire_file_get_abspath(file);
 
@@ -349,11 +403,6 @@ static int pakfire_stripper_strip_debug_sections(struct pakfire_stripper* self,
        if (r < 0)
                goto ERROR;
 
-       // Create the directories
-       r = pakfire_mkparentdir(build_id_path, 0755);
-       if (r < 0)
-               goto ERROR;
-
        // Make a path for a new temporary file
        r = pakfire_path(self->pakfire, tmppath, "%s", PAKFIRE_TMP_DIR "/.pakfire-strip.XXXXXXX");
        if (r < 0)
@@ -366,33 +415,16 @@ static int pakfire_stripper_strip_debug_sections(struct pakfire_stripper* self,
                goto ERROR;
        }
 
-       const char* extract_argv[] = {
-               "objcopy",
-               "--only-keep-debug",
-
-               // (Re-)compress everything using Zstandard
-               "--compress-debug-sections=zstd",
-
-               // Source File
-               path,
-
-               // Debug Info File
-               build_id_path,
-               NULL,
-       };
-
-       // Run the command
-       r = pakfire_jail_exec_command(self->jail, extract_argv, NULL, 0);
-       if (r < 0) {
-               ERROR(self->ctx, "Could not extract debug sections from %s: %s\n",
-                       pakfire_file_get_path(file), strerror(-r));
-               return r;
+       // Extract the debug information
+       if (extract_debuginfo) {
+               // Create the directories
+               r = pakfire_mkparentdir(build_id_path, 0755);
+               if (r < 0)
+                       goto ERROR;
 
-       // The command returned an error
-       } else if (r > 0) {
-               ERROR(self->ctx, "Could not extract debug sections from %s: %d\n",
-                       pakfire_file_get_path(file), r);
-               return -ENOTSUP;
+               r = pakfire_stripper_extract_debug_sections(self, file, elf, build_id_path);
+               if (r < 0)
+                       goto ERROR;
        }
 
        const char* strip_argv[] = {