Received: by 2002:a05:622a:1442:b0:3a5:28ea:c4b9 with SMTP id v2csp746288qtx; Thu, 17 Nov 2022 07:24:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf4NKMI8/7Kkfa2D9UHu7cSN6n8IfUCrhaEEDJYDYnRCQNJ51hkaROlw687INOHc6NJT8jwC X-Received: by 2002:a05:6a00:1d83:b0:56d:c342:ea5e with SMTP id z3-20020a056a001d8300b0056dc342ea5emr3365781pfw.71.1668698644211; Thu, 17 Nov 2022 07:24:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668698644; cv=none; d=google.com; s=arc-20160816; b=k4Td6Ew/Y5DeOLD8WBNAL0bRQ0SlocttllIYliY3WJJy/EubInnLBDnj/tEjg6dGRD A6/GgaKWPFwejUQWPwBVsHSqOGURWHnksEEWzjY2+eBxPBYOkIg9DQaudzSo2Fr8DlUL M5KJ/+ywF31IeXIs/8el5uqbXSdcmjsTdXrZADRjwo1BlDLUEj0gWgiDDX07F++AMTht mHl5rtNpJ/pzWVw59WLjkT7EYP06Q6fUmtPmu1EgeUW1z2xzVzdVzF8qKNimY8Pl2VvT M3o4+1r5B0UBDH/6i1rt+oD8bVzN0Cwa97b00GMH+MkQpsm9ooHLkyu1m+T0QtAngM52 DMCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature:dkim-signature; bh=D1kqm4NTuLqt4P5j0+BjzYHODH2usXp2+Kg4xoCqgvs=; b=KuTuL9+d615A7q1yjyBxg/tiDIOfdk42upbfh3OjsQ0rNU51GP2VdgNHklNVTLuJnP eXkGboRw14OcpxEwRcxzk5nSx8Yu0b3EnNzcka79DkDGXDs4RpmndAmWjwnJjfuNpjOk qs+u6l24Lw94utnEjQ2THVxRrHfLjcx1ieiFfIfzeLic9m0VAe/q3PmJllmpqIHfoXkZ FdznfYBF/jAXCtLYwCDgdA2CZkIDoBfcUGGhYnDU2Yty3Dr4QBYfT2LMEPaa1fVN94d8 9LukJ2BwQLW5edd4vtq79pLJvmHR76BBBGz7nUehfpM4y1lj0LHUX27YfIc+Onp9xOge onRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Vlyas2QB; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p12-20020a63c14c000000b00476e21bc1bdsi1242685pgi.162.2022.11.17.07.23.52; Thu, 17 Nov 2022 07:24:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Vlyas2QB; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239916AbiKQOlj (ORCPT + 92 others); Thu, 17 Nov 2022 09:41:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234954AbiKQOk7 (ORCPT ); Thu, 17 Nov 2022 09:40:59 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB9C1769EC for ; Thu, 17 Nov 2022 06:40:16 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 784F022789; Thu, 17 Nov 2022 14:40:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1668696015; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=D1kqm4NTuLqt4P5j0+BjzYHODH2usXp2+Kg4xoCqgvs=; b=Vlyas2QBo5dYyEWniYISh4gjJGw9UvUDJHmTlnKu38fYLU8fN9nL67Tfik1kocLVd6Xr+y sM6nTwVV25KlhpWxqkJzS2nFvwYiPOjW2CafRLRe+OpSH6A+pfefFJ075TfjeU/H3Za7oi rLfeC4ChFoJafD/LrKutFDVzcXxEhnM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1668696015; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=D1kqm4NTuLqt4P5j0+BjzYHODH2usXp2+Kg4xoCqgvs=; b=QnDENqFIA3AkfxbL5NOqeccDMU0aBYI8wyXJa6sED6R2lKp0ET2fghrZQhiI2PJD7i0tlP Lt6OnsPZR4h0oRBA== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id E30C92C141; Thu, 17 Nov 2022 14:40:14 +0000 (UTC) Date: Thu, 17 Nov 2022 14:40:14 +0000 (UTC) From: Richard Biener To: Peter Zijlstra cc: Ard Biesheuvel , "Jiri Slaby (SUSE)" , linux-kernel@vger.kernel.org, Alexander Potapenko , Alexander Shishkin , Alexei Starovoitov , Alexey Makhalov , Andrew Morton , Andrey Konovalov , Andrey Ryabinin , Andrii Nakryiko , Andy Lutomirski , Arnaldo Carvalho de Melo , Ben Segall , Borislav Petkov , Daniel Borkmann , Daniel Bristot de Oliveira , Dave Hansen , Dietmar Eggemann , Dmitry Vyukov , Don Zickus , Hao Luo , "H . J . Lu" , "H. Peter Anvin" , Huang Rui , Ingo Molnar , Jan Hubicka , Jason Baron , Jiri Kosina , Jiri Olsa , Joe Lawrence , John Fastabend , Josh Poimboeuf , Juergen Gross , Juri Lelli , KP Singh , Mark Rutland , Martin KaFai Lau , Martin Liska , Masahiro Yamada , Mel Gorman , Miguel Ojeda , Michal Marek , Miroslav Benes , Namhyung Kim , Nick Desaulniers , Oleksandr Tyshchenko , Petr Mladek , "Rafael J. Wysocki" , Sedat Dilek , Song Liu , Stanislav Fomichev , Stefano Stabellini , Steven Rostedt , Thomas Gleixner , Valentin Schneider , Vincent Guittot , Vincenzo Frascino , Viresh Kumar , VMware PV-Drivers Reviewers , Yonghong Song Subject: Re: [PATCH 00/46] gcc-LTO support for the kernel In-Reply-To: Message-ID: References: <20221114114344.18650-1-jirislaby@kernel.org> User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 17 Nov 2022, Peter Zijlstra wrote: > On Thu, Nov 17, 2022 at 01:55:07PM +0000, Richard Biener wrote: > > > > > I'm not sure what you're on about; only symbols annotated with > > > > EXPORT_SYMBOL*() are accessible from modules (aka DSOs) and those will > > > > have their address taken. You can feely eliminate any unused symbol. > > > > But IIRC that's not reflected on the ELF level by making EXPORT_SYMBOL*() > > symbols public and the rest hidden - instead all symbols global in the C TUs > > will become public and the module dynamic loader details are hidden from > > GCCs view of the kernel image as ELF relocatable object. > > It is reflected by keeping their address in __ksymtab_$foo sections, as > such their address 'escapes'. That's not enough to make symbols not appearing in __ksymtab_$foo sections eliminatable. > > > We have an __ADDRESSABLE() macro and asmlinkage modifier to annotate > > > symbols that may appear to the compiler as though they are never > > > referenced. > > > > > > Would it be possible to repurpose those so that the LTO code knows > > > which symbols it must not remove? > > > > I find > > > > /* > > * Force the compiler to emit 'sym' as a symbol, so that we can reference > > * it from inline assembler. Necessary in case 'sym' could be inlined > > * otherwise, or eliminated entirely due to lack of references that are > > * visible to the compiler. > > */ > > #define ___ADDRESSABLE(sym, __attrs) \ > > static void * __used __attrs \ > > __UNIQUE_ID(__PASTE(__addressable_,sym)) = (void *)&sym; > > #define __ADDRESSABLE(sym) \ > > ___ADDRESSABLE(sym, __section(".discard.addressable")) > > > > that should be enough to force LTO keeping 'sym' - unless there's > > a linker script that discards .discard.addressable which I fear LTO > > will notice, losing the effect. > > The initial LTO link pass will not discard .discard sections in order to > generate a regular ELF object file. This object file is then fed to > objtool and the kallsyms tool and eventually linked with the linker > script in a multi-stage link pass. > > Also see scripts/link-vmlinux.sh for all the horrible details. > > > The folks who worked on LTO enablement of the kernel should know the > > real issue better - I understand asm()s are a pain because GCC > > refuses to parse the assembler string heuristically for used > > symbols (but it can never be more than heuristics). > > I don't understand why it can't be more than heuristics; eventually the > asm() contents end up in a real assembler and it has to make sense. > > Might as well parse it directly -- isn't that what clang-ias does? GCC doesn't have an integrated assembler and the actual assembler text that's emitted is not known at the stage we need to know the symbol. Which means for GCC it would be heuristics. > > The issue with asm()s is not so much elimination (__used solves that) > > but that GCC can end up moving the asm() and the refered to symbols to > > different link-time units causing unresolved symbols for non-global > > symbols. -fno-toplevel-reorder should fix that at some cost. > > I thought the whole point of LTO was that there was only a single link > time unit, translate all the tus into intermadiate gunk and then collect > the whole lot in one go. that's what it does, but it fans out to parallelize the final compile, dividing the whole lot again which is where this problem can appear if GCC doesn't see that asm() X uses symbol Y. Richard. -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)