Skip to contentSkip to conversation

bpf: Make some functions static

PATCH In review Wang Hai 2 participants 2 messages Jul 18, 2020 – Jul 20, 2020

Subsystems (3)
lore
Share & tools
lore

Wang Hai

author
#0 lore raw

PATCH 1/1 bpf: Make some functions static

Fix sparse build warning:

net/bpf/test_run.c:120:14: warning:
symbol 'bpf_fentry_test1' was not declared. Should it be static?
net/bpf/test_run.c:125:14: warning:
symbol 'bpf_fentry_test2' was not declared. Should it be static?
net/bpf/test_run.c:130:14: warning:
symbol 'bpf_fentry_test3' was not declared. Should it be static?
net/bpf/test_run.c:135:14: warning:
symbol 'bpf_fentry_test4' was not declared. Should it be static?
net/bpf/test_run.c:140:14: warning:
symbol 'bpf_fentry_test5' was not declared. Should it be static?
net/bpf/test_run.c:145:14: warning:
symbol 'bpf_fentry_test6' was not declared. Should it be static?
net/bpf/test_run.c:154:14: warning:
symbol 'bpf_fentry_test7' was not declared. Should it be static?
net/bpf/test_run.c:159:14: warning:
symbol 'bpf_fentry_test8' was not declared. Should it be static?
net/bpf/test_run.c:164:14: warning:
symbol 'bpf_modify_return_test' was not declared. Should it be static?

---
 net/bpf/test_run.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
net/bpf/test_run.c +9 -9
index b03c469cd01f..0d78bd9b6c9d 100644
@@ -117,32 +117,32 @@ static int bpf_test_finish(const union bpf_attr *kattr,
 __diag_push();
 __diag_ignore(GCC, 8, "-Wmissing-prototypes",
 	      "Global functions as their definitions will be in vmlinux BTF");
-int noinline bpf_fentry_test1(int a)
+static noinline int bpf_fentry_test1(int a)
 {
 	return a + 1;
 }
 
-int noinline bpf_fentry_test2(int a, u64 b)
+static noinline int bpf_fentry_test2(int a, u64 b)
 {
 	return a + b;
 }
 
-int noinline bpf_fentry_test3(char a, int b, u64 c)
+static noinline int bpf_fentry_test3(char a, int b, u64 c)
 {
 	return a + b + c;
 }
 
-int noinline bpf_fentry_test4(void *a, char b, int c, u64 d)
+static noinline int bpf_fentry_test4(void *a, char b, int c, u64 d)
 {
 	return (long)a + b + c + d;
 }
 
-int noinline bpf_fentry_test5(u64 a, void *b, short c, int d, u64 e)
+static noinline int bpf_fentry_test5(u64 a, void *b, short c, int d, u64 e)
 {
 	return a + (long)b + c + d + e;
 }
 
-int noinline bpf_fentry_test6(u64 a, void *b, short c, int d, void *e, u64 f)
+static noinline int bpf_fentry_test6(u64 a, void *b, short c, int d, void *e, u64 f)
 {
 	return a + (long)b + c + d + (long)e + f;
 }
@@ -151,17 +151,17 @@ struct bpf_fentry_test_t {
 	struct bpf_fentry_test_t *a;
 };
 
-int noinline bpf_fentry_test7(struct bpf_fentry_test_t *arg)
+static noinline int bpf_fentry_test7(struct bpf_fentry_test_t *arg)
 {
 	return (long)arg;
 }
 
-int noinline bpf_fentry_test8(struct bpf_fentry_test_t *arg)
+static noinline int bpf_fentry_test8(struct bpf_fentry_test_t *arg)
 {
 	return (long)arg->a;
 }
 
-int noinline bpf_modify_return_test(int a, int *b)
+static noinline int bpf_modify_return_test(int a, int *b)
 {
 	*b += 1;
 	return a + *b;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 21 lines · Wang Hai

Fix sparse build warning:

net/bpf/test_run.c:120:14: warning:
symbol 'bpf_fentry_test1' was not declared. Should it be static?
net/bpf/test_run.c:125:14: warning:
symbol 'bpf_fentry_test2' was not declared. Should it be static?
net/bpf/test_run.c:130:14: warning:
symbol 'bpf_fentry_test3' was not declared. Should it be static?
net/bpf/test_run.c:135:14: warning:
symbol 'bpf_fentry_test4' was not declared. Should it be static?
net/bpf/test_run.c:140:14: warning:
symbol 'bpf_fentry_test5' was not declared. Should it be static?
net/bpf/test_run.c:145:14: warning:
symbol 'bpf_fentry_test6' was not declared. Should it be static?
net/bpf/test_run.c:154:14: warning:
symbol 'bpf_fentry_test7' was not declared. Should it be static?
net/bpf/test_run.c:159:14: warning:
symbol 'bpf_fentry_test8' was not declared. Should it be static?
net/bpf/test_run.c:164:14: warning:
symbol 'bpf_modify_return_test' was not declared. Should it be static?

Quoted 2 lines

Please see commit:

commit e9ff9d52540a53ce8c9eff5bf8b66467fe81eb2b

Author: Jean-Philippe Menil <[email protected]>
Date:   Fri Mar 27 21:47:13 2020 +0100

bpf: Fix build warning regarding missing prototypes

Fix build warnings when building net/bpf/test_run.o with W=1 due to missing prototype for bpf_fentry_test{1..6}.

Instead of declaring prototypes, turn off warnings with __diag_{push,ignore,pop} as pointed out by Alexei.

You probably use an old compiler (gcc < 8) which is why the warning is emitted.

Quoted 30 lines
---
  net/bpf/test_run.c | 18 +++++++++---------
  1 file changed, 9 insertions(+), 9 deletions(-)
net/bpf/test_run.c +3 -3
index b03c469cd01f..0d78bd9b6c9d 100644
@@ -117,32 +117,32 @@ static int bpf_test_finish(const union bpf_attr *kattr,
  __diag_push();
  __diag_ignore(GCC, 8, "-Wmissing-prototypes",
  	      "Global functions as their definitions will be in vmlinux BTF");
-int noinline bpf_fentry_test1(int a)
+static noinline int bpf_fentry_test1(int a)
  {
  	return a + 1;
  }
 
-int noinline bpf_fentry_test2(int a, u64 b)
+static noinline int bpf_fentry_test2(int a, u64 b)
  {
  	return a + b;
  }
 
-int noinline bpf_fentry_test3(char a, int b, u64 c)
+static noinline int bpf_fentry_test3(char a, int b, u64 c)
  {
  	return a + b + c;
  }
 

[...]