compressed_output.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // compressed_output.h -- compressed output sections for gold -*- C++ -*-
  2. // Copyright (C) 2007-2015 Free Software Foundation, Inc.
  3. // Written by Ian Lance Taylor <iant@google.com>.
  4. // This file is part of gold.
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 3 of the License, or
  8. // (at your option) any later version.
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. // MA 02110-1301, USA.
  17. // We support compressing .debug_* sections on output. (And,
  18. // potentially one day, other sections.) This is a form of
  19. // relaxation. This file adds support for merging and emitting the
  20. // compressed sections.
  21. #ifndef GOLD_COMPRESSED_OUTPUT_H
  22. #define GOLD_COMPRESSED_OUTPUT_H
  23. #include <string>
  24. #include "output.h"
  25. namespace gold
  26. {
  27. class General_options;
  28. // Read the compression header of a compressed debug section and return
  29. // the uncompressed size.
  30. extern uint64_t
  31. get_uncompressed_size(const unsigned char*, section_size_type);
  32. // Decompress a compressed debug section directly into the output file.
  33. extern bool
  34. decompress_input_section(const unsigned char*, unsigned long, unsigned char*,
  35. unsigned long, int, bool, elfcpp::Elf_Xword);
  36. // This is used for a section whose data should be compressed. It is
  37. // a regular Output_section which computes its contents into a buffer
  38. // and then postprocesses it.
  39. class Output_compressed_section : public Output_section
  40. {
  41. public:
  42. Output_compressed_section(const General_options* options,
  43. const char* name, elfcpp::Elf_Word flags,
  44. elfcpp::Elf_Xword type)
  45. : Output_section(name, flags, type),
  46. options_(options)
  47. { this->set_requires_postprocessing(); }
  48. protected:
  49. // Set the final data size.
  50. void
  51. set_final_data_size();
  52. // Write out the compressed contents.
  53. void
  54. do_write(Output_file*);
  55. private:
  56. // The options--this includes the compression type.
  57. const General_options* options_;
  58. // The compressed data.
  59. unsigned char* data_;
  60. // The new section name if we do compress.
  61. std::string new_section_name_;
  62. };
  63. } // End namespace gold.
  64. #endif // !defined(GOLD_COMPRESSED_OUTPUT_H)