Skip to content

Commit 5ad0ecb

Browse files
eddyz87anakryiko
authored andcommitted
libbpf: Struct_ops in SEC("?.struct_ops") / SEC("?.struct_ops.link")
Allow using two new section names for struct_ops maps: - SEC("?.struct_ops") - SEC("?.struct_ops.link") To specify maps that have bpf_map->autocreate == false after open. Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20240306104529.6453-12-eddyz87@gmail.com
1 parent 240bf8a commit 5ad0ecb

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

tools/lib/bpf/libbpf.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,15 @@ static int init_struct_ops_maps(struct bpf_object *obj, const char *sec_name,
13221322
return -ENOMEM;
13231323
map->btf_value_type_id = type_id;
13241324

1325+
/* Follow same convention as for programs autoload:
1326+
* SEC("?.struct_ops") means map is not created by default.
1327+
*/
1328+
if (sec_name[0] == '?') {
1329+
map->autocreate = false;
1330+
/* from now on forget there was ? in section name */
1331+
sec_name++;
1332+
}
1333+
13251334
map->def.type = BPF_MAP_TYPE_STRUCT_OPS;
13261335
map->def.key_size = sizeof(int);
13271336
map->def.value_size = type->size;
@@ -3685,7 +3694,9 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
36853694
sec_desc->shdr = sh;
36863695
sec_desc->data = data;
36873696
} else if (strcmp(name, STRUCT_OPS_SEC) == 0 ||
3688-
strcmp(name, STRUCT_OPS_LINK_SEC) == 0) {
3697+
strcmp(name, STRUCT_OPS_LINK_SEC) == 0 ||
3698+
strcmp(name, "?" STRUCT_OPS_SEC) == 0 ||
3699+
strcmp(name, "?" STRUCT_OPS_LINK_SEC) == 0) {
36893700
sec_desc->sec_type = SEC_ST_OPS;
36903701
sec_desc->shdr = sh;
36913702
sec_desc->data = data;
@@ -3705,6 +3716,8 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
37053716
if (!section_have_execinstr(obj, targ_sec_idx) &&
37063717
strcmp(name, ".rel" STRUCT_OPS_SEC) &&
37073718
strcmp(name, ".rel" STRUCT_OPS_LINK_SEC) &&
3719+
strcmp(name, ".rel?" STRUCT_OPS_SEC) &&
3720+
strcmp(name, ".rel?" STRUCT_OPS_LINK_SEC) &&
37083721
strcmp(name, ".rel" MAPS_ELF_SEC)) {
37093722
pr_info("elf: skipping relo section(%d) %s for section(%d) %s\n",
37103723
idx, name, targ_sec_idx,

0 commit comments

Comments
 (0)