Automatically compress debug info unless no-debuginfo-compression is set

This uses eu-elfcompress to compress the debuginfo. We use the older
zlib-gnu compression format which is older and has more widespread
support.

Closes: #43
Approved by: alexlarsson
tingping/wmclass
Alexander Larsson 2017-10-05 17:59:24 +02:00 committed by Atomic Bot
parent 5818790510
commit 34710550ef
8 changed files with 82 additions and 5 deletions

View File

@ -301,6 +301,10 @@
<listitem><para>By default (if strip is not true) flatpak-builder extracts all debug info in ELF files to a separate files
and puts this in an extension. If you want to disable this, set no-debuginfo to true.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>no-debuginfo-compression</option> (boolean)</term>
<listitem><para>By default when extracting debuginfo we compress the debug sections. If you want to disable this, set no-debuginfo-compression to true.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>arch</option> (object)</term>
<listitem><para>This is a dictionary defining for each arch a separate build options object that override the main one.</para></listitem>

View File

@ -1653,7 +1653,11 @@ builder_module_build_helper (BuilderModule *self,
else if (!builder_options_get_no_debuginfo (self->build_options, context) &&
/* No support for debuginfo for extensions atm */
!builder_context_get_build_extension (context))
post_process_flags |= BUILDER_POST_PROCESS_FLAGS_DEBUGINFO;
{
post_process_flags |= BUILDER_POST_PROCESS_FLAGS_DEBUGINFO;
if (!builder_options_get_no_debuginfo_compression (self->build_options, context))
post_process_flags |= BUILDER_POST_PROCESS_FLAGS_DEBUGINFO_COMPRESSION;
}
if (!builder_post_process (post_process_flags, app_dir,
cache, context, error))

View File

@ -38,6 +38,7 @@ struct BuilderOptions
gboolean strip;
gboolean no_debuginfo;
gboolean no_debuginfo_compression;
char *cflags;
char *cppflags;
char *cxxflags;
@ -73,6 +74,7 @@ enum {
PROP_ENV,
PROP_STRIP,
PROP_NO_DEBUGINFO,
PROP_NO_DEBUGINFO_COMPRESSION,
PROP_ARCH,
PROP_BUILD_ARGS,
PROP_CONFIG_OPTS,
@ -176,6 +178,10 @@ builder_options_get_property (GObject *object,
g_value_set_boolean (value, self->no_debuginfo);
break;
case PROP_NO_DEBUGINFO_COMPRESSION:
g_value_set_boolean (value, self->no_debuginfo_compression);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@ -271,6 +277,10 @@ builder_options_set_property (GObject *object,
self->no_debuginfo = g_value_get_boolean (value);
break;
case PROP_NO_DEBUGINFO_COMPRESSION:
self->no_debuginfo_compression = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@ -390,6 +400,13 @@ builder_options_class_init (BuilderOptionsClass *klass)
"",
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_NO_DEBUGINFO_COMPRESSION,
g_param_spec_boolean ("no-debuginfo-compression",
"",
"",
FALSE,
G_PARAM_READWRITE));
}
static void
@ -775,6 +792,22 @@ builder_options_get_no_debuginfo (BuilderOptions *self, BuilderContext *context)
return FALSE;
}
gboolean
builder_options_get_no_debuginfo_compression (BuilderOptions *self, BuilderContext *context)
{
g_autoptr(GList) options = get_all_options (self, context);
GList *l;
for (l = options; l != NULL; l = l->next)
{
BuilderOptions *o = l->data;
if (o->no_debuginfo_compression)
return TRUE;
}
return FALSE;
}
char **
builder_options_get_env (BuilderOptions *self, BuilderContext *context)
{
@ -953,6 +986,7 @@ builder_options_checksum (BuilderOptions *self,
builder_cache_checksum_strv (cache, self->make_install_args);
builder_cache_checksum_boolean (cache, self->strip);
builder_cache_checksum_boolean (cache, self->no_debuginfo);
builder_cache_checksum_compat_boolean (cache, self->no_debuginfo_compression);
arch_options = g_hash_table_lookup (self->arch, builder_context_get_arch (context));
if (arch_options)

View File

@ -66,6 +66,8 @@ void builder_options_checksum (BuilderOptions *self,
BuilderContext *context);
gboolean builder_options_get_no_debuginfo (BuilderOptions *self,
BuilderContext *context);
gboolean builder_options_get_no_debuginfo_compression (BuilderOptions *self,
BuilderContext *context);
gboolean builder_options_get_strip (BuilderOptions *self,
BuilderContext *context);

View File

@ -301,7 +301,6 @@ builder_post_process_python_time_stamp (GFile *app_dir,
return TRUE;
}
static gboolean
builder_post_process_strip (GFile *app_dir,
GPtrArray *changed,
@ -341,6 +340,7 @@ builder_post_process_strip (GFile *app_dir,
static gboolean
builder_post_process_debuginfo (GFile *app_dir,
GPtrArray *changed,
BuilderPostProcessFlags flags,
BuilderContext *context,
GError **error)
{
@ -453,13 +453,28 @@ builder_post_process_debuginfo (GFile *app_dir,
}
}
g_print ("stripping %s to %s\n", path, debug_path);
/* Some files are hardlinked and eu-strip modifies in-place,
which breaks rofiles-fuse. Unlink them */
if (!flatpak_break_hardlink (file, error))
return FALSE;
if (flags & BUILDER_POST_PROCESS_FLAGS_DEBUGINFO_COMPRESSION)
{
g_autoptr(GError) my_error = NULL;
g_print ("compressing debuginfo in: %s\n", path);
if (!eu_elfcompress (&my_error, "-t", "zlib-gnu", "-v", path, NULL))
{
if (g_error_matches (my_error, G_SPAWN_ERROR, G_SPAWN_ERROR_NOENT))
g_print ("Warning: eu-elfcompress not installed, will not compress debuginfo\n");
else
{
g_propagate_error (error, g_steal_pointer (&my_error));
return FALSE;
}
}
}
g_print ("stripping %s to %s\n", path, debug_path);
if (!eu_strip (error, "--remove-comment", "--reloc-debug-sections",
"-f", debug_path,
"-F", real_debug_path,
@ -496,7 +511,7 @@ builder_post_process (BuilderPostProcessFlags flags,
}
else if (flags & BUILDER_POST_PROCESS_FLAGS_DEBUGINFO)
{
if (!builder_post_process_debuginfo (app_dir, changed, context, error))
if (!builder_post_process_debuginfo (app_dir, changed, flags, context, error))
return FALSE;
}

View File

@ -31,6 +31,7 @@ typedef enum {
BUILDER_POST_PROCESS_FLAGS_PYTHON_TIMESTAMPS = 1<<0,
BUILDER_POST_PROCESS_FLAGS_STRIP = 1<<1,
BUILDER_POST_PROCESS_FLAGS_DEBUGINFO = 1<<2,
BUILDER_POST_PROCESS_FLAGS_DEBUGINFO_COMPRESSION = 1<<3,
} BuilderPostProcessFlags;
gboolean builder_post_process (BuilderPostProcessFlags flags,

View File

@ -159,6 +159,21 @@ eu_strip (GError **error,
return res;
}
gboolean
eu_elfcompress (GError **error,
...)
{
gboolean res;
va_list ap;
va_start (ap, error);
res = flatpak_spawn (NULL, NULL, error, "eu-elfcompress", ap);
va_end (ap);
return res;
}
static gboolean
elf_has_symtab (Elf *elf)
{

View File

@ -37,6 +37,8 @@ gboolean strip (GError **error,
...);
gboolean eu_strip (GError **error,
...);
gboolean eu_elfcompress (GError **error,
...);
gboolean is_elf_file (const char *path,
gboolean *is_shared,