1 // testfile.cc -- Dummy ELF objects for testing purposes.
3 // Copyright 2006, 2007, 2008, 2009, 2011 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 elfcpp::SHN_UNDEF
, // small_common_shndx
104 elfcpp::SHN_UNDEF
, // large_common_shndx
105 0, // small_common_section_flags
106 0, // large_common_section_flags
107 NULL
, // attributes_section
108 NULL
// attributes_vendor
113 #ifdef HAVE_TARGET_32_LITTLE
114 Target_test
<32, false> target_test_32_little
;
117 #ifdef HAVE_TARGET_32_BIG
118 Target_test
<32, true> target_test_32_big
;
121 #ifdef HAVE_TARGET_64_LITTLE
122 Target_test
<64, false> target_test_64_little
;
125 #ifdef HAVE_TARGET_64_BIG
126 Target_test
<64, true> target_test_64_big
;
129 // A pointer to the test targets. This is used in CHECKs.
131 #ifdef HAVE_TARGET_32_LITTLE
132 Target
* target_test_pointer_32_little
= &target_test_32_little
;
135 #ifdef HAVE_TARGET_32_BIG
136 Target
* target_test_pointer_32_big
= &target_test_32_big
;
139 #ifdef HAVE_TARGET_64_LITTLE
140 Target
* target_test_pointer_64_little
= &target_test_64_little
;
143 #ifdef HAVE_TARGET_64_BIG
144 Target
* target_test_pointer_64_big
= &target_test_64_big
;
147 // Select the test targets.
149 template<int size
, bool big_endian
>
150 class Target_selector_test
: public Target_selector
153 Target_selector_test()
154 : Target_selector(0xffff, size
, big_endian
, NULL
, NULL
)
158 do_instantiate_target()
165 do_recognize(int, int, int)
171 #ifdef HAVE_TARGET_32_LITTLE
172 return &target_test_32_little
;
177 #ifdef HAVE_TARGET_32_BIG
178 return &target_test_32_big
;
186 #ifdef HAVE_TARGET_64_LITTLE
187 return &target_test_64_little
;
192 #ifdef HAVE_TARGET_64_BIG
193 return &target_test_64_big
;
202 do_recognize_by_name(const char*)
206 do_supported_names(std::vector
<const char*>*)
210 // Register the test target selectors. These don't need to be
211 // conditionally compiled, as they will return NULL if there is no
214 Target_selector_test
<32, false> target_selector_test_32_little
;
215 Target_selector_test
<32, true> target_selector_test_32_big
;
216 Target_selector_test
<64, false> target_selector_test_64_little
;
217 Target_selector_test
<64, true> target_selector_test_64_big
;
219 // A simple ELF object with one empty section, named ".test" and one
220 // globally visible symbol named "test".
222 const unsigned char test_file_1_32_little
[] =
229 // EI_DATA: little endian
241 // e_machine: a magic value used for testing.
249 // e_shoff: starts right after file header
261 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
267 // Shdr 0: dummy entry
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, 0, 0, 0, 0, 0, 0, 0, 0,
270 0, 0, 0, 0, 0, 0, 0, 0,
274 // sh_name: after initial null
276 // sh_type: SHT_PROGBITS
278 // sh_flags: SHF_ALLOC
282 // sh_offset: after file header + 5 section headers
297 // sh_name: 1 null byte + ".test\0"
299 // sh_type: SHT_SYMTAB
305 // sh_offset: after file header + 5 section headers + empty section
307 // sh_size: two symbols: dummy symbol + test symbol
309 // sh_link: to .strtab
311 // sh_info: one local symbol, the dummy symbol
315 // sh_entsize: size of symbol
320 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
322 // sh_type: SHT_STRTAB
328 // sh_offset: after .symtab section. 284 == 0x11c
330 // sh_size: 1 null byte + "test\0"
343 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
345 // sh_type: SHT_STRTAB
351 // sh_offset: after .strtab section. 290 == 0x122
353 // sh_size: all section names
365 // Contents of .symtab section
367 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
377 // st_info: STT_NOTYPE, STB_GLOBAL
381 // st_shndx: In .test
385 // Contents of .strtab section
387 't', 'e', 's', 't', '\0',
390 // Contents of .shstrtab section
392 '.', 't', 'e', 's', 't', '\0',
393 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
394 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
395 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
398 const unsigned int test_file_1_size_32_little
= sizeof test_file_1_32_little
;
400 // 32-bit big-endian version of test_file_1_32_little.
402 const unsigned char test_file_1_32_big
[] =
409 // EI_DATA: big endian
421 // e_machine: a magic value used for testing.
429 // e_shoff: starts right after file header
441 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
447 // Shdr 0: dummy entry
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, 0, 0, 0, 0, 0, 0, 0, 0,
450 0, 0, 0, 0, 0, 0, 0, 0,
454 // sh_name: after initial null
456 // sh_type: SHT_PROGBITS
458 // sh_flags: SHF_ALLOC
462 // sh_offset: after file header + 5 section headers
477 // sh_name: 1 null byte + ".test\0"
479 // sh_type: SHT_SYMTAB
485 // sh_offset: after file header + 5 section headers + empty section
487 // sh_size: two symbols: dummy symbol + test symbol
489 // sh_link: to .strtab
491 // sh_info: one local symbol, the dummy symbol
495 // sh_entsize: size of symbol
500 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
502 // sh_type: SHT_STRTAB
508 // sh_offset: after .symtab section. 284 == 0x11c
510 // sh_size: 1 null byte + "test\0"
523 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
525 // sh_type: SHT_STRTAB
531 // sh_offset: after .strtab section. 290 == 0x122
533 // sh_size: all section names
545 // Contents of .symtab section
547 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
557 // st_info: STT_NOTYPE, STB_GLOBAL
561 // st_shndx: In .test
565 // Contents of .strtab section
567 't', 'e', 's', 't', '\0',
570 // Contents of .shstrtab section
572 '.', 't', 'e', 's', 't', '\0',
573 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
574 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
575 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
578 const unsigned int test_file_1_size_32_big
= sizeof test_file_1_32_big
;
580 // 64-bit little-endian version of test_file_1_32_little.
582 const unsigned char test_file_1_64_little
[] =
589 // EI_DATA: little endian
601 // e_machine: a magic value used for testing.
606 0, 0, 0, 0, 0, 0, 0, 0,
608 0, 0, 0, 0, 0, 0, 0, 0,
609 // e_shoff: starts right after file header
610 64, 0, 0, 0, 0, 0, 0, 0,
621 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
627 // Shdr 0: dummy entry
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,
631 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
635 // sh_name: after initial null
637 // sh_type: SHT_PROGBITS
639 // sh_flags: SHF_ALLOC
640 2, 0, 0, 0, 0, 0, 0, 0,
642 0, 0, 0, 0, 0, 0, 0, 0,
643 // sh_offset: after file header + 5 section headers. 384 == 0x180.
644 0x80, 0x1, 0, 0, 0, 0, 0, 0,
646 0, 0, 0, 0, 0, 0, 0, 0,
652 1, 0, 0, 0, 0, 0, 0, 0,
654 0, 0, 0, 0, 0, 0, 0, 0,
658 // sh_name: 1 null byte + ".test\0"
660 // sh_type: SHT_SYMTAB
663 0, 0, 0, 0, 0, 0, 0, 0,
665 0, 0, 0, 0, 0, 0, 0, 0,
666 // sh_offset: after file header + 5 section headers + empty section
668 0x80, 0x1, 0, 0, 0, 0, 0, 0,
669 // sh_size: two symbols: dummy symbol + test symbol
670 48, 0, 0, 0, 0, 0, 0, 0,
671 // sh_link: to .strtab
673 // sh_info: one local symbol, the dummy symbol
676 8, 0, 0, 0, 0, 0, 0, 0,
677 // sh_entsize: size of symbol
678 24, 0, 0, 0, 0, 0, 0, 0,
682 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
684 // sh_type: SHT_STRTAB
687 0, 0, 0, 0, 0, 0, 0, 0,
689 0, 0, 0, 0, 0, 0, 0, 0,
690 // sh_offset: after .symtab section. 432 == 0x1b0
691 0xb0, 0x1, 0, 0, 0, 0, 0, 0,
692 // sh_size: 1 null byte + "test\0"
693 6, 0, 0, 0, 0, 0, 0, 0,
699 1, 0, 0, 0, 0, 0, 0, 0,
701 0, 0, 0, 0, 0, 0, 0, 0,
705 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
707 // sh_type: SHT_STRTAB
710 0, 0, 0, 0, 0, 0, 0, 0,
712 0, 0, 0, 0, 0, 0, 0, 0,
713 // sh_offset: after .strtab section. 438 == 0x1b6
714 0xb6, 0x1, 0, 0, 0, 0, 0, 0,
715 // sh_size: all section names
716 33, 0, 0, 0, 0, 0, 0, 0,
722 1, 0, 0, 0, 0, 0, 0, 0,
724 0, 0, 0, 0, 0, 0, 0, 0,
727 // Contents of .symtab section
729 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
730 0, 0, 0, 0, 0, 0, 0, 0,
736 // st_info: STT_NOTYPE, STB_GLOBAL
740 // st_shndx: In .test
743 0, 0, 0, 0, 0, 0, 0, 0,
745 0, 0, 0, 0, 0, 0, 0, 0,
748 // Contents of .strtab section
750 't', 'e', 's', 't', '\0',
753 // Contents of .shstrtab section
755 '.', 't', 'e', 's', 't', '\0',
756 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
757 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
758 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
761 const unsigned int test_file_1_size_64_little
= sizeof test_file_1_64_little
;
763 // 64-bit big-endian version of test_file_1_32_little.
765 const unsigned char test_file_1_64_big
[] =
772 // EI_DATA: big endian
784 // e_machine: a magic value used for testing.
789 0, 0, 0, 0, 0, 0, 0, 0,
791 0, 0, 0, 0, 0, 0, 0, 0,
792 // e_shoff: starts right after file header
793 0, 0, 0, 0, 0, 0, 0, 64,
804 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
810 // Shdr 0: dummy entry
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,
814 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
818 // sh_name: after initial null
820 // sh_type: SHT_PROGBITS
822 // sh_flags: SHF_ALLOC
823 0, 0, 0, 0, 0, 0, 0, 2,
825 0, 0, 0, 0, 0, 0, 0, 0,
826 // sh_offset: after file header + 5 section headers. 384 == 0x180.
827 0, 0, 0, 0, 0, 0, 0x1, 0x80,
829 0, 0, 0, 0, 0, 0, 0, 0,
835 0, 0, 0, 0, 0, 0, 0, 1,
837 0, 0, 0, 0, 0, 0, 0, 0,
841 // sh_name: 1 null byte + ".test\0"
843 // sh_type: SHT_SYMTAB
846 0, 0, 0, 0, 0, 0, 0, 0,
848 0, 0, 0, 0, 0, 0, 0, 0,
849 // sh_offset: after file header + 5 section headers + empty section
851 0, 0, 0, 0, 0, 0, 0x1, 0x80,
852 // sh_size: two symbols: dummy symbol + test symbol
853 0, 0, 0, 0, 0, 0, 0, 48,
854 // sh_link: to .strtab
856 // sh_info: one local symbol, the dummy symbol
859 0, 0, 0, 0, 0, 0, 0, 8,
860 // sh_entsize: size of symbol
861 0, 0, 0, 0, 0, 0, 0, 24,
865 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
867 // sh_type: SHT_STRTAB
870 0, 0, 0, 0, 0, 0, 0, 0,
872 0, 0, 0, 0, 0, 0, 0, 0,
873 // sh_offset: after .symtab section. 432 == 0x1b0
874 0, 0, 0, 0, 0, 0, 0x1, 0xb0,
875 // sh_size: 1 null byte + "test\0"
876 0, 0, 0, 0, 0, 0, 0, 6,
882 0, 0, 0, 0, 0, 0, 0, 1,
884 0, 0, 0, 0, 0, 0, 0, 0,
888 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
890 // sh_type: SHT_STRTAB
893 0, 0, 0, 0, 0, 0, 0, 0,
895 0, 0, 0, 0, 0, 0, 0, 0,
896 // sh_offset: after .strtab section. 438 == 0x1b6
897 0, 0, 0, 0, 0, 0, 0x1, 0xb6,
898 // sh_size: all section names
899 0, 0, 0, 0, 0, 0, 0, 33,
905 0, 0, 0, 0, 0, 0, 0, 1,
907 0, 0, 0, 0, 0, 0, 0, 0,
910 // Contents of .symtab section
912 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
913 0, 0, 0, 0, 0, 0, 0, 0,
919 // st_info: STT_NOTYPE, STB_GLOBAL
923 // st_shndx: In .test
926 0, 0, 0, 0, 0, 0, 0, 0,
928 0, 0, 0, 0, 0, 0, 0, 0,
931 // Contents of .strtab section
933 't', 'e', 's', 't', '\0',
936 // Contents of .shstrtab section
938 '.', 't', 'e', 's', 't', '\0',
939 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
940 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
941 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
944 const unsigned int test_file_1_size_64_big
= sizeof test_file_1_64_big
;
946 } // End namespace gold_testsuite.