Netdev Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH bpf] selftests/bpf: bring back c++ include/link test
@ 2019-12-02 20:21 Stanislav Fomichev
  2019-12-02 21:30 ` Andrii Nakryiko
  0 siblings, 1 reply; 5+ messages in thread
From: Stanislav Fomichev @ 2019-12-02 20:21 UTC (permalink / raw)
  To: netdev, bpf; +Cc: davem, ast, daniel, Stanislav Fomichev

Commit 5c26f9a78358 ("libbpf: Don't use cxx to test_libpf target")
converted existing c++ test to c. We still want to include and
link against libbpf from c++ code, so reinstate this test back,
this time in a form of a selftest with a clear comment about
its purpose.

Fixes: 5c26f9a78358 ("libbpf: Don't use cxx to test_libpf target")
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
 tools/lib/bpf/.gitignore                                    | 1 -
 tools/lib/bpf/Makefile                                      | 5 +----
 tools/testing/selftests/bpf/.gitignore                      | 1 +
 tools/testing/selftests/bpf/Makefile                        | 6 +++++-
 .../test_libbpf.c => testing/selftests/bpf/test_cpp.cpp}    | 0
 5 files changed, 7 insertions(+), 6 deletions(-)
 rename tools/{lib/bpf/test_libbpf.c => testing/selftests/bpf/test_cpp.cpp} (100%)

diff --git a/tools/lib/bpf/.gitignore b/tools/lib/bpf/.gitignore
index 35bf013e368c..e97c2ebcf447 100644
--- a/tools/lib/bpf/.gitignore
+++ b/tools/lib/bpf/.gitignore
@@ -1,7 +1,6 @@
 libbpf_version.h
 libbpf.pc
 FEATURE-DUMP.libbpf
-test_libbpf
 libbpf.so.*
 TAGS
 tags
diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
index 3d3d024f7b94..defae23a0169 100644
--- a/tools/lib/bpf/Makefile
+++ b/tools/lib/bpf/Makefile
@@ -152,7 +152,7 @@ GLOBAL_SYM_COUNT = $(shell readelf -s --wide $(BPF_IN_SHARED) | \
 VERSIONED_SYM_COUNT = $(shell readelf -s --wide $(OUTPUT)libbpf.so | \
 			      grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | sort -u | wc -l)
 
-CMD_TARGETS = $(LIB_TARGET) $(PC_FILE) $(OUTPUT)test_libbpf
+CMD_TARGETS = $(LIB_TARGET) $(PC_FILE)
 
 all: fixdep
 	$(Q)$(MAKE) all_cmd
@@ -196,9 +196,6 @@ $(OUTPUT)libbpf.so.$(LIBBPF_VERSION): $(BPF_IN_SHARED)
 $(OUTPUT)libbpf.a: $(BPF_IN_STATIC)
 	$(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
 
-$(OUTPUT)test_libbpf: test_libbpf.c $(OUTPUT)libbpf.a
-	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(INCLUDES) $^ -lelf -o $@
-
 $(OUTPUT)libbpf.pc:
 	$(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
 		-e "s|@LIBDIR@|$(libdir_SQ)|" \
diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftests/bpf/.gitignore
index 4865116b96c7..419652458da4 100644
--- a/tools/testing/selftests/bpf/.gitignore
+++ b/tools/testing/selftests/bpf/.gitignore
@@ -37,5 +37,6 @@ libbpf.so.*
 test_hashmap
 test_btf_dump
 xdping
+test_cpp
 /no_alu32
 /bpf_gcc
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 085678d88ef8..ba394f0bd631 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -71,7 +71,7 @@ TEST_PROGS_EXTENDED := with_addr.sh \
 # Compile but not part of 'make run_tests'
 TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \
 	flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \
-	test_lirc_mode2_user xdping
+	test_lirc_mode2_user xdping test_cpp
 
 TEST_CUSTOM_PROGS = urandom_read
 
@@ -317,6 +317,10 @@ verifier/tests.h: verifier/*.c
 $(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT)
 	$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
 
+# Make sure we are able to include and link libbpf against c++.
+$(OUTPUT)/test_cpp: test_cpp.cpp $(BPFOBJ)
+	$(CXX) $(CFLAGS) $^ -lelf -o $@
+
 EXTRA_CLEAN := $(TEST_CUSTOM_PROGS)					\
 	prog_tests/tests.h map_tests/tests.h verifier/tests.h		\
 	feature $(OUTPUT)/*.o $(OUTPUT)/no_alu32 $(OUTPUT)/bpf_gcc
diff --git a/tools/lib/bpf/test_libbpf.c b/tools/testing/selftests/bpf/test_cpp.cpp
similarity index 100%
rename from tools/lib/bpf/test_libbpf.c
rename to tools/testing/selftests/bpf/test_cpp.cpp
-- 
2.24.0.393.g34dc348eaf-goog


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf] selftests/bpf: bring back c++ include/link test
  2019-12-02 20:21 [PATCH bpf] selftests/bpf: bring back c++ include/link test Stanislav Fomichev
@ 2019-12-02 21:30 ` Andrii Nakryiko
  2019-12-02 21:49   ` Stanislav Fomichev
  0 siblings, 1 reply; 5+ messages in thread
From: Andrii Nakryiko @ 2019-12-02 21:30 UTC (permalink / raw)
  To: Stanislav Fomichev
  Cc: Networking, bpf, David S. Miller, Alexei Starovoitov, Daniel Borkmann

On Mon, Dec 2, 2019 at 12:28 PM Stanislav Fomichev <sdf@google.com> wrote:
>
> Commit 5c26f9a78358 ("libbpf: Don't use cxx to test_libpf target")
> converted existing c++ test to c. We still want to include and
> link against libbpf from c++ code, so reinstate this test back,
> this time in a form of a selftest with a clear comment about
> its purpose.
>
> Fixes: 5c26f9a78358 ("libbpf: Don't use cxx to test_libpf target")
> Signed-off-by: Stanislav Fomichev <sdf@google.com>
> ---

thanks for clean up! Looks good except for explicit -lelf below.

>  tools/lib/bpf/.gitignore                                    | 1 -
>  tools/lib/bpf/Makefile                                      | 5 +----
>  tools/testing/selftests/bpf/.gitignore                      | 1 +
>  tools/testing/selftests/bpf/Makefile                        | 6 +++++-
>  .../test_libbpf.c => testing/selftests/bpf/test_cpp.cpp}    | 0
>  5 files changed, 7 insertions(+), 6 deletions(-)
>  rename tools/{lib/bpf/test_libbpf.c => testing/selftests/bpf/test_cpp.cpp} (100%)
>

[...]

>
> @@ -317,6 +317,10 @@ verifier/tests.h: verifier/*.c
>  $(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT)
>         $(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
>
> +# Make sure we are able to include and link libbpf against c++.
> +$(OUTPUT)/test_cpp: test_cpp.cpp $(BPFOBJ)
> +       $(CXX) $(CFLAGS) $^ -lelf -o $@

let's use $(LDLIBS) instead here

> +
>  EXTRA_CLEAN := $(TEST_CUSTOM_PROGS)                                    \
>         prog_tests/tests.h map_tests/tests.h verifier/tests.h           \
>         feature $(OUTPUT)/*.o $(OUTPUT)/no_alu32 $(OUTPUT)/bpf_gcc
> diff --git a/tools/lib/bpf/test_libbpf.c b/tools/testing/selftests/bpf/test_cpp.cpp
> similarity index 100%
> rename from tools/lib/bpf/test_libbpf.c
> rename to tools/testing/selftests/bpf/test_cpp.cpp
> --
> 2.24.0.393.g34dc348eaf-goog
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf] selftests/bpf: bring back c++ include/link test
  2019-12-02 21:30 ` Andrii Nakryiko
