Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2263060ybl; Thu, 19 Dec 2019 10:38:11 -0800 (PST) X-Google-Smtp-Source: APXvYqwXEsgzsUBHGr8+ms243jRTfLNggYzwPh150s8Tj6RjQW6U9EgTPVd2NuL5ZpLs8i4U8BAh X-Received: by 2002:a05:6830:13da:: with SMTP id e26mr10325931otq.302.1576780691462; Thu, 19 Dec 2019 10:38:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576780691; cv=none; d=google.com; s=arc-20160816; b=UV+ZEaVcmlCLFQr8JE0K0kE6aouwKW1pdIqWX8YfzmmEGINNomCD3RBSDS6nkLQWXK 3mmDNC1gjYZHkzWPjLkcaY8evu5EVbNrA9dOhr/BDx4G+RnTziJFfkD5E9//FvqIXZK0 k6FJ+XZq/Dn0HZdiYtdBJkrEftoNkB/v44BhL9o4+x4JDZa82PJXnqg9i0Tww64ZQset UtDKKqb5n5t5KNlaS9u6Rsa4/ZlzBE/STuQsBDQaAS0xUP3vVFsfWg1fvqHDPrM2D100 P6fF+Pb/UESBrdtgcOkeqaZP4wOIjXoJ1OmsIRonsKMr9Ej34GBgvm21FSLNqG3w4Med 9y6w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bFbS9wc3GtnlP4xV0l84hp2CTL7g93zDv+HYTSVgnyA=; b=Y3hRU4D5pL8i2ZmPLZ+AWp9PFDPYjZnhnxglEzCWEDAm+EhPsfcReoD3wunrINsJ4k ZdRsMxN6oJ/gKT8HC9xm8ZWvIhcGrkLRBp3fPikCsDz1oAd9slrMX+15mqeqnvMMHNDg hv9L+qJP//YnP7MBNGI++sPVifIav+4DG503BmUtVQ7BHMCKhTOPwIVl65psHvJ0zmre YJu8bEXAnl+KaKTHS3AlvzD8MB40db3M40wMF7Uo9Df90XfV9KqGtlVEsUdhfukczHpU mLWEFMTT/QU9KkE2oklHlp0pVRXHZPCQ5N4j43h05ysHfC+kDoEsFKA41CWPZ6us+aeP xMGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tC+5aVvc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m19si3346805oig.91.2019.12.19.10.37.58; Thu, 19 Dec 2019 10:38:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tC+5aVvc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727698AbfLSSgu (ORCPT + 99 others); Thu, 19 Dec 2019 13:36:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:53988 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727688AbfLSSgt (ORCPT ); Thu, 19 Dec 2019 13:36:49 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 088EC24672; Thu, 19 Dec 2019 18:36:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576780608; bh=BbG1MRN8dBGmcn2B4PnnDIylaywchjGJrrAUibn852c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tC+5aVvccleqJ+PoZuzYGThB3NcwmK2Qhlp2L0k3roChUOOQmaUGLrRJ5qwkc2PpJ 76Atj1LfU2hDp7CojNHIkT6nAOQsw8ufKWF12o9pJqHNU/eB7LiOfcNnL5k65ZJVln RbXCjiHKRCxQGKHVFoCmC8YAKIzKz7Njyf8+5D4w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paul Walmsley , Paul Walmsley , Sam Ravnborg , Masahiro Yamada , Sasha Levin Subject: [PATCH 4.4 044/162] modpost: skip ELF local symbols during section mismatch check Date: Thu, 19 Dec 2019 19:32:32 +0100 Message-Id: <20191219183210.598801805@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183150.477687052@linuxfoundation.org> References: <20191219183150.477687052@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paul Walmsley [ Upstream commit a4d26f1a0958bb1c2b60c6f1e67c6f5d43e2647b ] During development of a serial console driver with a gcc 8.2.0 toolchain for RISC-V, the following modpost warning appeared: ---- WARNING: vmlinux.o(.data+0x19b10): Section mismatch in reference from the variable .LANCHOR1 to the function .init.text:sifive_serial_console_setup() The variable .LANCHOR1 references the function __init sifive_serial_console_setup() If the reference is valid then annotate the variable with __init* or __refdata (see linux/init.h) or name the variable: *_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console ---- ".LANCHOR1" is an ELF local symbol, automatically created by gcc's section anchor generation code: https://gcc.gnu.org/onlinedocs/gccint/Anchored-Addresses.html https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/varasm.c;h=cd9591a45617464946dcf9a126dde277d9de9804;hb=9fb89fa845c1b2e0a18d85ada0b077c84508ab78#l7473 This was verified by compiling the kernel with -fno-section-anchors and observing that the ".LANCHOR1" ELF local symbol disappeared, and modpost no longer warned about the section mismatch. The serial driver code idiom triggering the warning is standard Linux serial driver practice that has a specific whitelist inclusion in modpost.c. I'm neither a modpost nor an ELF expert, but naively, it doesn't seem useful for modpost to report section mismatch warnings caused by ELF local symbols by default. Local symbols have compiler-generated names, and thus bypass modpost's whitelisting algorithm, which relies on the presence of a non-autogenerated symbol name. This increases the likelihood that false positive warnings will be generated (as in the above case). Thus, disable section mismatch reporting on ELF local symbols. The rationale here is similar to that of commit 2e3a10a1551d ("ARM: avoid ARM binutils leaking ELF local symbols") and of similar code already present in modpost.c: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/mod/modpost.c?h=v4.19-rc4&id=7876320f88802b22d4e2daf7eb027dd14175a0f8#n1256 This third version of the patch implements a suggestion from Masahiro Yamada to restructure the code as an additional pattern matching step inside secref_whitelist(), and further improves the patch description. Signed-off-by: Paul Walmsley Signed-off-by: Paul Walmsley Acked-by: Sam Ravnborg Signed-off-by: Masahiro Yamada Signed-off-by: Sasha Levin --- scripts/mod/modpost.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 81b1c02a76fad..f27df76059995 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1156,6 +1156,14 @@ static const struct sectioncheck *section_mismatch( * fromsec = text section * refsymname = *.constprop.* * + * Pattern 6: + * Hide section mismatch warnings for ELF local symbols. The goal + * is to eliminate false positive modpost warnings caused by + * compiler-generated ELF local symbol names such as ".LANCHOR1". + * Autogenerated symbol names bypass modpost's "Pattern 2" + * whitelisting, which relies on pattern-matching against symbol + * names to work. (One situation where gcc can autogenerate ELF + * local symbols is when "-fsection-anchors" is used.) **/ static int secref_whitelist(const struct sectioncheck *mismatch, const char *fromsec, const char *fromsym, @@ -1194,6 +1202,10 @@ static int secref_whitelist(const struct sectioncheck *mismatch, match(fromsym, optim_symbols)) return 0; + /* Check for pattern 6 */ + if (strstarts(fromsym, ".L")) + return 0; + return 1; } -- 2.20.1