aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/testing/selftests/bpf/progs/core_reloc_types.h
blob: fd8e1b4c67620fd84e3d67494b3850577d283d32 (plain) (blame)
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
#include <stdint.h>
#include <stdbool.h>

void preserce_ptr_sz_fn(long x) {}

#define __bpf_aligned __attribute__((aligned(8)))

/*
 * KERNEL
 */

struct core_reloc_kernel_output {
	int valid[10];
	char comm[sizeof("test_progs")];
	int comm_len;
	bool local_task_struct_matches;
};

/*
 * MODULE
 */

struct core_reloc_module_output {
	long long len;
	long long off;
	int read_ctx_sz;
	bool read_ctx_exists;
	bool buf_exists;
	bool len_exists;
	bool off_exists;
	/* we have test_progs[-flavor], so cut flavor part */
	char comm[sizeof("test_progs")];
	int comm_len;
};

/*
 * FLAVORS
 */
struct core_reloc_flavors {
	int a;
	int b;
	int c;
};

/* this is not a flavor, as it doesn't have triple underscore */
struct core_reloc_flavors__err_wrong_name {
	int a;
	int b;
	int c;
};

/*
 * NESTING
 */
/* original set up, used to record relocations in BPF program */
struct core_reloc_nesting_substruct {
	int a;
};

union core_reloc_nesting_subunion {
	int b;
};

struct core_reloc_nesting {
	union {
		struct core_reloc_nesting_substruct a;
	} a;
	struct {
		union core_reloc_nesting_subunion b;
	} b;
};

/* inlined anonymous struct/union instead of named structs in original */
struct core_reloc_nesting___anon_embed {
	int __just_for_padding;
	union {
		struct {
			int a;
		} a;
	} a;
	struct {
		union {
			int b;
		} b;
	} b;
};

/* different mix of nested structs/unions than in original */
struct core_reloc_nesting___struct_union_mixup {
	int __a;
	struct {
		int __a;
		union {
			char __a;
			int a;
		} a;
	} a;
	int __b;
	union {
		int __b;
		union {
			char __b;
			int b;
		} b;
	} b;
};

/* extra anon structs/unions, but still valid a.a.a and b.b.b accessors */
struct core_reloc_nesting___extra_nesting {
	int __padding;
	struct {
		struct {
			struct {
				struct {
					union {
						int a;
					} a;
				};
			};
		} a;
		int __some_more;
		struct {
			union {
				union {
					union {
						struct {
							int b;
						};
					} b;
				};
			} b;
		};
	};
};

/* three flavors of same struct with different structure but same layout for
 * a.a.a and b.b.b, thus successfully resolved and relocatable */
struct core_reloc_nesting___dup_compat_types {
	char __just_for_padding;
	/* 3 more bytes of padding */
	struct {
		struct {
			int a; /* offset 4 */
		} a;
	} a;
	long long __more_padding;
	struct {
		struct {
			int b; /* offset 16 */
		} b;
	} b;
};

struct core_reloc_nesting___dup_compat_types__2 {
	int __aligned_padding;
	struct {
		int __trickier_noop[0];
		struct {
			char __some_more_noops[0];
			int a; /* offset 4 */
		} a;
	} a;
	int __more_padding;
	struct {
		struct {
			struct {
				int __critical_padding;
				int b; /* offset 16 */
			} b;
			int __does_not_matter;
		};
	} b;
	int __more_irrelevant_stuff;
};

struct core_reloc_nesting___dup_compat_types__3 {
	char __correct_padding[4];
	struct {
		struct {
			int a; /* offset 4 */
		} a;
	} a;
	/* 8 byte padding due to next struct's alignment */
	struct {
		struct {
			int b;
		} b;
	} b __attribute__((aligned(16)));
};

/* b.b.b field is missing */
struct core_reloc_nesting___err_missing_field {
	struct {
		struct {
			int a;
		} a;
	} a;
	struct {
		struct {
			int x;
		} b;
	} b;
};

/* b.b.b field is an array of integers instead of plain int */
struct core_reloc_nesting___err_array_field {
	struct {
		struct {
			int a;
		} a;
	} a;
	struct {
		struct {
			int b[1];
		} b;
	} b;
};

/* middle b container is missing */
struct core_reloc_nesting___err_missing_container {
	struct {
		struct {
			int a;
		} a;
	} a;
	struct {
		int x;
	} b;
};