@ 2019-12-02 21:49   ` Stanislav Fomichev
  2019-12-02 21:57     ` Andrii Nakryiko
  0 siblings, 1 reply; 5+ messages in thread
From: Stanislav Fomichev @ 2019-12-02 21:49 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Stanislav Fomichev, Networking, bpf, David S. Miller,
	Alexei Starovoitov, Daniel Borkmann

On 12/02, Andrii Nakryiko wrote:
> On Mon, Dec 2, 2019 at 12:28 PM Stanislav Fomichev <sdf@google.com> wrote:
> > +# Make sure we are able to include and link libbpf against c++.
> > +$(OUTPUT)/test_cpp: test_cpp.cpp $(BPFOBJ)
> > +       $(CXX) $(CFLAGS) $^ -lelf -o $@
> 
> let's use $(LDLIBS) instead here
Sure, I'll send a v2 with $(LDLIBS); it might be worth doing for
consistency.

Just curious: any particular reason you want to do it?
(looking it tools/build/features, I don't see any possible -lelf
cross-dependency)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf] selftests/bpf: bring back c++ include/link test
  2019-12-02 21:49   ` Stanislav Fomichev
@ 2019-12-02 21:57     ` Andrii Nakryiko
  2019-12-02 22:15       ` Stanislav Fomichev
  0 siblings, 1 reply; 5+ messages in thread
From: Andrii Nakryiko @ 2019-12-02 21:57 UTC (permalink / raw)
  To: Stanislav Fomichev
  Cc: Stanislav Fomichev, Networking, bpf, David S. Miller,
	Alexei Starovoitov, Daniel Borkmann

On Mon, Dec 2, 2019 at 1:49 PM Stanislav Fomichev <sdf@fomichev.me> wrote:
>
> On 12/02, Andrii Nakryiko wrote:
> > On Mon, Dec 2, 2019 at 12:28 PM Stanislav Fomichev <sdf@google.com> wrote:
> > > +# Make sure we are able to include and link libbpf against c++.
> > > +$(OUTPUT)/test_cpp: test_cpp.cpp $(BPFOBJ)
> > > +       $(CXX) $(CFLAGS) $^ -lelf -o $@
> >
> > let's use $(LDLIBS) instead here
> Sure, I'll send a v2 with $(LDLIBS); it might be worth doing for
> consistency.
>
> Just curious: any particular reason you want to do it?
> (looking it tools/build/features, I don't see any possible -lelf
> cross-dependency)

The main reason is that I'd like to only have one (at least one per
Makefile) place where we specify expected library dependencies. In my
extern libbpf change I was adding explicit dependency on zlib, for
instance, and having to grep for -lxxx to see where I should add -lz
is error-prone and annoying. Nothing beyond that.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf] selftests/bpf: bring back c++ include/link test
  2019-12-02 21:57     ` Andrii Nakryiko
