From: Michael Tremer Date: Wed, 8 Jan 2025 15:23:35 +0000 (+0000) Subject: stripper: Add the debuglink only when we have extracted the debuginfo X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b3b2417110e2ccaecc3ab2a104e4fc2d5d41edf2;p=people%2Fric9%2Fpakfire.git stripper: Add the debuglink only when we have extracted the debuginfo Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/stripper.c b/src/pakfire/stripper.c index 99358a377..3b93ca9bd 100644 --- a/src/pakfire/stripper.c +++ b/src/pakfire/stripper.c @@ -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)