1 // testfile.cc -- Dummy ELF objects for testing purposes.
3 // Copyright 2006, 2007, 2008, 2009 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
98 "/dummy", // dynamic_linker
99 0x08000000, // default_text_segment_address
100 0x1000, // abi_pagesize
101 0x1000, // common_pagesize
102 elfcpp::SHN_UNDEF
, // small_common_shndx
103 elfcpp::SHN_UNDEF
, // large_common_shndx
104 0, // small_common_section_flags
105 0, // large_common_section_flags
106 NULL
, // attributes_section
107 NULL
// attributes_vendor
112 #ifdef HAVE_TARGET_32_LITTLE
113 Target_test
<32, false> target_test_32_little
;
116 #ifdef HAVE_TARGET_32_BIG
117 Target_test
<32, true> target_test_32_big
;
120 #ifdef HAVE_TARGET_64_LITTLE
121 Target_test
<64, false> target_test_64_little
;
124 #ifdef HAVE_TARGET_64_BIG
125 Target_test
<64, true> target_test_64_big
;
128 // A pointer to the test targets. This is used in CHECKs.
130 #ifdef HAVE_TARGET_32_LITTLE
131 Target
* target_test_pointer_32_little
= &target_test_32_little
;
134 #ifdef HAVE_TARGET_32_BIG
135 Target
* target_test_pointer_32_big
= &target_test_32_big
;
138 #ifdef HAVE_TARGET_64_LITTLE
139 Target
* target_test_pointer_64_little
= &target_test_64_little
;
142 #ifdef HAVE_TARGET_64_BIG
143 Target
* target_test_pointer_64_big
= &target_test_64_big
;
146 // Select the test targets.
148 template<int size
, bool big_endian
>
149 class Target_selector_test
: public Target_selector
152 Target_selector_test()
153 : Target_selector(0xffff, size
, big_endian
, NULL
)
157 do_instantiate_target()
164 do_recognize(int, int, int)
170 #ifdef HAVE_TARGET_32_LITTLE
171 return &target_test_32_little
;
176 #ifdef HAVE_TARGET_32_BIG
177 return &target_test_32_big
;
185 #ifdef HAVE_TARGET_64_LITTLE
186 return &target_test_64_little
;
191 #ifdef HAVE_TARGET_64_BIG
192 return &target_test_64_big
;
201 do_recognize_by_name(const char*)
205 do_supported_names(std::vector
<const char*>*)
209 // Register the test target selectors. These don't need to be
210 // conditionally compiled, as they will return NULL if there is no
213 Target_selector_test
<32, false> target_selector_test_32_little
;
214 Target_selector_test
<32, true> target_selector_test_32_big
;
215 Target_selector_test
<64, false> target_selector_test_64_little
;
216 Target_selector_test
<64, true> target_selector_test_64_big
;
218 // A simple ELF object with one empty section, named ".test" and one
219 // globally visible symbol named "test".
221 const unsigned char test_file_1_32_little
[] =
228 // EI_DATA: little endian
240 // e_machine: a magic value used for testing.
248 // e_shoff: starts right after file header
260 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
266 // Shdr 0: dummy entry
267 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
268 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
269 0, 0, 0, 0, 0, 0, 0, 0,
273 // sh_name: after initial null
275 // sh_type: SHT_PROGBITS
277 // sh_flags: SHF_ALLOC
281 // sh_offset: after file header + 5 section headers
296 // sh_name: 1 null byte + ".test\0"
298 // sh_type: SHT_SYMTAB
304 // sh_offset: after file header + 5 section headers + empty section
306 // sh_size: two symbols: dummy symbol + test symbol
308 // sh_link: to .strtab
310 // sh_info: one local symbol, the dummy symbol
314 // sh_entsize: size of symbol
319 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
321 // sh_type: SHT_STRTAB
327 // sh_offset: after .symtab section. 284 == 0x11c
329 // sh_size: 1 null byte + "test\0"
342 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
344 // sh_type: SHT_STRTAB
350 // sh_offset: after .strtab section. 290 == 0x122
352 // sh_size: all section names
364 // Contents of .symtab section
366 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
376 // st_info: STT_NOTYPE, STB_GLOBAL
380 // st_shndx: In .test
384 // Contents of .strtab section
386 't', 'e', 's', 't', '\0',
389 // Contents of .shstrtab section
391 '.', 't', 'e', 's', 't', '\0',
392 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
393 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
394 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
397 const unsigned int test_file_1_size_32_little
= sizeof test_file_1_32_little
;
399 // 32-bit big-endian version of test_file_1_32_little.
401 const unsigned char test_file_1_32_big
[] =
408 // EI_DATA: big endian
420 // e_machine: a magic value used for testing.
428 // e_shoff: starts right after file header
440 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
446 // Shdr 0: dummy entry
447 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
448 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
449 0, 0, 0, 0, 0, 0, 0, 0,
453 // sh_name: after initial null
455 // sh_type: SHT_PROGBITS
457 // sh_flags: SHF_ALLOC
461 // sh_offset: after file header + 5 section headers
476 // sh_name: 1 null byte + ".test\0"
478 // sh_type: SHT_SYMTAB
484 // sh_offset: after file header + 5 section headers + empty section
486 // sh_size: two symbols: dummy symbol + test symbol
488 // sh_link: to .strtab
490 // sh_info: one local symbol, the dummy symbol
494 // sh_entsize: size of symbol
499 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
501 // sh_type: SHT_STRTAB
507 // sh_offset: after .symtab section. 284 == 0x11c
509 // sh_size: 1 null byte + "test\0"
522 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
524 // sh_type: SHT_STRTAB
530 // sh_offset: after .strtab section. 290 == 0x122
532 // sh_size: all section names
544 // Contents of .symtab section
546 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
556 // st_info: STT_NOTYPE, STB_GLOBAL
560 // st_shndx: In .test
564 // Contents of .strtab section
566 't', 'e', 's', 't', '\0',
569 // Contents of .shstrtab section
571 '.', 't', 'e', 's', 't', '\0',
572 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
573 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
574 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
577 const unsigned int test_file_1_size_32_big
= sizeof test_file_1_32_big
;
579 // 64-bit little-endian version of test_file_1_32_little.
581 const unsigned char test_file_1_64_little
[] =
588 // EI_DATA: little endian
600 // e_machine: a magic value used for testing.
605 0, 0, 0, 0, 0, 0, 0, 0,
607 0, 0, 0, 0, 0, 0, 0, 0,
608 // e_shoff: starts right after file header
609 64, 0, 0, 0, 0, 0, 0, 0,
620 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
626 // Shdr 0: dummy entry
627 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
628 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
629 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
630 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
634 // sh_name: after initial null
636 // sh_type: SHT_PROGBITS
638 // sh_flags: SHF_ALLOC
639 2, 0, 0, 0, 0, 0, 0, 0,
641 0, 0, 0, 0, 0, 0, 0, 0,
642 // sh_offset: after file header + 5 section headers. 384 == 0x180.
643 0x80, 0x1, 0, 0, 0, 0, 0, 0,
645 0, 0, 0, 0, 0, 0, 0, 0,
651 1, 0, 0, 0, 0, 0, 0, 0,
653 0, 0, 0, 0, 0, 0, 0, 0,
657 // sh_name: 1 null byte + ".test\0"
659 // sh_type: SHT_SYMTAB
662 0, 0, 0, 0, 0, 0, 0, 0,
664 0, 0, 0, 0, 0, 0, 0, 0,
665 // sh_offset: after file header + 5 section headers + empty section
667 0x80, 0x1, 0, 0, 0, 0, 0, 0,
668 // sh_size: two symbols: dummy symbol + test symbol
669 48, 0, 0, 0, 0, 0, 0, 0,
670 // sh_link: to .strtab
672 // sh_info: one local symbol, the dummy symbol
675 8, 0, 0, 0, 0, 0, 0, 0,
676 // sh_entsize: size of symbol
677 24, 0, 0, 0, 0, 0, 0, 0,
681 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
683 // sh_type: SHT_STRTAB
686 0, 0, 0, 0, 0, 0, 0, 0,
688 0, 0, 0, 0, 0, 0, 0, 0,
689 // sh_offset: after .symtab section. 432 == 0x1b0
690 0xb0, 0x1, 0, 0, 0, 0, 0, 0,
691 // sh_size: 1 null byte + "test\0"
692 6, 0, 0, 0, 0, 0, 0, 0,
698 1, 0, 0, 0, 0, 0, 0, 0,
700 0, 0, 0, 0, 0, 0, 0, 0,
704 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
706 // sh_type: SHT_STRTAB
709 0, 0, 0, 0, 0, 0, 0, 0,
711 0, 0, 0, 0, 0, 0, 0, 0,
712 // sh_offset: after .strtab section. 438 == 0x1b6
713 0xb6, 0x1, 0, 0, 0, 0, 0, 0,
714 // sh_size: all section names
715 33, 0, 0, 0, 0, 0, 0, 0,
721 1, 0, 0, 0, 0, 0, 0, 0,
723 0, 0, 0, 0, 0, 0, 0, 0,
726 // Contents of .symtab section
728 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
729 0, 0, 0, 0, 0, 0, 0, 0,
735 // st_info: STT_NOTYPE, STB_GLOBAL
739 // st_shndx: In .test
742 0, 0, 0, 0, 0, 0, 0, 0,
744 0, 0, 0, 0, 0, 0, 0, 0,
747 // Contents of .strtab section
749 't', 'e', 's', 't', '\0',
752 // Contents of .shstrtab section
754 '.', 't', 'e', 's', 't', '\0',
755 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
756 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
757 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
760 const unsigned int test_file_1_size_64_little
= sizeof test_file_1_64_little
;
762 // 64-bit big-endian version of test_file_1_32_little.
764 const unsigned char test_file_1_64_big
[] =
771 // EI_DATA: big endian
783 // e_machine: a magic value used for testing.
788 0, 0, 0, 0, 0, 0, 0, 0,
790 0, 0, 0, 0, 0, 0, 0, 0,
791 // e_shoff: starts right after file header
792 0, 0, 0, 0, 0, 0, 0, 64,
803 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
809 // Shdr 0: dummy entry
810 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
811 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
812 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
813 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
817 // sh_name: after initial null
819 // sh_type: SHT_PROGBITS
821 // sh_flags: SHF_ALLOC
822 0, 0, 0, 0, 0, 0, 0, 2,
824 0, 0, 0, 0, 0, 0, 0, 0,
825 // sh_offset: after file header + 5 section headers. 384 == 0x180.
826 0, 0, 0, 0, 0, 0, 0x1, 0x80,
828 0, 0, 0, 0, 0, 0, 0, 0,
834 0, 0, 0, 0, 0, 0, 0, 1,
836 0, 0, 0, 0, 0, 0, 0, 0,
840 // sh_name: 1 null byte + ".test\0"
842 // sh_type: SHT_SYMTAB
845 0, 0, 0, 0, 0, 0, 0, 0,
847 0, 0, 0, 0, 0, 0, 0, 0,
848 // sh_offset: after file header + 5 section headers + empty section
850 0, 0, 0, 0, 0, 0, 0x1, 0x80,
851 // sh_size: two symbols: dummy symbol + test symbol
852 0, 0, 0, 0, 0, 0, 0, 48,
853 // sh_link: to .strtab
855 // sh_info: one local symbol, the dummy symbol
858 0, 0, 0, 0, 0, 0, 0, 8,
859 // sh_entsize: size of symbol
860 0, 0, 0, 0, 0, 0, 0, 24,
864 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
866 // sh_type: SHT_STRTAB
869 0, 0, 0, 0, 0, 0, 0, 0,
871 0, 0, 0, 0, 0, 0, 0, 0,
872 // sh_offset: after .symtab section. 432 == 0x1b0
873 0, 0, 0, 0, 0, 0, 0x1, 0xb0,
874 // sh_size: 1 null byte + "test\0"
875 0, 0, 0, 0, 0, 0, 0, 6,
881 0, 0, 0, 0, 0, 0, 0, 1,
883 0, 0, 0, 0, 0, 0, 0, 0,
887 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
889 // sh_type: SHT_STRTAB
892 0, 0, 0, 0, 0, 0, 0, 0,
894 0, 0, 0, 0, 0, 0, 0, 0,
895 // sh_offset: after .strtab section. 438 == 0x1b6
896 0, 0, 0, 0, 0, 0, 0x1, 0xb6,
897 // sh_size: all section names
898 0, 0, 0, 0, 0, 0, 0, 33,
904 0, 0, 0, 0, 0, 0, 0, 1,
906 0, 0, 0, 0, 0, 0, 0, 0,
909 // Contents of .symtab section
911 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
912 0, 0, 0, 0, 0, 0, 0, 0,
918 // st_info: STT_NOTYPE, STB_GLOBAL
922 // st_shndx: In .test
925 0, 0, 0, 0, 0, 0, 0, 0,
927 0, 0, 0, 0, 0, 0, 0, 0,
930 // Contents of .strtab section
932 't', 'e', 's', 't', '\0',
935 // Contents of .shstrtab section
937 '.', 't', 'e', 's', 't', '\0',
938 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
939 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
940 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
943 const unsigned int test_file_1_size_64_big
= sizeof test_file_1_64_big
;
945 } // End namespace gold_testsuite.