Commit | Line | Data |
---|---|---|
5a6f7e2d ILT |
1 | // testfile.cc -- Dummy ELF objects for testing purposes. |
2 | ||
6cb15b7f ILT |
3 | // Copyright 2006, 2007 Free Software Foundation, Inc. |
4 | // Written by Ian Lance Taylor <iant@google.com>. | |
5 | ||
6 | // This file is part of gold. | |
7 | ||
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. | |
12 | ||
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. | |
17 | ||
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. | |
22 | ||
5a6f7e2d ILT |
23 | #include "gold.h" |
24 | ||
25 | #include "target.h" | |
26 | #include "target-select.h" | |
27 | ||
28 | #include "test.h" | |
29 | #include "testfile.h" | |
30 | ||
31 | namespace gold_testsuite | |
32 | { | |
33 | ||
34 | using namespace gold; | |
35 | ||
36 | // A Target used for testing purposes. | |
37 | ||
38 | class Target_test : public Sized_target<32, false> | |
39 | { | |
40 | public: | |
41 | Target_test() | |
42 | : Sized_target<32, false>(&test_target_info) | |
43 | { } | |
44 | ||
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"); } | |
51 | ||
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"); } | |
57 | ||
58 | static const Target::Target_info test_target_info; | |
59 | }; | |
60 | ||
61 | const Target::Target_info Target_test::test_target_info = | |
62 | { | |
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 | |
be9d5a93 | 68 | false, // has_code_fill |
5a6f7e2d ILT |
69 | "/dummy", // dynamic_linker |
70 | 0x08000000, // text_segment_address | |
71 | 0x1000, // abi_pagesize | |
72 | 0x1000 // common_pagesize | |
73 | }; | |
74 | ||
75 | // The single test target. | |
76 | ||
77 | Target_test target_test; | |
78 | ||
79 | // A pointer to the test target. This is used in CHECKs. | |
80 | ||
81 | Target* target_test_pointer = &target_test; | |
82 | ||
83 | // Select the test target. | |
84 | ||
85 | class Target_selector_test : public Target_selector | |
86 | { | |
87 | public: | |
88 | Target_selector_test() | |
89 | : Target_selector(0xffff, 32, false) | |
90 | { } | |
91 | ||
92 | Target* | |
93 | recognize(int, int, int) | |
94 | { return &target_test; } | |
95 | }; | |
96 | ||
97 | // Register the test target selector. | |
98 | ||
99 | Target_selector_test target_selector_test; | |
100 | ||
101 | // A simple ELF object with one empty section, named ".test" and one | |
102 | // globally visible symbol named "test". | |
103 | ||
104 | const unsigned char test_file_1[] = | |
105 | { | |
106 | // Ehdr | |
107 | // EI_MAG[0-3] | |
108 | 0x7f, 'E', 'L', 'F', | |
109 | // EI_CLASS: 32 bit. | |
110 | 1, | |
111 | // EI_DATA: little endian | |
112 | 1, | |
113 | // EI_VERSION | |
114 | 1, | |
115 | // EI_OSABI | |
116 | 0, | |
117 | // EI_ABIVERSION | |
118 | 0, | |
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, | |
147 | ||
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, | |
153 | ||
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, | |
176 | ||
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, | |
199 | ||
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, | |
222 | ||
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, | |
245 | ||
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, | |
250 | ||
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 | |
262 | 0, | |
263 | // st_shndx: In .test | |
264 | 1, 0, | |
265 | ||
266 | // Offset 284 | |
267 | // Contents of .strtab section | |
268 | '\0', | |
269 | 't', 'e', 's', 't', '\0', | |
270 | ||
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' | |
278 | }; | |
279 | ||
280 | const unsigned int test_file_1_size = sizeof test_file_1; | |
281 | ||
282 | } // End namespace gold_testsuite. |