Skip to content

Commit c22911d

Browse files
committed
Core: FIx inconsistent compilation_context usage in helper/printk_formatter
1 parent c04e32b commit c22911d

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

pythonbpf/helper/bpf_helper_handler.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,16 @@ def bpf_printk_emitter(
157157
if isinstance(call.args[0], ast.JoinedStr):
158158
args = handle_fstring_print(
159159
call.args[0],
160-
compilation_context.module,
160+
compilation_context,
161161
builder,
162162
func,
163163
local_sym_tab,
164-
compilation_context.structs_sym_tab,
165164
)
166165
elif isinstance(call.args[0], ast.Constant) and isinstance(call.args[0].value, str):
167166
# TODO: We are only supporting single arguments for now.
168167
# In case of multiple args, the first one will be taken.
169168
args = simple_string_print(
170-
call.args[0].value, compilation_context.module, builder, func
169+
call.args[0].value, compilation_context, builder, func
171170
)
172171
else:
173172
raise NotImplementedError(
@@ -397,7 +396,7 @@ def bpf_perf_event_output_handler(
397396
ctx_ptr = func.args[0] # First argument to the function is ctx
398397

399398
data_ptr, size_val = get_data_ptr_and_size(
400-
data_arg, local_sym_tab, compilation_context.structs_sym_tab
399+
data_arg, local_sym_tab, compilation_context
401400
)
402401

403402
# BPF_F_CURRENT_CPU is -1 in 32 bit
@@ -446,7 +445,7 @@ def bpf_ringbuf_output_emitter(
446445
)
447446
data_arg = call.args[0]
448447
data_ptr, size_val = get_data_ptr_and_size(
449-
data_arg, local_sym_tab, compilation_context.structs_sym_tab
448+
data_arg, local_sym_tab, compilation_context
450449
)
451450
flags_val = ir.Constant(ir.IntType(64), 0)
452451

pythonbpf/helper/helper_utils.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,7 @@ def get_ptr_from_arg(arg, compilation_context, builder, local_sym_tab):
2929
return builder.load(sym.var)
3030

3131
# Use eval_expr for general case
32-
val = eval_expr(
33-
None,
34-
compilation_context.module,
35-
builder,
36-
arg,
37-
local_sym_tab,
38-
compilation_context.map_sym_tab,
39-
compilation_context.structs_sym_tab,
40-
)
32+
val = eval_expr(None, compilation_context, builder, arg, local_sym_tab)
4133
if val and isinstance(val[0].type, ir.PointerType):
4234
return val[0]
4335

pythonbpf/helper/printk_formatter.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
logger = logging.getLogger(__name__)
1010

1111

12-
def simple_string_print(string_value, module, builder, func):
12+
def simple_string_print(string_value, compilation_context, builder, func):
1313
"""Prepare arguments for bpf_printk from a simple string value"""
14+
module = compilation_context.module
1415
fmt_str = string_value + "\n\0"
1516
fmt_ptr = _create_format_string_global(fmt_str, func, module, builder)
1617

@@ -20,11 +21,10 @@ def simple_string_print(string_value, module, builder, func):
2021

2122
def handle_fstring_print(
2223
joined_str,
23-
module,
24+
compilation_context,
2425
builder,
2526
func,
2627
local_sym_tab=None,
27-
struct_sym_tab=None,
2828
):
2929
"""Handle f-string formatting for bpf_printk emitter."""
3030
fmt_parts = []
@@ -41,13 +41,13 @@ def handle_fstring_print(
4141
fmt_parts,
4242
exprs,
4343
local_sym_tab,
44-
struct_sym_tab,
44+
compilation_context.struct_sym_tab,
4545
)
4646
else:
4747
raise NotImplementedError(f"Unsupported f-string value type: {type(value)}")
4848

4949
fmt_str = "".join(fmt_parts)
50-
args = simple_string_print(fmt_str, module, builder, func)
50+
args = simple_string_print(fmt_str, compilation_context, builder, func)
5151

5252
# NOTE: Process expressions (limited to 3 due to BPF constraints)
5353
if len(exprs) > 3:
@@ -57,10 +57,10 @@ def handle_fstring_print(
5757
arg_value = _prepare_expr_args(
5858
expr,
5959
func,
60-
module,
60+
compilation_context.module,
6161
builder,
6262
local_sym_tab,
63-
struct_sym_tab,
63+
compilation_context.struct_sym_tab,
6464
)
6565
args.append(arg_value)
6666

0 commit comments

Comments
 (0)