* compressed_output.h (class Output_compressed_section): Use
authorIan Lance Taylor <ian@airs.com>
Thu, 3 Apr 2008 14:18:37 +0000 (14:18 +0000)
committerIan Lance Taylor <ian@airs.com>
Thu, 3 Apr 2008 14:18:37 +0000 (14:18 +0000)
unsigned buffer.
* compressed_output.cc (zlib_compress): Use unsigned buffers,
add zlib header.
(zlib_compressed_suffix): Removed.
(Output_compressed_section::set_final_data_size): Use unsigned
buffers.
* testsuite/Makefile.am (flagstest_compress_debug_sections):
Fix linker invocation.
(flagstest_o_specialfile_and_compress_debug_sections):
Likewise.
* testsuite/Makefile.in: Regenerated.

gold/ChangeLog
gold/Makefile.in
gold/compressed_output.cc
gold/compressed_output.h
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in

index 53b055fd2f710f45fdb9f4e0b5c1edde56b7dbdd..ecd4e5582a1669c3eadeb5e85ba38422505dd0b9 100644 (file)
@@ -1,3 +1,18 @@
+2008-04-03  Craig Silverstein  <csilvers@google.com>
+
+       * compressed_output.h (class Output_compressed_section): Use
+       unsigned buffer.
+       * compressed_output.cc (zlib_compress): Use unsigned buffers,
+       add zlib header.
+       (zlib_compressed_suffix): Removed.
+       (Output_compressed_section::set_final_data_size): Use unsigned
+       buffers.
+       * testsuite/Makefile.am (flagstest_compress_debug_sections):
+       Fix linker invocation.
+       (flagstest_o_specialfile_and_compress_debug_sections):
+       Likewise.
+       * testsuite/Makefile.in: Regenerated.
+
 2008-04-02  David S. Miller  <davem@davemloft.net>
 
        *  dwarf_reader.cc (Sized_dwarf_line_info::read_header_prolog,
index 127888fd738f393c90067a225b40aee976e43a06..55adee1ee8d897d51de237cdd78b83d92fc3ec2f 100644 (file)
@@ -50,7 +50,7 @@ DIST_COMMON = README $(am__configure_deps) $(srcdir)/../config.guess \
        $(srcdir)/../mkinstalldirs $(srcdir)/Makefile.am \
        $(srcdir)/Makefile.in $(srcdir)/config.in \
        $(top_srcdir)/configure $(top_srcdir)/po/Make-in ChangeLog \
-       NEWS pread.c yyscript.c yyscript.h
+       NEWS TODO pread.c yyscript.c yyscript.h
 subdir = .
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
index c7452333607af04f9fc24e96e3f52a47f91e4782..a0f8ed181ace455f9db37188f9fa3a1822561ed4 100644 (file)
@@ -38,15 +38,21 @@ namespace gold
 // (including not having zlib support in the library).  If it returns
 // true, it allocates memory for the compressed data using new, and
 // sets *COMPRESSED_DATA and *COMPRESSED_SIZE to appropriate values.
+// It also writes a header before COMPRESSED_DATA: 4 bytes saying
+// "ZLIB", and 8 bytes indicating the uncompressed size, in big-endian
+// order.
 
 #ifdef HAVE_ZLIB_H
 
 static bool
-zlib_compress(const char* uncompressed_data, unsigned long uncompressed_size,
-              char** compressed_data, unsigned long* compressed_size)
+zlib_compress(const unsigned char* uncompressed_data,
+              unsigned long uncompressed_size,
+              unsigned char** compressed_data,
+              unsigned long* compressed_size)
 {
+  const int header_size = 12;
   *compressed_size = uncompressed_size + uncompressed_size / 1000 + 128;
-  *compressed_data = new char[*compressed_size];
+  *compressed_data = new unsigned char[*compressed_size + header_size];
 
   int compress_level;
   if (parameters->options().optimize() >= 1)
@@ -54,13 +60,19 @@ zlib_compress(const char* uncompressed_data, unsigned long uncompressed_size,
   else
     compress_level = 1;
 
-  int rc = compress2(reinterpret_cast<Bytef*>(*compressed_data),
+  int rc = compress2(reinterpret_cast<Bytef*>(*compressed_data) + header_size,
                      compressed_size,
                      reinterpret_cast<const Bytef*>(uncompressed_data),
                      uncompressed_size,
                      compress_level);
   if (rc == Z_OK)
-    return true;
+    {
+      memcpy(*compressed_data, "ZLIB", 4);
+      elfcpp::Swap_unaligned<64, true>::writeval(*compressed_data + 4,
+                                                uncompressed_size);
+      *compressed_size += header_size;
+      return true;
+    }
   else
     {
       delete[] *compressed_data;
@@ -72,24 +84,14 @@ zlib_compress(const char* uncompressed_data, unsigned long uncompressed_size,
 #else // !defined(HAVE_ZLIB_H)
 
 static bool
-zlib_compress(const char*, unsigned long, char**, unsigned long*)
+zlib_compress(const unsigned char*, unsigned long,
+              unsigned char**, unsigned long*)
 {
   return false;
 }
 
 #endif // !defined(HAVE_ZLIB_H)
 
-// After compressing an output section, we rename it from foo to
-// foo.zlib.nnnn, where nnnn is the uncompressed size of the section.
-
-static std::string
-zlib_compressed_suffix(unsigned long uncompressed_size)
-{
-  char size_string[64];
-  snprintf(size_string, sizeof(size_string), "%lu", uncompressed_size);
-  return std::string(".zlib.") + size_string;
-}
-
 // Class Output_compressed_section.
 
 // Set the final data size of a compressed section.  This is where
@@ -102,8 +104,7 @@ Output_compressed_section::set_final_data_size()
 
   // (Try to) compress the data.
   unsigned long compressed_size;
-  unsigned char* u_uncompressed_data = this->postprocessing_buffer();
-  char* uncompressed_data = reinterpret_cast<char*>(u_uncompressed_data);
+  unsigned char* uncompressed_data = this->postprocessing_buffer();
 
   // At this point the contents of all regular input sections will
   // have been copied into the postprocessing buffer, and relocations
@@ -117,8 +118,8 @@ Output_compressed_section::set_final_data_size()
                             &this->data_, &compressed_size);
   if (success)
     {
-      std::string suffix(zlib_compressed_suffix(uncompressed_size));
-      this->new_section_name_ = std::string(this->name()) + suffix;
+      // This converts .debug_foo to .zdebug_foo
+      this->new_section_name_ = std::string(".z") + (this->name() + 1);
       this->set_name(this->new_section_name_.c_str());
       this->set_data_size(compressed_size);
     }
index 300b064c33740037565c7e678b6bc3ac74dc58f6..11b2762288f58b09b69b6de81ba7686a3657f250 100644 (file)
@@ -64,7 +64,7 @@ class Output_compressed_section : public Output_section
   // The options--this includes the compression type.
   const General_options* options_;
   // The compressed data.
-  char* data_;
+  unsigned char* data_;
   // The new section name if we do compress.
   std::string new_section_name_;
 };
index 70b3e15dda77263c4b128d074c1e260932d02751..d478ed45d202c45ab18f347e12b301103e24814c 100644 (file)
@@ -507,7 +507,7 @@ undef_symbol.err: undef_symbol_main.o undef_symbol.so gcctestdir/ld
 # Test --compress-debug-sections.  FIXME: check we actually compress.
 check_PROGRAMS += flagstest_compress_debug_sections
 flagstest_compress_debug_sections: flagstest_debug.o gcctestdir/ld
-       $(CXXLINK) -Bgcctestdir/ -o $@ $< --compress-debug-sections=zlib
+       $(CXXLINK) -Bgcctestdir/ -o $@ $< -Wl,--compress-debug-sections=zlib
        test -s $@
 
 
@@ -523,7 +523,7 @@ flagstest_o_specialfile: flagstest_debug.o gcctestdir/ld
 check_PROGRAMS += flagstest_o_specialfile_and_compress_debug_sections
 flagstest_o_specialfile_and_compress_debug_sections: flagstest_debug.o \
                gcctestdir/ld
-       $(CXXLINK) -Bgcctestdir/ -o /dev/stdout $< --compress-debug-sections=zlib 2>&1 | cat > $@
+       $(CXXLINK) -Bgcctestdir/ -o /dev/stdout $< -Wl,--compress-debug-sections=zlib 2>&1 | cat > $@
        chmod a+x $@
        test -s $@
 
index c0eefbb48b7c1309c6ff1decb2d60dc9bbda95e2..dfa6bfb259d14af4a766b52187ef424279e00bf3 100644 (file)
@@ -1813,7 +1813,7 @@ uninstall-am: uninstall-info-am
 @GCC_TRUE@@NATIVE_LINKER_TRUE@   exit 1; \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ fi
 @GCC_TRUE@@NATIVE_LINKER_TRUE@flagstest_compress_debug_sections: flagstest_debug.o gcctestdir/ld
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -o $@ $< --compress-debug-sections=zlib
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -o $@ $< -Wl,--compress-debug-sections=zlib
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ test -s $@
 @GCC_TRUE@@NATIVE_LINKER_TRUE@flagstest_o_specialfile: flagstest_debug.o gcctestdir/ld
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -o /dev/stdout $< 2>&1 | cat > $@
@@ -1821,7 +1821,7 @@ uninstall-am: uninstall-info-am
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ test -s $@
 @GCC_TRUE@@NATIVE_LINKER_TRUE@flagstest_o_specialfile_and_compress_debug_sections: flagstest_debug.o \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@         gcctestdir/ld
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -o /dev/stdout $< --compress-debug-sections=zlib 2>&1 | cat > $@
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -o /dev/stdout $< -Wl,--compress-debug-sections=zlib 2>&1 | cat > $@
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ chmod a+x $@
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ test -s $@
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_1.so: ver_test_1.o ver_test_2.so ver_test_3.o ver_test_4.so gcctestdir/ld