Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp968522ybt; Wed, 17 Jun 2020 19:24:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybqP5m8faB+OfNbXZxdKV1G/5hkwbSTGbNBIXcwlL2QIypBYSytXVTHiTkOU5inZsOxBHi X-Received: by 2002:a17:907:9495:: with SMTP id dm21mr1876235ejc.357.1592447053946; Wed, 17 Jun 2020 19:24:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592447053; cv=none; d=google.com; s=arc-20160816; b=TKP2vj8X8eJkoZQx2zyqVdMsBLROg1zDhD2gsXnVJ5bRrubjAyrZbXCs/1iGpp9bOm wUd78mIAclTKethTpTHLoTsfr9JgjG77DqjGspahZ5baKcNiCo7LplIuRHjebZJirWZI 2ffDSTUtltMYaVKv/Dymsuh+83JtdBO4CqXk0PwXlIpifx6hg7PAUQAexTZCkbNegbk2 sVbQGAu0NvC/TBuX+it9pP3PsiB25Vj+L0wMPeC0X2KyOFee4fBM0kADTnB/KHVG8wyq 6ZULXv2JTji49Oqxsh1rZMnLVuFNzZASkhhMhMiVWIxFxrLec9hDPqkme1ewceFFI1Dz Fxnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PB9ztYUJMqL++IywfaW0nqpumvo2XtBabU5rWMdQoMM=; b=Qk3MT2bgwlUSMf/qJiIL9nX7AJ1yIuMpSkg/7WpxasNmKY/0dU4fGtUAVny2GcpT/O GE0REsuqXzXcVpE5vq+gWCJmkirTJiE4rcJITKCFlgj2OG/OVaNy7ib6elFoEaQ5Us1x m/sqK8TGF0Uk1EJKXR1WhATkO4Bx+cOq+8h+rLTGUnYQpC+pZoKwmzif+SNsP35s4PLs kXDJnPMvalFtt6hDEf5MK1K6yesl9P1/692OGJW5Nh55jtbh+Ax7TlLnUPLYyTY+u2ZH 82eJngd3/yGPr3utiRG61njJywyWvP7WHKYunppryYeTGGM0+6zP9Z9eEwGX4IdxGAho BqSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PU81N6T0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 21si977358edv.510.2020.06.17.19.23.51; Wed, 17 Jun 2020 19:24:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PU81N6T0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730077AbgFRBTH (ORCPT + 99 others); Wed, 17 Jun 2020 21:19:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:46568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729157AbgFRBQH (ORCPT ); Wed, 17 Jun 2020 21:16:07 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B45F72088E; Thu, 18 Jun 2020 01:16:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592442966; bh=WDQHmXC96rpYPjUTKUtm1BoCjSJ3P3r3dBXWh66rDzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PU81N6T0LuJK33UTkmdzDdU0E6rC75SfzmFf1T+1m9QVTkR0R7LrnPq7TklGkaQw/ lBpC7iy4NqxBjE+mDcBoTScPVpamZsh/PAG50StGQb5tzsISU7X7gWmZV6DPR+ptGf IO/Y5HxQOxC1HhIUJDMIIrQAUwSslPPLJoFc1chs= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Andrii Nakryiko , Jean-Philippe Brucker , Daniel Borkmann , Sasha Levin , netdev@vger.kernel.org, bpf@vger.kernel.org, clang-built-linux@googlegroups.com Subject: [PATCH AUTOSEL 5.7 371/388] libbpf: Handle GCC noreturn-turned-volatile quirk Date: Wed, 17 Jun 2020 21:07:48 -0400 Message-Id: <20200618010805.600873-371-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200618010805.600873-1-sashal@kernel.org> References: <20200618010805.600873-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrii Nakryiko [ Upstream commit 32022fd97ed34f6812802bf1288db27c313576f4 ] Handle a GCC quirk of emitting extra volatile modifier in DWARF (and subsequently preserved in BTF by pahole) for function pointers marked as __attribute__((noreturn)). This was the way to mark such functions before GCC 2.5 added noreturn attribute. Drop such func_proto modifiers, similarly to how it's done for array (also to handle GCC quirk/bug). Such volatile attribute is emitted by GCC only, so existing selftests can't express such test. Simple repro is like this (compiled with GCC + BTF generated by pahole): struct my_struct { void __attribute__((noreturn)) (*fn)(int); }; struct my_struct a; Without this fix, output will be: struct my_struct { voidvolatile (*fn)(int); }; With the fix: struct my_struct { void (*fn)(int); }; Fixes: 351131b51c7a ("libbpf: add btf_dump API for BTF-to-C conversion") Reported-by: Jean-Philippe Brucker Signed-off-by: Andrii Nakryiko Signed-off-by: Daniel Borkmann Tested-by: Jean-Philippe Brucker Link: https://lore.kernel.org/bpf/20200610052335.2862559-1-andriin@fb.com Signed-off-by: Sasha Levin --- tools/lib/bpf/btf_dump.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c index 0c28ee82834b..653dbbe2e366 100644 --- a/tools/lib/bpf/btf_dump.c +++ b/tools/lib/bpf/btf_dump.c @@ -1137,6 +1137,20 @@ static void btf_dump_emit_mods(struct btf_dump *d, struct id_stack *decl_stack) } } +static void btf_dump_drop_mods(struct btf_dump *d, struct id_stack *decl_stack) +{ + const struct btf_type *t; + __u32 id; + + while (decl_stack->cnt) { + id = decl_stack->ids[decl_stack->cnt - 1]; + t = btf__type_by_id(d->btf, id); + if (!btf_is_mod(t)) + return; + decl_stack->cnt--; + } +} + static void btf_dump_emit_name(const struct btf_dump *d, const char *name, bool last_was_ptr) { @@ -1235,14 +1249,7 @@ static void btf_dump_emit_type_chain(struct btf_dump *d, * a const/volatile modifier for array, so we are * going to silently skip them here. */ - while (decls->cnt) { - next_id = decls->ids[decls->cnt - 1]; - next_t = btf__type_by_id(d->btf, next_id); - if (btf_is_mod(next_t)) - decls->cnt--; - else - break; - } + btf_dump_drop_mods(d, decls); if (decls->cnt == 0) { btf_dump_emit_name(d, fname, last_was_ptr); @@ -1270,7 +1277,15 @@ static void btf_dump_emit_type_chain(struct btf_dump *d, __u16 vlen = btf_vlen(t); int i; - btf_dump_emit_mods(d, decls); + /* + * GCC emits extra volatile qualifier for + * __attribute__((noreturn)) function pointers. Clang + * doesn't do it. It's a GCC quirk for backwards + * compatibility with code written for GCC <2.5. So, + * similarly to extra qualifiers for array, just drop + * them, instead of handling them. + */ + btf_dump_drop_mods(d, decls); if (decls->cnt) { btf_dump_printf(d, " ("); btf_dump_emit_type_chain(d, decls, fname, lvl); -- 2.25.1