/* middle b container is referenced through pointer instead of being embedded */
struct core_reloc_nesting___err_nonstruct_container {
	struct {
		struct {
			int a;
		} a;
	} a;
	struct {
		struct {
			int b;
		} *b;
	} b;
};

/* middle b container is an array of structs instead of plain struct */
struct core_reloc_nesting___err_array_container {
	struct {
		struct {
			int a;
		} a;
	} a;
	struct {
		struct {
			int b;
		} b[1];
	} b;
};

/* two flavors of same struct with incompatible layout for b.b.b */
struct core_reloc_nesting___err_dup_incompat_types__1 {
	struct {
		struct {
			int a; /* offset 0 */
		} a;
	} a;
	struct {
		struct {
			int b; /* offset 4 */
		} b;
	} b;
};

struct core_reloc_nesting___err_dup_incompat_types__2 {
	struct {
		struct {
			int a; /* offset 0 */
		} a;
	} a;
	int __extra_padding;
	struct {
		struct {
			int b; /* offset 8 (!) */
		} b;
	} b;
};

/* two flavors of same struct having one of a.a.a and b.b.b, but not both */
struct core_reloc_nesting___err_partial_match_dups__a {
	struct {
		struct {
			int a;
		} a;
	} a;
};

struct core_reloc_nesting___err_partial_match_dups__b {
	struct {
		struct {
			int b;
		} b;
	} b;
};

struct core_reloc_nesting___err_too_deep {
	struct {
		struct {
			int a;
		} a;
	} a;
	/* 65 levels of nestedness for b.b.b */
	struct {
		struct {
			struct { struct { struct { struct { struct {
			struct { struct { struct { struct { struct {
			struct { struct { struct { struct { struct {
			struct { struct { struct { struct { struct {
			struct { struct { struct { struct { struct {
			struct { struct { struct { struct { struct {
			struct { struct { struct { struct { struct {
			struct { struct { struct { struct { struct {
			struct { struct { struct { struct { struct {
			struct { struct { struct { struct { struct {
			struct { struct { struct { struct { struct {
			struct { struct { struct { struct { struct {
				/* this one is one too much */
				struct {
					int b;
				};
			}; }; }; }; };
			}; }; }; }; };
			}; }; }; }; };
			}; }; }; }; };
			}; }; }; }; };
			}; }; }; }; };
			}; }; }; }; };
			}; }; }; }; };
			}; }; }; }; };
			}; }; }; }; };
			}; }; }; }; };
			}; }; }; }; };
		} b;
	} b;
};

/*
 * ARRAYS
 */
struct core_reloc_arrays_output {
	int a2;
	char b123;
	int c1c;
	int d00d;
	int f10c;
};

struct core_reloc_arrays_substruct {
	int c;
	int d;
};

struct core_reloc_arrays {
	int a[5];
	char b[2][3][4];
	struct core_reloc_arrays_substruct c[3];
	struct core_reloc_arrays_substruct d[1][2];
	struct core_reloc_arrays_substruct f[][2];
};

/* bigger array dimensions */
struct core_reloc_arrays___diff_arr_dim {
	int a[7];
	char b[3][4][5];
	struct core_reloc_arrays_substruct c[4];
	struct core_reloc_arrays_substruct d[2][3];
	struct core_reloc_arrays_substruct f[1][3];
};

/* different size of array's value (struct) */
struct core_reloc_arrays___diff_arr_val_sz {
	int a[5];
	char b[2][3][4];
	struct {
		int __padding1;
		int c;
		int __padding2;
	} c[3];
	struct {
		int __padding1;
		int d;
		int __padding2;
	} d[1][2];
	struct {
		int __padding1;
		int c;
		int __padding2;
	} f[][2];
};

struct core_reloc_arrays___equiv_zero_sz_arr {
	int a[5];
	char b[2][3][4];
	struct core_reloc_arrays_substruct c[3];
	struct core_reloc_arrays_substruct d[1][2];
	/* equivalent to flexible array */
	struct core_reloc_arrays_substruct f[][2];
};

struct core_reloc_arrays___fixed_arr {
	int a[5];
	char b[2][3][4];
	struct core_reloc_arrays_substruct c[3];
	struct core_reloc_arrays_substruct d[1][2];
	/* not a flexible array anymore, but within access bounds */
	struct core_reloc_arrays_substruct f[1][2];
};

struct core_reloc_arrays___err_too_small {
	int a[2]; /* this one is too small */
	char b[2][3][4];
	struct core_reloc_arrays_substruct c[3];
	struct core_reloc_arrays_substruct d[1][2];
	struct core_reloc_arrays_substruct f[][2];
};

