summaryrefslogtreecommitdiff
path: root/ld/testsuite/ld-empic/runtest1.c
blob: f9ab6eb66817c54aca0251ab6a4c26a5309bb4ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* First C source file for actual execution test.  */

/* The main point of this test is to make sure that the code and data
   are truly position independent.  We statically initialize several
   global variables, and make sure that they are correctly adjusted at
   runtime.  */

int i = 1;
int j = 0;
extern int k;
int l;
char small_buf[] = "aaaa";
char *small_pointer = small_buf;
char big_buf[] = "aaaaaaaaaaaaaaaa";
char *big_pointer = big_buf;

extern int bar ();
int (*pbar) () = bar;

static int
foo2 (arg)
     int arg;
{
  l = arg;
  return i + j;
}

int (*pfoo2) () = foo2;

int
chkstr (z, c)
     char *z;
     int c;
{
  /* Switch statements need extra effort to be position independent,
     so we run one here, even though most of the cases will never be
     taken.  */
  switch (c)
    {
    case 1:
    case 2:
    case 3:
      return i - 1;
    case 4:
      break;
    case 5:
    case 6:
    case 7:
    case 8:
    case 9:
      return i * j;
    case 10:
    case 11:
    case 12:
    case 13:
    case 14:
    case 15:
      return j;
    case 16:
      break;
    default:
      return 0;
    }

  while (c-- != 0)
    if (*z++ != 'a')
      return 0;

  return *z == '\0';
}

/* This function is called by the assembler startup routine.  It tries
   to test that everything was correctly initialized.  It returns 0 on
   success, something else on failure.  */

int
foo ()
{
  if (i != 1)
    return 1;
  if (j != 0)
    return 2;
  if (! chkstr (small_buf, 4))
    return 3;
  if (! chkstr (small_pointer, 4))
    return 4;
  if (! chkstr (big_buf, 16))
    return 5;
  if (! chkstr (big_pointer, 16))
    return 6;

  if (l != 0)
    return 7;
  if (foo2 (1) != 1)
    return 8;
  if (l != 1)
    return 9;
  if ((*pfoo2) (2) != 1)
    return 10;
  if (l != 2)
    return 11;

  if (bar (1) != 0)
    return 12;
  if (bar (-1) != 1)
    return 13;
  if ((*pbar) (0xa5a5a5a5) != -1)
    return 14;
  if (k != 0xa5a5a5a5)
    return 15;
  if ((*pbar) (0) != 0xa5a5a5a5)
    return 16;
  if (k != 0)
    return 17;

  return 0;
}