All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: emit diff of mismatched public API, if any
@ 2019-05-22 16:15 Andrii Nakryiko
  2019-05-22 16:21 ` Alexei Starovoitov
  0 siblings, 1 reply; 6+ messages in thread
From: Andrii Nakryiko @ 2019-05-22 16:15 UTC (permalink / raw)
  To: andrii.nakryiko, netdev, bpf, ast, daniel; +Cc: Andrii Nakryiko

It's easy to have a mismatch of "intended to be public" vs really
exposed API functions. While Makefile does check for this mismatch, if
it actually occurs it's not trivial to determine which functions are
accidentally exposed. This patch dumps out a diff showing what's not
supposed to be exposed facilitating easier fixing.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
 tools/lib/bpf/.gitignore | 2 ++
 tools/lib/bpf/Makefile   | 8 ++++++++
 2 files changed, 10 insertions(+)

diff --git a/tools/lib/bpf/.gitignore b/tools/lib/bpf/.gitignore
index d9e9dec04605..c7306e858e2e 100644
--- a/tools/lib/bpf/.gitignore
+++ b/tools/lib/bpf/.gitignore
@@ -3,3 +3,5 @@ libbpf.pc
 FEATURE-DUMP.libbpf
 test_libbpf
 libbpf.so.*
+libbpf_global_syms.tmp
+libbpf_versioned_syms.tmp
diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
index f91639bf5650..7e7d6d851713 100644
--- a/tools/lib/bpf/Makefile
+++ b/tools/lib/bpf/Makefile
@@ -204,6 +204,14 @@ check_abi: $(OUTPUT)libbpf.so
 		     "versioned symbols in $^ ($(VERSIONED_SYM_COUNT))." \
 		     "Please make sure all LIBBPF_API symbols are"	 \
 		     "versioned in $(VERSION_SCRIPT)." >&2;		 \
+		readelf -s --wide $(OUTPUT)libbpf-in.o |		 \
+		    awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$8}'|   \
+		    sort -u > $(OUTPUT)libbpf_global_syms.tmp;		 \
+		readelf -s --wide $(OUTPUT)libbpf.so |			 \
+		    grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 |		 \
+		    sort -u > $(OUTPUT)libbpf_versioned_syms.tmp; 	 \
+		diff -u $(OUTPUT)libbpf_global_syms.tmp			 \
+		     $(OUTPUT)libbpf_versioned_syms.tmp;		 \
 		exit 1;							 \
 	fi
 
-- 
2.17.1


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

* Re: [PATCH bpf-next] libbpf: emit diff of mismatched public API, if any
  2019-05-22 16:15 [PATCH bpf-next] libbpf: emit diff of mismatched public API, if any Andrii Nakryiko
@ 2019-05-22 16:21 ` Alexei Starovoitov
  2019-05-22 16:46   ` Stanislav Fomichev
  2019-05-22 17:44   ` Andrii Nakryiko
  0 siblings, 2 replies; 6+ messages in thread
From: Alexei Starovoitov @ 2019-05-22 16:21 UTC (permalink / raw)
  To: Andrii Nakryiko, andrii.nakryiko, netdev, bpf, daniel

