Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2106709ybl; Thu, 19 Dec 2019 08:11:45 -0800 (PST) X-Google-Smtp-Source: APXvYqwqg3y5aCNRBwTftSSsaFu/jVpwQyDAMNGU5Bvw/eYcKBk2G1lJPItLX5/JLSt+FV7ZmEdN X-Received: by 2002:a9d:6b12:: with SMTP id g18mr9305854otp.211.1576771905129; Thu, 19 Dec 2019 08:11:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576771905; cv=none; d=google.com; s=arc-20160816; b=ilmR4WkWJj+4mTuHW4A52ZMTaLMSRTzW+QA9P14S48mHz5ok7qSfuLsWrRCSizpmaB 6mtgAYCqtFDP+keagIcYY3ZdM46QNMVqgmr9VkQApiOrMpimRjJz/lohBuU5MoDqo8M+ aHqKfPw3XAD60BmrenenNAZKpi7p+yv4OA8FwqekEZJzLBip/FxA8Ra33J3folbUjnpl bl9RijPFWCORNbDufxrKBAGTwR5OSaSm0jwbXiwDDxpnlXYz9iakfERsmfhQHob2pb/X EJEbqEybOsst/zL/NOq30e+UNUMrN4M/mLu/p2sBhVjVfP7M3ogm6/O4gai4gEF0im/O Fjnw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=W70zFZGzyE7SNJ8vtZCRZFHijcD3N2jrEOj9lF3r2TU=; b=UFTJdKRUE2sLJqwNIiL7RM1ufC8D7sDTxq2+q7QS/P7I5O8Wj7oNCRy1060k+gcZoE Lotefcs3dpYlSWLpBfANZgZY1BJseCvpq950RG/46ip1BVznAqImAqviAUnvujty+2Om Jmki2CFIXiJgE8JgstWJaOBuiXEOfLNEHxop9vyOXsWa2bMoeza3qkcJyPtsgJmiAd9L 9xjaeVYp6TrMOb4++eJ+HSW+bwBjwMCTp17PjGrPvq/gCXSP5Ddu6TaKqY+WlrlfXagG jhJRpWzD7vN41ERIpCCNyR3yiNsLC4ThiDnN4XbmAXk+xFIGujUtBsgVkXc/uVzd+VRL ZAQw== 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=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2si3289952otq.31.2019.12.19.08.11.26; Thu, 19 Dec 2019 08:11:45 -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; 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=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726895AbfLSQJA (ORCPT + 99 others); Thu, 19 Dec 2019 11:09:00 -0500 Received: from relay.sw.ru ([185.231.240.75]:57942 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726778AbfLSQJA (ORCPT ); Thu, 19 Dec 2019 11:09:00 -0500 Received: from dhcp-172-16-24-104.sw.ru ([172.16.24.104]) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1ihyM7-0007Tl-FY; Thu, 19 Dec 2019 19:08:51 +0300 Subject: Re: [Q] ld: Does LTO reorder ro variables in two files? To: Alexander Monakov Cc: Peter Zijlstra , gcc-help@gcc.gnu.org, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, linux-kernel@vger.kernel.org, Jan Hubicka References: <157675913272.349305.8936736338884044103.stgit@localhost.localdomain> <20191219131242.GK2827@hirez.programming.kicks-ass.net> <3db1b1c8-0228-56e4-a04f-e8d24cd1dd51@virtuozzo.com> From: Kirill Tkhai Message-ID: Date: Thu, 19 Dec 2019 19:08:50 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19.12.2019 18:45, Alexander Monakov wrote: > [adding Jan Hubicka, GCC LTO maintainer] > > On Thu, 19 Dec 2019, Kirill Tkhai wrote: > >> CC: gcc-help@gcc.gnu.org >> >> Hi, gcc guys, >> >> this thread starts here: https://lkml.org/lkml/2019/12/19/403 >> >> There are two const variables: >> >> struct sched_class idle_sched_class >> and >> struct sched_class fair_sched_class, >> >> which are declared in two files idle.c and fair.c. >> >> 1)In Makefile the order is: idle.o fair.o >> 2)the variables go to the same ro section >> 3)there is no SORT(.*) keyword in linker script. >> >> Is it always true, that after linkage &idle_sched_class < &fair_sched_class? > > No, with LTO you don't have that guarantee. For functions it's more obvious, > GCC wants to analyze functions in reverse topological order so callees are > generally optimized before callers, and it will emit assembly as it goes, so > function ordering with LTO does not give much care to translation unit > boundaries. For variables it's a bit more subtle, GCC partitions all variables > and functions so it can hand them off to multiple compiler processes while doing > LTO. There's no guarantees about order of variables that end up in different > partitions. > > There's __attribute__((no_reorder)) that is intended to enforce ordering even > with LTO (it's documented under "Common function attributes" but works for > global variables as well). Thanks, Alexander! Kirill