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, Output_section*,
50 bool, size_t, const unsigned char*)
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, Output_section*, bool,
56 unsigned char*, typename elfcpp::Elf_types<size>::Elf_Addr,
58 { ERROR("call to Target_test::relocate_section"); }
60 static const Target::Target_info test_target_info;
63 template<int size, bool big_endian>
64 const Target::Target_info Target_test<size, big_endian>::test_target_info =
67 big_endian, // is_big_endian
68 static_cast<elfcpp::EM>(0xffff), // machine_code
69 false, // has_make_symbol
71 false, // has_code_fill
72 false, // is_default_stack_executable
73 "/dummy", // dynamic_linker
74 0x08000000, // default_text_segment_address
75 0x1000, // abi_pagesize
76 0x1000 // common_pagesize
81 #ifdef HAVE_TARGET_32_LITTLE
82 Target_test<32, false> target_test_32_little;
85 #ifdef HAVE_TARGET_32_BIG
86 Target_test<32, true> target_test_32_big;
89 #ifdef HAVE_TARGET_64_LITTLE
90 Target_test<64, false> target_test_64_little;
93 #ifdef HAVE_TARGET_64_BIG
94 Target_test<64, true> target_test_64_big;
97 // A pointer to the test targets. This is used in CHECKs.
99 #ifdef HAVE_TARGET_32_LITTLE
100 Target* target_test_pointer_32_little = &target_test_32_little;
103 #ifdef HAVE_TARGET_32_BIG
104 Target* target_test_pointer_32_big = &target_test_32_big;
107 #ifdef HAVE_TARGET_64_LITTLE
108 Target* target_test_pointer_64_little = &target_test_64_little;
111 #ifdef HAVE_TARGET_64_BIG
112 Target* target_test_pointer_64_big = &target_test_64_big;
115 // Select the test targets.
117 template<int size, bool big_endian>
118 class Target_selector_test : public Target_selector
121 Target_selector_test()
122 : Target_selector(0xffff, size, big_endian)
126 recognize(int, int, int)
132 #ifdef HAVE_TARGET_32_LITTLE
133 return &target_test_32_little;
138 #ifdef HAVE_TARGET_32_BIG
139 return &target_test_32_big;
147 #ifdef HAVE_TARGET_64_LITTLE
148 return &target_test_64_little;
153 #ifdef HAVE_TARGET_64_BIG
154 return &target_test_64_big;
163 // Register the test target selectors. These don't need to be
164 // conditionally compiled, as they will return NULL if there is no
167 Target_selector_test<32, false> target_selector_test_32_little;
168 Target_selector_test<32, true> target_selector_test_32_big;
169 Target_selector_test<64, false> target_selector_test_64_little;
170 Target_selector_test<64, true> target_selector_test_64_big;
172 // A simple ELF object with one empty section, named ".test" and one
173 // globally visible symbol named "test".
175 const unsigned char test_file_1_32_little[] =
182 // EI_DATA: little endian
194 // e_machine: a magic value used for testing.
202 // e_shoff: starts right after file header
214 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
220 // Shdr 0: dummy entry
221 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
222 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
223 0, 0, 0, 0, 0, 0, 0, 0,
227 // sh_name: after initial null
229 // sh_type: SHT_PROGBITS
231 // sh_flags: SHF_ALLOC
235 // sh_offset: after file header + 5 section headers
250 // sh_name: 1 null byte + ".test\0"
252 // sh_type: SHT_SYMTAB
258 // sh_offset: after file header + 5 section headers + empty section
260 // sh_size: two symbols: dummy symbol + test symbol
262 // sh_link: to .strtab
264 // sh_info: one local symbol, the dummy symbol
268 // sh_entsize: size of symbol
273 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
275 // sh_type: SHT_STRTAB
281 // sh_offset: after .symtab section. 284 == 0x11c
283 // sh_size: 1 null byte + "test\0"
296 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
298 // sh_type: SHT_STRTAB
304 // sh_offset: after .strtab section. 290 == 0x122
306 // sh_size: all section names
318 // Contents of .symtab section
320 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
330 // st_info: STT_NOTYPE, STB_GLOBAL
334 // st_shndx: In .test
338 // Contents of .strtab section
340 't', 'e', 's', 't', '\0',
343 // Contents of .shstrtab section
345 '.', 't', 'e', 's', 't', '\0',
346 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
347 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
348 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
351 const unsigned int test_file_1_size_32_little = sizeof test_file_1_32_little;
353 // 32-bit big-endian version of test_file_1_32_little.
355 const unsigned char test_file_1_32_big[] =
362 // EI_DATA: big endian
374 // e_machine: a magic value used for testing.
382 // e_shoff: starts right after file header
394 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
400 // Shdr 0: dummy entry
401 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
402 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
403 0, 0, 0, 0, 0, 0, 0, 0,
407 // sh_name: after initial null
409 // sh_type: SHT_PROGBITS
411 // sh_flags: SHF_ALLOC
415 // sh_offset: after file header + 5 section headers
430 // sh_name: 1 null byte + ".test\0"
432 // sh_type: SHT_SYMTAB
438 // sh_offset: after file header + 5 section headers + empty section
440 // sh_size: two symbols: dummy symbol + test symbol
442 // sh_link: to .strtab
444 // sh_info: one local symbol, the dummy symbol
448 // sh_entsize: size of symbol
453 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
455 // sh_type: SHT_STRTAB
461 // sh_offset: after .symtab section. 284 == 0x11c
463 // sh_size: 1 null byte + "test\0"
476 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
478 // sh_type: SHT_STRTAB
484 // sh_offset: after .strtab section. 290 == 0x122
486 // sh_size: all section names
498 // Contents of .symtab section
500 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
510 // st_info: STT_NOTYPE, STB_GLOBAL
514 // st_shndx: In .test
518 // Contents of .strtab section
520 't', 'e', 's', 't', '\0',
523 // Contents of .shstrtab section
525 '.', 't', 'e', 's', 't', '\0',
526 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
527 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
528 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
531 const unsigned int test_file_1_size_32_big = sizeof test_file_1_32_big;
533 // 64-bit little-endian version of test_file_1_32_little.
535 const unsigned char test_file_1_64_little[] =
542 // EI_DATA: little endian
554 // e_machine: a magic value used for testing.
559 0, 0, 0, 0, 0, 0, 0, 0,
561 0, 0, 0, 0, 0, 0, 0, 0,
562 // e_shoff: starts right after file header
563 64, 0, 0, 0, 0, 0, 0, 0,
574 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
580 // Shdr 0: dummy entry
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,
583 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
584 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
588 // sh_name: after initial null
590 // sh_type: SHT_PROGBITS
592 // sh_flags: SHF_ALLOC
593 2, 0, 0, 0, 0, 0, 0, 0,
595 0, 0, 0, 0, 0, 0, 0, 0,
596 // sh_offset: after file header + 5 section headers. 384 == 0x180.
597 0x80, 0x1, 0, 0, 0, 0, 0, 0,
599 0, 0, 0, 0, 0, 0, 0, 0,
605 1, 0, 0, 0, 0, 0, 0, 0,
607 0, 0, 0, 0, 0, 0, 0, 0,
611 // sh_name: 1 null byte + ".test\0"
613 // sh_type: SHT_SYMTAB
616 0, 0, 0, 0, 0, 0, 0, 0,
618 0, 0, 0, 0, 0, 0, 0, 0,
619 // sh_offset: after file header + 5 section headers + empty section
621 0x80, 0x1, 0, 0, 0, 0, 0, 0,
622 // sh_size: two symbols: dummy symbol + test symbol
623 48, 0, 0, 0, 0, 0, 0, 0,
624 // sh_link: to .strtab
626 // sh_info: one local symbol, the dummy symbol
629 8, 0, 0, 0, 0, 0, 0, 0,
630 // sh_entsize: size of symbol
631 24, 0, 0, 0, 0, 0, 0, 0,
635 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
637 // sh_type: SHT_STRTAB
640 0, 0, 0, 0, 0, 0, 0, 0,
642 0, 0, 0, 0, 0, 0, 0, 0,
643 // sh_offset: after .symtab section. 432 == 0x1b0
644 0xb0, 0x1, 0, 0, 0, 0, 0, 0,
645 // sh_size: 1 null byte + "test\0"
646 6, 0, 0, 0, 0, 0, 0, 0,
652 1, 0, 0, 0, 0, 0, 0, 0,
654 0, 0, 0, 0, 0, 0, 0, 0,
658 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
660 // sh_type: SHT_STRTAB
663 0, 0, 0, 0, 0, 0, 0, 0,
665 0, 0, 0, 0, 0, 0, 0, 0,
666 // sh_offset: after .strtab section. 438 == 0x1b6
667 0xb6, 0x1, 0, 0, 0, 0, 0, 0,
668 // sh_size: all section names
669 33, 0, 0, 0, 0, 0, 0, 0,
675 1, 0, 0, 0, 0, 0, 0, 0,
677 0, 0, 0, 0, 0, 0, 0, 0,
680 // Contents of .symtab section
682 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
683 0, 0, 0, 0, 0, 0, 0, 0,
689 // st_info: STT_NOTYPE, STB_GLOBAL
693 // st_shndx: In .test
696 0, 0, 0, 0, 0, 0, 0, 0,
698 0, 0, 0, 0, 0, 0, 0, 0,
701 // Contents of .strtab section
703 't', 'e', 's', 't', '\0',
706 // Contents of .shstrtab section
708 '.', 't', 'e', 's', 't', '\0',
709 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
710 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
711 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
714 const unsigned int test_file_1_size_64_little = sizeof test_file_1_64_little;
716 // 64-bit big-endian version of test_file_1_32_little.
718 const unsigned char test_file_1_64_big[] =
725 // EI_DATA: big endian
737 // e_machine: a magic value used for testing.
742 0, 0, 0, 0, 0, 0, 0, 0,
744 0, 0, 0, 0, 0, 0, 0, 0,
745 // e_shoff: starts right after file header
746 0, 0, 0, 0, 0, 0, 0, 64,
757 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
763 // Shdr 0: dummy entry
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,
766 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
767 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
771 // sh_name: after initial null
773 // sh_type: SHT_PROGBITS
775 // sh_flags: SHF_ALLOC
776 0, 0, 0, 0, 0, 0, 0, 2,
778 0, 0, 0, 0, 0, 0, 0, 0,
779 // sh_offset: after file header + 5 section headers. 384 == 0x180.
780 0, 0, 0, 0, 0, 0, 0x1, 0x80,
782 0, 0, 0, 0, 0, 0, 0, 0,
788 0, 0, 0, 0, 0, 0, 0, 1,
790 0, 0, 0, 0, 0, 0, 0, 0,
794 // sh_name: 1 null byte + ".test\0"
796 // sh_type: SHT_SYMTAB
799 0, 0, 0, 0, 0, 0, 0, 0,
801 0, 0, 0, 0, 0, 0, 0, 0,
802 // sh_offset: after file header + 5 section headers + empty section
804 0, 0, 0, 0, 0, 0, 0x1, 0x80,
805 // sh_size: two symbols: dummy symbol + test symbol
806 0, 0, 0, 0, 0, 0, 0, 48,
807 // sh_link: to .strtab
809 // sh_info: one local symbol, the dummy symbol
812 0, 0, 0, 0, 0, 0, 0, 8,
813 // sh_entsize: size of symbol
814 0, 0, 0, 0, 0, 0, 0, 24,
818 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
820 // sh_type: SHT_STRTAB
823 0, 0, 0, 0, 0, 0, 0, 0,
825 0, 0, 0, 0, 0, 0, 0, 0,
826 // sh_offset: after .symtab section. 432 == 0x1b0
827 0, 0, 0, 0, 0, 0, 0x1, 0xb0,
828 // sh_size: 1 null byte + "test\0"
829 0, 0, 0, 0, 0, 0, 0, 6,
835 0, 0, 0, 0, 0, 0, 0, 1,
837 0, 0, 0, 0, 0, 0, 0, 0,
841 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
843 // sh_type: SHT_STRTAB
846 0, 0, 0, 0, 0, 0, 0, 0,
848 0, 0, 0, 0, 0, 0, 0, 0,
849 // sh_offset: after .strtab section. 438 == 0x1b6
850 0, 0, 0, 0, 0, 0, 0x1, 0xb6,
851 // sh_size: all section names
852 0, 0, 0, 0, 0, 0, 0, 33,
858 0, 0, 0, 0, 0, 0, 0, 1,
860 0, 0, 0, 0, 0, 0, 0, 0,
863 // Contents of .symtab section
865 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
866 0, 0, 0, 0, 0, 0, 0, 0,
872 // st_info: STT_NOTYPE, STB_GLOBAL
876 // st_shndx: In .test
879 0, 0, 0, 0, 0, 0, 0, 0,
881 0, 0, 0, 0, 0, 0, 0, 0,
884 // Contents of .strtab section
886 't', 'e', 's', 't', '\0',
889 // Contents of .shstrtab section
891 '.', 't', 'e', 's', 't', '\0',
892 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
893 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
894 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
897 const unsigned int test_file_1_size_64_big = sizeof test_file_1_64_big;
899 } // End namespace gold_testsuite.