[RFC,bpf-next,2/4] libbpf: introduce bpf_program__overwrite_section_name()
diff mbox series

Message ID 20200213210115.1455809-3-songliubraving@fb.com
State RFC
Delegated to: BPF Maintainers
Headers show
Series
  • bpftool: introduce prog profile
Related show

Commit Message

Song Liu Feb. 13, 2020, 9:01 p.m. UTC
This is a temporary solution before Eelco Chaudron's work for
bpf_program__set_attach_target():

https://patchwork.ozlabs.org/patch/1237539/

Signed-off-by: Song Liu <songliubraving@fb.com>
---
 tools/lib/bpf/libbpf.c   | 13 ++++++++++++-
 tools/lib/bpf/libbpf.h   |  4 ++++
 tools/lib/bpf/libbpf.map |  5 +++++
 3 files changed, 21 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 514b1a524abb..4c29a7181d57 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -238,6 +238,8 @@  struct bpf_program {
 	__u32 line_info_rec_size;
 	__u32 line_info_cnt;
 	__u32 prog_flags;
+
+	char *overwritten_section_name;
 };
 
 struct bpf_struct_ops {
@@ -442,6 +444,7 @@  static void bpf_program__exit(struct bpf_program *prog)
 	zfree(&prog->pin_name);
 	zfree(&prog->insns);
 	zfree(&prog->reloc_desc);
+	zfree(&prog->overwritten_section_name);
 
 	prog->nr_reloc = 0;
 	prog->insns_cnt = 0;
@@ -6637,7 +6640,7 @@  static int libbpf_find_attach_btf_id(struct bpf_program *prog)
 {
 	enum bpf_attach_type attach_type = prog->expected_attach_type;
 	__u32 attach_prog_fd = prog->attach_prog_fd;
-	const char *name = prog->section_name;
+	const char *name = prog->overwritten_section_name ? : prog->section_name;
 	int i, err;
 
 	if (!name)
@@ -8396,3 +8399,11 @@  void bpf_object__destroy_skeleton(struct bpf_object_skeleton *s)
 	free(s->progs);
 	free(s);
 }
+
+char *bpf_program__overwrite_section_name(struct bpf_program *prog,
+					  const char *sec_name)
+{
+	prog->overwritten_section_name = strdup(sec_name);
+
+	return prog->overwritten_section_name;
+}
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 3fe12c9d1f92..02f0d8b57cc4 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -595,6 +595,10 @@  bpf_program__bpil_addr_to_offs(struct bpf_prog_info_linear *info_linear);
 LIBBPF_API void
 bpf_program__bpil_offs_to_addr(struct bpf_prog_info_linear *info_linear);
 
+LIBBPF_API char *
+bpf_program__overwrite_section_name(struct bpf_program *prog,
+				    const char *sec_name);
+
 /*
  * A helper function to get the number of possible CPUs before looking up
  * per-CPU maps. Negative errno is returned on failure.
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index b035122142bb..ed26c20729db 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -235,3 +235,8 @@  LIBBPF_0.0.7 {
 		btf__align_of;
 		libbpf_find_kernel_btf;
 } LIBBPF_0.0.6;
+
+LIBBPF_0.0.8 {
+	global:
+		bpf_program__overwrite_section_name;
+} LIBBPF_0.0.7;