Debian Codegraph @

gcc/testsuite/gcc.dg/pr119151.c

raw
1 /* PR libgcc/119151 */
2 /* Should be run just on targets which don't have _Unwind_Find_FDE in libc.so. */
3 /* { dg-do run { target { { x86_64-*-linux* aarch64*-*-linux* powerpc64*-*-linux* riscv*-*-linux* } && lp64 } } } */
4 /* { dg-options "-O2" } */
5
6 struct object
7 {
8 void *pc_begin, *tbase, *dbase, *single;
9 __SIZE_TYPE__ i;
10 void *fde_end, *next;
11 };
12 struct dwarf_eh_bases
13 {
14 void *tbase, *dbase, *func;
15 };
16 extern void __register_frame_info (const void *, struct object *);
17 extern void *__deregister_frame_info (const void *);
18 extern const void *_Unwind_Find_FDE (void *, struct dwarf_eh_bases *);
19 #define DW_EH_PE_sdata8 0x0c
20 #define DW_EH_PE_pcrel 0x10
21 #define DW_CFA_def_cfa 0x0c
22 #define DW_CFA_offset 0x80
23
24 struct __attribute__((aligned (8))) eh_frame_cie {
25 unsigned len;
26 unsigned tag;
27 unsigned char version;
28 unsigned char augmentation[3];
29 unsigned char code_align_factor;
30 unsigned char data_align_factor;
31 unsigned char ra_column;
32 unsigned char augmentation_size;
33 unsigned char encoding;
34 unsigned char def_cfa;
35 unsigned char def_cfa_op1, def_cfa_op2;
36 unsigned char offset;
37 unsigned char offset_op;
38 };
39 struct __attribute__((aligned (8))) eh_frame_fde {
40 unsigned len;
41 unsigned cie_offset;
42 unsigned long long begin, size;
43 unsigned char augmentation;
44 };
45 struct eh_frame_cie_fde {
46 struct eh_frame_cie cie;
47 struct eh_frame_fde fde;
48 unsigned int zero;
49 struct object obj;
50 } eh_frame[256];
51 unsigned ehidx;
52 unsigned char code[0x800] __attribute__((aligned (8)));
53
54 void *
55 register_range (void *addr, unsigned size)
56 {
57 /* Fills in empty-ish CIE and FDE with pcrel sdata8 encoding so that
58 we don't need to worry about lp64 large code models.
59 We don't actually execute anything in code and only _Unwind_Find_FDE,
60 don't actually try to unwind anything. */
61 eh_frame[ehidx].cie.len
62 = (unsigned) ((char *) &eh_frame[ehidx].fde
63 - (char *) &eh_frame[ehidx].cie.tag);
64 eh_frame[ehidx].cie.tag = 0;
65 eh_frame[ehidx].cie.version = 3;
66 __builtin_memcpy (eh_frame[ehidx].cie.augmentation, "zR", 3);
67 eh_frame[ehidx].cie.code_align_factor = 1;
68 eh_frame[ehidx].cie.data_align_factor = 0x78; /* sleb128 -8 */
69 eh_frame[ehidx].cie.ra_column = 0x10;
70 eh_frame[ehidx].cie.augmentation_size = 1;
71 eh_frame[ehidx].cie.encoding = DW_EH_PE_pcrel | DW_EH_PE_sdata8;
72 eh_frame[ehidx].cie.def_cfa = DW_CFA_def_cfa;
73 eh_frame[ehidx].cie.def_cfa_op1 = 7;
74 eh_frame[ehidx].cie.def_cfa_op2 = 8;
75 eh_frame[ehidx].cie.offset = DW_CFA_offset + 0x10;
76 eh_frame[ehidx].cie.offset_op = 1;
77 eh_frame[ehidx].fde.len
78 = (unsigned) ((char *) &eh_frame[ehidx].zero
79 - (char *) &eh_frame[ehidx].fde.cie_offset);
80 eh_frame[ehidx].fde.cie_offset
81 = (unsigned) ((char *) &eh_frame[ehidx].fde.cie_offset
82 - (char *) &eh_frame[ehidx].cie);
83 eh_frame[ehidx].fde.begin
84 = (__INTPTR_TYPE__) ((__UINTPTR_TYPE__) addr
85 - (__UINTPTR_TYPE__) &eh_frame[ehidx].fde.begin);
86 eh_frame[ehidx].fde.size = size;
87 eh_frame[ehidx].fde.augmentation = 0;
88 eh_frame[ehidx].zero = 0;
89 __register_frame_info (&eh_frame[ehidx].cie, &eh_frame[ehidx].obj);
90 ++ehidx;
91 return &eh_frame[ehidx - 1].cie;
92 }
93
94 void
95 unregister (void *eh_frame)
96 {
97 __deregister_frame_info (eh_frame);
98 }
99
100 int
101 main ()
102 {
103 for (int i = 0; i < 0x50; i += 0x10)
104 register_range (&code[i], 10);
105 void *p = register_range (&code[0x50], 10);
106 for (int i = 0x60; i < 0xb0; i += 0x10)
107 register_range (&code[i], 10);
108 unregister (p);
109 register_range (&code[0x4c], 8);
110 struct dwarf_eh_bases bases;
111 const void *q = _Unwind_Find_FDE (&code[0x4c], &bases);
112 const void *r = _Unwind_Find_FDE (&code[0x51], &bases);
113 if (!q || q != r)
114 __builtin_abort ();
115 for (int i = 0; i <= 0xa0; i += 0x10)
116 if (i != 0x50)
117 {
118 q = _Unwind_Find_FDE (&code[i], &bases);
119 r = _Unwind_Find_FDE (&code[i + 9], &bases);
120 if (!q || q != r)
121 __builtin_abort ();
122 }
123 for (int i = 0xb0; i < 0x240; i += 0x10)
124 register_range (&code[i], 10);
125 p = register_range (&code[0x240], 10);
126 for (int i = 0x250; i < 0x470; i += 0x10)
127 register_range (&code[i], 10);
128 void *s = register_range (&code[0x470], 10);
129 for (int i = 0x480; i < 0x700; i += 0x10)
130 register_range (&code[i], 10);
131 unregister (p);
132 register_range (&code[0x23c], 16);
133 q = _Unwind_Find_FDE (&code[0x23d], &bases);
134 r = _Unwind_Find_FDE (&code[0x24b], &bases);
135 if (!q || q != r)
136 __builtin_abort ();
137 unregister (s);
138 register_range (&code[0x46c], 16);
139 q = _Unwind_Find_FDE (&code[0x46d], &bases);
140 r = _Unwind_Find_FDE (&code[0x47b], &bases);
141 if (!q || q != r)
142 __builtin_abort ();
143 for (int i = 0; i < 0x700; i += 0x10)
144 if (i != 0x50 && i != 0x240 && i != 0x470)
145 {
146 q = _Unwind_Find_FDE (&code[i], &bases);
147 r = _Unwind_Find_FDE (&code[i + 9], &bases);
148 if (!q || q != r)
149 __builtin_abort ();
150 }
151 }