Skip to content

Commit

Permalink
Automatically compress debug info unless no-debuginfo-compression is set
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alexlarsson authored and rh-atomic-bot committed Oct 5, 2017
1 parent 5818790 commit 3471055
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 5 deletions.
4 changes: 4 additions & 0 deletions doc/flatpak-manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 5 additions & 1 deletion src/builder-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
34 changes: 34 additions & 0 deletions src/builder-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct BuilderOptions

gboolean strip;
gboolean no_debuginfo;
gboolean no_debuginfo_compression;
char *cflags;
char *cppflags;
char *cxxflags;
Expand Down Expand Up @@ -73,6 +74,7 @@ enum {
PROP_ENV,
PROP_STRIP,
PROP_NO_DEBUGINFO,
PROP_NO_DEBUGINFO_COMPRESSION,
PROP_ARCH,
PROP_BUILD_ARGS,
PROP_CONFIG_OPTS,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/builder-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
23 changes: 19 additions & 4 deletions src/builder-post-process.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/builder-post-process.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions src/builder-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions src/builder-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3471055

Please sign in to comment.