struct core_reloc_arrays___err_too_shallow {
	int a[5];
	char b[2][3]; /* this one lacks one dimension */
	struct core_reloc_arrays_substruct c[3];
	struct core_reloc_arrays_substruct d[1][2];
	struct core_reloc_arrays_substruct f[][2];
};

struct core_reloc_arrays___err_non_array {
	int a; /* not an array */
	char b[2][3][4];
	struct core_reloc_arrays_substruct c[3];
	struct core_reloc_arrays_substruct d[1][2];
	struct core_reloc_arrays_substruct f[][2];
};

struct core_reloc_arrays___err_wrong_val_type {
	int a[5];
	char b[2][3][4];
	int c[3]; /* value is not a struct */
	struct core_reloc_arrays_substruct d[1][2];
	struct core_reloc_arrays_substruct f[][2];
};

struct core_reloc_arrays___err_bad_zero_sz_arr {
	/* zero-sized array, but not at the end */
	struct core_reloc_arrays_substruct f[0][2];
	int a[5];
	char b[2][3][4];
	struct core_reloc_arrays_substruct c[3];
	struct core_reloc_arrays_substruct d[1][2];
};

/*
 * PRIMITIVES
 */
enum core_reloc_primitives_enum {
	A = 0,
	B = 1,
};

struct core_reloc_primitives {
	char a;
	int b;
	enum core_reloc_primitives_enum c;
	void *d __bpf_aligned;
	int (*f)(const char *) __bpf_aligned;
};

struct core_reloc_primitives___diff_enum_def {
	char a;
	int b;
	void *d __bpf_aligned;
	int (*f)(const char *) __bpf_aligned;
	enum {
		X = 100,
		Y = 200,
	} c __bpf_aligned; /* inline enum def with differing set of values */
};

struct core_reloc_primitives___diff_func_proto {
	void (*f)(int) __bpf_aligned; /* incompatible function prototype */
	void *d __bpf_aligned;
	enum core_reloc_primitives_enum c __bpf_aligned;
	int b;
	char a;
};

struct core_reloc_primitives___diff_ptr_type {
	const char * const d __bpf_aligned; /* different pointee type + modifiers */
	char a __bpf_aligned;
	int b;
	enum core_reloc_primitives_enum c;
	int (*f)(const char *) __bpf_aligned;
};

struct core_reloc_primitives___err_non_enum {
	char a[1];
	int b;
	int c; /* int instead of enum */
	void *d __bpf_aligned;
	int (*f)(const char *) __bpf_aligned;
};

struct core_reloc_primitives___err_non_int {
	char a[1];
	int *b __bpf_aligned; /* ptr instead of int */
	enum core_reloc_primitives_enum c __bpf_aligned;
	void *d __bpf_aligned;
	int (*f)(const char *) __bpf_aligned;
};

struct core_reloc_primitives___err_non_ptr {
	char a[1];
	int b;
	enum core_reloc_primitives_enum c;
	int d; /* int instead of ptr */
	int (*f)(const char *) __bpf_aligned;
};

/*
 * MODS
 */
struct core_reloc_mods_output {
	int a, b, c, d, e, f, g, h;
};

typedef const int int_t;
typedef const char *char_ptr_t __bpf_aligned;
typedef const int arr_t[7];

struct core_reloc_mods_substruct {
	int x;
	int y;
};

typedef struct {
	int x;
	int y;
} core_reloc_mods_substruct_t;

struct core_reloc_mods {
	int a;
	int_t b;
	char *c __bpf_aligned;
	char_ptr_t d;
	int e[3] __bpf_aligned;
	arr_t f;
	struct core_reloc_mods_substruct g;
	core_reloc_mods_substruct_t h;
};

/* a/b, c/d, e/f, and g/h pairs are swapped */
struct core_reloc_mods___mod_swap {
	int b;
	int_t a;
	char *d __bpf_aligned;
	char_ptr_t c;
	int f[3] __bpf_aligned;
	arr_t e;
	struct {
		int y;
		int x;
	} h;
	core_reloc_mods_substruct_t g;
};

typedef int int1_t;
typedef int1_t int2_t;
typedef int2_t int3_t;

typedef int arr1_t[5];
typedef arr1_t arr2_t;
typedef arr2_t arr3_t;
typedef arr3_t arr4_t;

typedef const char * const volatile fancy_char_ptr_t __bpf_aligned;

typedef core_reloc_mods_substruct_t core_reloc_mods_substruct_tt;

