All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ard Biesheuvel <ardb@kernel.org>,
	"Jiri Slaby (SUSE)" <jirislaby@kernel.org>,
	linux-kernel@vger.kernel.org,
	Alexander Potapenko <glider@google.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Alexey Makhalov <amakhalov@vmware.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Andrey Konovalov <andreyknvl@gmail.com>,
	Andrey Ryabinin <ryabinin.a.a@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Andy Lutomirski <luto@kernel.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Ben Segall <bsegall@google.com>, Borislav Petkov <bp@alien8.de>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Daniel Bristot de Oliveira <bristot@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	Don Zickus <dzickus@redhat.com>, Hao Luo <haoluo@google.com>,
	"H . J . Lu" <hjl.tools@gmail.com>,
	"H. Peter Anvin" <hpa@zytor.com>, Huang Rui <ray.huang@amd.com>,
	Ingo Molnar <mingo@redhat.com>, Jan Hubicka <jh@suse.de>,
	Jason Baron <jbaron@akamai.com>, Jiri Kosina <jikos@kernel.org>,
	Jiri Olsa <jolsa@kernel.org>,
	Joe Lawrence <joe.lawrence@redhat.com>,
	John Fastabend <john.fastabend@gmail.com>,
	Josh Poimboeuf <jpoimboe@kernel.org>,
	Juergen Gross <jgross@suse.com>,
	Juri Lelli <juri.lelli@redhat.com>, KP Singh <kpsingh@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Martin Liska <mliska@suse.cz>,
	Masahiro Yamada <masahiroy@kernel.org>,
	Mel Gorman <mgorman@suse.de>, Miguel Ojeda <ojeda@kernel.org>,
	Michal Marek <michal.lkml@markovi.net>,
	Miroslav Benes <mbenes@suse.cz>,
	Namhyung Kim <namhyung@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
	Petr Mladek <pmladek@suse.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Sedat Dilek <sedat.dilek@gmail.com>, Song Liu <song@kernel.org>,
	Stanislav Fomichev <sdf@google.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Valentin Schneider <vschneid@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	VMware PV-Drivers Reviewers <pv-drivers@vmware.com>,
	Yonghong Song <yhs@fb.com>
