dwarves.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH dwarves] btf_encoder: fix and complete filtering out zero-sized per-CPU variables
@ 2021-05-24 23:42 Andrii Nakryiko
  2021-05-25 19:58 ` Arnaldo Carvalho de Melo
  2021-05-27 14:55 ` Arnaldo Carvalho de Melo
  0 siblings, 2 replies; 10+ messages in thread
From: Andrii Nakryiko @ 2021-05-24 23:42 UTC (permalink / raw)
  To: dwarves, acme, bpf, jolsa; +Cc: andrii, kernel-team

btf_encoder is ignoring zero-sized per-CPU ELF symbols, but the same has to be
done for DWARF variables when matching them with ELF symbols. This is due to
zero-sized DWARF variables matching unrelated (non-zero-sized) variable that
happens to be allocated at the exact same address, leading to a lot of
confusion in BTF.

See [0] for when this causes big problems.

  [0] https://lore.kernel.org/bpf/CAEf4BzZ0-sihSL-UAm21JcaCCY92CqfNxycHRZYXcoj8OYb=wA@mail.gmail.com/

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 btf_encoder.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/btf_encoder.c b/btf_encoder.c
index c711f124b31e..672b9943a4e2 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -538,6 +538,7 @@ int cu__encode_btf(struct cu *cu, int verbose, bool force,
 	cu__for_each_variable(cu, core_id, pos) {
 		uint32_t size, type, linkage;
 		const char *name, *dwarf_name;
+		const struct tag *tag;
 		uint64_t addr;
 		int id;
 
@@ -550,6 +551,7 @@ int cu__encode_btf(struct cu *cu, int verbose, bool force,
 
 		/* addr has to be recorded before we follow spec */
 		addr = var->ip.addr;
+		dwarf_name = variable__name(var, cu);
 
 		/* DWARF takes into account .data..percpu section offset
 		 * within its segment, which for vmlinux is 0, but for kernel
@@ -582,11 +584,9 @@ int cu__encode_btf(struct cu *cu, int verbose, bool force,
 		 *  modules per-CPU data section has non-zero offset so all
 		 *  per-CPU symbols have non-zero values.
 		 */
-		if (var->ip.addr == 0) {
-			dwarf_name = variable__name(var, cu);
+		if (var->ip.addr == 0)
 			if (!dwarf_name || strcmp(dwarf_name, name))
 				continue;
-		}
 
 		if (var->spec)
 			var = var->spec;
@@ -600,6 +600,13 @@ int cu__encode_btf(struct cu *cu, int verbose, bool force,
 			break;
 		}
 
+		tag = cu__type(cu, var->ip.tag.type);
+		if (tag__size(tag, cu) == 0) {
+			if (btf_elf__verbose)
+				fprintf(stderr, "Ignoring zero-sized per-CPU variable '%s'...\n", dwarf_name ?: "<missing name>");
+			continue;
+		}
+
 		type = var->ip.tag.type + type_id_off;
 		linkage = var->external ? BTF_VAR_GLOBAL_ALLOCATED : BTF_VAR_STATIC;
 
-- 
2.30.2


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

end of thread, other threads:[~2021-05-28  6:24 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-24 23:42 [PATCH dwarves] btf_encoder: fix and complete filtering out zero-sized per-CPU variables Andrii Nakryiko
2021-05-25 19:58 ` Arnaldo Carvalho de Melo
2021-05-27 14:55 ` Arnaldo Carvalho de Melo
2021-05-27 14:58   ` Arnaldo Carvalho de Melo
2021-05-27 15:27     ` Michal Suchánek
2021-05-27 15:38       ` Arnaldo Carvalho de Melo
2021-05-27 16:47         ` Arnaldo Carvalho de Melo
2021-05-28  6:24           ` Michal Suchánek
2021-05-27 16:45       ` Andrii Nakryiko
2021-05-27 16:43   ` Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).