Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1432946 > unrolled thread

Re: [PATCH] firmware: declare __{start,end}_builtin_fw as pointers

Started by"George Spelvin" <linux@sciencehorizons.net>
First post2016-06-28 14:30 +0200
Last post2016-06-28 22:20 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  Re: [PATCH] firmware: declare __{start,end}_builtin_fw as pointers "George Spelvin" <linux@sciencehorizons.net> - 2016-06-28 14:30 +0200
    Re: [PATCH] firmware: declare __{start,end}_builtin_fw as pointers Linus Torvalds <torvalds@linux-foundation.org> - 2016-06-28 22:20 +0200

#1432946 — Re: [PATCH] firmware: declare __{start,end}_builtin_fw as pointers

From"George Spelvin" <linux@sciencehorizons.net>
Date2016-06-28 14:30 +0200
SubjectRe: [PATCH] firmware: declare __{start,end}_builtin_fw as pointers
Message-ID<rP0jo-6Z4-55@gated-at.bofh.it>
+#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".

[toc] | [next] | [standalone]


#1433270

FromLinus Torvalds <torvalds@linux-foundation.org>
Date2016-06-28 22:20 +0200
Message-ID<rP7Ef-3d8-47@gated-at.bofh.it>
In reply to#1432946
On Tue, Jun 28, 2016 at 5:23 AM, George Spelvin
<linux@sciencehorizons.net> wrote:
> You could define a wrapper if you like, something like

We already have RELOC_HIDE() and OPTIMIZER_HIDE_VAR() that basically do this.

They both use 'r'. I guess they could use X.

                    Linus

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web