Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loader: __ksym support for variables #1354

Open
dylandreimerink opened this issue Feb 20, 2024 · 0 comments
Open

loader: __ksym support for variables #1354

dylandreimerink opened this issue Feb 20, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@dylandreimerink
Copy link
Member

While trying to replicate some tests for __weak symbols I discovered that we at pressent don't support __ksym variables, only functions.

For example, if you were to attempt to load:

extern const int bpf_prog_active __ksym;

SEC("xdp") int xdp_prog(struct xdp_md *ctx) {
	int *active = (int *)bpf_per_cpu_ptr(&bpf_prog_active, bpf_get_smp_processor_id());
	if (active)
		return 1;
	return 0;
}

It results in the following error: load BTF: data section .ksyms: expected *btf.Func, not *btf.Var: not supported, while loading with bpftool (libbpf) works fine.

What is supposed to happen is that the loader finds the address of the given kernel symbol and relocates it in the assembly.

Initial logic was added in https://lore.kernel.org/bpf/20200619231703.738941-1-andriin@fb.com/, at that point only "typeless" variables were supported so just a memory address essentially.

In a followup patch set BTF support was added https://lore.kernel.org/bpf/20200929235049.2533242-1-haoluo@google.com/, after which structured global variables can be read from the kernel with helpers such as bpf_this_cpu_ptr.

@dylandreimerink dylandreimerink added the enhancement New feature or request label Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant