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
*, Sized_relobj
<size
, big_endian
>*,
48 unsigned int, unsigned int, const unsigned char*, size_t,
49 Output_section
*, bool, size_t, const unsigned char*)
50 { ERROR("call to Target_test::gc_process_relocs"); }
53 scan_relocs(Symbol_table
*, Layout
*, Sized_relobj
<size
, big_endian
>*,
54 unsigned int, unsigned int, const unsigned char*, size_t,
55 Output_section
*, bool, size_t, const unsigned char*)
56 { ERROR("call to Target_test::scan_relocs"); }
59 relocate_section(const Relocate_info
<size
, big_endian
>*, unsigned int,
60 const unsigned char*, size_t, Output_section
*, bool,
61 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
62 section_size_type
, const Reloc_symbol_changes
*)
63 { ERROR("call to Target_test::relocate_section"); }
66 scan_relocatable_relocs(Symbol_table
*, Layout
*,
67 Sized_relobj
<size
, big_endian
>*, unsigned int,
68 unsigned int, const unsigned char*,
69 size_t, Output_section
*, bool, size_t,
70 const unsigned char*, Relocatable_relocs
*)
71 { ERROR("call to Target_test::scan_relocatable_relocs"); }
74 relocate_for_relocatable(const Relocate_info
<size
, big_endian
>*,
75 unsigned int, const unsigned char*, size_t,
76 Output_section
*, off_t
, const Relocatable_relocs
*,
78 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
79 section_size_type
, unsigned char*,
81 { ERROR("call to Target_test::relocate_for_relocatable"); }
83 static const Target::Target_info test_target_info
;
86 template<int size
, bool big_endian
>
87 const Target::Target_info Target_test
<size
, big_endian
>::test_target_info
=
90 big_endian
, // is_big_endian
91 static_cast<elfcpp::EM
>(0xffff), // machine_code
92 false, // has_make_symbol
94 false, // has_code_fill
95 false, // is_default_stack_executable
97 "/dummy", // dynamic_linker
98 0x08000000, // default_text_segment_address
99 0x1000, // abi_pagesize
100 0x1000, // common_pagesize
101 elfcpp::SHN_UNDEF
, // small_common_shndx
102 elfcpp::SHN_UNDEF
, // large_common_shndx
103 0, // small_common_section_flags
104 0, // large_common_section_flags
105 NULL
, // attributes_section
106 NULL
// attributes_vendor
111 #ifdef HAVE_TARGET_32_LITTLE
112 Target_test
<32, false> target_test_32_little
;
115 #ifdef HAVE_TARGET_32_BIG
116 Target_test
<32, true> target_test_32_big
;
119 #ifdef HAVE_TARGET_64_LITTLE
120 Target_test
<64, false> target_test_64_little
;
123 #ifdef HAVE_TARGET_64_BIG
124 Target_test
<64, true> target_test_64_big
;
127 // A pointer to the test targets. This is used in CHECKs.
129 #ifdef HAVE_TARGET_32_LITTLE
130 Target
* target_test_pointer_32_little
= &target_test_32_little
;
133 #ifdef HAVE_TARGET_32_BIG
134 Target
* target_test_pointer_32_big
= &target_test_32_big
;
137 #ifdef HAVE_TARGET_64_LITTLE
138 Target
* target_test_pointer_64_little
= &target_test_64_little
;
141 #ifdef HAVE_TARGET_64_BIG
142 Target
* target_test_pointer_64_big
= &target_test_64_big
;
145 // Select the test targets.
147 template<int size
, bool big_endian
>
148 class Target_selector_test
: public Target_selector
151 Target_selector_test()
152 : Target_selector(0xffff, size
, big_endian
, NULL
)
156 do_instantiate_target()
163 do_recognize(int, int, int)
169 #ifdef HAVE_TARGET_32_LITTLE
170 return &target_test_32_little
;
175 #ifdef HAVE_TARGET_32_BIG
176 return &target_test_32_big
;
184 #ifdef HAVE_TARGET_64_LITTLE
185 return &target_test_64_little
;
190 #ifdef HAVE_TARGET_64_BIG
191 return &target_test_64_big
;
200 do_recognize_by_name(const char*)
204 do_supported_names(std::vector
<const char*>*)
208 // Register the test target selectors. These don't need to be
209 // conditionally compiled, as they will return NULL if there is no
212 Target_selector_test
<32, false> target_selector_test_32_little
;
213 Target_selector_test
<32, true> target_selector_test_32_big
;
214 Target_selector_test
<64, false> target_selector_test_64_little
;
215 Target_selector_test
<64, true> target_selector_test_64_big
;
217 // A simple ELF object with one empty section, named ".test" and one
218 // globally visible symbol named "test".
220 const unsigned char test_file_1_32_little
[] =
227 // EI_DATA: little endian
239 // e_machine: a magic value used for testing.
247 // e_shoff: starts right after file header
259 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
265 // Shdr 0: dummy entry
266 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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,
272 // sh_name: after initial null
274 // sh_type: SHT_PROGBITS
276 // sh_flags: SHF_ALLOC
280 // sh_offset: after file header + 5 section headers
295 // sh_name: 1 null byte + ".test\0"
297 // sh_type: SHT_SYMTAB
303 // sh_offset: after file header + 5 section headers + empty section
305 // sh_size: two symbols: dummy symbol + test symbol
307 // sh_link: to .strtab
309 // sh_info: one local symbol, the dummy symbol
313 // sh_entsize: size of symbol
318 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
320 // sh_type: SHT_STRTAB
326 // sh_offset: after .symtab section. 284 == 0x11c
328 // sh_size: 1 null byte + "test\0"
341 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
343 // sh_type: SHT_STRTAB
349 // sh_offset: after .strtab section. 290 == 0x122
351 // sh_size: all section names
363 // Contents of .symtab section
365 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
375 // st_info: STT_NOTYPE, STB_GLOBAL
379 // st_shndx: In .test
383 // Contents of .strtab section
385 't', 'e', 's', 't', '\0',
388 // Contents of .shstrtab section
390 '.', 't', 'e', 's', 't', '\0',
391 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
392 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
393 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
396 const unsigned int test_file_1_size_32_little
= sizeof test_file_1_32_little
;
398 // 32-bit big-endian version of test_file_1_32_little.
400 const unsigned char test_file_1_32_big
[] =
407 // EI_DATA: big endian
419 // e_machine: a magic value used for testing.
427 // e_shoff: starts right after file header
439 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
445 // Shdr 0: dummy entry
446 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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,
452 // sh_name: after initial null
454 // sh_type: SHT_PROGBITS
456 // sh_flags: SHF_ALLOC
460 // sh_offset: after file header + 5 section headers
475 // sh_name: 1 null byte + ".test\0"
477 // sh_type: SHT_SYMTAB
483 // sh_offset: after file header + 5 section headers + empty section
485 // sh_size: two symbols: dummy symbol + test symbol
487 // sh_link: to .strtab
489 // sh_info: one local symbol, the dummy symbol
493 // sh_entsize: size of symbol
498 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
500 // sh_type: SHT_STRTAB
506 // sh_offset: after .symtab section. 284 == 0x11c
508 // sh_size: 1 null byte + "test\0"
521 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
523 // sh_type: SHT_STRTAB
529 // sh_offset: after .strtab section. 290 == 0x122
531 // sh_size: all section names
543 // Contents of .symtab section
545 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
555 // st_info: STT_NOTYPE, STB_GLOBAL
559 // st_shndx: In .test
563 // Contents of .strtab section
565 't', 'e', 's', 't', '\0',
568 // Contents of .shstrtab section
570 '.', 't', 'e', 's', 't', '\0',
571 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
572 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
573 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
576 const unsigned int test_file_1_size_32_big
= sizeof test_file_1_32_big
;
578 // 64-bit little-endian version of test_file_1_32_little.
580 const unsigned char test_file_1_64_little
[] =
587 // EI_DATA: little endian
599 // e_machine: a magic value used for testing.
604 0, 0, 0, 0, 0, 0, 0, 0,
606 0, 0, 0, 0, 0, 0, 0, 0,
607 // e_shoff: starts right after file header
608 64, 0, 0, 0, 0, 0, 0, 0,
619 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
625 // Shdr 0: dummy entry
626 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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,
633 // sh_name: after initial null
635 // sh_type: SHT_PROGBITS
637 // sh_flags: SHF_ALLOC
638 2, 0, 0, 0, 0, 0, 0, 0,
640 0, 0, 0, 0, 0, 0, 0, 0,
641 // sh_offset: after file header + 5 section headers. 384 == 0x180.
642 0x80, 0x1, 0, 0, 0, 0, 0, 0,
644 0, 0, 0, 0, 0, 0, 0, 0,
650 1, 0, 0, 0, 0, 0, 0, 0,
652 0, 0, 0, 0, 0, 0, 0, 0,
656 // sh_name: 1 null byte + ".test\0"
658 // sh_type: SHT_SYMTAB
661 0, 0, 0, 0, 0, 0, 0, 0,
663 0, 0, 0, 0, 0, 0, 0, 0,
664 // sh_offset: after file header + 5 section headers + empty section
666 0x80, 0x1, 0, 0, 0, 0, 0, 0,
667 // sh_size: two symbols: dummy symbol + test symbol
668 48, 0, 0, 0, 0, 0, 0, 0,
669 // sh_link: to .strtab
671 // sh_info: one local symbol, the dummy symbol
674 8, 0, 0, 0, 0, 0, 0, 0,
675 // sh_entsize: size of symbol
676 24, 0, 0, 0, 0, 0, 0, 0,
680 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
682 // sh_type: SHT_STRTAB
685 0, 0, 0, 0, 0, 0, 0, 0,
687 0, 0, 0, 0, 0, 0, 0, 0,
688 // sh_offset: after .symtab section. 432 == 0x1b0
689 0xb0, 0x1, 0, 0, 0, 0, 0, 0,
690 // sh_size: 1 null byte + "test\0"
691 6, 0, 0, 0, 0, 0, 0, 0,
697 1, 0, 0, 0, 0, 0, 0, 0,
699 0, 0, 0, 0, 0, 0, 0, 0,
703 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
705 // sh_type: SHT_STRTAB
708 0, 0, 0, 0, 0, 0, 0, 0,
710 0, 0, 0, 0, 0, 0, 0, 0,
711 // sh_offset: after .strtab section. 438 == 0x1b6
712 0xb6, 0x1, 0, 0, 0, 0, 0, 0,
713 // sh_size: all section names
714 33, 0, 0, 0, 0, 0, 0, 0,
720 1, 0, 0, 0, 0, 0, 0, 0,
722 0, 0, 0, 0, 0, 0, 0, 0,
725 // Contents of .symtab section
727 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
728 0, 0, 0, 0, 0, 0, 0, 0,
734 // st_info: STT_NOTYPE, STB_GLOBAL
738 // st_shndx: In .test
741 0, 0, 0, 0, 0, 0, 0, 0,
743 0, 0, 0, 0, 0, 0, 0, 0,
746 // Contents of .strtab section
748 't', 'e', 's', 't', '\0',
751 // Contents of .shstrtab section
753 '.', 't', 'e', 's', 't', '\0',
754 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
755 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
756 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
759 const unsigned int test_file_1_size_64_little
= sizeof test_file_1_64_little
;
761 // 64-bit big-endian version of test_file_1_32_little.
763 const unsigned char test_file_1_64_big
[] =
770 // EI_DATA: big endian
782 // e_machine: a magic value used for testing.
787 0, 0, 0, 0, 0, 0, 0, 0,
789 0, 0, 0, 0, 0, 0, 0, 0,
790 // e_shoff: starts right after file header
791 0, 0, 0, 0, 0, 0, 0, 64,
802 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
808 // Shdr 0: dummy entry
809 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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,
816 // sh_name: after initial null
818 // sh_type: SHT_PROGBITS
820 // sh_flags: SHF_ALLOC
821 0, 0, 0, 0, 0, 0, 0, 2,
823 0, 0, 0, 0, 0, 0, 0, 0,
824 // sh_offset: after file header + 5 section headers. 384 == 0x180.
825 0, 0, 0, 0, 0, 0, 0x1, 0x80,
827 0, 0, 0, 0, 0, 0, 0, 0,
833 0, 0, 0, 0, 0, 0, 0, 1,
835 0, 0, 0, 0, 0, 0, 0, 0,
839 // sh_name: 1 null byte + ".test\0"
841 // sh_type: SHT_SYMTAB
844 0, 0, 0, 0, 0, 0, 0, 0,
846 0, 0, 0, 0, 0, 0, 0, 0,
847 // sh_offset: after file header + 5 section headers + empty section
849 0, 0, 0, 0, 0, 0, 0x1, 0x80,
850 // sh_size: two symbols: dummy symbol + test symbol
851 0, 0, 0, 0, 0, 0, 0, 48,
852 // sh_link: to .strtab
854 // sh_info: one local symbol, the dummy symbol
857 0, 0, 0, 0, 0, 0, 0, 8,
858 // sh_entsize: size of symbol
859 0, 0, 0, 0, 0, 0, 0, 24,
863 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
865 // sh_type: SHT_STRTAB
868 0, 0, 0, 0, 0, 0, 0, 0,
870 0, 0, 0, 0, 0, 0, 0, 0,
871 // sh_offset: after .symtab section. 432 == 0x1b0
872 0, 0, 0, 0, 0, 0, 0x1, 0xb0,
873 // sh_size: 1 null byte + "test\0"
874 0, 0, 0, 0, 0, 0, 0, 6,
880 0, 0, 0, 0, 0, 0, 0, 1,
882 0, 0, 0, 0, 0, 0, 0, 0,
886 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
888 // sh_type: SHT_STRTAB
891 0, 0, 0, 0, 0, 0, 0, 0,
893 0, 0, 0, 0, 0, 0, 0, 0,
894 // sh_offset: after .strtab section. 438 == 0x1b6
895 0, 0, 0, 0, 0, 0, 0x1, 0xb6,
896 // sh_size: all section names
897 0, 0, 0, 0, 0, 0, 0, 33,
903 0, 0, 0, 0, 0, 0, 0, 1,
905 0, 0, 0, 0, 0, 0, 0, 0,
908 // Contents of .symtab section
910 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
911 0, 0, 0, 0, 0, 0, 0, 0,
917 // st_info: STT_NOTYPE, STB_GLOBAL
921 // st_shndx: In .test
924 0, 0, 0, 0, 0, 0, 0, 0,
926 0, 0, 0, 0, 0, 0, 0, 0,
929 // Contents of .strtab section
931 't', 'e', 's', 't', '\0',
934 // Contents of .shstrtab section
936 '.', 't', 'e', 's', 't', '\0',
937 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
938 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
939 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
942 const unsigned int test_file_1_size_64_big
= sizeof test_file_1_64_big
;
944 } // End namespace gold_testsuite.