On 5/22/19 9:15 AM, Andrii Nakryiko wrote:
> It's easy to have a mismatch of "intended to be public" vs really
> exposed API functions. While Makefile does check for this mismatch, if
> it actually occurs it's not trivial to determine which functions are
> accidentally exposed. This patch dumps out a diff showing what's not
> supposed to be exposed facilitating easier fixing.
> 
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> ---
>   tools/lib/bpf/.gitignore | 2 ++
>   tools/lib/bpf/Makefile   | 8 ++++++++
>   2 files changed, 10 insertions(+)
> 
> diff --git a/tools/lib/bpf/.gitignore b/tools/lib/bpf/.gitignore
> index d9e9dec04605..c7306e858e2e 100644
> --- a/tools/lib/bpf/.gitignore
> +++ b/tools/lib/bpf/.gitignore
> @@ -3,3 +3,5 @@ libbpf.pc
>   FEATURE-DUMP.libbpf
>   test_libbpf
>   libbpf.so.*
> +libbpf_global_syms.tmp
> +libbpf_versioned_syms.tmp
> diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
> index f91639bf5650..7e7d6d851713 100644
> --- a/tools/lib/bpf/Makefile
> +++ b/tools/lib/bpf/Makefile
> @@ -204,6 +204,14 @@ check_abi: $(OUTPUT)libbpf.so
>   		     "versioned symbols in $^ ($(VERSIONED_SYM_COUNT))." \
>   		     "Please make sure all LIBBPF_API symbols are"	 \
>   		     "versioned in $(VERSION_SCRIPT)." >&2;		 \
> +		readelf -s --wide $(OUTPUT)libbpf-in.o |		 \
> +		    awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$8}'|   \
> +		    sort -u > $(OUTPUT)libbpf_global_syms.tmp;		 \
> +		readelf -s --wide $(OUTPUT)libbpf.so |			 \
> +		    grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 |		 \
> +		    sort -u > $(OUTPUT)libbpf_versioned_syms.tmp; 	 \
> +		diff -u $(OUTPUT)libbpf_global_syms.tmp			 \
> +		     $(OUTPUT)libbpf_versioned_syms.tmp;		 \
>   		exit 1;							 \

good idea.
how about removing tmp files instead of adding them to .gitignore?

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

* Re: [PATCH bpf-next] libbpf: emit diff of mismatched public API, if any
  2019-05-22 16:21 ` Alexei Starovoitov
@ 2019-05-22 16:46   ` Stanislav Fomichev
  2019-05-22 17:45     ` Andrii Nakryiko
  2019-05-22 17:44   ` Andrii Nakryiko
  1 sibling, 1 reply; 6+ messages in thread
From: Stanislav Fomichev @ 2019-05-22 16:46 UTC (permalink / raw)
  To: Alexei Starovoitov; +Cc: Andrii Nakryiko, andrii.nakryiko, netdev, bpf, daniel

On 05/22, Alexei Starovoitov wrote:
> On 5/22/19 9:15 AM, Andrii Nakryiko wrote:
> > It's easy to have a mismatch of "intended to be public" vs really
> > exposed API functions. While Makefile does check for this mismatch, if
> > it actually occurs it's not trivial to determine which functions are
> > accidentally exposed. This patch dumps out a diff showing what's not
> > supposed to be exposed facilitating easier fixing.
> > 
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> > ---
> >   tools/lib/bpf/.gitignore | 2 ++
> >   tools/lib/bpf/Makefile   | 8 ++++++++
> >   2 files changed, 10 insertions(+)
> > 
> > diff --git a/tools/lib/bpf/.gitignore b/tools/lib/bpf/.gitignore
> > index d9e9dec04605..c7306e858e2e 100644
> > --- a/tools/lib/bpf/.gitignore
> > +++ b/tools/lib/bpf/.gitignore
> > @@ -3,3 +3,5 @@ libbpf.pc
> >   FEATURE-DUMP.libbpf
> >   test_libbpf
> >   libbpf.so.*
> > +libbpf_global_syms.tmp
> > +libbpf_versioned_syms.tmp
> > diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
> > index f91639bf5650..7e7d6d851713 100644
> > --- a/tools/lib/bpf/Makefile
> > +++ b/tools/lib/bpf/Makefile
> > @@ -204,6 +204,14 @@ check_abi: $(OUTPUT)libbpf.so
> >   		     "versioned symbols in $^ ($(VERSIONED_SYM_COUNT))." \
> >   		     "Please make sure all LIBBPF_API symbols are"	 \
> >   		     "versioned in $(VERSION_SCRIPT)." >&2;		 \
> > +		readelf -s --wide $(OUTPUT)libbpf-in.o |		 \
> > +		    awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$8}'|   \
> > +		    sort -u > $(OUTPUT)libbpf_global_syms.tmp;		 \
> > +		readelf -s --wide $(OUTPUT)libbpf.so |			 \
> > +		    grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 |		 \
> > +		    sort -u > $(OUTPUT)libbpf_versioned_syms.tmp; 	 \
> > +		diff -u $(OUTPUT)libbpf_global_syms.tmp			 \
> > +		     $(OUTPUT)libbpf_versioned_syms.tmp;		 \
> >   		exit 1;							 \
> 
> good idea.
> how about removing tmp files instead of adding them to .gitignore?
We should be able to do it without any temp files. At least in bash
one can do:

