From: Ramana.Radhakrishnan@arm.com (Ramana Radhakrishnan)
To: linux-arm-kernel@lists.infradead.org
Subject: compiler code model for the kernel
Date: Tue, 20 Nov 2018 13:25:00 +0000 [thread overview]
Message-ID: <979349c7-e6f1-9a2a-f38a-9631b4a35fce@arm.com> (raw)
In-Reply-To: <CAKv+Gu8LchCWB-b+cDmStwrNf5qDs6ZMQ4drv2HMk-8OyjbzNQ@mail.gmail.com>
Hi Ard,
CC'ing Richard E and James Greenhalgh as well on this thread.
On 19/11/2018 17:41, Ard Biesheuvel wrote:
> Hello all,
>
> Some of us (on cc) have discussed this a bit on various occasions, so
> perhaps it's time to sit down and do something about it :-)
>
> The Clang work that Nick is involved in has made explicit some
> assumptions that we are currently making in the kernel with respect to
> the behavior of GCC, and it would be good to formalise this so we can
> keep relying on it in the future, and to clarify to other compiler
> developers what is needed.
>
> GCC for x86 has a -mcmodel=kernel parameter, so perhaps we should
> introduce the same for AArch64. Under this model, we should be able to
> make the following assumptions:
I would prefer this is -mcmodel=kernel-small so that it's explicit that
this is like the small memory model.
On AArch64 this is what GCC calls the small absolute model in code i.e.
really all global data accesses from code are really PC relative and
thus position independent. The problem is data initializers but I
understand you are able to deal with it by producing relative
relocations by using hidden attributes.
Thus I wonder if we should go as far as implying -fvisibility=hidden in
the compiler for all global data. Is that what you do today ?
In-fact the patch stack I am carrying for the sp_el0 based canary toyed
with the idea of adding such a flag and only putting out the symbol name
for the offset as I really dont' see anyone but the kernel using that
kind of code generation.
> - symbol references are emitted as ADRP/ADD pairs
Ok.
> - no absolute references in generated code like jump tables etc (like
> -fpic/-fpie) [*]
Ok. -fPIC/pie with default hidden visibility just achieves the same
thing with -mcmodel=small ?
> - no shared library semantics (no GOT indirections to support symbol
> preemption, or to reduce the CoW footprint and/or avoid text
> relocations)
Ok.
> - resulting objects can be linked in -pie mode by ld.bfd
Ok, but never producing a GOT. Further you probably want to have checks
on the final binary once a build is completed to ensure this ?
>
> Another thing that came up is that we currently rely on the stack
> pointer never to assume a value that is not 16-byte aligned, even
> transiently.
I think we've discussed that to great detail as far as GCC is concerned.
I would prefer it is documented in the kernel documentation as a
requirement for this standard.
TL;DR
http://lists.infradead.org/pipermail/linux-arm-kernel/2018-November/611445.html
regards
Ramana
>
> Other things I've missed?
>
> [*] This is only strictly required in parts of the code that may
> execute at a different offset than the linked offset, even after
> processing dynamic relocations at boot time (e.g., KVM hyp code
> running in a different exception level) but avoiding those altogether
> is reasonable. Note that GCC does the right thing for us here already,
> but Clang current;y needs -fno-jump-tables to build the KVM hyp code.
>
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
next prev parent reply other threads:[~2018-11-20 13:25 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-19 17:41 compiler code model for the kernel Ard Biesheuvel
2018-11-19 17:48 ` Nick Desaulniers
2018-11-22 11:53 ` Dave Martin
2018-11-22 12:06 ` Ard Biesheuvel
2018-11-19 23:54 ` Nick Desaulniers
2018-11-20 11:20 ` Peter Smith
2018-11-20 13:16 ` Ard Biesheuvel
2018-11-20 13:23 ` Will Deacon
2018-11-20 13:49 ` Ard Biesheuvel
2018-11-20 17:02 ` Ramana Radhakrishnan
2018-11-20 13:25 ` Ramana Radhakrishnan [this message]
2018-11-20 13:37 ` Ard Biesheuvel
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=979349c7-e6f1-9a2a-f38a-9631b4a35fce@arm.com \
--to=ramana.radhakrishnan@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
/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