#include <sys/sendfile.h>
#include <sys/stat.h>
+#include <elf.h>
+
#include <pakfire/elf.h>
#include <pakfire/filelist.h>
#include <pakfire/hex.h>
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;
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);
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)
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[] = {