1 // testfile.cc -- Dummy ELF objects for testing purposes.
3 // Copyright 2006, 2007, 2008 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
92 "/dummy", // dynamic_linker
93 0x08000000, // default_text_segment_address
94 0x1000, // abi_pagesize
95 0x1000 // common_pagesize
100 #ifdef HAVE_TARGET_32_LITTLE
101 Target_test
<32, false> target_test_32_little
;
104 #ifdef HAVE_TARGET_32_BIG
105 Target_test
<32, true> target_test_32_big
;
108 #ifdef HAVE_TARGET_64_LITTLE
109 Target_test
<64, false> target_test_64_little
;
112 #ifdef HAVE_TARGET_64_BIG
113 Target_test
<64, true> target_test_64_big
;
116 // A pointer to the test targets. This is used in CHECKs.
118 #ifdef HAVE_TARGET_32_LITTLE
119 Target
* target_test_pointer_32_little
= &target_test_32_little
;
122 #ifdef HAVE_TARGET_32_BIG
123 Target
* target_test_pointer_32_big
= &target_test_32_big
;
126 #ifdef HAVE_TARGET_64_LITTLE
127 Target
* target_test_pointer_64_little
= &target_test_64_little
;
130 #ifdef HAVE_TARGET_64_BIG
131 Target
* target_test_pointer_64_big
= &target_test_64_big
;
134 // Select the test targets.
136 template<int size
, bool big_endian
>
137 class Target_selector_test
: public Target_selector
140 Target_selector_test()
141 : Target_selector(0xffff, size
, big_endian
, NULL
)
145 do_instantiate_target()
152 do_recognize(int, int, int)
158 #ifdef HAVE_TARGET_32_LITTLE
159 return &target_test_32_little
;
164 #ifdef HAVE_TARGET_32_BIG
165 return &target_test_32_big
;
173 #ifdef HAVE_TARGET_64_LITTLE
174 return &target_test_64_little
;
179 #ifdef HAVE_TARGET_64_BIG
180 return &target_test_64_big
;
189 do_recognize_by_name(const char*)
193 do_supported_names(std::vector
<const char*>*)
197 // Register the test target selectors. These don't need to be
198 // conditionally compiled, as they will return NULL if there is no
201 Target_selector_test
<32, false> target_selector_test_32_little
;
202 Target_selector_test
<32, true> target_selector_test_32_big
;
203 Target_selector_test
<64, false> target_selector_test_64_little
;
204 Target_selector_test
<64, true> target_selector_test_64_big
;
206 // A simple ELF object with one empty section, named ".test" and one
207 // globally visible symbol named "test".
209 const unsigned char test_file_1_32_little
[] =
216 // EI_DATA: little endian
228 // e_machine: a magic value used for testing.
236 // e_shoff: starts right after file header
248 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
254 // Shdr 0: dummy entry
255 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
256 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
257 0, 0, 0, 0, 0, 0, 0, 0,
261 // sh_name: after initial null
263 // sh_type: SHT_PROGBITS
265 // sh_flags: SHF_ALLOC
269 // sh_offset: after file header + 5 section headers
284 // sh_name: 1 null byte + ".test\0"
286 // sh_type: SHT_SYMTAB
292 // sh_offset: after file header + 5 section headers + empty section
294 // sh_size: two symbols: dummy symbol + test symbol
296 // sh_link: to .strtab
298 // sh_info: one local symbol, the dummy symbol
302 // sh_entsize: size of symbol
307 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
309 // sh_type: SHT_STRTAB
315 // sh_offset: after .symtab section. 284 == 0x11c
317 // sh_size: 1 null byte + "test\0"
330 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
332 // sh_type: SHT_STRTAB
338 // sh_offset: after .strtab section. 290 == 0x122
340 // sh_size: all section names
352 // Contents of .symtab section
354 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
364 // st_info: STT_NOTYPE, STB_GLOBAL
368 // st_shndx: In .test
372 // Contents of .strtab section
374 't', 'e', 's', 't', '\0',
377 // Contents of .shstrtab section
379 '.', 't', 'e', 's', 't', '\0',
380 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
381 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
382 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
385 const unsigned int test_file_1_size_32_little
= sizeof test_file_1_32_little
;
387 // 32-bit big-endian version of test_file_1_32_little.
389 const unsigned char test_file_1_32_big
[] =
396 // EI_DATA: big endian
408 // e_machine: a magic value used for testing.
416 // e_shoff: starts right after file header
428 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
434 // Shdr 0: dummy entry
435 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
436 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
437 0, 0, 0, 0, 0, 0, 0, 0,
441 // sh_name: after initial null
443 // sh_type: SHT_PROGBITS
445 // sh_flags: SHF_ALLOC
449 // sh_offset: after file header + 5 section headers
464 // sh_name: 1 null byte + ".test\0"
466 // sh_type: SHT_SYMTAB
472 // sh_offset: after file header + 5 section headers + empty section
474 // sh_size: two symbols: dummy symbol + test symbol
476 // sh_link: to .strtab
478 // sh_info: one local symbol, the dummy symbol
482 // sh_entsize: size of symbol
487 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
489 // sh_type: SHT_STRTAB
495 // sh_offset: after .symtab section. 284 == 0x11c
497 // sh_size: 1 null byte + "test\0"
510 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
512 // sh_type: SHT_STRTAB
518 // sh_offset: after .strtab section. 290 == 0x122
520 // sh_size: all section names
532 // Contents of .symtab section
534 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
544 // st_info: STT_NOTYPE, STB_GLOBAL
548 // st_shndx: In .test
552 // Contents of .strtab section
554 't', 'e', 's', 't', '\0',
557 // Contents of .shstrtab section
559 '.', 't', 'e', 's', 't', '\0',
560 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
561 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
562 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
565 const unsigned int test_file_1_size_32_big
= sizeof test_file_1_32_big
;
567 // 64-bit little-endian version of test_file_1_32_little.
569 const unsigned char test_file_1_64_little
[] =
576 // EI_DATA: little endian
588 // e_machine: a magic value used for testing.
593 0, 0, 0, 0, 0, 0, 0, 0,
595 0, 0, 0, 0, 0, 0, 0, 0,
596 // e_shoff: starts right after file header
597 64, 0, 0, 0, 0, 0, 0, 0,
608 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
614 // Shdr 0: dummy entry
615 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
616 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
617 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
618 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
622 // sh_name: after initial null
624 // sh_type: SHT_PROGBITS
626 // sh_flags: SHF_ALLOC
627 2, 0, 0, 0, 0, 0, 0, 0,
629 0, 0, 0, 0, 0, 0, 0, 0,
630 // sh_offset: after file header + 5 section headers. 384 == 0x180.
631 0x80, 0x1, 0, 0, 0, 0, 0, 0,
633 0, 0, 0, 0, 0, 0, 0, 0,
639 1, 0, 0, 0, 0, 0, 0, 0,
641 0, 0, 0, 0, 0, 0, 0, 0,
645 // sh_name: 1 null byte + ".test\0"
647 // sh_type: SHT_SYMTAB
650 0, 0, 0, 0, 0, 0, 0, 0,
652 0, 0, 0, 0, 0, 0, 0, 0,
653 // sh_offset: after file header + 5 section headers + empty section
655 0x80, 0x1, 0, 0, 0, 0, 0, 0,
656 // sh_size: two symbols: dummy symbol + test symbol
657 48, 0, 0, 0, 0, 0, 0, 0,
658 // sh_link: to .strtab
660 // sh_info: one local symbol, the dummy symbol
663 8, 0, 0, 0, 0, 0, 0, 0,
664 // sh_entsize: size of symbol
665 24, 0, 0, 0, 0, 0, 0, 0,
669 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
671 // sh_type: SHT_STRTAB
674 0, 0, 0, 0, 0, 0, 0, 0,
676 0, 0, 0, 0, 0, 0, 0, 0,
677 // sh_offset: after .symtab section. 432 == 0x1b0
678 0xb0, 0x1, 0, 0, 0, 0, 0, 0,
679 // sh_size: 1 null byte + "test\0"
680 6, 0, 0, 0, 0, 0, 0, 0,
686 1, 0, 0, 0, 0, 0, 0, 0,
688 0, 0, 0, 0, 0, 0, 0, 0,
692 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
694 // sh_type: SHT_STRTAB
697 0, 0, 0, 0, 0, 0, 0, 0,
699 0, 0, 0, 0, 0, 0, 0, 0,
700 // sh_offset: after .strtab section. 438 == 0x1b6
701 0xb6, 0x1, 0, 0, 0, 0, 0, 0,
702 // sh_size: all section names
703 33, 0, 0, 0, 0, 0, 0, 0,
709 1, 0, 0, 0, 0, 0, 0, 0,
711 0, 0, 0, 0, 0, 0, 0, 0,
714 // Contents of .symtab section
716 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
717 0, 0, 0, 0, 0, 0, 0, 0,
723 // st_info: STT_NOTYPE, STB_GLOBAL
727 // st_shndx: In .test
730 0, 0, 0, 0, 0, 0, 0, 0,
732 0, 0, 0, 0, 0, 0, 0, 0,
735 // Contents of .strtab section
737 't', 'e', 's', 't', '\0',
740 // Contents of .shstrtab section
742 '.', 't', 'e', 's', 't', '\0',
743 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
744 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
745 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
748 const unsigned int test_file_1_size_64_little
= sizeof test_file_1_64_little
;
750 // 64-bit big-endian version of test_file_1_32_little.
752 const unsigned char test_file_1_64_big
[] =
759 // EI_DATA: big endian
771 // e_machine: a magic value used for testing.
776 0, 0, 0, 0, 0, 0, 0, 0,
778 0, 0, 0, 0, 0, 0, 0, 0,
779 // e_shoff: starts right after file header
780 0, 0, 0, 0, 0, 0, 0, 64,
791 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
797 // Shdr 0: dummy entry
798 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
799 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
800 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
801 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
805 // sh_name: after initial null
807 // sh_type: SHT_PROGBITS
809 // sh_flags: SHF_ALLOC
810 0, 0, 0, 0, 0, 0, 0, 2,
812 0, 0, 0, 0, 0, 0, 0, 0,
813 // sh_offset: after file header + 5 section headers. 384 == 0x180.
814 0, 0, 0, 0, 0, 0, 0x1, 0x80,
816 0, 0, 0, 0, 0, 0, 0, 0,
822 0, 0, 0, 0, 0, 0, 0, 1,
824 0, 0, 0, 0, 0, 0, 0, 0,
828 // sh_name: 1 null byte + ".test\0"
830 // sh_type: SHT_SYMTAB
833 0, 0, 0, 0, 0, 0, 0, 0,
835 0, 0, 0, 0, 0, 0, 0, 0,
836 // sh_offset: after file header + 5 section headers + empty section
838 0, 0, 0, 0, 0, 0, 0x1, 0x80,
839 // sh_size: two symbols: dummy symbol + test symbol
840 0, 0, 0, 0, 0, 0, 0, 48,
841 // sh_link: to .strtab
843 // sh_info: one local symbol, the dummy symbol
846 0, 0, 0, 0, 0, 0, 0, 8,
847 // sh_entsize: size of symbol
848 0, 0, 0, 0, 0, 0, 0, 24,
852 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
854 // sh_type: SHT_STRTAB
857 0, 0, 0, 0, 0, 0, 0, 0,
859 0, 0, 0, 0, 0, 0, 0, 0,
860 // sh_offset: after .symtab section. 432 == 0x1b0
861 0, 0, 0, 0, 0, 0, 0x1, 0xb0,
862 // sh_size: 1 null byte + "test\0"
863 0, 0, 0, 0, 0, 0, 0, 6,
869 0, 0, 0, 0, 0, 0, 0, 1,
871 0, 0, 0, 0, 0, 0, 0, 0,
875 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
877 // sh_type: SHT_STRTAB
880 0, 0, 0, 0, 0, 0, 0, 0,
882 0, 0, 0, 0, 0, 0, 0, 0,
883 // sh_offset: after .strtab section. 438 == 0x1b6
884 0, 0, 0, 0, 0, 0, 0x1, 0xb6,
885 // sh_size: all section names
886 0, 0, 0, 0, 0, 0, 0, 33,
892 0, 0, 0, 0, 0, 0, 0, 1,
894 0, 0, 0, 0, 0, 0, 0, 0,
897 // Contents of .symtab section
899 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
900 0, 0, 0, 0, 0, 0, 0, 0,
906 // st_info: STT_NOTYPE, STB_GLOBAL
910 // st_shndx: In .test
913 0, 0, 0, 0, 0, 0, 0, 0,
915 0, 0, 0, 0, 0, 0, 0, 0,
918 // Contents of .strtab section
920 't', 'e', 's', 't', '\0',
923 // Contents of .shstrtab section
925 '.', 't', 'e', 's', 't', '\0',
926 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
927 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
928 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
931 const unsigned int test_file_1_size_64_big
= sizeof test_file_1_64_big
;
933 } // End namespace gold_testsuite.