1 // testfile.cc -- Dummy ELF objects for testing purposes.
3 // Copyright (C) 2006-2016 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
,
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
112 32, // hash_entry_size
117 #ifdef HAVE_TARGET_32_LITTLE
118 Target_test
<32, false> target_test_32_little
;
121 #ifdef HAVE_TARGET_32_BIG
122 Target_test
<32, true> target_test_32_big
;
125 #ifdef HAVE_TARGET_64_LITTLE
126 Target_test
<64, false> target_test_64_little
;
129 #ifdef HAVE_TARGET_64_BIG
130 Target_test
<64, true> target_test_64_big
;
133 // A pointer to the test targets. This is used in CHECKs.
135 #ifdef HAVE_TARGET_32_LITTLE
136 Target
* target_test_pointer_32_little
= &target_test_32_little
;
139 #ifdef HAVE_TARGET_32_BIG
140 Target
* target_test_pointer_32_big
= &target_test_32_big
;
143 #ifdef HAVE_TARGET_64_LITTLE
144 Target
* target_test_pointer_64_little
= &target_test_64_little
;
147 #ifdef HAVE_TARGET_64_BIG
148 Target
* target_test_pointer_64_big
= &target_test_64_big
;
151 // Select the test targets.
153 template<int size
, bool big_endian
>
154 class Target_selector_test
: public Target_selector
157 Target_selector_test()
158 : Target_selector(0xffff, size
, big_endian
, NULL
, NULL
)
162 do_instantiate_target()
169 do_recognize(Input_file
*, off_t
, int, int, int)
175 #ifdef HAVE_TARGET_32_LITTLE
176 return &target_test_32_little
;
181 #ifdef HAVE_TARGET_32_BIG
182 return &target_test_32_big
;
190 #ifdef HAVE_TARGET_64_LITTLE
191 return &target_test_64_little
;
196 #ifdef HAVE_TARGET_64_BIG
197 return &target_test_64_big
;
206 do_recognize_by_name(const char*)
210 do_supported_names(std::vector
<const char*>*)
214 // Register the test target selectors. These don't need to be
215 // conditionally compiled, as they will return NULL if there is no
218 Target_selector_test
<32, false> target_selector_test_32_little
;
219 Target_selector_test
<32, true> target_selector_test_32_big
;
220 Target_selector_test
<64, false> target_selector_test_64_little
;
221 Target_selector_test
<64, true> target_selector_test_64_big
;
223 // A simple ELF object with one empty section, named ".test" and one
224 // globally visible symbol named "test".
226 const unsigned char test_file_1_32_little
[] =
233 // EI_DATA: little endian
245 // e_machine: a magic value used for testing.
253 // e_shoff: starts right after file header
265 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
271 // Shdr 0: dummy entry
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, 0, 0, 0, 0, 0, 0, 0, 0,
274 0, 0, 0, 0, 0, 0, 0, 0,
278 // sh_name: after initial null
280 // sh_type: SHT_PROGBITS
282 // sh_flags: SHF_ALLOC
286 // sh_offset: after file header + 5 section headers
301 // sh_name: 1 null byte + ".test\0"
303 // sh_type: SHT_SYMTAB
309 // sh_offset: after file header + 5 section headers + empty section
311 // sh_size: two symbols: dummy symbol + test symbol
313 // sh_link: to .strtab
315 // sh_info: one local symbol, the dummy symbol
319 // sh_entsize: size of symbol
324 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
326 // sh_type: SHT_STRTAB
332 // sh_offset: after .symtab section. 284 == 0x11c
334 // sh_size: 1 null byte + "test\0"
347 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
349 // sh_type: SHT_STRTAB
355 // sh_offset: after .strtab section. 290 == 0x122
357 // sh_size: all section names
369 // Contents of .symtab section
371 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
381 // st_info: STT_NOTYPE, STB_GLOBAL
385 // st_shndx: In .test
389 // Contents of .strtab section
391 't', 'e', 's', 't', '\0',
394 // Contents of .shstrtab section
396 '.', 't', 'e', 's', 't', '\0',
397 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
398 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
399 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
402 const unsigned int test_file_1_size_32_little
= sizeof test_file_1_32_little
;
404 // 32-bit big-endian version of test_file_1_32_little.
406 const unsigned char test_file_1_32_big
[] =
413 // EI_DATA: big endian
425 // e_machine: a magic value used for testing.
433 // e_shoff: starts right after file header
445 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
451 // Shdr 0: dummy entry
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, 0, 0, 0, 0, 0, 0, 0, 0,
454 0, 0, 0, 0, 0, 0, 0, 0,
458 // sh_name: after initial null
460 // sh_type: SHT_PROGBITS
462 // sh_flags: SHF_ALLOC
466 // sh_offset: after file header + 5 section headers
481 // sh_name: 1 null byte + ".test\0"
483 // sh_type: SHT_SYMTAB
489 // sh_offset: after file header + 5 section headers + empty section
491 // sh_size: two symbols: dummy symbol + test symbol
493 // sh_link: to .strtab
495 // sh_info: one local symbol, the dummy symbol
499 // sh_entsize: size of symbol
504 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
506 // sh_type: SHT_STRTAB
512 // sh_offset: after .symtab section. 284 == 0x11c
514 // sh_size: 1 null byte + "test\0"
527 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
529 // sh_type: SHT_STRTAB
535 // sh_offset: after .strtab section. 290 == 0x122
537 // sh_size: all section names
549 // Contents of .symtab section
551 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
561 // st_info: STT_NOTYPE, STB_GLOBAL
565 // st_shndx: In .test
569 // Contents of .strtab section
571 't', 'e', 's', 't', '\0',
574 // Contents of .shstrtab section
576 '.', 't', 'e', 's', 't', '\0',
577 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
578 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
579 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
582 const unsigned int test_file_1_size_32_big
= sizeof test_file_1_32_big
;
584 // 64-bit little-endian version of test_file_1_32_little.
586 const unsigned char test_file_1_64_little
[] =
593 // EI_DATA: little endian
605 // e_machine: a magic value used for testing.
610 0, 0, 0, 0, 0, 0, 0, 0,
612 0, 0, 0, 0, 0, 0, 0, 0,
613 // e_shoff: starts right after file header
614 64, 0, 0, 0, 0, 0, 0, 0,
625 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
631 // Shdr 0: dummy entry
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,
635 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
639 // sh_name: after initial null
641 // sh_type: SHT_PROGBITS
643 // sh_flags: SHF_ALLOC
644 2, 0, 0, 0, 0, 0, 0, 0,
646 0, 0, 0, 0, 0, 0, 0, 0,
647 // sh_offset: after file header + 5 section headers. 384 == 0x180.
648 0x80, 0x1, 0, 0, 0, 0, 0, 0,
650 0, 0, 0, 0, 0, 0, 0, 0,
656 1, 0, 0, 0, 0, 0, 0, 0,
658 0, 0, 0, 0, 0, 0, 0, 0,
662 // sh_name: 1 null byte + ".test\0"
664 // sh_type: SHT_SYMTAB
667 0, 0, 0, 0, 0, 0, 0, 0,
669 0, 0, 0, 0, 0, 0, 0, 0,
670 // sh_offset: after file header + 5 section headers + empty section
672 0x80, 0x1, 0, 0, 0, 0, 0, 0,
673 // sh_size: two symbols: dummy symbol + test symbol
674 48, 0, 0, 0, 0, 0, 0, 0,
675 // sh_link: to .strtab
677 // sh_info: one local symbol, the dummy symbol
680 8, 0, 0, 0, 0, 0, 0, 0,
681 // sh_entsize: size of symbol
682 24, 0, 0, 0, 0, 0, 0, 0,
686 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
688 // sh_type: SHT_STRTAB
691 0, 0, 0, 0, 0, 0, 0, 0,
693 0, 0, 0, 0, 0, 0, 0, 0,
694 // sh_offset: after .symtab section. 432 == 0x1b0
695 0xb0, 0x1, 0, 0, 0, 0, 0, 0,
696 // sh_size: 1 null byte + "test\0"
697 6, 0, 0, 0, 0, 0, 0, 0,
703 1, 0, 0, 0, 0, 0, 0, 0,
705 0, 0, 0, 0, 0, 0, 0, 0,
709 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
711 // sh_type: SHT_STRTAB
714 0, 0, 0, 0, 0, 0, 0, 0,
716 0, 0, 0, 0, 0, 0, 0, 0,
717 // sh_offset: after .strtab section. 438 == 0x1b6
718 0xb6, 0x1, 0, 0, 0, 0, 0, 0,
719 // sh_size: all section names
720 33, 0, 0, 0, 0, 0, 0, 0,
726 1, 0, 0, 0, 0, 0, 0, 0,
728 0, 0, 0, 0, 0, 0, 0, 0,
731 // Contents of .symtab section
733 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
734 0, 0, 0, 0, 0, 0, 0, 0,
740 // st_info: STT_NOTYPE, STB_GLOBAL
744 // st_shndx: In .test
747 0, 0, 0, 0, 0, 0, 0, 0,
749 0, 0, 0, 0, 0, 0, 0, 0,
752 // Contents of .strtab section
754 't', 'e', 's', 't', '\0',
757 // Contents of .shstrtab section
759 '.', 't', 'e', 's', 't', '\0',
760 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
761 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
762 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
765 const unsigned int test_file_1_size_64_little
= sizeof test_file_1_64_little
;
767 // 64-bit big-endian version of test_file_1_32_little.
769 const unsigned char test_file_1_64_big
[] =
776 // EI_DATA: big endian
788 // e_machine: a magic value used for testing.
793 0, 0, 0, 0, 0, 0, 0, 0,
795 0, 0, 0, 0, 0, 0, 0, 0,
796 // e_shoff: starts right after file header
797 0, 0, 0, 0, 0, 0, 0, 64,
808 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
814 // Shdr 0: dummy entry
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,
818 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
822 // sh_name: after initial null
824 // sh_type: SHT_PROGBITS
826 // sh_flags: SHF_ALLOC
827 0, 0, 0, 0, 0, 0, 0, 2,
829 0, 0, 0, 0, 0, 0, 0, 0,
830 // sh_offset: after file header + 5 section headers. 384 == 0x180.
831 0, 0, 0, 0, 0, 0, 0x1, 0x80,
833 0, 0, 0, 0, 0, 0, 0, 0,
839 0, 0, 0, 0, 0, 0, 0, 1,
841 0, 0, 0, 0, 0, 0, 0, 0,
845 // sh_name: 1 null byte + ".test\0"
847 // sh_type: SHT_SYMTAB
850 0, 0, 0, 0, 0, 0, 0, 0,
852 0, 0, 0, 0, 0, 0, 0, 0,
853 // sh_offset: after file header + 5 section headers + empty section
855 0, 0, 0, 0, 0, 0, 0x1, 0x80,
856 // sh_size: two symbols: dummy symbol + test symbol
857 0, 0, 0, 0, 0, 0, 0, 48,
858 // sh_link: to .strtab
860 // sh_info: one local symbol, the dummy symbol
863 0, 0, 0, 0, 0, 0, 0, 8,
864 // sh_entsize: size of symbol
865 0, 0, 0, 0, 0, 0, 0, 24,
869 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
871 // sh_type: SHT_STRTAB
874 0, 0, 0, 0, 0, 0, 0, 0,
876 0, 0, 0, 0, 0, 0, 0, 0,
877 // sh_offset: after .symtab section. 432 == 0x1b0
878 0, 0, 0, 0, 0, 0, 0x1, 0xb0,
879 // sh_size: 1 null byte + "test\0"
880 0, 0, 0, 0, 0, 0, 0, 6,
886 0, 0, 0, 0, 0, 0, 0, 1,
888 0, 0, 0, 0, 0, 0, 0, 0,
892 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
894 // sh_type: SHT_STRTAB
897 0, 0, 0, 0, 0, 0, 0, 0,
899 0, 0, 0, 0, 0, 0, 0, 0,
900 // sh_offset: after .strtab section. 438 == 0x1b6
901 0, 0, 0, 0, 0, 0, 0x1, 0xb6,
902 // sh_size: all section names
903 0, 0, 0, 0, 0, 0, 0, 33,
909 0, 0, 0, 0, 0, 0, 0, 1,
911 0, 0, 0, 0, 0, 0, 0, 0,
914 // Contents of .symtab section
916 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
917 0, 0, 0, 0, 0, 0, 0, 0,
923 // st_info: STT_NOTYPE, STB_GLOBAL
927 // st_shndx: In .test
930 0, 0, 0, 0, 0, 0, 0, 0,
932 0, 0, 0, 0, 0, 0, 0, 0,
935 // Contents of .strtab section
937 't', 'e', 's', 't', '\0',
940 // Contents of .shstrtab section
942 '.', 't', 'e', 's', 't', '\0',
943 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
944 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
945 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
948 const unsigned int test_file_1_size_64_big
= sizeof test_file_1_64_big
;
950 } // End namespace gold_testsuite.