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.
26 #include "target-select.h"
31 namespace gold_testsuite
36 // A Target used for testing purposes.
38 template<int size
, bool big_endian
>
39 class Target_test
: public Sized_target
<size
, big_endian
>
43 : Sized_target
<size
, big_endian
>(&test_target_info
)
47 scan_relocs(const General_options
&, Symbol_table
*, Layout
*,
48 Sized_relobj
<size
, big_endian
>*, unsigned int,
49 unsigned int, const unsigned char*, size_t, size_t,
50 const unsigned char*, Symbol
**)
51 { ERROR("call to Target_test::scan_relocs"); }
54 relocate_section(const Relocate_info
<size
, big_endian
>*, unsigned int,
55 const unsigned char*, size_t, unsigned char*,
56 typename
elfcpp::Elf_types
<size
>::Elf_Addr
, off_t
)
57 { ERROR("call to Target_test::relocate_section"); }
59 static const Target::Target_info test_target_info
;
62 template<int size
, bool big_endian
>
63 const Target::Target_info Target_test
<size
, big_endian
>::test_target_info
=
66 big_endian
, // is_big_endian
67 static_cast<elfcpp::EM
>(0xffff), // machine_code
68 false, // has_make_symbol
70 false, // has_code_fill
71 "/dummy", // dynamic_linker
72 0x08000000, // text_segment_address
73 0x1000, // abi_pagesize
74 0x1000 // common_pagesize
79 #ifdef HAVE_TARGET_32_LITTLE
80 Target_test
<32, false> target_test_32_little
;
83 #ifdef HAVE_TARGET_32_BIG
84 Target_test
<32, true> target_test_32_big
;
87 #ifdef HAVE_TARGET_64_LITTLE
88 Target_test
<64, false> target_test_64_little
;
91 #ifdef HAVE_TARGET_64_BIG
92 Target_test
<64, true> target_test_64_big
;
95 // A pointer to the test targets. This is used in CHECKs.
97 #ifdef HAVE_TARGET_32_LITTLE
98 Target
* target_test_pointer_32_little
= &target_test_32_little
;
101 #ifdef HAVE_TARGET_32_BIG
102 Target
* target_test_pointer_32_big
= &target_test_32_big
;
105 #ifdef HAVE_TARGET_64_LITTLE
106 Target
* target_test_pointer_64_little
= &target_test_64_little
;
109 #ifdef HAVE_TARGET_64_BIG
110 Target
* target_test_pointer_64_big
= &target_test_64_big
;
113 // Select the test targets.
115 template<int size
, bool big_endian
>
116 class Target_selector_test
: public Target_selector
119 Target_selector_test()
120 : Target_selector(0xffff, size
, big_endian
)
124 recognize(int, int, int)
130 #ifdef HAVE_TARGET_32_LITTLE
131 return &target_test_32_little
;
136 #ifdef HAVE_TARGET_32_BIG
137 return &target_test_32_big
;
145 #ifdef HAVE_TARGET_64_LITTLE
146 return &target_test_64_little
;
151 #ifdef HAVE_TARGET_64_BIG
152 return &target_test_64_big
;
161 // Register the test target selectors. These don't need to be
162 // conditionally compiled, as they will return NULL if there is no
165 Target_selector_test
<32, false> target_selector_test_32_little
;
166 Target_selector_test
<32, true> target_selector_test_32_big
;
167 Target_selector_test
<64, false> target_selector_test_64_little
;
168 Target_selector_test
<64, true> target_selector_test_64_big
;
170 // A simple ELF object with one empty section, named ".test" and one
171 // globally visible symbol named "test".
173 const unsigned char test_file_1_32_little
[] =
180 // EI_DATA: little endian
192 // e_machine: a magic value used for testing.
200 // e_shoff: starts right after file header
212 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
218 // Shdr 0: dummy entry
219 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
220 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
221 0, 0, 0, 0, 0, 0, 0, 0,
225 // sh_name: after initial null
227 // sh_type: SHT_PROGBITS
229 // sh_flags: SHF_ALLOC
233 // sh_offset: after file header + 5 section headers
248 // sh_name: 1 null byte + ".test\0"
250 // sh_type: SHT_SYMTAB
256 // sh_offset: after file header + 5 section headers + empty section
258 // sh_size: two symbols: dummy symbol + test symbol
260 // sh_link: to .strtab
262 // sh_info: one local symbol, the dummy symbol
266 // sh_entsize: size of symbol
271 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
273 // sh_type: SHT_STRTAB
279 // sh_offset: after .symtab section. 284 == 0x11c
281 // sh_size: 1 null byte + "test\0"
294 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
296 // sh_type: SHT_STRTAB
302 // sh_offset: after .strtab section. 290 == 0x122
304 // sh_size: all section names
316 // Contents of .symtab section
318 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
328 // st_info: STT_NOTYPE, STB_GLOBAL
332 // st_shndx: In .test
336 // Contents of .strtab section
338 't', 'e', 's', 't', '\0',
341 // Contents of .shstrtab section
343 '.', 't', 'e', 's', 't', '\0',
344 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
345 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
346 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
349 const unsigned int test_file_1_size_32_little
= sizeof test_file_1_32_little
;
351 // 32-bit big-endian version of test_file_1_32_little.
353 const unsigned char test_file_1_32_big
[] =
360 // EI_DATA: big endian
372 // e_machine: a magic value used for testing.
380 // e_shoff: starts right after file header
392 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
398 // Shdr 0: dummy entry
399 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
400 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
401 0, 0, 0, 0, 0, 0, 0, 0,
405 // sh_name: after initial null
407 // sh_type: SHT_PROGBITS
409 // sh_flags: SHF_ALLOC
413 // sh_offset: after file header + 5 section headers
428 // sh_name: 1 null byte + ".test\0"
430 // sh_type: SHT_SYMTAB
436 // sh_offset: after file header + 5 section headers + empty section
438 // sh_size: two symbols: dummy symbol + test symbol
440 // sh_link: to .strtab
442 // sh_info: one local symbol, the dummy symbol
446 // sh_entsize: size of symbol
451 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
453 // sh_type: SHT_STRTAB
459 // sh_offset: after .symtab section. 284 == 0x11c
461 // sh_size: 1 null byte + "test\0"
474 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
476 // sh_type: SHT_STRTAB
482 // sh_offset: after .strtab section. 290 == 0x122
484 // sh_size: all section names
496 // Contents of .symtab section
498 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
508 // st_info: STT_NOTYPE, STB_GLOBAL
512 // st_shndx: In .test
516 // Contents of .strtab section
518 't', 'e', 's', 't', '\0',
521 // Contents of .shstrtab section
523 '.', 't', 'e', 's', 't', '\0',
524 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
525 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
526 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
529 const unsigned int test_file_1_size_32_big
= sizeof test_file_1_32_big
;
531 // 64-bit little-endian version of test_file_1_32_little.
533 const unsigned char test_file_1_64_little
[] =
540 // EI_DATA: little endian
552 // e_machine: a magic value used for testing.
557 0, 0, 0, 0, 0, 0, 0, 0,
559 0, 0, 0, 0, 0, 0, 0, 0,
560 // e_shoff: starts right after file header
561 64, 0, 0, 0, 0, 0, 0, 0,
572 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
578 // Shdr 0: dummy entry
579 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
580 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
581 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
582 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
586 // sh_name: after initial null
588 // sh_type: SHT_PROGBITS
590 // sh_flags: SHF_ALLOC
591 2, 0, 0, 0, 0, 0, 0, 0,
593 0, 0, 0, 0, 0, 0, 0, 0,
594 // sh_offset: after file header + 5 section headers. 384 == 0x180.
595 0x80, 0x1, 0, 0, 0, 0, 0, 0,
597 0, 0, 0, 0, 0, 0, 0, 0,
603 1, 0, 0, 0, 0, 0, 0, 0,
605 0, 0, 0, 0, 0, 0, 0, 0,
609 // sh_name: 1 null byte + ".test\0"
611 // sh_type: SHT_SYMTAB
614 0, 0, 0, 0, 0, 0, 0, 0,
616 0, 0, 0, 0, 0, 0, 0, 0,
617 // sh_offset: after file header + 5 section headers + empty section
619 0x80, 0x1, 0, 0, 0, 0, 0, 0,
620 // sh_size: two symbols: dummy symbol + test symbol
621 48, 0, 0, 0, 0, 0, 0, 0,
622 // sh_link: to .strtab
624 // sh_info: one local symbol, the dummy symbol
627 8, 0, 0, 0, 0, 0, 0, 0,
628 // sh_entsize: size of symbol
629 24, 0, 0, 0, 0, 0, 0, 0,
633 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
635 // sh_type: SHT_STRTAB
638 0, 0, 0, 0, 0, 0, 0, 0,
640 0, 0, 0, 0, 0, 0, 0, 0,
641 // sh_offset: after .symtab section. 432 == 0x1b0
642 0xb0, 0x1, 0, 0, 0, 0, 0, 0,
643 // sh_size: 1 null byte + "test\0"
644 6, 0, 0, 0, 0, 0, 0, 0,
650 1, 0, 0, 0, 0, 0, 0, 0,
652 0, 0, 0, 0, 0, 0, 0, 0,
656 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
658 // sh_type: SHT_STRTAB
661 0, 0, 0, 0, 0, 0, 0, 0,
663 0, 0, 0, 0, 0, 0, 0, 0,
664 // sh_offset: after .strtab section. 438 == 0x1b6
665 0xb6, 0x1, 0, 0, 0, 0, 0, 0,
666 // sh_size: all section names
667 33, 0, 0, 0, 0, 0, 0, 0,
673 1, 0, 0, 0, 0, 0, 0, 0,
675 0, 0, 0, 0, 0, 0, 0, 0,
678 // Contents of .symtab section
680 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
681 0, 0, 0, 0, 0, 0, 0, 0,
687 // st_info: STT_NOTYPE, STB_GLOBAL
691 // st_shndx: In .test
694 0, 0, 0, 0, 0, 0, 0, 0,
696 0, 0, 0, 0, 0, 0, 0, 0,
699 // Contents of .strtab section
701 't', 'e', 's', 't', '\0',
704 // Contents of .shstrtab section
706 '.', 't', 'e', 's', 't', '\0',
707 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
708 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
709 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
712 const unsigned int test_file_1_size_64_little
= sizeof test_file_1_64_little
;
714 // 64-bit big-endian version of test_file_1_32_little.
716 const unsigned char test_file_1_64_big
[] =
723 // EI_DATA: big endian
735 // e_machine: a magic value used for testing.
740 0, 0, 0, 0, 0, 0, 0, 0,
742 0, 0, 0, 0, 0, 0, 0, 0,
743 // e_shoff: starts right after file header
744 0, 0, 0, 0, 0, 0, 0, 64,
755 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
761 // Shdr 0: dummy entry
762 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
763 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
764 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
765 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
769 // sh_name: after initial null
771 // sh_type: SHT_PROGBITS
773 // sh_flags: SHF_ALLOC
774 0, 0, 0, 0, 0, 0, 0, 2,
776 0, 0, 0, 0, 0, 0, 0, 0,
777 // sh_offset: after file header + 5 section headers. 384 == 0x180.
778 0, 0, 0, 0, 0, 0, 0x1, 0x80,
780 0, 0, 0, 0, 0, 0, 0, 0,
786 0, 0, 0, 0, 0, 0, 0, 1,
788 0, 0, 0, 0, 0, 0, 0, 0,
792 // sh_name: 1 null byte + ".test\0"
794 // sh_type: SHT_SYMTAB
797 0, 0, 0, 0, 0, 0, 0, 0,
799 0, 0, 0, 0, 0, 0, 0, 0,
800 // sh_offset: after file header + 5 section headers + empty section
802 0, 0, 0, 0, 0, 0, 0x1, 0x80,
803 // sh_size: two symbols: dummy symbol + test symbol
804 0, 0, 0, 0, 0, 0, 0, 48,
805 // sh_link: to .strtab
807 // sh_info: one local symbol, the dummy symbol
810 0, 0, 0, 0, 0, 0, 0, 8,
811 // sh_entsize: size of symbol
812 0, 0, 0, 0, 0, 0, 0, 24,
816 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
818 // sh_type: SHT_STRTAB
821 0, 0, 0, 0, 0, 0, 0, 0,
823 0, 0, 0, 0, 0, 0, 0, 0,
824 // sh_offset: after .symtab section. 432 == 0x1b0
825 0, 0, 0, 0, 0, 0, 0x1, 0xb0,
826 // sh_size: 1 null byte + "test\0"
827 0, 0, 0, 0, 0, 0, 0, 6,
833 0, 0, 0, 0, 0, 0, 0, 1,
835 0, 0, 0, 0, 0, 0, 0, 0,
839 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
841 // sh_type: SHT_STRTAB
844 0, 0, 0, 0, 0, 0, 0, 0,
846 0, 0, 0, 0, 0, 0, 0, 0,
847 // sh_offset: after .strtab section. 438 == 0x1b6
848 0, 0, 0, 0, 0, 0, 0x1, 0xb6,
849 // sh_size: all section names
850 0, 0, 0, 0, 0, 0, 0, 33,
856 0, 0, 0, 0, 0, 0, 0, 1,
858 0, 0, 0, 0, 0, 0, 0, 0,
861 // Contents of .symtab section
863 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
864 0, 0, 0, 0, 0, 0, 0, 0,
870 // st_info: STT_NOTYPE, STB_GLOBAL
874 // st_shndx: In .test
877 0, 0, 0, 0, 0, 0, 0, 0,
879 0, 0, 0, 0, 0, 0, 0, 0,
882 // Contents of .strtab section
884 't', 'e', 's', 't', '\0',
887 // Contents of .shstrtab section
889 '.', 't', 'e', 's', 't', '\0',
890 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
891 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
892 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
895 const unsigned int test_file_1_size_64_big
= sizeof test_file_1_64_big
;
897 } // End namespace gold_testsuite.