linux-kbuild.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Konrad Dybcio <konrad.dybcio@linaro.org>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: Masahiro Yamada <masahiroy@kernel.org>,
	Ard Biesheuvel <ardb+git@google.com>,
	linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org,
	Nick Desaulniers <ndesaulniers@google.com>,
	Kees Cook <keescook@chromium.org>, Arnd Bergmann <arnd@arndb.de>
Subject: Re: [PATCH v5] kallsyms: Avoid weak references for kallsyms symbols
Date: Tue, 23 Apr 2024 18:24:05 +0200	[thread overview]
Message-ID: <77482887-4be9-4c33-8b2c-e30e8ccfbf57@linaro.org> (raw)
In-Reply-To: <CAMj1kXERSHjh0k9uCmYuNf31Fg79sd_6EHuS=Y_-xEdNGWeiAw@mail.gmail.com>



On 4/23/24 18:22, Ard Biesheuvel wrote:
> On Tue, 23 Apr 2024 at 18:01, Konrad Dybcio <konrad.dybcio@linaro.org> wrote:
>>
>>
>>
>> On 4/22/24 18:02, Masahiro Yamada wrote:
>>> On Sat, Apr 20, 2024 at 11:53 PM Ard Biesheuvel <ardb+git@google.com> wrote:
>>>>
>>>> From: Ard Biesheuvel <ardb@kernel.org>
>>>>
>>>> kallsyms is a directory of all the symbols in the vmlinux binary, and so
>>>> creating it poses somewhat of a chicken-and-egg problem, as its non-zero
>>>> size affects the layout of the binary, and therefore the values of the
>>>> symbols.
>>>>
>>>> For this reason, the kernel is linked more than once, and the first pass
>>>> does not include any kallsyms data at all. For the linker to accept
>>>> this, the symbol declarations describing the kallsyms metadata are
>>>> emitted as having weak linkage, so they can remain unsatisfied. During
>>>> the subsequent passes, the weak references are satisfied by the kallsyms
>>>> metadata that was constructed based on information gathered from the
>>>> preceding passes.
>>>>
>>>> Weak references lead to somewhat worse codegen, because taking their
>>>> address may need to produce NULL (if the reference was unsatisfied), and
>>>> this is not usually supported by RIP or PC relative symbol references.
>>>>
>>>> Given that these references are ultimately always satisfied in the final
>>>> link, let's drop the weak annotation on the declarations, and instead,
>>>> provide fallback definitions with weak linkage. This informs the
>>>> compiler that ultimately, the reference will always be satisfied.
>>>>
>>>> While at it, drop the FRV specific annotation that these symbols reside
>>>> in .rodata - FRV is long gone.
>>>>
>>>> Cc: Masahiro Yamada <masahiroy@kernel.org>
>>>> Cc: linux-kbuild@vger.kernel.org
>>>> Acked-by: Nick Desaulniers <ndesaulniers@google.com>
>>>> Acked-by: Kees Cook <keescook@chromium.org>
>>>> Acked-by: Arnd Bergmann <arnd@arndb.de>
>>>> Link: https://lore.kernel.org/all/20240415075837.2349766-5-ardb+git@google.com
>>>> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
>>>> ---
>>>> v5: - avoid PROVIDE() in the linker script, use weak definitions instead
>>>>       - drop tested-by, replace reviewed-by with acked-by
>>>>
>>>
>>> Applied to linux-kbuild. Thanks.
>>
>> Hi, this commit seems to break call traces, resulting in output like:
>>
>> [    2.777006] Call trace:
>> [    2.777007]  _text+0x89e7e8/0x39e0000
>> [    2.777008]  _text+0x89e82c/0x39e0000
>> [    2.777009]  _text+0x2b940cc/0x2bd2a90
>> [    2.777011]  _text+0x2b941a4/0x2bd2a90
>> [    2.777012]  _text+0x145dc/0x39e0000
>> [    2.777014]  _text+0x2b51184/0x2bd2a90
>> [    2.777016]  _text+0x18fc6a4/0x39e0000
>> [    2.777018]  _text+0x15644/0x39e0000
>> [    2.777019] ---[ end trace 0000000000000000 ]---
>>
> 
> This patch triggers an issue in the compiler, which appears to perform
> constant propagation on variables defined as weak, and this is
> definitely a compiler bug. (A weak variable can be superseded by
> another instance from a different object at link time, so the compiler
> cannot make assumptions based on the version of the variable it
> observes at compile time)

Sounds like fun..

> 
> It has already been dropped from the kbuild tree.

Thanks!

Konrad

      reply	other threads:[~2024-04-23 16:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-20 14:53 [PATCH v5] kallsyms: Avoid weak references for kallsyms symbols Ard Biesheuvel
2024-04-22 16:02 ` Masahiro Yamada
2024-04-23 16:01   ` Konrad Dybcio
2024-04-23 16:22     ` Ard Biesheuvel
2024-04-23 16:24       ` Konrad Dybcio [this message]

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=77482887-4be9-4c33-8b2c-e30e8ccfbf57@linaro.org \
    --to=konrad.dybcio@linaro.org \
    --cc=ardb+git@google.com \
    --cc=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=keescook@chromium.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=ndesaulniers@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).