1 // basic_test.cc -- a test case for gold
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.
23 // The goal of this program is to produce as many different types of
24 // relocations as we can in a stand-alone program that does not use
25 // TLS. This program is compiled without optimization.
27 // 1 Code reference to global data.
28 // 2 Code reference to static data.
29 // 3 Code reference to BSS data.
30 // 4 Code reference to offset within global data.
31 // 5 Code reference to offset within static data.
32 // 6 Code reference to offset within BSS data.
33 // 7 Switch statement with a table of destinations.
34 // 8 Taking the address of a label (a gcc extension).
35 // 9 Taking the address of a nested function (a gcc extension).
36 // 10 Data reference to global data.
37 // 11 Data reference to static data.
38 // 12 Data reference to BSS data.
39 // 13 Data reference to offset within global data.
40 // 14 Data reference to offset within static data.
41 // 15 Data reference to offset within BSS data.
43 // 17 Inline function.
44 // 18 Call through pointer to method.
45 // 19 Initialize variable to pointer to method.
46 // 20 Global constructor and destructor.
48 // 1 Code reference to global data.
51 // 2 Code reference to static data.
54 // 3 Code reference to BSS data (initialized after program starts, to
58 // 4 Code reference to offset within global data.
59 char t4
[] = "Hello, world";
61 // 5 Code reference to offset within static data.
62 static char t5
[] = "Hello, world";
64 // 6 Code reference to offset within BSS data (initialized after
65 // program starts, to contents of t4).
68 // Test cases 1 through 6.
81 // 7 Switch statement with a table of destinations.
113 // 8 Taking the address of a label (a gcc extension).
118 for (int j
= 0; j
< 10; ++j
)
135 // 9 Taking the address of a nested function (a gcc extension).
136 // Disabled because this is only supported in C, not C++.
141 return (*pfn
)(10) - 10;
159 // 10 Data reference to global data.
162 // 11 Data reference to static data.
165 // 12 Data reference to BSS data.
168 // 13 Data reference to offset within global data.
171 // 14 Data reference to offset within static data.
174 // 15 Data reference to offset within BSS data.
177 // Test cases 10 through 15.
203 class t16b
: public t16a
216 return t16v
.t() == 92;
219 // 17 Inline function.
233 // 18 Call through pointer to method.
250 t18f(int (t18a::* p
)())
258 return t18f(&t18a::ta
) == 65;
261 // 19 Initialize variable to pointer to method.
263 int (t18a::* t19v
)() = &t18a::tb
;
268 return (t18v
.*t19v
)() == 90;
271 // 20 Global constructor and destructor.
293 return t20v
.get() == 96;
296 // Main function. Initialize variables and call test functions.
302 for (int i
= 0; i
< 13; ++i
)