tools/resolve_btfids: Warn when having multiple IDs for single type
Subsystems (3)
Jiri Olsa
reviewerPATCH 1/1 tools/resolve_btfids: Warn when having multiple IDs for single type
The kernel image can contain multiple types (structs/unions) with the same name. This causes distinct type hierarchies in BTF data and makes resolve_btfids fail with error like:
BTFIDS vmlinux
FAILED unresolved symbol udp6_sock
as reported by Qais Yousef [1].
This change adds warning when multiple types of the same name are detected:
BTFIDS vmlinux
WARN: multiple IDs found for 'file' (526, 113351)
WARN: multiple IDs found for 'sk_buff' (2744, 113958)
We keep the lower ID for the given type instance and let the build continue.
[1] https://lore.kernel.org/lkml/20201229151352.6hzmjvu3qh6p2qgg@e107158-lin/
--- tools/bpf/resolve_btfids/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
tools/bpf/resolve_btfids/main.c +9 -2
@@ -139,6 +139,8 @@ int eprintf(int level, int var, const char *fmt, ...)#define pr_debug2 (fmt, ...) pr_debugN(2, pr_fmt(fmt), ##__VA_ARGS__)#define pr_err (fmt, ...) \ eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__) +#define pr_info (fmt, ...) \ + eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__)static bool is_btf_id (const char *name) {
@@ -526,8 +528,13 @@ static int symbols_resolve(struct object *obj) id =btf_id__find (root, str);if (id) { - id->id = type_id; - (*nr)--; +if (id->id) { +pr_info ("WARN: multiple IDs found for '%s' (%d, %d)\n" , + str, id->id, type_id); + }else { + id->id = type_id; + (*nr)--; + } } }
Signature · 1 line
2.26.2
Quoted 13 lines · Jiri Olsa
The kernel image can contain multiple types (structs/unions) with the same name. This causes distinct type hierarchies in BTF data and makes
resolve_btfidsfail with error like:BTFIDS vmlinux
FAILED unresolved symboludp6_sockas reported by Qais Yousef [1].
This change adds warning when multiple types of the same name are detected:
Quoted 6 lines
BTFIDS vmlinux
WARN: multiple IDs found for 'file' (526, 113351)
WARN: multiple IDs found for 'sk_buff' (2744, 113958)We keep the lower ID for the given type instance and let the build continue.
I think it would make sense to mention this decision in the warning. 'WARN: multiple IDs' is ambiguous and confusing when action is not specified.
Quoted 18 lines · Alexei Starovoitov
Quoted 17 lines · Jiri Olsa
The kernel image can contain multiple types (structs/unions) with the same name. This causes distinct type hierarchies in BTF data and makes
resolve_btfidsfail with error like:BTFIDS vmlinux
FAILED unresolved symboludp6_sockas reported by Qais Yousef [1].
This change adds warning when multiple types of the same name are detected:
BTFIDS vmlinux
WARN: multiple IDs found for 'file' (526, 113351)
WARN: multiple IDs found for 'sk_buff' (2744, 113958)
Quoted 5 lines
Quoted 2 lines
We keep the lower ID for the given type instance and let the build continue.
I think it would make sense to mention this decision in the warning. 'WARN: multiple IDs' is ambiguous and confusing when action is not specified.
ok, how about:
WARN: multiple IDs found for 'file': 526, 113351 - using 526
jirka
Quoted 23 lines · Jiri Olsa
Quoted 21 lines · Alexei Starovoitov
Quoted 19 lines · Jiri Olsa
The kernel image can contain multiple types (structs/unions) with the same name. This causes distinct type hierarchies in BTF data and makes
resolve_btfidsfail with error like:BTFIDS vmlinux
FAILED unresolved symboludp6_sockas reported by Qais Yousef [1].
This change adds warning when multiple types of the same name are detected:
BTFIDS vmlinux
WARN: multiple IDs found for 'file' (526, 113351)
WARN: multiple IDs found for 'sk_buff' (2744, 113958)We keep the lower ID for the given type instance and let the build continue.
Quoted 6 lines
Quoted 2 lines
I think it would make sense to mention this decision in the warning. 'WARN: multiple IDs' is ambiguous and confusing when action is not specified.
ok, how about:
WARN: multiple IDs found for 'file': 526, 113351 - using 526
yep. much better imo.
Please add a comment to .c file with the suggestion that such types should be renamed to avoid ambiguity.
Adding 'please rename' to WARN is probably overkill.
Quoted 17 lines · Jiri Olsa
The kernel image can contain multiple types (structs/unions) with the same name. This causes distinct type hierarchies in BTF data and makes
resolve_btfidsfail with error like:BTFIDS vmlinux
FAILED unresolved symboludp6_sockas reported by Qais Yousef [1].
This change adds warning when multiple types of the same name are detected:
BTFIDS vmlinux
WARN: multiple IDs found for 'file' (526, 113351)
WARN: multiple IDs found for 'sk_buff' (2744, 113958)
Quoted 7 lines
We keep the lower ID for the given type instance and let the build continue.
[1] https://lore.kernel.org/lkml/20201229151352.6hzmjvu3qh6p2qgg@e107158-lin/
Reported-by Qais Yousef <[email protected]>Signed-off-by Jiri Olsa <[email protected]>---
see comments below, but otherwise lgtm
tools/bpf/resolve_btfids/main.c int eprintf(int level, int var, const char *fmt, ...) · line 143
Quoted 13 lines
tools/bpf/resolve_btfids/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)tools/bpf/resolve_btfids/main.c +2
-0@@ -139,6 +139,8 @@ int eprintf(int level, int var, const char *fmt, ...)#define pr_debug2 (fmt, ...) pr_debugN(2, pr_fmt(fmt), ##__VA_ARGS__)#define pr_err (fmt, ...) \ eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__) +#define pr_info (fmt, ...) \ + eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__)
how is it different from pr_err? Did you forget to update verboseness levels or it's intentional?
Quoted 5 lines
tools/bpf/resolve_btfids/main.c +0
-0static bool is_btf_id (const char *name) {@@ -526,8 +528,13 @@ static int symbols_resolve(struct object *obj)
tools/bpf/resolve_btfids/main.c static int symbols_resolve(struct object *obj) · line 536
Quoted 10 lines
tools/bpf/resolve_btfids/main.c +6
-2id =btf_id__find (root, str);if (id) { - id->id = type_id; - (*nr)--; +if (id->id) { +pr_info ("WARN: multiple IDs found for '%s' (%d, %d)\n" , + str, id->id, type_id); + }else { + id->id = type_id; + (*nr)--;
btw, there is a nasty shadowing of nr variable, which is used both for the for() loop condition (as int) and as int * inside the loop body. It's better to rename inner (or outer) nr, it's extremely confusing as is.
Quoted 7 lines
tools/bpf/resolve_btfids/main.c +1
-1+ } } } --2.26.2
Quoted 33 lines · Andrii Nakryiko
Quoted 17 lines · Jiri Olsa
The kernel image can contain multiple types (structs/unions) with the same name. This causes distinct type hierarchies in BTF data and makes
resolve_btfidsfail with error like:BTFIDS vmlinux
FAILED unresolved symboludp6_sockas reported by Qais Yousef [1].
This change adds warning when multiple types of the same name are detected:
BTFIDS vmlinux
WARN: multiple IDs found for 'file' (526, 113351)
WARN: multiple IDs found for 'sk_buff' (2744, 113958)Quoted 7 lines
We keep the lower ID for the given type instance and let the build continue.
[1] https://lore.kernel.org/lkml/20201229151352.6hzmjvu3qh6p2qgg@e107158-lin/
Reported-by Qais Yousef <[email protected]>Signed-off-by Jiri Olsa <[email protected]>---
see comments below, but otherwise lgtm
Acked-by Andrii Nakryiko <[email protected]>Quoted 3 lines
tools/bpf/resolve_btfids/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
Quoted 13 lines
tools/bpf/resolve_btfids/main.c int eprintf(int level, int var, const char *fmt, ...) · line 143
Quoted 10 lines
tools/bpf/resolve_btfids/main.c +2
-0@@ -139,6 +139,8 @@ int eprintf(int level, int var, const char *fmt, ...)#define pr_debug2 (fmt, ...) pr_debugN(2, pr_fmt(fmt), ##__VA_ARGS__)#define pr_err (fmt, ...) \ eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__) +#define pr_info (fmt, ...) \ + eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__)how is it different from
pr_err? Did you forget to update verboseness levels or it's intentional?
intentional, I'm using pr_err to print in error paths, so I wanted to add new one for other 'info' messages without -v
Quoted 6 lines
Quoted 6 lines
tools/bpf/resolve_btfids/main.c +0
-0static bool is_btf_id (const char *name) {@@ -526,8 +528,13 @@ static int symbols_resolve(struct object *obj)
Quoted 15 lines
tools/bpf/resolve_btfids/main.c static int symbols_resolve(struct object *obj) · line 536
Quoted 10 lines
tools/bpf/resolve_btfids/main.c +6
-2id =btf_id__find (root, str);if (id) { - id->id = type_id; - (*nr)--; +if (id->id) { +pr_info ("WARN: multiple IDs found for '%s' (%d, %d)\n" , + str, id->id, type_id); + }else { + id->id = type_id; + (*nr)--;btw, there is a nasty shadowing of nr variable, which is used both for the
for()loop condition (as int) and asint *inside the loop body. It's better to rename inner (or outer) nr, it's extremely confusing as is.
nice, I'll change that
thanks,
jirka
Quoted 9 lines
Quoted 8 lines
tools/bpf/resolve_btfids/main.c +1
-1+ } } } --2.26.2