From patchwork Sat Oct 1 10:44:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 12996488 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79202C433FE for ; Sat, 1 Oct 2022 10:45:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229547AbiJAKpI (ORCPT ); Sat, 1 Oct 2022 06:45:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229477AbiJAKpG (ORCPT ); Sat, 1 Oct 2022 06:45:06 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8FBB23BD5 for ; Sat, 1 Oct 2022 03:45:03 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id b2so13693275eja.6 for ; Sat, 01 Oct 2022 03:45:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=8BosUY18tElRYe26ebCRL2pHI22bw2J0kGndde6SkYk=; b=TIxxPtPCgVv/Fyeb2bhOqqTHB4Z/7Rd4tadtN3vixEDeq0xhq5K9fY/PeDIrVkWdmt fqXEhNKFQ2YYobOGhH3yxa+vJ37yN2fzAK1nbF4dskKDSQiGfCLMhD8mrTDNMU2qGMJu GQvL/RRx61TOvonY4cU7wqX9K0LT1Pz8NZG+/RgpJ8TSj86ohKIHX59NtVsOvROAPi0C SVCVznFON0AI72Sxf9jCAUQYZcEOhbzEoQgHp0TJGIyxZiYmBestpXSU6IzEKwu4hQxd iPYBJTFXHNgoAN4aceQ83F1tcepo2JhcbWxAUqyijt3BZU2GwfGq5gFtvzQqUKej4XAC efMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=8BosUY18tElRYe26ebCRL2pHI22bw2J0kGndde6SkYk=; b=Kb0IZHuPw7WpIOpPWRYCXsCkh4DepXzCp8/WZRyAwWCAAk+RlhWliJF4jFjMhR7ZPH +b1j0s6pudL4cZT5XG/dVOwozaqJVyCAlkii0HbNVtOAzmn97cvBEXqQJeu6IkaeU3lh to6CwHAgoMCa8bp4cpRd/9M1gQwgr4Naf681qlgV8BEiYtLRdpr9dd4RECtfM0cEGx3J wt8f2IqxQwum6QMontZyMbaOrG++vGzqi+sgzv7iC1Wpb4jKj1XUP5OaWNMw+U0umHuj kzkuTWcHVl7DnBOa4+2LSG6XZ9YXkVfcTJoLLJLBhK0I8hNgnmzRtVl+sCOo/efEQeui 1fDQ== X-Gm-Message-State: ACrzQf0GwL7CHXCmpJSnYqjiWFqaTp8MDvtS8CYCIvQxC+KG6tIhoOVr T6beyEFjmGC9un1jhQTO1bFxyuY2N1qOCSxJ X-Google-Smtp-Source: AMsMyM7RnDj1ZrahHIrTNxgjg84wt1EoaqOmhiMhZCjOuwrV7Cy/3zeaoSlaKBvUtURlh8PHgzUATw== X-Received: by 2002:a17:907:2c47:b0:787:6f95:2bfe with SMTP id hf7-20020a1709072c4700b007876f952bfemr9575210ejc.705.1664621101565; Sat, 01 Oct 2022 03:45:01 -0700 (PDT) Received: from badger.. (boundsly.muster.volia.net. [93.72.16.93]) by smtp.gmail.com with ESMTPSA id y8-20020a056402358800b0044dbecdcd29sm3415635edc.12.2022.10.01.03.45.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 03:45:01 -0700 (PDT) From: Eduard Zingerman To: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net, kernel-team@fb.com Cc: Eduard Zingerman Subject: [PATCH bpf-next v2 1/2] bpftool: Print newline before '}' for struct with padding only fields Date: Sat, 1 Oct 2022 13:44:24 +0300 Message-Id: <20221001104425.415768-1-eddyz87@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net btf_dump_emit_struct_def attempts to print empty structures at a single line, e.g. `struct empty {}`. However, it has to account for a case when there are no regular but some padding fields in the struct. In such case `vlen` would be zero, but size would be non-zero. E.g. here is struct bpf_timer from vmlinux.h before this patch: struct bpf_timer { long: 64; long: 64;}; And after this patch: struct bpf_dynptr { long: 64; long: 64; }; Signed-off-by: Eduard Zingerman --- tools/lib/bpf/btf_dump.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c index 4221f73a74d0..e4da6de68d8f 100644 --- a/tools/lib/bpf/btf_dump.c +++ b/tools/lib/bpf/btf_dump.c @@ -944,7 +944,11 @@ static void btf_dump_emit_struct_def(struct btf_dump *d, lvl + 1); } - if (vlen) + /* + * Keep `struct empty {}` on a single line, + * only print newline when there are regular or padding fields. + */ + if (vlen || t->size) btf_dump_printf(d, "\n"); btf_dump_printf(d, "%s}", pfx(lvl)); if (packed) From patchwork Sat Oct 1 10:44:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 12996489 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCAC1C433F5 for ; Sat, 1 Oct 2022 10:45:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229562AbiJAKpK (ORCPT ); Sat, 1 Oct 2022 06:45:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229511AbiJAKpH (ORCPT ); Sat, 1 Oct 2022 06:45:07 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6576C1EC7C for ; Sat, 1 Oct 2022 03:45:04 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id b2so13693329eja.6 for ; Sat, 01 Oct 2022 03:45:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=I0Kgwsm6MMz+s3g+ObWAwy803kmWiuaT8m3YfjMLBoQ=; b=SbM7OeVL/PVedugz++gsCeDZQ8Vfbo1BzM0wl9g7iYM3WBG0IFFo48s1EvEwCTv/Cz +9mrBz3aov1uR252JgUIQmfmyVEOSdbLlRPB+oM2dwwTrul9IBtp/K/+XNlpKSRDqcyo J87OvP5O4bilhivTSwD3fmlj0kJB7r3A3RUzJ0LP9dETbFiPeOSxr2gpGnkNiEaBv8fg O9e8/OSO6kD+Iacdu6wdknIspZLcI8CFzPt5hAM5/1oGVMrfJvBT+CwUSnAlLusF/So5 HXgsoDwqao8mEeHdM0Du6kguOOTG6oU1JwjbV0YNInEn1vqDxeHOGEqRW/nSCbnphcFZ 6wpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=I0Kgwsm6MMz+s3g+ObWAwy803kmWiuaT8m3YfjMLBoQ=; b=MX5s0oyKsTapQNiGvy3MmFVXFNDR6U5EVlPr7FjNbrMX04g074KTnaOqvNHw90XPU0 As6z7O2PjjsxvhIsA4HeKgN739PojhPdLxXHRh3eilbncDAm2rk/SMu62UeFrLDxNCMQ 39DqUxZMm67tM/ZBTsG0j6XvTe1jrSaDoJzkKoUiRfDcIA8tHZLJ0HacTAcgexk7qgzW Y4PBiFCD+cP6LRzrkH57XutzvEThncqn0BoIi7s27eJItF0/c0VfwjxOWhvjaOKzmugJ v+fCHnTV3Alr1gk/Pbu6GRLHQeAfqld7Lec4JTlhchGtih3tlfMK5G6LReZXbvdl7TSx m51w== X-Gm-Message-State: ACrzQf27Sedw1limzPaVskXwYtMmE811baIHJUkXhbW4H212mQMZbJ4S ULj3AXBg6QZ3UckqOS8VuEc00Tv5M5Fm0nJm X-Google-Smtp-Source: AMsMyM6Mle0jPKVAtcCEl5p+Fb6WD7LT95q+DgQ91tCn2HPZNyc0o3+QMQmgPCvPz5hzs0viIpwqFA== X-Received: by 2002:a17:907:2e01:b0:77f:92be:8181 with SMTP id ig1-20020a1709072e0100b0077f92be8181mr9461766ejc.229.1664621102702; Sat, 01 Oct 2022 03:45:02 -0700 (PDT) Received: from badger.. (boundsly.muster.volia.net. [93.72.16.93]) by smtp.gmail.com with ESMTPSA id y8-20020a056402358800b0044dbecdcd29sm3415635edc.12.2022.10.01.03.45.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 03:45:02 -0700 (PDT) From: Eduard Zingerman To: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net, kernel-team@fb.com Cc: Eduard Zingerman Subject: [PATCH bpf-next v2 2/2] selftests/bpf: Test btf dump for struct with padding only fields Date: Sat, 1 Oct 2022 13:44:25 +0300 Message-Id: <20221001104425.415768-2-eddyz87@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001104425.415768-1-eddyz87@gmail.com> References: <20221001104425.415768-1-eddyz87@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Structures with zero regular fields but some padding constitute a special case in btf_dump.c:btf_dump_emit_struct_def with regards to newline before closing '}'. Signed-off-by: Eduard Zingerman --- .../selftests/bpf/progs/btf_dump_test_case_padding.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c b/tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c index f2661c8d2d90..7cb522d22a66 100644 --- a/tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c +++ b/tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c @@ -102,12 +102,21 @@ struct zone { struct zone_padding __pad__; }; +/* ----- START-EXPECTED-OUTPUT ----- */ +struct padding_wo_named_members { + long: 64; + long: 64; +}; + +/* ------ END-EXPECTED-OUTPUT ------ */ + int f(struct { struct padded_implicitly _1; struct padded_explicitly _2; struct padded_a_lot _3; struct padded_cache_line _4; struct zone _5; + struct padding_wo_named_members _6; } *_) { return 0;