/* we need more typedefs */
struct core_reloc_mods___typedefs {
	core_reloc_mods_substruct_tt g;
	core_reloc_mods_substruct_tt h;
	arr4_t f;
	arr4_t e;
	fancy_char_ptr_t d;
	fancy_char_ptr_t c;
	int3_t b __bpf_aligned;
	int3_t a;
};

/*
 * PTR_AS_ARR
 */
struct core_reloc_ptr_as_arr {
	int a;
};

struct core_reloc_ptr_as_arr___diff_sz {
	int :32; /* padding */
	char __some_more_padding;
	int a;
};

/*
 * INTS
 */
struct core_reloc_ints {
	uint8_t		u8_field;
	int8_t		s8_field;
	uint16_t	u16_field;
	int16_t		s16_field;
	uint32_t	u32_field;
	int32_t		s32_field;
	uint64_t	u64_field;
	int64_t		s64_field;
};

/* signed/unsigned types swap */
struct core_reloc_ints___reverse_sign {
	int8_t		u8_field;
	uint8_t		s8_field;
	int16_t		u16_field;
	uint16_t	s16_field;
	int32_t		u32_field;
	uint32_t	s32_field;
	int64_t		u64_field;
	uint64_t	s64_field;
};

struct core_reloc_ints___bool {
	bool		u8_field; /* bool instead of uint8 */
	int8_t		s8_field;
	uint16_t	u16_field;
	int16_t		s16_field;
	uint32_t	u32_field;
	int32_t		s32_field;
	uint64_t	u64_field;
	int64_t		s64_field;
};

/*
 * MISC
 */
struct core_reloc_misc_output {
	int a, b, c;
};

struct core_reloc_misc___a {
	int a1;
	int a2;
};

struct core_reloc_misc___b {
	int b1;
	int b2;
};

/* this one extends core_reloc_misc_extensible struct from BPF prog */
struct core_reloc_misc_extensible {
	int a;
	int b;
	int c;
	int d;
};

/*
 * FIELD EXISTENCE
 */
struct core_reloc_existence_output {
	int a_exists;
	int a_value;
	int b_exists;
	int b_value;
	int c_exists;
	int c_value;
	int arr_exists;
	int arr_value;
	int s_exists;
	int s_value;
};

struct core_reloc_existence {
	int a;
	struct {
		int b;
	};
	int c;
	int arr[1];
	struct {
		int x;
	} s;
};

struct core_reloc_existence___minimal {
	int a;
};

struct core_reloc_existence___wrong_field_defs {
	void *a;
	int b[1];
	struct{ int x; } c;
	int arr;
	int s;
};

/*
 * BITFIELDS
 */
/* bitfield read results, all as plain integers */
struct core_reloc_bitfields_output {
	int64_t		ub1;
	int64_t		ub2;
	int64_t		ub7;
	int64_t		sb4;
	int64_t		sb20;
	int64_t		u32;
	int64_t		s32;
};

struct core_reloc_bitfields {
	/* unsigned bitfields */
	uint8_t		ub1: 1;
	uint8_t		ub2: 2;
	uint32_t	ub7: 7;
	/* signed bitfields */
	int8_t		sb4: 4;
	int32_t		sb20: 20;
	/* non-bitfields */
	uint32_t	u32;
	int32_t		s32;
};

/* different bit sizes (both up and down) */
struct core_reloc_bitfields___bit_sz_change {
	/* unsigned bitfields */
	uint16_t	ub1: 3;		/*  1 ->  3 */
	uint32_t	ub2: 20;	/*  2 -> 20 */
	uint8_t		ub7: 1;		/*  7 ->  1 */
	/* signed bitfields */
	int8_t		sb4: 1;		/*  4 ->  1 */
	int32_t		sb20: 30;	/* 20 -> 30 */
	/* non-bitfields */
	uint16_t	u32;			/* 32 -> 16 */
	int64_t		s32 __bpf_aligned;	/* 32 -> 64 */
};

/* turn bitfield into non-bitfield and vice versa */
struct core_reloc_bitfields___bitfield_vs_int {
	uint64_t	ub1;		/*  3 -> 64 non-bitfield */
	uint8_t		ub2;		/* 20 ->  8 non-bitfield */
	int64_t		ub7 __bpf_aligned;	/*  7 -> 64 non-bitfield signed */
	int64_t		sb4 __bpf_aligned;	/*  4 -> 64 non-bitfield signed */
	uint64_t	sb20 __bpf_aligned;	/* 20 -> 16 non-bitfield unsigned */
	int32_t		u32: 20;		/* 32 non-bitfield -> 20 bitfield */
	uint64_t	s32: 60 __bpf_aligned;	/* 32 non-bitfield -> 60 bitfield */
};

