1 // testfile.cc -- Dummy ELF objects for testing purposes.
3 // Copyright (C) 2006-2017 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 emit_relocs_scan(Symbol_table*, Layout*,
76 Sized_relobj_file<size, big_endian>*, unsigned int,
77 unsigned int, const unsigned char*,
78 size_t, Output_section*, bool, size_t,
79 const unsigned char*, Relocatable_relocs*)
80 { ERROR("call to Target_test::emit_relocs_scan"); }
83 relocate_relocs(const Relocate_info<size, big_endian>*,
84 unsigned int, const unsigned char*, size_t,
85 Output_section*, typename elfcpp::Elf_types<size>::Elf_Off,
87 typename elfcpp::Elf_types<size>::Elf_Addr,
88 section_size_type, unsigned char*,
90 { ERROR("call to Target_test::relocate_relocs"); }
92 static const Target::Target_info test_target_info;
95 template<int size, bool big_endian>
96 const Target::Target_info Target_test<size, big_endian>::test_target_info =
99 big_endian, // is_big_endian
100 static_cast<elfcpp::EM>(0xffff), // machine_code
101 false, // has_make_symbol
102 false, // has_resolve
103 false, // has_code_fill
104 false, // is_default_stack_executable
105 false, // can_icf_inline_merge_sections
107 "/dummy", // dynamic_linker
108 0x08000000, // default_text_segment_address
109 0x1000, // abi_pagesize
110 0x1000, // common_pagesize
111 false, // isolate_execinstr
113 elfcpp::SHN_UNDEF, // small_common_shndx
114 elfcpp::SHN_UNDEF, // large_common_shndx
115 0, // small_common_section_flags
116 0, // large_common_section_flags
117 NULL, // attributes_section
118 NULL, // attributes_vendor
119 "_start", // entry_symbol_name
120 32, // hash_entry_size
125 #ifdef HAVE_TARGET_32_LITTLE
126 Target_test<32, false> target_test_32_little;
129 #ifdef HAVE_TARGET_32_BIG
130 Target_test<32, true> target_test_32_big;
133 #ifdef HAVE_TARGET_64_LITTLE
134 Target_test<64, false> target_test_64_little;
137 #ifdef HAVE_TARGET_64_BIG
138 Target_test<64, true> target_test_64_big;
141 // A pointer to the test targets. This is used in CHECKs.
143 #ifdef HAVE_TARGET_32_LITTLE
144 Target* target_test_pointer_32_little = &target_test_32_little;
147 #ifdef HAVE_TARGET_32_BIG
148 Target* target_test_pointer_32_big = &target_test_32_big;
151 #ifdef HAVE_TARGET_64_LITTLE
152 Target* target_test_pointer_64_little = &target_test_64_little;
155 #ifdef HAVE_TARGET_64_BIG
156 Target* target_test_pointer_64_big = &target_test_64_big;
159 // Select the test targets.
161 template<int size, bool big_endian>
162 class Target_selector_test : public Target_selector
165 Target_selector_test()
166 : Target_selector(0xffff, size, big_endian, NULL, NULL)
170 do_instantiate_target()
177 do_recognize(Input_file*, off_t, int, int, int)
183 #ifdef HAVE_TARGET_32_LITTLE
184 return &target_test_32_little;
189 #ifdef HAVE_TARGET_32_BIG
190 return &target_test_32_big;
198 #ifdef HAVE_TARGET_64_LITTLE
199 return &target_test_64_little;
204 #ifdef HAVE_TARGET_64_BIG
205 return &target_test_64_big;
214 do_recognize_by_name(const char*)
218 do_supported_names(std::vector<const char*>*)
222 // Register the test target selectors. These don't need to be
223 // conditionally compiled, as they will return NULL if there is no
226 Target_selector_test<32, false> target_selector_test_32_little;
227 Target_selector_test<32, true> target_selector_test_32_big;
228 Target_selector_test<64, false> target_selector_test_64_little;
229 Target_selector_test<64, true> target_selector_test_64_big;
231 // A simple ELF object with one empty section, named ".test" and one
232 // globally visible symbol named "test".
234 const unsigned char test_file_1_32_little[] =
241 // EI_DATA: little endian
253 // e_machine: a magic value used for testing.
261 // e_shoff: starts right after file header
273 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
279 // Shdr 0: dummy entry
280 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
281 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
282 0, 0, 0, 0, 0, 0, 0, 0,
286 // sh_name: after initial null
288 // sh_type: SHT_PROGBITS
290 // sh_flags: SHF_ALLOC
294 // sh_offset: after file header + 5 section headers
309 // sh_name: 1 null byte + ".test\0"
311 // sh_type: SHT_SYMTAB
317 // sh_offset: after file header + 5 section headers + empty section
319 // sh_size: two symbols: dummy symbol + test symbol
321 // sh_link: to .strtab
323 // sh_info: one local symbol, the dummy symbol
327 // sh_entsize: size of symbol
332 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
334 // sh_type: SHT_STRTAB
340 // sh_offset: after .symtab section. 284 == 0x11c
342 // sh_size: 1 null byte + "test\0"
355 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
357 // sh_type: SHT_STRTAB
363 // sh_offset: after .strtab section. 290 == 0x122
365 // sh_size: all section names
377 // Contents of .symtab section
379 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
389 // st_info: STT_NOTYPE, STB_GLOBAL
393 // st_shndx: In .test
397 // Contents of .strtab section
399 't', 'e', 's', 't', '\0',
402 // Contents of .shstrtab section
404 '.', 't', 'e', 's', 't', '\0',
405 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
406 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
407 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
410 const unsigned int test_file_1_size_32_little = sizeof test_file_1_32_little;
412 // 32-bit big-endian version of test_file_1_32_little.
414 const unsigned char test_file_1_32_big[] =
421 // EI_DATA: big endian
433 // e_machine: a magic value used for testing.
441 // e_shoff: starts right after file header
453 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
459 // Shdr 0: dummy entry
460 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
461 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
462 0, 0, 0, 0, 0, 0, 0, 0,
466 // sh_name: after initial null
468 // sh_type: SHT_PROGBITS
470 // sh_flags: SHF_ALLOC
474 // sh_offset: after file header + 5 section headers
489 // sh_name: 1 null byte + ".test\0"
491 // sh_type: SHT_SYMTAB
497 // sh_offset: after file header + 5 section headers + empty section
499 // sh_size: two symbols: dummy symbol + test symbol
501 // sh_link: to .strtab
503 // sh_info: one local symbol, the dummy symbol
507 // sh_entsize: size of symbol
512 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
514 // sh_type: SHT_STRTAB
520 // sh_offset: after .symtab section. 284 == 0x11c
522 // sh_size: 1 null byte + "test\0"
535 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
537 // sh_type: SHT_STRTAB
543 // sh_offset: after .strtab section. 290 == 0x122
545 // sh_size: all section names
557 // Contents of .symtab section
559 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
569 // st_info: STT_NOTYPE, STB_GLOBAL
573 // st_shndx: In .test
577 // Contents of .strtab section
579 't', 'e', 's', 't', '\0',
582 // Contents of .shstrtab section
584 '.', 't', 'e', 's', 't', '\0',
585 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
586 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
587 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
590 const unsigned int test_file_1_size_32_big = sizeof test_file_1_32_big;
592 // 64-bit little-endian version of test_file_1_32_little.
594 const unsigned char test_file_1_64_little[] =
601 // EI_DATA: little endian
613 // e_machine: a magic value used for testing.
618 0, 0, 0, 0, 0, 0, 0, 0,
620 0, 0, 0, 0, 0, 0, 0, 0,
621 // e_shoff: starts right after file header
622 64, 0, 0, 0, 0, 0, 0, 0,
633 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
639 // Shdr 0: dummy entry
640 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
641 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
642 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
643 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
647 // sh_name: after initial null
649 // sh_type: SHT_PROGBITS
651 // sh_flags: SHF_ALLOC
652 2, 0, 0, 0, 0, 0, 0, 0,
654 0, 0, 0, 0, 0, 0, 0, 0,
655 // sh_offset: after file header + 5 section headers. 384 == 0x180.
656 0x80, 0x1, 0, 0, 0, 0, 0, 0,
658 0, 0, 0, 0, 0, 0, 0, 0,
664 1, 0, 0, 0, 0, 0, 0, 0,
666 0, 0, 0, 0, 0, 0, 0, 0,
670 // sh_name: 1 null byte + ".test\0"
672 // sh_type: SHT_SYMTAB
675 0, 0, 0, 0, 0, 0, 0, 0,
677 0, 0, 0, 0, 0, 0, 0, 0,
678 // sh_offset: after file header + 5 section headers + empty section
680 0x80, 0x1, 0, 0, 0, 0, 0, 0,
681 // sh_size: two symbols: dummy symbol + test symbol
682 48, 0, 0, 0, 0, 0, 0, 0,
683 // sh_link: to .strtab
685 // sh_info: one local symbol, the dummy symbol
688 8, 0, 0, 0, 0, 0, 0, 0,
689 // sh_entsize: size of symbol
690 24, 0, 0, 0, 0, 0, 0, 0,
694 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
696 // sh_type: SHT_STRTAB
699 0, 0, 0, 0, 0, 0, 0, 0,
701 0, 0, 0, 0, 0, 0, 0, 0,
702 // sh_offset: after .symtab section. 432 == 0x1b0
703 0xb0, 0x1, 0, 0, 0, 0, 0, 0,
704 // sh_size: 1 null byte + "test\0"
705 6, 0, 0, 0, 0, 0, 0, 0,
711 1, 0, 0, 0, 0, 0, 0, 0,
713 0, 0, 0, 0, 0, 0, 0, 0,
717 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
719 // sh_type: SHT_STRTAB
722 0, 0, 0, 0, 0, 0, 0, 0,
724 0, 0, 0, 0, 0, 0, 0, 0,
725 // sh_offset: after .strtab section. 438 == 0x1b6
726 0xb6, 0x1, 0, 0, 0, 0, 0, 0,
727 // sh_size: all section names
728 33, 0, 0, 0, 0, 0, 0, 0,
734 1, 0, 0, 0, 0, 0, 0, 0,
736 0, 0, 0, 0, 0, 0, 0, 0,
739 // Contents of .symtab section
741 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
742 0, 0, 0, 0, 0, 0, 0, 0,
748 // st_info: STT_NOTYPE, STB_GLOBAL
752 // st_shndx: In .test
755 0, 0, 0, 0, 0, 0, 0, 0,
757 0, 0, 0, 0, 0, 0, 0, 0,
760 // Contents of .strtab section
762 't', 'e', 's', 't', '\0',
765 // Contents of .shstrtab section
767 '.', 't', 'e', 's', 't', '\0',
768 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
769 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
770 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
773 const unsigned int test_file_1_size_64_little = sizeof test_file_1_64_little;
775 // 64-bit big-endian version of test_file_1_32_little.
777 const unsigned char test_file_1_64_big[] =
784 // EI_DATA: big endian
796 // e_machine: a magic value used for testing.
801 0, 0, 0, 0, 0, 0, 0, 0,
803 0, 0, 0, 0, 0, 0, 0, 0,
804 // e_shoff: starts right after file header
805 0, 0, 0, 0, 0, 0, 0, 64,
816 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
822 // Shdr 0: dummy entry
823 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
824 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
825 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
826 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
830 // sh_name: after initial null
832 // sh_type: SHT_PROGBITS
834 // sh_flags: SHF_ALLOC
835 0, 0, 0, 0, 0, 0, 0, 2,
837 0, 0, 0, 0, 0, 0, 0, 0,
838 // sh_offset: after file header + 5 section headers. 384 == 0x180.
839 0, 0, 0, 0, 0, 0, 0x1, 0x80,
841 0, 0, 0, 0, 0, 0, 0, 0,
847 0, 0, 0, 0, 0, 0, 0, 1,
849 0, 0, 0, 0, 0, 0, 0, 0,
853 // sh_name: 1 null byte + ".test\0"
855 // sh_type: SHT_SYMTAB
858 0, 0, 0, 0, 0, 0, 0, 0,
860 0, 0, 0, 0, 0, 0, 0, 0,
861 // sh_offset: after file header + 5 section headers + empty section
863 0, 0, 0, 0, 0, 0, 0x1, 0x80,
864 // sh_size: two symbols: dummy symbol + test symbol
865 0, 0, 0, 0, 0, 0, 0, 48,
866 // sh_link: to .strtab
868 // sh_info: one local symbol, the dummy symbol
871 0, 0, 0, 0, 0, 0, 0, 8,
872 // sh_entsize: size of symbol
873 0, 0, 0, 0, 0, 0, 0, 24,
877 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
879 // sh_type: SHT_STRTAB
882 0, 0, 0, 0, 0, 0, 0, 0,
884 0, 0, 0, 0, 0, 0, 0, 0,
885 // sh_offset: after .symtab section. 432 == 0x1b0
886 0, 0, 0, 0, 0, 0, 0x1, 0xb0,
887 // sh_size: 1 null byte + "test\0"
888 0, 0, 0, 0, 0, 0, 0, 6,
894 0, 0, 0, 0, 0, 0, 0, 1,
896 0, 0, 0, 0, 0, 0, 0, 0,
900 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
902 // sh_type: SHT_STRTAB
905 0, 0, 0, 0, 0, 0, 0, 0,
907 0, 0, 0, 0, 0, 0, 0, 0,
908 // sh_offset: after .strtab section. 438 == 0x1b6
909 0, 0, 0, 0, 0, 0, 0x1, 0xb6,
910 // sh_size: all section names
911 0, 0, 0, 0, 0, 0, 0, 33,
917 0, 0, 0, 0, 0, 0, 0, 1,
919 0, 0, 0, 0, 0, 0, 0, 0,
922 // Contents of .symtab section
924 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
925 0, 0, 0, 0, 0, 0, 0, 0,
931 // st_info: STT_NOTYPE, STB_GLOBAL
935 // st_shndx: In .test
938 0, 0, 0, 0, 0, 0, 0, 0,
940 0, 0, 0, 0, 0, 0, 0, 0,
943 // Contents of .strtab section
945 't', 'e', 's', 't', '\0',
948 // Contents of .shstrtab section
950 '.', 't', 'e', 's', 't', '\0',
951 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
952 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
953 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
956 const unsigned int test_file_1_size_64_big = sizeof test_file_1_64_big;
958 } // End namespace gold_testsuite.