OpenCores
URL https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [gnu/] [binutils/] [gold/] [testsuite/] [initpri1.c] - Blame information for rev 166

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 khays
/* initpri1.c -- test constructor priorities.
2
 
3
   Copyright 2007, 2008, 2009 Free Software Foundation, Inc.
4
   Copied from the gcc testsuite, where the test was contributed by
5
   Mark Mitchell <mark@codesourcery.com>.
6
 
7
   This file is part of gold.
8
 
9
   This program is free software; you can redistribute it and/or modify
10
   it under the terms of the GNU General Public License as published by
11
   the Free Software Foundation; either version 3 of the License, or
12
   (at your option) any later version.
13
 
14
   This program is distributed in the hope that it will be useful,
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
   GNU General Public License for more details.
18
 
19
   You should have received a copy of the GNU General Public License
20
   along with this program; if not, write to the Free Software
21
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22
   MA 02110-1301, USA.  */
23
 
24
/* This tests that the linker handles constructor and destructor
25
   priorities correctly.  */
26
 
27
#include <stdlib.h>
28
 
29
/* Constructor priorities in attributes were added in gcc 4.3.  */
30
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2)
31
 
32
int i;
33
int j;
34
 
35
void c1(void) __attribute__((constructor (500)));
36
void c2(void) __attribute__((constructor (700)));
37
void c3(void) __attribute__((constructor (600)));
38
 
39
void c1() {
40
  if (i++ != 0)
41
    abort ();
42
}
43
 
44
void c2() {
45
  if (i++ != 2)
46
    abort ();
47
}
48
 
49
void c3() {
50
  if (i++ != 1)
51
    abort ();
52
}
53
 
54
void d1(void) __attribute__((destructor (500)));
55
void d2(void) __attribute__((destructor (700)));
56
void d3(void) __attribute__((destructor (600)));
57
 
58
void d1() {
59
  if (--i != 0)
60
    abort ();
61
}
62
 
63
void d2() {
64
  if (--i != 2)
65
    abort ();
66
}
67
 
68
void d3() {
69
  if (j != 4)
70
    abort ();
71
  if (--i != 1)
72
    abort ();
73
}
74
 
75
void cd4(void) __attribute__((constructor (800), destructor (800)));
76
 
77
void cd4() {
78
  if (i != 3)
79
    abort ();
80
  ++j;
81
}
82
 
83
void cd5(void) __attribute__((constructor, destructor));
84
 
85
void cd5() {
86
  if (i != 3)
87
    abort();
88
  ++j;
89
}
90
 
91
int main (void) {
92
  if (i != 3)
93
    return 1;
94
  if (j != 2)
95
    abort ();
96
  return 0;
97
}
98
 
99
#else /* !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2)) */
100
 
101
int main (void) {
102
  exit (0);
103
}
104
 
105
#endif /* !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2)) */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.