diff options
author | Cary Coutant <ccoutant@google.com> | 2010-07-03 20:52:24 +0000 |
---|---|---|
committer | Cary Coutant <ccoutant@google.com> | 2010-07-03 20:52:24 +0000 |
commit | 0acf065b19253e02ea32188ea0cbdf4e80e3c42d (patch) | |
tree | 0d2d49261e7a67a1fe51bff909c8506dd46dfa04 /gas | |
parent | 3a5530eaabb2592d7807687d51a8a9c8c6b4b3cd (diff) | |
download | gdb-0acf065b19253e02ea32188ea0cbdf4e80e3c42d.zip gdb-0acf065b19253e02ea32188ea0cbdf4e80e3c42d.tar.gz gdb-0acf065b19253e02ea32188ea0cbdf4e80e3c42d.tar.bz2 |
bfd/ChangeLog:
* compress.c (bfd_uncompress_section_contents): Add ATTRIBUTE_UNUSED.
* dwarf2.c (read_and_uncompress_section): New function.
(read_section): Call it.
(find_line): Likewise.
binutils/ChangeLog:
* objdump.c (load_specific_debug_section): Decompress section contents
before applying relocations.
* readelf.c (load_specific_debug_section): Update section size after
decompression.
gas/ChangeLog:
* Makefile.am: Add compress-debug.c and compress-debug.h.
* Makefile.in: Regenerate.
* config.in: Add HAVE_ZLIB_H.
* configure.in: Check for zlib.h.
* configure: Regenerate.
* as.c (parse_args): Add --compress-debug-sections and
--nocompress-debug-sections.
* as.h (flag_compress_debug): New variable.
* compress-debug.c: New file.
* compress-debug.h: New file.
* write.c: Include compress-debug.h.
(compress_frag): New function.
(compress_debug): New function.
(write_object_file): Compress debug sections if requested.
Diffstat (limited to 'gas')
-rw-r--r-- | gas/ChangeLog | 18 | ||||
-rw-r--r-- | gas/Makefile.am | 2 | ||||
-rw-r--r-- | gas/Makefile.in | 19 | ||||
-rw-r--r-- | gas/as.c | 14 | ||||
-rw-r--r-- | gas/as.h | 3 | ||||
-rw-r--r-- | gas/config.in | 3 | ||||
-rwxr-xr-x | gas/configure | 92 | ||||
-rw-r--r-- | gas/configure.in | 3 | ||||
-rw-r--r-- | gas/write.c | 196 |
9 files changed, 339 insertions, 11 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog index 86b3c35..50dd6c1 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,21 @@ +2010-07-03 Cary Coutant <ccoutant@google.com> + + * Makefile.am: Add compress-debug.c and compress-debug.h. + * Makefile.in: Regenerate. + * config.in: Add HAVE_ZLIB_H. + * configure.in: Check for zlib.h. + * configure: Regenerate. + + * as.c (parse_args): Add --compress-debug-sections and + --nocompress-debug-sections. + * as.h (flag_compress_debug): New variable. + * compress-debug.c: New file. + * compress-debug.h: New file. + * write.c: Include compress-debug.h. + (compress_frag): New function. + (compress_debug): New function. + (write_object_file): Compress debug sections if requested. + 2010-07-03 Andreas Schwab <schwab@linux-m68k.org> * config/tc-ppc.c (ppc_set_cpu): Cast PPC_OPCODE_xxx to ppc_cpu_t diff --git a/gas/Makefile.am b/gas/Makefile.am index d23b472..6971f73 100644 --- a/gas/Makefile.am +++ b/gas/Makefile.am @@ -43,6 +43,7 @@ GAS_CFILES = \ app.c \ as.c \ atof-generic.c \ + compress-debug.c \ cond.c \ depend.c \ dwarf2dbg.c \ @@ -78,6 +79,7 @@ HFILES = \ bignum.h \ bit_fix.h \ cgen.h \ + compress-debug.h \ dwarf2dbg.h \ dw2gencfi.h \ ecoff.h \ diff --git a/gas/Makefile.in b/gas/Makefile.in index 84e2f50..6793520 100644 --- a/gas/Makefile.in +++ b/gas/Makefile.in @@ -73,14 +73,14 @@ CONFIG_CLEAN_FILES = gdb.ini .gdbinit po/Makefile.in CONFIG_CLEAN_VPATH_FILES = PROGRAMS = $(noinst_PROGRAMS) am__objects_1 = app.$(OBJEXT) as.$(OBJEXT) atof-generic.$(OBJEXT) \ - cond.$(OBJEXT) depend.$(OBJEXT) dwarf2dbg.$(OBJEXT) \ - dw2gencfi.$(OBJEXT) ecoff.$(OBJEXT) ehopt.$(OBJEXT) \ - expr.$(OBJEXT) flonum-copy.$(OBJEXT) flonum-konst.$(OBJEXT) \ - flonum-mult.$(OBJEXT) frags.$(OBJEXT) hash.$(OBJEXT) \ - input-file.$(OBJEXT) input-scrub.$(OBJEXT) listing.$(OBJEXT) \ - literal.$(OBJEXT) macro.$(OBJEXT) messages.$(OBJEXT) \ - output-file.$(OBJEXT) read.$(OBJEXT) remap.$(OBJEXT) \ - sb.$(OBJEXT) stabs.$(OBJEXT) subsegs.$(OBJEXT) \ + compress-debug.$(OBJEXT) cond.$(OBJEXT) depend.$(OBJEXT) \ + dwarf2dbg.$(OBJEXT) dw2gencfi.$(OBJEXT) ecoff.$(OBJEXT) \ + ehopt.$(OBJEXT) expr.$(OBJEXT) flonum-copy.$(OBJEXT) \ + flonum-konst.$(OBJEXT) flonum-mult.$(OBJEXT) frags.$(OBJEXT) \ + hash.$(OBJEXT) input-file.$(OBJEXT) input-scrub.$(OBJEXT) \ + listing.$(OBJEXT) literal.$(OBJEXT) macro.$(OBJEXT) \ + messages.$(OBJEXT) output-file.$(OBJEXT) read.$(OBJEXT) \ + remap.$(OBJEXT) sb.$(OBJEXT) stabs.$(OBJEXT) subsegs.$(OBJEXT) \ symbols.$(OBJEXT) write.$(OBJEXT) am_as_new_OBJECTS = $(am__objects_1) as_new_OBJECTS = $(am_as_new_OBJECTS) @@ -311,6 +311,7 @@ GAS_CFILES = \ app.c \ as.c \ atof-generic.c \ + compress-debug.c \ cond.c \ depend.c \ dwarf2dbg.c \ @@ -345,6 +346,7 @@ HFILES = \ bignum.h \ bit_fix.h \ cgen.h \ + compress-debug.h \ dwarf2dbg.h \ dw2gencfi.h \ ecoff.h \ @@ -771,6 +773,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atof-vax.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bfin-parse.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cgen.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/compress-debug.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cond.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/depend.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dw2gencfi.Po@am__quote@ @@ -437,7 +437,9 @@ parse_args (int * pargc, char *** pargv) OPTION_AL, OPTION_HASH_TABLE_SIZE, OPTION_REDUCE_MEMORY_OVERHEADS, - OPTION_WARN_FATAL + OPTION_WARN_FATAL, + OPTION_COMPRESS_DEBUG, + OPTION_NOCOMPRESS_DEBUG /* When you add options here, check that they do not collide with OPTION_MD_BASE. See as.h. */ }; @@ -455,6 +457,8 @@ parse_args (int * pargc, char *** pargv) ,{"a", optional_argument, NULL, 'a'} /* Handle -al=<FILE>. */ ,{"al", optional_argument, NULL, OPTION_AL} + ,{"compress-debug-sections", no_argument, NULL, OPTION_COMPRESS_DEBUG} + ,{"nocompress-debug-sections", no_argument, NULL, OPTION_NOCOMPRESS_DEBUG} ,{"debug-prefix-map", required_argument, NULL, OPTION_DEBUG_PREFIX_MAP} ,{"defsym", required_argument, NULL, OPTION_DEFSYM} ,{"dump-config", no_argument, NULL, OPTION_DUMPCONFIG} @@ -634,6 +638,14 @@ This program has absolutely no warranty.\n")); #endif exit (EXIT_SUCCESS); + case OPTION_COMPRESS_DEBUG: + flag_compress_debug = 1; + break; + + case OPTION_NOCOMPRESS_DEBUG: + flag_compress_debug = 0; + break; + case OPTION_DEBUG_PREFIX_MAP: add_debug_prefix_map (optarg); break; @@ -365,6 +365,9 @@ COMMON int flag_strip_local_absolute; /* True if we should generate a traditional format object file. */ COMMON int flag_traditional_format; +/* TRUE if debug sections should be compressed. */ +COMMON int flag_compress_debug; + /* TRUE if .note.GNU-stack section with SEC_CODE should be created */ COMMON int flag_execstack; diff --git a/gas/config.in b/gas/config.in index 55f4c9c..c63b1c6 100644 --- a/gas/config.in +++ b/gas/config.in @@ -114,6 +114,9 @@ /* Define to 1 if you have the `unlink' function. */ #undef HAVE_UNLINK +/* Define to 1 if you have the <zlib.h> header file. */ +#undef HAVE_ZLIB_H + /* Using i386 COFF? */ #undef I386COFF diff --git a/gas/configure b/gas/configure index b466d5f..530fa0d 100755 --- a/gas/configure +++ b/gas/configure @@ -766,6 +766,7 @@ enable_werror enable_build_warnings enable_nls enable_maintainer_mode +with_zlib ' ac_precious_vars='build_alias host_alias @@ -1419,6 +1420,7 @@ Optional Packages: --with-pic try to use only PIC/non-PIC objects [default=use both] --with-gnu-ld assume the C compiler uses GNU ld [default=no] + --with-zlib include zlib support (auto/yes/no) default=auto Some influential environment variables: CC C compiler command @@ -11193,7 +11195,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11196 "configure" +#line 11198 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11299,7 +11301,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11302 "configure" +#line 11304 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -13984,6 +13986,92 @@ $as_echo "#define USE_BINARY_FOPEN 1" >>confdefs.h ;; esac +# Link in zlib if we can. This allows us to write compressed debug sections. + + # See if the user specified whether he wants zlib support or not. + +# Check whether --with-zlib was given. +if test "${with_zlib+set}" = set; then : + withval=$with_zlib; +else + with_zlib=auto +fi + + + if test "$with_zlib" != "no"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing zlibVersion" >&5 +$as_echo_n "checking for library containing zlibVersion... " >&6; } +if test "${ac_cv_search_zlibVersion+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_func_search_save_LIBS=$LIBS +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char zlibVersion (); +int +main () +{ +return zlibVersion (); + ; + return 0; +} +_ACEOF +for ac_lib in '' z; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_zlibVersion=$ac_res +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext + if test "${ac_cv_search_zlibVersion+set}" = set; then : + break +fi +done +if test "${ac_cv_search_zlibVersion+set}" = set; then : + +else + ac_cv_search_zlibVersion=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_zlibVersion" >&5 +$as_echo "$ac_cv_search_zlibVersion" >&6; } +ac_res=$ac_cv_search_zlibVersion +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + for ac_header in zlib.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "zlib.h" "ac_cv_header_zlib_h" "$ac_includes_default" +if test "x$ac_cv_header_zlib_h" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_ZLIB_H 1 +_ACEOF + +fi + +done + +fi + + if test "$with_zlib" = "yes" -a "$ac_cv_header_zlib_h" != "yes"; then + as_fn_error "zlib (libz) library was explicitly requested but not found" "$LINENO" 5 + fi + fi + + # Support for VMS timestamps via cross compile if test "$ac_cv_header_time_h" = yes; then diff --git a/gas/configure.in b/gas/configure.in index 4fbf292..0d5e3e1 100644 --- a/gas/configure.in +++ b/gas/configure.in @@ -709,6 +709,9 @@ AC_CHECK_DECLS([vsnprintf]) BFD_BINARY_FOPEN +# Link in zlib if we can. This allows us to write compressed debug sections. +AM_ZLIB + # Support for VMS timestamps via cross compile if test "$ac_cv_header_time_h" = yes; then diff --git a/gas/write.c b/gas/write.c index a148b24..71ac635 100644 --- a/gas/write.c +++ b/gas/write.c @@ -28,6 +28,7 @@ #include "output-file.h" #include "dwarf2dbg.h" #include "libbfd.h" +#include "compress-debug.h" #ifndef TC_ADJUST_RELOC_COUNT #define TC_ADJUST_RELOC_COUNT(FIX, COUNT) @@ -1288,6 +1289,194 @@ write_relocs (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED) #endif } +static int +compress_frag (struct z_stream_s *strm, const char *contents, int in_size, + fragS **last_newf, struct obstack *ob) +{ + int out_size; + int total_out_size = 0; + fragS *f = *last_newf; + char *next_out; + int avail_out; + + /* Call the compression routine repeatedly until it has finished + processing the frag. */ + while (in_size > 0) + { + /* Reserve all the space available in the current chunk. + If none is available, start a new frag. */ + avail_out = obstack_room (ob); + if (avail_out <= 0) + { + obstack_finish (ob); + f = frag_alloc (ob); + f->fr_type = rs_fill; + (*last_newf)->fr_next = f; + *last_newf = f; + avail_out = obstack_room (ob); + } + if (avail_out <= 0) + as_fatal (_("can't extend frag")); + next_out = obstack_next_free (ob); + obstack_blank_fast (ob, avail_out); + out_size = compress_data (strm, &contents, &in_size, + &next_out, &avail_out); + if (out_size < 0) + return -1; + + f->fr_fix += out_size; + total_out_size += out_size; + + /* Return unused space. */ + if (avail_out > 0) + obstack_blank_fast (ob, -avail_out); + } + + return total_out_size; +} + +static void +compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED) +{ + segment_info_type *seginfo = seg_info (sec); + fragS *f; + fragS *first_newf; + fragS *last_newf; + struct obstack *ob = &seginfo->frchainP->frch_obstack; + bfd_size_type uncompressed_size = (bfd_size_type) sec->size; + bfd_size_type compressed_size; + const char *section_name; + char *compressed_name; + char *header; + struct z_stream_s *strm; + int x; + + if (seginfo == NULL + || !(bfd_get_section_flags (abfd, sec) & SEC_HAS_CONTENTS) + || (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)) + return; + + section_name = bfd_get_section_name (stdoutput, sec); + if (strncmp (section_name, ".debug_", 7) != 0) + return; + + strm = compress_init (); + if (strm == NULL) + return; + + /* Create a new frag to contain the "ZLIB" header. */ + first_newf = frag_alloc (ob); + if (obstack_room (ob) < 12) + first_newf = frag_alloc (ob); + if (obstack_room (ob) < 12) + as_fatal (_("can't extend frag %u chars"), 12); + last_newf = first_newf; + obstack_blank_fast (ob, 12); + last_newf->fr_type = rs_fill; + last_newf->fr_fix = 12; + header = last_newf->fr_literal; + memcpy (header, "ZLIB", 4); + header[11] = uncompressed_size; uncompressed_size >>= 8; + header[10] = uncompressed_size; uncompressed_size >>= 8; + header[9] = uncompressed_size; uncompressed_size >>= 8; + header[8] = uncompressed_size; uncompressed_size >>= 8; + header[7] = uncompressed_size; uncompressed_size >>= 8; + header[6] = uncompressed_size; uncompressed_size >>= 8; + header[5] = uncompressed_size; uncompressed_size >>= 8; + header[4] = uncompressed_size; + compressed_size = 12; + + /* Stream the frags through the compression engine, adding new frags + as necessary to accomodate the compressed output. */ + for (f = seginfo->frchainP->frch_root; + f; + f = f->fr_next) + { + offsetT fill_size; + char *fill_literal; + offsetT count; + int out_size; + + gas_assert (f->fr_type == rs_fill); + if (f->fr_fix) + { + out_size = compress_frag (strm, f->fr_literal, f->fr_fix, + &last_newf, ob); + if (out_size < 0) + return; + compressed_size += out_size; + } + fill_literal = f->fr_literal + f->fr_fix; + fill_size = f->fr_var; + count = f->fr_offset; + gas_assert (count >= 0); + if (fill_size && count) + { + while (count--) + { + out_size = compress_frag (strm, fill_literal, (int) fill_size, + &last_newf, ob); + if (out_size < 0) + return; + compressed_size += out_size; + } + } + } + + /* Flush the compression state. */ + for (;;) + { + int avail_out; + char *next_out; + int out_size; + + /* Reserve all the space available in the current chunk. + If none is available, start a new frag. */ + avail_out = obstack_room (ob); + if (avail_out <= 0) + { + fragS *newf; + + obstack_finish (ob); + newf = frag_alloc (ob); + newf->fr_type = rs_fill; + last_newf->fr_next = newf; + last_newf = newf; + avail_out = obstack_room (ob); + } + if (avail_out <= 0) + as_fatal (_("can't extend frag")); + next_out = obstack_next_free (ob); + obstack_blank_fast (ob, avail_out); + x = compress_finish (strm, &next_out, &avail_out, &out_size); + if (x < 0) + return; + + last_newf->fr_fix += out_size; + compressed_size += out_size; + + /* Return unused space. */ + if (avail_out > 0) + obstack_blank_fast (ob, -avail_out); + + if (x == 0) + break; + } + + /* Replace the uncompressed frag list with the compressed frag list. */ + seginfo->frchainP->frch_root = first_newf; + seginfo->frchainP->frch_last = last_newf; + + /* Update the section size and its name. */ + x = bfd_set_section_size (abfd, sec, compressed_size); + gas_assert (x); + compressed_name = (char *) xmalloc (strlen (section_name) + 2); + compressed_name[0] = '.'; + compressed_name[1] = 'z'; + strcpy (compressed_name + 2, section_name + 1); + bfd_section_name (stdoutput, sec) = compressed_name; +} + static void write_contents (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, @@ -1912,6 +2101,13 @@ write_object_file (void) obj_frob_file_after_relocs (); #endif + /* Once all relocations have been written, we can compress the + contents of the debug sections. This needs to be done before + we start writing any sections, because it will affect the file + layout, which is fixed once we start writing contents. */ + if (flag_compress_debug) + bfd_map_over_sections (stdoutput, compress_debug, (char *) 0); + bfd_map_over_sections (stdoutput, write_contents, (char *) 0); } |