Commit | Line | Data |
---|---|---|
a445fddf ILT |
1 | // script_test_2.cc -- linker script test 2 for gold -*- C++ -*- |
2 | ||
3 | // Copyright 2008 Free Software Foundation, Inc. | |
4 | // Written by Ian Lance Taylor <iant@google.com>. | |
5 | ||
6 | // This file is part of gold. | |
7 | ||
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. | |
12 | ||
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. | |
17 | ||
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. | |
22 | ||
23 | // A test of some uses of the SECTIONS clause. Look at | |
24 | // script_test_2.t to make sense of this test. | |
25 | ||
26 | #include <cassert> | |
27 | #include <cstddef> | |
28 | #include <cstring> | |
29 | #include <stdint.h> | |
30 | ||
31 | extern char start_test_area[]; | |
32 | extern char start_test_area_1[]; | |
33 | extern char start_data[]; | |
34 | extern char end_data[]; | |
35 | extern char start_fill[]; | |
36 | extern char end_fill[]; | |
37 | extern char end_test_area[]; | |
7c07ecec ILT |
38 | extern char test_addr[]; |
39 | extern char test_addr_alias[]; | |
a445fddf ILT |
40 | |
41 | int | |
42 | main(int, char**) | |
43 | { | |
44 | assert(reinterpret_cast<uintptr_t>(start_test_area) == 0x20000001); | |
45 | assert(reinterpret_cast<uintptr_t>(start_test_area_1) == 0x20000010); | |
46 | ||
47 | // We should see the string from script_test_2b.o next. The | |
48 | // subalign should move it up to 0x20000020. | |
49 | for (int i = 0; i < 16; ++i) | |
50 | assert(start_test_area_1[i] == 0); | |
7c98e6bb | 51 | assert(strcmp(start_test_area_1 + 16, "test bb") == 0); |
a445fddf ILT |
52 | |
53 | // Next the string from script_test_2a.o, after the subalign. | |
54 | for (int i = 16 + 7; i < 48; ++i) | |
55 | assert(start_test_area_1[i] == 0); | |
83bfb6b7 | 56 | assert(strcmp(start_test_area_1 + 48, "test aa") == 0); |
a445fddf ILT |
57 | |
58 | // Move four bytes forward to start_data. | |
7c98e6bb | 59 | assert(reinterpret_cast<uintptr_t>(start_test_area_1 + 48 + 8 + 4) |
a445fddf ILT |
60 | == reinterpret_cast<uintptr_t>(start_data)); |
61 | assert(memcmp(start_data, "\1\2\0\4\0\0\0\010\0\0\0\0\0\0\0", 15) == 0 | |
62 | || memcmp(start_data, "\1\0\2\0\0\0\4\0\0\0\0\0\0\0\010", 15) == 0); | |
63 | assert(end_data == start_data + 15); | |
64 | ||
65 | // Check that FILL works as expected. | |
66 | assert(start_fill == end_data); | |
67 | assert(memcmp(start_fill, "\x12\x34\x56\x78\x12\x34\x56\0", 8) == 0); | |
68 | assert(end_fill == start_fill + 8); | |
69 | ||
70 | assert(end_test_area == end_fill); | |
7c07ecec ILT |
71 | |
72 | assert(test_addr == start_test_area_1); | |
73 | assert(test_addr_alias == test_addr); | |
a445fddf | 74 | } |