Skip to content

Commit e1b62d2

Browse files
dave-tuckerfasterthanlime
authored andcommitted
bpf: Maps live in maps section
This forces all maps to the maps section so we remain compatible with libbpf. This requires aya-rs#181 to avoid breaking userspace. Signed-off-by: Dave Tucker <[email protected]>
1 parent cec58c4 commit e1b62d2

File tree

5 files changed

+101
-1
lines changed

5 files changed

+101
-1
lines changed

bpf/aya-bpf-macros/src/expand.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ impl Map {
4949
}
5050

5151
pub fn expand(&self) -> Result<TokenStream> {
52-
let section_name = format!("maps/{}", self.name);
52+
let section_name = "maps".to_string();
53+
let name = &self.name;
5354
let item = &self.item;
5455
Ok(quote! {
5556
#[no_mangle]
5657
#[link_section = #section_name]
58+
#[export_name = #name]
5759
#item
5860
})
5961
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//! ```cargo
2+
//! [dependencies]
3+
//! aya-bpf = { path = "../../../../bpf/aya-bpf" }
4+
//! ```
5+
6+
#![no_std]
7+
#![no_main]
8+
9+
use aya_bpf::{
10+
bindings::xdp_action,
11+
macros::{map, xdp},
12+
programs::XdpContext,
13+
maps::Array,
14+
};
15+
16+
#[map]
17+
static mut FOO: Array<u32> = Array::<u32>::with_max_entries(10, 0);
18+
19+
#[map(name = "BAR")]
20+
static mut BAZ: Array<u32> = Array::<u32>::with_max_entries(10, 0);
21+
22+
#[xdp]
23+
pub fn pass(ctx: XdpContext) -> u32 {
24+
match unsafe { try_pass(ctx) } {
25+
Ok(ret) => ret,
26+
Err(_) => xdp_action::XDP_ABORTED,
27+
}
28+
}
29+
30+
unsafe fn try_pass(_ctx: XdpContext) -> Result<u32, u32> {
31+
Ok(xdp_action::XDP_PASS)
32+
}
33+
34+
#[panic_handler]
35+
fn panic(_info: &core::panic::PanicInfo) -> ! {
36+
unsafe { core::hint::unreachable_unchecked() }
37+
}
105 KB
Binary file not shown.

test/cases/020_elf/000_maps/test.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
# SUMMARY: Check that maps are correctly represented in ELF files
3+
# LABELS:
4+
5+
set -ex
6+
7+
# Source libraries. Uncomment if needed/defined
8+
#. "${RT_LIB}"
9+
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
10+
11+
NAME=map_test
12+
13+
clean_up() {
14+
rm -rf ebpf user ${NAME}.o
15+
}
16+
17+
trap clean_up EXIT
18+
19+
# Test code goes here
20+
compile_ebpf ${NAME}.ebpf.rs
21+
22+
readelf --sections ${NAME}.o | grep -q "maps"
23+
readelf --syms ${NAME}.o | grep -q "BAR"
24+
25+
exit 0

test/cases/020_elf/group.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh
2+
# SUMMARY: Tests to check ELF from aya-bpf
3+
# LABELS:
4+
5+
# Source libraries. Uncomment if needed/defined
6+
# . "${RT_LIB}"
7+
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
8+
9+
set -e
10+
11+
group_init() {
12+
# Group initialisation code goes here
13+
return 0
14+
}
15+
16+
group_deinit() {
17+
# Group de-initialisation code goes here
18+
return 0
19+
}
20+
21+
CMD=$1
22+
case $CMD in
23+
init)
24+
group_init
25+
res=$?
26+
;;
27+
deinit)
28+
group_deinit
29+
res=$?
30+
;;
31+
*)
32+
res=1
33+
;;
34+
esac
35+
36+
exit $res

0 commit comments

Comments
 (0)