diff -u <(readelf -s --wide ${OUTPUT}libbpf-in.o | \
	  awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $8}' | \
	  sort -u) \
	<(readelf -s --wide ${OUTPUT}libbpf.so | \
	  grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | \
	  sort -u)

But might be complicated in the makefile :-/

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

* Re: [PATCH bpf-next] libbpf: emit diff of mismatched public API, if any
  2019-05-22 16:21 ` Alexei Starovoitov
  2019-05-22 16:46   ` Stanislav Fomichev
@ 2019-05-22 17:44   ` Andrii Nakryiko
  1 sibling, 0 replies; 6+ messages in thread
From: Andrii Nakryiko @ 2019-05-22 17:44 UTC (permalink / raw)
  To: Alexei Starovoitov; +Cc: Andrii Nakryiko, netdev, bpf, daniel

On Wed, May 22, 2019 at 9:21 AM Alexei Starovoitov <ast@fb.com> wrote:
>
> On 5/22/19 9:15 AM, Andrii Nakryiko wrote:
> > It's easy to have a mismatch of "intended to be public" vs really
> > exposed API functions. While Makefile does check for this mismatch, if
> > it actually occurs it's not trivial to determine which functions are
> > accidentally exposed. This patch dumps out a diff showing what's not
> > supposed to be exposed facilitating easier fixing.
> >
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> > ---
> >   tools/lib/bpf/.gitignore | 2 ++
> >   tools/lib/bpf/Makefile   | 8 ++++++++
> >   2 files changed, 10 insertions(+)
> >
> > diff --git a/tools/lib/bpf/.gitignore b/tools/lib/bpf/.gitignore
> > index d9e9dec04605..c7306e858e2e 100644
> > --- a/tools/lib/bpf/.gitignore
> > +++ b/tools/lib/bpf/.gitignore
> > @@ -3,3 +3,5 @@ libbpf.pc
> >   FEATURE-DUMP.libbpf
> >   test_libbpf
> >   libbpf.so.*
> > +libbpf_global_syms.tmp
> > +libbpf_versioned_syms.tmp
> > diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
> > index f91639bf5650..7e7d6d851713 100644
> > --- a/tools/lib/bpf/Makefile
> > +++ b/tools/lib/bpf/Makefile
> > @@ -204,6 +204,14 @@ check_abi: $(OUTPUT)libbpf.so
> >                    "versioned symbols in $^ ($(VERSIONED_SYM_COUNT))." \
> >                    "Please make sure all LIBBPF_API symbols are"       \
> >                    "versioned in $(VERSION_SCRIPT)." >&2;              \
> > +             readelf -s --wide $(OUTPUT)libbpf-in.o |                 \
> > +                 awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$8}'|   \
> > +                 sort -u > $(OUTPUT)libbpf_global_syms.tmp;           \
> > +             readelf -s --wide $(OUTPUT)libbpf.so |                   \
> > +                 grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 |             \
> > +                 sort -u > $(OUTPUT)libbpf_versioned_syms.tmp;        \
> > +             diff -u $(OUTPUT)libbpf_global_syms.tmp                  \
> > +                  $(OUTPUT)libbpf_versioned_syms.tmp;                 \
> >               exit 1;                                                  \
>
> good idea.
> how about removing tmp files instead of adding them to .gitignore?

ok, will remove them

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

* Re: [PATCH bpf-next] libbpf: emit diff of mismatched public API, if any
  2019-05-22 16:46   ` Stanislav Fomichev
@ 2019-05-22 17:45     ` Andrii Nakryiko
  2019-05-22 18:00       ` Stanislav Fomichev
  0 siblings, 1 reply; 6+ messages in thread
From: Andrii Nakryiko @ 2019-05-22 17:45 UTC (permalink / raw)
  To: Stanislav Fomichev
  Cc: Alexei Starovoitov, Andrii Nakryiko, netdev, bpf, daniel