struct core_reloc_bitfields___just_big_enough {
	uint64_t	ub1: 4;
	uint64_t	ub2: 60; /* packed tightly */
	uint32_t	ub7;
	uint32_t	sb4;
	uint32_t	sb20;
	uint32_t	u32;
	uint32_t	s32;
} __attribute__((packed)) ;

struct core_reloc_bitfields___err_too_big_bitfield {
	uint64_t	ub1: 4;
	uint64_t	ub2: 61; /* packed tightly */
	uint32_t	ub7;
	uint32_t	sb4;
	uint32_t	sb20;
	uint32_t	u32;
	uint32_t	s32;
} __attribute__((packed)) ;

/*
 * SIZE
 */
struct core_reloc_size_output {
	int int_sz;
	int int_off;
	int struct_sz;
	int struct_off;
	int union_sz;
	int union_off;
	int arr_sz;
	int arr_off;
	int arr_elem_sz;
	int arr_elem_off;
	int ptr_sz;
	int ptr_off;
	int enum_sz;
	int enum_off;
	int float_sz;
	int float_off;
};

struct core_reloc_size {
	int int_field;
	struct { int x; } struct_field;
	union { int x; } union_field;
	int arr_field[4];
	void *ptr_field;
	enum { VALUE = 123 } enum_field;
	float float_field;
};

struct core_reloc_size___diff_sz {
	uint64_t int_field;
	struct { int x; int y; int z; } struct_field;
	union { int x; char bla[123]; } union_field;
	char arr_field[10];
	void *ptr_field;
	enum { OTHER_VALUE = 0xFFFFFFFFFFFFFFFF } enum_field;
	double float_field;
};

struct core_reloc_size___diff_offs {
	float float_field;
	enum { YET_OTHER_VALUE = 123 } enum_field;
	void *ptr_field;
	int arr_field[4];
	union { int x; } union_field;
	struct { int x; } struct_field;
	int int_field;
};

/* Error case of two candidates with the fields (int_field) at the same
 * offset, but with differing final relocation values: size 4 vs size 1
 */
struct core_reloc_size___err_ambiguous1 {
	/* int at offset 0 */
	int int_field;

	struct { int x; } struct_field;
	union { int x; } union_field;
	int arr_field[4];
	void *ptr_field;
	enum { VALUE___1 = 123 } enum_field;
	float float_field;
};

struct core_reloc_size___err_ambiguous2 {
	/* char at offset 0 */
	char int_field;

	struct { int x; } struct_field;
	union { int x; } union_field;
	int arr_field[4];
	void *ptr_field;
	enum { VALUE___2 = 123 } enum_field;
	float float_field;
};

/*
 * TYPE EXISTENCE, MATCH & SIZE
 */
struct core_reloc_type_based_output {
	bool struct_exists;
	bool complex_struct_exists;
	bool union_exists;
	bool enum_exists;
	bool typedef_named_struct_exists;
	bool typedef_anon_struct_exists;
	bool typedef_struct_ptr_exists;
	bool typedef_int_exists;
	bool typedef_enum_exists;
	bool typedef_void_ptr_exists;
	bool typedef_restrict_ptr_exists;
	bool typedef_func_proto_exists;
	bool typedef_arr_exists;

	bool struct_matches;
	bool complex_struct_matches;
	bool union_matches;
	bool enum_matches;
	bool typedef_named_struct_matches;
	bool typedef_anon_struct_matches;
	bool typedef_struct_ptr_matches;
	bool typedef_int_matches;
	bool typedef_enum_matches;
	bool typedef_void_ptr_matches;
	bool typedef_restrict_ptr_matches;
	bool typedef_func_proto_matches;
	bool typedef_arr_matches;

	int struct_sz;
	int union_sz;
	int enum_sz;
	int typedef_named_struct_sz;
	int typedef_anon_struct_sz;
	int typedef_struct_ptr_sz;
	int typedef_int_sz;
	int typedef_enum_sz;
	int typedef_void_ptr_sz;
	int typedef_func_proto_sz;
	int typedef_arr_sz;
};

struct a_struct {
	int x;
};

struct a_complex_struct {
	union {
		struct a_struct * restrict a;
		void *b;
	} x;
	volatile long y;
};

