From d8c9ee2288ff17179091d8e60fd1405ecc4fa782 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 8 Jan 2025 15:02:28 +0000 Subject: [PATCH] stripper: Don't try to extract debuginfo from *.o files Signed-off-by: Michael Tremer --- src/pakfire/stripper.c | 94 ++++++++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 31 deletions(-) diff --git a/src/pakfire/stripper.c b/src/pakfire/stripper.c index 4297c351a..4a21c1e2a 100644 --- a/src/pakfire/stripper.c +++ b/src/pakfire/stripper.c @@ -24,6 +24,8 @@ #include #include +#include + #include #include #include @@ -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[] = { -- 2.47.3