xref: /netbsd-src/external/gpl3/binutils/dist/gold/compressed_output.h (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
12a6b7db3Sskrll // compressed_output.h -- compressed output sections for gold  -*- C++ -*-
22a6b7db3Sskrll 
3*cb63e24eSchristos // Copyright (C) 2007-2024 Free Software Foundation, Inc.
42a6b7db3Sskrll // Written by Ian Lance Taylor <iant@google.com>.
52a6b7db3Sskrll 
62a6b7db3Sskrll // This file is part of gold.
72a6b7db3Sskrll 
82a6b7db3Sskrll // This program is free software; you can redistribute it and/or modify
92a6b7db3Sskrll // it under the terms of the GNU General Public License as published by
102a6b7db3Sskrll // the Free Software Foundation; either version 3 of the License, or
112a6b7db3Sskrll // (at your option) any later version.
122a6b7db3Sskrll 
132a6b7db3Sskrll // This program is distributed in the hope that it will be useful,
142a6b7db3Sskrll // but WITHOUT ANY WARRANTY; without even the implied warranty of
152a6b7db3Sskrll // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
162a6b7db3Sskrll // GNU General Public License for more details.
172a6b7db3Sskrll 
182a6b7db3Sskrll // You should have received a copy of the GNU General Public License
192a6b7db3Sskrll // along with this program; if not, write to the Free Software
202a6b7db3Sskrll // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
212a6b7db3Sskrll // MA 02110-1301, USA.
222a6b7db3Sskrll 
232a6b7db3Sskrll // We support compressing .debug_* sections on output.  (And,
242a6b7db3Sskrll // potentially one day, other sections.)  This is a form of
252a6b7db3Sskrll // relaxation.  This file adds support for merging and emitting the
262a6b7db3Sskrll // compressed sections.
272a6b7db3Sskrll 
282a6b7db3Sskrll #ifndef GOLD_COMPRESSED_OUTPUT_H
292a6b7db3Sskrll #define GOLD_COMPRESSED_OUTPUT_H
302a6b7db3Sskrll 
312a6b7db3Sskrll #include <string>
322a6b7db3Sskrll 
332a6b7db3Sskrll #include "output.h"
342a6b7db3Sskrll 
352a6b7db3Sskrll namespace gold
362a6b7db3Sskrll {
372a6b7db3Sskrll 
382a6b7db3Sskrll class General_options;
392a6b7db3Sskrll 
40be12b8bcSchristos // Read the compression header of a compressed debug section and return
41be12b8bcSchristos // the uncompressed size.
42be12b8bcSchristos 
43be12b8bcSchristos extern uint64_t
44be12b8bcSchristos get_uncompressed_size(const unsigned char*, section_size_type);
45be12b8bcSchristos 
46be12b8bcSchristos // Decompress a compressed debug section directly into the output file.
47be12b8bcSchristos 
48be12b8bcSchristos extern bool
49be12b8bcSchristos decompress_input_section(const unsigned char*, unsigned long, unsigned char*,
509573673dSchristos 			 unsigned long, int, bool, elfcpp::Elf_Xword);
51be12b8bcSchristos 
522a6b7db3Sskrll // This is used for a section whose data should be compressed.  It is
532a6b7db3Sskrll // a regular Output_section which computes its contents into a buffer
542a6b7db3Sskrll // and then postprocesses it.
552a6b7db3Sskrll 
562a6b7db3Sskrll class Output_compressed_section : public Output_section
572a6b7db3Sskrll {
582a6b7db3Sskrll  public:
Output_compressed_section(const General_options * options,const char * name,elfcpp::Elf_Word flags,elfcpp::Elf_Xword type)592a6b7db3Sskrll   Output_compressed_section(const General_options* options,
602a6b7db3Sskrll 			    const char* name, elfcpp::Elf_Word flags,
612a6b7db3Sskrll 			    elfcpp::Elf_Xword type)
622a6b7db3Sskrll     : Output_section(name, flags, type),
632a6b7db3Sskrll       options_(options)
642a6b7db3Sskrll   { this->set_requires_postprocessing(); }
652a6b7db3Sskrll 
662a6b7db3Sskrll  protected:
672a6b7db3Sskrll   // Set the final data size.
682a6b7db3Sskrll   void
692a6b7db3Sskrll   set_final_data_size();
702a6b7db3Sskrll 
712a6b7db3Sskrll   // Write out the compressed contents.
722a6b7db3Sskrll   void
732a6b7db3Sskrll   do_write(Output_file*);
742a6b7db3Sskrll 
752a6b7db3Sskrll  private:
762a6b7db3Sskrll   // The options--this includes the compression type.
772a6b7db3Sskrll   const General_options* options_;
782a6b7db3Sskrll   // The compressed data.
792a6b7db3Sskrll   unsigned char* data_;
802a6b7db3Sskrll   // The new section name if we do compress.
812a6b7db3Sskrll   std::string new_section_name_;
822a6b7db3Sskrll };
832a6b7db3Sskrll 
842a6b7db3Sskrll } // End namespace gold.
852a6b7db3Sskrll 
862a6b7db3Sskrll #endif // !defined(GOLD_COMPRESSED_OUTPUT_H)
87