From patchwork Thu Apr 8 18:46:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 417475 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp894919jai; Thu, 8 Apr 2021 11:46:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnH7YerZfMuQO1zJD30uC1RI4Wsk08QkI+A0cEvIBpnNj/gEDnrew2S4XvfQRnlql6WkKM X-Received: by 2002:a63:f008:: with SMTP id k8mr9315206pgh.15.1617907600737; Thu, 08 Apr 2021 11:46:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617907600; cv=none; d=google.com; s=arc-20160816; b=O/HSzMpdynqbOzYrvepuxbRCwrXtawzJqTd0MVBhB3M3J9G0eTOL0mEELdO8ny2CEM zR7fO0rl05eb7hwu+zv+FXJVHJ/gLq5Zq1WqZWKYbQKvJcMDj4ndjJrPUQXn3BSUZF4O 4Cm7Iqa1qpc9YTbUwiS8AjJS60aC/97t6UW8t7Nh5amNCRNK9ZXjQTwLfCGgyAWhoZVq T6+RF9ZeXquTZDQm5/hKMRXaOMqDl+6JkmcW326ldtDuSnDDWtteZwh4dC49PGzTaZ0O ilL5k6DK8p+fTAk3zXPbgtOOioJjkvKf5JjjbCfwQWHkJYDx+iLRy4dAgafygFH6r1Kz +7Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=6gAnMk/3QmoHKKKOynZbE6ARTru22AXVPx9J9ennqYk=; b=taMg6MbI0wnbhTIPHut5gZwfbusGxTUykrIDZYIBXqc9Mi0lPoBgZ1JNyUPatWOSIR gy9BckUSOWNGIk0TFzlFz9wlfesTraC2Gn7mpYXpJnKCxcjz7mKnarNJQKFy8nyNfz7f 7lBJC4h9Oz96rIDWLwQZ8XRQWsswkMistiSwb+o8jI0KI6VmZbJjuxGqUS2yysPULbHZ FTQV00GTc9arm4wGnffzIg2te2/Ev40LyRTqPpJditMesbzUXbXjEBLmaAwOrhvr0egc b+w4v8N2z6wmDF2Pj3HgVMHB1L8Q7THS4KZMe931QbeoJPi1F/PciXJjs3xZ9VGYkzF/ Bglg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CsxGIoVi; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e24si54842pgv.298.2021.04.08.11.46.40; Thu, 08 Apr 2021 11:46:40 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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=@google.com header.s=20161025 header.b=CsxGIoVi; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232790AbhDHSqv (ORCPT + 12 others); Thu, 8 Apr 2021 14:46:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232775AbhDHSqu (ORCPT ); Thu, 8 Apr 2021 14:46:50 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BB2AC061761 for ; Thu, 8 Apr 2021 11:46:39 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id h26so1659119qtm.13 for ; Thu, 08 Apr 2021 11:46:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=6gAnMk/3QmoHKKKOynZbE6ARTru22AXVPx9J9ennqYk=; b=CsxGIoVitXO3OMbftljWu8Ki/FTK07cSA2VhLFY87N/obK/8HhQZTl3uWoLXcLQY+9 5XeUpzxisdaS1wXSrhGdjDUBgEN1xJqho2avlRpMrJ7x7wFuZZVox4bm9t8ME1fvefAB 73l3UAuQ3P/qkAZ3I0b8k8OxQAk/XlFrKuzbvy75sQxwVEfiGZu38eaC8C/qvX7fr3F4 wpBLuRw7iEovcshgem96DIb8CJLc4UWoFJ8pbS73TaWo3YhI1iQvwHvOsyTBv5bMBF4d 8BMw9g/iWrTuB6XFmPbApdr7P7ADW4iVgnCP/7uCEimfRvK7CcPlJ56vNkQfvR971+Nm z5Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=6gAnMk/3QmoHKKKOynZbE6ARTru22AXVPx9J9ennqYk=; b=N0fb/J8MfTRuje84PsPofkl75GlY0ojFm3SeoE+3Na2ZvlVRyONko77JTPcwcutQjZ /g3MCTU8NevbjbzTruOz++q9a8DerWVQ7E6LFvmo4kdvgtrMhXm2ihz4PROAufNn3YvQ YP16WYVtpx//7rHXECv2d2arTW7MlO+YewN21yQn2177DJLeVhu2XAoH4WCMUmauVnl6 KrEI49zAO1K0HAG3H7a0Gx73NSXfQYnq23F80H/9Kh2ebxqB2vc6OPgbZ1j+TR1l9ngI BZZxzCMvxEw7CWT6SYAl/xiUs6YyJMns5dsfkfU/IIxntGcQErFlLhntOIEKguXBg1ZA yTkw== X-Gm-Message-State: AOAM531HasooV5R2VonzIsLFyW2aOis2Rffg6d0eh1Lq15waitWroanw 6jh6XQlRPE73kj4NVvLhpRVDAMgJRt+Y2pSc6no= X-Received: from ndesaulniers1.mtv.corp.google.com ([2620:15c:211:202:258e:3713:7415:ce58]) (user=ndesaulniers job=sendgmr) by 2002:a05:6214:2628:: with SMTP id gv8mr10352013qvb.19.1617907598457; Thu, 08 Apr 2021 11:46:38 -0700 (PDT) Date: Thu, 8 Apr 2021 11:46:31 -0700 In-Reply-To: <20210407152621.3826f93e893c0cf9b327071f@linux-foundation.org> Message-Id: <20210408184631.1156669-1-ndesaulniers@google.com> Mime-Version: 1.0 References: <20210407152621.3826f93e893c0cf9b327071f@linux-foundation.org> X-Mailer: git-send-email 2.31.1.295.g9ea45b61b8-goog Subject: [PATCH v2] gcov: re-fix clang-11+ support From: Nick Desaulniers To: akpm@linux-foundation.org Cc: clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org, maskray@google.com, nathan@kernel.org, ndesaulniers@google.com, oberpar@linux.ibm.com, psodagud@quicinc.com, stable@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org LLVM changed the expected function signature for llvm_gcda_emit_function() in the clang-11 release. Users of clang-11 or newer may have noticed their kernels producing invalid coverage information: $ llvm-cov gcov -a -c -u -f -b .gcda -- gcno=.gcno 1 : checksum mismatch, \ (, ) != (, ) 2 Invalid .gcda File! ... Fix up the function signatures so calling this function interprets its parameters correctly and computes the correct cfg checksum. In particular, in clang-11, the additional checksum is no longer optional. Link: https://reviews.llvm.org/rG25544ce2df0daa4304c07e64b9c8b0f7df60c11d Cc: stable@vger.kernel.org #5.4+ Reported-by: Prasad Sodagudi Tested-by: Prasad Sodagudi Signed-off-by: Nick Desaulniers Reviewed-by: Nathan Chancellor --- Changes V1 -> V2: * Carried Nathan's reviewed-by tag. * Rebased on mainline, as per Andrew. * Left off patch 2/2 from the series https://lore.kernel.org/lkml/20210407185456.41943-1-ndesaulniers@google.com/ I assume that dropping support for clang-10+GCOV will be held separately for -next for 5.13, while this will be sent for 5.12? kernel/gcov/clang.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) base-commit: 3fb4f979b4fa1f92a02b538ae86e725b73e703d0 -- 2.31.1.295.g9ea45b61b8-goog diff --git a/kernel/gcov/clang.c b/kernel/gcov/clang.c index 8743150db2ac..c466c7fbdece 100644 --- a/kernel/gcov/clang.c +++ b/kernel/gcov/clang.c @@ -70,7 +70,9 @@ struct gcov_fn_info { u32 ident; u32 checksum; +#if CONFIG_CLANG_VERSION < 110000 u8 use_extra_checksum; +#endif u32 cfg_checksum; u32 num_counters; @@ -145,10 +147,8 @@ void llvm_gcda_emit_function(u32 ident, const char *function_name, list_add_tail(&info->head, ¤t_info->functions); } -EXPORT_SYMBOL(llvm_gcda_emit_function); #else -void llvm_gcda_emit_function(u32 ident, u32 func_checksum, - u8 use_extra_checksum, u32 cfg_checksum) +void llvm_gcda_emit_function(u32 ident, u32 func_checksum, u32 cfg_checksum) { struct gcov_fn_info *info = kzalloc(sizeof(*info), GFP_KERNEL); @@ -158,12 +158,11 @@ void llvm_gcda_emit_function(u32 ident, u32 func_checksum, INIT_LIST_HEAD(&info->head); info->ident = ident; info->checksum = func_checksum; - info->use_extra_checksum = use_extra_checksum; info->cfg_checksum = cfg_checksum; list_add_tail(&info->head, ¤t_info->functions); } -EXPORT_SYMBOL(llvm_gcda_emit_function); #endif +EXPORT_SYMBOL(llvm_gcda_emit_function); void llvm_gcda_emit_arcs(u32 num_counters, u64 *counters) { @@ -293,11 +292,16 @@ int gcov_info_is_compatible(struct gcov_info *info1, struct gcov_info *info2) !list_is_last(&fn_ptr2->head, &info2->functions)) { if (fn_ptr1->checksum != fn_ptr2->checksum) return false; +#if CONFIG_CLANG_VERSION < 110000 if (fn_ptr1->use_extra_checksum != fn_ptr2->use_extra_checksum) return false; if (fn_ptr1->use_extra_checksum && fn_ptr1->cfg_checksum != fn_ptr2->cfg_checksum) return false; +#else + if (fn_ptr1->cfg_checksum != fn_ptr2->cfg_checksum) + return false; +#endif fn_ptr1 = list_next_entry(fn_ptr1, head); fn_ptr2 = list_next_entry(fn_ptr2, head); } @@ -529,17 +533,22 @@ static size_t convert_to_gcda(char *buffer, struct gcov_info *info) list_for_each_entry(fi_ptr, &info->functions, head) { u32 i; - u32 len = 2; - - if (fi_ptr->use_extra_checksum) - len++; pos += store_gcov_u32(buffer, pos, GCOV_TAG_FUNCTION); - pos += store_gcov_u32(buffer, pos, len); +#if CONFIG_CLANG_VERSION < 110000 + pos += store_gcov_u32(buffer, pos, + fi_ptr->use_extra_checksum ? 3 : 2); +#else + pos += store_gcov_u32(buffer, pos, 3); +#endif pos += store_gcov_u32(buffer, pos, fi_ptr->ident); pos += store_gcov_u32(buffer, pos, fi_ptr->checksum); +#if CONFIG_CLANG_VERSION < 110000 if (fi_ptr->use_extra_checksum) pos += store_gcov_u32(buffer, pos, fi_ptr->cfg_checksum); +#else + pos += store_gcov_u32(buffer, pos, fi_ptr->cfg_checksum); +#endif pos += store_gcov_u32(buffer, pos, GCOV_TAG_COUNTER_BASE); pos += store_gcov_u32(buffer, pos, fi_ptr->num_counters * 2);