union a_union {
	int y;
	int z;
};

typedef struct a_struct named_struct_typedef;

typedef struct { int x, y, z; } anon_struct_typedef;

typedef struct {
	int a, b, c;
} *struct_ptr_typedef;

enum an_enum {
	AN_ENUM_VAL1 = 1,
	AN_ENUM_VAL2 = 2,
	AN_ENUM_VAL3 = 3,
};

typedef int int_typedef;

typedef enum { TYPEDEF_ENUM_VAL1, TYPEDEF_ENUM_VAL2 } enum_typedef;

typedef void *void_ptr_typedef;
typedef int *restrict restrict_ptr_typedef;

typedef int (*func_proto_typedef)(long);

typedef char arr_typedef[20];

struct core_reloc_type_based {
	struct a_struct f1;
	struct a_complex_struct f2;
	union a_union f3;
	enum an_enum f4;
	named_struct_typedef f5;
	anon_struct_typedef f6;
	struct_ptr_typedef f7;
	int_typedef f8;
	enum_typedef f9;
	void_ptr_typedef f10;
	restrict_ptr_typedef f11;
	func_proto_typedef f12;
	arr_typedef f13;
};

/* no types in target */
struct core_reloc_type_based___all_missing {
};

/* different member orders, enum variant values, signedness, etc */
struct a_struct___diff {
	int x;
	int a;
};

struct a_struct___forward;

struct a_complex_struct___diff {
	union {
		struct a_struct___forward *a;
		void *b;
	} x;
	volatile long y;
};

union a_union___diff {
	int z;
	int y;
};

typedef struct a_struct___diff named_struct_typedef___diff;

typedef struct { int z, x, y; } anon_struct_typedef___diff;

typedef struct {
	int c;
	int b;
	int a;
} *struct_ptr_typedef___diff;

enum an_enum___diff {
	AN_ENUM_VAL2___diff = 0,
	AN_ENUM_VAL1___diff = 42,
	AN_ENUM_VAL3___diff = 1,
};

typedef unsigned int int_typedef___diff;

typedef enum { TYPEDEF_ENUM_VAL2___diff, TYPEDEF_ENUM_VAL1___diff = 50 } enum_typedef___diff;

typedef const void *void_ptr_typedef___diff;

typedef int_typedef___diff (*func_proto_typedef___diff)(long);

typedef char arr_typedef___diff[3];

struct core_reloc_type_based___diff {
	struct a_struct___diff f1;
	struct a_complex_struct___diff f2;
	union a_union___diff f3;
	enum an_enum___diff f4;
	named_struct_typedef___diff f5;
	anon_struct_typedef___diff f6;
	struct_ptr_typedef___diff f7;
	int_typedef___diff f8;
	enum_typedef___diff f9;
	void_ptr_typedef___diff f10;
	func_proto_typedef___diff f11;
	arr_typedef___diff f12;
};

/* different type sizes, extra modifiers, anon vs named enums, etc */
struct a_struct___diff_sz {
	long x;
	int y;
	char z;
};

union a_union___diff_sz {
	char yy;
	char zz;
};

typedef struct a_struct___diff_sz named_struct_typedef___diff_sz;

typedef struct { long xx, yy, zzz; } anon_struct_typedef___diff_sz;

typedef struct {
	char aa[1], bb[2], cc[3];
} *struct_ptr_typedef___diff_sz;

enum an_enum___diff_sz {
	AN_ENUM_VAL1___diff_sz = 0x123412341234,
	AN_ENUM_VAL2___diff_sz = 2,
};

typedef unsigned long int_typedef___diff_sz;

typedef enum an_enum___diff_sz enum_typedef___diff_sz;

typedef const void * const void_ptr_typedef___diff_sz;

typedef int_typedef___diff_sz (*func_proto_typedef___diff_sz)(char);

typedef int arr_typedef___diff_sz[2];

struct core_reloc_type_based___diff_sz {
	struct a_struct___diff_sz f1;
	union a_union___diff_sz f2;
	enum an_enum___diff_sz f3;
	named_struct_typedef___diff_sz f4;
	anon_struct_typedef___diff_sz f5;
	struct_ptr_typedef___diff_sz f6;
	int_typedef___diff_sz f7;
	enum_typedef___diff_sz f8;
	void_ptr_typedef___diff_sz f9;
	func_proto_typedef___diff_sz f10;
	arr_typedef___diff_sz f11;
};

/* incompatibilities between target and local types */
union a_struct___incompat { /* union instead of struct */
	int x;
};