Subject: Re: [PATCH 00/46] gcc-LTO support for the kernel
Date: Thu, 17 Nov 2022 14:40:14 +0000 (UTC)	[thread overview]
Message-ID: <nycvar.YFH.7.77.849.2211171434440.3995@jbgna.fhfr.qr> (raw)
In-Reply-To: <Y3ZGAf2rdV1Ia5P3@hirez.programming.kicks-ass.net>

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 <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)

  reply	other threads:[~2022-11-17 14:41 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-14 11:42 [PATCH 00/46] gcc-LTO support for the kernel Jiri Slaby (SUSE)
2022-11-14 11:42 ` [PATCH 01/46] x86/boot: robustify calling startup_{32,64}() from the decompressor code Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 02/46] kbuild: pass jobserver to cmd_ld_vmlinux.o Jiri Slaby (SUSE)
2022-11-14 17:57   ` Masahiro Yamada
2022-11-15  6:36     ` Jiri Slaby
2022-11-14 11:43 ` [PATCH 03/46] kbuild: lto: preserve MAKEFLAGS for module linking Jiri Slaby (SUSE)
2022-11-14 18:02   ` Masahiro Yamada
2022-11-14 11:43 ` [PATCH 04/46] compiler.h: introduce __visible_on_lto Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 05/46] compiler.h: introduce __global_on_lto Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 06/46] Compiler Attributes, lto: introduce __noreorder Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 07/46] tracepoint, lto: Mark static call functions as __visible Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 08/46] static_call, lto: Mark static keys " Jiri Slaby (SUSE)
2022-11-14 15:51   ` Peter Zijlstra
2022-11-14 18:52     ` Josh Poimboeuf
2022-11-14 20:34     ` Andi Kleen
2022-11-17  8:24       ` Peter Zijlstra
2022-11-14 18:57   ` Josh Poimboeuf
2022-11-14 11:43 ` [PATCH 09/46] static_call, lto: Mark static_call_return0() " Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 10/46] static_call, lto: Mark func_a() as __visible_on_lto Jiri Slaby (SUSE)
2022-11-14 15:54   ` Peter Zijlstra
2022-11-14 20:29     ` Andi Kleen
2022-11-14 11:43 ` [PATCH 11/46] x86/alternative, lto: Mark int3_*() as global and __visible Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 12/46] x86/paravirt, lto: Mark native_steal_clock() as __visible_on_lto Jiri Slaby (SUSE)
2022-11-14 15:58   ` Peter Zijlstra
2022-11-14 11:43 ` [PATCH 13/46] x86/preempt, lto: Mark preempt_schedule_*thunk() as __visible Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 14/46] x86/sev, lto: Mark cpuid_table_copy as __visible_on_lto Jiri Slaby (SUSE)
2022-11-14 16:02   ` Peter Zijlstra
2022-11-14 11:43 ` [PATCH 15/46] x86/xen, lto: Mark xen_vcpu_stolen() as __visible Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 16/46] x86, lto: Mark gdt_page and native_sched_clock() " Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 17/46] amd, lto: Mark amd pmu and pstate functions as __visible_on_lto Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 18/46] entry, lto: Mark raw_irqentry_exit_cond_resched() as __visible Jiri Slaby (SUSE)
2022-11-16 23:30   ` Thomas Gleixner
2022-11-17  8:40     ` Peter Zijlstra
2022-11-17 22:07       ` Andi Kleen
2022-11-18  1:28         ` Thomas Gleixner
2022-11-19  0:50           ` Andi Kleen
2022-11-19  8:50             ` Thomas Gleixner
2022-11-22  9:32     ` Jiri Slaby
2022-11-14 11:43 ` [PATCH 19/46] export, lto: Mark __kstrtab* in EXPORT_SYMBOL() as global and __visible Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 20/46] softirq, lto: Mark irq_enter/exit_rcu() as __visible Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 21/46] btf, lto: pass scope as strings Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 22/46] btf, lto: Make all BTF IDs global on LTO Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 23/46] init.h, lto: mark initcalls as __noreorder Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 24/46] bpf, lto: mark interpreter jump table " Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 25/46] sched, lto: mark sched classes " Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 26/46] x86/apic, lto: Mark apic_driver*() " Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 27/46] linkage, lto: use C version for SYSCALL_ALIAS() / cond_syscall() Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 28/46] scripts, lto: re-add gcc-ld Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 29/46] scripts, lto: use CONFIG_LTO for many LTO specific actions Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 30/46] Kbuild, lto: Add Link Time Optimization support Jiri Slaby (SUSE)
2022-11-14 18:55   ` Josh Poimboeuf
2022-11-15 13:31     ` Martin Liška
2022-11-14 11:43 ` [PATCH 31/46] x86/purgatory, lto: Disable gcc LTO for purgatory Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 32/46] x86/realmode, lto: Disable gcc LTO for real mode code Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 33/46] x86/vdso, lto: Disable gcc LTO for the vdso Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 34/46] scripts, lto: disable gcc LTO for some mod sources Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 35/46] Kbuild, lto: disable gcc LTO for bounds+asm-offsets Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 36/46] lib/string, lto: disable gcc LTO for string.o Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 37/46] Compiler attributes, lto: disable __flatten with LTO Jiri Slaby (SUSE)
2022-11-14 17:01   ` Miguel Ojeda
2022-11-14 11:43 ` [PATCH 38/46] Kbuild, lto: don't include weak source file symbols in System.map Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 39/46] x86, lto: Disable relative init pointers with gcc LTO Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 40/46] x86/livepatch, lto: Disable live patching " Jiri Slaby (SUSE)
2022-11-14 19:07   ` Josh Poimboeuf
2022-11-14 20:28     ` Andi Kleen
2022-11-14 22:00       ` Josh Poimboeuf
2022-11-15 13:32         ` Martin Liška
2022-11-17 20:00   ` Song Liu
2022-11-14 11:43 ` [PATCH 41/46] x86/lib, lto: Mark 32bit mem{cpy,move,set} as __used Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 42/46] mm/kasan, lto: Mark kasan " Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 43/46] scripts, lto: check C symbols for modversions Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 44/46] scripts/bloat-o-meter, lto: handle gcc LTO Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 45/46] kasan, lto: remove extra BUILD_BUG() in memory_is_poisoned Jiri Slaby (SUSE)
2022-11-26 17:07   ` Andrey Konovalov
2022-11-14 11:43 ` [PATCH 46/46] x86, lto: Finally enable gcc LTO for x86 Jiri Slaby (SUSE)
2022-11-14 11:56 ` [PATCH 00/46] gcc-LTO support for the kernel Ard Biesheuvel
2022-11-14 12:04   ` Jiri Slaby
2022-11-14 19:40 ` Ard Biesheuvel
2022-11-17  8:28   ` Peter Zijlstra
2022-11-17  8:50     ` Richard Biener
2022-11-17 11:42       ` Peter Zijlstra
2022-11-17 11:49         ` Ard Biesheuvel
2022-11-17 13:55           ` Richard Biener
2022-11-17 14:32             ` Peter Zijlstra
2022-11-17 14:40               ` Richard Biener [this message]
2022-11-17 15:15             ` Ard Biesheuvel
2022-11-17 11:48       ` Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=nycvar.YFH.7.77.849.2211171434440.3995@jbgna.fhfr.qr \
    --to=rguenther@suse.de \
    --cc=acme@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=amakhalov@vmware.com \
    --cc=andreyknvl@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ardb@kernel.org \
    --cc=ast@kernel.org \
    --cc=bp@alien8.de \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=daniel@iogearbox.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=dvyukov@google.com \
    --cc=dzickus@redhat.com \
    --cc=glider@google.com \
    --cc=haoluo@google.com \
    --cc=hjl.tools@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jbaron@akamai.com \
    --cc=jgross@suse.com \
    --cc=jh@suse.de \
    --cc=jikos@kernel.org \
    --cc=jirislaby@kernel.org \
    --cc=joe.lawrence@redhat.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=jpoimboe@kernel.org \
    --cc=juri.lelli@redhat.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=martin.lau@linux.dev \
    --cc=masahiroy@kernel.org \
    --cc=mbenes@suse.cz \
    --cc=mgorman@suse.de \
    --cc=michal.lkml@markovi.net \
    --cc=mingo@redhat.com \
    --cc=mliska@suse.cz \
    --cc=namhyung@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=ojeda@kernel.org \
    --cc=oleksandr_tyshchenko@epam.com \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=pv-drivers@vmware.com \
    --cc=rafael@kernel.org \
    --cc=ray.huang@amd.com \
    --cc=rostedt@goodmis.org \
    --cc=ryabinin.a.a@gmail.com \
    --cc=sdf@google.com \
    --cc=sedat.dilek@gmail.com \
    --cc=song@kernel.org \
    --cc=sstabellini@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=vincent.guittot@linaro.org \
    --cc=vincenzo.frascino@arm.com \
    --cc=viresh.kumar@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.