From 4a60c42cd0608541d6a05072f26834c20b76d3a0 Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Fri, 3 Oct 2025 21:25:58 +0530 Subject: [PATCH 01/10] add global failing test Signed-off-by: varun-r-mallya --- tests/c-form/globals.bpf.c | 0 tests/failing_tests/globals.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/c-form/globals.bpf.c create mode 100644 tests/failing_tests/globals.py diff --git a/tests/c-form/globals.bpf.c b/tests/c-form/globals.bpf.c new file mode 100644 index 0000000..e69de29 diff --git a/tests/failing_tests/globals.py b/tests/failing_tests/globals.py new file mode 100644 index 0000000..e69de29 From c3a512d5cf737346e0003ba2283c59433b266d5a Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Fri, 3 Oct 2025 22:20:04 +0530 Subject: [PATCH 02/10] add global support with broken generation function --- pythonbpf/codegen.py | 3 +- pythonbpf/globals_pass.py | 86 +++++++++++++++++++++++++++++----- tests/c-form/globals.bpf.c | 27 +++++++++++ tests/failing_tests/globals.py | 23 +++++++++ 4 files changed, 127 insertions(+), 12 deletions(-) diff --git a/pythonbpf/codegen.py b/pythonbpf/codegen.py index 5de23a5..e0cb7b6 100644 --- a/pythonbpf/codegen.py +++ b/pythonbpf/codegen.py @@ -4,7 +4,7 @@ from .functions_pass import func_proc from .maps import maps_proc from .structs import structs_proc -from .globals_pass import globals_processing +from .globals_pass import globals_list_creation, globals_processing from .debuginfo import DW_LANG_C11, DwarfBehaviorEnum, DebugInfoGenerator import os import subprocess @@ -46,6 +46,7 @@ def processor(source_code, filename, module): license_processing(tree, module) globals_processing(tree, module) + globals_list_creation(tree, module) def compile_to_ir(filename: str, output: str, loglevel=logging.WARNING): diff --git a/pythonbpf/globals_pass.py b/pythonbpf/globals_pass.py index 1228809..86ba19f 100644 --- a/pythonbpf/globals_pass.py +++ b/pythonbpf/globals_pass.py @@ -1,8 +1,71 @@ from llvmlite import ir import ast +from llvmlite import ir +import ast +from logging import Logger +import logging +from .type_deducer import ctypes_to_ir + +logger: Logger = logging.getLogger(__name__) + + +def emit_global(module: ir.Module, node, name): + print("global", node.returns.id) + ty = ctypes_to_ir(node.returns.id) + + gvar = ir.GlobalVariable(module, ty, name=name) + gvar.initializer = ir.Constant(ty, initial_value) + gvar.align = 8 + gvar.linkage = "dso_local" + gvar.global_constant = False + return gvar -def emit_globals(module: ir.Module, names: list[str]): + +def globals_processing(tree, module): + """Process stuff decorated with @bpf and @bpfglobal except license and return the section name""" + global_sym_tab = [] + + for node in tree.body: + # Skip non-assignment and non-function nodes + if not (isinstance(node, (ast.FunctionDef, ast.AnnAssign, ast.Assign))): + continue + + # Get the name based on node type + if isinstance(node, ast.FunctionDef): + name = node.name + else: + continue + + # Check for duplicate names + if name in global_sym_tab: + raise SyntaxError(f"ERROR: Global name '{name}' previously defined") + else: + global_sym_tab.append(name) + + # Process decorated functions + if isinstance(node, ast.FunctionDef) and node.name != "LICENSE": + # Check decorators + decorators = [ + dec.id for dec in node.decorator_list if isinstance(dec, ast.Name) + ] + + if "bpf" in decorators and "bpfglobal" in decorators: + if ( + len(node.body) == 1 + and isinstance(node.body[0], ast.Return) + and node.body[0].value is not None + and isinstance(node.body[0].value, (ast.Constant, ast.Name)) + ): + emit_global(module, node, name) + return node.name + else: + logger.info(f"Invalid global expression for '{node.name}'") + return None + + return None + +def emit_llvm_compiler_used(module: ir.Module, names: list[str]): """ Emit the @llvm.compiler.used global given a list of function/global names. """ @@ -24,26 +87,27 @@ def emit_globals(module: ir.Module, names: list[str]): gv.section = "llvm.metadata" -def globals_processing(tree, module: ir.Module): +def globals_list_creation(tree, module: ir.Module): collected = ["LICENSE"] for node in tree.body: if isinstance(node, ast.FunctionDef): for dec in node.decorator_list: if ( - isinstance(dec, ast.Call) - and isinstance(dec.func, ast.Name) - and dec.func.id == "section" - and len(dec.args) == 1 - and isinstance(dec.args[0], ast.Constant) - and isinstance(dec.args[0].value, str) + isinstance(dec, ast.Call) + and isinstance(dec.func, ast.Name) + and dec.func.id == "section" + and len(dec.args) == 1 + and isinstance(dec.args[0], ast.Constant) + and isinstance(dec.args[0].value, str) ): collected.append(node.name) - elif isinstance(dec, ast.Name) and dec.id == "bpfglobal": - collected.append(node.name) + # NOTE: all globals other than + # elif isinstance(dec, ast.Name) and dec.id == "bpfglobal": + # collected.append(node.name) elif isinstance(dec, ast.Name) and dec.id == "map": collected.append(node.name) - emit_globals(module, collected) + emit_llvm_compiler_used(module, collected) diff --git a/tests/c-form/globals.bpf.c b/tests/c-form/globals.bpf.c index e69de29..588cac5 100644 --- a/tests/c-form/globals.bpf.c +++ b/tests/c-form/globals.bpf.c @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +#include +#include +#include +#include + +struct test_struct { + __u64 a; + __u64 b; +}; + +struct test_struct w = {}; +volatile __u64 prev_time = 0; + +SEC("tracepoint/syscalls/sys_enter_execve") +int trace_execve(void *ctx) +{ + bpf_printk("previous %ul now %ul", w.b, w.a); + __u64 ts = bpf_ktime_get_ns(); + bpf_printk("prev %ul now %ul", prev_time, ts); + w.a = ts; + w.b = prev_time; + prev_time = ts; + return 0; +} + +char LICENSE[] SEC("license") = "GPL"; diff --git a/tests/failing_tests/globals.py b/tests/failing_tests/globals.py index e69de29..e1b9222 100644 --- a/tests/failing_tests/globals.py +++ b/tests/failing_tests/globals.py @@ -0,0 +1,23 @@ +import logging + +from pythonbpf import compile, bpf, section, bpfglobal, compile_to_ir +from ctypes import c_void_p, c_int64 + +@bpf +@bpfglobal +def somevalue() -> c_int64: + return c_int64(0) + +@bpf +@section("sometag1") +def sometag(ctx: c_void_p) -> c_int64: + return c_int64(0) + +@bpf +@bpfglobal +def LICENSE() -> str: + return "GPL" + + +compile_to_ir("globals.py", "globals.ll", loglevel=logging.INFO) +compile() From ab1c4223d5514bdabf323ebaa828d7990446dbea Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Fri, 3 Oct 2025 22:55:40 +0530 Subject: [PATCH 03/10] fix broken IR generation logic for globals --- pythonbpf/globals_pass.py | 74 +++++++++++++++++++++++----------- tests/failing_tests/globals.py | 19 +++++++-- 2 files changed, 65 insertions(+), 28 deletions(-) diff --git a/pythonbpf/globals_pass.py b/pythonbpf/globals_pass.py index 86ba19f..4178f0f 100644 --- a/pythonbpf/globals_pass.py +++ b/pythonbpf/globals_pass.py @@ -1,8 +1,6 @@ from llvmlite import ir import ast -from llvmlite import ir -import ast from logging import Logger import logging from .type_deducer import ctypes_to_ir @@ -11,11 +9,41 @@ def emit_global(module: ir.Module, node, name): - print("global", node.returns.id) + logger.info(f"global identifier {name} processing") + # TODO: below part is LLM generated check logic. + # deduce LLVM type from the annotated return + if not isinstance(node.returns, ast.Name): + raise ValueError(f"Unsupported return annotation {ast.dump(node.returns)}") ty = ctypes_to_ir(node.returns.id) + # extract the return expression + ret_stmt = node.body[0] + if not isinstance(ret_stmt, ast.Return) or ret_stmt.value is None: + raise ValueError(f"Global '{name}' has no valid return") + + init_val = ret_stmt.value + + # simple constant like "return 0" + if isinstance(init_val, ast.Constant): + llvm_init = ir.Constant(ty, init_val.value) + + # variable reference like "return SOME_CONST" + elif isinstance(init_val, ast.Name): + # you may need symbol resolution here, stub as 0 for now + raise ValueError(f"Name reference {init_val.id} not yet supported") + + # constructor call like "return c_int64(0)" or dataclass(...) + elif isinstance(init_val, ast.Call): + if len(init_val.args) == 1 and isinstance(init_val.args[0], ast.Constant): + llvm_init = ir.Constant(ty, init_val.args[0].value) + else: + raise ValueError(f"Complex constructor not supported: {ast.dump(init_val)}") + + else: + raise ValueError(f"Unsupported return expr {ast.dump(init_val)}") + gvar = ir.GlobalVariable(module, ty, name=name) - gvar.initializer = ir.Constant(ty, initial_value) + gvar.initializer = llvm_init gvar.align = 8 gvar.linkage = "dso_local" gvar.global_constant = False @@ -24,11 +52,11 @@ def emit_global(module: ir.Module, node, name): def globals_processing(tree, module): """Process stuff decorated with @bpf and @bpfglobal except license and return the section name""" - global_sym_tab = [] + globals_sym_tab = [] for node in tree.body: # Skip non-assignment and non-function nodes - if not (isinstance(node, (ast.FunctionDef, ast.AnnAssign, ast.Assign))): + if not (isinstance(node, ast.FunctionDef)): continue # Get the name based on node type @@ -38,33 +66,31 @@ def globals_processing(tree, module): continue # Check for duplicate names - if name in global_sym_tab: + if name in globals_sym_tab: raise SyntaxError(f"ERROR: Global name '{name}' previously defined") else: - global_sym_tab.append(name) + globals_sym_tab.append(name) - # Process decorated functions if isinstance(node, ast.FunctionDef) and node.name != "LICENSE": - # Check decorators decorators = [ dec.id for dec in node.decorator_list if isinstance(dec, ast.Name) ] - if "bpf" in decorators and "bpfglobal" in decorators: if ( - len(node.body) == 1 - and isinstance(node.body[0], ast.Return) - and node.body[0].value is not None - and isinstance(node.body[0].value, (ast.Constant, ast.Name)) + len(node.body) == 1 + and isinstance(node.body[0], ast.Return) + and node.body[0].value is not None + and isinstance( + node.body[0].value, (ast.Constant, ast.Name, ast.Call) + ) ): emit_global(module, node, name) - return node.name else: - logger.info(f"Invalid global expression for '{node.name}'") - return None + raise SyntaxError(f"ERROR: Invalid syntax for {name} global") return None + def emit_llvm_compiler_used(module: ir.Module, names: list[str]): """ Emit the @llvm.compiler.used global given a list of function/global names. @@ -94,12 +120,12 @@ def globals_list_creation(tree, module: ir.Module): if isinstance(node, ast.FunctionDef): for dec in node.decorator_list: if ( - isinstance(dec, ast.Call) - and isinstance(dec.func, ast.Name) - and dec.func.id == "section" - and len(dec.args) == 1 - and isinstance(dec.args[0], ast.Constant) - and isinstance(dec.args[0].value, str) + isinstance(dec, ast.Call) + and isinstance(dec.func, ast.Name) + and dec.func.id == "section" + and len(dec.args) == 1 + and isinstance(dec.args[0], ast.Constant) + and isinstance(dec.args[0].value, str) ): collected.append(node.name) diff --git a/tests/failing_tests/globals.py b/tests/failing_tests/globals.py index e1b9222..05ac5fd 100644 --- a/tests/failing_tests/globals.py +++ b/tests/failing_tests/globals.py @@ -1,17 +1,28 @@ import logging from pythonbpf import compile, bpf, section, bpfglobal, compile_to_ir -from ctypes import c_void_p, c_int64 +from ctypes import c_void_p, c_int64, c_int32 @bpf @bpfglobal -def somevalue() -> c_int64: +def somevalue() -> c_int32: + return c_int32(0) + +@bpf +@bpfglobal +def somevalue2() -> c_int64: return c_int64(0) @bpf -@section("sometag1") +@bpfglobal +def somevalue1() -> c_int32: + return c_int32(0) + +@bpf +@section("tracepoint/syscalls/sys_enter_execve") def sometag(ctx: c_void_p) -> c_int64: - return c_int64(0) + print("test") + return c_int64(1) @bpf @bpfglobal From 7aeac86bd34c2171b9b55100663928f1308a7d57 Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Sat, 4 Oct 2025 06:32:25 +0530 Subject: [PATCH 04/10] fix broken IR generation logic for globals --- pythonbpf/globals_pass.py | 7 ++-- tests/failing_tests/globals.py | 67 ++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/pythonbpf/globals_pass.py b/pythonbpf/globals_pass.py index 4178f0f..198d813 100644 --- a/pythonbpf/globals_pass.py +++ b/pythonbpf/globals_pass.py @@ -34,11 +34,11 @@ def emit_global(module: ir.Module, node, name): # constructor call like "return c_int64(0)" or dataclass(...) elif isinstance(init_val, ast.Call): - if len(init_val.args) == 1 and isinstance(init_val.args[0], ast.Constant): + if len(init_val.args) >= 1 and isinstance(init_val.args[0], ast.Constant): llvm_init = ir.Constant(ty, init_val.args[0].value) else: - raise ValueError(f"Complex constructor not supported: {ast.dump(init_val)}") - + logger.info("Defaulting to zero as no constant argument found") + llvm_init = ir.Constant(ty, 0) else: raise ValueError(f"Unsupported return expr {ast.dump(init_val)}") @@ -49,7 +49,6 @@ def emit_global(module: ir.Module, node, name): gvar.global_constant = False return gvar - def globals_processing(tree, module): """Process stuff decorated with @bpf and @bpfglobal except license and return the section name""" globals_sym_tab = [] diff --git a/tests/failing_tests/globals.py b/tests/failing_tests/globals.py index 05ac5fd..6b914fd 100644 --- a/tests/failing_tests/globals.py +++ b/tests/failing_tests/globals.py @@ -18,6 +18,73 @@ def somevalue2() -> c_int64: def somevalue1() -> c_int32: return c_int32(0) +import ast +from dataclasses import dataclass +from typing import List + +# --- Passing examples --- + +# Simple constant return +@bpf +@bpfglobal +def g1() -> c_int64: + return 42 + +# Constructor with one constant argument +@bpf +@bpfglobal +def g2() -> c_int64: + return c_int64(0) + + +# --- Failing examples --- + +# No return annotation +# @bpf +# @bpfglobal +# def g3(): +# return 42 + +# Return annotation is complex +# @bpf +# @bpfglobal +# def g4() -> List[int]: +# return [] + +# # Return is missing +# @bpf +# @bpfglobal +# def g5() -> c_int64: +# pass + +# # Return is a variable reference +# #TODO: maybe fix this sometime later. It defaults to 0 +CONST = 5 +@bpf +@bpfglobal +def g6() -> c_int64: + return c_int64(CONST) + +# Constructor with multiple args +#TODO: this is not working. should it work ? +@bpf +@bpfglobal +def g7() -> c_int64: + return c_int64(1, 2) + +# Dataclass call +#TODO: fails with dataclass +# @dataclass +# class Point: +# x: c_int64 +# y: c_int64 + +# @bpf +# @bpfglobal +# def g8() -> Point: +# return Point(1, 2) + + @bpf @section("tracepoint/syscalls/sys_enter_execve") def sometag(ctx: c_void_p) -> c_int64: From 7720fe9f9fb75d22d4c4f9f204cfa53bf8159ee3 Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Sat, 4 Oct 2025 06:33:09 +0530 Subject: [PATCH 05/10] format chore --- pythonbpf/globals_pass.py | 1 + tests/failing_tests/globals.py | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pythonbpf/globals_pass.py b/pythonbpf/globals_pass.py index 198d813..4c6ed97 100644 --- a/pythonbpf/globals_pass.py +++ b/pythonbpf/globals_pass.py @@ -49,6 +49,7 @@ def emit_global(module: ir.Module, node, name): gvar.global_constant = False return gvar + def globals_processing(tree, module): """Process stuff decorated with @bpf and @bpfglobal except license and return the section name""" globals_sym_tab = [] diff --git a/tests/failing_tests/globals.py b/tests/failing_tests/globals.py index 6b914fd..ae526a5 100644 --- a/tests/failing_tests/globals.py +++ b/tests/failing_tests/globals.py @@ -18,9 +18,6 @@ def somevalue2() -> c_int64: def somevalue1() -> c_int32: return c_int32(0) -import ast -from dataclasses import dataclass -from typing import List # --- Passing examples --- From ab610147a53c68a1d7f6db671dcf9e2b4bdb0567 Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Sat, 4 Oct 2025 06:36:26 +0530 Subject: [PATCH 06/10] update globals test and todos. --- pythonbpf/globals_pass.py | 4 ++-- tests/failing_tests/globals.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pythonbpf/globals_pass.py b/pythonbpf/globals_pass.py index 4c6ed97..b73a072 100644 --- a/pythonbpf/globals_pass.py +++ b/pythonbpf/globals_pass.py @@ -10,13 +10,13 @@ def emit_global(module: ir.Module, node, name): logger.info(f"global identifier {name} processing") - # TODO: below part is LLM generated check logic. # deduce LLVM type from the annotated return if not isinstance(node.returns, ast.Name): raise ValueError(f"Unsupported return annotation {ast.dump(node.returns)}") ty = ctypes_to_ir(node.returns.id) # extract the return expression + # TODO: turn this return extractor into a generic function I can use everywhere. ret_stmt = node.body[0] if not isinstance(ret_stmt, ast.Return) or ret_stmt.value is None: raise ValueError(f"Global '{name}' has no valid return") @@ -29,7 +29,7 @@ def emit_global(module: ir.Module, node, name): # variable reference like "return SOME_CONST" elif isinstance(init_val, ast.Name): - # you may need symbol resolution here, stub as 0 for now + # need symbol resolution here, stub as 0 for now raise ValueError(f"Name reference {init_val.id} not yet supported") # constructor call like "return c_int64(0)" or dataclass(...) diff --git a/tests/failing_tests/globals.py b/tests/failing_tests/globals.py index ae526a5..02c604e 100644 --- a/tests/failing_tests/globals.py +++ b/tests/failing_tests/globals.py @@ -6,17 +6,17 @@ @bpf @bpfglobal def somevalue() -> c_int32: - return c_int32(0) + return c_int32(42) @bpf @bpfglobal def somevalue2() -> c_int64: - return c_int64(0) + return c_int64(69) @bpf @bpfglobal def somevalue1() -> c_int32: - return c_int32(0) + return c_int32(42) # --- Passing examples --- @@ -31,7 +31,7 @@ def g1() -> c_int64: @bpf @bpfglobal def g2() -> c_int64: - return c_int64(0) + return c_int64(69) # --- Failing examples --- From df3f00261abf8f586b2645151f0881d30f3cd93a Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Sat, 4 Oct 2025 08:17:16 +0530 Subject: [PATCH 07/10] changer order of passes --- pythonbpf/codegen.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pythonbpf/codegen.py b/pythonbpf/codegen.py index e0cb7b6..3b8f76a 100644 --- a/pythonbpf/codegen.py +++ b/pythonbpf/codegen.py @@ -40,12 +40,13 @@ def processor(source_code, filename, module): for func_node in bpf_chunks: logger.info(f"Found BPF function/struct: {func_node.name}") + license_processing(tree, module) + globals_processing(tree, module) + structs_sym_tab = structs_proc(tree, module, bpf_chunks) map_sym_tab = maps_proc(tree, module, bpf_chunks) func_proc(tree, module, bpf_chunks, map_sym_tab, structs_sym_tab) - license_processing(tree, module) - globals_processing(tree, module) globals_list_creation(tree, module) From 7ae84a0d5ad3240078a2e544c5e9de2f05184f0b Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Sun, 5 Oct 2025 00:55:22 +0530 Subject: [PATCH 08/10] add failing test --- tests/failing_tests/undeclared_values.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/failing_tests/undeclared_values.py diff --git a/tests/failing_tests/undeclared_values.py b/tests/failing_tests/undeclared_values.py new file mode 100644 index 0000000..1cd0d59 --- /dev/null +++ b/tests/failing_tests/undeclared_values.py @@ -0,0 +1,21 @@ +import logging + +from pythonbpf import compile, bpf, section, bpfglobal, compile_to_ir +from ctypes import c_void_p, c_int64 + +# This should not pass as somevalue is not declared at all. +@bpf +@section("tracepoint/syscalls/sys_enter_execve") +def sometag(ctx: c_void_p) -> c_int64: + print("test") + print(f"{somevalue}") + return c_int64(1) + +@bpf +@bpfglobal +def LICENSE() -> str: + return "GPL" + + +compile_to_ir("globals.py", "globals.ll", loglevel=logging.INFO) +compile() From 01bd7604edac1f35765db1141c21ccfb0b98b0af Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Sun, 5 Oct 2025 14:02:46 +0530 Subject: [PATCH 09/10] add global symbol table populate function --- pythonbpf/codegen.py | 7 ++++++- pythonbpf/globals_pass.py | 24 ++++++++++++++++++++++++ tests/failing_tests/globals.py | 17 ++++++++++------- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/pythonbpf/codegen.py b/pythonbpf/codegen.py index 3b8f76a..772c2b2 100644 --- a/pythonbpf/codegen.py +++ b/pythonbpf/codegen.py @@ -4,7 +4,11 @@ from .functions_pass import func_proc from .maps import maps_proc from .structs import structs_proc -from .globals_pass import globals_list_creation, globals_processing +from .globals_pass import ( + globals_list_creation, + globals_processing, + populate_global_symbol_table, +) from .debuginfo import DW_LANG_C11, DwarfBehaviorEnum, DebugInfoGenerator import os import subprocess @@ -40,6 +44,7 @@ def processor(source_code, filename, module): for func_node in bpf_chunks: logger.info(f"Found BPF function/struct: {func_node.name}") + populate_global_symbol_table(tree, module) license_processing(tree, module) globals_processing(tree, module) diff --git a/pythonbpf/globals_pass.py b/pythonbpf/globals_pass.py index b73a072..1e97763 100644 --- a/pythonbpf/globals_pass.py +++ b/pythonbpf/globals_pass.py @@ -7,6 +7,30 @@ logger: Logger = logging.getLogger(__name__) +# TODO: this is going to be a huge fuck of a headache in the future. +global_sym_tab = [] + + +def populate_global_symbol_table(tree, module: ir.Module): + for node in tree.body: + if isinstance(node, ast.FunctionDef): + for dec in node.decorator_list: + if ( + isinstance(dec, ast.Call) + and isinstance(dec.func, ast.Name) + and dec.func.id == "section" + and len(dec.args) == 1 + and isinstance(dec.args[0], ast.Constant) + and isinstance(dec.args[0].value, str) + ): + global_sym_tab.append(node) + elif isinstance(dec, ast.Name) and dec.id == "bpfglobal": + global_sym_tab.append(node) + + elif isinstance(dec, ast.Name) and dec.id == "map": + global_sym_tab.append(node) + return False + def emit_global(module: ir.Module, node, name): logger.info(f"global identifier {name} processing") diff --git a/tests/failing_tests/globals.py b/tests/failing_tests/globals.py index 02c604e..55d9740 100644 --- a/tests/failing_tests/globals.py +++ b/tests/failing_tests/globals.py @@ -25,7 +25,7 @@ def somevalue1() -> c_int32: @bpf @bpfglobal def g1() -> c_int64: - return 42 + return c_int64(42) # Constructor with one constant argument @bpf @@ -56,18 +56,18 @@ def g2() -> c_int64: # # Return is a variable reference # #TODO: maybe fix this sometime later. It defaults to 0 -CONST = 5 -@bpf -@bpfglobal -def g6() -> c_int64: - return c_int64(CONST) +# CONST = 5 +# @bpf +# @bpfglobal +# def g6() -> c_int64: +# return c_int64(CONST) # Constructor with multiple args #TODO: this is not working. should it work ? @bpf @bpfglobal def g7() -> c_int64: - return c_int64(1, 2) + return c_int64(1) # Dataclass call #TODO: fails with dataclass @@ -86,6 +86,9 @@ def g7() -> c_int64: @section("tracepoint/syscalls/sys_enter_execve") def sometag(ctx: c_void_p) -> c_int64: print("test") + global somevalue + somevalue = 2 + print(f"{somevalue}") return c_int64(1) @bpf From 3abe07c5b27bb689b6a0fadfa8d81ca16dd3c32c Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Sun, 5 Oct 2025 14:02:46 +0530 Subject: [PATCH 10/10] add global symbol table populate function --- tests/failing_tests/undeclared_values.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/failing_tests/undeclared_values.py b/tests/failing_tests/undeclared_values.py index 1cd0d59..02f5184 100644 --- a/tests/failing_tests/undeclared_values.py +++ b/tests/failing_tests/undeclared_values.py @@ -8,7 +8,7 @@ @section("tracepoint/syscalls/sys_enter_execve") def sometag(ctx: c_void_p) -> c_int64: print("test") - print(f"{somevalue}") + print(f"{somevalue}") #type: ignore return c_int64(1) @bpf