Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp878056ybt; Wed, 24 Jun 2020 13:35:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwND02DUWX0vpP8z7iVEe1ODQujWkM8oCTI99VDyAs1QxYFZNbVT3EA27OWZRcD1O6T+o99 X-Received: by 2002:a05:6402:a58:: with SMTP id bt24mr18715353edb.333.1593030921115; Wed, 24 Jun 2020 13:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593030921; cv=none; d=google.com; s=arc-20160816; b=lWOZGuK1ZGKbRfxU8KTnq6VqLeGtnsAh6BBhvXDD7AwkD5hBGu811JafsoJyUq8Mby /sNcbN3ocuCQRgXS03C8VORpfbU8boSqqy7ndsEuqpU2PNkcuPXniFgZNthHVhG9jH3o Bm5noDDxBNUxs1FVMq1Nv9ETZSnqIlIBS9BHlLQxw+07giAVIc742sf/oeTj6LnpgVEa FogePRz9oEGZmjK9CY1Jssy49R0oRX3/YU/uGth/+gVQpkwDtQmySh92a57CZGDckj2U EKn+X2BD7tQOzs5pRt+giFX/MbTHh2+1nukaUXQEsF6D3jkS/MuSHXeTDl7Bi2ak1BS1 DDmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=edIkT6p07lpLePHQP+aYqsXpIzZ2+6woe9Vgp5gIJI4=; b=kqiNo9eCUxcXgNfUUYvV4z6ZV3Md5HwUmeEgZ2dgt/I1ZnE5T67h1M44aYCfsTkd/T yXFYeAju2NrzGwGeCYDwe/3qpo349PdhB6q6Up2rvemF9Ho3AqNz/w//FZFu1B5qngoV 55cTZfoHJ9HbHBIM6e9+xmI8nCijyVXSFDDpRrAHSxHpHopxWYtCoydvBdO3jrAcmyUr p86r8MFuxkC+dB8/GrbUrSwVGInpCgfBFHOKgmTA1XQZEDhcAh8V1Unwrf2MTylmMDVR RHmNYeOtESrYEbxHDiBFAKfdK8DcBXNn30S9rrHb5zAUtVbhGbdVJ7VUsiHyepDl7NKH NiKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=egWHIaow; 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=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 d5si14170754ejw.224.2020.06.24.13.34.57; Wed, 24 Jun 2020 13:35:21 -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=@google.com header.s=20161025 header.b=egWHIaow; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406477AbgFXUdW (ORCPT + 99 others); Wed, 24 Jun 2020 16:33:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406496AbgFXUdR (ORCPT ); Wed, 24 Jun 2020 16:33:17 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19CE5C06179B for ; Wed, 24 Jun 2020 13:33:17 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id s9so3500063ybj.18 for ; Wed, 24 Jun 2020 13:33:17 -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=edIkT6p07lpLePHQP+aYqsXpIzZ2+6woe9Vgp5gIJI4=; b=egWHIaowycA2j4XZam7KmKMW2pQ89pwKSamnnESmMZjXlGrpDiBMEKX0ymsIpEUG5Q Q/5jq7wq9EUsrGut0D7nH0OzX+X6PmQ4BsvV+OFdyIwItO18fwnnqRcjLL/etsokICn2 kJA/eOpcLnRws54bEMudJOUeKnPBfutms4HPc2YVoU7pUuEXirkoHEo/+ZivIPBIpcjm QAZkoUB6YhA3LjQHac3tKT7W83SDE0ybUBlgAkHod3lCaXJMmDghQ2Hjaer2BjebhMdJ 6tJB8nkEwUWILUX4LAlqgG6pcwYlTLpv3LHaWpmgIRcC8eGvhD6AT800VKeaZEkZUUaI CVRw== 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=edIkT6p07lpLePHQP+aYqsXpIzZ2+6woe9Vgp5gIJI4=; b=ZY/szmQ6Ui5Bfzea6tVmC2LO1KNnZn4hq7rfgaeqYGxoJU53FbtqEBI7VpJpyF8V/h 1Myi4/eSfV0vj57sQCv5RYxHZRh1OmGUeMS/mqk+ztOJ3hkSN0MaALVjkskxyemBEvUD Ov3sN8YbsBZH3iuJEDzVgp7zk4e6bvdTGDpqyvpv1htMPpwT4Og6Kmwwpz8Xuna7EUYz GOINWzYN5NKA14mV732utvBih3ZpHER/mRE1Fkr+4pLSPLHyUpv5o+1DgZ4Qg8HfgVmO AW4tbFsh9abnCrvMTYPEBjwr/cQeD/MIE0xcoRDlCQKN2d1AXJX3cz7cLK9AQd70qhf1 oZEQ== X-Gm-Message-State: AOAM531nbEHiTfM8FBFV4SwYu7B3nyGf1OIm7Dt5qluWDVjOZclitC9U AUO6iB2uPTTpTxi9ADMQWg4MnF7VR/H9pPJeX9c= X-Received: by 2002:a25:2fc5:: with SMTP id v188mr45630243ybv.130.1593030796295; Wed, 24 Jun 2020 13:33:16 -0700 (PDT) Date: Wed, 24 Jun 2020 13:31:48 -0700 In-Reply-To: <20200624203200.78870-1-samitolvanen@google.com> Message-Id: <20200624203200.78870-11-samitolvanen@google.com> Mime-Version: 1.0 References: <20200624203200.78870-1-samitolvanen@google.com> X-Mailer: git-send-email 2.27.0.212.ge8ba1cc988-goog Subject: [PATCH 10/22] init: lto: fix PREL32 relocations From: Sami Tolvanen To: Masahiro Yamada , Will Deacon Cc: Greg Kroah-Hartman , "Paul E. McKenney" , Kees Cook , Nick Desaulniers , clang-built-linux@googlegroups.com, kernel-hardening@lists.openwall.com, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, x86@kernel.org, Sami Tolvanen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With LTO, the compiler can rename static functions to avoid global naming collisions. As initcall functions are typically static, renaming can break references to them in inline assembly. This change adds a global stub with a stable name for each initcall to fix the issue when PREL32 relocations are used. Signed-off-by: Sami Tolvanen --- include/linux/init.h | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/include/linux/init.h b/include/linux/init.h index af638cd6dd52..5b4bdc5a8399 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -209,26 +209,48 @@ extern bool initcall_debug; */ #define __initcall_section(__sec, __iid) \ #__sec ".init.." #__iid + +/* + * With LTO, the compiler can rename static functions to avoid + * global naming collisions. We use a global stub function for + * initcalls to create a stable symbol name whose address can be + * taken in inline assembly when PREL32 relocations are used. + */ +#define __initcall_stub(fn, __iid, id) \ + __initcall_name(initstub, __iid, id) + +#define __define_initcall_stub(__stub, fn) \ + int __init __stub(void) \ + { \ + return fn(); \ + } \ + __ADDRESSABLE(__stub) #else #define __initcall_section(__sec, __iid) \ #__sec ".init" + +#define __initcall_stub(fn, __iid, id) fn + +#define __define_initcall_stub(__stub, fn) \ + __ADDRESSABLE(fn) #endif #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS -#define ____define_initcall(fn, __name, __sec) \ - __ADDRESSABLE(fn) \ +#define ____define_initcall(fn, __stub, __name, __sec) \ + __define_initcall_stub(__stub, fn) \ asm(".section \"" __sec "\", \"a\" \n" \ __stringify(__name) ": \n" \ - ".long " #fn " - . \n" \ + ".long " __stringify(__stub) " - . \n" \ ".previous \n"); #else -#define ____define_initcall(fn, __name, __sec) \ +#define ____define_initcall(fn, __unused, __name, __sec) \ static initcall_t __name __used \ __attribute__((__section__(__sec))) = fn; #endif #define __unique_initcall(fn, id, __sec, __iid) \ ____define_initcall(fn, \ + __initcall_stub(fn, __iid, id), \ __initcall_name(initcall, __iid, id), \ __initcall_section(__sec, __iid)) -- 2.27.0.212.ge8ba1cc988-goog