hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c
....@@ -19,7 +19,7 @@
1919 /*
2020 *struct padded_explicitly {
2121 * int a;
22
- * int: 32;
22
+ * long: 0;
2323 * int b;
2424 *};
2525 *
....@@ -28,41 +28,28 @@
2828
2929 struct padded_explicitly {
3030 int a;
31
- int: 1; /* algo will explicitly pad with full 32 bits here */
31
+ int: 1; /* algo will emit aligning `long: 0;` here */
3232 int b;
3333 };
3434
3535 /* ----- START-EXPECTED-OUTPUT ----- */
36
-/*
37
- *struct padded_a_lot {
38
- * int a;
39
- * long: 32;
40
- * long: 64;
41
- * long: 64;
42
- * int b;
43
- *};
44
- *
45
- */
46
-/* ------ END-EXPECTED-OUTPUT ------ */
47
-
4836 struct padded_a_lot {
4937 int a;
50
- /* 32 bit of implicit padding here, which algo will make explicit */
5138 long: 64;
5239 long: 64;
5340 int b;
5441 };
42
+
43
+/* ------ END-EXPECTED-OUTPUT ------ */
5544
5645 /* ----- START-EXPECTED-OUTPUT ----- */
5746 /*
5847 *struct padded_cache_line {
5948 * int a;
60
- * long: 32;
6149 * long: 64;
6250 * long: 64;
6351 * long: 64;
6452 * int b;
65
- * long: 32;
6653 * long: 64;
6754 * long: 64;
6855 * long: 64;
....@@ -85,7 +72,7 @@
8572 *struct zone {
8673 * int a;
8774 * short b;
88
- * short: 16;
75
+ * long: 0;
8976 * struct zone_padding __pad__;
9077 *};
9178 *
....@@ -102,12 +89,160 @@
10289 struct zone_padding __pad__;
10390 };
10491
92
+/* ----- START-EXPECTED-OUTPUT ----- */
93
+struct padding_wo_named_members {
94
+ long: 64;
95
+ long: 64;
96
+};
97
+
98
+struct padding_weird_1 {
99
+ int a;
100
+ long: 64;
101
+ short: 16;
102
+ short b;
103
+};
104
+
105
+/* ------ END-EXPECTED-OUTPUT ------ */
106
+
107
+/* ----- START-EXPECTED-OUTPUT ----- */
108
+/*
109
+ *struct padding_weird_2 {
110
+ * long: 56;
111
+ * char a;
112
+ * long: 56;
113
+ * char b;
114
+ * char: 8;
115
+ *};
116
+ *
117
+ */
118
+/* ------ END-EXPECTED-OUTPUT ------ */
119
+struct padding_weird_2 {
120
+ int: 32; /* these paddings will be collapsed into `long: 56;` */
121
+ short: 16;
122
+ char: 8;
123
+ char a;
124
+ int: 32; /* these paddings will be collapsed into `long: 56;` */
125
+ short: 16;
126
+ char: 8;
127
+ char b;
128
+ char: 8;
129
+};
130
+
131
+/* ----- START-EXPECTED-OUTPUT ----- */
132
+struct exact_1byte {
133
+ char x;
134
+};
135
+
136
+struct padded_1byte {
137
+ char: 8;
138
+};
139
+
140
+struct exact_2bytes {
141
+ short x;
142
+};
143
+
144
+struct padded_2bytes {
145
+ short: 16;
146
+};
147
+
148
+struct exact_4bytes {
149
+ int x;
150
+};
151
+
152
+struct padded_4bytes {
153
+ int: 32;
154
+};
155
+
156
+struct exact_8bytes {
157
+ long x;
158
+};
159
+
160
+struct padded_8bytes {
161
+ long: 64;
162
+};
163
+
164
+struct ff_periodic_effect {
165
+ int: 32;
166
+ short magnitude;
167
+ long: 0;
168
+ short phase;
169
+ long: 0;
170
+ int: 32;
171
+ int custom_len;
172
+ short *custom_data;
173
+};
174
+
175
+struct ib_wc {
176
+ long: 64;
177
+ long: 64;
178
+ int: 32;
179
+ int byte_len;
180
+ void *qp;
181
+ union {} ex;
182
+ long: 64;
183
+ int slid;
184
+ int wc_flags;
185
+ long: 64;
186
+ char smac[6];
187
+ long: 0;
188
+ char network_hdr_type;
189
+};
190
+
191
+struct acpi_object_method {
192
+ long: 64;
193
+ char: 8;
194
+ char type;
195
+ short reference_count;
196
+ char flags;
197
+ short: 0;
198
+ char: 8;
199
+ char sync_level;
200
+ long: 64;
201
+ void *node;
202
+ void *aml_start;
203
+ union {} dispatch;
204
+ long: 64;
205
+ int aml_length;
206
+};
207
+
208
+struct nested_unpacked {
209
+ int x;
210
+};
211
+
212
+struct nested_packed {
213
+ struct nested_unpacked a;
214
+ char c;
215
+} __attribute__((packed));
216
+
217
+struct outer_mixed_but_unpacked {
218
+ struct nested_packed b1;
219
+ short a1;
220
+ struct nested_packed b2;
221
+};
222
+
223
+/* ------ END-EXPECTED-OUTPUT ------ */
224
+
105225 int f(struct {
106226 struct padded_implicitly _1;
107227 struct padded_explicitly _2;
108228 struct padded_a_lot _3;
109229 struct padded_cache_line _4;
110230 struct zone _5;
231
+ struct padding_wo_named_members _6;
232
+ struct padding_weird_1 _7;
233
+ struct padding_weird_2 _8;
234
+ struct exact_1byte _100;
235
+ struct padded_1byte _101;
236
+ struct exact_2bytes _102;
237
+ struct padded_2bytes _103;
238
+ struct exact_4bytes _104;
239
+ struct padded_4bytes _105;
240
+ struct exact_8bytes _106;
241
+ struct padded_8bytes _107;
242
+ struct ff_periodic_effect _200;
243
+ struct ib_wc _201;
244
+ struct acpi_object_method _202;
245
+ struct outer_mixed_but_unpacked _203;
111246 } *_)
112247 {
113248 return 0;