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