On Wed, May 22, 2019 at 9:46 AM Stanislav Fomichev <sdf@fomichev.me> wrote:
>
> On 05/22, Alexei Starovoitov wrote:
> > On 5/22/19 9:15 AM, Andrii Nakryiko wrote:
> > > It's easy to have a mismatch of "intended to be public" vs really
> > > exposed API functions. While Makefile does check for this mismatch, if
> > > it actually occurs it's not trivial to determine which functions are
> > > accidentally exposed. This patch dumps out a diff showing what's not
> > > supposed to be exposed facilitating easier fixing.
> > >
> > > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> > > ---
> > >   tools/lib/bpf/.gitignore | 2 ++
> > >   tools/lib/bpf/Makefile   | 8 ++++++++
> > >   2 files changed, 10 insertions(+)
> > >
> > > diff --git a/tools/lib/bpf/.gitignore b/tools/lib/bpf/.gitignore
> > > index d9e9dec04605..c7306e858e2e 100644
> > > --- a/tools/lib/bpf/.gitignore
> > > +++ b/tools/lib/bpf/.gitignore
> > > @@ -3,3 +3,5 @@ libbpf.pc
> > >   FEATURE-DUMP.libbpf
> > >   test_libbpf
> > >   libbpf.so.*
> > > +libbpf_global_syms.tmp
> > > +libbpf_versioned_syms.tmp
> > > diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
> > > index f91639bf5650..7e7d6d851713 100644
> > > --- a/tools/lib/bpf/Makefile
> > > +++ b/tools/lib/bpf/Makefile
> > > @@ -204,6 +204,14 @@ check_abi: $(OUTPUT)libbpf.so
> > >                  "versioned symbols in $^ ($(VERSIONED_SYM_COUNT))." \
> > >                  "Please make sure all LIBBPF_API symbols are"       \
> > >                  "versioned in $(VERSION_SCRIPT)." >&2;              \
> > > +           readelf -s --wide $(OUTPUT)libbpf-in.o |                 \
> > > +               awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$8}'|   \
> > > +               sort -u > $(OUTPUT)libbpf_global_syms.tmp;           \
> > > +           readelf -s --wide $(OUTPUT)libbpf.so |                   \
> > > +               grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 |             \
> > > +               sort -u > $(OUTPUT)libbpf_versioned_syms.tmp;        \
> > > +           diff -u $(OUTPUT)libbpf_global_syms.tmp                  \
> > > +                $(OUTPUT)libbpf_versioned_syms.tmp;                 \
> > >             exit 1;                                                  \
> >
> > good idea.
> > how about removing tmp files instead of adding them to .gitignore?
> We should be able to do it without any temp files. At least in bash
> one can do:
>
> diff -u <(readelf -s --wide ${OUTPUT}libbpf-in.o | \
>           awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $8}' | \
>           sort -u) \
>         <(readelf -s --wide ${OUTPUT}libbpf.so | \
>           grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | \
>           sort -u)
>
> But might be complicated in the makefile :-/

that was my initial implementation, but it doesn't work in Makefile,
as it's bash-specific

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

* Re: [PATCH bpf-next] libbpf: emit diff of mismatched public API, if any
  2019-05-22 17:45     ` Andrii Nakryiko
@ 2019-05-22 18:00       ` Stanislav Fomichev
  0 siblings, 0 replies; 6+ messages in thread
From: Stanislav Fomichev @ 2019-05-22 18:00 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: Alexei Starovoitov, Andrii Nakryiko, netdev, bpf, daniel

