public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Pinski <pinskia@gmail.com>
To: Saleem Abdulrasool <compnerd@compnerd.org>
Cc: GCC Mailing List <gcc@gcc.gnu.org>,
	Renato Golin <renato.golin@linaro.org>
Subject: Re: ARM inline assembly usage in Linux kernel
Date: Wed, 19 Feb 2014 03:02:00 -0000	[thread overview]
Message-ID: <CA+=Sn1kr+Vjf8bRRvg7nTzdPw3YCgHPYff4vFBEyN3jJFcZRQw@mail.gmail.com> (raw)
In-Reply-To: <20140219025428.GA5417@lithium.compnerd.org>

On Tue, Feb 18, 2014 at 6:56 PM, Saleem Abdulrasool
<compnerd@compnerd.org> wrote:
> Hello.
>
> I am sending this at the behest of Renato.  I have been working on the ARM
> integrated assembler in LLVM and came across an interesting item in the Linux
> kernel.
>
> I am wondering if this is an unstated covenant between the kernel and GCC or
> simply a clever use of an unintended/undefined behaviour.
>
> The Linux kernel uses the *compiler* as a fancy preprocessor to generate a
> specially crafted assembly file.  This file is then post-processed via sed to
> generate a header containing constants which is shared across assembly and C
> sources.
>
> In order to clarify the question, I am selecting a particular example and
> pulling out the relevant bits of the source code below.
>
> #define DEFINE(sym, val) asm volatile("\n->" #sym " %0 " #val : : "i" (val))
>
> #define __NR_PAGEFLAGS 22
>
> void definitions(void) {
>   DEFINE(NR_PAGEFLAGS, __NR_PAGEFLAGS);
> }
>
> This is then assembled to generate the following:
>
> ->NR_PAGEFLAGS #22 __NR_PAGEFLAGS
>
> This will later be post-processed to generate:
>
> #define NR_PAGELAGS 22 /* __NR_PAGEFLAGS */
>
> By using the inline assembler to evaluate (constant) expressions into constant
> values and then emit that using a special identifier (->) is a fairly clever
> trick.  This leads to my question: is this just use of an unintentional
> "feature" or something that was worked out between the two projects.
>
> Please explicitly CC me on any response as I am not subscribed to this mailing
> list.

I don't see why this is a bad use of the inline-asm.  GCC does not
know and is not supposed to know what the string inside the inline-asm
is going to be.  In fact if you have a newer assembler than the
compiler, you could use instructions that GCC does not even know
about.  This is the purpose of inline-asm.  I think it was a bad
design decision on LLVM/clang's part that it would check the assembly
code up front.

Thanks,
Andrew Pinski


>
> Thanks.
>
> --
> Saleem Abdulrasool
> compnerd (at) compnerd (dot) org
>

  reply	other threads:[~2014-02-19  3:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-19  2:56 Saleem Abdulrasool
2014-02-19  3:02 ` Andrew Pinski [this message]
2014-02-19 11:58   ` Richard Sandiford
2014-02-19 23:17     ` Renato Golin
2014-02-19 23:20       ` Andrew Pinski
2014-02-19 23:26         ` Renato Golin
2014-02-20 12:59           ` Ramana Radhakrishnan
2014-02-20 13:17             ` Renato Golin
2014-02-20 10:11         ` Ramana Radhakrishnan
2014-02-20 10:21           ` Renato Golin
2014-02-20 12:09         ` Richard Earnshaw

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='CA+=Sn1kr+Vjf8bRRvg7nTzdPw3YCgHPYff4vFBEyN3jJFcZRQw@mail.gmail.com' \
    --to=pinskia@gmail.com \
    --cc=compnerd@compnerd.org \
    --cc=gcc@gcc.gnu.org \
    --cc=renato.golin@linaro.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).