* elflink.c (bfd_elf_final_link): Move code reading relocs to..
[binutils.git] / gold / binary.h
blob75bc731e29854a479cdfc2d94020207376d196ce
1 // binary.h -- binary input files for gold -*- C++ -*-
3 // Copyright 2008 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.
25 #ifndef GOLD_BINARY_H
26 #define GOLD_BINARY_H
28 #include <string>
30 #include "elfcpp.h"
32 namespace gold
35 class Task;
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.
43 class Binary_to_elf
45 public:
46 Binary_to_elf(elfcpp::EM machine, int size, bool big_endian,
47 const std::string& filename);
49 ~Binary_to_elf();
51 // Read contents and create an ELF buffer. Return true if this
52 // succeeds, false otherwise.
53 bool
54 convert(const Task*);
56 // Return a pointer to the contents of the ELF file.
57 const unsigned char*
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[].
63 unsigned char*
64 converted_data_leak()
66 unsigned char* ret = this->data_;
67 this->data_ = NULL;
68 return ret;
71 // Return the size of the ELF file.
72 size_t
73 converted_size() const
74 { return this->filesize_; }
76 private:
77 Binary_to_elf(const Binary_to_elf&);
78 Binary_to_elf& operator=(const Binary_to_elf&);
80 template<int size, bool big_endian>
81 bool
82 sized_convert(const Task*);
84 template<int size, bool big_endian>
85 void
86 write_file_header(unsigned char**);
88 template<int size, bool big_endian>
89 void
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>
96 void
97 write_symbol(const std::string&, const Stringpool_template<char>*,
98 section_size_type, unsigned int, unsigned char**);
100 // The ELF machine code of the file to create.
101 elfcpp::EM elf_machine_;
102 // The size of the file to create, 32 or 64.
103 int size_;
104 // Whether to create a big endian file.
105 bool big_endian_;
106 // The name of the file to read.
107 std::string filename_;
108 // The ELF file data, allocated by new [].
109 unsigned char* data_;
110 // The ELF file size.
111 section_size_type filesize_;
114 } // End namespace gold.
116 #endif // !defined(GOLD_BINARY_H)