forked from ephox-gcc-plugins/initify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
283 lines (232 loc) · 7.09 KB
/
test.c
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/* result:
initified local var: _1_YES_print_exit: _1_YES_print_exit
initified local var: _1_YES_print_init: _1_YES_print_init
initified function arg: print_simple_should_init.isra.0.constprop: ["2. YES %s"]
initified function arg: print_simple_should_init.isra.0.constprop: ["3. YES\012"]
initified function arg: _1_YES_print_init: ["4. YES %s %s %s"]
initified function arg: _1_YES_print_init: ["5. YES"]
initified function arg: _1_YES_print_init: ["6. YES"]
initified function arg: _1_YES_print_init: ["7. YES"]
initified function arg: _1_YES_print_init: ["8. YES"]
initified function arg: _1_YES_print_init: ["9. YES %s"]
initified function arg: _1_YES_print_init: ["10. YES"]
initified function arg: _1_YES_print_init: ["11. YES %s %d"]
initified function arg: _1_YES_print_init: ["12. YES"]
initified function arg: _1_YES_print_init: ["13. YES"]
initified function arg: _1_YES_print_init: ["14. YES"]
initified function arg: _1_YES_print_init: ["15. YES %s %s %s"]
initified function arg: _1_YES_print_init: ["16. YES"]
initified function arg: _1_YES_print_init: ["17. YES"]
initified function arg: _1_YES_print_init: ["18. YES"]
initified function arg: _1_YES_print_init: ["19. YES"]
initified local var: _20_YES_func: _20_YES_func
initified local var: _21_YES_func: _21_YES_func
initified function arg: _1_YES_print_init: ["22. YES"]
initified function arg: _1_YES_print_init: ["23. YES"]
initified local var, phi arg: _1_YES_print_init: ["24. YES"]
initified local var, phi arg: _1_YES_print_init: ["25. YES"]
initified local var, phi arg: _1_YES_print_exit: ["26. YES"]
initified function arg: _1_YES_print_init: ["28. YES"]
objdump -s -j .init.rodata.str test
objdump -s -j .exit.rodata.str test
initified function arg: print_simple_should_init.isra.0.constprop: ["SHOULD_INIT"]
__init attribute is missing from the 'print_simple_should_init.isra' function
*/
#include <stdio.h>
#include <stdarg.h>
#include <stdbool.h>
#define __section(S) __attribute__ ((__section__(#S)))
#define __init __section(.init.text)
#define __exit __section(.exit.text)
#define __constsection(x) __section(x)
#define __initconst __constsection(.init.rodata)
#define __exitconst __constsection(.exit.rodata)
#define __printf(a, b) __attribute__((format(printf, a, b)))
#define __nocapture(...) __attribute__((nocapture(__VA_ARGS__)))
int __printf(3, 0) __nocapture(2) print_vararg_no_vararg(const char *d, const char *a, const char *str, ...)
{
va_list args;
va_start(args, str);
printf("%s\n", va_arg(args, const char *));
va_end(args);
return printf(d);
}
int __nocapture(1, 3) print_format_and_vararg(const char *d, const char *str, ...)
{
va_list args;
va_start(args, str);
printf("%s\n", va_arg(args, const char *));
printf("%s\n", va_arg(args, const char *));
printf("%s\n", va_arg(args, const char *));
va_end(args);
return printf(d);
}
int __nocapture(3) print_vararg(const char *d, const char *str, ...)
{
va_list args;
va_start(args, str);
printf("%s\n", va_arg(args, const char *));
printf("%s\n", va_arg(args, const char *));
printf("%s\n", va_arg(args, const char *));
va_end(args);
return printf(d);
}
int __printf(1, 3) __nocapture(2) print_vararg_2(const char *d, const char *str, ...)
{
va_list args;
va_start(args, str);
printf("%s\n", va_arg(args, const char *));
printf("%s\n", va_arg(args, const char *));
printf("%s\n", va_arg(args, const char *));
va_end(args);
return printf(d);
}
int __printf(1, 0) print_vararg_3(const char *d, const char *str, ...)
{
va_list args;
va_start(args, str);
printf("%s\n", va_arg(args, const char *));
va_end(args);
return printf(d);
}
static int __nocapture(1) print_simple_2(const char *format)
{
return printf(format, format, format);
}
int __nocapture() print_simple_3(const char *format, const char *d)
{
return printf(format, d);
}
static int __nocapture(1) print_simple_4(const char *format)
{
return printf(format, format, format);
}
static const char * __nocapture(-1) print_simple_5(const char *format)
{
printf(format, format, format);
return format;
}
static int __nocapture(1, 3) print_simple_should_init(const char *format, const char *d, const char *str, const char *str2)
{
print_simple_4("SHOULD_INIT");
return printf(format, str, str2);
}
void __exit _1_YES_print_exit(const char *str)
{
print_simple_4(str?__func__:"26. YES");
}
struct global_struct {
const char *str;
const char *str_3;
};
static struct global_struct strs;
bool __init _1_YES_print_init(const char *str)
{
unsigned int i;
const char *local_str, *local_str_2, *str_3, *local_str_3;
int (*print_fn)(const char *format);
if (!str) {
local_str = "24. YES";
local_str_2 = "12. NO";
local_str_3 = "50. NO";
} else {
local_str = "25. YES";
local_str_2 = "13. NO";
}
if (str)
print_fn = &print_simple_2;
else
print_fn = &print_simple_4;
print_fn("47. NO");
print_simple_2(local_str);
printf(local_str_2);
print_simple_2(__func__);
print_simple_should_init("2. YES %s", "2. NO", "3. YES\n", "3. NO");
print_simple_should_init("27. YES %s", "21. NO", "38. YES\n", "31. NO");
print_vararg("5. NO", "6. NO", "4. YES %s %s %s", "5. YES", "6. YES", "7. YES");
print_vararg_no_vararg("7. NO", "8. YES", "9. YES %s", "8. NO");
print_format_and_vararg("10. YES", "9. NO", "11. YES %s %d", "12. YES");
print_vararg_2("13. YES", "14. YES", "15. YES %s %s %s", "16. YES", "17. YES", "18. YES");
print_vararg_3("19. YES", "10. NO", "11. NO %s %s %s");
print_simple_3("22. YES", "23. YES");
str_3 = print_simple_5("28. YES");
if (str && str_3)
return true;
strs.str = str;
strs.str_3 = print_simple_5(local_str_3);
return false;
}
void _21_not_init(const char *str)
{
unsigned int i;
const char *local_str_2, str_3;
static const char static_str[] = "14. NO_cicamica";
printf("15. NO %s %s\n", static_str, str);
if (!str)
local_str_2 = "17. NO";
else
local_str_2 = "19. NO";
printf(local_str_2);
printf("20. NO\n");
print_vararg("22. NO", "23. NO", "24. NO %s %s %s", "25. NO", "26. NO", "27. NO");
print_vararg_no_vararg("28. NO", "29. NO", "30. NO %s", "31. NO");
print_format_and_vararg("32. NO", "33. NO", "34. NO %s %d", "35. NO");
print_vararg_2("36. NO", "37. NO", "38. NO %s %s %s", "39. NO", "40. NO", "41. NO");
print_vararg_3("42. NO", "43. NO", "44. NO %s %s %s");
print_simple_3("45. NO", "46. NO");
print_simple_5("49. NO");
}
void __init _20_YES_func(void)
{
print_simple_2(__func__);
}
void __init _21_YES_func(void)
{
print_simple_2(__func__);
}
void no_print(const char *str)
{
printf("%s\n", str);
}
void _12_NO_func(void)
{
printf("%s\n", __func__);
no_print(__func__);
}
struct dd { const char *func; };
void dd_print(const struct dd *dd)
{
printf("%s\n", dd->func);
}
void __init _13_NO_func(void)
{
static struct x {
struct {
const char *n;
} f;
} xx = {
.f = {
.n = __func__,
},
};
dd_print(&xx);
}
void __init _14_NO_func(void)
{
static const struct dd ee = { .func = __func__ + 1};
dd_print(&ee);
}
void __init _15_NO_func(void)
{
asm("" : : "r"(&__func__));
}
int main(int argc, char *argv[])
{
static const char str[] = "10. NO";
if (_1_YES_print_init(argv ? str : argv))
printf("AAAA\n");
else
printf("BBB\n");
_12_NO_func();
return 0;
}