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