Skip to content

Commit 74662ea

Browse files
Jakub Kicinskiborkmann
authored andcommitted
samples: bpf: rename struct bpf_map_def to avoid conflict with libbpf
Both tools/lib/bpf/libbpf.h and samples/bpf/bpf_load.h define their own version of struct bpf_map_def. The version in bpf_load.h has more fields. libbpf does not support inner maps and its definition of struct bpf_map_def lacks the related fields. Rename the definition in bpf_load.h (samples/bpf) to avoid conflicts. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent e368751 commit 74662ea

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

samples/bpf/bpf_load.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ static int load_elf_maps_section(struct bpf_map_data *maps, int maps_shndx,
420420

421421
/* Keeping compatible with ELF maps section changes
422422
* ------------------------------------------------
423-
* The program size of struct bpf_map_def is known by loader
423+
* The program size of struct bpf_load_map_def is known by loader
424424
* code, but struct stored in ELF file can be different.
425425
*
426426
* Unfortunately sym[i].st_size is zero. To calculate the
@@ -429,7 +429,7 @@ static int load_elf_maps_section(struct bpf_map_data *maps, int maps_shndx,
429429
* symbols.
430430
*/
431431
map_sz_elf = data_maps->d_size / nr_maps;
432-
map_sz_copy = sizeof(struct bpf_map_def);
432+
map_sz_copy = sizeof(struct bpf_load_map_def);
433433
if (map_sz_elf < map_sz_copy) {
434434
/*
435435
* Backward compat, loading older ELF file with
@@ -448,8 +448,8 @@ static int load_elf_maps_section(struct bpf_map_data *maps, int maps_shndx,
448448

449449
/* Memcpy relevant part of ELF maps data to loader maps */
450450
for (i = 0; i < nr_maps; i++) {
451+
struct bpf_load_map_def *def;
451452
unsigned char *addr, *end;
452-
struct bpf_map_def *def;
453453
const char *map_name;
454454
size_t offset;
455455

@@ -464,9 +464,9 @@ static int load_elf_maps_section(struct bpf_map_data *maps, int maps_shndx,
464464

465465
/* Symbol value is offset into ELF maps section data area */
466466
offset = sym[i].st_value;
467-
def = (struct bpf_map_def *)(data_maps->d_buf + offset);
467+
def = (struct bpf_load_map_def *)(data_maps->d_buf + offset);
468468
maps[i].elf_offset = offset;
469-
memset(&maps[i].def, 0, sizeof(struct bpf_map_def));
469+
memset(&maps[i].def, 0, sizeof(struct bpf_load_map_def));
470470
memcpy(&maps[i].def, def, map_sz_copy);
471471

472472
/* Verify no newer features were requested */

samples/bpf/bpf_load.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#define MAX_MAPS 32
88
#define MAX_PROGS 32
99

10-
struct bpf_map_def {
10+
struct bpf_load_map_def {
1111
unsigned int type;
1212
unsigned int key_size;
1313
unsigned int value_size;
@@ -21,7 +21,7 @@ struct bpf_map_data {
2121
int fd;
2222
char *name;
2323
size_t elf_offset;
24-
struct bpf_map_def def;
24+
struct bpf_load_map_def def;
2525
};
2626

2727
typedef void (*fixup_map_cb)(struct bpf_map_data *map, int idx);

0 commit comments

Comments
 (0)