Skip to content

Commit

Permalink
tools: Remove feature-libelf-mmap feature detection
Browse files Browse the repository at this point in the history
It's trivial to handle missing ELF_C_MMAP_READ support in libelf the way that
objtool has solved it in
("774bec3fddcc objtool: Add fallback from ELF_C_READ_MMAP to ELF_C_READ").

So instead of having an entire feature detector for that, just do what objtool
does for perf and libbpf. And keep their Makefiles a bit simpler.

Signed-off-by: Andrii Nakryiko <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
anakryiko authored and Alexei Starovoitov committed Aug 19, 2020
1 parent 8536703 commit 22dd1ac
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 36 deletions.
1 change: 0 additions & 1 deletion tools/build/Makefile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ FEATURE_TESTS_BASIC := \
libelf-getphdrnum \
libelf-gelf_getnote \
libelf-getshdrstrndx \
libelf-mmap \
libnuma \
numa_num_possible_cpus \
libperl \
Expand Down
4 changes: 0 additions & 4 deletions tools/build/feature/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ FILES= \
test-libelf-getphdrnum.bin \
test-libelf-gelf_getnote.bin \
test-libelf-getshdrstrndx.bin \
test-libelf-mmap.bin \
test-libdebuginfod.bin \
test-libnuma.bin \
test-numa_num_possible_cpus.bin \
Expand Down Expand Up @@ -146,9 +145,6 @@ $(OUTPUT)test-dwarf.bin:
$(OUTPUT)test-dwarf_getlocations.bin:
$(BUILD) $(DWARFLIBS)

$(OUTPUT)test-libelf-mmap.bin:
$(BUILD) -lelf

$(OUTPUT)test-libelf-getphdrnum.bin:
$(BUILD) -lelf

Expand Down
4 changes: 0 additions & 4 deletions tools/build/feature/test-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
# include "test-libelf.c"
#undef main

#define main main_test_libelf_mmap
# include "test-libelf-mmap.c"
#undef main

#define main main_test_get_current_dir_name
# include "test-get_current_dir_name.c"
#undef main
Expand Down
9 changes: 0 additions & 9 deletions tools/build/feature/test-libelf-mmap.c

This file was deleted.

6 changes: 1 addition & 5 deletions tools/lib/bpf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ifndef VERBOSE
endif

FEATURE_USER = .libbpf
FEATURE_TESTS = libelf libelf-mmap zlib bpf
FEATURE_TESTS = libelf zlib bpf
FEATURE_DISPLAY = libelf zlib bpf

INCLUDES = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(ARCH)/include/uapi -I$(srctree)/tools/include/uapi
Expand Down Expand Up @@ -98,10 +98,6 @@ else
CFLAGS := -g -Wall
endif

ifeq ($(feature-libelf-mmap), 1)
override CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
endif

# Append required CFLAGS
override CFLAGS += $(EXTRA_WARNINGS) -Wno-switch-enum
override CFLAGS += -Werror -Wall
Expand Down
14 changes: 6 additions & 8 deletions tools/lib/bpf/libbpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,6 @@ static void pr_perm_msg(int err)
___err; })
#endif

#ifdef HAVE_LIBELF_MMAP_SUPPORT
# define LIBBPF_ELF_C_READ_MMAP ELF_C_READ_MMAP
#else
# define LIBBPF_ELF_C_READ_MMAP ELF_C_READ
#endif

static inline __u64 ptr_to_u64(const void *ptr)
{
return (__u64) (unsigned long) ptr;
Expand Down Expand Up @@ -1064,6 +1058,11 @@ static void bpf_object__elf_finish(struct bpf_object *obj)
obj->efile.obj_buf_sz = 0;
}

/* if libelf is old and doesn't support mmap(), fall back to read() */
#ifndef ELF_C_READ_MMAP
#define ELF_C_READ_MMAP ELF_C_READ
#endif

static int bpf_object__elf_init(struct bpf_object *obj)
{
int err = 0;
Expand Down Expand Up @@ -1092,8 +1091,7 @@ static int bpf_object__elf_init(struct bpf_object *obj)
return err;
}

obj->efile.elf = elf_begin(obj->efile.fd,
LIBBPF_ELF_C_READ_MMAP, NULL);
obj->efile.elf = elf_begin(obj->efile.fd, ELF_C_READ_MMAP, NULL);
}

if (!obj->efile.elf) {
Expand Down
4 changes: 0 additions & 4 deletions tools/perf/Makefile.config
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,6 @@ ifndef NO_LIBELF
EXTLIBS += -lelf
$(call detected,CONFIG_LIBELF)

ifeq ($(feature-libelf-mmap), 1)
CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
endif

ifeq ($(feature-libelf-getphdrnum), 1)
CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
endif
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct option;
* libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
* for newer versions we can use mmap to reduce memory usage:
*/
#ifdef HAVE_LIBELF_MMAP_SUPPORT
#ifdef ELF_C_READ_MMAP
# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
#else
# define PERF_ELF_C_READ_MMAP ELF_C_READ
Expand Down

0 comments on commit 22dd1ac

Please sign in to comment.