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