Skip to content

Commit a7045ac

Browse files
d-e-s-odanielocfb
authored andcommitted
libbpf-rs: Few changes to recent patches
This patch changes a few nuisances from recent pull requests: - Rename `Linker::add()` to `add_file` to follow libbpf naming more closely (I still kept `Linker::link()` (as opposed to finalize)) as it seems apt. - Fix `SEC` used in `test_skeleton_builder_deterministic`. The program would no longer load with libbpf 1.0. - Use `vmlinux.h` instead of `<linux/bpf.h>` for consistency with other skeletons. Signed-off-by: Daniel Müller <deso@posteo.net>
1 parent 78a5f52 commit a7045ac

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

libbpf-cargo/src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn strip_dwarf_info(file: &Path) -> Result<()> {
118118
let mut linker =
119119
libbpf_rs::Linker::new(file).context("Failed to instantiate libbpf object file linker")?;
120120
linker
121-
.add(temp_file)
121+
.add_file(temp_file)
122122
.context("Failed to add object file to BPF linker")?;
123123
linker.link().context("Failed to link object file")?;
124124
Ok(())

libbpf-cargo/src/test.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,14 +929,14 @@ fn test_skeleton_builder_deterministic() {
929929
write(
930930
proj_dir.join("src/bpf/prog.bpf.c"),
931931
r#"
932-
#include <linux/bpf.h>
932+
#include "vmlinux.h"
933933
#include <bpf/bpf_helpers.h>
934934
935935
struct {
936936
__uint(type, BPF_MAP_TYPE_REUSEPORT_SOCKARRAY);
937937
} sock_map SEC(".maps");
938938
939-
SEC("sk_reuseport/reuse_pass")
939+
SEC("sk_reuseport")
940940
long prog_select_sk(struct sk_reuseport_md *reuse_md)
941941
{
942942
unsigned int index = 0;
@@ -947,6 +947,8 @@ fn test_skeleton_builder_deterministic() {
947947
)
948948
.expect("failed to write prog.bpf.c");
949949

950+
add_vmlinux_header(&proj_dir);
951+
950952
let skel1 = NamedTempFile::new().unwrap();
951953
SkeletonBuilder::new()
952954
.source(proj_dir.join("src/bpf/prog.bpf.c"))

libbpf-rs/src/linker.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Linker {
3737
}
3838

3939
/// Add a file to the set of files to link.
40-
pub fn add<P>(&mut self, file: P) -> Result<()>
40+
pub fn add_file<P>(&mut self, file: P) -> Result<()>
4141
where
4242
P: AsRef<Path>,
4343
{
@@ -52,7 +52,8 @@ impl Linker {
5252
}
5353
}
5454

55-
/// Link all BPF object files [`add`](Self::add)ed to this object into a single one.
55+
/// Link all BPF object files [added](Self::add_file) to this object into
56+
/// a single one.
5657
pub fn link(&self) -> Result<()> {
5758
// SAFETY: `linker` is a valid pointer.
5859
let err = unsafe { libbpf_sys::bpf_linker__finalize(self.linker) };

libbpf-rs/tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ fn test_object_link_files() {
10271027
let mut linker = Linker::new(output_file.path()).unwrap();
10281028
let () = files
10291029
.into_iter()
1030-
.try_for_each(|file| linker.add(file))
1030+
.try_for_each(|file| linker.add_file(file))
10311031
.unwrap();
10321032
let () = linker.link().unwrap();
10331033

0 commit comments

Comments
 (0)