linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "George Spelvin" <linux@sciencehorizons.net>
To: vegard.nossum@gmail.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] firmware: declare __{start,end}_builtin_fw as pointers
Date: 28 Jun 2016 08:23:50 -0400	[thread overview]
Message-ID: <20160628122350.6688.qmail@ns.sciencehorizons.net> (raw)

+#define external_array(type, name) \
+	({ \
+		extern type name[]; \
+		type *name_ptr = name; \
+		asm ("" : "+r" (name_ptr)); \
+		name_ptr; \
+	})

I've had to pull similar tricks to persuade GCC to generate
the code I wanted (in my case, it was optimization: "evaluate it
in this order, damn it!"), and I prefer to use the asm itself
with overlapping operands to do the assignment.

#define external_array(type, name) \
	({ \
		extern type name[]; \
		type *name_ptr;
		asm ("" : "=g" (name_ptr) : "0" (name)); \
		name_ptr; \
	})

You could define a wrapper if you like, something like

/*
 * Assign dst = src, but prevent the compiler from inferring anything
 * about the assigned value, so it can't do any unwanted optimization.
 */
#define blind_assign(dst,src) asm("" : "=X" (dst) : "0" (src))

In case it helps, here's a list of architecture-independent operand
constraints (that I think is exhaustive, but I'm not 100% sure):
r - general-purpose register
f - floating-point register
m - memory
o - offsettable memory (excluding pre/post inc/decrement modes)
i - immediate
g - "general", any of the above
X - "wildcard".  This matches anything at all, including special-purpose
    registers that are not included in "r".

             reply	other threads:[~2016-06-28 12:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-28 12:23 George Spelvin [this message]
2016-06-28 20:08 ` [PATCH] firmware: declare __{start,end}_builtin_fw as pointers Linus Torvalds
  -- strict thread matches above, loose matches on Subject: below --
2016-06-25 15:04 Vegard Nossum
2016-06-25 21:06 ` Vegard Nossum
2016-06-26  9:24   ` Vegard Nossum
2016-06-26 17:17     ` Linus Torvalds
2016-10-14  5:52       ` Jiri Slaby
2016-10-14  6:25         ` Vegard Nossum
2016-10-14  6:30           ` Jiri Slaby

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=20160628122350.6688.qmail@ns.sciencehorizons.net \
    --to=linux@sciencehorizons.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vegard.nossum@gmail.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).