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, size_t,
50 const unsigned char*, Symbol
**)
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, unsigned char*,
56 typename
elfcpp::Elf_types
<size
>::Elf_Addr
, off_t
)
57 { ERROR("call to Target_test::relocate_section"); }
59 static const Target::Target_info test_target_info
;
62 template<int size
, bool big_endian
>
63 const Target::Target_info Target_test
<size
, big_endian
>::test_target_info
=
66 big_endian
, // is_big_endian
67 static_cast<elfcpp::EM
>(0xffff), // machine_code
68 false, // has_make_symbol
70 false, // has_code_fill
71 false, // is_default_stack_executable
72 "/dummy", // dynamic_linker
73 0x08000000, // default_text_segment_address
74 0x1000, // abi_pagesize
75 0x1000 // common_pagesize
80 #ifdef HAVE_TARGET_32_LITTLE
81 Target_test
<32, false> target_test_32_little
;
84 #ifdef HAVE_TARGET_32_BIG
85 Target_test
<32, true> target_test_32_big
;
88 #ifdef HAVE_TARGET_64_LITTLE
89 Target_test
<64, false> target_test_64_little
;
92 #ifdef HAVE_TARGET_64_BIG
93 Target_test
<64, true> target_test_64_big
;
96 // A pointer to the test targets. This is used in CHECKs.
98 #ifdef HAVE_TARGET_32_LITTLE
99 Target
* target_test_pointer_32_little
= &target_test_32_little
;
102 #ifdef HAVE_TARGET_32_BIG
103 Target
* target_test_pointer_32_big
= &target_test_32_big
;
106 #ifdef HAVE_TARGET_64_LITTLE
107 Target
* target_test_pointer_64_little
= &target_test_64_little
;
110 #ifdef HAVE_TARGET_64_BIG
111 Target
* target_test_pointer_64_big
= &target_test_64_big
;
114 // Select the test targets.
116 template<int size
, bool big_endian
>
117 class Target_selector_test
: public Target_selector
120 Target_selector_test()
121 : Target_selector(0xffff, size
, big_endian
)
125 recognize(int, int, int)
131 #ifdef HAVE_TARGET_32_LITTLE
132 return &target_test_32_little
;
137 #ifdef HAVE_TARGET_32_BIG
138 return &target_test_32_big
;
146 #ifdef HAVE_TARGET_64_LITTLE
147 return &target_test_64_little
;
152 #ifdef HAVE_TARGET_64_BIG
153 return &target_test_64_big
;
162 // Register the test target selectors. These don't need to be
163 // conditionally compiled, as they will return NULL if there is no
166 Target_selector_test
<32, false> target_selector_test_32_little
;
167 Target_selector_test
<32, true> target_selector_test_32_big
;
168 Target_selector_test
<64, false> target_selector_test_64_little
;
169 Target_selector_test
<64, true> target_selector_test_64_big
;
171 // A simple ELF object with one empty section, named ".test" and one
172 // globally visible symbol named "test".
174 const unsigned char test_file_1_32_little
[] =
181 // EI_DATA: little endian
193 // e_machine: a magic value used for testing.
201 // e_shoff: starts right after file header
213 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
219 // Shdr 0: dummy entry
220 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
221 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
222 0, 0, 0, 0, 0, 0, 0, 0,
226 // sh_name: after initial null
228 // sh_type: SHT_PROGBITS
230 // sh_flags: SHF_ALLOC
234 // sh_offset: after file header + 5 section headers
249 // sh_name: 1 null byte + ".test\0"
251 // sh_type: SHT_SYMTAB
257 // sh_offset: after file header + 5 section headers + empty section
259 // sh_size: two symbols: dummy symbol + test symbol
261 // sh_link: to .strtab
263 // sh_info: one local symbol, the dummy symbol
267 // sh_entsize: size of symbol
272 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
274 // sh_type: SHT_STRTAB
280 // sh_offset: after .symtab section. 284 == 0x11c
282 // sh_size: 1 null byte + "test\0"
295 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
297 // sh_type: SHT_STRTAB
303 // sh_offset: after .strtab section. 290 == 0x122
305 // sh_size: all section names
317 // Contents of .symtab section
319 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
329 // st_info: STT_NOTYPE, STB_GLOBAL
333 // st_shndx: In .test
337 // Contents of .strtab section
339 't', 'e', 's', 't', '\0',
342 // Contents of .shstrtab section
344 '.', 't', 'e', 's', 't', '\0',
345 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
346 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
347 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
350 const unsigned int test_file_1_size_32_little
= sizeof test_file_1_32_little
;
352 // 32-bit big-endian version of test_file_1_32_little.
354 const unsigned char test_file_1_32_big
[] =
361 // EI_DATA: big endian
373 // e_machine: a magic value used for testing.
381 // e_shoff: starts right after file header
393 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
399 // Shdr 0: dummy entry
400 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
401 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
402 0, 0, 0, 0, 0, 0, 0, 0,
406 // sh_name: after initial null
408 // sh_type: SHT_PROGBITS
410 // sh_flags: SHF_ALLOC
414 // sh_offset: after file header + 5 section headers
429 // sh_name: 1 null byte + ".test\0"
431 // sh_type: SHT_SYMTAB
437 // sh_offset: after file header + 5 section headers + empty section
439 // sh_size: two symbols: dummy symbol + test symbol
441 // sh_link: to .strtab
443 // sh_info: one local symbol, the dummy symbol
447 // sh_entsize: size of symbol
452 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
454 // sh_type: SHT_STRTAB
460 // sh_offset: after .symtab section. 284 == 0x11c
462 // sh_size: 1 null byte + "test\0"
475 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
477 // sh_type: SHT_STRTAB
483 // sh_offset: after .strtab section. 290 == 0x122
485 // sh_size: all section names
497 // Contents of .symtab section
499 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
509 // st_info: STT_NOTYPE, STB_GLOBAL
513 // st_shndx: In .test
517 // Contents of .strtab section
519 't', 'e', 's', 't', '\0',
522 // Contents of .shstrtab section
524 '.', 't', 'e', 's', 't', '\0',
525 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
526 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
527 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
530 const unsigned int test_file_1_size_32_big
= sizeof test_file_1_32_big
;
532 // 64-bit little-endian version of test_file_1_32_little.
534 const unsigned char test_file_1_64_little
[] =
541 // EI_DATA: little endian
553 // e_machine: a magic value used for testing.
558 0, 0, 0, 0, 0, 0, 0, 0,
560 0, 0, 0, 0, 0, 0, 0, 0,
561 // e_shoff: starts right after file header
562 64, 0, 0, 0, 0, 0, 0, 0,
573 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
579 // Shdr 0: dummy entry
580 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
581 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
582 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
583 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
587 // sh_name: after initial null
589 // sh_type: SHT_PROGBITS
591 // sh_flags: SHF_ALLOC
592 2, 0, 0, 0, 0, 0, 0, 0,
594 0, 0, 0, 0, 0, 0, 0, 0,
595 // sh_offset: after file header + 5 section headers. 384 == 0x180.
596 0x80, 0x1, 0, 0, 0, 0, 0, 0,
598 0, 0, 0, 0, 0, 0, 0, 0,
604 1, 0, 0, 0, 0, 0, 0, 0,
606 0, 0, 0, 0, 0, 0, 0, 0,
610 // sh_name: 1 null byte + ".test\0"
612 // sh_type: SHT_SYMTAB
615 0, 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 + empty section
620 0x80, 0x1, 0, 0, 0, 0, 0, 0,
621 // sh_size: two symbols: dummy symbol + test symbol
622 48, 0, 0, 0, 0, 0, 0, 0,
623 // sh_link: to .strtab
625 // sh_info: one local symbol, the dummy symbol
628 8, 0, 0, 0, 0, 0, 0, 0,
629 // sh_entsize: size of symbol
630 24, 0, 0, 0, 0, 0, 0, 0,
634 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
636 // sh_type: SHT_STRTAB
639 0, 0, 0, 0, 0, 0, 0, 0,
641 0, 0, 0, 0, 0, 0, 0, 0,
642 // sh_offset: after .symtab section. 432 == 0x1b0
643 0xb0, 0x1, 0, 0, 0, 0, 0, 0,
644 // sh_size: 1 null byte + "test\0"
645 6, 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" + ".symtab\0" + ".strtab\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 .strtab section. 438 == 0x1b6
666 0xb6, 0x1, 0, 0, 0, 0, 0, 0,
667 // sh_size: all section names
668 33, 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,
679 // Contents of .symtab section
681 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
682 0, 0, 0, 0, 0, 0, 0, 0,
688 // st_info: STT_NOTYPE, STB_GLOBAL
692 // st_shndx: In .test
695 0, 0, 0, 0, 0, 0, 0, 0,
697 0, 0, 0, 0, 0, 0, 0, 0,
700 // Contents of .strtab section
702 't', 'e', 's', 't', '\0',
705 // Contents of .shstrtab section
707 '.', 't', 'e', 's', 't', '\0',
708 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
709 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
710 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
713 const unsigned int test_file_1_size_64_little
= sizeof test_file_1_64_little
;
715 // 64-bit big-endian version of test_file_1_32_little.
717 const unsigned char test_file_1_64_big
[] =
724 // EI_DATA: big endian
736 // e_machine: a magic value used for testing.
741 0, 0, 0, 0, 0, 0, 0, 0,
743 0, 0, 0, 0, 0, 0, 0, 0,
744 // e_shoff: starts right after file header
745 0, 0, 0, 0, 0, 0, 0, 64,
756 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
762 // Shdr 0: dummy entry
763 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
764 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
765 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
766 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
770 // sh_name: after initial null
772 // sh_type: SHT_PROGBITS
774 // sh_flags: SHF_ALLOC
775 0, 0, 0, 0, 0, 0, 0, 2,
777 0, 0, 0, 0, 0, 0, 0, 0,
778 // sh_offset: after file header + 5 section headers. 384 == 0x180.
779 0, 0, 0, 0, 0, 0, 0x1, 0x80,
781 0, 0, 0, 0, 0, 0, 0, 0,
787 0, 0, 0, 0, 0, 0, 0, 1,
789 0, 0, 0, 0, 0, 0, 0, 0,
793 // sh_name: 1 null byte + ".test\0"
795 // sh_type: SHT_SYMTAB
798 0, 0, 0, 0, 0, 0, 0, 0,
800 0, 0, 0, 0, 0, 0, 0, 0,
801 // sh_offset: after file header + 5 section headers + empty section
803 0, 0, 0, 0, 0, 0, 0x1, 0x80,
804 // sh_size: two symbols: dummy symbol + test symbol
805 0, 0, 0, 0, 0, 0, 0, 48,
806 // sh_link: to .strtab
808 // sh_info: one local symbol, the dummy symbol
811 0, 0, 0, 0, 0, 0, 0, 8,
812 // sh_entsize: size of symbol
813 0, 0, 0, 0, 0, 0, 0, 24,
817 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
819 // sh_type: SHT_STRTAB
822 0, 0, 0, 0, 0, 0, 0, 0,
824 0, 0, 0, 0, 0, 0, 0, 0,
825 // sh_offset: after .symtab section. 432 == 0x1b0
826 0, 0, 0, 0, 0, 0, 0x1, 0xb0,
827 // sh_size: 1 null byte + "test\0"
828 0, 0, 0, 0, 0, 0, 0, 6,
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" + ".symtab\0" + ".strtab\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 .strtab section. 438 == 0x1b6
849 0, 0, 0, 0, 0, 0, 0x1, 0xb6,
850 // sh_size: all section names
851 0, 0, 0, 0, 0, 0, 0, 33,
857 0, 0, 0, 0, 0, 0, 0, 1,
859 0, 0, 0, 0, 0, 0, 0, 0,
862 // Contents of .symtab section
864 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
865 0, 0, 0, 0, 0, 0, 0, 0,
871 // st_info: STT_NOTYPE, STB_GLOBAL
875 // st_shndx: In .test
878 0, 0, 0, 0, 0, 0, 0, 0,
880 0, 0, 0, 0, 0, 0, 0, 0,
883 // Contents of .strtab section
885 't', 'e', 's', 't', '\0',
888 // Contents of .shstrtab section
890 '.', 't', 'e', 's', 't', '\0',
891 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
892 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
893 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
896 const unsigned int test_file_1_size_64_big
= sizeof test_file_1_64_big
;
898 } // End namespace gold_testsuite.