1 #include <stdint.h>
2 #include <stdbool.h>
3
preserce_ptr_sz_fn(long x)4 void preserce_ptr_sz_fn(long x) {}
5
6 #define __bpf_aligned __attribute__((aligned(8)))
7
8 /*
9 * KERNEL
10 */
11
12 struct core_reloc_kernel_output {
13 int valid[10];
14 char comm[sizeof("test_progs")];
15 int comm_len;
16 };
17
18 /*
19 * FLAVORS
20 */
21 struct core_reloc_flavors {
22 int a;
23 int b;
24 int c;
25 };
26
27 /* this is not a flavor, as it doesn't have triple underscore */
28 struct core_reloc_flavors__err_wrong_name {
29 int a;
30 int b;
31 int c;
32 };
33
34 /*
35 * NESTING
36 */
37 /* original set up, used to record relocations in BPF program */
38 struct core_reloc_nesting_substruct {
39 int a;
40 };
41
42 union core_reloc_nesting_subunion {
43 int b;
44 };
45
46 struct core_reloc_nesting {
47 union {
48 struct core_reloc_nesting_substruct a;
49 } a;
50 struct {
51 union core_reloc_nesting_subunion b;
52 } b;
53 };
54
55 /* inlined anonymous struct/union instead of named structs in original */
56 struct core_reloc_nesting___anon_embed {
57 int __just_for_padding;
58 union {
59 struct {
60 int a;
61 } a;
62 } a;
63 struct {
64 union {
65 int b;
66 } b;
67 } b;
68 };
69
70 /* different mix of nested structs/unions than in original */
71 struct core_reloc_nesting___struct_union_mixup {
72 int __a;
73 struct {
74 int __a;
75 union {
76 char __a;
77 int a;
78 } a;
79 } a;
80 int __b;
81 union {
82 int __b;
83 union {
84 char __b;
85 int b;
86 } b;
87 } b;
88 };
89
90 /* extra anon structs/unions, but still valid a.a.a and b.b.b accessors */
91 struct core_reloc_nesting___extra_nesting {
92 int __padding;
93 struct {
94 struct {
95 struct {
96 struct {
97 union {
98 int a;
99 } a;
100 };
101 };
102 } a;
103 int __some_more;
104 struct {
105 union {
106 union {
107 union {
108 struct {
109 int b;
110 };
111 } b;
112 };
113 } b;
114 };
115 };
116 };
117
118 /* three flavors of same struct with different structure but same layout for
119 * a.a.a and b.b.b, thus successfully resolved and relocatable */
120 struct core_reloc_nesting___dup_compat_types {
121 char __just_for_padding;
122 /* 3 more bytes of padding */
123 struct {
124 struct {
125 int a; /* offset 4 */
126 } a;
127 } a;
128 long long __more_padding;
129 struct {
130 struct {
131 int b; /* offset 16 */
132 } b;
133 } b;
134 };
135
136 struct core_reloc_nesting___dup_compat_types__2 {
137 int __aligned_padding;
138 struct {
139 int __trickier_noop[0];
140 struct {
141 char __some_more_noops[0];
142 int a; /* offset 4 */
143 } a;
144 } a;
145 int __more_padding;
146 struct {
147 struct {
148 struct {
149 int __critical_padding;
150 int b; /* offset 16 */
151 } b;
152 int __does_not_matter;
153 };
154 } b;
155 int __more_irrelevant_stuff;
156 };
157
158 struct core_reloc_nesting___dup_compat_types__3 {
159 char __correct_padding[4];
160 struct {
161 struct {
162 int a; /* offset 4 */
163 } a;
164 } a;
165 /* 8 byte padding due to next struct's alignment */
166 struct {
167 struct {
168 int b;
169 } b;
170 } b __attribute__((aligned(16)));
171 };
172
173 /* b.b.b field is missing */
174 struct core_reloc_nesting___err_missing_field {
175 struct {
176 struct {
177 int a;
178 } a;
179 } a;
180 struct {
181 struct {
182 int x;
183 } b;
184 } b;
185 };
186
187 /* b.b.b field is an array of integers instead of plain int */
188 struct core_reloc_nesting___err_array_field {
189 struct {
190 struct {
191 int a;
192 } a;
193 } a;
194 struct {
195 struct {
196 int b[1];
197 } b;
198 } b;
199 };
200
201 /* middle b container is missing */
202 struct core_reloc_nesting___err_missing_container {
203 struct {
204 struct {
205 int a;
206 } a;
207 } a;
208 struct {
209 int x;
210 } b;
211 };
212
213 /* middle b container is referenced through pointer instead of being embedded */
214 struct core_reloc_nesting___err_nonstruct_container {
215 struct {
216 struct {
217 int a;
218 } a;
219 } a;
220 struct {
221 struct {
222 int b;
223 } *b;
224 } b;
225 };
226
227 /* middle b container is an array of structs instead of plain struct */
228 struct core_reloc_nesting___err_array_container {
229 struct {
230 struct {
231 int a;
232 } a;
233 } a;
234 struct {
235 struct {
236 int b;
237 } b[1];
238 } b;
239 };
240
241 /* two flavors of same struct with incompatible layout for b.b.b */
242 struct core_reloc_nesting___err_dup_incompat_types__1 {
243 struct {
244 struct {
245 int a; /* offset 0 */
246 } a;
247 } a;
248 struct {
249 struct {
250 int b; /* offset 4 */
251 } b;
252 } b;
253 };
254
255 struct core_reloc_nesting___err_dup_incompat_types__2 {
256 struct {
257 struct {
258 int a; /* offset 0 */
259 } a;
260 } a;
261 int __extra_padding;
262 struct {
263 struct {
264 int b; /* offset 8 (!) */
265 } b;
266 } b;
267 };
268
269 /* two flavors of same struct having one of a.a.a and b.b.b, but not both */
270 struct core_reloc_nesting___err_partial_match_dups__a {
271 struct {
272 struct {
273 int a;
274 } a;
275 } a;
276 };
277
278 struct core_reloc_nesting___err_partial_match_dups__b {
279 struct {
280 struct {
281 int b;
282 } b;
283 } b;
284 };
285
286 struct core_reloc_nesting___err_too_deep {
287 struct {
288 struct {
289 int a;
290 } a;
291 } a;
292 /* 65 levels of nestedness for b.b.b */
293 struct {
294 struct {
295 struct { struct { struct { struct { struct {
296 struct { struct { struct { struct { struct {
297 struct { struct { struct { struct { struct {
298 struct { struct { struct { struct { struct {
299 struct { struct { struct { struct { struct {
300 struct { struct { struct { struct { struct {
301 struct { struct { struct { struct { struct {
302 struct { struct { struct { struct { struct {
303 struct { struct { struct { struct { struct {
304 struct { struct { struct { struct { struct {
305 struct { struct { struct { struct { struct {
306 struct { struct { struct { struct { struct {
307 /* this one is one too much */
308 struct {
309 int b;
310 };
311 }; }; }; }; };
312 }; }; }; }; };
313 }; }; }; }; };
314 }; }; }; }; };
315 }; }; }; }; };
316 }; }; }; }; };
317 }; }; }; }; };
318 }; }; }; }; };
319 }; }; }; }; };
320 }; }; }; }; };
321 }; }; }; }; };
322 }; }; }; }; };
323 } b;
324 } b;
325 };
326
327 /*
328 * ARRAYS
329 */
330 struct core_reloc_arrays_output {
331 int a2;
332 char b123;
333 int c1c;
334 int d00d;
335 int f10c;
336 };
337
338 struct core_reloc_arrays_substruct {
339 int c;
340 int d;
341 };
342
343 struct core_reloc_arrays {
344 int a[5];
345 char b[2][3][4];
346 struct core_reloc_arrays_substruct c[3];
347 struct core_reloc_arrays_substruct d[1][2];
348 struct core_reloc_arrays_substruct f[][2];
349 };
350
351 /* bigger array dimensions */
352 struct core_reloc_arrays___diff_arr_dim {
353 int a[7];
354 char b[3][4][5];
355 struct core_reloc_arrays_substruct c[4];
356 struct core_reloc_arrays_substruct d[2][3];
357 struct core_reloc_arrays_substruct f[1][3];
358 };
359
360 /* different size of array's value (struct) */
361 struct core_reloc_arrays___diff_arr_val_sz {
362 int a[5];
363 char b[2][3][4];
364 struct {
365 int __padding1;
366 int c;
367 int __padding2;
368 } c[3];
369 struct {
370 int __padding1;
371 int d;
372 int __padding2;
373 } d[1][2];
374 struct {
375 int __padding1;
376 int c;
377 int __padding2;
378 } f[][2];
379 };
380
381 struct core_reloc_arrays___equiv_zero_sz_arr {
382 int a[5];
383 char b[2][3][4];
384 struct core_reloc_arrays_substruct c[3];
385 struct core_reloc_arrays_substruct d[1][2];
386 /* equivalent to flexible array */
387 struct core_reloc_arrays_substruct f[][2];
388 };
389
390 struct core_reloc_arrays___fixed_arr {
391 int a[5];
392 char b[2][3][4];
393 struct core_reloc_arrays_substruct c[3];
394 struct core_reloc_arrays_substruct d[1][2];
395 /* not a flexible array anymore, but within access bounds */
396 struct core_reloc_arrays_substruct f[1][2];
397 };
398
399 struct core_reloc_arrays___err_too_small {
400 int a[2]; /* this one is too small */
401 char b[2][3][4];
402 struct core_reloc_arrays_substruct c[3];
403 struct core_reloc_arrays_substruct d[1][2];
404 struct core_reloc_arrays_substruct f[][2];
405 };
406
407 struct core_reloc_arrays___err_too_shallow {
408 int a[5];
409 char b[2][3]; /* this one lacks one dimension */
410 struct core_reloc_arrays_substruct c[3];
411 struct core_reloc_arrays_substruct d[1][2];
412 struct core_reloc_arrays_substruct f[][2];
413 };
414
415 struct core_reloc_arrays___err_non_array {
416 int a; /* not an array */
417 char b[2][3][4];
418 struct core_reloc_arrays_substruct c[3];
419 struct core_reloc_arrays_substruct d[1][2];
420 struct core_reloc_arrays_substruct f[][2];
421 };
422
423 struct core_reloc_arrays___err_wrong_val_type {
424 int a[5];
425 char b[2][3][4];
426 int c[3]; /* value is not a struct */
427 struct core_reloc_arrays_substruct d[1][2];
428 struct core_reloc_arrays_substruct f[][2];
429 };
430
431 struct core_reloc_arrays___err_bad_zero_sz_arr {
432 /* zero-sized array, but not at the end */
433 struct core_reloc_arrays_substruct f[0][2];
434 int a[5];
435 char b[2][3][4];
436 struct core_reloc_arrays_substruct c[3];
437 struct core_reloc_arrays_substruct d[1][2];
438 };
439
440 /*
441 * PRIMITIVES
442 */
443 enum core_reloc_primitives_enum {
444 A = 0,
445 B = 1,
446 };
447
448 struct core_reloc_primitives {
449 char a;
450 int b;
451 enum core_reloc_primitives_enum c;
452 void *d __bpf_aligned;
453 int (*f)(const char *) __bpf_aligned;
454 };
455
456 struct core_reloc_primitives___diff_enum_def {
457 char a;
458 int b;
459 void *d __bpf_aligned;
460 int (*f)(const char *) __bpf_aligned;
461 enum {
462 X = 100,
463 Y = 200,
464 } c __bpf_aligned; /* inline enum def with differing set of values */
465 };
466
467 struct core_reloc_primitives___diff_func_proto {
468 void (*f)(int) __bpf_aligned; /* incompatible function prototype */
469 void *d __bpf_aligned;
470 enum core_reloc_primitives_enum c __bpf_aligned;
471 int b;
472 char a;
473 };
474
475 struct core_reloc_primitives___diff_ptr_type {
476 const char * const d __bpf_aligned; /* different pointee type + modifiers */
477 char a __bpf_aligned;
478 int b;
479 enum core_reloc_primitives_enum c;
480 int (*f)(const char *) __bpf_aligned;
481 };
482
483 struct core_reloc_primitives___err_non_enum {
484 char a[1];
485 int b;
486 int c; /* int instead of enum */
487 void *d __bpf_aligned;
488 int (*f)(const char *) __bpf_aligned;
489 };
490
491 struct core_reloc_primitives___err_non_int {
492 char a[1];
493 int *b __bpf_aligned; /* ptr instead of int */
494 enum core_reloc_primitives_enum c __bpf_aligned;
495 void *d __bpf_aligned;
496 int (*f)(const char *) __bpf_aligned;
497 };
498
499 struct core_reloc_primitives___err_non_ptr {
500 char a[1];
501 int b;
502 enum core_reloc_primitives_enum c;
503 int d; /* int instead of ptr */
504 int (*f)(const char *) __bpf_aligned;
505 };
506
507 /*
508 * MODS
509 */
510 struct core_reloc_mods_output {
511 int a, b, c, d, e, f, g, h;
512 };
513
514 typedef const int int_t;
515 typedef const char *char_ptr_t __bpf_aligned;
516 typedef const int arr_t[7];
517
518 struct core_reloc_mods_substruct {
519 int x;
520 int y;
521 };
522
523 typedef struct {
524 int x;
525 int y;
526 } core_reloc_mods_substruct_t;
527
528 struct core_reloc_mods {
529 int a;
530 int_t b;
531 char *c __bpf_aligned;
532 char_ptr_t d;
533 int e[3] __bpf_aligned;
534 arr_t f;
535 struct core_reloc_mods_substruct g;
536 core_reloc_mods_substruct_t h;
537 };
538
539 /* a/b, c/d, e/f, and g/h pairs are swapped */
540 struct core_reloc_mods___mod_swap {
541 int b;
542 int_t a;
543 char *d __bpf_aligned;
544 char_ptr_t c;
545 int f[3] __bpf_aligned;
546 arr_t e;
547 struct {
548 int y;
549 int x;
550 } h;
551 core_reloc_mods_substruct_t g;
552 };
553
554 typedef int int1_t;
555 typedef int1_t int2_t;
556 typedef int2_t int3_t;
557
558 typedef int arr1_t[5];
559 typedef arr1_t arr2_t;
560 typedef arr2_t arr3_t;
561 typedef arr3_t arr4_t;
562
563 typedef const char * const volatile fancy_char_ptr_t __bpf_aligned;
564
565 typedef core_reloc_mods_substruct_t core_reloc_mods_substruct_tt;
566
567 /* we need more typedefs */
568 struct core_reloc_mods___typedefs {
569 core_reloc_mods_substruct_tt g;
570 core_reloc_mods_substruct_tt h;
571 arr4_t f;
572 arr4_t e;
573 fancy_char_ptr_t d;
574 fancy_char_ptr_t c;
575 int3_t b __bpf_aligned;
576 int3_t a;
577 };
578
579 /*
580 * PTR_AS_ARR
581 */
582 struct core_reloc_ptr_as_arr {
583 int a;
584 };
585
586 struct core_reloc_ptr_as_arr___diff_sz {
587 int :32; /* padding */
588 char __some_more_padding;
589 int a;
590 };
591
592 /*
593 * INTS
594 */
595 struct core_reloc_ints {
596 uint8_t u8_field;
597 int8_t s8_field;
598 uint16_t u16_field;
599 int16_t s16_field;
600 uint32_t u32_field;
601 int32_t s32_field;
602 uint64_t u64_field;
603 int64_t s64_field;
604 };
605
606 /* signed/unsigned types swap */
607 struct core_reloc_ints___reverse_sign {
608 int8_t u8_field;
609 uint8_t s8_field;
610 int16_t u16_field;
611 uint16_t s16_field;
612 int32_t u32_field;
613 uint32_t s32_field;
614 int64_t u64_field;
615 uint64_t s64_field;
616 };
617
618 struct core_reloc_ints___bool {
619 bool u8_field; /* bool instead of uint8 */
620 int8_t s8_field;
621 uint16_t u16_field;
622 int16_t s16_field;
623 uint32_t u32_field;
624 int32_t s32_field;
625 uint64_t u64_field;
626 int64_t s64_field;
627 };
628
629 /*
630 * MISC
631 */
632 struct core_reloc_misc_output {
633 int a, b, c;
634 };
635
636 struct core_reloc_misc___a {
637 int a1;
638 int a2;
639 };
640
641 struct core_reloc_misc___b {
642 int b1;
643 int b2;
644 };
645
646 /* this one extends core_reloc_misc_extensible struct from BPF prog */
647 struct core_reloc_misc_extensible {
648 int a;
649 int b;
650 int c;
651 int d;
652 };
653
654 /*
655 * FIELD EXISTENCE
656 */
657 struct core_reloc_existence_output {
658 int a_exists;
659 int a_value;
660 int b_exists;
661 int b_value;
662 int c_exists;
663 int c_value;
664 int arr_exists;
665 int arr_value;
666 int s_exists;
667 int s_value;
668 };
669
670 struct core_reloc_existence {
671 int a;
672 struct {
673 int b;
674 };
675 int c;
676 int arr[1];
677 struct {
678 int x;
679 } s;
680 };
681
682 struct core_reloc_existence___minimal {
683 int a;
684 };
685
686 struct core_reloc_existence___wrong_field_defs {
687 void *a;
688 int b[1];
689 struct{ int x; } c;
690 int arr;
691 int s;
692 };
693
694 /*
695 * BITFIELDS
696 */
697 /* bitfield read results, all as plain integers */
698 struct core_reloc_bitfields_output {
699 int64_t ub1;
700 int64_t ub2;
701 int64_t ub7;
702 int64_t sb4;
703 int64_t sb20;
704 int64_t u32;
705 int64_t s32;
706 };
707
708 struct core_reloc_bitfields {
709 /* unsigned bitfields */
710 uint8_t ub1: 1;
711 uint8_t ub2: 2;
712 uint32_t ub7: 7;
713 /* signed bitfields */
714 int8_t sb4: 4;
715 int32_t sb20: 20;
716 /* non-bitfields */
717 uint32_t u32;
718 int32_t s32;
719 };
720
721 /* different bit sizes (both up and down) */
722 struct core_reloc_bitfields___bit_sz_change {
723 /* unsigned bitfields */
724 uint16_t ub1: 3; /* 1 -> 3 */
725 uint32_t ub2: 20; /* 2 -> 20 */
726 uint8_t ub7: 1; /* 7 -> 1 */
727 /* signed bitfields */
728 int8_t sb4: 1; /* 4 -> 1 */
729 int32_t sb20: 30; /* 20 -> 30 */
730 /* non-bitfields */
731 uint16_t u32; /* 32 -> 16 */
732 int64_t s32 __bpf_aligned; /* 32 -> 64 */
733 };
734
735 /* turn bitfield into non-bitfield and vice versa */
736 struct core_reloc_bitfields___bitfield_vs_int {
737 uint64_t ub1; /* 3 -> 64 non-bitfield */
738 uint8_t ub2; /* 20 -> 8 non-bitfield */
739 int64_t ub7 __bpf_aligned; /* 7 -> 64 non-bitfield signed */
740 int64_t sb4 __bpf_aligned; /* 4 -> 64 non-bitfield signed */
741 uint64_t sb20 __bpf_aligned; /* 20 -> 16 non-bitfield unsigned */
742 int32_t u32: 20; /* 32 non-bitfield -> 20 bitfield */
743 uint64_t s32: 60 __bpf_aligned; /* 32 non-bitfield -> 60 bitfield */
744 };
745
746 struct core_reloc_bitfields___just_big_enough {
747 uint64_t ub1: 4;
748 uint64_t ub2: 60; /* packed tightly */
749 uint32_t ub7;
750 uint32_t sb4;
751 uint32_t sb20;
752 uint32_t u32;
753 uint32_t s32;
754 } __attribute__((packed)) ;
755
756 struct core_reloc_bitfields___err_too_big_bitfield {
757 uint64_t ub1: 4;
758 uint64_t ub2: 61; /* packed tightly */
759 uint32_t ub7;
760 uint32_t sb4;
761 uint32_t sb20;
762 uint32_t u32;
763 uint32_t s32;
764 } __attribute__((packed)) ;
765
766 /*
767 * SIZE
768 */
769 struct core_reloc_size_output {
770 int int_sz;
771 int struct_sz;
772 int union_sz;
773 int arr_sz;
774 int arr_elem_sz;
775 int ptr_sz;
776 int enum_sz;
777 };
778
779 struct core_reloc_size {
780 int int_field;
781 struct { int x; } struct_field;
782 union { int x; } union_field;
783 int arr_field[4];
784 void *ptr_field;
785 enum { VALUE = 123 } enum_field;
786 };
787
788 struct core_reloc_size___diff_sz {
789 uint64_t int_field;
790 struct { int x; int y; int z; } struct_field;
791 union { int x; char bla[123]; } union_field;
792 char arr_field[10];
793 void *ptr_field;
794 enum { OTHER_VALUE = 0xFFFFFFFFFFFFFFFF } enum_field;
795 };
796
797 /* Error case of two candidates with the fields (int_field) at the same
798 * offset, but with differing final relocation values: size 4 vs size 1
799 */
800 struct core_reloc_size___err_ambiguous1 {
801 /* int at offset 0 */
802 int int_field;
803
804 struct { int x; } struct_field;
805 union { int x; } union_field;
806 int arr_field[4];
807 void *ptr_field;
808 enum { VALUE___1 = 123 } enum_field;
809 };
810
811 struct core_reloc_size___err_ambiguous2 {
812 /* char at offset 0 */
813 char int_field;
814
815 struct { int x; } struct_field;
816 union { int x; } union_field;
817 int arr_field[4];
818 void *ptr_field;
819 enum { VALUE___2 = 123 } enum_field;
820 };
821
822 /*
823 * TYPE EXISTENCE & SIZE
824 */
825 struct core_reloc_type_based_output {
826 bool struct_exists;
827 bool union_exists;
828 bool enum_exists;
829 bool typedef_named_struct_exists;
830 bool typedef_anon_struct_exists;
831 bool typedef_struct_ptr_exists;
832 bool typedef_int_exists;
833 bool typedef_enum_exists;
834 bool typedef_void_ptr_exists;
835 bool typedef_func_proto_exists;
836 bool typedef_arr_exists;
837
838 int struct_sz;
839 int union_sz;
840 int enum_sz;
841 int typedef_named_struct_sz;
842 int typedef_anon_struct_sz;
843 int typedef_struct_ptr_sz;
844 int typedef_int_sz;
845 int typedef_enum_sz;
846 int typedef_void_ptr_sz;
847 int typedef_func_proto_sz;
848 int typedef_arr_sz;
849 };
850
851 struct a_struct {
852 int x;
853 };
854
855 union a_union {
856 int y;
857 int z;
858 };
859
860 typedef struct a_struct named_struct_typedef;
861
862 typedef struct { int x, y, z; } anon_struct_typedef;
863
864 typedef struct {
865 int a, b, c;
866 } *struct_ptr_typedef;
867
868 enum an_enum {
869 AN_ENUM_VAL1 = 1,
870 AN_ENUM_VAL2 = 2,
871 AN_ENUM_VAL3 = 3,
872 };
873
874 typedef int int_typedef;
875
876 typedef enum { TYPEDEF_ENUM_VAL1, TYPEDEF_ENUM_VAL2 } enum_typedef;
877
878 typedef void *void_ptr_typedef;
879
880 typedef int (*func_proto_typedef)(long);
881
882 typedef char arr_typedef[20];
883
884 struct core_reloc_type_based {
885 struct a_struct f1;
886 union a_union f2;
887 enum an_enum f3;
888 named_struct_typedef f4;
889 anon_struct_typedef f5;
890 struct_ptr_typedef f6;
891 int_typedef f7;
892 enum_typedef f8;
893 void_ptr_typedef f9;
894 func_proto_typedef f10;
895 arr_typedef f11;
896 };
897
898 /* no types in target */
899 struct core_reloc_type_based___all_missing {
900 };
901
902 /* different type sizes, extra modifiers, anon vs named enums, etc */
903 struct a_struct___diff_sz {
904 long x;
905 int y;
906 char z;
907 };
908
909 union a_union___diff_sz {
910 char yy;
911 char zz;
912 };
913
914 typedef struct a_struct___diff_sz named_struct_typedef___diff_sz;
915
916 typedef struct { long xx, yy, zzz; } anon_struct_typedef___diff_sz;
917
918 typedef struct {
919 char aa[1], bb[2], cc[3];
920 } *struct_ptr_typedef___diff_sz;
921
922 enum an_enum___diff_sz {
923 AN_ENUM_VAL1___diff_sz = 0x123412341234,
924 AN_ENUM_VAL2___diff_sz = 2,
925 };
926
927 typedef unsigned long int_typedef___diff_sz;
928
929 typedef enum an_enum___diff_sz enum_typedef___diff_sz;
930
931 typedef const void * const void_ptr_typedef___diff_sz;
932
933 typedef int_typedef___diff_sz (*func_proto_typedef___diff_sz)(char);
934
935 typedef int arr_typedef___diff_sz[2];
936
937 struct core_reloc_type_based___diff_sz {
938 struct a_struct___diff_sz f1;
939 union a_union___diff_sz f2;
940 enum an_enum___diff_sz f3;
941 named_struct_typedef___diff_sz f4;
942 anon_struct_typedef___diff_sz f5;
943 struct_ptr_typedef___diff_sz f6;
944 int_typedef___diff_sz f7;
945 enum_typedef___diff_sz f8;
946 void_ptr_typedef___diff_sz f9;
947 func_proto_typedef___diff_sz f10;
948 arr_typedef___diff_sz f11;
949 };
950
951 /* incompatibilities between target and local types */
952 union a_struct___incompat { /* union instead of struct */
953 int x;
954 };
955
956 struct a_union___incompat { /* struct instead of union */
957 int y;
958 int z;
959 };
960
961 /* typedef to union, not to struct */
962 typedef union a_struct___incompat named_struct_typedef___incompat;
963
964 /* typedef to void pointer, instead of struct */
965 typedef void *anon_struct_typedef___incompat;
966
967 /* extra pointer indirection */
968 typedef struct {
969 int a, b, c;
970 } **struct_ptr_typedef___incompat;
971
972 /* typedef of a struct with int, instead of int */
973 typedef struct { int x; } int_typedef___incompat;
974
975 /* typedef to func_proto, instead of enum */
976 typedef int (*enum_typedef___incompat)(void);
977
978 /* pointer to char instead of void */
979 typedef char *void_ptr_typedef___incompat;
980
981 /* void return type instead of int */
982 typedef void (*func_proto_typedef___incompat)(long);
983
984 /* multi-dimensional array instead of a single-dimensional */
985 typedef int arr_typedef___incompat[20][2];
986
987 struct core_reloc_type_based___incompat {
988 union a_struct___incompat f1;
989 struct a_union___incompat f2;
990 /* the only valid one is enum, to check that something still succeeds */
991 enum an_enum f3;
992 named_struct_typedef___incompat f4;
993 anon_struct_typedef___incompat f5;
994 struct_ptr_typedef___incompat f6;
995 int_typedef___incompat f7;
996 enum_typedef___incompat f8;
997 void_ptr_typedef___incompat f9;
998 func_proto_typedef___incompat f10;
999 arr_typedef___incompat f11;
1000 };
1001
1002 /* func_proto with incompatible signature */
1003 typedef void (*func_proto_typedef___fn_wrong_ret1)(long);
1004 typedef int * (*func_proto_typedef___fn_wrong_ret2)(long);
1005 typedef struct { int x; } int_struct_typedef;
1006 typedef int_struct_typedef (*func_proto_typedef___fn_wrong_ret3)(long);
1007 typedef int (*func_proto_typedef___fn_wrong_arg)(void *);
1008 typedef int (*func_proto_typedef___fn_wrong_arg_cnt1)(long, long);
1009 typedef int (*func_proto_typedef___fn_wrong_arg_cnt2)(void);
1010
1011 struct core_reloc_type_based___fn_wrong_args {
1012 /* one valid type to make sure relos still work */
1013 struct a_struct f1;
1014 func_proto_typedef___fn_wrong_ret1 f2;
1015 func_proto_typedef___fn_wrong_ret2 f3;
1016 func_proto_typedef___fn_wrong_ret3 f4;
1017 func_proto_typedef___fn_wrong_arg f5;
1018 func_proto_typedef___fn_wrong_arg_cnt1 f6;
1019 func_proto_typedef___fn_wrong_arg_cnt2 f7;
1020 };
1021
1022 /*
1023 * TYPE ID MAPPING (LOCAL AND TARGET)
1024 */
1025 struct core_reloc_type_id_output {
1026 int local_anon_struct;
1027 int local_anon_union;
1028 int local_anon_enum;
1029 int local_anon_func_proto_ptr;
1030 int local_anon_void_ptr;
1031 int local_anon_arr;
1032
1033 int local_struct;
1034 int local_union;
1035 int local_enum;
1036 int local_int;
1037 int local_struct_typedef;
1038 int local_func_proto_typedef;
1039 int local_arr_typedef;
1040
1041 int targ_struct;
1042 int targ_union;
1043 int targ_enum;
1044 int targ_int;
1045 int targ_struct_typedef;
1046 int targ_func_proto_typedef;
1047 int targ_arr_typedef;
1048 };
1049
1050 struct core_reloc_type_id {
1051 struct a_struct f1;
1052 union a_union f2;
1053 enum an_enum f3;
1054 named_struct_typedef f4;
1055 func_proto_typedef f5;
1056 arr_typedef f6;
1057 };
1058
1059 struct core_reloc_type_id___missing_targets {
1060 /* nothing */
1061 };
1062
1063 /*
1064 * ENUMERATOR VALUE EXISTENCE AND VALUE RELOCATION
1065 */
1066 struct core_reloc_enumval_output {
1067 bool named_val1_exists;
1068 bool named_val2_exists;
1069 bool named_val3_exists;
1070 bool anon_val1_exists;
1071 bool anon_val2_exists;
1072 bool anon_val3_exists;
1073
1074 int named_val1;
1075 int named_val2;
1076 int anon_val1;
1077 int anon_val2;
1078 };
1079
1080 enum named_enum {
1081 NAMED_ENUM_VAL1 = 1,
1082 NAMED_ENUM_VAL2 = 2,
1083 NAMED_ENUM_VAL3 = 3,
1084 };
1085
1086 typedef enum {
1087 ANON_ENUM_VAL1 = 0x10,
1088 ANON_ENUM_VAL2 = 0x20,
1089 ANON_ENUM_VAL3 = 0x30,
1090 } anon_enum;
1091
1092 struct core_reloc_enumval {
1093 enum named_enum f1;
1094 anon_enum f2;
1095 };
1096
1097 /* differing enumerator values */
1098 enum named_enum___diff {
1099 NAMED_ENUM_VAL1___diff = 101,
1100 NAMED_ENUM_VAL2___diff = 202,
1101 NAMED_ENUM_VAL3___diff = 303,
1102 };
1103
1104 typedef enum {
1105 ANON_ENUM_VAL1___diff = 0x11,
1106 ANON_ENUM_VAL2___diff = 0x22,
1107 ANON_ENUM_VAL3___diff = 0x33,
1108 } anon_enum___diff;
1109
1110 struct core_reloc_enumval___diff {
1111 enum named_enum___diff f1;
1112 anon_enum___diff f2;
1113 };
1114
1115 /* missing (optional) third enum value */
1116 enum named_enum___val3_missing {
1117 NAMED_ENUM_VAL1___val3_missing = 111,
1118 NAMED_ENUM_VAL2___val3_missing = 222,
1119 };
1120
1121 typedef enum {
1122 ANON_ENUM_VAL1___val3_missing = 0x111,
1123 ANON_ENUM_VAL2___val3_missing = 0x222,
1124 } anon_enum___val3_missing;
1125
1126 struct core_reloc_enumval___val3_missing {
1127 enum named_enum___val3_missing f1;
1128 anon_enum___val3_missing f2;
1129 };
1130
1131 /* missing (mandatory) second enum value, should fail */
1132 enum named_enum___err_missing {
1133 NAMED_ENUM_VAL1___err_missing = 1,
1134 NAMED_ENUM_VAL3___err_missing = 3,
1135 };
1136
1137 typedef enum {
1138 ANON_ENUM_VAL1___err_missing = 0x111,
1139 ANON_ENUM_VAL3___err_missing = 0x222,
1140 } anon_enum___err_missing;
1141
1142 struct core_reloc_enumval___err_missing {
1143 enum named_enum___err_missing f1;
1144 anon_enum___err_missing f2;
1145 };
1146