1 // testfile.cc -- Dummy ELF objects for testing purposes.
3 // Copyright (C) 2006-2020 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
121 elfcpp::SHT_PROGBITS
, // unwind_section_type
126 #ifdef HAVE_TARGET_32_LITTLE
127 Target_test
<32, false> target_test_32_little
;
130 #ifdef HAVE_TARGET_32_BIG
131 Target_test
<32, true> target_test_32_big
;
134 #ifdef HAVE_TARGET_64_LITTLE
135 Target_test
<64, false> target_test_64_little
;
138 #ifdef HAVE_TARGET_64_BIG
139 Target_test
<64, true> target_test_64_big
;
142 // A pointer to the test targets. This is used in CHECKs.
144 #ifdef HAVE_TARGET_32_LITTLE
145 Target
* target_test_pointer_32_little
= &target_test_32_little
;
148 #ifdef HAVE_TARGET_32_BIG
149 Target
* target_test_pointer_32_big
= &target_test_32_big
;
152 #ifdef HAVE_TARGET_64_LITTLE
153 Target
* target_test_pointer_64_little
= &target_test_64_little
;
156 #ifdef HAVE_TARGET_64_BIG
157 Target
* target_test_pointer_64_big
= &target_test_64_big
;
160 // Select the test targets.
162 template<int size
, bool big_endian
>
163 class Target_selector_test
: public Target_selector
166 Target_selector_test()
167 : Target_selector(0xffff, size
, big_endian
, NULL
, NULL
)
171 do_instantiate_target()
178 do_recognize(Input_file
*, off_t
, int, int, int)
184 #ifdef HAVE_TARGET_32_LITTLE
185 return &target_test_32_little
;
190 #ifdef HAVE_TARGET_32_BIG
191 return &target_test_32_big
;
199 #ifdef HAVE_TARGET_64_LITTLE
200 return &target_test_64_little
;
205 #ifdef HAVE_TARGET_64_BIG
206 return &target_test_64_big
;
215 do_recognize_by_name(const char*)
219 do_supported_names(std::vector
<const char*>*)
223 // Register the test target selectors. These don't need to be
224 // conditionally compiled, as they will return NULL if there is no
227 Target_selector_test
<32, false> target_selector_test_32_little
;
228 Target_selector_test
<32, true> target_selector_test_32_big
;
229 Target_selector_test
<64, false> target_selector_test_64_little
;
230 Target_selector_test
<64, true> target_selector_test_64_big
;
232 // A simple ELF object with one empty section, named ".test" and one
233 // globally visible symbol named "test".
235 const unsigned char test_file_1_32_little
[] =
242 // EI_DATA: little endian
254 // e_machine: a magic value used for testing.
262 // e_shoff: starts right after file header
274 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
280 // Shdr 0: dummy entry
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, 0, 0, 0, 0, 0, 0, 0, 0,
283 0, 0, 0, 0, 0, 0, 0, 0,
287 // sh_name: after initial null
289 // sh_type: SHT_PROGBITS
291 // sh_flags: SHF_ALLOC
295 // sh_offset: after file header + 5 section headers
310 // sh_name: 1 null byte + ".test\0"
312 // sh_type: SHT_SYMTAB
318 // sh_offset: after file header + 5 section headers + empty section
320 // sh_size: two symbols: dummy symbol + test symbol
322 // sh_link: to .strtab
324 // sh_info: one local symbol, the dummy symbol
328 // sh_entsize: size of symbol
333 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
335 // sh_type: SHT_STRTAB
341 // sh_offset: after .symtab section. 284 == 0x11c
343 // sh_size: 1 null byte + "test\0"
356 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
358 // sh_type: SHT_STRTAB
364 // sh_offset: after .strtab section. 290 == 0x122
366 // sh_size: all section names
378 // Contents of .symtab section
380 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
390 // st_info: STT_NOTYPE, STB_GLOBAL
394 // st_shndx: In .test
398 // Contents of .strtab section
400 't', 'e', 's', 't', '\0',
403 // Contents of .shstrtab section
405 '.', 't', 'e', 's', 't', '\0',
406 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
407 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
408 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
411 const unsigned int test_file_1_size_32_little
= sizeof test_file_1_32_little
;
413 // 32-bit big-endian version of test_file_1_32_little.
415 const unsigned char test_file_1_32_big
[] =
422 // EI_DATA: big endian
434 // e_machine: a magic value used for testing.
442 // e_shoff: starts right after file header
454 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
460 // Shdr 0: dummy entry
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, 0, 0, 0, 0, 0, 0, 0, 0,
463 0, 0, 0, 0, 0, 0, 0, 0,
467 // sh_name: after initial null
469 // sh_type: SHT_PROGBITS
471 // sh_flags: SHF_ALLOC
475 // sh_offset: after file header + 5 section headers
490 // sh_name: 1 null byte + ".test\0"
492 // sh_type: SHT_SYMTAB
498 // sh_offset: after file header + 5 section headers + empty section
500 // sh_size: two symbols: dummy symbol + test symbol
502 // sh_link: to .strtab
504 // sh_info: one local symbol, the dummy symbol
508 // sh_entsize: size of symbol
513 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
515 // sh_type: SHT_STRTAB
521 // sh_offset: after .symtab section. 284 == 0x11c
523 // sh_size: 1 null byte + "test\0"
536 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
538 // sh_type: SHT_STRTAB
544 // sh_offset: after .strtab section. 290 == 0x122
546 // sh_size: all section names
558 // Contents of .symtab section
560 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
570 // st_info: STT_NOTYPE, STB_GLOBAL
574 // st_shndx: In .test
578 // Contents of .strtab section
580 't', 'e', 's', 't', '\0',
583 // Contents of .shstrtab section
585 '.', 't', 'e', 's', 't', '\0',
586 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
587 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
588 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
591 const unsigned int test_file_1_size_32_big
= sizeof test_file_1_32_big
;
593 // 64-bit little-endian version of test_file_1_32_little.
595 const unsigned char test_file_1_64_little
[] =
602 // EI_DATA: little endian
614 // e_machine: a magic value used for testing.
619 0, 0, 0, 0, 0, 0, 0, 0,
621 0, 0, 0, 0, 0, 0, 0, 0,
622 // e_shoff: starts right after file header
623 64, 0, 0, 0, 0, 0, 0, 0,
634 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
640 // Shdr 0: dummy entry
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,
644 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
648 // sh_name: after initial null
650 // sh_type: SHT_PROGBITS
652 // sh_flags: SHF_ALLOC
653 2, 0, 0, 0, 0, 0, 0, 0,
655 0, 0, 0, 0, 0, 0, 0, 0,
656 // sh_offset: after file header + 5 section headers. 384 == 0x180.
657 0x80, 0x1, 0, 0, 0, 0, 0, 0,
659 0, 0, 0, 0, 0, 0, 0, 0,
665 1, 0, 0, 0, 0, 0, 0, 0,
667 0, 0, 0, 0, 0, 0, 0, 0,
671 // sh_name: 1 null byte + ".test\0"
673 // sh_type: SHT_SYMTAB
676 0, 0, 0, 0, 0, 0, 0, 0,
678 0, 0, 0, 0, 0, 0, 0, 0,
679 // sh_offset: after file header + 5 section headers + empty section
681 0x80, 0x1, 0, 0, 0, 0, 0, 0,
682 // sh_size: two symbols: dummy symbol + test symbol
683 48, 0, 0, 0, 0, 0, 0, 0,
684 // sh_link: to .strtab
686 // sh_info: one local symbol, the dummy symbol
689 8, 0, 0, 0, 0, 0, 0, 0,
690 // sh_entsize: size of symbol
691 24, 0, 0, 0, 0, 0, 0, 0,
695 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
697 // sh_type: SHT_STRTAB
700 0, 0, 0, 0, 0, 0, 0, 0,
702 0, 0, 0, 0, 0, 0, 0, 0,
703 // sh_offset: after .symtab section. 432 == 0x1b0
704 0xb0, 0x1, 0, 0, 0, 0, 0, 0,
705 // sh_size: 1 null byte + "test\0"
706 6, 0, 0, 0, 0, 0, 0, 0,
712 1, 0, 0, 0, 0, 0, 0, 0,
714 0, 0, 0, 0, 0, 0, 0, 0,
718 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
720 // sh_type: SHT_STRTAB
723 0, 0, 0, 0, 0, 0, 0, 0,
725 0, 0, 0, 0, 0, 0, 0, 0,
726 // sh_offset: after .strtab section. 438 == 0x1b6
727 0xb6, 0x1, 0, 0, 0, 0, 0, 0,
728 // sh_size: all section names
729 33, 0, 0, 0, 0, 0, 0, 0,
735 1, 0, 0, 0, 0, 0, 0, 0,
737 0, 0, 0, 0, 0, 0, 0, 0,
740 // Contents of .symtab section
742 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
743 0, 0, 0, 0, 0, 0, 0, 0,
749 // st_info: STT_NOTYPE, STB_GLOBAL
753 // st_shndx: In .test
756 0, 0, 0, 0, 0, 0, 0, 0,
758 0, 0, 0, 0, 0, 0, 0, 0,
761 // Contents of .strtab section
763 't', 'e', 's', 't', '\0',
766 // Contents of .shstrtab section
768 '.', 't', 'e', 's', 't', '\0',
769 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
770 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
771 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
774 const unsigned int test_file_1_size_64_little
= sizeof test_file_1_64_little
;
776 // 64-bit big-endian version of test_file_1_32_little.
778 const unsigned char test_file_1_64_big
[] =
785 // EI_DATA: big endian
797 // e_machine: a magic value used for testing.
802 0, 0, 0, 0, 0, 0, 0, 0,
804 0, 0, 0, 0, 0, 0, 0, 0,
805 // e_shoff: starts right after file header
806 0, 0, 0, 0, 0, 0, 0, 64,
817 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
823 // Shdr 0: dummy entry
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,
827 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
831 // sh_name: after initial null
833 // sh_type: SHT_PROGBITS
835 // sh_flags: SHF_ALLOC
836 0, 0, 0, 0, 0, 0, 0, 2,
838 0, 0, 0, 0, 0, 0, 0, 0,
839 // sh_offset: after file header + 5 section headers. 384 == 0x180.
840 0, 0, 0, 0, 0, 0, 0x1, 0x80,
842 0, 0, 0, 0, 0, 0, 0, 0,
848 0, 0, 0, 0, 0, 0, 0, 1,
850 0, 0, 0, 0, 0, 0, 0, 0,
854 // sh_name: 1 null byte + ".test\0"
856 // sh_type: SHT_SYMTAB
859 0, 0, 0, 0, 0, 0, 0, 0,
861 0, 0, 0, 0, 0, 0, 0, 0,
862 // sh_offset: after file header + 5 section headers + empty section
864 0, 0, 0, 0, 0, 0, 0x1, 0x80,
865 // sh_size: two symbols: dummy symbol + test symbol
866 0, 0, 0, 0, 0, 0, 0, 48,
867 // sh_link: to .strtab
869 // sh_info: one local symbol, the dummy symbol
872 0, 0, 0, 0, 0, 0, 0, 8,
873 // sh_entsize: size of symbol
874 0, 0, 0, 0, 0, 0, 0, 24,
878 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
880 // sh_type: SHT_STRTAB
883 0, 0, 0, 0, 0, 0, 0, 0,
885 0, 0, 0, 0, 0, 0, 0, 0,
886 // sh_offset: after .symtab section. 432 == 0x1b0
887 0, 0, 0, 0, 0, 0, 0x1, 0xb0,
888 // sh_size: 1 null byte + "test\0"
889 0, 0, 0, 0, 0, 0, 0, 6,
895 0, 0, 0, 0, 0, 0, 0, 1,
897 0, 0, 0, 0, 0, 0, 0, 0,
901 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
903 // sh_type: SHT_STRTAB
906 0, 0, 0, 0, 0, 0, 0, 0,
908 0, 0, 0, 0, 0, 0, 0, 0,
909 // sh_offset: after .strtab section. 438 == 0x1b6
910 0, 0, 0, 0, 0, 0, 0x1, 0xb6,
911 // sh_size: all section names
912 0, 0, 0, 0, 0, 0, 0, 33,
918 0, 0, 0, 0, 0, 0, 0, 1,
920 0, 0, 0, 0, 0, 0, 0, 0,
923 // Contents of .symtab section
925 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
926 0, 0, 0, 0, 0, 0, 0, 0,
932 // st_info: STT_NOTYPE, STB_GLOBAL
936 // st_shndx: In .test
939 0, 0, 0, 0, 0, 0, 0, 0,
941 0, 0, 0, 0, 0, 0, 0, 0,
944 // Contents of .strtab section
946 't', 'e', 's', 't', '\0',
949 // Contents of .shstrtab section
951 '.', 't', 'e', 's', 't', '\0',
952 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
953 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
954 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
957 const unsigned int test_file_1_size_64_big
= sizeof test_file_1_64_big
;
959 } // End namespace gold_testsuite.