blob: 4f8b82a85234f795f8c0a04d4efdd8c462ebe008 (
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
|
// SPDX-License-Identifier: GPL-2.0
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"
#include "bpf_experimental.h"
/*
* Read-only and frozen, so the verifier sees a constant zero, while clang
* cannot fold the volatile read and keeps the call below.
*/
const volatile int never;
/* Only called from dead code, hence removed as a whole before the JIT runs. */
static __noinline int dead_subprog(struct __sk_buff *ctx)
{
return ctx->len;
}
__noinline int exception_cb_behind_dead_subprog_cb(u64 cookie)
{
return 42;
}
/*
* libbpf appends the exception callback behind the subprograms reached by
* calls, so removing the dead one compacts subprog_info[] underneath the
* callback's index.
*/
SEC("?tc")
__exception_cb(exception_cb_behind_dead_subprog_cb)
__success __retval(42)
int exception_cb_behind_dead_subprog(struct __sk_buff *ctx)
{
if (never)
return dead_subprog(ctx);
bpf_throw(0);
return 0;
}
char _license[] SEC("license") = "GPL";
|