Commit 14aadb9
selftests/bpf: Annotate bpf_obj_new_impl() with __must_check
The verifier requires that pointers returned by bpf_obj_new_impl() are
either dropped or stored in a map. Therefore programs that do not use
its return values will fail to load. Make the compiler point out these
issues. Adjust selftests that check that the verifier does indeed spot
these bugs.
Note that now there two different bpf_obj_new_impl() declarations: one
with __must_check from bpf_experimental.h, and one without from
vmlinux.h. According to the GCC doc [1] this is fine and has the
desired effect:
Compatible attribute specifications on distinct declarations of the
same function are merged.
[1] https://gcc.gnu.org/onlinedocs/gcc-12.4.0/gcc/Function-Attributes.html
Link: https://lore.kernel.org/bpf/CAADnVQL6Q+QRv3_JwEd26biwGpFYcwD_=BjBJWLAtpgOP9CKRw@mail.gmail.com/
Suggested-by: Alexei Starovoitov <[email protected]>
Signed-off-by: Ilya Leoshkevich <[email protected]>1 parent 27199db commit 14aadb9
File tree
2 files changed
+24
-5
lines changed- tools/testing/selftests/bpf
- progs
2 files changed
+24
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
11 | 15 | | |
12 | 16 | | |
13 | 17 | | |
| |||
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
23 | | - | |
| 27 | + | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
216 | 220 | | |
217 | 221 | | |
218 | 222 | | |
219 | 223 | | |
220 | 224 | | |
221 | 225 | | |
222 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
223 | 231 | | |
224 | 232 | | |
225 | 233 | | |
226 | 234 | | |
227 | 235 | | |
228 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
229 | 241 | | |
230 | | - | |
231 | 242 | | |
232 | 243 | | |
233 | 244 | | |
| |||
252 | 263 | | |
253 | 264 | | |
254 | 265 | | |
255 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
256 | 271 | | |
257 | 272 | | |
258 | 273 | | |
| |||
0 commit comments