struct a_union___incompat { /* struct instead of union */
	int y;
	int z;
};

/* typedef to union, not to struct */
typedef union a_struct___incompat named_struct_typedef___incompat;

/* typedef to void pointer, instead of struct */
typedef void *anon_struct_typedef___incompat;

/* extra pointer indirection */
typedef struct {
	int a, b, c;
} **struct_ptr_typedef___incompat;

/* typedef of a struct with int, instead of int */
typedef struct { int x; } int_typedef___incompat;

/* typedef to func_proto, instead of enum */
typedef int (*enum_typedef___incompat)(void);

/* pointer to char instead of void */
typedef char *void_ptr_typedef___incompat;

/* void return type instead of int */
typedef void (*func_proto_typedef___incompat)(long);

/* multi-dimensional array instead of a single-dimensional */
typedef int arr_typedef___incompat[20][2];

struct core_reloc_type_based___incompat {
	union a_struct___incompat f1;
	struct a_union___incompat f2;
	/* the only valid one is enum, to check that something still succeeds */
	enum an_enum f3;
	named_struct_typedef___incompat f4;
	anon_struct_typedef___incompat f5;
	struct_ptr_typedef___incompat f6;
	int_typedef___incompat f7;
	enum_typedef___incompat f8;
	void_ptr_typedef___incompat f9;
	func_proto_typedef___incompat f10;
	arr_typedef___incompat f11;
};

/* func_proto with incompatible signature */
typedef void (*func_proto_typedef___fn_wrong_ret1)(long);
typedef int * (*func_proto_typedef___fn_wrong_ret2)(long);
typedef struct { int x; } int_struct_typedef;
typedef int_struct_typedef (*func_proto_typedef___fn_wrong_ret3)(long);
typedef int (*func_proto_typedef___fn_wrong_arg)(void *);
typedef int (*func_proto_typedef___fn_wrong_arg_cnt1)(long, long);
typedef int (*func_proto_typedef___fn_wrong_arg_cnt2)(void);

struct core_reloc_type_based___fn_wrong_args {
	/* one valid type to make sure relos still work */
	struct a_struct f1;
	func_proto_typedef___fn_wrong_ret1 f2;
	func_proto_typedef___fn_wrong_ret2 f3;
	func_proto_typedef___fn_wrong_ret3 f4;
	func_proto_typedef___fn_wrong_arg f5;
	func_proto_typedef___fn_wrong_arg_cnt1 f6;
	func_proto_typedef___fn_wrong_arg_cnt2 f7;
};

/*
 * TYPE ID MAPPING (LOCAL AND TARGET)
 */
struct core_reloc_type_id_output {
	int local_anon_struct;
	int local_anon_union;
	int local_anon_enum;
	int local_anon_func_proto_ptr;
	int local_anon_void_ptr;
	int local_anon_arr;

	int local_struct;
	int local_union;
	int local_enum;
	int local_int;
	int local_struct_typedef;
	int local_func_proto_typedef;
	int local_arr_typedef;

	int targ_struct;
	int targ_union;
	int targ_enum;
	int targ_int;
	int targ_struct_typedef;
	int targ_func_proto_typedef;
	int targ_arr_typedef;
};

struct core_reloc_type_id {
	struct a_struct f1;
	union a_union f2;
	enum an_enum f3;
	named_struct_typedef f4;
	func_proto_typedef f5;
	arr_typedef f6;
};

struct core_reloc_type_id___missing_targets {
	/* nothing */
};

/*
 * ENUMERATOR VALUE EXISTENCE AND VALUE RELOCATION
 */
struct core_reloc_enumval_output {
	bool named_val1_exists;
	bool named_val2_exists;
	bool named_val3_exists;
	bool anon_val1_exists;
	bool anon_val2_exists;
	bool anon_val3_exists;

	int named_val1;
	int named_val2;
	int anon_val1;
	int anon_val2;
};

struct core_reloc_enum64val_output {
	bool unsigned_val1_exists;
	bool unsigned_val2_exists;
	bool unsigned_val3_exists;
	bool signed_val1_exists;
	bool signed_val2_exists;
	bool signed_val3_exists;

	long unsigned_val1;
	long unsigned_val2;
	long signed_val1;
	long signed_val2;
};

enum named_enum {
	NAMED_ENUM_VAL1 = 1,
	NAMED_ENUM_VAL2 = 2,
	NAMED_ENUM_VAL3 = 3,
};

