1 // compressed_output.h -- compressed output sections for gold -*- C++ -*-
3 // Copyright 2007 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
23 // We support compressing .debug_* sections on output. (And,
24 // potentially one day, other sections.) This is a form of
25 // relaxation. This file adds support for merging and emitting the
26 // compressed sections.
28 #ifndef GOLD_COMPRESSED_OUTPUT_H
29 #define GOLD_COMPRESSED_OUTPUT_H
40 class General_options
;
42 // This is used for compressing a section before emitting it in the
43 // output file. This only works for unloaded sections, since it
44 // assumes the final section contents are available at
45 // set_final_data_size() time. For loaded sections (those that end up
46 // in segments), this is not true; relocations are applied after
47 // set_final_data_size() is called. However, for unloaded sections,
48 // we can -- and do -- postpone calling finalize_data_size() until
49 // after relocations are applies.
51 class Output_compressed_section_data
: public Output_section_data
54 Output_compressed_section_data(uint64_t addralign
,
55 const General_options
& options
)
56 : Output_section_data(addralign
), options_(options
), data_(NULL
)
60 // Add an input section.
62 do_add_input_section(Relobj
* object
, unsigned int shndx
);
64 // Set the final data size.
66 set_final_data_size();
68 // Change the name of the output section to reflect it's compressed.
70 do_modified_output_section_name(const char* name
);
72 // Write the data to the file.
74 do_write(Output_file
*);
81 const unsigned char* contents
;
84 Object_entry(Relobj
* o
, unsigned int s
)
85 : object(o
), shndx(s
), contents(NULL
), length(0)
89 const General_options
& options_
;
90 std::vector
<Object_entry
> objects_
;
92 std::string new_section_name_
;
95 // This is a special case for when the output section is a string
96 // section and does not have any relocations to apply to it.
98 template<typename Char_type
>
99 class Output_compressed_string
: public Output_merge_string
<Char_type
>
102 Output_compressed_string(uint64_t addralign
,
103 const General_options
& options
)
104 : Output_merge_string
<Char_type
>(addralign
),
105 options_(options
), compressed_data_(NULL
)
108 ~Output_compressed_string()
109 { delete[] compressed_data_
; }
112 // Add an input section.
114 do_add_input_section(Relobj
* object
, unsigned int shndx
);
116 // Set the final data size. Also compresses the buffer.
118 set_final_data_size();
120 // Change the name of the output section to reflect it's compressed.
122 do_modified_output_section_name(const char* name
);
124 // Write the data to the file.
126 do_write(Output_file
*);
129 const General_options
& options_
;
130 char* compressed_data_
;
131 // This is just a buffer to store the section name in "permanent" storage.
132 std::string new_section_name_
;
135 } // End namespace gold.
137 #endif // !defined(GOLD_COMPRESSED_OUTPUT_H)