1 // testfile.cc -- Dummy ELF objects for testing purposes.
3 // Copyright 2006, 2007 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 scan_relocs(const General_options
&, Symbol_table
*, Layout
*,
48 Sized_relobj
<size
, big_endian
>*, unsigned int,
49 unsigned int, const unsigned char*, size_t, Output_section
*,
50 bool, size_t, const unsigned char*)
51 { ERROR("call to Target_test::scan_relocs"); }
54 relocate_section(const Relocate_info
<size
, big_endian
>*, unsigned int,
55 const unsigned char*, size_t, Output_section
*, bool,
56 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
58 { ERROR("call to Target_test::relocate_section"); }
61 scan_relocatable_relocs(const General_options
&, Symbol_table
*, Layout
*,
62 Sized_relobj
<size
, big_endian
>*, unsigned int,
63 unsigned int, const unsigned char*,
64 size_t, Output_section
*, bool, size_t,
65 const unsigned char*, Relocatable_relocs
*)
66 { ERROR("call to Target_test::scan_relocatable_relocs"); }
69 relocate_for_relocatable(const Relocate_info
<size
, big_endian
>*,
70 unsigned int, const unsigned char*, size_t,
71 Output_section
*, off_t
, const Relocatable_relocs
*,
73 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
74 section_size_type
, unsigned char*,
76 { ERROR("call to Target_test::relocate_for_relocatable"); }
78 static const Target::Target_info test_target_info
;
81 template<int size
, bool big_endian
>
82 const Target::Target_info Target_test
<size
, big_endian
>::test_target_info
=
85 big_endian
, // is_big_endian
86 static_cast<elfcpp::EM
>(0xffff), // machine_code
87 false, // has_make_symbol
89 false, // has_code_fill
90 false, // is_default_stack_executable
91 "/dummy", // dynamic_linker
92 0x08000000, // default_text_segment_address
93 0x1000, // abi_pagesize
94 0x1000 // common_pagesize
99 #ifdef HAVE_TARGET_32_LITTLE
100 Target_test
<32, false> target_test_32_little
;
103 #ifdef HAVE_TARGET_32_BIG
104 Target_test
<32, true> target_test_32_big
;
107 #ifdef HAVE_TARGET_64_LITTLE
108 Target_test
<64, false> target_test_64_little
;
111 #ifdef HAVE_TARGET_64_BIG
112 Target_test
<64, true> target_test_64_big
;
115 // A pointer to the test targets. This is used in CHECKs.
117 #ifdef HAVE_TARGET_32_LITTLE
118 Target
* target_test_pointer_32_little
= &target_test_32_little
;
121 #ifdef HAVE_TARGET_32_BIG
122 Target
* target_test_pointer_32_big
= &target_test_32_big
;
125 #ifdef HAVE_TARGET_64_LITTLE
126 Target
* target_test_pointer_64_little
= &target_test_64_little
;
129 #ifdef HAVE_TARGET_64_BIG
130 Target
* target_test_pointer_64_big
= &target_test_64_big
;
133 // Select the test targets.
135 template<int size
, bool big_endian
>
136 class Target_selector_test
: public Target_selector
139 Target_selector_test()
140 : Target_selector(0xffff, size
, big_endian
)
144 recognize(int, int, int)
150 #ifdef HAVE_TARGET_32_LITTLE
151 return &target_test_32_little
;
156 #ifdef HAVE_TARGET_32_BIG
157 return &target_test_32_big
;
165 #ifdef HAVE_TARGET_64_LITTLE
166 return &target_test_64_little
;
171 #ifdef HAVE_TARGET_64_BIG
172 return &target_test_64_big
;
181 recognize_by_name(const char*)
185 // Register the test target selectors. These don't need to be
186 // conditionally compiled, as they will return NULL if there is no
189 Target_selector_test
<32, false> target_selector_test_32_little
;
190 Target_selector_test
<32, true> target_selector_test_32_big
;
191 Target_selector_test
<64, false> target_selector_test_64_little
;
192 Target_selector_test
<64, true> target_selector_test_64_big
;
194 // A simple ELF object with one empty section, named ".test" and one
195 // globally visible symbol named "test".
197 const unsigned char test_file_1_32_little
[] =
204 // EI_DATA: little endian
216 // e_machine: a magic value used for testing.
224 // e_shoff: starts right after file header
236 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
242 // Shdr 0: dummy entry
243 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
244 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
245 0, 0, 0, 0, 0, 0, 0, 0,
249 // sh_name: after initial null
251 // sh_type: SHT_PROGBITS
253 // sh_flags: SHF_ALLOC
257 // sh_offset: after file header + 5 section headers
272 // sh_name: 1 null byte + ".test\0"
274 // sh_type: SHT_SYMTAB
280 // sh_offset: after file header + 5 section headers + empty section
282 // sh_size: two symbols: dummy symbol + test symbol
284 // sh_link: to .strtab
286 // sh_info: one local symbol, the dummy symbol
290 // sh_entsize: size of symbol
295 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
297 // sh_type: SHT_STRTAB
303 // sh_offset: after .symtab section. 284 == 0x11c
305 // sh_size: 1 null byte + "test\0"
318 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
320 // sh_type: SHT_STRTAB
326 // sh_offset: after .strtab section. 290 == 0x122
328 // sh_size: all section names
340 // Contents of .symtab section
342 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
352 // st_info: STT_NOTYPE, STB_GLOBAL
356 // st_shndx: In .test
360 // Contents of .strtab section
362 't', 'e', 's', 't', '\0',
365 // Contents of .shstrtab section
367 '.', 't', 'e', 's', 't', '\0',
368 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
369 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
370 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
373 const unsigned int test_file_1_size_32_little
= sizeof test_file_1_32_little
;
375 // 32-bit big-endian version of test_file_1_32_little.
377 const unsigned char test_file_1_32_big
[] =
384 // EI_DATA: big endian
396 // e_machine: a magic value used for testing.
404 // e_shoff: starts right after file header
416 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
422 // Shdr 0: dummy entry
423 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
424 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
425 0, 0, 0, 0, 0, 0, 0, 0,
429 // sh_name: after initial null
431 // sh_type: SHT_PROGBITS
433 // sh_flags: SHF_ALLOC
437 // sh_offset: after file header + 5 section headers
452 // sh_name: 1 null byte + ".test\0"
454 // sh_type: SHT_SYMTAB
460 // sh_offset: after file header + 5 section headers + empty section
462 // sh_size: two symbols: dummy symbol + test symbol
464 // sh_link: to .strtab
466 // sh_info: one local symbol, the dummy symbol
470 // sh_entsize: size of symbol
475 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
477 // sh_type: SHT_STRTAB
483 // sh_offset: after .symtab section. 284 == 0x11c
485 // sh_size: 1 null byte + "test\0"
498 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
500 // sh_type: SHT_STRTAB
506 // sh_offset: after .strtab section. 290 == 0x122
508 // sh_size: all section names
520 // Contents of .symtab section
522 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
532 // st_info: STT_NOTYPE, STB_GLOBAL
536 // st_shndx: In .test
540 // Contents of .strtab section
542 't', 'e', 's', 't', '\0',
545 // Contents of .shstrtab section
547 '.', 't', 'e', 's', 't', '\0',
548 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
549 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
550 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
553 const unsigned int test_file_1_size_32_big
= sizeof test_file_1_32_big
;
555 // 64-bit little-endian version of test_file_1_32_little.
557 const unsigned char test_file_1_64_little
[] =
564 // EI_DATA: little endian
576 // e_machine: a magic value used for testing.
581 0, 0, 0, 0, 0, 0, 0, 0,
583 0, 0, 0, 0, 0, 0, 0, 0,
584 // e_shoff: starts right after file header
585 64, 0, 0, 0, 0, 0, 0, 0,
596 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
602 // Shdr 0: dummy entry
603 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
604 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
605 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
606 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
610 // sh_name: after initial null
612 // sh_type: SHT_PROGBITS
614 // sh_flags: SHF_ALLOC
615 2, 0, 0, 0, 0, 0, 0, 0,
617 0, 0, 0, 0, 0, 0, 0, 0,
618 // sh_offset: after file header + 5 section headers. 384 == 0x180.
619 0x80, 0x1, 0, 0, 0, 0, 0, 0,
621 0, 0, 0, 0, 0, 0, 0, 0,
627 1, 0, 0, 0, 0, 0, 0, 0,
629 0, 0, 0, 0, 0, 0, 0, 0,
633 // sh_name: 1 null byte + ".test\0"
635 // sh_type: SHT_SYMTAB
638 0, 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 + empty section
643 0x80, 0x1, 0, 0, 0, 0, 0, 0,
644 // sh_size: two symbols: dummy symbol + test symbol
645 48, 0, 0, 0, 0, 0, 0, 0,
646 // sh_link: to .strtab
648 // sh_info: one local symbol, the dummy symbol
651 8, 0, 0, 0, 0, 0, 0, 0,
652 // sh_entsize: size of symbol
653 24, 0, 0, 0, 0, 0, 0, 0,
657 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
659 // sh_type: SHT_STRTAB
662 0, 0, 0, 0, 0, 0, 0, 0,
664 0, 0, 0, 0, 0, 0, 0, 0,
665 // sh_offset: after .symtab section. 432 == 0x1b0
666 0xb0, 0x1, 0, 0, 0, 0, 0, 0,
667 // sh_size: 1 null byte + "test\0"
668 6, 0, 0, 0, 0, 0, 0, 0,
674 1, 0, 0, 0, 0, 0, 0, 0,
676 0, 0, 0, 0, 0, 0, 0, 0,
680 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\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 .strtab section. 438 == 0x1b6
689 0xb6, 0x1, 0, 0, 0, 0, 0, 0,
690 // sh_size: all section names
691 33, 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,
702 // Contents of .symtab section
704 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
705 0, 0, 0, 0, 0, 0, 0, 0,
711 // st_info: STT_NOTYPE, STB_GLOBAL
715 // st_shndx: In .test
718 0, 0, 0, 0, 0, 0, 0, 0,
720 0, 0, 0, 0, 0, 0, 0, 0,
723 // Contents of .strtab section
725 't', 'e', 's', 't', '\0',
728 // Contents of .shstrtab section
730 '.', 't', 'e', 's', 't', '\0',
731 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
732 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
733 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
736 const unsigned int test_file_1_size_64_little
= sizeof test_file_1_64_little
;
738 // 64-bit big-endian version of test_file_1_32_little.
740 const unsigned char test_file_1_64_big
[] =
747 // EI_DATA: big endian
759 // e_machine: a magic value used for testing.
764 0, 0, 0, 0, 0, 0, 0, 0,
766 0, 0, 0, 0, 0, 0, 0, 0,
767 // e_shoff: starts right after file header
768 0, 0, 0, 0, 0, 0, 0, 64,
779 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
785 // Shdr 0: dummy entry
786 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
787 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
788 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
789 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
793 // sh_name: after initial null
795 // sh_type: SHT_PROGBITS
797 // sh_flags: SHF_ALLOC
798 0, 0, 0, 0, 0, 0, 0, 2,
800 0, 0, 0, 0, 0, 0, 0, 0,
801 // sh_offset: after file header + 5 section headers. 384 == 0x180.
802 0, 0, 0, 0, 0, 0, 0x1, 0x80,
804 0, 0, 0, 0, 0, 0, 0, 0,
810 0, 0, 0, 0, 0, 0, 0, 1,
812 0, 0, 0, 0, 0, 0, 0, 0,
816 // sh_name: 1 null byte + ".test\0"
818 // sh_type: SHT_SYMTAB
821 0, 0, 0, 0, 0, 0, 0, 0,
823 0, 0, 0, 0, 0, 0, 0, 0,
824 // sh_offset: after file header + 5 section headers + empty section
826 0, 0, 0, 0, 0, 0, 0x1, 0x80,
827 // sh_size: two symbols: dummy symbol + test symbol
828 0, 0, 0, 0, 0, 0, 0, 48,
829 // sh_link: to .strtab
831 // sh_info: one local symbol, the dummy symbol
834 0, 0, 0, 0, 0, 0, 0, 8,
835 // sh_entsize: size of symbol
836 0, 0, 0, 0, 0, 0, 0, 24,
840 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
842 // sh_type: SHT_STRTAB
845 0, 0, 0, 0, 0, 0, 0, 0,
847 0, 0, 0, 0, 0, 0, 0, 0,
848 // sh_offset: after .symtab section. 432 == 0x1b0
849 0, 0, 0, 0, 0, 0, 0x1, 0xb0,
850 // sh_size: 1 null byte + "test\0"
851 0, 0, 0, 0, 0, 0, 0, 6,
857 0, 0, 0, 0, 0, 0, 0, 1,
859 0, 0, 0, 0, 0, 0, 0, 0,
863 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\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 .strtab section. 438 == 0x1b6
872 0, 0, 0, 0, 0, 0, 0x1, 0xb6,
873 // sh_size: all section names
874 0, 0, 0, 0, 0, 0, 0, 33,
880 0, 0, 0, 0, 0, 0, 0, 1,
882 0, 0, 0, 0, 0, 0, 0, 0,
885 // Contents of .symtab section
887 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
888 0, 0, 0, 0, 0, 0, 0, 0,
894 // st_info: STT_NOTYPE, STB_GLOBAL
898 // st_shndx: In .test
901 0, 0, 0, 0, 0, 0, 0, 0,
903 0, 0, 0, 0, 0, 0, 0, 0,
906 // Contents of .strtab section
908 't', 'e', 's', 't', '\0',
911 // Contents of .shstrtab section
913 '.', 't', 'e', 's', 't', '\0',
914 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
915 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
916 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
919 const unsigned int test_file_1_size_64_big
= sizeof test_file_1_64_big
;
921 } // End namespace gold_testsuite.