Skip to content

Commit 624c3ed

Browse files
authored
Merge pull request #33 from OrderLab/dev
Refactor headers
2 parents 511d959 + 5931b96 commit 624c3ed

38 files changed

Lines changed: 1774 additions & 6008 deletions

core/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ add_library(
88
epass STATIC
99
bpf_ir.c
1010
array.c
11-
hashtbl.c
1211
ptrset.c
1312
ir_helper.c
1413
ir_value.c
@@ -28,17 +27,13 @@ add_library(
2827
aux/kern_utils.c
2928
aux/cg_prog_check.c
3029
ir_cg.c
31-
ir_cg_v2.c
3230
ir_cg_norm.c
33-
ir_cg_norm_v2.c
3431
lli.c
3532
include/linux/bpf_ir.h)
3633

3734
add_executable(test_list tests/test_list.c)
38-
add_executable(test_hashtable tests/test_hashtable.c)
3935
add_executable(test_ptrset tests/test_ptrset.c)
4036

41-
target_link_libraries(test_hashtable epass)
4237
target_link_libraries(test_ptrset epass)
4338

4439
include_directories(include)

core/array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: GPL-2.0-only
2-
#include <linux/bpf_ir.h>
2+
#include "ir.h"
33

44
void bpf_ir_array_init(struct array *res, size_t size)
55
{

core/aux/cg_prog_check.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: GPL-2.0-only
2-
#include <linux/bpf_ir.h>
2+
#include "ir.h"
33
#include "ir_cg.h"
44

55
static void check_userdata(struct bpf_ir_env *env, struct ir_function *fun)
@@ -10,7 +10,7 @@ static void check_userdata(struct bpf_ir_env *env, struct ir_function *fun)
1010
struct ir_basic_block *bb = *pos;
1111
struct ir_insn *insn;
1212
list_for_each_entry(insn, &bb->ir_insn_head, list_ptr) {
13-
if (!insn_cg_v2(insn)) {
13+
if (!insn_cg(insn)) {
1414
print_ir_insn_err(env, insn, "No userdata");
1515
RAISE_ERROR("No userdata");
1616
}

core/aux/disasm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
// Modified from kernel/bpf/disasm.c
3-
#include <linux/bpf_ir.h>
3+
#include "ir.h"
44

55
static const char *const bpf_class_string[8] = {
66
[BPF_LD] = "ld", [BPF_LDX] = "ldx", [BPF_ST] = "st",

core/aux/ir_utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: GPL-2.0-only
2-
#include <linux/bpf_ir.h>
2+
#include "ir.h"
33

44
// Insert some instructions to print a message
55
void bpf_ir_printk_insns(struct bpf_ir_env *env, struct ir_insn *insn,

core/aux/kern_utils.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: GPL-2.0-only
2-
#include <linux/bpf_ir.h>
2+
#include "ir.h"
33

44
static int apply_pass_opt(struct bpf_ir_env *env, const char *opt)
55
{
@@ -93,8 +93,6 @@ static int apply_global_opt(struct bpf_ir_env *env, const char *opt)
9393
{
9494
if (strcmp(opt, "force") == 0) {
9595
env->opts.force = true;
96-
} else if (strcmp(opt, "disable_coalesce") == 0) {
97-
env->opts.disable_coalesce = true;
9896
} else if (strcmp(opt, "print_bpf") == 0) {
9997
env->opts.print_mode = BPF_IR_PRINT_BPF;
10098
} else if (strcmp(opt, "print_dump") == 0) {
@@ -113,8 +111,6 @@ static int apply_global_opt(struct bpf_ir_env *env, const char *opt)
113111
env->opts.print_only = true;
114112
} else if (strcmp(opt, "fakerun") == 0) {
115113
env->opts.fake_run = true;
116-
} else if (strcmp(opt, "cgv1") == 0) {
117-
env->opts.cg_v2 = false;
118114
} else if (strcmp(opt, "dotgraph") == 0) {
119115
env->opts.dotgraph = true;
120116
} else if (strncmp(opt, "verbose=", 8) == 0) {

core/aux/prog_check.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: GPL-2.0-only
2-
#include <linux/bpf_ir.h>
2+
#include "ir.h"
33

44
static void check_insn_users_use_insn(struct bpf_ir_env *env,
55
struct ir_insn *insn)

core/bpf_ir.c

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: GPL-2.0-only
2-
#include <linux/bpf_ir.h>
2+
#include "ir.h"
33

44
static const s8 helper_func_arg_num[] = {
55
[1] = 2, // map_lookup_elem
@@ -1503,18 +1503,9 @@ void bpf_ir_free_function(struct ir_function *fun)
15031503
bpf_ir_array_free(&fun->sp->users);
15041504
free_proto(fun->sp);
15051505
}
1506-
for (u8 i = 0; i < BPF_REG_10; ++i) {
1507-
struct ir_insn *insn = fun->cg_info.regs[i];
1508-
bpf_ir_array_free(&insn->users);
1509-
free_proto(insn);
1510-
}
15111506
bpf_ir_array_free(&fun->all_bbs);
15121507
bpf_ir_array_free(&fun->reachable_bbs);
15131508
bpf_ir_array_free(&fun->end_bbs);
1514-
bpf_ir_array_free(&fun->cg_info.seo);
1515-
1516-
bpf_ir_array_free(&fun->cg_info.all_var);
1517-
bpf_ir_ptrset_free(&fun->cg_info.all_var_v2);
15181509
}
15191510

15201511
static void init_function(struct bpf_ir_env *env, struct ir_function *fun,
@@ -1529,10 +1520,6 @@ static void init_function(struct bpf_ir_env *env, struct ir_function *fun,
15291520
INIT_ARRAY(&fun->all_bbs, struct ir_basic_block *);
15301521
INIT_ARRAY(&fun->reachable_bbs, struct ir_basic_block *);
15311522
INIT_ARRAY(&fun->end_bbs, struct ir_basic_block *);
1532-
INIT_ARRAY(&fun->cg_info.all_var, struct ir_insn *);
1533-
INIT_ARRAY(&fun->cg_info.seo, struct ir_insn *);
1534-
INIT_PTRSET_DEF(&fun->cg_info.all_var_v2);
1535-
fun->cg_info.stack_offset = 0;
15361523
for (size_t i = 0; i < MAX_BPF_REG; ++i) {
15371524
struct array *currentDef = &tenv->currentDef[i];
15381525
bpf_ir_array_free(currentDef);
@@ -1548,17 +1535,6 @@ static void init_function(struct bpf_ir_env *env, struct ir_function *fun,
15481535
bpf_ir_array_push(env, &fun->all_bbs, &bb->ir_bb);
15491536
free_proto(bb);
15501537
}
1551-
for (u8 i = 0; i < BPF_REG_10; ++i) {
1552-
struct ir_insn *insn;
1553-
SAFE_MALLOC(fun->cg_info.regs[i], sizeof(struct ir_insn));
1554-
// Those should be read-only
1555-
insn = fun->cg_info.regs[i];
1556-
insn->op = IR_INSN_REG;
1557-
insn->parent_bb = NULL;
1558-
INIT_ARRAY(&insn->users, struct ir_insn *);
1559-
insn->value_num = 0;
1560-
insn->reg_id = i;
1561-
}
15621538
}
15631539

15641540
static void gen_bb_succ(struct bpf_ir_env *env, struct ir_function *fun)
@@ -1974,10 +1950,8 @@ struct bpf_ir_opts bpf_ir_default_opts(void)
19741950
opts.print_mode = BPF_IR_PRINT_BPF;
19751951
opts.builtin_pass_cfg_num = 0;
19761952
opts.custom_pass_num = 0;
1977-
opts.disable_coalesce = false;
19781953
opts.force = false;
19791954
opts.verbose = 1;
1980-
opts.cg_v2 = true;
19811955
opts.dotgraph = false;
19821956
opts.fake_run = false;
19831957
opts.max_iteration = 10;

core/epasstool/epasstool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef _EPASS_TOOL_H_
33
#define _EPASS_TOOL_H_
44

5-
#include <linux/bpf_ir.h>
5+
#include "ir.h"
66

77
struct user_opts {
88
char gopt[64];

core/epasstool/read.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
#include "bpf/libbpf.h"
33
#include "epasstool.h"
4-
#include <unistd.h>
5-
#include <sys/wait.h>
64

75
static void print_bpf_prog_dump(FILE *fp, const struct bpf_insn *insns,
86
size_t len)
@@ -91,7 +89,7 @@ int epass_read(struct user_opts uopts)
9189
struct bpf_program *prog = NULL;
9290
if (uopts.auto_sec) {
9391
prog = bpf_object__next_program(obj, NULL);
94-
strcpy(uopts.sec, bpf_program__section_name(prog));
92+
strcpy(uopts.sec, bpf_program__name(prog));
9593
} else {
9694
prog = bpf_object__find_program_by_name(obj, uopts.sec);
9795
}
@@ -101,10 +99,26 @@ int epass_read(struct user_opts uopts)
10199
err = 1;
102100
goto end;
103101
}
104-
size_t sz = bpf_program__insn_cnt(prog);
105-
const struct bpf_insn *insn = bpf_program__insns(prog);
106102

107-
err = epass_run(uopts, insn, sz);
103+
u64 tot_prog_cnt = 0;
104+
105+
while (prog) {
106+
size_t sz = bpf_program__insn_cnt(prog);
107+
tot_prog_cnt += sz;
108+
const struct bpf_insn *insn = bpf_program__insns(prog);
109+
err = epass_run(uopts, insn, sz);
110+
111+
if (uopts.auto_sec) {
112+
prog = bpf_object__next_program(obj, prog);
113+
if (prog) {
114+
strcpy(uopts.sec, bpf_program__name(prog));
115+
}
116+
} else {
117+
prog = NULL;
118+
}
119+
}
120+
121+
printf("processed %llu instructions\n", tot_prog_cnt);
108122

109123
end:
110124
bpf_object__close(obj);

0 commit comments

Comments
 (0)