]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gold/testsuite/script_test_2.cc
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gold / testsuite / script_test_2.cc
1 // script_test_2.cc -- linker script test 2 for gold -*- C++ -*-
2
3 // Copyright (C) 2008-2021 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[] __attribute__((__aligned__(1)));
32 extern char start_test_area_1[] __attribute__((__aligned__(1)));
33 extern char start_data[] __attribute__((__aligned__(1)));
34 extern char end_data[] __attribute__((__aligned__(1)));
35 extern char start_fill[] __attribute__((__aligned__(1)));
36 extern char end_fill[] __attribute__((__aligned__(1)));
37 extern char end_test_area[] __attribute__((__aligned__(1)));
38 extern char test_addr[] __attribute__((__aligned__(1)));
39 extern char test_addr_alias[] __attribute__((__aligned__(1)));
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) == 0x20000020);
46
47 assert(strcmp(start_test_area_1, "test bb") == 0);
48
49 // Next the string from script_test_2a.o, after the subalign.
50 for (int i = 7; i < 32; ++i)
51 assert(start_test_area_1[i] == 0);
52 assert(strcmp(start_test_area_1 + 32, "test aa") == 0);
53
54 // Skip to start_data at relative offset 60.
55 for (int i = 32 + 7; i < 60; ++i)
56 assert(start_test_area_1[i] == 0);
57 assert(reinterpret_cast<uintptr_t>(start_test_area_1 + 60)
58 == reinterpret_cast<uintptr_t>(start_data));
59 assert(memcmp(start_data, "\1\2\0\4\0\0\0\010\0\0\0\0\0\0\0", 15) == 0
60 || memcmp(start_data, "\1\0\2\0\0\0\4\0\0\0\0\0\0\0\010", 15) == 0);
61 assert(end_data == start_data + 15);
62
63 // Check that FILL works as expected.
64 assert(start_fill == end_data);
65 assert(memcmp(start_fill, "\x12\x34\x56\x78\x12\x34\x56\0", 8) == 0);
66 assert(end_fill == start_fill + 8);
67
68 assert(end_test_area == end_fill);
69
70 assert(test_addr == start_test_area_1);
71 assert(test_addr_alias == test_addr);
72 }