On 05/22, Andrii Nakryiko wrote:
> On Wed, May 22, 2019 at 9:46 AM Stanislav Fomichev <sdf@fomichev.me> wrote:
> >
> > On 05/22, Alexei Starovoitov wrote:
> > > On 5/22/19 9:15 AM, Andrii Nakryiko wrote:
> > > > It's easy to have a mismatch of "intended to be public" vs really
> > > > exposed API functions. While Makefile does check for this mismatch, if
> > > > it actually occurs it's not trivial to determine which functions are
> > > > accidentally exposed. This patch dumps out a diff showing what's not
> > > > supposed to be exposed facilitating easier fixing.
> > > >
> > > > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> > > > ---
> > > >   tools/lib/bpf/.gitignore | 2 ++
> > > >   tools/lib/bpf/Makefile   | 8 ++++++++
> > > >   2 files changed, 10 insertions(+)
> > > >
> > > > diff --git a/tools/lib/bpf/.gitignore b/tools/lib/bpf/.gitignore
> > > > index d9e9dec04605..c7306e858e2e 100644
> > > > --- a/tools/lib/bpf/.gitignore
> > > > +++ b/tools/lib/bpf/.gitignore
> > > > @@ -3,3 +3,5 @@ libbpf.pc
> > > >   FEATURE-DUMP.libbpf
> > > >   test_libbpf
> > > >   libbpf.so.*
> > > > +libbpf_global_syms.tmp
> > > > +libbpf_versioned_syms.tmp
> > > > diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
> > > > index f91639bf5650..7e7d6d851713 100644
> > > > --- a/tools/lib/bpf/Makefile
> > > > +++ b/tools/lib/bpf/Makefile
> > > > @@ -204,6 +204,14 @@ check_abi: $(OUTPUT)libbpf.so
> > > >                  "versioned symbols in $^ ($(VERSIONED_SYM_COUNT))." \
> > > >                  "Please make sure all LIBBPF_API symbols are"       \
> > > >                  "versioned in $(VERSION_SCRIPT)." >&2;              \
> > > > +           readelf -s --wide $(OUTPUT)libbpf-in.o |                 \
> > > > +               awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$8}'|   \
> > > > +               sort -u > $(OUTPUT)libbpf_global_syms.tmp;           \
> > > > +           readelf -s --wide $(OUTPUT)libbpf.so |                   \
> > > > +               grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 |             \
> > > > +               sort -u > $(OUTPUT)libbpf_versioned_syms.tmp;        \
> > > > +           diff -u $(OUTPUT)libbpf_global_syms.tmp                  \
> > > > +                $(OUTPUT)libbpf_versioned_syms.tmp;                 \
> > > >             exit 1;                                                  \
> > >
> > > good idea.
> > > how about removing tmp files instead of adding them to .gitignore?
> > We should be able to do it without any temp files. At least in bash
> > one can do:
> >
> > diff -u <(readelf -s --wide ${OUTPUT}libbpf-in.o | \
> >           awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $8}' | \
> >           sort -u) \
> >         <(readelf -s --wide ${OUTPUT}libbpf.so | \
> >           grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | \
> >           sort -u)
> >
> > But might be complicated in the makefile :-/
> 
> that was my initial implementation, but it doesn't work in Makefile,
> as it's bash-specific
I guess you can wrap it in 'bash -c', but I'm not sure it's better
than the temp files at this point :)

diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
index f91639bf5650..a0005673dcd5 100644
--- a/tools/lib/bpf/Makefile
+++ b/tools/lib/bpf/Makefile
@@ -204,6 +204,13 @@ check_abi: $(OUTPUT)libbpf.so
                     "versioned symbols in $^ ($(VERSIONED_SYM_COUNT))." \
                     "Please make sure all LIBBPF_API symbols are"       \
                     "versioned in $(VERSION_SCRIPT)." >&2;              \
+               bash -c " \
+                    diff -u <(readelf -s --wide $(OUTPUT)libbpf-in.o |  \
+                              awk '/GLOBAL/ && /DEFAULT/ && !/UND/      \
+                              {print \$$8}' | sort -u)                  \
+                            <(readelf -s --wide $(OUTPUT)libbpf.so |    \
+                              grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 |  \
+                              sort -u);"                                \
                exit 1;                                                  \
        fi

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

end of thread, other threads:[~2019-05-22 18:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-22 16:15 [PATCH bpf-next] libbpf: emit diff of mismatched public API, if any Andrii Nakryiko
2019-05-22 16:21 ` Alexei Starovoitov
2019-05-22 16:46   ` Stanislav Fomichev
2019-05-22 17:45     ` Andrii Nakryiko
2019-05-22 18:00       ` Stanislav Fomichev
2019-05-22 17:44   ` Andrii Nakryiko

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.