@ 2019-12-02 22:15       ` Stanislav Fomichev
  0 siblings, 0 replies; 5+ messages in thread
From: Stanislav Fomichev @ 2019-12-02 22:15 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Stanislav Fomichev, Networking, bpf, David S. Miller,
	Alexei Starovoitov, Daniel Borkmann

On 12/02, Andrii Nakryiko wrote:
> On Mon, Dec 2, 2019 at 1:49 PM Stanislav Fomichev <sdf@fomichev.me> wrote:
> >
> > On 12/02, Andrii Nakryiko wrote:
> > > On Mon, Dec 2, 2019 at 12:28 PM Stanislav Fomichev <sdf@google.com> wrote:
> > > > +# Make sure we are able to include and link libbpf against c++.
> > > > +$(OUTPUT)/test_cpp: test_cpp.cpp $(BPFOBJ)
> > > > +       $(CXX) $(CFLAGS) $^ -lelf -o $@
> > >
> > > let's use $(LDLIBS) instead here
> > Sure, I'll send a v2 with $(LDLIBS); it might be worth doing for
> > consistency.
> >
> > Just curious: any particular reason you want to do it?
> > (looking it tools/build/features, I don't see any possible -lelf
> > cross-dependency)
> 
> The main reason is that I'd like to only have one (at least one per
> Makefile) place where we specify expected library dependencies. In my
> extern libbpf change I was adding explicit dependency on zlib, for
> instance, and having to grep for -lxxx to see where I should add -lz
> is error-prone and annoying. Nothing beyond that.
Makes sense, agreed.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-02 20:21 [PATCH bpf] selftests/bpf: bring back c++ include/link test Stanislav Fomichev
2019-12-02 21:30 ` Andrii Nakryiko
2019-12-02 21:49   ` Stanislav Fomichev
2019-12-02 21:57     ` Andrii Nakryiko
2019-12-02 22:15       ` Stanislav Fomichev

Netdev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netdev/0 netdev/git/0.git
	git clone --mirror https://lore.kernel.org/netdev/1 netdev/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netdev netdev/ https://lore.kernel.org/netdev \
		netdev@vger.kernel.org
	public-inbox-index netdev

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netdev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git