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(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::gc_process_relocs"); }
54 scan_relocs(const General_options
&, Symbol_table
*, Layout
*,
55 Sized_relobj
<size
, big_endian
>*, unsigned int,
56 unsigned int, const unsigned char*, size_t, Output_section
*,
57 bool, size_t, const unsigned char*)
58 { ERROR("call to Target_test::scan_relocs"); }
61 relocate_section(const Relocate_info
<size
, big_endian
>*, unsigned int,
62 const unsigned char*, size_t, Output_section
*, bool,
63 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
65 { ERROR("call to Target_test::relocate_section"); }
68 scan_relocatable_relocs(const General_options
&, Symbol_table
*, Layout
*,
69 Sized_relobj
<size
, big_endian
>*, unsigned int,
70 unsigned int, const unsigned char*,
71 size_t, Output_section
*, bool, size_t,
72 const unsigned char*, Relocatable_relocs
*)
73 { ERROR("call to Target_test::scan_relocatable_relocs"); }
76 relocate_for_relocatable(const Relocate_info
<size
, big_endian
>*,
77 unsigned int, const unsigned char*, size_t,
78 Output_section
*, off_t
, const Relocatable_relocs
*,
80 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
81 section_size_type
, unsigned char*,
83 { ERROR("call to Target_test::relocate_for_relocatable"); }
85 static const Target::Target_info test_target_info
;
88 template<int size
, bool big_endian
>
89 const Target::Target_info Target_test
<size
, big_endian
>::test_target_info
=
92 big_endian
, // is_big_endian
93 static_cast<elfcpp::EM
>(0xffff), // machine_code
94 false, // has_make_symbol
96 false, // has_code_fill
97 false, // is_default_stack_executable
99 "/dummy", // dynamic_linker
100 0x08000000, // default_text_segment_address
101 0x1000, // abi_pagesize
102 0x1000 // common_pagesize
107 #ifdef HAVE_TARGET_32_LITTLE
108 Target_test
<32, false> target_test_32_little
;
111 #ifdef HAVE_TARGET_32_BIG
112 Target_test
<32, true> target_test_32_big
;
115 #ifdef HAVE_TARGET_64_LITTLE
116 Target_test
<64, false> target_test_64_little
;
119 #ifdef HAVE_TARGET_64_BIG
120 Target_test
<64, true> target_test_64_big
;
123 // A pointer to the test targets. This is used in CHECKs.
125 #ifdef HAVE_TARGET_32_LITTLE
126 Target
* target_test_pointer_32_little
= &target_test_32_little
;
129 #ifdef HAVE_TARGET_32_BIG
130 Target
* target_test_pointer_32_big
= &target_test_32_big
;
133 #ifdef HAVE_TARGET_64_LITTLE
134 Target
* target_test_pointer_64_little
= &target_test_64_little
;
137 #ifdef HAVE_TARGET_64_BIG
138 Target
* target_test_pointer_64_big
= &target_test_64_big
;
141 // Select the test targets.
143 template<int size
, bool big_endian
>
144 class Target_selector_test
: public Target_selector
147 Target_selector_test()
148 : Target_selector(0xffff, size
, big_endian
, NULL
)
152 do_instantiate_target()
159 do_recognize(int, int, int)
165 #ifdef HAVE_TARGET_32_LITTLE
166 return &target_test_32_little
;
171 #ifdef HAVE_TARGET_32_BIG
172 return &target_test_32_big
;
180 #ifdef HAVE_TARGET_64_LITTLE
181 return &target_test_64_little
;
186 #ifdef HAVE_TARGET_64_BIG
187 return &target_test_64_big
;
196 do_recognize_by_name(const char*)
200 do_supported_names(std::vector
<const char*>*)
204 // Register the test target selectors. These don't need to be
205 // conditionally compiled, as they will return NULL if there is no
208 Target_selector_test
<32, false> target_selector_test_32_little
;
209 Target_selector_test
<32, true> target_selector_test_32_big
;
210 Target_selector_test
<64, false> target_selector_test_64_little
;
211 Target_selector_test
<64, true> target_selector_test_64_big
;
213 // A simple ELF object with one empty section, named ".test" and one
214 // globally visible symbol named "test".
216 const unsigned char test_file_1_32_little
[] =
223 // EI_DATA: little endian
235 // e_machine: a magic value used for testing.
243 // e_shoff: starts right after file header
255 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
261 // Shdr 0: dummy entry
262 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
263 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
264 0, 0, 0, 0, 0, 0, 0, 0,
268 // sh_name: after initial null
270 // sh_type: SHT_PROGBITS
272 // sh_flags: SHF_ALLOC
276 // sh_offset: after file header + 5 section headers
291 // sh_name: 1 null byte + ".test\0"
293 // sh_type: SHT_SYMTAB
299 // sh_offset: after file header + 5 section headers + empty section
301 // sh_size: two symbols: dummy symbol + test symbol
303 // sh_link: to .strtab
305 // sh_info: one local symbol, the dummy symbol
309 // sh_entsize: size of symbol
314 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
316 // sh_type: SHT_STRTAB
322 // sh_offset: after .symtab section. 284 == 0x11c
324 // sh_size: 1 null byte + "test\0"
337 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
339 // sh_type: SHT_STRTAB
345 // sh_offset: after .strtab section. 290 == 0x122
347 // sh_size: all section names
359 // Contents of .symtab section
361 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
371 // st_info: STT_NOTYPE, STB_GLOBAL
375 // st_shndx: In .test
379 // Contents of .strtab section
381 't', 'e', 's', 't', '\0',
384 // Contents of .shstrtab section
386 '.', 't', 'e', 's', 't', '\0',
387 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
388 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
389 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
392 const unsigned int test_file_1_size_32_little
= sizeof test_file_1_32_little
;
394 // 32-bit big-endian version of test_file_1_32_little.
396 const unsigned char test_file_1_32_big
[] =
403 // EI_DATA: big endian
415 // e_machine: a magic value used for testing.
423 // e_shoff: starts right after file header
435 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
441 // Shdr 0: dummy entry
442 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
443 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
444 0, 0, 0, 0, 0, 0, 0, 0,
448 // sh_name: after initial null
450 // sh_type: SHT_PROGBITS
452 // sh_flags: SHF_ALLOC
456 // sh_offset: after file header + 5 section headers
471 // sh_name: 1 null byte + ".test\0"
473 // sh_type: SHT_SYMTAB
479 // sh_offset: after file header + 5 section headers + empty section
481 // sh_size: two symbols: dummy symbol + test symbol
483 // sh_link: to .strtab
485 // sh_info: one local symbol, the dummy symbol
489 // sh_entsize: size of symbol
494 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
496 // sh_type: SHT_STRTAB
502 // sh_offset: after .symtab section. 284 == 0x11c
504 // sh_size: 1 null byte + "test\0"
517 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
519 // sh_type: SHT_STRTAB
525 // sh_offset: after .strtab section. 290 == 0x122
527 // sh_size: all section names
539 // Contents of .symtab section
541 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
551 // st_info: STT_NOTYPE, STB_GLOBAL
555 // st_shndx: In .test
559 // Contents of .strtab section
561 't', 'e', 's', 't', '\0',
564 // Contents of .shstrtab section
566 '.', 't', 'e', 's', 't', '\0',
567 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
568 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
569 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
572 const unsigned int test_file_1_size_32_big
= sizeof test_file_1_32_big
;
574 // 64-bit little-endian version of test_file_1_32_little.
576 const unsigned char test_file_1_64_little
[] =
583 // EI_DATA: little endian
595 // e_machine: a magic value used for testing.
600 0, 0, 0, 0, 0, 0, 0, 0,
602 0, 0, 0, 0, 0, 0, 0, 0,
603 // e_shoff: starts right after file header
604 64, 0, 0, 0, 0, 0, 0, 0,
615 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
621 // Shdr 0: dummy entry
622 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
623 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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,
629 // sh_name: after initial null
631 // sh_type: SHT_PROGBITS
633 // sh_flags: SHF_ALLOC
634 2, 0, 0, 0, 0, 0, 0, 0,
636 0, 0, 0, 0, 0, 0, 0, 0,
637 // sh_offset: after file header + 5 section headers. 384 == 0x180.
638 0x80, 0x1, 0, 0, 0, 0, 0, 0,
640 0, 0, 0, 0, 0, 0, 0, 0,
646 1, 0, 0, 0, 0, 0, 0, 0,
648 0, 0, 0, 0, 0, 0, 0, 0,
652 // sh_name: 1 null byte + ".test\0"
654 // sh_type: SHT_SYMTAB
657 0, 0, 0, 0, 0, 0, 0, 0,
659 0, 0, 0, 0, 0, 0, 0, 0,
660 // sh_offset: after file header + 5 section headers + empty section
662 0x80, 0x1, 0, 0, 0, 0, 0, 0,
663 // sh_size: two symbols: dummy symbol + test symbol
664 48, 0, 0, 0, 0, 0, 0, 0,
665 // sh_link: to .strtab
667 // sh_info: one local symbol, the dummy symbol
670 8, 0, 0, 0, 0, 0, 0, 0,
671 // sh_entsize: size of symbol
672 24, 0, 0, 0, 0, 0, 0, 0,
676 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
678 // sh_type: SHT_STRTAB
681 0, 0, 0, 0, 0, 0, 0, 0,
683 0, 0, 0, 0, 0, 0, 0, 0,
684 // sh_offset: after .symtab section. 432 == 0x1b0
685 0xb0, 0x1, 0, 0, 0, 0, 0, 0,
686 // sh_size: 1 null byte + "test\0"
687 6, 0, 0, 0, 0, 0, 0, 0,
693 1, 0, 0, 0, 0, 0, 0, 0,
695 0, 0, 0, 0, 0, 0, 0, 0,
699 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
701 // sh_type: SHT_STRTAB
704 0, 0, 0, 0, 0, 0, 0, 0,
706 0, 0, 0, 0, 0, 0, 0, 0,
707 // sh_offset: after .strtab section. 438 == 0x1b6
708 0xb6, 0x1, 0, 0, 0, 0, 0, 0,
709 // sh_size: all section names
710 33, 0, 0, 0, 0, 0, 0, 0,
716 1, 0, 0, 0, 0, 0, 0, 0,
718 0, 0, 0, 0, 0, 0, 0, 0,
721 // Contents of .symtab section
723 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
724 0, 0, 0, 0, 0, 0, 0, 0,
730 // st_info: STT_NOTYPE, STB_GLOBAL
734 // st_shndx: In .test
737 0, 0, 0, 0, 0, 0, 0, 0,
739 0, 0, 0, 0, 0, 0, 0, 0,
742 // Contents of .strtab section
744 't', 'e', 's', 't', '\0',
747 // Contents of .shstrtab section
749 '.', 't', 'e', 's', 't', '\0',
750 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
751 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
752 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
755 const unsigned int test_file_1_size_64_little
= sizeof test_file_1_64_little
;
757 // 64-bit big-endian version of test_file_1_32_little.
759 const unsigned char test_file_1_64_big
[] =
766 // EI_DATA: big endian
778 // e_machine: a magic value used for testing.
783 0, 0, 0, 0, 0, 0, 0, 0,
785 0, 0, 0, 0, 0, 0, 0, 0,
786 // e_shoff: starts right after file header
787 0, 0, 0, 0, 0, 0, 0, 64,
798 // e_shnum: dummy, .test, .symtab, .strtab, .shstrtab
804 // Shdr 0: dummy entry
805 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
806 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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,
812 // sh_name: after initial null
814 // sh_type: SHT_PROGBITS
816 // sh_flags: SHF_ALLOC
817 0, 0, 0, 0, 0, 0, 0, 2,
819 0, 0, 0, 0, 0, 0, 0, 0,
820 // sh_offset: after file header + 5 section headers. 384 == 0x180.
821 0, 0, 0, 0, 0, 0, 0x1, 0x80,
823 0, 0, 0, 0, 0, 0, 0, 0,
829 0, 0, 0, 0, 0, 0, 0, 1,
831 0, 0, 0, 0, 0, 0, 0, 0,
835 // sh_name: 1 null byte + ".test\0"
837 // sh_type: SHT_SYMTAB
840 0, 0, 0, 0, 0, 0, 0, 0,
842 0, 0, 0, 0, 0, 0, 0, 0,
843 // sh_offset: after file header + 5 section headers + empty section
845 0, 0, 0, 0, 0, 0, 0x1, 0x80,
846 // sh_size: two symbols: dummy symbol + test symbol
847 0, 0, 0, 0, 0, 0, 0, 48,
848 // sh_link: to .strtab
850 // sh_info: one local symbol, the dummy symbol
853 0, 0, 0, 0, 0, 0, 0, 8,
854 // sh_entsize: size of symbol
855 0, 0, 0, 0, 0, 0, 0, 24,
859 // sh_name: 1 null byte + ".test\0" + ".symtab\0"
861 // sh_type: SHT_STRTAB
864 0, 0, 0, 0, 0, 0, 0, 0,
866 0, 0, 0, 0, 0, 0, 0, 0,
867 // sh_offset: after .symtab section. 432 == 0x1b0
868 0, 0, 0, 0, 0, 0, 0x1, 0xb0,
869 // sh_size: 1 null byte + "test\0"
870 0, 0, 0, 0, 0, 0, 0, 6,
876 0, 0, 0, 0, 0, 0, 0, 1,
878 0, 0, 0, 0, 0, 0, 0, 0,
882 // sh_name: 1 null byte + ".test\0" + ".symtab\0" + ".strtab\0"
884 // sh_type: SHT_STRTAB
887 0, 0, 0, 0, 0, 0, 0, 0,
889 0, 0, 0, 0, 0, 0, 0, 0,
890 // sh_offset: after .strtab section. 438 == 0x1b6
891 0, 0, 0, 0, 0, 0, 0x1, 0xb6,
892 // sh_size: all section names
893 0, 0, 0, 0, 0, 0, 0, 33,
899 0, 0, 0, 0, 0, 0, 0, 1,
901 0, 0, 0, 0, 0, 0, 0, 0,
904 // Contents of .symtab section
906 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
907 0, 0, 0, 0, 0, 0, 0, 0,
913 // st_info: STT_NOTYPE, STB_GLOBAL
917 // st_shndx: In .test
920 0, 0, 0, 0, 0, 0, 0, 0,
922 0, 0, 0, 0, 0, 0, 0, 0,
925 // Contents of .strtab section
927 't', 'e', 's', 't', '\0',
930 // Contents of .shstrtab section
932 '.', 't', 'e', 's', 't', '\0',
933 '.', 's', 'y', 'm', 't', 'a', 'b', '\0',
934 '.', 's', 't', 'r', 't', 'a', 'b', '\0',
935 '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', '\0'
938 const unsigned int test_file_1_size_64_big
= sizeof test_file_1_64_big
;
940 } // End namespace gold_testsuite.