1 // testfile.cc -- Dummy ELF objects for testing purposes.
3 // Copyright 2006, 2007, 2008, 2009, 2011, 2012 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_for_relocatable(const Relocate_info
<size
, big_endian
>*,
76 unsigned int, const unsigned char*, size_t,
77 Output_section
*, off_t
, const Relocatable_relocs
*,
79 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
80 section_size_type
, unsigned char*,
82 { ERROR("call to Target_test::relocate_for_relocatable"); }
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
115 #ifdef HAVE_TARGET_32_LITTLE
116 Target_test
<32, false> target_test_32_little
;
119 #ifdef HAVE_TARGET_32_BIG
120 Target_test
<32, true> target_test_32_big
;
123 #ifdef HAVE_TARGET_64_LITTLE
124 Target_test
<64, false> target_test_64_little
;
127 #ifdef HAVE_TARGET_64_BIG
128 Target_test
<64, true> target_test_64_big
;
131 // A pointer to the test targets. This is used in CHECKs.
133 #ifdef HAVE_TARGET_32_LITTLE
134 Target
* target_test_pointer_32_little
= &target_test_32_little
;
137 #ifdef HAVE_TARGET_32_BIG
138 Target
* target_test_pointer_32_big
= &target_test_32_big
;
141 #ifdef HAVE_TARGET_64_LITTLE
142 Target
* target_test_pointer_64_little
= &target_test_64_little
;
145 #ifdef HAVE_TARGET_64_BIG
146 Target
* target_test_pointer_64_big
= &target_test_64_big
;
149 // Select the test targets.
151 template<int size
, bool big_endian
>
152 class Target_selector_test
: public Target_selector
155 Target_selector_test()
156 : Target_selector(0xffff, size
, big_endian
, NULL
, NULL
)
160 do_instantiate_target()
167 do_recognize(Input_file
*, off_t
, int, int, int)
173 #ifdef HAVE_TARGET_32_LITTLE
174 return &target_test_32_little
;
179 #ifdef HAVE_TARGET_32_BIG
180 return &target_test_32_big
;
188 #ifdef HAVE_TARGET_64_LITTLE
189 return &target_test_64_little
;
194 #ifdef HAVE_TARGET_64_BIG
195 return &target_test_64_big
;
204 do_recognize_by_name(const char*)
208 do_supported_names(std::vector
<const char*>*)
212 // Register the test target selectors. These don't need to be
213 // conditionally compiled, as they will return NULL if there is no
216 Target_selector_test
<32, false> target_selector_test_32_little
;
217 Target_selector_test
<32, true> target_selector_test_32_big
;
218 Target_selector_test
<64, false> target_selector_test_64_little
;
219 Target_selector_test
<64, true> target_selector_test_64_big
;
221 // A simple ELF object with one empty section, named ".test" and one
222 // globally visible symbol named "test".
224 const unsigned char test_file_1_32_little
[] =
231 // EI_DATA: little endian
243 // e_machine: a magic value used for testing.
251 // e_shoff: starts right after file header
263 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
269 // Shdr 0: dummy entry
270 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
271 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
272 0, 0, 0, 0, 0, 0, 0, 0,
276 // sh_name: after initial null
278 // sh_type: SHT_PROGBITS
280 // sh_flags: SHF_ALLOC
284 // sh_offset: after file header + 5 section headers
299 // sh_name: 1 null byte + ".test\0"
301 // sh_type: SHT_SYMTAB
307 // sh_offset: after file header + 5 section headers + empty section
309 // sh_size: two symbols: dummy symbol + test symbol
311 // sh_link: to .strtab
313 // sh_info: one local symbol, the dummy symbol
317 // sh_entsize: size of symbol
322 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
324 // sh_type: SHT_STRTAB
330 // sh_offset: after .symtab section. 284 == 0x11c
332 // sh_size: 1 null byte + "test\0"
345 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
347 // sh_type: SHT_STRTAB
353 // sh_offset: after .strtab section. 290 == 0x122
355 // sh_size: all section names
367 // Contents of .symtab section
369 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
379 // st_info: STT_NOTYPE, STB_GLOBAL
383 // st_shndx: In .test
387 // Contents of .strtab section
389 't', 'e', 's', 't', '\0',
392 // Contents of .shstrtab section
394 '.', 't', 'e', 's', 't', '\0',
395 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
396 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
397 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
400 const unsigned int test_file_1_size_32_little
= sizeof test_file_1_32_little
;
402 // 32-bit big-endian version of test_file_1_32_little.
404 const unsigned char test_file_1_32_big
[] =
411 // EI_DATA: big endian
423 // e_machine: a magic value used for testing.
431 // e_shoff: starts right after file header
443 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
449 // Shdr 0: dummy entry
450 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
451 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
452 0, 0, 0, 0, 0, 0, 0, 0,
456 // sh_name: after initial null
458 // sh_type: SHT_PROGBITS
460 // sh_flags: SHF_ALLOC
464 // sh_offset: after file header + 5 section headers
479 // sh_name: 1 null byte + ".test\0"
481 // sh_type: SHT_SYMTAB
487 // sh_offset: after file header + 5 section headers + empty section
489 // sh_size: two symbols: dummy symbol + test symbol
491 // sh_link: to .strtab
493 // sh_info: one local symbol, the dummy symbol
497 // sh_entsize: size of symbol
502 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
504 // sh_type: SHT_STRTAB
510 // sh_offset: after .symtab section. 284 == 0x11c
512 // sh_size: 1 null byte + "test\0"
525 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
527 // sh_type: SHT_STRTAB
533 // sh_offset: after .strtab section. 290 == 0x122
535 // sh_size: all section names
547 // Contents of .symtab section
549 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
559 // st_info: STT_NOTYPE, STB_GLOBAL
563 // st_shndx: In .test
567 // Contents of .strtab section
569 't', 'e', 's', 't', '\0',
572 // Contents of .shstrtab section
574 '.', 't', 'e', 's', 't', '\0',
575 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
576 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
577 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
580 const unsigned int test_file_1_size_32_big
= sizeof test_file_1_32_big
;
582 // 64-bit little-endian version of test_file_1_32_little.
584 const unsigned char test_file_1_64_little
[] =
591 // EI_DATA: little endian
603 // e_machine: a magic value used for testing.
608 0, 0, 0, 0, 0, 0, 0, 0,
610 0, 0, 0, 0, 0, 0, 0, 0,
611 // e_shoff: starts right after file header
612 64, 0, 0, 0, 0, 0, 0, 0,
623 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
629 // Shdr 0: dummy entry
630 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
631 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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,
637 // sh_name: after initial null
639 // sh_type: SHT_PROGBITS
641 // sh_flags: SHF_ALLOC
642 2, 0, 0, 0, 0, 0, 0, 0,
644 0, 0, 0, 0, 0, 0, 0, 0,
645 // sh_offset: after file header + 5 section headers. 384 == 0x180.
646 0x80, 0x1, 0, 0, 0, 0, 0, 0,
648 0, 0, 0, 0, 0, 0, 0, 0,
654 1, 0, 0, 0, 0, 0, 0, 0,
656 0, 0, 0, 0, 0, 0, 0, 0,
660 // sh_name: 1 null byte + ".test\0"
662 // sh_type: SHT_SYMTAB
665 0, 0, 0, 0, 0, 0, 0, 0,
667 0, 0, 0, 0, 0, 0, 0, 0,
668 // sh_offset: after file header + 5 section headers + empty section
670 0x80, 0x1, 0, 0, 0, 0, 0, 0,
671 // sh_size: two symbols: dummy symbol + test symbol
672 48, 0, 0, 0, 0, 0, 0, 0,
673 // sh_link: to .strtab
675 // sh_info: one local symbol, the dummy symbol
678 8, 0, 0, 0, 0, 0, 0, 0,
679 // sh_entsize: size of symbol
680 24, 0, 0, 0, 0, 0, 0, 0,
684 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
686 // sh_type: SHT_STRTAB
689 0, 0, 0, 0, 0, 0, 0, 0,
691 0, 0, 0, 0, 0, 0, 0, 0,
692 // sh_offset: after .symtab section. 432 == 0x1b0
693 0xb0, 0x1, 0, 0, 0, 0, 0, 0,
694 // sh_size: 1 null byte + "test\0"
695 6, 0, 0, 0, 0, 0, 0, 0,
701 1, 0, 0, 0, 0, 0, 0, 0,
703 0, 0, 0, 0, 0, 0, 0, 0,
707 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
709 // sh_type: SHT_STRTAB
712 0, 0, 0, 0, 0, 0, 0, 0,
714 0, 0, 0, 0, 0, 0, 0, 0,
715 // sh_offset: after .strtab section. 438 == 0x1b6
716 0xb6, 0x1, 0, 0, 0, 0, 0, 0,
717 // sh_size: all section names
718 33, 0, 0, 0, 0, 0, 0, 0,
724 1, 0, 0, 0, 0, 0, 0, 0,
726 0, 0, 0, 0, 0, 0, 0, 0,
729 // Contents of .symtab section
731 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
732 0, 0, 0, 0, 0, 0, 0, 0,
738 // st_info: STT_NOTYPE, STB_GLOBAL
742 // st_shndx: In .test
745 0, 0, 0, 0, 0, 0, 0, 0,
747 0, 0, 0, 0, 0, 0, 0, 0,
750 // Contents of .strtab section
752 't', 'e', 's', 't', '\0',
755 // Contents of .shstrtab section
757 '.', 't', 'e', 's', 't', '\0',
758 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
759 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
760 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
763 const unsigned int test_file_1_size_64_little
= sizeof test_file_1_64_little
;
765 // 64-bit big-endian version of test_file_1_32_little.
767 const unsigned char test_file_1_64_big
[] =
774 // EI_DATA: big endian
786 // e_machine: a magic value used for testing.
791 0, 0, 0, 0, 0, 0, 0, 0,
793 0, 0, 0, 0, 0, 0, 0, 0,
794 // e_shoff: starts right after file header
795 0, 0, 0, 0, 0, 0, 0, 64,
806 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
812 // Shdr 0: dummy entry
813 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
814 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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,
820 // sh_name: after initial null
822 // sh_type: SHT_PROGBITS
824 // sh_flags: SHF_ALLOC
825 0, 0, 0, 0, 0, 0, 0, 2,
827 0, 0, 0, 0, 0, 0, 0, 0,
828 // sh_offset: after file header + 5 section headers. 384 == 0x180.
829 0, 0, 0, 0, 0, 0, 0x1, 0x80,
831 0, 0, 0, 0, 0, 0, 0, 0,
837 0, 0, 0, 0, 0, 0, 0, 1,
839 0, 0, 0, 0, 0, 0, 0, 0,
843 // sh_name: 1 null byte + ".test\0"
845 // sh_type: SHT_SYMTAB
848 0, 0, 0, 0, 0, 0, 0, 0,
850 0, 0, 0, 0, 0, 0, 0, 0,
851 // sh_offset: after file header + 5 section headers + empty section
853 0, 0, 0, 0, 0, 0, 0x1, 0x80,
854 // sh_size: two symbols: dummy symbol + test symbol
855 0, 0, 0, 0, 0, 0, 0, 48,
856 // sh_link: to .strtab
858 // sh_info: one local symbol, the dummy symbol
861 0, 0, 0, 0, 0, 0, 0, 8,
862 // sh_entsize: size of symbol
863 0, 0, 0, 0, 0, 0, 0, 24,
867 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
869 // sh_type: SHT_STRTAB
872 0, 0, 0, 0, 0, 0, 0, 0,
874 0, 0, 0, 0, 0, 0, 0, 0,
875 // sh_offset: after .symtab section. 432 == 0x1b0
876 0, 0, 0, 0, 0, 0, 0x1, 0xb0,
877 // sh_size: 1 null byte + "test\0"
878 0, 0, 0, 0, 0, 0, 0, 6,
884 0, 0, 0, 0, 0, 0, 0, 1,
886 0, 0, 0, 0, 0, 0, 0, 0,
890 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
892 // sh_type: SHT_STRTAB
895 0, 0, 0, 0, 0, 0, 0, 0,
897 0, 0, 0, 0, 0, 0, 0, 0,
898 // sh_offset: after .strtab section. 438 == 0x1b6
899 0, 0, 0, 0, 0, 0, 0x1, 0xb6,
900 // sh_size: all section names
901 0, 0, 0, 0, 0, 0, 0, 33,
907 0, 0, 0, 0, 0, 0, 0, 1,
909 0, 0, 0, 0, 0, 0, 0, 0,
912 // Contents of .symtab section
914 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
915 0, 0, 0, 0, 0, 0, 0, 0,
921 // st_info: STT_NOTYPE, STB_GLOBAL
925 // st_shndx: In .test
928 0, 0, 0, 0, 0, 0, 0, 0,
930 0, 0, 0, 0, 0, 0, 0, 0,
933 // Contents of .strtab section
935 't', 'e', 's', 't', '\0',
938 // Contents of .shstrtab section
940 '.', 't', 'e', 's', 't', '\0',
941 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
942 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
943 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
946 const unsigned int test_file_1_size_64_big
= sizeof test_file_1_64_big
;
948 } // End namespace gold_testsuite.