1 // testfile.cc -- Dummy ELF objects for testing purposes.
3 // Copyright (C) 2006-2014 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 gc_process_relocs(Symbol_table*, Layout*,
48 Sized_relobj_file<size, big_endian>*,
49 unsigned int, unsigned int, const unsigned char*, size_t,
50 Output_section*, bool, size_t, const unsigned char*)
51 { ERROR("call to Target_test::gc_process_relocs"); }
54 scan_relocs(Symbol_table*, Layout*, Sized_relobj_file<size, big_endian>*,
55 unsigned int, unsigned int, const unsigned char*, size_t,
56 Output_section*, bool, size_t, const unsigned char*)
57 { ERROR("call to Target_test::scan_relocs"); }
60 relocate_section(const Relocate_info<size, big_endian>*, unsigned int,
61 const unsigned char*, size_t, Output_section*, bool,
62 unsigned char*, typename elfcpp::Elf_types<size>::Elf_Addr,
63 section_size_type, const Reloc_symbol_changes*)
64 { ERROR("call to Target_test::relocate_section"); }
67 scan_relocatable_relocs(Symbol_table*, Layout*,
68 Sized_relobj_file<size, big_endian>*, unsigned int,
69 unsigned int, const unsigned char*,
70 size_t, Output_section*, bool, size_t,
71 const unsigned char*, Relocatable_relocs*)
72 { ERROR("call to Target_test::scan_relocatable_relocs"); }
75 relocate_relocs(const Relocate_info<size, big_endian>*,
76 unsigned int, const unsigned char*, size_t,
77 Output_section*, typename elfcpp::Elf_types<size>::Elf_Off,
78 const Relocatable_relocs*, unsigned char*,
79 typename elfcpp::Elf_types<size>::Elf_Addr,
80 section_size_type, unsigned char*,
82 { ERROR("call to Target_test::relocate_relocs"); }
84 static const Target::Target_info test_target_info;
87 template<int size, bool big_endian>
88 const Target::Target_info Target_test<size, big_endian>::test_target_info =
91 big_endian, // is_big_endian
92 static_cast<elfcpp::EM>(0xffff), // machine_code
93 false, // has_make_symbol
95 false, // has_code_fill
96 false, // is_default_stack_executable
97 false, // can_icf_inline_merge_sections
99 "/dummy", // dynamic_linker
100 0x08000000, // default_text_segment_address
101 0x1000, // abi_pagesize
102 0x1000, // common_pagesize
103 false, // isolate_execinstr
105 elfcpp::SHN_UNDEF, // small_common_shndx
106 elfcpp::SHN_UNDEF, // large_common_shndx
107 0, // small_common_section_flags
108 0, // large_common_section_flags
109 NULL, // attributes_section
110 NULL, // attributes_vendor
111 "_start" // entry_symbol_name
116 #ifdef HAVE_TARGET_32_LITTLE
117 Target_test<32, false> target_test_32_little;
120 #ifdef HAVE_TARGET_32_BIG
121 Target_test<32, true> target_test_32_big;
124 #ifdef HAVE_TARGET_64_LITTLE
125 Target_test<64, false> target_test_64_little;
128 #ifdef HAVE_TARGET_64_BIG
129 Target_test<64, true> target_test_64_big;
132 // A pointer to the test targets. This is used in CHECKs.
134 #ifdef HAVE_TARGET_32_LITTLE
135 Target* target_test_pointer_32_little = &target_test_32_little;
138 #ifdef HAVE_TARGET_32_BIG
139 Target* target_test_pointer_32_big = &target_test_32_big;
142 #ifdef HAVE_TARGET_64_LITTLE
143 Target* target_test_pointer_64_little = &target_test_64_little;
146 #ifdef HAVE_TARGET_64_BIG
147 Target* target_test_pointer_64_big = &target_test_64_big;
150 // Select the test targets.
152 template<int size, bool big_endian>
153 class Target_selector_test : public Target_selector
156 Target_selector_test()
157 : Target_selector(0xffff, size, big_endian, NULL, NULL)
161 do_instantiate_target()
168 do_recognize(Input_file*, off_t, int, int, int)
174 #ifdef HAVE_TARGET_32_LITTLE
175 return &target_test_32_little;
180 #ifdef HAVE_TARGET_32_BIG
181 return &target_test_32_big;
189 #ifdef HAVE_TARGET_64_LITTLE
190 return &target_test_64_little;
195 #ifdef HAVE_TARGET_64_BIG
196 return &target_test_64_big;
205 do_recognize_by_name(const char*)
209 do_supported_names(std::vector<const char*>*)
213 // Register the test target selectors. These don't need to be
214 // conditionally compiled, as they will return NULL if there is no
217 Target_selector_test<32, false> target_selector_test_32_little;
218 Target_selector_test<32, true> target_selector_test_32_big;
219 Target_selector_test<64, false> target_selector_test_64_little;
220 Target_selector_test<64, true> target_selector_test_64_big;
222 // A simple ELF object with one empty section, named ".test" and one
223 // globally visible symbol named "test".
225 const unsigned char test_file_1_32_little[] =
232 // EI_DATA: little endian
244 // e_machine: a magic value used for testing.
252 // e_shoff: starts right after file header
264 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
270 // Shdr 0: dummy entry
271 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
272 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
273 0, 0, 0, 0, 0, 0, 0, 0,
277 // sh_name: after initial null
279 // sh_type: SHT_PROGBITS
281 // sh_flags: SHF_ALLOC
285 // sh_offset: after file header + 5 section headers
300 // sh_name: 1 null byte + ".test\0"
302 // sh_type: SHT_SYMTAB
308 // sh_offset: after file header + 5 section headers + empty section
310 // sh_size: two symbols: dummy symbol + test symbol
312 // sh_link: to .strtab
314 // sh_info: one local symbol, the dummy symbol
318 // sh_entsize: size of symbol
323 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
325 // sh_type: SHT_STRTAB
331 // sh_offset: after .symtab section. 284 == 0x11c
333 // sh_size: 1 null byte + "test\0"
346 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
348 // sh_type: SHT_STRTAB
354 // sh_offset: after .strtab section. 290 == 0x122
356 // sh_size: all section names
368 // Contents of .symtab section
370 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
380 // st_info: STT_NOTYPE, STB_GLOBAL
384 // st_shndx: In .test
388 // Contents of .strtab section
390 't', 'e', 's', 't', '\0',
393 // Contents of .shstrtab section
395 '.', 't', 'e', 's', 't', '\0',
396 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
397 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
398 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
401 const unsigned int test_file_1_size_32_little = sizeof test_file_1_32_little;
403 // 32-bit big-endian version of test_file_1_32_little.
405 const unsigned char test_file_1_32_big[] =
412 // EI_DATA: big endian
424 // e_machine: a magic value used for testing.
432 // e_shoff: starts right after file header
444 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
450 // Shdr 0: dummy entry
451 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
452 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
453 0, 0, 0, 0, 0, 0, 0, 0,
457 // sh_name: after initial null
459 // sh_type: SHT_PROGBITS
461 // sh_flags: SHF_ALLOC
465 // sh_offset: after file header + 5 section headers
480 // sh_name: 1 null byte + ".test\0"
482 // sh_type: SHT_SYMTAB
488 // sh_offset: after file header + 5 section headers + empty section
490 // sh_size: two symbols: dummy symbol + test symbol
492 // sh_link: to .strtab
494 // sh_info: one local symbol, the dummy symbol
498 // sh_entsize: size of symbol
503 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
505 // sh_type: SHT_STRTAB
511 // sh_offset: after .symtab section. 284 == 0x11c
513 // sh_size: 1 null byte + "test\0"
526 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
528 // sh_type: SHT_STRTAB
534 // sh_offset: after .strtab section. 290 == 0x122
536 // sh_size: all section names
548 // Contents of .symtab section
550 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
560 // st_info: STT_NOTYPE, STB_GLOBAL
564 // st_shndx: In .test
568 // Contents of .strtab section
570 't', 'e', 's', 't', '\0',
573 // Contents of .shstrtab section
575 '.', 't', 'e', 's', 't', '\0',
576 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
577 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
578 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
581 const unsigned int test_file_1_size_32_big = sizeof test_file_1_32_big;
583 // 64-bit little-endian version of test_file_1_32_little.
585 const unsigned char test_file_1_64_little[] =
592 // EI_DATA: little endian
604 // e_machine: a magic value used for testing.
609 0, 0, 0, 0, 0, 0, 0, 0,
611 0, 0, 0, 0, 0, 0, 0, 0,
612 // e_shoff: starts right after file header
613 64, 0, 0, 0, 0, 0, 0, 0,
624 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
630 // Shdr 0: dummy entry
631 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
632 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
633 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
634 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
638 // sh_name: after initial null
640 // sh_type: SHT_PROGBITS
642 // sh_flags: SHF_ALLOC
643 2, 0, 0, 0, 0, 0, 0, 0,
645 0, 0, 0, 0, 0, 0, 0, 0,
646 // sh_offset: after file header + 5 section headers. 384 == 0x180.
647 0x80, 0x1, 0, 0, 0, 0, 0, 0,
649 0, 0, 0, 0, 0, 0, 0, 0,
655 1, 0, 0, 0, 0, 0, 0, 0,
657 0, 0, 0, 0, 0, 0, 0, 0,
661 // sh_name: 1 null byte + ".test\0"
663 // sh_type: SHT_SYMTAB
666 0, 0, 0, 0, 0, 0, 0, 0,
668 0, 0, 0, 0, 0, 0, 0, 0,
669 // sh_offset: after file header + 5 section headers + empty section
671 0x80, 0x1, 0, 0, 0, 0, 0, 0,
672 // sh_size: two symbols: dummy symbol + test symbol
673 48, 0, 0, 0, 0, 0, 0, 0,
674 // sh_link: to .strtab
676 // sh_info: one local symbol, the dummy symbol
679 8, 0, 0, 0, 0, 0, 0, 0,
680 // sh_entsize: size of symbol
681 24, 0, 0, 0, 0, 0, 0, 0,
685 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
687 // sh_type: SHT_STRTAB
690 0, 0, 0, 0, 0, 0, 0, 0,
692 0, 0, 0, 0, 0, 0, 0, 0,
693 // sh_offset: after .symtab section. 432 == 0x1b0
694 0xb0, 0x1, 0, 0, 0, 0, 0, 0,
695 // sh_size: 1 null byte + "test\0"
696 6, 0, 0, 0, 0, 0, 0, 0,
702 1, 0, 0, 0, 0, 0, 0, 0,
704 0, 0, 0, 0, 0, 0, 0, 0,
708 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
710 // sh_type: SHT_STRTAB
713 0, 0, 0, 0, 0, 0, 0, 0,
715 0, 0, 0, 0, 0, 0, 0, 0,
716 // sh_offset: after .strtab section. 438 == 0x1b6
717 0xb6, 0x1, 0, 0, 0, 0, 0, 0,
718 // sh_size: all section names
719 33, 0, 0, 0, 0, 0, 0, 0,
725 1, 0, 0, 0, 0, 0, 0, 0,
727 0, 0, 0, 0, 0, 0, 0, 0,
730 // Contents of .symtab section
732 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
733 0, 0, 0, 0, 0, 0, 0, 0,
739 // st_info: STT_NOTYPE, STB_GLOBAL
743 // st_shndx: In .test
746 0, 0, 0, 0, 0, 0, 0, 0,
748 0, 0, 0, 0, 0, 0, 0, 0,
751 // Contents of .strtab section
753 't', 'e', 's', 't', '\0',
756 // Contents of .shstrtab section
758 '.', 't', 'e', 's', 't', '\0',
759 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
760 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
761 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
764 const unsigned int test_file_1_size_64_little = sizeof test_file_1_64_little;
766 // 64-bit big-endian version of test_file_1_32_little.
768 const unsigned char test_file_1_64_big[] =
775 // EI_DATA: big endian
787 // e_machine: a magic value used for testing.
792 0, 0, 0, 0, 0, 0, 0, 0,
794 0, 0, 0, 0, 0, 0, 0, 0,
795 // e_shoff: starts right after file header
796 0, 0, 0, 0, 0, 0, 0, 64,
807 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
813 // Shdr 0: dummy entry
814 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
815 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
816 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
817 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
821 // sh_name: after initial null
823 // sh_type: SHT_PROGBITS
825 // sh_flags: SHF_ALLOC
826 0, 0, 0, 0, 0, 0, 0, 2,
828 0, 0, 0, 0, 0, 0, 0, 0,
829 // sh_offset: after file header + 5 section headers. 384 == 0x180.
830 0, 0, 0, 0, 0, 0, 0x1, 0x80,
832 0, 0, 0, 0, 0, 0, 0, 0,
838 0, 0, 0, 0, 0, 0, 0, 1,
840 0, 0, 0, 0, 0, 0, 0, 0,
844 // sh_name: 1 null byte + ".test\0"
846 // sh_type: SHT_SYMTAB
849 0, 0, 0, 0, 0, 0, 0, 0,
851 0, 0, 0, 0, 0, 0, 0, 0,
852 // sh_offset: after file header + 5 section headers + empty section
854 0, 0, 0, 0, 0, 0, 0x1, 0x80,
855 // sh_size: two symbols: dummy symbol + test symbol
856 0, 0, 0, 0, 0, 0, 0, 48,
857 // sh_link: to .strtab
859 // sh_info: one local symbol, the dummy symbol
862 0, 0, 0, 0, 0, 0, 0, 8,
863 // sh_entsize: size of symbol
864 0, 0, 0, 0, 0, 0, 0, 24,
868 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
870 // sh_type: SHT_STRTAB
873 0, 0, 0, 0, 0, 0, 0, 0,
875 0, 0, 0, 0, 0, 0, 0, 0,
876 // sh_offset: after .symtab section. 432 == 0x1b0
877 0, 0, 0, 0, 0, 0, 0x1, 0xb0,
878 // sh_size: 1 null byte + "test\0"
879 0, 0, 0, 0, 0, 0, 0, 6,
885 0, 0, 0, 0, 0, 0, 0, 1,
887 0, 0, 0, 0, 0, 0, 0, 0,
891 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
893 // sh_type: SHT_STRTAB
896 0, 0, 0, 0, 0, 0, 0, 0,
898 0, 0, 0, 0, 0, 0, 0, 0,
899 // sh_offset: after .strtab section. 438 == 0x1b6
900 0, 0, 0, 0, 0, 0, 0x1, 0xb6,
901 // sh_size: all section names
902 0, 0, 0, 0, 0, 0, 0, 33,
908 0, 0, 0, 0, 0, 0, 0, 1,
910 0, 0, 0, 0, 0, 0, 0, 0,
913 // Contents of .symtab section
915 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
916 0, 0, 0, 0, 0, 0, 0, 0,
922 // st_info: STT_NOTYPE, STB_GLOBAL
926 // st_shndx: In .test
929 0, 0, 0, 0, 0, 0, 0, 0,
931 0, 0, 0, 0, 0, 0, 0, 0,
934 // Contents of .strtab section
936 't', 'e', 's', 't', '\0',
939 // Contents of .shstrtab section
941 '.', 't', 'e', 's', 't', '\0',
942 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
943 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
944 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
947 const unsigned int test_file_1_size_64_big = sizeof test_file_1_64_big;
949 } // End namespace gold_testsuite.