Add licensing text to every source file.
[binutils.git] / gold / testsuite / testfile.cc
blobbb2da76b1127b08e32740b13aedeefdd2c590f15
1 // testfile.cc -- Dummy ELF objects for testing purposes.
3 // Copyright 2006, 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 #include "gold.h"
25 #include "target.h"
26 #include "target-select.h"
28 #include "test.h"
29 #include "testfile.h"
31 namespace gold_testsuite
34 using namespace gold;
36 // A Target used for testing purposes.
38 class Target_test : public Sized_target<32, false>
40 public:
41 Target_test()
42 : Sized_target<32, false>(&test_target_info)
43 { }
45 void
46 scan_relocs(const General_options&, Symbol_table*, Layout*,
47 Sized_relobj<32, false>*, unsigned int, unsigned int,
48 const unsigned char*, size_t, size_t, const unsigned char*,
49 Symbol**)
50 { ERROR("call to Target_test::scan_relocs"); }
52 void
53 relocate_section(const Relocate_info<32, false>*, unsigned int,
54 const unsigned char*, size_t, unsigned char*,
55 elfcpp::Elf_types<32>::Elf_Addr, off_t)
56 { ERROR("call to Target_test::relocate_section"); }
58 static const Target::Target_info test_target_info;
61 const Target::Target_info Target_test::test_target_info =
63 32, // size
64 false, // is_big_endian
65 static_cast<elfcpp::EM>(0xffff), // machine_code
66 false, // has_make_symbol
67 false, // has_resolve
68 false, // has_code_fill
69 "/dummy", // dynamic_linker
70 0x08000000, // text_segment_address
71 0x1000, // abi_pagesize
72 0x1000 // common_pagesize
75 // The single test target.
77 Target_test target_test;
79 // A pointer to the test target. This is used in CHECKs.
81 Target* target_test_pointer = &target_test;
83 // Select the test target.
85 class Target_selector_test : public Target_selector
87 public:
88 Target_selector_test()
89 : Target_selector(0xffff, 32, false)
90 { }
92 Target*
93 recognize(int, int, int)
94 { return &target_test; }
97 // Register the test target selector.
99 Target_selector_test target_selector_test;
101 // A simple ELF object with one empty section, named ".test" and one
102 // globally visible symbol named "test".
104 const unsigned char test_file_1[] =
106 // Ehdr
107 // EI_MAG[0-3]
108 0x7f, 'E', 'L', 'F',
109 // EI_CLASS: 32 bit.
111 // EI_DATA: little endian
113 // EI_VERSION
115 // EI_OSABI
117 // EI_ABIVERSION
119 // EI_PAD
120 0, 0, 0, 0, 0, 0, 0,
121 // e_type: ET_REL
122 1, 0,
123 // e_machine: a magic value used for testing.
124 0xff, 0xff,
125 // e_version
126 1, 0, 0, 0,
127 // e_entry
128 0, 0, 0, 0,
129 // e_phoff
130 0, 0, 0, 0,
131 // e_shoff: starts right after file header
132 52, 0, 0, 0,
133 // e_flags
134 0, 0, 0, 0,
135 // e_ehsize
136 52, 0,
137 // e_phentsize
138 32, 0,
139 // e_phnum
140 0, 0,
141 // e_shentsize
142 40, 0,
143 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
144 5, 0,
145 // e_shstrndx
146 4, 0,
148 // Offset 52
149 // Shdr 0: dummy entry
150 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
151 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
152 0, 0, 0, 0, 0, 0, 0, 0,
154 // Offset 92
155 // Shdr 1: .test
156 // sh_name: after initial null
157 1, 0, 0, 0,
158 // sh_type: SHT_PROGBITS
159 1, 0, 0, 0,
160 // sh_flags: SHF_ALLOC
161 2, 0, 0, 0,
162 // sh_addr
163 0, 0, 0, 0,
164 // sh_offset: after file header + 5 section headers
165 252, 0, 0, 0,
166 // sh_size
167 0, 0, 0, 0,
168 // sh_link
169 0, 0, 0, 0,
170 // sh_info
171 0, 0, 0, 0,
172 // sh_addralign
173 1, 0, 0, 0,
174 // sh_entsize
175 0, 0, 0, 0,
177 // Offset 132
178 // Shdr 2: .symtab
179 // sh_name: 1 null byte + ".test\0"
180 7, 0, 0, 0,
181 // sh_type: SHT_SYMTAB
182 2, 0, 0, 0,
183 // sh_flags
184 0, 0, 0, 0,
185 // sh_addr
186 0, 0, 0, 0,
187 // sh_offset: after file header + 5 section headers + empty section
188 252, 0, 0, 0,
189 // sh_size: two symbols: dummy symbol + test symbol
190 32, 0, 0, 0,
191 // sh_link: to .strtab
192 3, 0, 0, 0,
193 // sh_info: one local symbol, the dummy symbol
194 1, 0, 0, 0,
195 // sh_addralign
196 4, 0, 0, 0,
197 // sh_entsize: size of symbol
198 16, 0, 0, 0,
200 // Offset 172
201 // Shdr 3: .strtab
202 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
203 15, 0, 0, 0,
204 // sh_type: SHT_STRTAB
205 3, 0, 0, 0,
206 // sh_flags
207 0, 0, 0, 0,
208 // sh_addr
209 0, 0, 0, 0,
210 // sh_offset: after .symtab section. 284 == 0x11c
211 0x1c, 0x1, 0, 0,
212 // sh_size: 1 null byte + "test\0"
213 6, 0, 0, 0,
214 // sh_link
215 0, 0, 0, 0,
216 // sh_info
217 0, 0, 0, 0,
218 // sh_addralign
219 1, 0, 0, 0,
220 // sh_entsize
221 0, 0, 0, 0,
223 // Offset 212
224 // Shdr 4: .shstrtab
225 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
226 23, 0, 0, 0,
227 // sh_type: SHT_STRTAB
228 3, 0, 0, 0,
229 // sh_flags
230 0, 0, 0, 0,
231 // sh_addr
232 0, 0, 0, 0,
233 // sh_offset: after .strtab section. 290 == 0x122
234 0x22, 0x1, 0, 0,
235 // sh_size: all section names
236 33, 0, 0, 0,
237 // sh_link
238 0, 0, 0, 0,
239 // sh_info
240 0, 0, 0, 0,
241 // sh_addralign
242 1, 0, 0, 0,
243 // sh_entsize
244 0, 0, 0, 0,
246 // Offset 252
247 // Contents of .symtab section
248 // Symbol 0
249 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
251 // Offset 268
252 // Symbol 1
253 // st_name
254 1, 0, 0, 0,
255 // st_value
256 0, 0, 0, 0,
257 // st_size
258 0, 0, 0, 0,
259 // st_info: STT_NOTYPE, STB_GLOBAL
260 0x10,
261 // st_other
263 // st_shndx: In .test
264 1, 0,
266 // Offset 284
267 // Contents of .strtab section
268 '\0',
269 't', 'e', 's', 't', '\0',
271 // Offset 290
272 // Contents of .shstrtab section
273 '\0',
274 '.', 't', 'e', 's', 't', '\0',
275 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
276 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
277 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
280 const unsigned int test_file_1_size = sizeof test_file_1;
282 } // End namespace gold_testsuite.