xref: /aosp_15_r20/external/elfutils/tests/testfile-dwarf-45.source (revision 7304104da70ce23c86437a01be71edd1a2d7f37e)
1*7304104dSAndroid Build Coastguard Worker# Nonsensical program used to generate an example DWARF4 and DWARF5 file.
2*7304104dSAndroid Build Coastguard Worker# The generated code is the same, but the DWARF representation is different.
3*7304104dSAndroid Build Coastguard Worker
4*7304104dSAndroid Build Coastguard Worker# = hello.h =
5*7304104dSAndroid Build Coastguard Worker
6*7304104dSAndroid Build Coastguard Workerextern int m;
7*7304104dSAndroid Build Coastguard Workerextern int baz (int x);
8*7304104dSAndroid Build Coastguard Worker
9*7304104dSAndroid Build Coastguard Workerstatic inline int
10*7304104dSAndroid Build Coastguard Workerfrob (int a, int b)
11*7304104dSAndroid Build Coastguard Worker{
12*7304104dSAndroid Build Coastguard Worker  int c = a;
13*7304104dSAndroid Build Coastguard Worker
14*7304104dSAndroid Build Coastguard Worker  if (a > b)
15*7304104dSAndroid Build Coastguard Worker    c -= b;
16*7304104dSAndroid Build Coastguard Worker
17*7304104dSAndroid Build Coastguard Worker  return baz (c);
18*7304104dSAndroid Build Coastguard Worker}
19*7304104dSAndroid Build Coastguard Worker
20*7304104dSAndroid Build Coastguard Worker# = hello.c =
21*7304104dSAndroid Build Coastguard Worker
22*7304104dSAndroid Build Coastguard Worker#include <stddef.h>
23*7304104dSAndroid Build Coastguard Worker#include "hello.h"
24*7304104dSAndroid Build Coastguard Worker
25*7304104dSAndroid Build Coastguard Workerextern int main (int, char **);
26*7304104dSAndroid Build Coastguard Workerint m = 2;
27*7304104dSAndroid Build Coastguard Worker
28*7304104dSAndroid Build Coastguard Workerwchar_t foo (wchar_t);
29*7304104dSAndroid Build Coastguard Workerint baz (int x)
30*7304104dSAndroid Build Coastguard Worker{
31*7304104dSAndroid Build Coastguard Worker  int r = x;
32*7304104dSAndroid Build Coastguard Worker
33*7304104dSAndroid Build Coastguard Worker  if (x > m)
34*7304104dSAndroid Build Coastguard Worker    r -= m;
35*7304104dSAndroid Build Coastguard Worker
36*7304104dSAndroid Build Coastguard Worker  r = foo (r);
37*7304104dSAndroid Build Coastguard Worker  return r;
38*7304104dSAndroid Build Coastguard Worker}
39*7304104dSAndroid Build Coastguard Worker
40*7304104dSAndroid Build Coastguard Workerwchar_t
41*7304104dSAndroid Build Coastguard Workerfoo (wchar_t f)
42*7304104dSAndroid Build Coastguard Worker{
43*7304104dSAndroid Build Coastguard Worker  if (f < 0)
44*7304104dSAndroid Build Coastguard Worker    return main (f, NULL);
45*7304104dSAndroid Build Coastguard Worker
46*7304104dSAndroid Build Coastguard Worker  return f > 0 ? frob (f - 1, m) : 0;
47*7304104dSAndroid Build Coastguard Worker}
48*7304104dSAndroid Build Coastguard Worker
49*7304104dSAndroid Build Coastguard Worker# = world.c =
50*7304104dSAndroid Build Coastguard Worker
51*7304104dSAndroid Build Coastguard Worker#include "hello.h"
52*7304104dSAndroid Build Coastguard Worker#include <stdlib.h>
53*7304104dSAndroid Build Coastguard Worker
54*7304104dSAndroid Build Coastguard Workerint
55*7304104dSAndroid Build Coastguard Workercalc (const char *word)
56*7304104dSAndroid Build Coastguard Worker{
57*7304104dSAndroid Build Coastguard Worker  if (word == 0 || word[0] == '\0')
58*7304104dSAndroid Build Coastguard Worker    return 0;
59*7304104dSAndroid Build Coastguard Worker
60*7304104dSAndroid Build Coastguard Worker  return frob (word[0], m + 42);
61*7304104dSAndroid Build Coastguard Worker}
62*7304104dSAndroid Build Coastguard Worker
63*7304104dSAndroid Build Coastguard Workerint
64*7304104dSAndroid Build Coastguard Workermain (int argc, const char **argv)
65*7304104dSAndroid Build Coastguard Worker{
66*7304104dSAndroid Build Coastguard Worker  const char *n;
67*7304104dSAndroid Build Coastguard Worker  if (argc > 1)
68*7304104dSAndroid Build Coastguard Worker    n = argv[0];
69*7304104dSAndroid Build Coastguard Worker  else
70*7304104dSAndroid Build Coastguard Worker    n = "world";
71*7304104dSAndroid Build Coastguard Worker
72*7304104dSAndroid Build Coastguard Worker  exit (calc (n));
73*7304104dSAndroid Build Coastguard Worker}
74*7304104dSAndroid Build Coastguard Worker
75*7304104dSAndroid Build Coastguard Worker$ gcc -gdwarf-4 -gno-as-loc-support -gno-variable-location-views -O2 -c world.c
76*7304104dSAndroid Build Coastguard Worker$ gcc -gdwarf-4 -gno-as-loc-support -gno-variable-location-views -O2 -c hello.c
77*7304104dSAndroid Build Coastguard Worker$ gcc -o testfile-dwarf-4 hello.o world.o
78*7304104dSAndroid Build Coastguard Worker
79*7304104dSAndroid Build Coastguard Worker$ gcc -gdwarf-5 -gno-as-loc-support -gno-variable-location-views -O2 -c world.c
80*7304104dSAndroid Build Coastguard Worker$ gcc -gdwarf-5 -gno-as-loc-support -gno-variable-location-views -O2 -c hello.c
81*7304104dSAndroid Build Coastguard Worker$ gcc -o testfile-dwarf-5 hello.o world.o
82*7304104dSAndroid Build Coastguard Worker
83*7304104dSAndroid Build Coastguard Worker$ gcc -gdwarf-4 -gsplit-dwarf -gno-as-loc-support -gno-variable-location-views -O2 -o testfile-world4.o -c world.c
84*7304104dSAndroid Build Coastguard Worker$ gcc -gdwarf-4 -gsplit-dwarf -gno-as-loc-support -gno-variable-location-views -O2 -o testfile-hello4.o -c hello.c
85*7304104dSAndroid Build Coastguard Worker$ gcc -o testfile-splitdwarf-4 testfile-hello4.o testfile-world4.o
86*7304104dSAndroid Build Coastguard Worker
87*7304104dSAndroid Build Coastguard Worker$ gcc -gdwarf-5 -gsplit-dwarf -gno-as-loc-support -gno-variable-location-views -O2 -o testfile-world5.o -c world.c
88*7304104dSAndroid Build Coastguard Worker$ gcc -gdwarf-5 -gsplit-dwarf -gno-as-loc-support -gno-variable-location-views -O2 -o testfile-hello5.o -c hello.c
89*7304104dSAndroid Build Coastguard Worker$ gcc -o testfile-splitdwarf-5 testfile-hello5.o testfile-world5.o
90