[PATCH] gas: Add --force-compress-debug-sections
Tom de Vries
tdevries@suse.de
Thu Feb 23 12:45:19 GMT 2023
Gas has an option --compress-debug-sections that allows it to generate
compressed debug sections.
That does not guarantee that the debug sections are in fact compressed:
...
$ gcc ~/hello.c -Wa,-gdwarf-5 -c -Wa,--compress-debug-sections=zstd
$ readelf -S -W hello.o | grep " .debug"
[ 9] .debug_line PROGBITS 0000a8 000053 00 0 0 1
[11] .debug_line_str PROGBITS 0000fb 000025 01 MS 0 0 1
[12] .debug_info PROGBITS 000120 000039 00 0 0 1
[14] .debug_abbrev PROGBITS 000159 000028 00 0 0 1
[15] .debug_aranges PROGBITS 000190 000030 00 0 0 16
[17] .debug_str PROGBITS 0001c0 000039 01 MS 0 0 1
...
Sensibly so, they're only compressed if that provides a size benefit.
However, for the purposes of testing components consuming dwarf
we may want the sections to be compressed regardless.
Add a new option --force-compress-debug-sections that ignores the size
heuristic, such that we have instead:
...
$ gcc ~/hello.c -Wa,-gdwarf-5 -c -Wa,--compress-debug-sections=zstd \
-Wa,--force-compress-debug-sections
$ readelf -S -W hello.o | grep " .debug"
[ 9] .debug_line PROGBITS 0000a8 000064 00 C 0 0 8
[11] .debug_line_str PROGBITS 000110 000046 01 MSC 0 0 8
[12] .debug_info PROGBITS 000158 000046 00 C 0 0 8
[14] .debug_abbrev PROGBITS 0001a0 000049 00 C 0 0 8
[15] .debug_aranges PROGBITS 0001f0 000034 00 C 0 0 8
[17] .debug_str PROGBITS 000228 00005a 01 MSC 0 0 8
...
Advertised as:
...
$ as --help 2>&1 | grep compress
--compress-debug-sections[={none|zlib|zlib-gnu|zlib-gabi|zstd}]
compress DWARF debug sections
--nocompress-debug-sections
don't compress DWARF debug sections
--force-compress-debug-sections
force compression of DWARF debug sections
...
Tested on x86_64-linux.
---
gas/as.c | 13 ++++++++++++-
gas/as.h | 4 ++++
gas/doc/as.texi | 10 ++++++++--
gas/write.c | 4 ++--
4 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/gas/as.c b/gas/as.c
index 598bfd56cf5..835c51c609b 100644
--- a/gas/as.c
+++ b/gas/as.c
@@ -230,6 +230,8 @@ enum compressed_debug_section_type flag_compress_debug
= DEFAULT_COMPRESSED_DEBUG_ALGORITHM;
#endif
+bool flag_force_compress_debug = false;
+
static void
show_usage (FILE * stream)
{
@@ -262,6 +264,9 @@ Options:\n\
--nocompress-debug-sections\n\
don't compress DWARF debug sections\n"));
fprintf (stream, _("\
+ --force-compress-debug-sections\n\
+ force compression of DWARF debug sections\n")),
+ fprintf (stream, _("\
-D produce assembler debugging messages\n"));
fprintf (stream, _("\
--dump-config display how the assembler is configured and then exit\n"));
@@ -508,7 +513,8 @@ parse_args (int * pargc, char *** pargv)
OPTION_NOCOMPRESS_DEBUG,
OPTION_NO_PAD_SECTIONS,
OPTION_MULTIBYTE_HANDLING, /* = STD_BASE + 40 */
- OPTION_SFRAME
+ OPTION_SFRAME,
+ OPTION_FORCE_COMPRESS_DEBUG
/* When you add options here, check that they do
not collide with OPTION_MD_BASE. See as.h. */
};
@@ -528,6 +534,7 @@ parse_args (int * pargc, char *** pargv)
,{"al", optional_argument, NULL, OPTION_AL}
,{"compress-debug-sections", optional_argument, NULL, OPTION_COMPRESS_DEBUG}
,{"nocompress-debug-sections", no_argument, NULL, OPTION_NOCOMPRESS_DEBUG}
+ ,{"force-compress-debug-sections", no_argument, NULL, OPTION_FORCE_COMPRESS_DEBUG}
,{"debug-prefix-map", required_argument, NULL, OPTION_DEBUG_PREFIX_MAP}
,{"defsym", required_argument, NULL, OPTION_DEFSYM}
,{"dump-config", no_argument, NULL, OPTION_DUMPCONFIG}
@@ -771,6 +778,10 @@ This program has absolutely no warranty.\n"));
flag_compress_debug = COMPRESS_DEBUG_NONE;
break;
+ case OPTION_FORCE_COMPRESS_DEBUG:
+ flag_force_compress_debug = true;
+ break;
+
case OPTION_DEBUG_PREFIX_MAP:
add_debug_prefix_map (optarg);
break;
diff --git a/gas/as.h b/gas/as.h
index 4c5fa9ecf7d..3f8935d2827 100644
--- a/gas/as.h
+++ b/gas/as.h
@@ -331,6 +331,10 @@ COMMON int flag_traditional_format;
/* Type of compressed debug sections we should generate. */
COMMON enum compressed_debug_section_type flag_compress_debug;
+/* True if we want to generate compressed debug sections, even if it
+ doesn't make them smaller. */
+COMMON bool flag_force_compress_debug;
+
/* TRUE if .note.GNU-stack section with SEC_CODE should be created */
COMMON int flag_execstack;
diff --git a/gas/doc/as.texi b/gas/doc/as.texi
index bbdfa4bfdca..c853cafbbe5 100644
--- a/gas/doc/as.texi
+++ b/gas/doc/as.texi
@@ -229,6 +229,7 @@ gcc(1), ld(1), and the Info entries for @file{binutils} and @file{ld}.
@value{AS} [@b{-a}[@b{cdghlns}][=@var{file}]]
[@b{--alternate}]
[@b{--compress-debug-sections}] [@b{--nocompress-debug-sections}]
+ [@b{--force-compress-debug-sections}]
[@b{-D}]
[@b{--dump-config}]
[@b{--debug-prefix-map} @var{old}=@var{new}]
@@ -718,7 +719,8 @@ Begin in alternate macro mode.
Compress DWARF debug sections using zlib with SHF_COMPRESSED from the
ELF ABI. The resulting object file may not be compatible with older
linkers and object file utilities. Note if compression would make a
-given section @emph{larger} then it is not compressed.
+given section @emph{larger} then it is not compressed, unless
+@option{--force-compress-debug-section} is used.
@ifset ELF
@cindex @samp{--compress-debug-sections=} option
@@ -738,7 +740,11 @@ using the obsoleted zlib-gnu format. The debug sections are renamed to begin
with @samp{.zdebug}.
@option{--compress-debug-sections=zstd} compresses DWARF debug
sections using zstd. Note - if compression would actually make a section
-@emph{larger}, then it is not compressed nor renamed.
+@emph{larger}, then it is not compressed nor renamed, unless
+@option{--force-compress-debug-section} is used.
+
+@item --force-compress-debug-sections
+Compress DWARF debug sections, even if this does not reduce size.
@end ifset
diff --git a/gas/write.c b/gas/write.c
index 8273b7a42f1..8fcbc326e3f 100644
--- a/gas/write.c
+++ b/gas/write.c
@@ -1465,7 +1465,7 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)
flagword flags = bfd_section_flags (sec);
if (seginfo == NULL
- || uncompressed_size < 32
+ || (!flag_force_compress_debug && uncompressed_size < 32)
|| (flags & SEC_HAS_CONTENTS) == 0)
return;
@@ -1582,7 +1582,7 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)
/* PR binutils/18087: If compression didn't make the section smaller,
just keep it uncompressed. */
- if (compressed_size >= uncompressed_size)
+ if (!flag_force_compress_debug && compressed_size >= uncompressed_size)
return;
/* Replace the uncompressed frag list with the compressed frag list. */
--
2.35.3
More information about the Binutils
mailing list