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
109 #ifdef HAVE_TARGET_32_LITTLE
110 Target_test
<32, false> target_test_32_little
;
113 #ifdef HAVE_TARGET_32_BIG
114 Target_test
<32, true> target_test_32_big
;
117 #ifdef HAVE_TARGET_64_LITTLE
118 Target_test
<64, false> target_test_64_little
;
121 #ifdef HAVE_TARGET_64_BIG
122 Target_test
<64, true> target_test_64_big
;
125 // A pointer to the test targets. This is used in CHECKs.
127 #ifdef HAVE_TARGET_32_LITTLE
128 Target
* target_test_pointer_32_little
= &target_test_32_little
;
131 #ifdef HAVE_TARGET_32_BIG
132 Target
* target_test_pointer_32_big
= &target_test_32_big
;
135 #ifdef HAVE_TARGET_64_LITTLE
136 Target
* target_test_pointer_64_little
= &target_test_64_little
;
139 #ifdef HAVE_TARGET_64_BIG
140 Target
* target_test_pointer_64_big
= &target_test_64_big
;
143 // Select the test targets.
145 template<int size
, bool big_endian
>
146 class Target_selector_test
: public Target_selector
149 Target_selector_test()
150 : Target_selector(0xffff, size
, big_endian
, NULL
)
154 do_instantiate_target()
161 do_recognize(int, int, int)
167 #ifdef HAVE_TARGET_32_LITTLE
168 return &target_test_32_little
;
173 #ifdef HAVE_TARGET_32_BIG
174 return &target_test_32_big
;
182 #ifdef HAVE_TARGET_64_LITTLE
183 return &target_test_64_little
;
188 #ifdef HAVE_TARGET_64_BIG
189 return &target_test_64_big
;
198 do_recognize_by_name(const char*)
202 do_supported_names(std::vector
<const char*>*)
206 // Register the test target selectors. These don't need to be
207 // conditionally compiled, as they will return NULL if there is no
210 Target_selector_test
<32, false> target_selector_test_32_little
;
211 Target_selector_test
<32, true> target_selector_test_32_big
;
212 Target_selector_test
<64, false> target_selector_test_64_little
;
213 Target_selector_test
<64, true> target_selector_test_64_big
;
215 // A simple ELF object with one empty section, named ".test" and one
216 // globally visible symbol named "test".
218 const unsigned char test_file_1_32_little
[] =
225 // EI_DATA: little endian
237 // e_machine: a magic value used for testing.
245 // e_shoff: starts right after file header
257 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
263 // Shdr 0: dummy entry
264 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
265 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
266 0, 0, 0, 0, 0, 0, 0, 0,
270 // sh_name: after initial null
272 // sh_type: SHT_PROGBITS
274 // sh_flags: SHF_ALLOC
278 // sh_offset: after file header + 5 section headers
293 // sh_name: 1 null byte + ".test\0"
295 // sh_type: SHT_SYMTAB
301 // sh_offset: after file header + 5 section headers + empty section
303 // sh_size: two symbols: dummy symbol + test symbol
305 // sh_link: to .strtab
307 // sh_info: one local symbol, the dummy symbol
311 // sh_entsize: size of symbol
316 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
318 // sh_type: SHT_STRTAB
324 // sh_offset: after .symtab section. 284 == 0x11c
326 // sh_size: 1 null byte + "test\0"
339 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
341 // sh_type: SHT_STRTAB
347 // sh_offset: after .strtab section. 290 == 0x122
349 // sh_size: all section names
361 // Contents of .symtab section
363 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
373 // st_info: STT_NOTYPE, STB_GLOBAL
377 // st_shndx: In .test
381 // Contents of .strtab section
383 't', 'e', 's', 't', '\0',
386 // Contents of .shstrtab section
388 '.', 't', 'e', 's', 't', '\0',
389 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
390 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
391 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
394 const unsigned int test_file_1_size_32_little
= sizeof test_file_1_32_little
;
396 // 32-bit big-endian version of test_file_1_32_little.
398 const unsigned char test_file_1_32_big
[] =
405 // EI_DATA: big endian
417 // e_machine: a magic value used for testing.
425 // e_shoff: starts right after file header
437 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
443 // Shdr 0: dummy entry
444 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
445 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
446 0, 0, 0, 0, 0, 0, 0, 0,
450 // sh_name: after initial null
452 // sh_type: SHT_PROGBITS
454 // sh_flags: SHF_ALLOC
458 // sh_offset: after file header + 5 section headers
473 // sh_name: 1 null byte + ".test\0"
475 // sh_type: SHT_SYMTAB
481 // sh_offset: after file header + 5 section headers + empty section
483 // sh_size: two symbols: dummy symbol + test symbol
485 // sh_link: to .strtab
487 // sh_info: one local symbol, the dummy symbol
491 // sh_entsize: size of symbol
496 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
498 // sh_type: SHT_STRTAB
504 // sh_offset: after .symtab section. 284 == 0x11c
506 // sh_size: 1 null byte + "test\0"
519 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
521 // sh_type: SHT_STRTAB
527 // sh_offset: after .strtab section. 290 == 0x122
529 // sh_size: all section names
541 // Contents of .symtab section
543 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
553 // st_info: STT_NOTYPE, STB_GLOBAL
557 // st_shndx: In .test
561 // Contents of .strtab section
563 't', 'e', 's', 't', '\0',
566 // Contents of .shstrtab section
568 '.', 't', 'e', 's', 't', '\0',
569 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
570 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
571 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
574 const unsigned int test_file_1_size_32_big
= sizeof test_file_1_32_big
;
576 // 64-bit little-endian version of test_file_1_32_little.
578 const unsigned char test_file_1_64_little
[] =
585 // EI_DATA: little endian
597 // e_machine: a magic value used for testing.
602 0, 0, 0, 0, 0, 0, 0, 0,
604 0, 0, 0, 0, 0, 0, 0, 0,
605 // e_shoff: starts right after file header
606 64, 0, 0, 0, 0, 0, 0, 0,
617 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
623 // Shdr 0: dummy entry
624 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
625 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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,
631 // sh_name: after initial null
633 // sh_type: SHT_PROGBITS
635 // sh_flags: SHF_ALLOC
636 2, 0, 0, 0, 0, 0, 0, 0,
638 0, 0, 0, 0, 0, 0, 0, 0,
639 // sh_offset: after file header + 5 section headers. 384 == 0x180.
640 0x80, 0x1, 0, 0, 0, 0, 0, 0,
642 0, 0, 0, 0, 0, 0, 0, 0,
648 1, 0, 0, 0, 0, 0, 0, 0,
650 0, 0, 0, 0, 0, 0, 0, 0,
654 // sh_name: 1 null byte + ".test\0"
656 // sh_type: SHT_SYMTAB
659 0, 0, 0, 0, 0, 0, 0, 0,
661 0, 0, 0, 0, 0, 0, 0, 0,
662 // sh_offset: after file header + 5 section headers + empty section
664 0x80, 0x1, 0, 0, 0, 0, 0, 0,
665 // sh_size: two symbols: dummy symbol + test symbol
666 48, 0, 0, 0, 0, 0, 0, 0,
667 // sh_link: to .strtab
669 // sh_info: one local symbol, the dummy symbol
672 8, 0, 0, 0, 0, 0, 0, 0,
673 // sh_entsize: size of symbol
674 24, 0, 0, 0, 0, 0, 0, 0,
678 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
680 // sh_type: SHT_STRTAB
683 0, 0, 0, 0, 0, 0, 0, 0,
685 0, 0, 0, 0, 0, 0, 0, 0,
686 // sh_offset: after .symtab section. 432 == 0x1b0
687 0xb0, 0x1, 0, 0, 0, 0, 0, 0,
688 // sh_size: 1 null byte + "test\0"
689 6, 0, 0, 0, 0, 0, 0, 0,
695 1, 0, 0, 0, 0, 0, 0, 0,
697 0, 0, 0, 0, 0, 0, 0, 0,
701 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
703 // sh_type: SHT_STRTAB
706 0, 0, 0, 0, 0, 0, 0, 0,
708 0, 0, 0, 0, 0, 0, 0, 0,
709 // sh_offset: after .strtab section. 438 == 0x1b6
710 0xb6, 0x1, 0, 0, 0, 0, 0, 0,
711 // sh_size: all section names
712 33, 0, 0, 0, 0, 0, 0, 0,
718 1, 0, 0, 0, 0, 0, 0, 0,
720 0, 0, 0, 0, 0, 0, 0, 0,
723 // Contents of .symtab section
725 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
726 0, 0, 0, 0, 0, 0, 0, 0,
732 // st_info: STT_NOTYPE, STB_GLOBAL
736 // st_shndx: In .test
739 0, 0, 0, 0, 0, 0, 0, 0,
741 0, 0, 0, 0, 0, 0, 0, 0,
744 // Contents of .strtab section
746 't', 'e', 's', 't', '\0',
749 // Contents of .shstrtab section
751 '.', 't', 'e', 's', 't', '\0',
752 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
753 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
754 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
757 const unsigned int test_file_1_size_64_little
= sizeof test_file_1_64_little
;
759 // 64-bit big-endian version of test_file_1_32_little.
761 const unsigned char test_file_1_64_big
[] =
768 // EI_DATA: big endian
780 // e_machine: a magic value used for testing.
785 0, 0, 0, 0, 0, 0, 0, 0,
787 0, 0, 0, 0, 0, 0, 0, 0,
788 // e_shoff: starts right after file header
789 0, 0, 0, 0, 0, 0, 0, 64,
800 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
806 // Shdr 0: dummy entry
807 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
808 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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,
814 // sh_name: after initial null
816 // sh_type: SHT_PROGBITS
818 // sh_flags: SHF_ALLOC
819 0, 0, 0, 0, 0, 0, 0, 2,
821 0, 0, 0, 0, 0, 0, 0, 0,
822 // sh_offset: after file header + 5 section headers. 384 == 0x180.
823 0, 0, 0, 0, 0, 0, 0x1, 0x80,
825 0, 0, 0, 0, 0, 0, 0, 0,
831 0, 0, 0, 0, 0, 0, 0, 1,
833 0, 0, 0, 0, 0, 0, 0, 0,
837 // sh_name: 1 null byte + ".test\0"
839 // sh_type: SHT_SYMTAB
842 0, 0, 0, 0, 0, 0, 0, 0,
844 0, 0, 0, 0, 0, 0, 0, 0,
845 // sh_offset: after file header + 5 section headers + empty section
847 0, 0, 0, 0, 0, 0, 0x1, 0x80,
848 // sh_size: two symbols: dummy symbol + test symbol
849 0, 0, 0, 0, 0, 0, 0, 48,
850 // sh_link: to .strtab
852 // sh_info: one local symbol, the dummy symbol
855 0, 0, 0, 0, 0, 0, 0, 8,
856 // sh_entsize: size of symbol
857 0, 0, 0, 0, 0, 0, 0, 24,
861 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
863 // sh_type: SHT_STRTAB
866 0, 0, 0, 0, 0, 0, 0, 0,
868 0, 0, 0, 0, 0, 0, 0, 0,
869 // sh_offset: after .symtab section. 432 == 0x1b0
870 0, 0, 0, 0, 0, 0, 0x1, 0xb0,
871 // sh_size: 1 null byte + "test\0"
872 0, 0, 0, 0, 0, 0, 0, 6,
878 0, 0, 0, 0, 0, 0, 0, 1,
880 0, 0, 0, 0, 0, 0, 0, 0,
884 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
886 // sh_type: SHT_STRTAB
889 0, 0, 0, 0, 0, 0, 0, 0,
891 0, 0, 0, 0, 0, 0, 0, 0,
892 // sh_offset: after .strtab section. 438 == 0x1b6
893 0, 0, 0, 0, 0, 0, 0x1, 0xb6,
894 // sh_size: all section names
895 0, 0, 0, 0, 0, 0, 0, 33,
901 0, 0, 0, 0, 0, 0, 0, 1,
903 0, 0, 0, 0, 0, 0, 0, 0,
906 // Contents of .symtab section
908 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
909 0, 0, 0, 0, 0, 0, 0, 0,
915 // st_info: STT_NOTYPE, STB_GLOBAL
919 // st_shndx: In .test
922 0, 0, 0, 0, 0, 0, 0, 0,
924 0, 0, 0, 0, 0, 0, 0, 0,
927 // Contents of .strtab section
929 't', 'e', 's', 't', '\0',
932 // Contents of .shstrtab section
934 '.', 't', 'e', 's', 't', '\0',
935 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
936 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
937 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
940 const unsigned int test_file_1_size_64_big
= sizeof test_file_1_64_big
;
942 } // End namespace gold_testsuite.