xref: /netbsd-src/external/gpl3/binutils.old/dist/gold/compressed_output.h (revision e992f068c547fd6e84b3f104dc2340adcc955732)
175fd0b74Schristos // compressed_output.h -- compressed output sections for gold  -*- C++ -*-
275fd0b74Schristos 
3*e992f068Schristos // Copyright (C) 2007-2022 Free Software Foundation, Inc.
475fd0b74Schristos // Written by Ian Lance Taylor <iant@google.com>.
575fd0b74Schristos 
675fd0b74Schristos // This file is part of gold.
775fd0b74Schristos 
875fd0b74Schristos // This program is free software; you can redistribute it and/or modify
975fd0b74Schristos // it under the terms of the GNU General Public License as published by
1075fd0b74Schristos // the Free Software Foundation; either version 3 of the License, or
1175fd0b74Schristos // (at your option) any later version.
1275fd0b74Schristos 
1375fd0b74Schristos // This program is distributed in the hope that it will be useful,
1475fd0b74Schristos // but WITHOUT ANY WARRANTY; without even the implied warranty of
1575fd0b74Schristos // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1675fd0b74Schristos // GNU General Public License for more details.
1775fd0b74Schristos 
1875fd0b74Schristos // You should have received a copy of the GNU General Public License
1975fd0b74Schristos // along with this program; if not, write to the Free Software
2075fd0b74Schristos // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
2175fd0b74Schristos // MA 02110-1301, USA.
2275fd0b74Schristos 
2375fd0b74Schristos // We support compressing .debug_* sections on output.  (And,
2475fd0b74Schristos // potentially one day, other sections.)  This is a form of
2575fd0b74Schristos // relaxation.  This file adds support for merging and emitting the
2675fd0b74Schristos // compressed sections.
2775fd0b74Schristos 
2875fd0b74Schristos #ifndef GOLD_COMPRESSED_OUTPUT_H
2975fd0b74Schristos #define GOLD_COMPRESSED_OUTPUT_H
3075fd0b74Schristos 
3175fd0b74Schristos #include <string>
3275fd0b74Schristos 
3375fd0b74Schristos #include "output.h"
3475fd0b74Schristos 
3575fd0b74Schristos namespace gold
3675fd0b74Schristos {
3775fd0b74Schristos 
3875fd0b74Schristos class General_options;
3975fd0b74Schristos 
4075fd0b74Schristos // Read the compression header of a compressed debug section and return
4175fd0b74Schristos // the uncompressed size.
4275fd0b74Schristos 
4375fd0b74Schristos extern uint64_t
4475fd0b74Schristos get_uncompressed_size(const unsigned char*, section_size_type);
4575fd0b74Schristos 
4675fd0b74Schristos // Decompress a compressed debug section directly into the output file.
4775fd0b74Schristos 
4875fd0b74Schristos extern bool
4975fd0b74Schristos decompress_input_section(const unsigned char*, unsigned long, unsigned char*,
5075fd0b74Schristos 			 unsigned long, int, bool, elfcpp::Elf_Xword);
5175fd0b74Schristos 
5275fd0b74Schristos // This is used for a section whose data should be compressed.  It is
5375fd0b74Schristos // a regular Output_section which computes its contents into a buffer
5475fd0b74Schristos // and then postprocesses it.
5575fd0b74Schristos 
5675fd0b74Schristos class Output_compressed_section : public Output_section
5775fd0b74Schristos {
5875fd0b74Schristos  public:
Output_compressed_section(const General_options * options,const char * name,elfcpp::Elf_Word flags,elfcpp::Elf_Xword type)5975fd0b74Schristos   Output_compressed_section(const General_options* options,
6075fd0b74Schristos 			    const char* name, elfcpp::Elf_Word flags,
6175fd0b74Schristos 			    elfcpp::Elf_Xword type)
6275fd0b74Schristos     : Output_section(name, flags, type),
6375fd0b74Schristos       options_(options)
6475fd0b74Schristos   { this->set_requires_postprocessing(); }
6575fd0b74Schristos 
6675fd0b74Schristos  protected:
6775fd0b74Schristos   // Set the final data size.
6875fd0b74Schristos   void
6975fd0b74Schristos   set_final_data_size();
7075fd0b74Schristos 
7175fd0b74Schristos   // Write out the compressed contents.
7275fd0b74Schristos   void
7375fd0b74Schristos   do_write(Output_file*);
7475fd0b74Schristos 
7575fd0b74Schristos  private:
7675fd0b74Schristos   // The options--this includes the compression type.
7775fd0b74Schristos   const General_options* options_;
7875fd0b74Schristos   // The compressed data.
7975fd0b74Schristos   unsigned char* data_;
8075fd0b74Schristos   // The new section name if we do compress.
8175fd0b74Schristos   std::string new_section_name_;
8275fd0b74Schristos };
8375fd0b74Schristos 
8475fd0b74Schristos } // End namespace gold.
8575fd0b74Schristos 
8675fd0b74Schristos #endif // !defined(GOLD_COMPRESSED_OUTPUT_H)
87