return r;
}
+#define pakfire_stripper_build_id_path(stripper, buffer, build_id) \
+ __pakfire_stripper_build_id_path(stripper, buffer, sizeof(buffer), build_id)
+
+static int __pakfire_stripper_build_id_path(struct pakfire_stripper* stripper,
+ char* buffer, size_t length, const char* build_id) {
+ const char* buildroot = pakfire_relpath(stripper->pakfire, stripper->path);
+
+ return __pakfire_path(stripper->pakfire, buffer, length,
+ "%s/usr/lib/debug/.build-id/%c%c/%s.debug",
+ buildroot, build_id[0], build_id[1], build_id + 2);
+}
+
+#define pakfire_stripper_debug_path(stripper, buffer, file) \
+ __pakfire_stripper_debug_path(stripper, buffer, sizeof(buffer), file)
+
+static int __pakfire_stripper_debug_path(struct pakfire_stripper* stripper,
+ char* buffer, size_t length, struct pakfire_file* file) {
+ const char* buildroot = pakfire_relpath(stripper->pakfire, stripper->path);
+
+ return __pakfire_path(stripper->pakfire, buffer, length,
+ "%s/usr/lib/debug%s.debug", buildroot, pakfire_file_get_path(file));
+}
+
+static int pakfire_stripper_extract_debug_sections(struct pakfire_stripper* stripper,
+ struct pakfire_file* file, const char* build_id) {
+ char build_id_path[PATH_MAX];
+ char debug_path[PATH_MAX];
+ const char* path = NULL;
+ int r;
+
+ // Fetch the path
+ path = pakfire_file_get_abspath(file);
+
+ // Make the debug path
+ r = pakfire_stripper_debug_path(stripper, debug_path, file);
+ if (r < 0)
+ return r;
+
+ // Make Build ID path
+ r = pakfire_stripper_build_id_path(stripper, build_id_path, build_id);
+ if (r < 0)
+ return r;
+
+ // Create the directories
+ r = pakfire_mkparentdir(debug_path, 0755);
+ if (r < 0)
+ return r;
+
+ r = pakfire_mkparentdir(build_id_path, 0755);
+ if (r < 0)
+ return r;
+
+ const char* argv[] = {
+ "objcopy",
+ "--only-keep-debug",
+ pakfire_relpath(stripper->pakfire, path),
+ pakfire_relpath(stripper->pakfire, debug_path),
+ NULL,
+ };
+
+ // Run the command
+ r = pakfire_jail_exec_command(stripper->jail, argv, NULL, 0);
+ if (r < 0) {
+ ERROR(stripper->ctx, "Could not strip 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(stripper->ctx, "Could not strip debug sections from %s\n",
+ pakfire_file_get_path(file));
+ return -ENOTSUP;
+ }
+
+ // Create a symlink
+ r = pakfire_symlink(stripper->ctx, debug_path, build_id_path);
+ if (r < 0)
+ return r;
+
+ return r;
+}
+
static int pakfire_stripper_strip(
struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) {
struct pakfire_stripper* stripper = data;
if (r < 0)
goto ERROR;
+ // Extract debug information
+ r = pakfire_stripper_extract_debug_sections(stripper, file, build_id);
+ if (r < 0)
+ goto ERROR;
+
ERROR:
if (build_id)
free(build_id);