typedef enum {
	ANON_ENUM_VAL1 = 0x10,
	ANON_ENUM_VAL2 = 0x20,
	ANON_ENUM_VAL3 = 0x30,
} anon_enum;

struct core_reloc_enumval {
	enum named_enum f1;
	anon_enum f2;
};

enum named_unsigned_enum64 {
	UNSIGNED_ENUM64_VAL1 = 0x1ffffffffULL,
	UNSIGNED_ENUM64_VAL2 = 0x2,
	UNSIGNED_ENUM64_VAL3 = 0x3ffffffffULL,
};

enum named_signed_enum64 {
	SIGNED_ENUM64_VAL1 = 0x1ffffffffLL,
	SIGNED_ENUM64_VAL2 = -2,
	SIGNED_ENUM64_VAL3 = 0x3ffffffffLL,
};

struct core_reloc_enum64val {
	enum named_unsigned_enum64 f1;
	enum named_signed_enum64 f2;
};

/* differing enumerator values */
enum named_enum___diff {
	NAMED_ENUM_VAL1___diff = 101,
	NAMED_ENUM_VAL2___diff = 202,
	NAMED_ENUM_VAL3___diff = 303,
};

typedef enum {
	ANON_ENUM_VAL1___diff = 0x11,
	ANON_ENUM_VAL2___diff = 0x22,
	ANON_ENUM_VAL3___diff = 0x33,
} anon_enum___diff;

struct core_reloc_enumval___diff {
	enum named_enum___diff f1;
	anon_enum___diff f2;
};

enum named_unsigned_enum64___diff {
	UNSIGNED_ENUM64_VAL1___diff = 0x101ffffffffULL,
	UNSIGNED_ENUM64_VAL2___diff = 0x202ffffffffULL,
	UNSIGNED_ENUM64_VAL3___diff = 0x303ffffffffULL,
};

enum named_signed_enum64___diff {
	SIGNED_ENUM64_VAL1___diff = -101,
	SIGNED_ENUM64_VAL2___diff = -202,
	SIGNED_ENUM64_VAL3___diff = -303,
};

struct core_reloc_enum64val___diff {
	enum named_unsigned_enum64___diff f1;
	enum named_signed_enum64___diff f2;
};

/* missing (optional) third enum value */
enum named_enum___val3_missing {
	NAMED_ENUM_VAL1___val3_missing = 111,
	NAMED_ENUM_VAL2___val3_missing = 222,
};

typedef enum {
	ANON_ENUM_VAL1___val3_missing = 0x111,
	ANON_ENUM_VAL2___val3_missing = 0x222,
} anon_enum___val3_missing;

struct core_reloc_enumval___val3_missing {
	enum named_enum___val3_missing f1;
	anon_enum___val3_missing f2;
};

enum named_unsigned_enum64___val3_missing {
	UNSIGNED_ENUM64_VAL1___val3_missing = 0x111ffffffffULL,
	UNSIGNED_ENUM64_VAL2___val3_missing = 0x222,
};

enum named_signed_enum64___val3_missing {
	SIGNED_ENUM64_VAL1___val3_missing = 0x111ffffffffLL,
	SIGNED_ENUM64_VAL2___val3_missing = -222,
};

struct core_reloc_enum64val___val3_missing {
	enum named_unsigned_enum64___val3_missing f1;
	enum named_signed_enum64___val3_missing f2;
};

/* missing (mandatory) second enum value, should fail */
enum named_enum___err_missing {
	NAMED_ENUM_VAL1___err_missing = 1,
	NAMED_ENUM_VAL3___err_missing = 3,
};

typedef enum {
	ANON_ENUM_VAL1___err_missing = 0x111,
	ANON_ENUM_VAL3___err_missing = 0x222,
} anon_enum___err_missing;

struct core_reloc_enumval___err_missing {
	enum named_enum___err_missing f1;
	anon_enum___err_missing f2;
};

enum named_unsigned_enum64___err_missing {
	UNSIGNED_ENUM64_VAL1___err_missing = 0x1ffffffffULL,
	UNSIGNED_ENUM64_VAL3___err_missing = 0x3ffffffffULL,
};

enum named_signed_enum64___err_missing {
	SIGNED_ENUM64_VAL1___err_missing = 0x1ffffffffLL,
	SIGNED_ENUM64_VAL3___err_missing = -3,
};

struct core_reloc_enum64val___err_missing {
	enum named_unsigned_enum64___err_missing f1;
	enum named_signed_enum64___err_missing f2;
};