From: Michael Tremer Date: Sun, 29 Dec 2024 20:03:58 +0000 (+0000) Subject: stripper: Extract the GNU Build ID X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d3f424b5528ae25325ad87a3d7545681ea8b4593;p=people%2Fric9%2Fpakfire.git stripper: Extract the GNU Build ID Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 95d199f51..49a6e1a62 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -1273,7 +1273,7 @@ ERROR: static const char* post_build_scripts[] = { "compress-man-pages", - "strip", + // "strip", NULL, }; diff --git a/src/libpakfire/stripper.c b/src/libpakfire/stripper.c index bd68e0511..3dcde4620 100644 --- a/src/libpakfire/stripper.c +++ b/src/libpakfire/stripper.c @@ -25,8 +25,10 @@ // libdw #include +#include #include +#include #include #include #include @@ -163,6 +165,42 @@ ERROR: return r; } +static int pakfire_stripper_extract_build_id(struct pakfire_stripper* stripper, + struct pakfire_file* file, int fd, char** build_id) { + Elf* elf = NULL; + const void* buffer = NULL; + ssize_t length = -1; + int r = 0; + + elf = elf_begin(fd, ELF_C_READ, NULL); + if (!elf) { + ERROR(stripper->ctx, "Could not open ELF file %s: %s\n", + pakfire_file_get_path(file), elf_errmsg(-1)); + r = -ENOTSUP; + goto ERROR; + } + + // Extract the GNU Build ID + length = dwelf_elf_gnu_build_id(elf, &buffer); + if (length < 0) { + ERROR(stripper->ctx, "Could not read the GNU Build ID from %s: %s\n", + pakfire_file_get_path(file), elf_errmsg(-1)); + r = -ENOTSUP; + goto ERROR; + } + + // Convert the Build ID to hex + *build_id = __pakfire_hexlify(buffer, length); + + DEBUG(stripper->ctx, "%s has Build ID %s\n", pakfire_file_get_path(file), *build_id); + +ERROR: + if (elf) + elf_end(elf); + + return r; +} + static int pakfire_stripper_copy_source_file( struct pakfire_stripper* stripper, const char* filename) { struct stat st = {}; @@ -352,6 +390,7 @@ ERROR: static int pakfire_stripper_strip( struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { struct pakfire_stripper* stripper = data; + char* build_id = NULL; int fd = -EBADF; int r; @@ -362,12 +401,19 @@ static int pakfire_stripper_strip( goto ERROR; } + // Extract the Build ID + r = pakfire_stripper_extract_build_id(stripper, file, fd, &build_id); + if (r < 0) + goto ERROR; + // Copy sources r = pakfire_stripper_copy_sources(stripper, file, fd); if (r < 0) goto ERROR; ERROR: + if (build_id) + free(build_id); if (fd >= 0) close(fd);