diff mbox series

[bpf-next,02/10] libbpf: add internal helper to get raw BTF strings section

Message ID 20210310040431.916483-3-andrii@kernel.org (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series BPF static linking | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 6 maintainers not CCed: yhs@fb.com kpsingh@kernel.org kafai@fb.com ast@kernel.org john.fastabend@gmail.com songliubraving@fb.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 24 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Andrii Nakryiko March 10, 2021, 4:04 a.m. UTC
struct btf is an efficient and convenient data structure to be used as a set
of deduplicated strings. This patch adds libbpf-internal btf_raw_str() helper
that gives access to strings section raw data (regardless of whether BTF
object is read-only or writeable) and its size in bytes. This is going to be
used by bpf_linker to implement ELF string table section.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/lib/bpf/btf.c             | 11 +++++++++++
 tools/lib/bpf/libbpf_internal.h |  1 +
 2 files changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index e0b0a78b04fe..6ee82ffcf3ff 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -1296,6 +1296,17 @@  static void *btf_get_raw_data(const struct btf *btf, __u32 *size, bool swap_endi
 	return NULL;
 }
 
+/*
+ * Internal helper to get the size and direct pointer to strings section.
+ * This is used in cases where struct btf is used as an efficient and
+ * convenient strings container (e.g., bpf_linker).
+ */
+const void *btf_raw_strs(const struct btf *btf, size_t *size)
+{
+	*size = btf->hdr->str_len;
+	return btf->strs_data;
+}
+
 const void *btf__get_raw_data(const struct btf *btf_ro, __u32 *size)
 {
 	struct btf *btf = (struct btf *)btf_ro;
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index d09860e435c8..069250e8e871 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -115,6 +115,7 @@  struct btf_type *btf_type_by_id(struct btf *btf, __u32 type_id);
 void *btf_add_mem(void **data, size_t *cap_cnt, size_t elem_sz,
 		  size_t cur_cnt, size_t max_cnt, size_t add_cnt);
 int btf_ensure_mem(void **data, size_t *cap_cnt, size_t elem_sz, size_t need_cnt);
+const void *btf_raw_strs(const struct btf *btf, size_t *size);
 
 static inline bool libbpf_validate_opts(const char *opts,
 					size_t opts_sz, size_t user_sz,