Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5452344img; Wed, 27 Mar 2019 08:46:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqwRsJ7ySc/DnXMt4sCdu4UYLnm62K0qH+IWrHecYcARweDdedq1OVj8tWHvX3nC7Tc4AeB6 X-Received: by 2002:a62:604:: with SMTP id 4mr852136pfg.38.1553701612500; Wed, 27 Mar 2019 08:46:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553701612; cv=none; d=google.com; s=arc-20160816; b=pAJxXErIDD76g1ODsNt3v9VnlDvdVhKqwKkYwGUWqCtsMouMyyHKGRmD1cjfCBSs2Q bQwp4G33tqTAU9mBk4edFcNU2ch+HLksd5wkdNiP5Ha1PYRn8r99QV4DNmDB7eFx6ccP S9DJRE4HJcSQ3IpFtnut722/of3lJFfucAH1zURoh6wCooILWuQagwjh9Ia/arrHMyyc MmKC/6eLPJzBF/dBlNHyLlLZDxf2UUBS2AxS+H4uSkNu6BbS2tw6V8Ah4j2sNjIy/SUy fPkcilrp5Ma/eRiIP0OA+OmlrLdsAYDkqi16Ga6hHnrXW1fEbsfqXMTLHgTqamE+mNUr PaEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=18MDMoQ6KDCkZVpWz8YKZ/ihjqMvagKU9A59mdLB1oY=; b=B0Hmvf2bWEl11aOf46EkJkV1vvBlHCDFCIxAa7OqU6aax1kFFWbhIp2kwUOqqzIiyH sKRF3YSlcOpmm1j0gLtCeFZt/pqHunhJdcyPOliwPHabySfopr6rMM7x36726GJ1Yjq2 Ld+SBUUsmPRSo2kCLWtc7A+pbXs1TdUDJcVd9fYVP1YXwtqvMbkdWgApH+WE/NQDZxjF q0GXGHZgkzRC1t4uMWjeK+J+1B3vo18t7noFU5MHilPPB5oza+/XjF7g1ZKwsts5+Cs1 Rrs149AoPqmUapEg58EwXAYgl3YrPjSgxAPfP4ZNPmu/HO2uJ8vifReKlZxmkhT4IITM L8wQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x206si17378467pgx.37.2019.03.27.08.46.36; Wed, 27 Mar 2019 08:46:52 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727699AbfC0PpX (ORCPT + 99 others); Wed, 27 Mar 2019 11:45:23 -0400 Received: from mga02.intel.com ([134.134.136.20]:3893 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727225AbfC0PpW (ORCPT ); Wed, 27 Mar 2019 11:45:22 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Mar 2019 08:45:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,277,1549958400"; d="scan'208";a="129133921" Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.7.201.137]) by orsmga008.jf.intel.com with ESMTP; 27 Mar 2019 08:45:22 -0700 Received: by tassilo.localdomain (Postfix, from userid 1000) id 0F8673015ED; Wed, 27 Mar 2019 08:45:22 -0700 (PDT) Date: Wed, 27 Mar 2019 08:45:22 -0700 From: Andi Kleen To: Thomas Gleixner Cc: Andi Kleen , x86@kernel.org, Andrew Morton , LKML , Josh Poimboeuf Subject: Re: [PATCH 02/17] x86, lto: Mark all top level asm statements as .text Message-ID: <20190327154522.GV18020@tassilo.jf.intel.com> References: <20190321220009.29334-1-andi@firstfloor.org> <20190321220009.29334-3-andi@firstfloor.org> <20190326213803.GN18020@tassilo.jf.intel.com> <20190327005523.bbxxittqf4d5bdz5@two.firstfloor.org> <20190327145918.GU18020@tassilo.jf.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > Why on earth is this needed for LTO? > > From the GCC manual: > > "This attribute, attached to a global variable or function, nullifies the > effect of the -fw hole-program command-line option, so the object remains > visible outside the current compilation unit." > > Neither the variable nor the data generated are global anymore. This data > is only used inside this compilation unit and I don't see why LTO needs a > reference outside of it. If so, then I really want to understand WHY > exactly. The LTO code generation doesn't compile file by file, but reorders all the functions and other top level statements into "partitions". The partitions are ordered by call graph so that inlining and some other optimizations work efficiently Then it finally runs multiple copies of the gcc code generator that generate code from these partitions, each generating an own assembler file. The top level assembler is not part of the call graph that drives the partitioning. So it can happen (in fact it's likely) that the top level assembler statement ends up in a different partition and final assembler file than the other functions in the same source file. The repartitioning handles all symbols that are visible to C automatically. But for top level asm() referencing C symbols gcc doesn't know what it is referenced. Normally in non LTO it just works because everything ends up in the same assembler file and the assembler can resolve the static label. But that won't work if it's in a different assembler file, as in LTO. Fixing it would probably require adding some new syntax to top level asm to declare symbols it referenced, so that gcc understands the references. But if we make it __visible and global it works too because the linker resolves it. That's simple enough, although can be a bit unexpected. More information on LTO internals: https://gcc.gnu.org/onlinedocs/gccint/LTO-Overview.html#LTO-Overview -Andi