diff --git a/bpf/aya-bpf-macros/src/expand.rs b/bpf/aya-bpf-macros/src/expand.rs index ed10ca3f8..4285de814 100644 --- a/bpf/aya-bpf-macros/src/expand.rs +++ b/bpf/aya-bpf-macros/src/expand.rs @@ -49,11 +49,13 @@ impl Map { } pub fn expand(&self) -> Result { - let section_name = format!("maps/{}", self.name); + let section_name = "maps".to_string(); + let name = &self.name; let item = &self.item; Ok(quote! { #[no_mangle] #[link_section = #section_name] + #[export_name = #name] #item }) } diff --git a/test/cases/020_elf/000_maps/map_test.ebpf.rs b/test/cases/020_elf/000_maps/map_test.ebpf.rs new file mode 100644 index 000000000..609e93624 --- /dev/null +++ b/test/cases/020_elf/000_maps/map_test.ebpf.rs @@ -0,0 +1,37 @@ +//! ```cargo +//! [dependencies] +//! aya-bpf = { path = "../../../../bpf/aya-bpf" } +//! ``` + +#![no_std] +#![no_main] + +use aya_bpf::{ + bindings::xdp_action, + macros::{map, xdp}, + programs::XdpContext, + maps::Array, +}; + +#[map] +static mut FOO: Array = Array::::with_max_entries(10, 0); + +#[map(name = "BAR")] +static mut BAZ: Array = Array::::with_max_entries(10, 0); + +#[xdp] +pub fn pass(ctx: XdpContext) -> u32 { + match unsafe { try_pass(ctx) } { + Ok(ret) => ret, + Err(_) => xdp_action::XDP_ABORTED, + } +} + +unsafe fn try_pass(_ctx: XdpContext) -> Result { + Ok(xdp_action::XDP_PASS) +} + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + unsafe { core::hint::unreachable_unchecked() } +} \ No newline at end of file diff --git a/test/cases/020_elf/000_maps/map_test.o b/test/cases/020_elf/000_maps/map_test.o new file mode 100644 index 000000000..522a86d28 Binary files /dev/null and b/test/cases/020_elf/000_maps/map_test.o differ diff --git a/test/cases/020_elf/000_maps/test.sh b/test/cases/020_elf/000_maps/test.sh new file mode 100755 index 000000000..3ce0f4cc8 --- /dev/null +++ b/test/cases/020_elf/000_maps/test.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# SUMMARY: Check that maps are correctly represented in ELF files +# LABELS: + +set -ex + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +NAME=map_test + +clean_up() { + rm -rf ebpf user ${NAME}.o +} + +trap clean_up EXIT + +# Test code goes here +compile_ebpf ${NAME}.ebpf.rs + +readelf --sections ${NAME}.o | grep -q "maps" +readelf --syms ${NAME}.o | grep -q "BAR" + +exit 0 \ No newline at end of file diff --git a/test/cases/020_elf/group.sh b/test/cases/020_elf/group.sh new file mode 100644 index 000000000..9a46609c8 --- /dev/null +++ b/test/cases/020_elf/group.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# SUMMARY: Tests to check ELF from aya-bpf +# LABELS: + +# Source libraries. Uncomment if needed/defined +# . "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +set -e + +group_init() { + # Group initialisation code goes here + return 0 +} + +group_deinit() { + # Group de-initialisation code goes here + return 0 +} + +CMD=$1 +case $CMD in +init) + group_init + res=$? + ;; +deinit) + group_deinit + res=$? + ;; +*) + res=1 + ;; +esac + +exit $res \ No newline at end of file