1 // binary.h -- binary input files for gold -*- C++ -*-
3 // Copyright (C) 2008-2019 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 // Support binary input files by making them look like an ELF file.
37 template<typename Stringpool_char
>
38 class Stringpool_template
;
40 // This class takes a file name and creates a buffer which looks like
41 // an ELF file read into memory.
46 Binary_to_elf(elfcpp::EM machine
, int size
, bool big_endian
,
47 const std::string
& filename
);
51 // Read contents and create an ELF buffer. Return true if this
52 // succeeds, false otherwise.
56 // Return a pointer to the contents of the ELF file.
58 converted_data() const
59 { return this->data_
; }
61 // Return a pointer to the contents of the ELF file and let the
62 // caller take charge of it. It was allocated using new[].
66 unsigned char* ret
= this->data_
;
71 // Return the size of the ELF file.
73 converted_size() const
74 { return this->filesize_
; }
77 Binary_to_elf(const Binary_to_elf
&);
78 Binary_to_elf
& operator=(const Binary_to_elf
&);
80 template<int size
, bool big_endian
>
82 sized_convert(const Task
*);
84 template<int size
, bool big_endian
>
86 write_file_header(unsigned char**);
88 template<int size
, bool big_endian
>
90 write_section_header(const char*, const Stringpool_template
<char>*,
91 elfcpp::SHT
, unsigned int, section_size_type
,
92 section_size_type
, unsigned int, unsigned int,
93 unsigned int, unsigned int, unsigned char**);
95 template<int size
, bool big_endian
>
97 write_symbol(const std::string
&, const Stringpool_template
<char>*,
98 section_size_type
, typename
elfcpp::Elf_types
<32>::Elf_WXword
,
99 unsigned int, unsigned char**);
101 // The ELF machine code of the file to create.
102 elfcpp::EM elf_machine_
;
103 // The size of the file to create, 32 or 64.
105 // Whether to create a big endian file.
107 // The name of the file to read.
108 std::string filename_
;
109 // The ELF file data, allocated by new [].
110 unsigned char* data_
;
111 // The ELF file size.
112 section_size_type filesize_
;
115 } // End namespace gold.
117 #endif // !defined(GOLD_BINARY_H)