* [PATCH bpf-next] libbpf: make sure bpf headers are c++ include-able
@ 2018-11-20 18:14 Stanislav Fomichev
2018-11-20 21:00 ` Y Song
0 siblings, 1 reply; 10+ messages in thread
From: Stanislav Fomichev @ 2018-11-20 18:14 UTC (permalink / raw)
To: netdev, ast, daniel; +Cc: Stanislav Fomichev
Wrap headers in extern "C", to turn off C++ mangling.
This simplifies including libbpf in c++ and linking against it.
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
tools/lib/bpf/bpf.h | 9 +++++++++
tools/lib/bpf/libbpf.h | 9 +++++++++
2 files changed, 18 insertions(+)
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index 26a51538213c..9ea3aec82d8a 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -27,6 +27,10 @@
#include <stdbool.h>
#include <stddef.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#ifndef LIBBPF_API
#define LIBBPF_API __attribute__((visibility("default")))
#endif
@@ -128,4 +132,9 @@ LIBBPF_API int bpf_load_btf(void *btf, __u32 btf_size, char *log_buf,
LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf,
__u32 *buf_len, __u32 *prog_id, __u32 *fd_type,
__u64 *probe_offset, __u64 *probe_addr);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
#endif /* __LIBBPF_BPF_H */
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index b1686a787102..74e57e041705 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -16,6 +16,10 @@
#include <sys/types.h> // for size_t
#include <linux/bpf.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#ifndef LIBBPF_API
#define LIBBPF_API __attribute__((visibility("default")))
#endif
@@ -335,4 +339,9 @@ int libbpf_nl_get_qdisc(int sock, unsigned int nl_pid, int ifindex,
libbpf_dump_nlmsg_t dump_qdisc_nlmsg, void *cookie);
int libbpf_nl_get_filter(int sock, unsigned int nl_pid, int ifindex, int handle,
libbpf_dump_nlmsg_t dump_filter_nlmsg, void *cookie);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
#endif /* __LIBBPF_LIBBPF_H */
--
2.19.1.1215.g8438c0b245-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next] libbpf: make sure bpf headers are c++ include-able
2018-11-20 18:14 [PATCH bpf-next] libbpf: make sure bpf headers are c++ include-able Stanislav Fomichev
@ 2018-11-20 21:00 ` Y Song
2018-11-20 21:24 ` Stanislav Fomichev
0 siblings, 1 reply; 10+ messages in thread
From: Y Song @ 2018-11-20 21:00 UTC (permalink / raw)
To: Stanislav Fomichev; +Cc: netdev, Alexei Starovoitov, Daniel Borkmann
On Tue, Nov 20, 2018 at 10:19 AM Stanislav Fomichev <sdf@google.com> wrote:
>
> Wrap headers in extern "C", to turn off C++ mangling.
> This simplifies including libbpf in c++ and linking against it.
>
> Signed-off-by: Stanislav Fomichev <sdf@google.com>
> ---
> tools/lib/bpf/bpf.h | 9 +++++++++
> tools/lib/bpf/libbpf.h | 9 +++++++++
Do you want to add tools/lib/bpf/btf.h as well? it has some functions
which could be used outside libbpf as well.
> 2 files changed, 18 insertions(+)
>
> diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
> index 26a51538213c..9ea3aec82d8a 100644
> --- a/tools/lib/bpf/bpf.h
> +++ b/tools/lib/bpf/bpf.h
> @@ -27,6 +27,10 @@
> #include <stdbool.h>
> #include <stddef.h>
>
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
Some (but not all) __cplusplus extern wrappers wraps standard include as well
like "#include <stdbool.h>", "#include <stddef.h>". probably does not
matter here
since they may not have function prototype. But just want to point it out so you
are aware of this and may double check.
> +
> #ifndef LIBBPF_API
> #define LIBBPF_API __attribute__((visibility("default")))
> #endif
> @@ -128,4 +132,9 @@ LIBBPF_API int bpf_load_btf(void *btf, __u32 btf_size, char *log_buf,
> LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf,
> __u32 *buf_len, __u32 *prog_id, __u32 *fd_type,
> __u64 *probe_offset, __u64 *probe_addr);
> +
> +#ifdef __cplusplus
> +} /* extern "C" */
> +#endif
> +
> #endif /* __LIBBPF_BPF_H */
> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> index b1686a787102..74e57e041705 100644
> --- a/tools/lib/bpf/libbpf.h
> +++ b/tools/lib/bpf/libbpf.h
> @@ -16,6 +16,10 @@
> #include <sys/types.h> // for size_t
> #include <linux/bpf.h>
>
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> #ifndef LIBBPF_API
> #define LIBBPF_API __attribute__((visibility("default")))
> #endif
> @@ -335,4 +339,9 @@ int libbpf_nl_get_qdisc(int sock, unsigned int nl_pid, int ifindex,
> libbpf_dump_nlmsg_t dump_qdisc_nlmsg, void *cookie);
> int libbpf_nl_get_filter(int sock, unsigned int nl_pid, int ifindex, int handle,
> libbpf_dump_nlmsg_t dump_filter_nlmsg, void *cookie);
> +
> +#ifdef __cplusplus
> +} /* extern "C" */
> +#endif
> +
> #endif /* __LIBBPF_LIBBPF_H */
> --
> 2.19.1.1215.g8438c0b245-goog
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next] libbpf: make sure bpf headers are c++ include-able
2018-11-20 21:00 ` Y Song
@ 2018-11-20 21:24 ` Stanislav Fomichev
2018-11-20 21:37 ` [PATCH bpf-next v2] " Stanislav Fomichev
0 siblings, 1 reply; 10+ messages in thread
From: Stanislav Fomichev @ 2018-11-20 21:24 UTC (permalink / raw)
To: Y Song; +Cc: Stanislav Fomichev, netdev, Alexei Starovoitov, Daniel Borkmann
On 11/20, Y Song wrote:
> On Tue, Nov 20, 2018 at 10:19 AM Stanislav Fomichev <sdf@google.com> wrote:
> >
> > Wrap headers in extern "C", to turn off C++ mangling.
> > This simplifies including libbpf in c++ and linking against it.
> >
> > Signed-off-by: Stanislav Fomichev <sdf@google.com>
> > ---
> > tools/lib/bpf/bpf.h | 9 +++++++++
> > tools/lib/bpf/libbpf.h | 9 +++++++++
>
> Do you want to add tools/lib/bpf/btf.h as well? it has some functions
> which could be used outside libbpf as well.
Sure, I can do that in v2.
> > 2 files changed, 18 insertions(+)
> >
> > diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
> > index 26a51538213c..9ea3aec82d8a 100644
> > --- a/tools/lib/bpf/bpf.h
> > +++ b/tools/lib/bpf/bpf.h
> > @@ -27,6 +27,10 @@
> > #include <stdbool.h>
> > #include <stddef.h>
> >
> > +#ifdef __cplusplus
> > +extern "C" {
> > +#endif
>
> Some (but not all) __cplusplus extern wrappers wraps standard include as well
> like "#include <stdbool.h>", "#include <stddef.h>". probably does not
> matter here
> since they may not have function prototype. But just want to point it out so you
> are aware of this and may double check.
Standard headers should be safe, they are usually wrapped into
__BEGIN_DECLS/__END_DECLS (which is extern "C" {}). For <linux/bpf.h>
I don't think we need an extern, because it only defines enums/structs
and not something we can link against (global vars/functions).
> > +
> > #ifndef LIBBPF_API
> > #define LIBBPF_API __attribute__((visibility("default")))
> > #endif
> > @@ -128,4 +132,9 @@ LIBBPF_API int bpf_load_btf(void *btf, __u32 btf_size, char *log_buf,
> > LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf,
> > __u32 *buf_len, __u32 *prog_id, __u32 *fd_type,
> > __u64 *probe_offset, __u64 *probe_addr);
> > +
> > +#ifdef __cplusplus
> > +} /* extern "C" */
> > +#endif
> > +
> > #endif /* __LIBBPF_BPF_H */
> > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> > index b1686a787102..74e57e041705 100644
> > --- a/tools/lib/bpf/libbpf.h
> > +++ b/tools/lib/bpf/libbpf.h
> > @@ -16,6 +16,10 @@
> > #include <sys/types.h> // for size_t
> > #include <linux/bpf.h>
> >
> > +#ifdef __cplusplus
> > +extern "C" {
> > +#endif
> > +
> > #ifndef LIBBPF_API
> > #define LIBBPF_API __attribute__((visibility("default")))
> > #endif
> > @@ -335,4 +339,9 @@ int libbpf_nl_get_qdisc(int sock, unsigned int nl_pid, int ifindex,
> > libbpf_dump_nlmsg_t dump_qdisc_nlmsg, void *cookie);
> > int libbpf_nl_get_filter(int sock, unsigned int nl_pid, int ifindex, int handle,
> > libbpf_dump_nlmsg_t dump_filter_nlmsg, void *cookie);
> > +
> > +#ifdef __cplusplus
> > +} /* extern "C" */
> > +#endif
> > +
> > #endif /* __LIBBPF_LIBBPF_H */
> > --
> > 2.19.1.1215.g8438c0b245-goog
> >
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH bpf-next v2] libbpf: make sure bpf headers are c++ include-able
2018-11-20 21:24 ` Stanislav Fomichev
@ 2018-11-20 21:37 ` Stanislav Fomichev
2018-11-20 22:11 ` Y Song
2018-11-20 23:49 ` Alexei Starovoitov
0 siblings, 2 replies; 10+ messages in thread
From: Stanislav Fomichev @ 2018-11-20 21:37 UTC (permalink / raw)
To: netdev, ast, daniel, ys114321; +Cc: Stanislav Fomichev
Wrap headers in extern "C", to turn off C++ mangling.
This simplifies including libbpf in c++ and linking against it.
v2 changes:
* do the same for btf.h
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
tools/lib/bpf/bpf.h | 9 +++++++++
tools/lib/bpf/btf.h | 8 ++++++++
tools/lib/bpf/libbpf.h | 9 +++++++++
3 files changed, 26 insertions(+)
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index 26a51538213c..9ea3aec82d8a 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -27,6 +27,10 @@
#include <stdbool.h>
#include <stddef.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#ifndef LIBBPF_API
#define LIBBPF_API __attribute__((visibility("default")))
#endif
@@ -128,4 +132,9 @@ LIBBPF_API int bpf_load_btf(void *btf, __u32 btf_size, char *log_buf,
LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf,
__u32 *buf_len, __u32 *prog_id, __u32 *fd_type,
__u64 *probe_offset, __u64 *probe_addr);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
#endif /* __LIBBPF_BPF_H */
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index b77e7080f7e7..5f3d7de850fc 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -6,6 +6,10 @@
#include <linux/types.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#ifndef LIBBPF_API
#define LIBBPF_API __attribute__((visibility("default")))
#endif
@@ -29,4 +33,8 @@ LIBBPF_API int btf__resolve_type(const struct btf *btf, __u32 type_id);
LIBBPF_API int btf__fd(const struct btf *btf);
LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset);
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
#endif /* __LIBBPF_BTF_H */
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index b1686a787102..74e57e041705 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -16,6 +16,10 @@
#include <sys/types.h> // for size_t
#include <linux/bpf.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#ifndef LIBBPF_API
#define LIBBPF_API __attribute__((visibility("default")))
#endif
@@ -335,4 +339,9 @@ int libbpf_nl_get_qdisc(int sock, unsigned int nl_pid, int ifindex,
libbpf_dump_nlmsg_t dump_qdisc_nlmsg, void *cookie);
int libbpf_nl_get_filter(int sock, unsigned int nl_pid, int ifindex, int handle,
libbpf_dump_nlmsg_t dump_filter_nlmsg, void *cookie);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
#endif /* __LIBBPF_LIBBPF_H */
--
2.19.1.1215.g8438c0b245-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v2] libbpf: make sure bpf headers are c++ include-able
2018-11-20 21:37 ` [PATCH bpf-next v2] " Stanislav Fomichev
@ 2018-11-20 22:11 ` Y Song
2018-11-20 23:49 ` Alexei Starovoitov
1 sibling, 0 replies; 10+ messages in thread
From: Y Song @ 2018-11-20 22:11 UTC (permalink / raw)
To: Stanislav Fomichev; +Cc: netdev, Alexei Starovoitov, Daniel Borkmann
On Tue, Nov 20, 2018 at 1:37 PM Stanislav Fomichev <sdf@google.com> wrote:
>
> Wrap headers in extern "C", to turn off C++ mangling.
> This simplifies including libbpf in c++ and linking against it.
>
> v2 changes:
> * do the same for btf.h
>
> Signed-off-by: Stanislav Fomichev <sdf@google.com>
Acked-by: Yonghong Song <yhs@fb.com>
> ---
> tools/lib/bpf/bpf.h | 9 +++++++++
> tools/lib/bpf/btf.h | 8 ++++++++
> tools/lib/bpf/libbpf.h | 9 +++++++++
> 3 files changed, 26 insertions(+)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v2] libbpf: make sure bpf headers are c++ include-able
2018-11-20 21:37 ` [PATCH bpf-next v2] " Stanislav Fomichev
2018-11-20 22:11 ` Y Song
@ 2018-11-20 23:49 ` Alexei Starovoitov
2018-11-21 0:05 ` Stanislav Fomichev
1 sibling, 1 reply; 10+ messages in thread
From: Alexei Starovoitov @ 2018-11-20 23:49 UTC (permalink / raw)
To: Stanislav Fomichev; +Cc: netdev, ast, daniel, ys114321
On Tue, Nov 20, 2018 at 01:37:23PM -0800, Stanislav Fomichev wrote:
> Wrap headers in extern "C", to turn off C++ mangling.
> This simplifies including libbpf in c++ and linking against it.
>
> v2 changes:
> * do the same for btf.h
>
> Signed-off-by: Stanislav Fomichev <sdf@google.com>
> ---
> tools/lib/bpf/bpf.h | 9 +++++++++
> tools/lib/bpf/btf.h | 8 ++++++++
> tools/lib/bpf/libbpf.h | 9 +++++++++
> 3 files changed, 26 insertions(+)
>
> diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
> index 26a51538213c..9ea3aec82d8a 100644
> --- a/tools/lib/bpf/bpf.h
> +++ b/tools/lib/bpf/bpf.h
> @@ -27,6 +27,10 @@
> #include <stdbool.h>
> #include <stddef.h>
>
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
Acked-by: Alexei Starovoitov <ast@kernel.org>
was wondering whether it's possible to make it testable.
HOSTCXX is available, but I don't see much of the kernel tree
using it...
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v2] libbpf: make sure bpf headers are c++ include-able
2018-11-20 23:49 ` Alexei Starovoitov
@ 2018-11-21 0:05 ` Stanislav Fomichev
2018-11-21 0:15 ` Alexei Starovoitov
0 siblings, 1 reply; 10+ messages in thread
From: Stanislav Fomichev @ 2018-11-21 0:05 UTC (permalink / raw)
To: Alexei Starovoitov; +Cc: Stanislav Fomichev, netdev, ast, daniel, ys114321
On 11/20, Alexei Starovoitov wrote:
> On Tue, Nov 20, 2018 at 01:37:23PM -0800, Stanislav Fomichev wrote:
> > Wrap headers in extern "C", to turn off C++ mangling.
> > This simplifies including libbpf in c++ and linking against it.
> >
> > v2 changes:
> > * do the same for btf.h
> >
> > Signed-off-by: Stanislav Fomichev <sdf@google.com>
> > ---
> > tools/lib/bpf/bpf.h | 9 +++++++++
> > tools/lib/bpf/btf.h | 8 ++++++++
> > tools/lib/bpf/libbpf.h | 9 +++++++++
> > 3 files changed, 26 insertions(+)
> >
> > diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
> > index 26a51538213c..9ea3aec82d8a 100644
> > --- a/tools/lib/bpf/bpf.h
> > +++ b/tools/lib/bpf/bpf.h
> > @@ -27,6 +27,10 @@
> > #include <stdbool.h>
> > #include <stddef.h>
> >
> > +#ifdef __cplusplus
> > +extern "C" {
> > +#endif
>
> Acked-by: Alexei Starovoitov <ast@kernel.org>
>
> was wondering whether it's possible to make it testable.
> HOSTCXX is available, but I don't see much of the kernel tree
> using it...
By testable you mean compile some dummy c++ main and link against libbpf?
perf has something similar:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/c++/clang-test.cpp#n7
But they don't use Makefiles for that (there is USE_CXX feature test as
well), so I'm not sure either :-/
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v2] libbpf: make sure bpf headers are c++ include-able
2018-11-21 0:05 ` Stanislav Fomichev
@ 2018-11-21 0:15 ` Alexei Starovoitov
2018-11-21 1:59 ` Stanislav Fomichev
0 siblings, 1 reply; 10+ messages in thread
From: Alexei Starovoitov @ 2018-11-21 0:15 UTC (permalink / raw)
To: Stanislav Fomichev; +Cc: Stanislav Fomichev, netdev, ast, daniel, ys114321
On Tue, Nov 20, 2018 at 04:05:55PM -0800, Stanislav Fomichev wrote:
> On 11/20, Alexei Starovoitov wrote:
> > On Tue, Nov 20, 2018 at 01:37:23PM -0800, Stanislav Fomichev wrote:
> > > Wrap headers in extern "C", to turn off C++ mangling.
> > > This simplifies including libbpf in c++ and linking against it.
> > >
> > > v2 changes:
> > > * do the same for btf.h
> > >
> > > Signed-off-by: Stanislav Fomichev <sdf@google.com>
> > > ---
> > > tools/lib/bpf/bpf.h | 9 +++++++++
> > > tools/lib/bpf/btf.h | 8 ++++++++
> > > tools/lib/bpf/libbpf.h | 9 +++++++++
> > > 3 files changed, 26 insertions(+)
> > >
> > > diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
> > > index 26a51538213c..9ea3aec82d8a 100644
> > > --- a/tools/lib/bpf/bpf.h
> > > +++ b/tools/lib/bpf/bpf.h
> > > @@ -27,6 +27,10 @@
> > > #include <stdbool.h>
> > > #include <stddef.h>
> > >
> > > +#ifdef __cplusplus
> > > +extern "C" {
> > > +#endif
> >
> > Acked-by: Alexei Starovoitov <ast@kernel.org>
> >
> > was wondering whether it's possible to make it testable.
> > HOSTCXX is available, but I don't see much of the kernel tree
> > using it...
> By testable you mean compile some dummy c++ main and link against libbpf?
yes. something like this.
to make sure that it keeps being functional and no one introduces 'int new'
in some function argument list by accident.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v2] libbpf: make sure bpf headers are c++ include-able
2018-11-21 0:15 ` Alexei Starovoitov
@ 2018-11-21 1:59 ` Stanislav Fomichev
2018-11-21 2:42 ` Alexei Starovoitov
0 siblings, 1 reply; 10+ messages in thread
From: Stanislav Fomichev @ 2018-11-21 1:59 UTC (permalink / raw)
To: Alexei Starovoitov; +Cc: Stanislav Fomichev, netdev, ast, daniel, ys114321
On 11/20, Alexei Starovoitov wrote:
> On Tue, Nov 20, 2018 at 04:05:55PM -0800, Stanislav Fomichev wrote:
> > On 11/20, Alexei Starovoitov wrote:
> > > On Tue, Nov 20, 2018 at 01:37:23PM -0800, Stanislav Fomichev wrote:
> > > > Wrap headers in extern "C", to turn off C++ mangling.
> > > > This simplifies including libbpf in c++ and linking against it.
> > > >
> > > > v2 changes:
> > > > * do the same for btf.h
> > > >
> > > > Signed-off-by: Stanislav Fomichev <sdf@google.com>
> > > > ---
> > > > tools/lib/bpf/bpf.h | 9 +++++++++
> > > > tools/lib/bpf/btf.h | 8 ++++++++
> > > > tools/lib/bpf/libbpf.h | 9 +++++++++
> > > > 3 files changed, 26 insertions(+)
> > > >
> > > > diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
> > > > index 26a51538213c..9ea3aec82d8a 100644
> > > > --- a/tools/lib/bpf/bpf.h
> > > > +++ b/tools/lib/bpf/bpf.h
> > > > @@ -27,6 +27,10 @@
> > > > #include <stdbool.h>
> > > > #include <stddef.h>
> > > >
> > > > +#ifdef __cplusplus
> > > > +extern "C" {
> > > > +#endif
> > >
> > > Acked-by: Alexei Starovoitov <ast@kernel.org>
> > >
> > > was wondering whether it's possible to make it testable.
> > > HOSTCXX is available, but I don't see much of the kernel tree
> > > using it...
> > By testable you mean compile some dummy c++ main and link against libbpf?
>
> yes. something like this.
> to make sure that it keeps being functional and no one introduces 'int new'
> in some function argument list by accident.
I tried something like the patch below, it does seem to work locally (building
in the same directory, no cross-compile). Who would be the best to
review that kind of stuff?
diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
index 425b480bda75..4c0e58628aad 100644
--- a/tools/lib/bpf/Makefile
+++ b/tools/lib/bpf/Makefile
@@ -66,7 +66,7 @@ ifndef VERBOSE
endif
FEATURE_USER = .libbpf
-FEATURE_TESTS = libelf libelf-mmap bpf reallocarray
+FEATURE_TESTS = libelf libelf-mmap bpf reallocarray cxx
FEATURE_DISPLAY = libelf bpf
INCLUDES = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(ARCH)/include/uapi -I$(srctree)/tools/include/uapi
@@ -148,6 +148,10 @@ LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE))
CMD_TARGETS = $(LIB_FILE)
+ifeq ($(feature-cxx), 1)
+ CMD_TARGETS += $(OUTPUT)test_libbpf
+endif
+
TARGETS = $(CMD_TARGETS)
all: fixdep all_cmd
@@ -175,6 +179,9 @@ $(OUTPUT)libbpf.so: $(BPF_IN)
$(OUTPUT)libbpf.a: $(BPF_IN)
$(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
+$(OUTPUT)test_libbpf: test_libbpf.cpp $(OUTPUT)libbpf.a
+ $(QUIET_LINK)$(CXX) $^ -lelf -o $@
+
define do_install
if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v2] libbpf: make sure bpf headers are c++ include-able
2018-11-21 1:59 ` Stanislav Fomichev
@ 2018-11-21 2:42 ` Alexei Starovoitov
0 siblings, 0 replies; 10+ messages in thread
From: Alexei Starovoitov @ 2018-11-21 2:42 UTC (permalink / raw)
To: Stanislav Fomichev; +Cc: Stanislav Fomichev, netdev, ast, daniel, ys114321
On Tue, Nov 20, 2018 at 05:59:52PM -0800, Stanislav Fomichev wrote:
> On 11/20, Alexei Starovoitov wrote:
> > On Tue, Nov 20, 2018 at 04:05:55PM -0800, Stanislav Fomichev wrote:
> > > On 11/20, Alexei Starovoitov wrote:
> > > > On Tue, Nov 20, 2018 at 01:37:23PM -0800, Stanislav Fomichev wrote:
> > > > > Wrap headers in extern "C", to turn off C++ mangling.
> > > > > This simplifies including libbpf in c++ and linking against it.
> > > > >
> > > > > v2 changes:
> > > > > * do the same for btf.h
> > > > >
> > > > > Signed-off-by: Stanislav Fomichev <sdf@google.com>
> > > > > ---
> > > > > tools/lib/bpf/bpf.h | 9 +++++++++
> > > > > tools/lib/bpf/btf.h | 8 ++++++++
> > > > > tools/lib/bpf/libbpf.h | 9 +++++++++
> > > > > 3 files changed, 26 insertions(+)
> > > > >
> > > > > diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
> > > > > index 26a51538213c..9ea3aec82d8a 100644
> > > > > --- a/tools/lib/bpf/bpf.h
> > > > > +++ b/tools/lib/bpf/bpf.h
> > > > > @@ -27,6 +27,10 @@
> > > > > #include <stdbool.h>
> > > > > #include <stddef.h>
> > > > >
> > > > > +#ifdef __cplusplus
> > > > > +extern "C" {
> > > > > +#endif
> > > >
> > > > Acked-by: Alexei Starovoitov <ast@kernel.org>
> > > >
> > > > was wondering whether it's possible to make it testable.
> > > > HOSTCXX is available, but I don't see much of the kernel tree
> > > > using it...
> > > By testable you mean compile some dummy c++ main and link against libbpf?
> >
> > yes. something like this.
> > to make sure that it keeps being functional and no one introduces 'int new'
> > in some function argument list by accident.
> I tried something like the patch below, it does seem to work locally (building
> in the same directory, no cross-compile). Who would be the best to
> review that kind of stuff?
>
> diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
> index 425b480bda75..4c0e58628aad 100644
> --- a/tools/lib/bpf/Makefile
> +++ b/tools/lib/bpf/Makefile
> @@ -66,7 +66,7 @@ ifndef VERBOSE
> endif
>
> FEATURE_USER = .libbpf
> -FEATURE_TESTS = libelf libelf-mmap bpf reallocarray
> +FEATURE_TESTS = libelf libelf-mmap bpf reallocarray cxx
> FEATURE_DISPLAY = libelf bpf
>
> INCLUDES = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(ARCH)/include/uapi -I$(srctree)/tools/include/uapi
> @@ -148,6 +148,10 @@ LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE))
>
> CMD_TARGETS = $(LIB_FILE)
>
> +ifeq ($(feature-cxx), 1)
> + CMD_TARGETS += $(OUTPUT)test_libbpf
> +endif
> +
> TARGETS = $(CMD_TARGETS)
>
> all: fixdep all_cmd
> @@ -175,6 +179,9 @@ $(OUTPUT)libbpf.so: $(BPF_IN)
> $(OUTPUT)libbpf.a: $(BPF_IN)
> $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
>
> +$(OUTPUT)test_libbpf: test_libbpf.cpp $(OUTPUT)libbpf.a
> + $(QUIET_LINK)$(CXX) $^ -lelf -o $@
looks good to me.
pls include test_libbpf.cpp and resubmit for bpf-next.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2018-11-21 13:14 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-20 18:14 [PATCH bpf-next] libbpf: make sure bpf headers are c++ include-able Stanislav Fomichev
2018-11-20 21:00 ` Y Song
2018-11-20 21:24 ` Stanislav Fomichev
2018-11-20 21:37 ` [PATCH bpf-next v2] " Stanislav Fomichev
2018-11-20 22:11 ` Y Song
2018-11-20 23:49 ` Alexei Starovoitov
2018-11-21 0:05 ` Stanislav Fomichev
2018-11-21 0:15 ` Alexei Starovoitov
2018-11-21 1:59 ` Stanislav Fomichev
2018-11-21 2:42 ` Alexei Starovoitov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.