1/* script_test_12a.c -- a test case for gold
2
3   Copyright (C) 2015-2020 Free Software Foundation, Inc.
4   Written by Cary Coutant <ccoutant@gmail.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   This tests linker script behavior, that gold distinguishes correctly
24   between
25      *(.x1) *(.x2) *(.x3)
26   and
27      *(.x1 .x2 .x3)
28   in an input section spec. In the first case, the output section
29   should contain all .x1 sections, followed by all .x2 sections,
30   then all .x3 sections; i.e.:
31      script_test_12a.o(.x1)
32      script_test_12b.o(.x1)
33      script_test_12a.o(.x2)
34      script_test_12b.o(.x2)
35      script_test_12a.o(.x3)
36      script_test_12b.o(.x3)
37
38   In the second case, the output section should interleave the
39   .x1, .x2, and .x3 sections in the order seen; i.e.:
40      script_test_12a.o(.x1)
41      script_test_12a.o(.x2)
42      script_test_12a.o(.x3)
43      script_test_12b.o(.x1)
44      script_test_12b.o(.x2)
45      script_test_12b.o(.x3)
46
47   The linker scripts set the absolute symbol INTERLEAVED, which we
48   test here to determine which ordering to expect. The scripts also
49   define the symbols test_array_start and test_array_end.
50*/
51
52extern int test_array_start;
53extern int test_array_end;
54extern char interleaved __attribute__((__aligned__(1)));
55
56int
57main(void)
58{
59  int last = 0;
60  int *p;
61  long should_be_interleaved = (long)&interleaved;
62  int mask = (should_be_interleaved == 1 ? 0x7f : 0xff);
63  for (p = &test_array_start; p < &test_array_end; ++p)
64    {
65      int next = *p & mask;
66      if (next <= last)
67	return 1;
68      last = next;
69    }
70  return 0;
71}
72
73int a1[] __attribute((section(".x1"))) = { 0x01, 0x02, 0x03, 0x04 };
74int a2[] __attribute((section(".x2"))) = { 0x11, 0x12, 0x13, 0x14};
75int a3[] __attribute((section(".x3"))) = { 0x21, 0x22, 0x23, 0x24 };
76int a4[] __attribute((section(".x4"))) = { 0xff, 0xff, 0xff, 0xff };
77