]> git.ipfire.org Git - people/ric9/pakfire.git/commitdiff
stripper: Add the debuglink only when we have extracted the debuginfo
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 8 Jan 2025 15:23:35 +0000 (15:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 8 Jan 2025 15:24:44 +0000 (15:24 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/stripper.c

index 99358a3777fee67f258e5e37c48b775a9ddbafd6..3b93ca9bda97c02ff1b01152499ecc8480de1adb 100644 (file)
@@ -377,6 +377,8 @@ static int pakfire_stripper_strip_debuginfo(struct pakfire_stripper* self,
        FILE* f = NULL;
        int r;
 
+       char** argv = NULL;
+
        int extract_debuginfo = 1;
 
        // Check whether we should extract debug information
@@ -420,14 +422,7 @@ static int pakfire_stripper_strip_debuginfo(struct pakfire_stripper* self,
                goto ERROR;
        }
 
-       // Extract the debug information
-       if (extract_debuginfo) {
-               r = pakfire_stripper_extract_debuginfo(self, file, elf, build_id_path);
-               if (r < 0)
-                       goto ERROR;
-       }
-
-       const char* strip_argv[] = {
+       const char* strip[] = {
                "objcopy",
 
                // Ask to strip all debug information
@@ -441,9 +436,8 @@ static int pakfire_stripper_strip_debuginfo(struct pakfire_stripper* self,
                "--remove-section=.gnu.debuglto_*",
                "--strip-symbol=__gnu_lto_v1",
 
-               // Add the debuglink
+               // Remove any previous debuglinks
                "--remove-section=.gnu_debuglink",
-               "--add-gnu-debuglink", build_id_path,
 
                // The source file
                path,
@@ -453,8 +447,25 @@ static int pakfire_stripper_strip_debuginfo(struct pakfire_stripper* self,
                NULL,
        };
 
+       // Compose the commandline
+       r = pakfire_strings_appendm(&argv, strip);
+       if (r < 0)
+               goto ERROR;
+
+       // Extract the debug information
+       if (extract_debuginfo) {
+               r = pakfire_stripper_extract_debuginfo(self, file, elf, build_id_path);
+               if (r < 0)
+                       goto ERROR;
+
+               // Add the debuglink
+               r = pakfire_strings_appendf(&argv, "--add-gnu-debuglink=%s", build_id_path);
+               if (r < 0)
+                       goto ERROR;
+       }
+
        // Run the command
-       r = pakfire_jail_exec_command(self->jail, strip_argv, NULL, 0);
+       r = pakfire_jail_exec_command(self->jail, (const char**)argv, NULL, 0);
        if (r < 0) {
                ERROR(self->ctx, "Could not strip debug sections from %s: %s\n",
                        pakfire_file_get_path(file), strerror(-r));
@@ -474,6 +485,8 @@ static int pakfire_stripper_strip_debuginfo(struct pakfire_stripper* self,
                goto ERROR;
 
 ERROR:
+       if (argv)
+               pakfire_strings_free(argv);
        if (*tmppath)
                unlink(tmppath);
        if (f)