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"); }
61 scan_relocatable_relocs(const General_options
&, Symbol_table
*, Layout
*,
62 Sized_relobj
<size
, big_endian
>*, unsigned int,
63 unsigned int, const unsigned char*,
64 size_t, Output_section
*, bool, size_t,
65 const unsigned char*, Relocatable_relocs
*)
66 { ERROR("call to Target_test::scan_relocatable_relocs"); }
69 relocate_for_relocatable(const Relocate_info
<size
, big_endian
>*,
70 unsigned int, const unsigned char*, size_t,
71 Output_section
*, off_t
, const Relocatable_relocs
*,
73 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
74 section_size_type
, unsigned char*,
76 { ERROR("call to Target_test::relocate_for_relocatable"); }
78 static const Target::Target_info test_target_info
;
81 template<int size
, bool big_endian
>
82 const Target::Target_info Target_test
<size
, big_endian
>::test_target_info
=
85 big_endian
, // is_big_endian
86 static_cast<elfcpp::EM
>(0xffff), // machine_code
87 false, // has_make_symbol
89 false, // has_code_fill
90 false, // is_default_stack_executable
91 "/dummy", // dynamic_linker
92 0x08000000, // default_text_segment_address
93 0x1000, // abi_pagesize
94 0x1000 // common_pagesize
99 #ifdef HAVE_TARGET_32_LITTLE
100 Target_test
<32, false> target_test_32_little
;
103 #ifdef HAVE_TARGET_32_BIG
104 Target_test
<32, true> target_test_32_big
;
107 #ifdef HAVE_TARGET_64_LITTLE
108 Target_test
<64, false> target_test_64_little
;
111 #ifdef HAVE_TARGET_64_BIG
112 Target_test
<64, true> target_test_64_big
;
115 // A pointer to the test targets. This is used in CHECKs.
117 #ifdef HAVE_TARGET_32_LITTLE
118 Target
* target_test_pointer_32_little
= &target_test_32_little
;
121 #ifdef HAVE_TARGET_32_BIG
122 Target
* target_test_pointer_32_big
= &target_test_32_big
;
125 #ifdef HAVE_TARGET_64_LITTLE
126 Target
* target_test_pointer_64_little
= &target_test_64_little
;
129 #ifdef HAVE_TARGET_64_BIG
130 Target
* target_test_pointer_64_big
= &target_test_64_big
;
133 // Select the test targets.
135 template<int size
, bool big_endian
>
136 class Target_selector_test
: public Target_selector
139 Target_selector_test()
140 : Target_selector(0xffff, size
, big_endian
)
144 recognize(int, int, int)
150 #ifdef HAVE_TARGET_32_LITTLE
151 return &target_test_32_little
;
156 #ifdef HAVE_TARGET_32_BIG
157 return &target_test_32_big
;
165 #ifdef HAVE_TARGET_64_LITTLE
166 return &target_test_64_little
;
171 #ifdef HAVE_TARGET_64_BIG
172 return &target_test_64_big
;
181 // Register the test target selectors. These don't need to be
182 // conditionally compiled, as they will return NULL if there is no
185 Target_selector_test
<32, false> target_selector_test_32_little
;
186 Target_selector_test
<32, true> target_selector_test_32_big
;
187 Target_selector_test
<64, false> target_selector_test_64_little
;
188 Target_selector_test
<64, true> target_selector_test_64_big
;
190 // A simple ELF object with one empty section, named ".test" and one
191 // globally visible symbol named "test".
193 const unsigned char test_file_1_32_little
[] =
200 // EI_DATA: little endian
212 // e_machine: a magic value used for testing.
220 // e_shoff: starts right after file header
232 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
238 // Shdr 0: dummy entry
239 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
240 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
241 0, 0, 0, 0, 0, 0, 0, 0,
245 // sh_name: after initial null
247 // sh_type: SHT_PROGBITS
249 // sh_flags: SHF_ALLOC
253 // sh_offset: after file header + 5 section headers
268 // sh_name: 1 null byte + ".test\0"
270 // sh_type: SHT_SYMTAB
276 // sh_offset: after file header + 5 section headers + empty section
278 // sh_size: two symbols: dummy symbol + test symbol
280 // sh_link: to .strtab
282 // sh_info: one local symbol, the dummy symbol
286 // sh_entsize: size of symbol
291 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
293 // sh_type: SHT_STRTAB
299 // sh_offset: after .symtab section. 284 == 0x11c
301 // sh_size: 1 null byte + "test\0"
314 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
316 // sh_type: SHT_STRTAB
322 // sh_offset: after .strtab section. 290 == 0x122
324 // sh_size: all section names
336 // Contents of .symtab section
338 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
348 // st_info: STT_NOTYPE, STB_GLOBAL
352 // st_shndx: In .test
356 // Contents of .strtab section
358 't', 'e', 's', 't', '\0',
361 // Contents of .shstrtab section
363 '.', 't', 'e', 's', 't', '\0',
364 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
365 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
366 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
369 const unsigned int test_file_1_size_32_little
= sizeof test_file_1_32_little
;
371 // 32-bit big-endian version of test_file_1_32_little.
373 const unsigned char test_file_1_32_big
[] =
380 // EI_DATA: big endian
392 // e_machine: a magic value used for testing.
400 // e_shoff: starts right after file header
412 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
418 // Shdr 0: dummy entry
419 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
420 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
421 0, 0, 0, 0, 0, 0, 0, 0,
425 // sh_name: after initial null
427 // sh_type: SHT_PROGBITS
429 // sh_flags: SHF_ALLOC
433 // sh_offset: after file header + 5 section headers
448 // sh_name: 1 null byte + ".test\0"
450 // sh_type: SHT_SYMTAB
456 // sh_offset: after file header + 5 section headers + empty section
458 // sh_size: two symbols: dummy symbol + test symbol
460 // sh_link: to .strtab
462 // sh_info: one local symbol, the dummy symbol
466 // sh_entsize: size of symbol
471 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
473 // sh_type: SHT_STRTAB
479 // sh_offset: after .symtab section. 284 == 0x11c
481 // sh_size: 1 null byte + "test\0"
494 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
496 // sh_type: SHT_STRTAB
502 // sh_offset: after .strtab section. 290 == 0x122
504 // sh_size: all section names
516 // Contents of .symtab section
518 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
528 // st_info: STT_NOTYPE, STB_GLOBAL
532 // st_shndx: In .test
536 // Contents of .strtab section
538 't', 'e', 's', 't', '\0',
541 // Contents of .shstrtab section
543 '.', 't', 'e', 's', 't', '\0',
544 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
545 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
546 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
549 const unsigned int test_file_1_size_32_big
= sizeof test_file_1_32_big
;
551 // 64-bit little-endian version of test_file_1_32_little.
553 const unsigned char test_file_1_64_little
[] =
560 // EI_DATA: little endian
572 // e_machine: a magic value used for testing.
577 0, 0, 0, 0, 0, 0, 0, 0,
579 0, 0, 0, 0, 0, 0, 0, 0,
580 // e_shoff: starts right after file header
581 64, 0, 0, 0, 0, 0, 0, 0,
592 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
598 // Shdr 0: dummy entry
599 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
600 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
601 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
602 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
606 // sh_name: after initial null
608 // sh_type: SHT_PROGBITS
610 // sh_flags: SHF_ALLOC
611 2, 0, 0, 0, 0, 0, 0, 0,
613 0, 0, 0, 0, 0, 0, 0, 0,
614 // sh_offset: after file header + 5 section headers. 384 == 0x180.
615 0x80, 0x1, 0, 0, 0, 0, 0, 0,
617 0, 0, 0, 0, 0, 0, 0, 0,
623 1, 0, 0, 0, 0, 0, 0, 0,
625 0, 0, 0, 0, 0, 0, 0, 0,
629 // sh_name: 1 null byte + ".test\0"
631 // sh_type: SHT_SYMTAB
634 0, 0, 0, 0, 0, 0, 0, 0,
636 0, 0, 0, 0, 0, 0, 0, 0,
637 // sh_offset: after file header + 5 section headers + empty section
639 0x80, 0x1, 0, 0, 0, 0, 0, 0,
640 // sh_size: two symbols: dummy symbol + test symbol
641 48, 0, 0, 0, 0, 0, 0, 0,
642 // sh_link: to .strtab
644 // sh_info: one local symbol, the dummy symbol
647 8, 0, 0, 0, 0, 0, 0, 0,
648 // sh_entsize: size of symbol
649 24, 0, 0, 0, 0, 0, 0, 0,
653 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
655 // sh_type: SHT_STRTAB
658 0, 0, 0, 0, 0, 0, 0, 0,
660 0, 0, 0, 0, 0, 0, 0, 0,
661 // sh_offset: after .symtab section. 432 == 0x1b0
662 0xb0, 0x1, 0, 0, 0, 0, 0, 0,
663 // sh_size: 1 null byte + "test\0"
664 6, 0, 0, 0, 0, 0, 0, 0,
670 1, 0, 0, 0, 0, 0, 0, 0,
672 0, 0, 0, 0, 0, 0, 0, 0,
676 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
678 // sh_type: SHT_STRTAB
681 0, 0, 0, 0, 0, 0, 0, 0,
683 0, 0, 0, 0, 0, 0, 0, 0,
684 // sh_offset: after .strtab section. 438 == 0x1b6
685 0xb6, 0x1, 0, 0, 0, 0, 0, 0,
686 // sh_size: all section names
687 33, 0, 0, 0, 0, 0, 0, 0,
693 1, 0, 0, 0, 0, 0, 0, 0,
695 0, 0, 0, 0, 0, 0, 0, 0,
698 // Contents of .symtab section
700 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
701 0, 0, 0, 0, 0, 0, 0, 0,
707 // st_info: STT_NOTYPE, STB_GLOBAL
711 // st_shndx: In .test
714 0, 0, 0, 0, 0, 0, 0, 0,
716 0, 0, 0, 0, 0, 0, 0, 0,
719 // Contents of .strtab section
721 't', 'e', 's', 't', '\0',
724 // Contents of .shstrtab section
726 '.', 't', 'e', 's', 't', '\0',
727 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
728 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
729 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
732 const unsigned int test_file_1_size_64_little
= sizeof test_file_1_64_little
;
734 // 64-bit big-endian version of test_file_1_32_little.
736 const unsigned char test_file_1_64_big
[] =
743 // EI_DATA: big endian
755 // e_machine: a magic value used for testing.
760 0, 0, 0, 0, 0, 0, 0, 0,
762 0, 0, 0, 0, 0, 0, 0, 0,
763 // e_shoff: starts right after file header
764 0, 0, 0, 0, 0, 0, 0, 64,
775 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
781 // Shdr 0: dummy entry
782 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
783 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
784 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
785 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
789 // sh_name: after initial null
791 // sh_type: SHT_PROGBITS
793 // sh_flags: SHF_ALLOC
794 0, 0, 0, 0, 0, 0, 0, 2,
796 0, 0, 0, 0, 0, 0, 0, 0,
797 // sh_offset: after file header + 5 section headers. 384 == 0x180.
798 0, 0, 0, 0, 0, 0, 0x1, 0x80,
800 0, 0, 0, 0, 0, 0, 0, 0,
806 0, 0, 0, 0, 0, 0, 0, 1,
808 0, 0, 0, 0, 0, 0, 0, 0,
812 // sh_name: 1 null byte + ".test\0"
814 // sh_type: SHT_SYMTAB
817 0, 0, 0, 0, 0, 0, 0, 0,
819 0, 0, 0, 0, 0, 0, 0, 0,
820 // sh_offset: after file header + 5 section headers + empty section
822 0, 0, 0, 0, 0, 0, 0x1, 0x80,
823 // sh_size: two symbols: dummy symbol + test symbol
824 0, 0, 0, 0, 0, 0, 0, 48,
825 // sh_link: to .strtab
827 // sh_info: one local symbol, the dummy symbol
830 0, 0, 0, 0, 0, 0, 0, 8,
831 // sh_entsize: size of symbol
832 0, 0, 0, 0, 0, 0, 0, 24,
836 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
838 // sh_type: SHT_STRTAB
841 0, 0, 0, 0, 0, 0, 0, 0,
843 0, 0, 0, 0, 0, 0, 0, 0,
844 // sh_offset: after .symtab section. 432 == 0x1b0
845 0, 0, 0, 0, 0, 0, 0x1, 0xb0,
846 // sh_size: 1 null byte + "test\0"
847 0, 0, 0, 0, 0, 0, 0, 6,
853 0, 0, 0, 0, 0, 0, 0, 1,
855 0, 0, 0, 0, 0, 0, 0, 0,
859 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
861 // sh_type: SHT_STRTAB
864 0, 0, 0, 0, 0, 0, 0, 0,
866 0, 0, 0, 0, 0, 0, 0, 0,
867 // sh_offset: after .strtab section. 438 == 0x1b6
868 0, 0, 0, 0, 0, 0, 0x1, 0xb6,
869 // sh_size: all section names
870 0, 0, 0, 0, 0, 0, 0, 33,
876 0, 0, 0, 0, 0, 0, 0, 1,
878 0, 0, 0, 0, 0, 0, 0, 0,
881 // Contents of .symtab section
883 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
884 0, 0, 0, 0, 0, 0, 0, 0,
890 // st_info: STT_NOTYPE, STB_GLOBAL
894 // st_shndx: In .test
897 0, 0, 0, 0, 0, 0, 0, 0,
899 0, 0, 0, 0, 0, 0, 0, 0,
902 // Contents of .strtab section
904 't', 'e', 's', 't', '\0',
907 // Contents of .shstrtab section
909 '.', 't', 'e', 's', 't', '\0',
910 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
911 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
912 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
915 const unsigned int test_file_1_size_64_big
= sizeof test_file_1_64_big
;
917 } // End namespace gold_testsuite.