From patchwork Wed Dec 11 02:12:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 13902753 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7AFC1AAA00; Wed, 11 Dec 2024 02:12:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733883174; cv=none; b=ZGMFHYdzQlyzP1oRQznWSDnD2SMYi3NlYeAGF/xQGowbkwjtkk1E1bXeqRIR8Vdr8EvKbuojT0Wxk2zNob85U+55sEtKr99qJTcOq48VPhxKQ2T8bTtryq2BPhNxg9PPb+d5VbtNw/yCjLPYNw2X99eip8OxsImPobq0kXqCODs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733883174; c=relaxed/simple; bh=NjRaaAO6uex0kdaiIQaOYi7H2xOTaN60xPEIg5ToN0M=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bheJspGrOxQXuuKVpjT9X5widkSIxgRt6WsTKz8nZlZjPSgs/NWR4+m5fpkItfdg1aac5ReZ8mTztwzAuG3l96eAn/eCEd3eQKJ8gjYwqYiiLXPauSU5ZRYizT1d1ezolU8UYsgb3q8q1i434hTHxS/Sp0PXIcJZtMkm3ZORAvs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mU9HZtY4; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mU9HZtY4" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-216634dd574so17169925ad.2; Tue, 10 Dec 2024 18:12:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733883172; x=1734487972; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8aNATulEVG1VuSXf5yPINwpgfqOcEXSA+A1XLcEmzZk=; b=mU9HZtY4uVEockpeBOyBvibMyMyHHiTQ8Wylqo30R8uO+UimeKcE/pnasRRXmjSHnR MkxyNJPYU7TPfvahJ/heIfdOX9upEi5m1FWhAl37R1N0sbJe4J7C7YUEJUV5MXXlpGFq y1b82YLSwwXQ5DO2L2lzbUtT1NrqoESHfbYEiMQTptx2Ygb0V7TC86V+j4IeH4DytdL5 R+8dvVlNOvBYSJocjt9bP1Dk2K5liitBot7ztYVnQJFhwAvhy8x+vJ73xyE8Bb7LYz0f ibMFdBvTERmgYJmEuei4EmWhLY0HF9bPHFSTez9Io1wzf5RqWLdLmQAbWOKRQHyeej37 8x2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733883172; x=1734487972; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8aNATulEVG1VuSXf5yPINwpgfqOcEXSA+A1XLcEmzZk=; b=U9u3XO9Jr4pT3ixjWWdRdQKGi8duMk1XVpjyF192mm8XG9lvE1IOhf85j1iXA2b4cL nabg4heWVILlkSWT1dJNqZlX3RamSvcSaJzkQkhVVizFhPQVc3P6quIINP4odihjVCk0 GGxK88IA7IYMILswQDvB5p0K2ARfgxYj33r/waob8I/+zkyePRA8vvYpvbBJme1wMaej D33ZgRLret89iQKajwhJ6n/TNkYBAuq/hAwEsx68YmIpptCIC2kml7bCaAx3CcAjldvn eB9tiPdSoKoZxsfbq/tzF/21HQ2UQKVqCV1nZERdiRSTMfUP8Py8sYP8OgCn5Bm382p4 W1Bw== X-Gm-Message-State: AOJu0YyqPD5tkC9+BQiW9H6bI+5cLwQILK7Zv2rgh6qN0V3YpzQVbpxN ArrJr9WLGrNA/tYa2Lm0pxS4V3sw7O9WVxZMVNLvbt3d/5IU4vKvNx8fIA== X-Gm-Gg: ASbGncuAGTd+ph8cAHeUat/zuwPrDCQLdyJfXqhpK+79Ccuw4M4I6FLV/XLNTv+r68U prQPpZZXiJGPY+tTMTO98n0D6Y8zYMSQQ16tqKjnT8pYYPSarrGL6TXvXHWN5WFIrCHLpusB8EL lMyk20eX8zdLyszbjILwDSqSIhO9ceoexgBUdz05bcIbUaiCrQ3cx6Dy1lhyU6cdSPERb3vlFTF PAOA7Ojg8yRx9ywzaxzgZeJZK7Y5a7KSdvPx202nfuOtcC+8Q== X-Google-Smtp-Source: AGHT+IGyDdrKTSIntUAePjiyO1cqihLCOUbzoRyivebYrB3swvGtGur8GUriovXy9zEkaWJheaLelA== X-Received: by 2002:a17:902:ce86:b0:215:7cde:7fa3 with SMTP id d9443c01a7336-21778509fa3mr20710385ad.25.1733883171655; Tue, 10 Dec 2024 18:12:51 -0800 (PST) Received: from honey-badger.. ([38.34.87.7]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-215f8e3e5f2sm96573975ad.13.2024.12.10.18.12.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 18:12:51 -0800 (PST) From: Eduard Zingerman To: dwarves@vger.kernel.org, arnaldo.melo@gmail.com, alan.maguire@oracle.com Cc: bpf@vger.kernel.org, kernel-team@fb.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, yonghong.song@linux.dev, Eduard Zingerman , Arnaldo Carvalho de Melo Subject: [PATCH dwarves v1 1/2] btf_loader: support for multiple BTF_DECL_TAGs pointing to same tag Date: Tue, 10 Dec 2024 18:12:26 -0800 Message-ID: <20241211021227.2341735-1-eddyz87@gmail.com> X-Mailer: git-send-email 2.47.0 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 btf_loader issues a warning when it sees several BTF_DECL_TAGs pointing to the same type. Such situation is possible in practice after patch [0], that marks certain functions with kfunc and bpf_fastcall tags. E.g.: $ pfunct vmlinux -F btf -f bpf_rdonly_cast WARNING: still unsuported BTF_KIND_DECL_TAG(bpf_fastcall) for bpf_cast_to_kern_ctx already with attribute (bpf_kfunc), ignoring WARNING: still unsuported BTF_KIND_DECL_TAG(bpf_fastcall) for bpf_rdonly_cast already with attribute (bpf_kfunc), ignoring bpf_kfunc void * bpf_rdonly_cast(const void * obj__ign, u32 btf_id__k); This commit extends 'struct tag' to allow attaching multiple attributes. Define 'struct attributes' as follows: struct attributes { uint64_t cnt; const char *values[]; }; In order to avoid adding counter field in 'struct tag', as not many instances of 'struct tag' would have attributes. Same command after this patch: $ pfunct vmlinux -F btf -f bpf_rdonly_cast bpf_kfunc bpf_fastcall void * bpf_rdonly_cast(const void * obj__ign, u32 btf_id__k); [0] https://lore.kernel.org/dwarves/094b626d44e817240ae8e44b6f7933b13c26d879.camel@gmail.com/T/#m8a6cb49a99d1b2ba38d616495a540ae8fc5f3a76 Reported-by: Arnaldo Carvalho de Melo Closes: https://lore.kernel.org/dwarves/Z1dFXVFYmQ-nHSVO@x1/ Signed-off-by: Eduard Zingerman Reviewed-by: Alan Maguire Tested-by: Alan Maguire --- btf_loader.c | 31 +++++++++++++++++++++++-------- dwarf_loader.c | 2 +- dwarves.c | 3 +++ dwarves.h | 8 +++++++- dwarves_fprintf.c | 6 ++++-- tests/btf_functions.sh | 2 +- 6 files changed, 39 insertions(+), 13 deletions(-) diff --git a/btf_loader.c b/btf_loader.c index 4814f29..af9e1db 100644 --- a/btf_loader.c +++ b/btf_loader.c @@ -459,9 +459,28 @@ static int create_new_tag(struct cu *cu, int type, const struct btf_type *tp, ui return 0; } +static struct attributes *attributes__realloc(struct attributes *attributes, const char *value) +{ + struct attributes *result; + uint64_t cnt; + size_t sz; + + cnt = attributes ? attributes->cnt : 0; + sz = sizeof(*attributes) + (cnt + 1) * sizeof(*attributes->values); + result = realloc(attributes, sz); + if (!result) + return NULL; + if (!attributes) + result->cnt = 0; + result->values[cnt] = value; + result->cnt++; + return result; +} + static int process_decl_tag(struct cu *cu, const struct btf_type *tp) { struct tag *tag = cu__type(cu, tp->type); + struct attributes *tmp; if (tag == NULL) tag = cu__function(cu, tp->type); @@ -475,15 +494,11 @@ static int process_decl_tag(struct cu *cu, const struct btf_type *tp) } const char *attribute = cu__btf_str(cu, tp->name_off); + tmp = attributes__realloc(tag->attributes, attribute); + if (!tmp) + return -ENOMEM; - if (tag->attribute != NULL) { - char bf[128]; - - fprintf(stderr, "WARNING: still unsuported BTF_KIND_DECL_TAG(%s) for %s already with attribute (%s), ignoring\n", - attribute, tag__name(tag, cu, bf, sizeof(bf), NULL), tag->attribute); - } else { - tag->attribute = attribute; - } + tag->attributes = tmp; return 0; } diff --git a/dwarf_loader.c b/dwarf_loader.c index 598fde4..34376b2 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -513,7 +513,7 @@ static void tag__init(struct tag *tag, struct cu *cu, Dwarf_Die *die) dwarf_tag__set_attr_type(dtag, abstract_origin, die, DW_AT_abstract_origin); tag->recursivity_level = 0; - tag->attribute = NULL; + tag->attributes = NULL; if (cu->extra_dbg_info) { pthread_mutex_lock(&libdw__lock); diff --git a/dwarves.c b/dwarves.c index ae512b9..f970dd2 100644 --- a/dwarves.c +++ b/dwarves.c @@ -210,6 +210,9 @@ void tag__delete(struct tag *tag, struct cu *cu) assert(list_empty(&tag->node)); + if (tag->attributes) + free(tag->attributes); + switch (tag->tag) { case DW_TAG_union_type: type__delete(tag__type(tag), cu); break; diff --git a/dwarves.h b/dwarves.h index 1cb0d62..0a4d5a2 100644 --- a/dwarves.h +++ b/dwarves.h @@ -516,10 +516,16 @@ int cu__for_all_tags(struct cu *cu, struct cu *cu, void *cookie), void *cookie); +struct attributes { + uint64_t cnt; + const char *values[]; +}; + /** struct tag - basic representation of a debug info element * @priv - extra data, for instance, DWARF offset, id, decl_{file,line} * @top_level - * @shared_tags: used by struct namespace + * @attributes - attributes specified by BTF_DECL_TAGs targeting this tag */ struct tag { struct list_head node; @@ -530,7 +536,7 @@ struct tag { bool has_btf_type_tag:1; bool shared_tags:1; uint8_t recursivity_level; - const char *attribute; + struct attributes *attributes; }; // To use with things like type->type_enum == perf_event_type+perf_user_event_type diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c index e16a6b4..c3e7f3c 100644 --- a/dwarves_fprintf.c +++ b/dwarves_fprintf.c @@ -1405,9 +1405,11 @@ static size_t function__fprintf(const struct tag *tag, const struct cu *cu, struct ftype *ftype = func->btf ? tag__ftype(cu__type(cu, func->proto.tag.type)) : &func->proto; size_t printed = 0; bool inlined = !conf->strip_inline && function__declared_inline(func); + int i; - if (tag->attribute) - printed += fprintf(fp, "%s ", tag->attribute); + if (tag->attributes) + for (i = 0; i < tag->attributes->cnt; ++i) + printed += fprintf(fp, "%s ", tag->attributes->values[i]); if (func->virtuality == DW_VIRTUALITY_virtual || func->virtuality == DW_VIRTUALITY_pure_virtual) diff --git a/tests/btf_functions.sh b/tests/btf_functions.sh index 61f8a00..c92e5ae 100755 --- a/tests/btf_functions.sh +++ b/tests/btf_functions.sh @@ -66,7 +66,7 @@ pfunct --all --no_parm_names --format_path=dwarf $vmlinux | \ sort|uniq > $outdir/dwarf.funcs # all functions from BTF (removing bpf_kfunc prefix where found) pfunct --all --no_parm_names --format_path=btf $outdir/vmlinux.btf 2>/dev/null|\ - awk '{ gsub("^bpf_kfunc ",""); print $0}'|sort|uniq > $outdir/btf.funcs + awk '{ gsub("^(bpf_kfunc |bpf_fastcall )+",""); print $0}'|sort|uniq > $outdir/btf.funcs exact=0 inline=0 From patchwork Wed Dec 11 02:12:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 13902754 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0D991ACEC2; Wed, 11 Dec 2024 02:12:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733883175; cv=none; b=Ev1t9FRJKnpeJDDCEplfQ/zD8yHZvN23JYQtfFJctwIG7Zp3omv5oaIWVGlpPWQfKuXKkAMOijUi6KZF/oEwpqNxEvxVeW7F9CZlP8LaLHtHTuBjPpQ+dvOGH2WyOzACPe9s+6MGvbEoMWrRv3dIPtxzWik++8vp+7hxdUUEEMw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733883175; c=relaxed/simple; bh=yv09W4fl+bfMtHO8UCf/vs+fWaeVEc9nQwKGo+Z7+rs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TIopgXEHoXggTuR151msk/XakBLo021cY5dPSAJClERKVYaJ23OC30KLrA9FJI/xWKVLHU6HBFk90KiUq4061QOyhX3k3QsXyDLjTp/QgZPr6kNiVA4DtPufeKGu8nhwsChD8gyTnIsFhPuZbsDebK1v12Fk0fAzqGWCUoE9hww= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Bn2IcS2R; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bn2IcS2R" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2162c0f6a39so2027645ad.0; Tue, 10 Dec 2024 18:12:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733883173; x=1734487973; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5ENr+oTUFVNcUM072Bx4z+rQtyQML1ZHCxeXHzKI2FE=; b=Bn2IcS2RDvpeD7BEMYcZiHRt/PubLix30wIfCbaHX6ZspmZwR8Ria/nifGEscUUGyj 2QXfFLpnmZFrolQpXsHX5qczT0WQPMruPqaPIRanEpEw4vT3zL/jPNH+phjXiff1VjHn /wxHrRedm40rMZFrmS1mGYb0mYDVRRhRquNz2kZ39ZdiQtSM/una8M0kcSVnzq5IBae/ vnhD5pp7jV93H83HQ3cSSYHOd2sEOL19BRiMjnxd1wl+iq5/IIySjGilwUS10J5BPWUl opz70At6VTX0PGbJ4vLv7tRCYH14xKlG2kjacQwkqFaI9+lr4ImXjIWkH89PTWsaM5Wh 3JaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733883173; x=1734487973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5ENr+oTUFVNcUM072Bx4z+rQtyQML1ZHCxeXHzKI2FE=; b=pZoClIBCKbbl8/OscL61GOjsMVK50pqAtqzYsv+JWhhGXfVL9p4is4fHbMI3C69o4o tUcMH81eLBQYUqS2bl7RDtjvF9tejHyipGf+3AgzWmnVHzSIt17zZMcqb0bc9ACxGBfU Il+/rfIBmBm5Jmnh9LWmhwGNItri4PJVGAUSFhKs2fdusQS+onuVEuhJmG2IfhNxDBNV u7imHPCRditryVbjavQT+0CzAL0eJWhxliGuldApEXarylR2AcUtxvV6jzMyYxL8T7tK 0qnwsLOAYkFNkjZLXInuW/00iqg6X/6ufegF01iVuAEp6kely0yIcRIyOaRPJaaMhFz1 cI9A== X-Gm-Message-State: AOJu0YzYqjLDA/ww1Otp3118QkAu6N7i9gQVjGLAWJ2ROwqMky7lVR2j GAI0HGQ+rJcwINFXtKAQrzewuUHCY7LDlT/gtvL70K3NMD7lfGX49A+CLw== X-Gm-Gg: ASbGncsfdKaoNNdpJaAgubIxfEifLMIHnuspoG+r+Tk90rSap+MDIqEZ+LKewJ+kFCG CRJ2mFTjYLJKXz0Q8dpImkJQlSLqHpgxKYU2BdSpPFpTeHQ4b8DYVwZiNgwDsI++KULXh0ctgZX 2EklTOvwyjtEItIMinpfkVDMZrr1LUldDKuH6K+tlhyrnImXbqX453/5+9yFSgoABim53uGlpXg sJQ1NGxniPR3lYg4FAP02MqGBELy0ZmA1dsbaxYCCTDSeAkFA== X-Google-Smtp-Source: AGHT+IGcSUew2Dn7Zg3ipvwLjKZJC7Lz7Ztxse4QgovWNLxPlL5Aayh37ibDK/HtRSGp/Pe8AL4qQg== X-Received: by 2002:a17:902:ea08:b0:215:7287:67bb with SMTP id d9443c01a7336-21779d60d08mr14230605ad.0.1733883172682; Tue, 10 Dec 2024 18:12:52 -0800 (PST) Received: from honey-badger.. ([38.34.87.7]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-215f8e3e5f2sm96573975ad.13.2024.12.10.18.12.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 18:12:52 -0800 (PST) From: Eduard Zingerman To: dwarves@vger.kernel.org, arnaldo.melo@gmail.com, alan.maguire@oracle.com Cc: bpf@vger.kernel.org, kernel-team@fb.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, yonghong.song@linux.dev, Eduard Zingerman Subject: [PATCH dwarves v1 2/2] tests: verify that pfunct prints btf_decl_tags read from BTF Date: Tue, 10 Dec 2024 18:12:27 -0800 Message-ID: <20241211021227.2341735-2-eddyz87@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241211021227.2341735-1-eddyz87@gmail.com> References: <20241211021227.2341735-1-eddyz87@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When using BTF as a source, pfunct should now be able to print btf_decl_tags for programs like below: #define __tag(x) __attribute__((btf_decl_tag(#x))) __tag(a) __tag(b) void foo(void) {} This situation arises after recent kernel changes, where tags 'kfunc' and 'bpf_fastcall' are added to some functions. To avoid dependency on a recent kernel version test this by compiling a small C program using clang with --target=bpf, which would instruct clang to generate .BTF section. Signed-off-by: Eduard Zingerman Reviewed-by: Alan Maguire Tested-by: Alan Maguire --- tests/pfunct-btf-decl-tags.sh | 65 +++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 tests/pfunct-btf-decl-tags.sh diff --git a/tests/pfunct-btf-decl-tags.sh b/tests/pfunct-btf-decl-tags.sh new file mode 100755 index 0000000..7e7f547 --- /dev/null +++ b/tests/pfunct-btf-decl-tags.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only + +# Check that pfunct can print btf_decl_tags read from BTF + +tmpobj=$(mktemp /tmp/pfunct-btf-decl-tags.sh.XXXXXX.o) + +cleanup() +{ + rm $tmpobj +} + +trap cleanup EXIT + +CLANG=${CLANG:-clang} +if ! command -v $CLANG > /dev/null; then + echo "Need clang for test $0" + exit 1 +fi + +(cat <