linux-next.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [tip:x86/vdso] x86, vdso: Reimplement vdso.so preparation in build-time C
       [not found] ` <tip-6f121e548f83674ab4920a4e60afb58d4f61b829@git.kernel.org>
@ 2014-05-29 19:17   ` Paul Gortmaker
  2014-05-29 19:32     ` Andy Lutomirski
  0 siblings, 1 reply; 20+ messages in thread
From: Paul Gortmaker @ 2014-05-29 19:17 UTC (permalink / raw)
  To: mingo, H. Peter Anvin, luto, LKML, tglx@linutronix.de, hpa
  Cc: linux-tip-commits, linux-next@vger.kernel.org

On Mon, May 5, 2014 at 6:25 PM, tip-bot for Andy Lutomirski
<tipbot@zytor.com> wrote:
> Commit-ID:  6f121e548f83674ab4920a4e60afb58d4f61b829
> Gitweb:     http://git.kernel.org/tip/6f121e548f83674ab4920a4e60afb58d4f61b829
> Author:     Andy Lutomirski <luto@amacapital.net>
> AuthorDate: Mon, 5 May 2014 12:19:34 -0700
> Committer:  H. Peter Anvin <hpa@linux.intel.com>
> CommitDate: Mon, 5 May 2014 13:18:51 -0700
>
> x86, vdso: Reimplement vdso.so preparation in build-time C

Just a heads up in case it hasn't been mentioned already;
the x86 builds in linux-next which IIRC are done as cross
compile on a powerpc box are failing as follows:

  VDSO2C  arch/x86/vdso/vdso-image-64.c
/bin/sh: line 1: 15995 Segmentation fault      arch/x86/vdso/vdso2c
arch/x86/vdso/vdso64.so.dbg arch/x86/vdso/vdso-image-64.c
make[3]: *** [arch/x86/vdso/vdso-image-64.c] Error 139

http://kisskb.ellerman.id.au/kisskb/buildresult/11265454/

Paul.
--

>
> Currently, vdso.so files are prepared and analyzed by a combination
> of objcopy, nm, some linker script tricks, and some simple ELF
> parsers in the kernel.  Replace all of that with plain C code that
> runs at build time.
>
> All five vdso images now generate .c files that are compiled and
> linked in to the kernel image.
>
> This should cause only one userspace-visible change: the loaded vDSO
> images are stripped more heavily than they used to be.  Everything
> outside the loadable segment is dropped.  In particular, this causes
> the section table and section name strings to be missing.  This
> should be fine: real dynamic loaders don't load or inspect these
> tables anyway.  The result is roughly equivalent to eu-strip's
> --strip-sections option.
>
> The purpose of this change is to enable the vvar and hpet mappings
> to be moved to the page following the vDSO load segment.  Currently,
> it is possible for the section table to extend into the page after
> the load segment, so, if we map it, it risks overlapping the vvar or
> hpet page.  This happens whenever the load segment is just under a
> multiple of PAGE_SIZE.
>
> The only real subtlety here is that the old code had a C file with
> inline assembler that did 'call VDSO32_vsyscall' and a linker script
> that defined 'VDSO32_vsyscall = __kernel_vsyscall'.  This most
> likely worked by accident: the linker script entry defines a symbol
> associated with an address as opposed to an alias for the real
> dynamic symbol __kernel_vsyscall.  That caused ld to relocate the
> reference at link time instead of leaving an interposable dynamic
> relocation.  Since the VDSO32_vsyscall hack is no longer needed, I
> now use 'call __kernel_vsyscall', and I added -Bsymbolic to make it
> work.  vdso2c will generate an error and abort the build if the
> resulting image contains any dynamic relocations, so we won't
> silently generate bad vdso images.
>
> (Dynamic relocations are a problem because nothing will even attempt
> to relocate the vdso.)
>
> Signed-off-by: Andy Lutomirski <luto@amacapital.net>
> Link: http://lkml.kernel.org/r/2c4fcf45524162a34d87fdda1eb046b2a5cecee7.1399317206.git.luto@amacapital.net
> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
> ---

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [tip:x86/vdso] x86, vdso: Reimplement vdso.so preparation in build-time C
  2014-05-29 19:17   ` [tip:x86/vdso] x86, vdso: Reimplement vdso.so preparation in build-time C Paul Gortmaker
@ 2014-05-29 19:32     ` Andy Lutomirski
  2014-05-29 19:43       ` H. Peter Anvin
  2014-05-29 19:43       ` [tip:x86/vdso] x86, vdso: Reimplement vdso.so preparation in build-time C Josh Boyer
  0 siblings, 2 replies; 20+ messages in thread
From: Andy Lutomirski @ 2014-05-29 19:32 UTC (permalink / raw)
  To: Paul Gortmaker
  Cc: Ingo Molnar, H. Peter Anvin, LKML, tglx@linutronix.de,
	H. Peter Anvin, linux-tip-commits, linux-next@vger.kernel.org

On Thu, May 29, 2014 at 12:17 PM, Paul Gortmaker
<paul.gortmaker@windriver.com> wrote:
> On Mon, May 5, 2014 at 6:25 PM, tip-bot for Andy Lutomirski
> <tipbot@zytor.com> wrote:
>> Commit-ID:  6f121e548f83674ab4920a4e60afb58d4f61b829
>> Gitweb:     http://git.kernel.org/tip/6f121e548f83674ab4920a4e60afb58d4f61b829
>> Author:     Andy Lutomirski <luto@amacapital.net>
>> AuthorDate: Mon, 5 May 2014 12:19:34 -0700
>> Committer:  H. Peter Anvin <hpa@linux.intel.com>
>> CommitDate: Mon, 5 May 2014 13:18:51 -0700
>>
>> x86, vdso: Reimplement vdso.so preparation in build-time C
>
> Just a heads up in case it hasn't been mentioned already;
> the x86 builds in linux-next which IIRC are done as cross
> compile on a powerpc box are failing as follows:
>
>   VDSO2C  arch/x86/vdso/vdso-image-64.c
> /bin/sh: line 1: 15995 Segmentation fault      arch/x86/vdso/vdso2c
> arch/x86/vdso/vdso64.so.dbg arch/x86/vdso/vdso-image-64.c
> make[3]: *** [arch/x86/vdso/vdso-image-64.c] Error 139
>
> http://kisskb.ellerman.id.au/kisskb/buildresult/11265454/
>

Egads.  This wouldn't be a big-endian host by any chance?

--Andy

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [tip:x86/vdso] x86, vdso: Reimplement vdso.so preparation in build-time C
  2014-05-29 19:32     ` Andy Lutomirski
@ 2014-05-29 19:43       ` H. Peter Anvin
  2014-05-29 19:46         ` Andy Lutomirski
  2014-05-29 19:43       ` [tip:x86/vdso] x86, vdso: Reimplement vdso.so preparation in build-time C Josh Boyer
  1 sibling, 1 reply; 20+ messages in thread
From: H. Peter Anvin @ 2014-05-29 19:43 UTC (permalink / raw)
  To: Andy Lutomirski, Paul Gortmaker
  Cc: Ingo Molnar, LKML, tglx@linutronix.de, H. Peter Anvin,
	linux-tip-commits, linux-next@vger.kernel.org

On 05/29/2014 12:32 PM, Andy Lutomirski wrote:
> On Thu, May 29, 2014 at 12:17 PM, Paul Gortmaker
> <paul.gortmaker@windriver.com> wrote:
>> On Mon, May 5, 2014 at 6:25 PM, tip-bot for Andy Lutomirski
>> <tipbot@zytor.com> wrote:
>>> Commit-ID:  6f121e548f83674ab4920a4e60afb58d4f61b829
>>> Gitweb:     http://git.kernel.org/tip/6f121e548f83674ab4920a4e60afb58d4f61b829
>>> Author:     Andy Lutomirski <luto@amacapital.net>
>>> AuthorDate: Mon, 5 May 2014 12:19:34 -0700
>>> Committer:  H. Peter Anvin <hpa@linux.intel.com>
>>> CommitDate: Mon, 5 May 2014 13:18:51 -0700
>>>
>>> x86, vdso: Reimplement vdso.so preparation in build-time C
>>
>> Just a heads up in case it hasn't been mentioned already;
>> the x86 builds in linux-next which IIRC are done as cross
>> compile on a powerpc box are failing as follows:
>>
>>   VDSO2C  arch/x86/vdso/vdso-image-64.c
>> /bin/sh: line 1: 15995 Segmentation fault      arch/x86/vdso/vdso2c
>> arch/x86/vdso/vdso64.so.dbg arch/x86/vdso/vdso-image-64.c
>> make[3]: *** [arch/x86/vdso/vdso-image-64.c] Error 139
>>
>> http://kisskb.ellerman.id.au/kisskb/buildresult/11265454/
>>
> 
> Egads.  This wouldn't be a big-endian host by any chance?
> 

He said PowerPC; most but not all PowerPC systems are bigendian.  Seems
like a fair assumption to make.

	-hpa

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [tip:x86/vdso] x86, vdso: Reimplement vdso.so preparation in build-time C
  2014-05-29 19:32     ` Andy Lutomirski
  2014-05-29 19:43       ` H. Peter Anvin
@ 2014-05-29 19:43       ` Josh Boyer
  1 sibling, 0 replies; 20+ messages in thread
From: Josh Boyer @ 2014-05-29 19:43 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: Paul Gortmaker, Ingo Molnar, H. Peter Anvin, LKML,
	tglx@linutronix.de, H. Peter Anvin,
	linux-tip-commits@vger.kernel.org, linux-next@vger.kernel.org

On Thu, May 29, 2014 at 3:32 PM, Andy Lutomirski <luto@amacapital.net> wrote:
> On Thu, May 29, 2014 at 12:17 PM, Paul Gortmaker
> <paul.gortmaker@windriver.com> wrote:
>> On Mon, May 5, 2014 at 6:25 PM, tip-bot for Andy Lutomirski
>> <tipbot@zytor.com> wrote:
>>> Commit-ID:  6f121e548f83674ab4920a4e60afb58d4f61b829
>>> Gitweb:     http://git.kernel.org/tip/6f121e548f83674ab4920a4e60afb58d4f61b829
>>> Author:     Andy Lutomirski <luto@amacapital.net>
>>> AuthorDate: Mon, 5 May 2014 12:19:34 -0700
>>> Committer:  H. Peter Anvin <hpa@linux.intel.com>
>>> CommitDate: Mon, 5 May 2014 13:18:51 -0700
>>>
>>> x86, vdso: Reimplement vdso.so preparation in build-time C
>>
>> Just a heads up in case it hasn't been mentioned already;
>> the x86 builds in linux-next which IIRC are done as cross
>> compile on a powerpc box are failing as follows:
>>
>>   VDSO2C  arch/x86/vdso/vdso-image-64.c
>> /bin/sh: line 1: 15995 Segmentation fault      arch/x86/vdso/vdso2c
>> arch/x86/vdso/vdso64.so.dbg arch/x86/vdso/vdso-image-64.c
>> make[3]: *** [arch/x86/vdso/vdso-image-64.c] Error 139
>>
>> http://kisskb.ellerman.id.au/kisskb/buildresult/11265454/
>>
>
> Egads.  This wouldn't be a big-endian host by any chance?

Likely if it's really a cross compile on a powerpc machine.  Virtually
all existing powerpc machines are big-endian.

josh

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [tip:x86/vdso] x86, vdso: Reimplement vdso.so preparation in build-time C
  2014-05-29 19:43       ` H. Peter Anvin
@ 2014-05-29 19:46         ` Andy Lutomirski
  2014-05-29 21:57           ` [PATCH 0/2] x86,vdso: vdso build fixes and improvements Andy Lutomirski
  2014-05-30 15:48           ` [PATCH v2 " Andy Lutomirski
  0 siblings, 2 replies; 20+ messages in thread
From: Andy Lutomirski @ 2014-05-29 19:46 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Paul Gortmaker, Ingo Molnar, LKML, tglx@linutronix.de,
	H. Peter Anvin, linux-tip-commits, linux-next@vger.kernel.org

On Thu, May 29, 2014 at 12:43 PM, H. Peter Anvin <hpa@zytor.com> wrote:
> On 05/29/2014 12:32 PM, Andy Lutomirski wrote:
>> On Thu, May 29, 2014 at 12:17 PM, Paul Gortmaker
>> <paul.gortmaker@windriver.com> wrote:
>>> On Mon, May 5, 2014 at 6:25 PM, tip-bot for Andy Lutomirski
>>> <tipbot@zytor.com> wrote:
>>>> Commit-ID:  6f121e548f83674ab4920a4e60afb58d4f61b829
>>>> Gitweb:     http://git.kernel.org/tip/6f121e548f83674ab4920a4e60afb58d4f61b829
>>>> Author:     Andy Lutomirski <luto@amacapital.net>
>>>> AuthorDate: Mon, 5 May 2014 12:19:34 -0700
>>>> Committer:  H. Peter Anvin <hpa@linux.intel.com>
>>>> CommitDate: Mon, 5 May 2014 13:18:51 -0700
>>>>
>>>> x86, vdso: Reimplement vdso.so preparation in build-time C
>>>
>>> Just a heads up in case it hasn't been mentioned already;
>>> the x86 builds in linux-next which IIRC are done as cross
>>> compile on a powerpc box are failing as follows:
>>>
>>>   VDSO2C  arch/x86/vdso/vdso-image-64.c
>>> /bin/sh: line 1: 15995 Segmentation fault      arch/x86/vdso/vdso2c
>>> arch/x86/vdso/vdso64.so.dbg arch/x86/vdso/vdso-image-64.c
>>> make[3]: *** [arch/x86/vdso/vdso-image-64.c] Error 139
>>>
>>> http://kisskb.ellerman.id.au/kisskb/buildresult/11265454/
>>>
>>
>> Egads.  This wouldn't be a big-endian host by any chance?
>>
>
> He said PowerPC; most but not all PowerPC systems are bigendian.  Seems
> like a fair assumption to make.
>

I suppose I shouldn't have assumed that code in arch/x86 would always
run on little-endian machines.  I'll fix it.

--Andy

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 0/2] x86,vdso: vdso build fixes and improvements
  2014-05-29 19:46         ` Andy Lutomirski
@ 2014-05-29 21:57           ` Andy Lutomirski
  2014-05-29 21:57             ` [PATCH 1/2] x86,vdso: When vdso2c fails, unlink the output Andy Lutomirski
                               ` (2 more replies)
  2014-05-30 15:48           ` [PATCH v2 " Andy Lutomirski
  1 sibling, 3 replies; 20+ messages in thread
From: Andy Lutomirski @ 2014-05-29 21:57 UTC (permalink / raw)
  To: Paul Gortmaker, H. Peter Anvin
  Cc: Josh Boyer, Ingo Molnar, LKML, tglx@linutronix.de,
	linux-tip-commits@vger.kernel.org, linux-next@vger.kernel.org,
	Andy Lutomirski

Patch 1 causes make;make to behave similarly to make if vdso2c fails.
Patch 2 hopefully fixes x86 crossbuilds on big-endian machines.  I don't
have a big-endian machine to test on, though.

Andy Lutomirski (2):
  x86,vdso: When vdso2c fails, unlink the output
  x86,vdso: Fix cross-compilation from big-endian architectures

 arch/x86/vdso/vdso2c.c | 35 ++++++++++++++++++-------
 arch/x86/vdso/vdso2c.h | 69 ++++++++++++++++++++++++++------------------------
 2 files changed, 62 insertions(+), 42 deletions(-)

-- 
1.9.3

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 1/2] x86,vdso: When vdso2c fails, unlink the output
  2014-05-29 21:57           ` [PATCH 0/2] x86,vdso: vdso build fixes and improvements Andy Lutomirski
@ 2014-05-29 21:57             ` Andy Lutomirski
  2014-05-29 21:57             ` [PATCH 2/2] x86,vdso: Fix cross-compilation from big-endian architectures Andy Lutomirski
  2014-05-29 22:41             ` [PATCH 0/2] x86,vdso: vdso build fixes and improvements Paul Gortmaker
  2 siblings, 0 replies; 20+ messages in thread
From: Andy Lutomirski @ 2014-05-29 21:57 UTC (permalink / raw)
  To: Paul Gortmaker, H. Peter Anvin
  Cc: Josh Boyer, Ingo Molnar, LKML, tglx@linutronix.de,
	linux-tip-commits@vger.kernel.org, linux-next@vger.kernel.org,
	Andy Lutomirski

This avoids bizarre failures if make is run again.

Signed-off-by: Andy Lutomirski <luto@amacapital.net>
---
 arch/x86/vdso/vdso2c.c | 20 +++++++++++---------
 arch/x86/vdso/vdso2c.h | 10 +++-------
 2 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/arch/x86/vdso/vdso2c.c b/arch/x86/vdso/vdso2c.c
index 81edd1e..fe8bfbf 100644
--- a/arch/x86/vdso/vdso2c.c
+++ b/arch/x86/vdso/vdso2c.c
@@ -14,6 +14,8 @@
 #include <linux/elf.h>
 #include <linux/types.h>
 
+const char *outfilename;
+
 /* Symbols that we need in vdso2c. */
 enum {
 	sym_vvar_page,
@@ -44,6 +46,7 @@ static void fail(const char *format, ...)
 	va_start(ap, format);
 	fprintf(stderr, "Error: ");
 	vfprintf(stderr, format, ap);
+	unlink(outfilename);
 	exit(1);
 	va_end(ap);
 }
@@ -82,17 +85,16 @@ static void fail(const char *format, ...)
 #undef Elf_Sym
 #undef Elf_Dyn
 
-static int go(void *addr, size_t len, FILE *outfile, const char *name)
+static void go(void *addr, size_t len, FILE *outfile, const char *name)
 {
 	Elf64_Ehdr *hdr = (Elf64_Ehdr *)addr;
 
 	if (hdr->e_ident[EI_CLASS] == ELFCLASS64) {
-		return go64(addr, len, outfile, name);
+		go64(addr, len, outfile, name);
 	} else if (hdr->e_ident[EI_CLASS] == ELFCLASS32) {
-		return go32(addr, len, outfile, name);
+		go32(addr, len, outfile, name);
 	} else {
-		fprintf(stderr, "Error: unknown ELF class\n");
-		return 1;
+		fail("unknown ELF class\n");
 	}
 }
 
@@ -102,7 +104,6 @@ int main(int argc, char **argv)
 	off_t len;
 	void *addr;
 	FILE *outfile;
-	int ret;
 	char *name, *tmp;
 	int namelen;
 
@@ -143,14 +144,15 @@ int main(int argc, char **argv)
 	if (addr == MAP_FAILED)
 		err(1, "mmap");
 
-	outfile = fopen(argv[2], "w");
+	outfilename = argv[2];
+	outfile = fopen(outfilename, "w");
 	if (!outfile)
 		err(1, "%s", argv[2]);
 
-	ret = go(addr, (size_t)len, outfile, name);
+	go(addr, (size_t)len, outfile, name);
 
 	munmap(addr, len);
 	fclose(outfile);
 
-	return ret;
+	return 0;
 }
diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h
index 3dcc61e..26a7c1f 100644
--- a/arch/x86/vdso/vdso2c.h
+++ b/arch/x86/vdso/vdso2c.h
@@ -4,7 +4,7 @@
  * are built for 32-bit userspace.
  */
 
-static int GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
+static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 {
 	int found_load = 0;
 	unsigned long load_size = -1;  /* Work around bogus warning */
@@ -62,10 +62,8 @@ static int GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 			alt_sec = sh;
 	}
 
-	if (!symtab_hdr) {
+	if (!symtab_hdr)
 		fail("no symbol table\n");
-		return 1;
-	}
 
 	strtab_hdr = addr + hdr->e_shoff +
 		hdr->e_shentsize * symtab_hdr->sh_link;
@@ -112,7 +110,7 @@ static int GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 
 	if (!name) {
 		fwrite(addr, load_size, 1, outfile);
-		return 0;
+		return;
 	}
 
 	fprintf(outfile, "/* AUTOMATICALLY GENERATED -- DO NOT EDIT */\n\n");
@@ -152,6 +150,4 @@ static int GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 				required_syms[i], syms[i]);
 	}
 	fprintf(outfile, "};\n");
-
-	return 0;
 }
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 2/2] x86,vdso: Fix cross-compilation from big-endian architectures
  2014-05-29 21:57           ` [PATCH 0/2] x86,vdso: vdso build fixes and improvements Andy Lutomirski
  2014-05-29 21:57             ` [PATCH 1/2] x86,vdso: When vdso2c fails, unlink the output Andy Lutomirski
@ 2014-05-29 21:57             ` Andy Lutomirski
  2014-05-29 22:41             ` [PATCH 0/2] x86,vdso: vdso build fixes and improvements Paul Gortmaker
  2 siblings, 0 replies; 20+ messages in thread
From: Andy Lutomirski @ 2014-05-29 21:57 UTC (permalink / raw)
  To: Paul Gortmaker, H. Peter Anvin
  Cc: Josh Boyer, Ingo Molnar, LKML, tglx@linutronix.de,
	linux-tip-commits@vger.kernel.org, linux-next@vger.kernel.org,
	Andy Lutomirski

This adds a macro GET(x) to convert x from big-endian to
little-endian.  Hopefully I put it everywhere it needs to go and got
all the cases needed for everyone's linux/elf.h.

Signed-off-by: Andy Lutomirski <luto@amacapital.net>
---
 arch/x86/vdso/vdso2c.c | 15 +++++++++++++
 arch/x86/vdso/vdso2c.h | 59 ++++++++++++++++++++++++++++----------------------
 2 files changed, 48 insertions(+), 26 deletions(-)

diff --git a/arch/x86/vdso/vdso2c.c b/arch/x86/vdso/vdso2c.c
index fe8bfbf..de19ced 100644
--- a/arch/x86/vdso/vdso2c.c
+++ b/arch/x86/vdso/vdso2c.c
@@ -51,6 +51,21 @@ static void fail(const char *format, ...)
 	va_end(ap);
 }
 
+/*
+ * Evil macros to do a little-endian read.
+ */
+#define __GET_TYPE(x, type, bits, ifnot)				\
+	__builtin_choose_expr(						\
+		__builtin_types_compatible_p(typeof(x), type),		\
+		le##bits##toh((x)), ifnot)
+
+extern void bad_get(uint64_t);
+
+#define GET(x)								\
+	__GET_TYPE((x), __u32, 32, __GET_TYPE((x), __u64, 64,		\
+	__GET_TYPE((x), __s32, 32, __GET_TYPE((x), __s64, 64,		\
+	__GET_TYPE((x), __u16, 16, bad_get(x))))))
+
 #define NSYMS (sizeof(required_syms) / sizeof(required_syms[0]))
 
 #define BITS 64
diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h
index 26a7c1f..dadecb9 100644
--- a/arch/x86/vdso/vdso2c.h
+++ b/arch/x86/vdso/vdso2c.h
@@ -18,25 +18,27 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 	const char *secstrings;
 	uint64_t syms[NSYMS] = {};
 
-	Elf_Phdr *pt = (Elf_Phdr *)(addr + hdr->e_phoff);
+	Elf_Phdr *pt = (Elf_Phdr *)(addr + GET(hdr->e_phoff));
 
 	/* Walk the segment table. */
-	for (i = 0; i < hdr->e_phnum; i++) {
-		if (pt[i].p_type == PT_LOAD) {
+	for (i = 0; i < GET(hdr->e_phnum); i++) {
+		if (GET(pt[i].p_type) == PT_LOAD) {
 			if (found_load)
 				fail("multiple PT_LOAD segs\n");
 
-			if (pt[i].p_offset != 0 || pt[i].p_vaddr != 0)
+			if (GET(pt[i].p_offset) != 0 ||
+			    GET(pt[i].p_vaddr) != 0)
 				fail("PT_LOAD in wrong place\n");
 
-			if (pt[i].p_memsz != pt[i].p_filesz)
+			if (GET(pt[i].p_memsz) != GET(pt[i].p_filesz))
 				fail("cannot handle memsz != filesz\n");
 
-			load_size = pt[i].p_memsz;
+			load_size = GET(pt[i].p_memsz);
 			found_load = 1;
-		} else if (pt[i].p_type == PT_DYNAMIC) {
-			dyn = addr + pt[i].p_offset;
-			dyn_end = addr + pt[i].p_offset + pt[i].p_memsz;
+		} else if (GET(pt[i].p_type) == PT_DYNAMIC) {
+			dyn = addr + GET(pt[i].p_offset);
+			dyn_end = addr + GET(pt[i].p_offset) +
+				GET(pt[i].p_memsz);
 		}
 	}
 	if (!found_load)
@@ -44,43 +46,48 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 	data_size = (load_size + 4095) / 4096 * 4096;
 
 	/* Walk the dynamic table */
-	for (i = 0; dyn + i < dyn_end && dyn[i].d_tag != DT_NULL; i++) {
-		if (dyn[i].d_tag == DT_REL || dyn[i].d_tag == DT_RELSZ ||
-		    dyn[i].d_tag == DT_RELENT || dyn[i].d_tag == DT_TEXTREL)
+	for (i = 0; dyn + i < dyn_end && GET(dyn[i].d_tag) != DT_NULL; i++) {
+		typeof(dyn[i].d_tag) tag = GET(dyn[i].d_tag);
+		if (tag == DT_REL || tag == DT_RELSZ ||
+		    tag == DT_RELENT || tag == DT_TEXTREL)
 			fail("vdso image contains dynamic relocations\n");
 	}
 
 	/* Walk the section table */
-	secstrings_hdr = addr + hdr->e_shoff + hdr->e_shentsize*hdr->e_shstrndx;
-	secstrings = addr + secstrings_hdr->sh_offset;
-	for (i = 0; i < hdr->e_shnum; i++) {
-		Elf_Shdr *sh = addr + hdr->e_shoff + hdr->e_shentsize * i;
-		if (sh->sh_type == SHT_SYMTAB)
+	secstrings_hdr = addr + GET(hdr->e_shoff) +
+		GET(hdr->e_shentsize)*GET(hdr->e_shstrndx);
+	secstrings = addr + GET(secstrings_hdr->sh_offset);
+	for (i = 0; i < GET(hdr->e_shnum); i++) {
+		Elf_Shdr *sh = addr + GET(hdr->e_shoff) +
+			GET(hdr->e_shentsize) * i;
+		if (GET(sh->sh_type) == SHT_SYMTAB)
 			symtab_hdr = sh;
 
-		if (!strcmp(secstrings + sh->sh_name, ".altinstructions"))
+		if (!strcmp(secstrings + GET(sh->sh_name), ".altinstructions"))
 			alt_sec = sh;
 	}
 
 	if (!symtab_hdr)
 		fail("no symbol table\n");
 
-	strtab_hdr = addr + hdr->e_shoff +
-		hdr->e_shentsize * symtab_hdr->sh_link;
+	strtab_hdr = addr + GET(hdr->e_shoff) +
+		GET(hdr->e_shentsize) * GET(symtab_hdr->sh_link);
 
 	/* Walk the symbol table */
-	for (i = 0; i < symtab_hdr->sh_size / symtab_hdr->sh_entsize; i++) {
+	for (i = 0; i < GET(symtab_hdr->sh_size) / GET(symtab_hdr->sh_entsize);
+	     i++) {
 		int k;
-		Elf_Sym *sym = addr + symtab_hdr->sh_offset +
-			symtab_hdr->sh_entsize * i;
-		const char *name = addr + strtab_hdr->sh_offset + sym->st_name;
+		Elf_Sym *sym = addr + GET(symtab_hdr->sh_offset) +
+			GET(symtab_hdr->sh_entsize) * i;
+		const char *name = addr + GET(strtab_hdr->sh_offset) +
+			GET(sym->st_name);
 		for (k = 0; k < NSYMS; k++) {
 			if (!strcmp(name, required_syms[k])) {
 				if (syms[k]) {
 					fail("duplicate symbol %s\n",
 					     required_syms[k]);
 				}
-				syms[k] = sym->st_value;
+				syms[k] = GET(sym->st_value);
 			}
 		}
 	}
@@ -106,7 +113,7 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 	hdr->e_shoff = 0;
 	hdr->e_shentsize = 0;
 	hdr->e_shnum = 0;
-	hdr->e_shstrndx = SHN_UNDEF;
+	hdr->e_shstrndx = htole16(SHN_UNDEF);
 
 	if (!name) {
 		fwrite(addr, load_size, 1, outfile);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH 0/2] x86,vdso: vdso build fixes and improvements
  2014-05-29 21:57           ` [PATCH 0/2] x86,vdso: vdso build fixes and improvements Andy Lutomirski
  2014-05-29 21:57             ` [PATCH 1/2] x86,vdso: When vdso2c fails, unlink the output Andy Lutomirski
  2014-05-29 21:57             ` [PATCH 2/2] x86,vdso: Fix cross-compilation from big-endian architectures Andy Lutomirski
@ 2014-05-29 22:41             ` Paul Gortmaker
  2014-05-29 22:49               ` Andy Lutomirski
  2 siblings, 1 reply; 20+ messages in thread
From: Paul Gortmaker @ 2014-05-29 22:41 UTC (permalink / raw)
  To: Andy Lutomirski, H. Peter Anvin
  Cc: Josh Boyer, Ingo Molnar, LKML, tglx@linutronix.de,
	linux-tip-commits@vger.kernel.org, linux-next@vger.kernel.org,
	Stephen Rothwell

On 14-05-29 05:57 PM, Andy Lutomirski wrote:
> Patch 1 causes make;make to behave similarly to make if vdso2c fails.
> Patch 2 hopefully fixes x86 crossbuilds on big-endian machines.  I don't
> have a big-endian machine to test on, though.

Since the x86 builds are unconditionally failing as-is now in
linux-next, perhaps Stephen [Cc'd] can layer these on the top of
the tree he'll be making within the next couple of hours to give
them a big-endian test.

Paul.
--

> 
> Andy Lutomirski (2):
>   x86,vdso: When vdso2c fails, unlink the output
>   x86,vdso: Fix cross-compilation from big-endian architectures
> 
>  arch/x86/vdso/vdso2c.c | 35 ++++++++++++++++++-------
>  arch/x86/vdso/vdso2c.h | 69 ++++++++++++++++++++++++++------------------------
>  2 files changed, 62 insertions(+), 42 deletions(-)
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 0/2] x86,vdso: vdso build fixes and improvements
  2014-05-29 22:41             ` [PATCH 0/2] x86,vdso: vdso build fixes and improvements Paul Gortmaker
@ 2014-05-29 22:49               ` Andy Lutomirski
  2014-05-30  5:42                 ` Stephen Rothwell
  0 siblings, 1 reply; 20+ messages in thread
From: Andy Lutomirski @ 2014-05-29 22:49 UTC (permalink / raw)
  To: Paul Gortmaker
  Cc: H. Peter Anvin, Josh Boyer, Ingo Molnar, LKML, tglx@linutronix.de,
	linux-tip-commits@vger.kernel.org, linux-next@vger.kernel.org,
	Stephen Rothwell

On Thu, May 29, 2014 at 3:41 PM, Paul Gortmaker
<paul.gortmaker@windriver.com> wrote:
> On 14-05-29 05:57 PM, Andy Lutomirski wrote:
>> Patch 1 causes make;make to behave similarly to make if vdso2c fails.
>> Patch 2 hopefully fixes x86 crossbuilds on big-endian machines.  I don't
>> have a big-endian machine to test on, though.
>
> Since the x86 builds are unconditionally failing as-is now in
> linux-next, perhaps Stephen [Cc'd] can layer these on the top of
> the tree he'll be making within the next couple of hours to give
> them a big-endian test.

Stephen, if you do this, could you also send me some of the build outputs:

arch/x86/vdso/*.so.dbg
arch/x86/vdso/*-image-*.c

I'd like to verify that the output is correct.  It would be
unfortunate if the cross-built kernel had some subtle error.

Thanks,
Andy

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 0/2] x86,vdso: vdso build fixes and improvements
  2014-05-29 22:49               ` Andy Lutomirski
@ 2014-05-30  5:42                 ` Stephen Rothwell
  2014-05-30 15:40                   ` Andy Lutomirski
  0 siblings, 1 reply; 20+ messages in thread
From: Stephen Rothwell @ 2014-05-30  5:42 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: Paul Gortmaker, H. Peter Anvin, Josh Boyer, Ingo Molnar, LKML,
	tglx@linutronix.de, linux-tip-commits@vger.kernel.org,
	linux-next@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 1220 bytes --]

Hi Andy,

On Thu, 29 May 2014 15:49:52 -0700 Andy Lutomirski <luto@amacapital.net> wrote:
>
> On Thu, May 29, 2014 at 3:41 PM, Paul Gortmaker
> <paul.gortmaker@windriver.com> wrote:
> > On 14-05-29 05:57 PM, Andy Lutomirski wrote:
> >> Patch 1 causes make;make to behave similarly to make if vdso2c fails.
> >> Patch 2 hopefully fixes x86 crossbuilds on big-endian machines.  I don't
> >> have a big-endian machine to test on, though.
> >
> > Since the x86 builds are unconditionally failing as-is now in
> > linux-next, perhaps Stephen [Cc'd] can layer these on the top of
> > the tree he'll be making within the next couple of hours to give
> > them a big-endian test.

I added them just after the merge of the tip tree today and will keep
them there until they (or somo other solution) turn up some other way.

> Stephen, if you do this, could you also send me some of the build outputs:
> 
> arch/x86/vdso/*.so.dbg
> arch/x86/vdso/*-image-*.c
> 
> I'd like to verify that the output is correct.  It would be
> unfortunate if the cross-built kernel had some subtle error.

OK, I will send them in a separate email.

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 0/2] x86,vdso: vdso build fixes and improvements
  2014-05-30  5:42                 ` Stephen Rothwell
@ 2014-05-30 15:40                   ` Andy Lutomirski
  0 siblings, 0 replies; 20+ messages in thread
From: Andy Lutomirski @ 2014-05-30 15:40 UTC (permalink / raw)
  To: Stephen Rothwell
  Cc: Paul Gortmaker, H. Peter Anvin, Josh Boyer, Ingo Molnar, LKML,
	tglx@linutronix.de, linux-tip-commits@vger.kernel.org,
	linux-next@vger.kernel.org

On Thu, May 29, 2014 at 10:42 PM, Stephen Rothwell <sfr@canb.auug.org.au> wrote:
> Hi Andy,
>
> On Thu, 29 May 2014 15:49:52 -0700 Andy Lutomirski <luto@amacapital.net> wrote:
>>
>> On Thu, May 29, 2014 at 3:41 PM, Paul Gortmaker
>> <paul.gortmaker@windriver.com> wrote:
>> > On 14-05-29 05:57 PM, Andy Lutomirski wrote:
>> >> Patch 1 causes make;make to behave similarly to make if vdso2c fails.
>> >> Patch 2 hopefully fixes x86 crossbuilds on big-endian machines.  I don't
>> >> have a big-endian machine to test on, though.
>> >
>> > Since the x86 builds are unconditionally failing as-is now in
>> > linux-next, perhaps Stephen [Cc'd] can layer these on the top of
>> > the tree he'll be making within the next couple of hours to give
>> > them a big-endian test.
>
> I added them just after the merge of the tip tree today and will keep
> them there until they (or somo other solution) turn up some other way.
>
>> Stephen, if you do this, could you also send me some of the build outputs:
>>
>> arch/x86/vdso/*.so.dbg
>> arch/x86/vdso/*-image-*.c
>>
>> I'd like to verify that the output is correct.  It would be
>> unfortunate if the cross-built kernel had some subtle error.
>
> OK, I will send them in a separate email.

For the benefit of the archives: the patches are bad.  New ones coming.

--Andy

>
> --
> Cheers,
> Stephen Rothwell                    sfr@canb.auug.org.au



-- 
Andy Lutomirski
AMA Capital Management, LLC

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v2 0/2] x86,vdso: vdso build fixes and improvements
  2014-05-29 19:46         ` Andy Lutomirski
  2014-05-29 21:57           ` [PATCH 0/2] x86,vdso: vdso build fixes and improvements Andy Lutomirski
@ 2014-05-30 15:48           ` Andy Lutomirski
  2014-05-30 15:48             ` [PATCH v2 1/2] x86,vdso: When vdso2c fails, unlink the output Andy Lutomirski
  2014-05-30 15:48             ` [PATCH v2 2/2] x86,vdso: Fix cross-compilation from big-endian architectures Andy Lutomirski
  1 sibling, 2 replies; 20+ messages in thread
From: Andy Lutomirski @ 2014-05-30 15:48 UTC (permalink / raw)
  To: Paul Gortmaker, H. Peter Anvin
  Cc: Josh Boyer, Ingo Molnar, LKML, tglx@linutronix.de,
	linux-tip-commits@vger.kernel.org, linux-next@vger.kernel.org,
	Andy Lutomirski

Patch 1 causes make;make to behave similarly to make if vdso2c fails.
Patch 2 hopefully fixes x86 crossbuilds on big-endian machines.  I don't
have a big-endian machine to test on, though.

Changes from v1: Add two missing endian fixes

Andy Lutomirski (2):
  x86,vdso: When vdso2c fails, unlink the output
  x86,vdso: Fix cross-compilation from big-endian architectures

 arch/x86/vdso/vdso2c.c | 35 +++++++++++++++++-------
 arch/x86/vdso/vdso2c.h | 73 ++++++++++++++++++++++++++------------------------
 2 files changed, 64 insertions(+), 44 deletions(-)

-- 
1.9.3

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v2 1/2] x86,vdso: When vdso2c fails, unlink the output
  2014-05-30 15:48           ` [PATCH v2 " Andy Lutomirski
@ 2014-05-30 15:48             ` Andy Lutomirski
  2014-05-30 15:48             ` [PATCH v2 2/2] x86,vdso: Fix cross-compilation from big-endian architectures Andy Lutomirski
  1 sibling, 0 replies; 20+ messages in thread
From: Andy Lutomirski @ 2014-05-30 15:48 UTC (permalink / raw)
  To: Paul Gortmaker, H. Peter Anvin
  Cc: Josh Boyer, Ingo Molnar, LKML, tglx@linutronix.de,
	linux-tip-commits@vger.kernel.org, linux-next@vger.kernel.org,
	Andy Lutomirski

This avoids bizarre failures if make is run again.

Signed-off-by: Andy Lutomirski <luto@amacapital.net>
---
 arch/x86/vdso/vdso2c.c | 20 +++++++++++---------
 arch/x86/vdso/vdso2c.h | 10 +++-------
 2 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/arch/x86/vdso/vdso2c.c b/arch/x86/vdso/vdso2c.c
index 81edd1e..fe8bfbf 100644
--- a/arch/x86/vdso/vdso2c.c
+++ b/arch/x86/vdso/vdso2c.c
@@ -14,6 +14,8 @@
 #include <linux/elf.h>
 #include <linux/types.h>
 
+const char *outfilename;
+
 /* Symbols that we need in vdso2c. */
 enum {
 	sym_vvar_page,
@@ -44,6 +46,7 @@ static void fail(const char *format, ...)
 	va_start(ap, format);
 	fprintf(stderr, "Error: ");
 	vfprintf(stderr, format, ap);
+	unlink(outfilename);
 	exit(1);
 	va_end(ap);
 }
@@ -82,17 +85,16 @@ static void fail(const char *format, ...)
 #undef Elf_Sym
 #undef Elf_Dyn
 
-static int go(void *addr, size_t len, FILE *outfile, const char *name)
+static void go(void *addr, size_t len, FILE *outfile, const char *name)
 {
 	Elf64_Ehdr *hdr = (Elf64_Ehdr *)addr;
 
 	if (hdr->e_ident[EI_CLASS] == ELFCLASS64) {
-		return go64(addr, len, outfile, name);
+		go64(addr, len, outfile, name);
 	} else if (hdr->e_ident[EI_CLASS] == ELFCLASS32) {
-		return go32(addr, len, outfile, name);
+		go32(addr, len, outfile, name);
 	} else {
-		fprintf(stderr, "Error: unknown ELF class\n");
-		return 1;
+		fail("unknown ELF class\n");
 	}
 }
 
@@ -102,7 +104,6 @@ int main(int argc, char **argv)
 	off_t len;
 	void *addr;
 	FILE *outfile;
-	int ret;
 	char *name, *tmp;
 	int namelen;
 
@@ -143,14 +144,15 @@ int main(int argc, char **argv)
 	if (addr == MAP_FAILED)
 		err(1, "mmap");
 
-	outfile = fopen(argv[2], "w");
+	outfilename = argv[2];
+	outfile = fopen(outfilename, "w");
 	if (!outfile)
 		err(1, "%s", argv[2]);
 
-	ret = go(addr, (size_t)len, outfile, name);
+	go(addr, (size_t)len, outfile, name);
 
 	munmap(addr, len);
 	fclose(outfile);
 
-	return ret;
+	return 0;
 }
diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h
index 3dcc61e..26a7c1f 100644
--- a/arch/x86/vdso/vdso2c.h
+++ b/arch/x86/vdso/vdso2c.h
@@ -4,7 +4,7 @@
  * are built for 32-bit userspace.
  */
 
-static int GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
+static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 {
 	int found_load = 0;
 	unsigned long load_size = -1;  /* Work around bogus warning */
@@ -62,10 +62,8 @@ static int GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 			alt_sec = sh;
 	}
 
-	if (!symtab_hdr) {
+	if (!symtab_hdr)
 		fail("no symbol table\n");
-		return 1;
-	}
 
 	strtab_hdr = addr + hdr->e_shoff +
 		hdr->e_shentsize * symtab_hdr->sh_link;
@@ -112,7 +110,7 @@ static int GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 
 	if (!name) {
 		fwrite(addr, load_size, 1, outfile);
-		return 0;
+		return;
 	}
 
 	fprintf(outfile, "/* AUTOMATICALLY GENERATED -- DO NOT EDIT */\n\n");
@@ -152,6 +150,4 @@ static int GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 				required_syms[i], syms[i]);
 	}
 	fprintf(outfile, "};\n");
-
-	return 0;
 }
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v2 2/2] x86,vdso: Fix cross-compilation from big-endian architectures
  2014-05-30 15:48           ` [PATCH v2 " Andy Lutomirski
  2014-05-30 15:48             ` [PATCH v2 1/2] x86,vdso: When vdso2c fails, unlink the output Andy Lutomirski
@ 2014-05-30 15:48             ` Andy Lutomirski
  2014-05-30 20:02               ` H. Peter Anvin
  1 sibling, 1 reply; 20+ messages in thread
From: Andy Lutomirski @ 2014-05-30 15:48 UTC (permalink / raw)
  To: Paul Gortmaker, H. Peter Anvin
  Cc: Josh Boyer, Ingo Molnar, LKML, tglx@linutronix.de,
	linux-tip-commits@vger.kernel.org, linux-next@vger.kernel.org,
	Andy Lutomirski

This adds a macro GET(x) to convert x from big-endian to
little-endian.  Hopefully I put it everywhere it needs to go and got
all the cases needed for everyone's linux/elf.h.

Signed-off-by: Andy Lutomirski <luto@amacapital.net>
---
 arch/x86/vdso/vdso2c.c | 15 ++++++++++++
 arch/x86/vdso/vdso2c.h | 63 ++++++++++++++++++++++++++++----------------------
 2 files changed, 50 insertions(+), 28 deletions(-)

diff --git a/arch/x86/vdso/vdso2c.c b/arch/x86/vdso/vdso2c.c
index fe8bfbf..de19ced 100644
--- a/arch/x86/vdso/vdso2c.c
+++ b/arch/x86/vdso/vdso2c.c
@@ -51,6 +51,21 @@ static void fail(const char *format, ...)
 	va_end(ap);
 }
 
+/*
+ * Evil macros to do a little-endian read.
+ */
+#define __GET_TYPE(x, type, bits, ifnot)				\
+	__builtin_choose_expr(						\
+		__builtin_types_compatible_p(typeof(x), type),		\
+		le##bits##toh((x)), ifnot)
+
+extern void bad_get(uint64_t);
+
+#define GET(x)								\
+	__GET_TYPE((x), __u32, 32, __GET_TYPE((x), __u64, 64,		\
+	__GET_TYPE((x), __s32, 32, __GET_TYPE((x), __s64, 64,		\
+	__GET_TYPE((x), __u16, 16, bad_get(x))))))
+
 #define NSYMS (sizeof(required_syms) / sizeof(required_syms[0]))
 
 #define BITS 64
diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h
index 26a7c1f..f0475da 100644
--- a/arch/x86/vdso/vdso2c.h
+++ b/arch/x86/vdso/vdso2c.h
@@ -18,25 +18,27 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 	const char *secstrings;
 	uint64_t syms[NSYMS] = {};
 
-	Elf_Phdr *pt = (Elf_Phdr *)(addr + hdr->e_phoff);
+	Elf_Phdr *pt = (Elf_Phdr *)(addr + GET(hdr->e_phoff));
 
 	/* Walk the segment table. */
-	for (i = 0; i < hdr->e_phnum; i++) {
-		if (pt[i].p_type == PT_LOAD) {
+	for (i = 0; i < GET(hdr->e_phnum); i++) {
+		if (GET(pt[i].p_type) == PT_LOAD) {
 			if (found_load)
 				fail("multiple PT_LOAD segs\n");
 
-			if (pt[i].p_offset != 0 || pt[i].p_vaddr != 0)
+			if (GET(pt[i].p_offset) != 0 ||
+			    GET(pt[i].p_vaddr) != 0)
 				fail("PT_LOAD in wrong place\n");
 
-			if (pt[i].p_memsz != pt[i].p_filesz)
+			if (GET(pt[i].p_memsz) != GET(pt[i].p_filesz))
 				fail("cannot handle memsz != filesz\n");
 
-			load_size = pt[i].p_memsz;
+			load_size = GET(pt[i].p_memsz);
 			found_load = 1;
-		} else if (pt[i].p_type == PT_DYNAMIC) {
-			dyn = addr + pt[i].p_offset;
-			dyn_end = addr + pt[i].p_offset + pt[i].p_memsz;
+		} else if (GET(pt[i].p_type) == PT_DYNAMIC) {
+			dyn = addr + GET(pt[i].p_offset);
+			dyn_end = addr + GET(pt[i].p_offset) +
+				GET(pt[i].p_memsz);
 		}
 	}
 	if (!found_load)
@@ -44,43 +46,48 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 	data_size = (load_size + 4095) / 4096 * 4096;
 
 	/* Walk the dynamic table */
-	for (i = 0; dyn + i < dyn_end && dyn[i].d_tag != DT_NULL; i++) {
-		if (dyn[i].d_tag == DT_REL || dyn[i].d_tag == DT_RELSZ ||
-		    dyn[i].d_tag == DT_RELENT || dyn[i].d_tag == DT_TEXTREL)
+	for (i = 0; dyn + i < dyn_end && GET(dyn[i].d_tag) != DT_NULL; i++) {
+		typeof(dyn[i].d_tag) tag = GET(dyn[i].d_tag);
+		if (tag == DT_REL || tag == DT_RELSZ ||
+		    tag == DT_RELENT || tag == DT_TEXTREL)
 			fail("vdso image contains dynamic relocations\n");
 	}
 
 	/* Walk the section table */
-	secstrings_hdr = addr + hdr->e_shoff + hdr->e_shentsize*hdr->e_shstrndx;
-	secstrings = addr + secstrings_hdr->sh_offset;
-	for (i = 0; i < hdr->e_shnum; i++) {
-		Elf_Shdr *sh = addr + hdr->e_shoff + hdr->e_shentsize * i;
-		if (sh->sh_type == SHT_SYMTAB)
+	secstrings_hdr = addr + GET(hdr->e_shoff) +
+		GET(hdr->e_shentsize)*GET(hdr->e_shstrndx);
+	secstrings = addr + GET(secstrings_hdr->sh_offset);
+	for (i = 0; i < GET(hdr->e_shnum); i++) {
+		Elf_Shdr *sh = addr + GET(hdr->e_shoff) +
+			GET(hdr->e_shentsize) * i;
+		if (GET(sh->sh_type) == SHT_SYMTAB)
 			symtab_hdr = sh;
 
-		if (!strcmp(secstrings + sh->sh_name, ".altinstructions"))
+		if (!strcmp(secstrings + GET(sh->sh_name), ".altinstructions"))
 			alt_sec = sh;
 	}
 
 	if (!symtab_hdr)
 		fail("no symbol table\n");
 
-	strtab_hdr = addr + hdr->e_shoff +
-		hdr->e_shentsize * symtab_hdr->sh_link;
+	strtab_hdr = addr + GET(hdr->e_shoff) +
+		GET(hdr->e_shentsize) * GET(symtab_hdr->sh_link);
 
 	/* Walk the symbol table */
-	for (i = 0; i < symtab_hdr->sh_size / symtab_hdr->sh_entsize; i++) {
+	for (i = 0; i < GET(symtab_hdr->sh_size) / GET(symtab_hdr->sh_entsize);
+	     i++) {
 		int k;
-		Elf_Sym *sym = addr + symtab_hdr->sh_offset +
-			symtab_hdr->sh_entsize * i;
-		const char *name = addr + strtab_hdr->sh_offset + sym->st_name;
+		Elf_Sym *sym = addr + GET(symtab_hdr->sh_offset) +
+			GET(symtab_hdr->sh_entsize) * i;
+		const char *name = addr + GET(strtab_hdr->sh_offset) +
+			GET(sym->st_name);
 		for (k = 0; k < NSYMS; k++) {
 			if (!strcmp(name, required_syms[k])) {
 				if (syms[k]) {
 					fail("duplicate symbol %s\n",
 					     required_syms[k]);
 				}
-				syms[k] = sym->st_value;
+				syms[k] = GET(sym->st_value);
 			}
 		}
 	}
@@ -106,7 +113,7 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 	hdr->e_shoff = 0;
 	hdr->e_shentsize = 0;
 	hdr->e_shnum = 0;
-	hdr->e_shstrndx = SHN_UNDEF;
+	hdr->e_shstrndx = htole16(SHN_UNDEF);
 
 	if (!name) {
 		fwrite(addr, load_size, 1, outfile);
@@ -140,9 +147,9 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 	fprintf(outfile, "\t},\n");
 	if (alt_sec) {
 		fprintf(outfile, "\t.alt = %lu,\n",
-			(unsigned long)alt_sec->sh_offset);
+			(unsigned long)GET(alt_sec->sh_offset));
 		fprintf(outfile, "\t.alt_len = %lu,\n",
-			(unsigned long)alt_sec->sh_size);
+			(unsigned long)GET(alt_sec->sh_size));
 	}
 	for (i = 0; i < NSYMS; i++) {
 		if (syms[i])
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH v2 2/2] x86,vdso: Fix cross-compilation from big-endian architectures
  2014-05-30 15:48             ` [PATCH v2 2/2] x86,vdso: Fix cross-compilation from big-endian architectures Andy Lutomirski
@ 2014-05-30 20:02               ` H. Peter Anvin
  2014-05-30 20:09                 ` Andy Lutomirski
  0 siblings, 1 reply; 20+ messages in thread
From: H. Peter Anvin @ 2014-05-30 20:02 UTC (permalink / raw)
  To: Andy Lutomirski, Paul Gortmaker
  Cc: Josh Boyer, Ingo Molnar, LKML, tglx@linutronix.de,
	linux-tip-commits@vger.kernel.org, linux-next@vger.kernel.org

On 05/30/2014 08:48 AM, Andy Lutomirski wrote:
> This adds a macro GET(x) to convert x from big-endian to
> little-endian.  Hopefully I put it everywhere it needs to go and got
> all the cases needed for everyone's linux/elf.h.
> 
> Signed-off-by: Andy Lutomirski <luto@amacapital.net>
> ---
>  arch/x86/vdso/vdso2c.c | 15 ++++++++++++
>  arch/x86/vdso/vdso2c.h | 63 ++++++++++++++++++++++++++++----------------------
>  2 files changed, 50 insertions(+), 28 deletions(-)

A couple of observations:

1. We shouldn't use double-underscore in host C code.

2. It would be nice if we can take these sort of things (host-build
   helper macros) and move them to some common file in the Linux kernel
   eventually, so it would be a good thing to make the naming a little
   less general.

3. Even though it isn't necessary, making it work on 8-bit values so
   one doesn't have to worry about the type would seem like a good
   thing.

I came up with the following, it seems like a reasonable simplification:

> #define _LE(x, bits, ifnot)						\
> 	__builtin_choose_expr(						\
> 		(sizeof(x) == bits/8),					\
> 		(__typeof__(x))le##bits##toh(x), ifnot)
> 
> extern void bad_le(uint64_t);
> #define _LAST_LE(x)							\
> 	__builtin_choose_expr(sizeof(x) == 1, (x), bad_le(x))
> 
> #define LE(x)								\
> 	_LE(x, 64, _LE(x, 32, _LE(x, 16, _LAST_LE(x))))

What do you think?

	-hpa

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v2 2/2] x86,vdso: Fix cross-compilation from big-endian architectures
  2014-05-30 20:02               ` H. Peter Anvin
@ 2014-05-30 20:09                 ` Andy Lutomirski
  2014-05-30 20:21                   ` H. Peter Anvin
  0 siblings, 1 reply; 20+ messages in thread
From: Andy Lutomirski @ 2014-05-30 20:09 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Paul Gortmaker, Josh Boyer, Ingo Molnar, LKML, tglx@linutronix.de,
	linux-tip-commits@vger.kernel.org, linux-next@vger.kernel.org

On Fri, May 30, 2014 at 1:02 PM, H. Peter Anvin <hpa@zytor.com> wrote:
> On 05/30/2014 08:48 AM, Andy Lutomirski wrote:
>> This adds a macro GET(x) to convert x from big-endian to
>> little-endian.  Hopefully I put it everywhere it needs to go and got
>> all the cases needed for everyone's linux/elf.h.
>>
>> Signed-off-by: Andy Lutomirski <luto@amacapital.net>
>> ---
>>  arch/x86/vdso/vdso2c.c | 15 ++++++++++++
>>  arch/x86/vdso/vdso2c.h | 63 ++++++++++++++++++++++++++++----------------------
>>  2 files changed, 50 insertions(+), 28 deletions(-)
>
> A couple of observations:
>
> 1. We shouldn't use double-underscore in host C code.
>
> 2. It would be nice if we can take these sort of things (host-build
>    helper macros) and move them to some common file in the Linux kernel
>    eventually, so it would be a good thing to make the naming a little
>    less general.
>
> 3. Even though it isn't necessary, making it work on 8-bit values so
>    one doesn't have to worry about the type would seem like a good
>    thing.
>
> I came up with the following, it seems like a reasonable simplification:
>
>> #define _LE(x, bits, ifnot)                                           \
>>       __builtin_choose_expr(                                          \
>>               (sizeof(x) == bits/8),                                  \
>>               (__typeof__(x))le##bits##toh(x), ifnot)

This will do awful things if x is a floating-point type, and, for
integers, the cast is probably unnecessary.  But it should be okay.

>>
>> extern void bad_le(uint64_t);

If this ever goes in a common header, then we should do the
__attribute__((error)) thing.  I wonder if it would ever make sense to
have __LINUX_HOSTPROG__ and make some of the basic headers work.  Hmm.

>> #define _LAST_LE(x)                                                   \
>>       __builtin_choose_expr(sizeof(x) == 1, (x), bad_le(x))
>>
>> #define LE(x)                                                         \
>>       _LE(x, 64, _LE(x, 32, _LE(x, 16, _LAST_LE(x))))
>
> What do you think?

My only real real objection is that _LE sounds like converting *to*
little-endian to me.  Admittedly, that's the same thing on any
remotely sane architecture, but still.

--Andy

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v2 2/2] x86,vdso: Fix cross-compilation from big-endian architectures
  2014-05-30 20:09                 ` Andy Lutomirski
@ 2014-05-30 20:21                   ` H. Peter Anvin
  2014-05-30 20:34                     ` Andy Lutomirski
  0 siblings, 1 reply; 20+ messages in thread
From: H. Peter Anvin @ 2014-05-30 20:21 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: Paul Gortmaker, Josh Boyer, Ingo Molnar, LKML, tglx@linutronix.de,
	linux-tip-commits@vger.kernel.org, linux-next@vger.kernel.org

On 05/30/2014 01:09 PM, Andy Lutomirski wrote:
>>
>> I came up with the following, it seems like a reasonable simplification:
>>
>>> #define _LE(x, bits, ifnot)                                           \
>>>       __builtin_choose_expr(                                          \
>>>               (sizeof(x) == bits/8),                                  \
>>>               (__typeof__(x))le##bits##toh(x), ifnot)
> 
> This will do awful things if x is a floating-point type, and, for
> integers, the cast is probably unnecessary.  But it should be okay.
> 

I mostly wanted to preserve the signedness.  Yes, if we care about
floating-point it gets trickier.

At some point hopefully there will be a native C feature to handle this
crap.

>>> extern void bad_le(uint64_t);
> 
> If this ever goes in a common header, then we should do the
> __attribute__((error)) thing.  I wonder if it would ever make sense to
> have __LINUX_HOSTPROG__ and make some of the basic headers work.  Hmm.
> 
>>> #define _LAST_LE(x)                                                   \
>>>       __builtin_choose_expr(sizeof(x) == 1, (x), bad_le(x))
>>>
>>> #define LE(x)                                                         \
>>>       _LE(x, 64, _LE(x, 32, _LE(x, 16, _LAST_LE(x))))
>>
>> What do you think?
> 
> My only real real objection is that _LE sounds like converting *to*
> little-endian to me.  Admittedly, that's the same thing on any
> remotely sane architecture, but still.

GET_LE() then?

	-hpa

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v2 2/2] x86,vdso: Fix cross-compilation from big-endian architectures
  2014-05-30 20:21                   ` H. Peter Anvin
@ 2014-05-30 20:34                     ` Andy Lutomirski
  2014-05-31  0:14                       ` H. Peter Anvin
  0 siblings, 1 reply; 20+ messages in thread
From: Andy Lutomirski @ 2014-05-30 20:34 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Paul Gortmaker, Josh Boyer, Ingo Molnar, LKML, tglx@linutronix.de,
	linux-tip-commits@vger.kernel.org, linux-next@vger.kernel.org

On Fri, May 30, 2014 at 1:21 PM, H. Peter Anvin <hpa@zytor.com> wrote:
> On 05/30/2014 01:09 PM, Andy Lutomirski wrote:
>>>
>>> I came up with the following, it seems like a reasonable simplification:
>>>
>>>> #define _LE(x, bits, ifnot)                                           \
>>>>       __builtin_choose_expr(                                          \
>>>>               (sizeof(x) == bits/8),                                  \
>>>>               (__typeof__(x))le##bits##toh(x), ifnot)
>>
>> This will do awful things if x is a floating-point type, and, for
>> integers, the cast is probably unnecessary.  But it should be okay.
>>
>
> I mostly wanted to preserve the signedness.  Yes, if we care about
> floating-point it gets trickier.
>
> At some point hopefully there will be a native C feature to handle this
> crap.
>
>>>> extern void bad_le(uint64_t);
>>
>> If this ever goes in a common header, then we should do the
>> __attribute__((error)) thing.  I wonder if it would ever make sense to
>> have __LINUX_HOSTPROG__ and make some of the basic headers work.  Hmm.
>>
>>>> #define _LAST_LE(x)                                                   \
>>>>       __builtin_choose_expr(sizeof(x) == 1, (x), bad_le(x))
>>>>
>>>> #define LE(x)                                                         \
>>>>       _LE(x, 64, _LE(x, 32, _LE(x, 16, _LAST_LE(x))))
>>>
>>> What do you think?
>>
>> My only real real objection is that _LE sounds like converting *to*
>> little-endian to me.  Admittedly, that's the same thing on any
>> remotely sane architecture, but still.
>
> GET_LE() then?

Sounds good.

Are you planning on writing the patch?

I think my v2 is good -- the only diff I could find in my image.c
files and Stephen's was in the alt_xyz output, and I think I fixed
that in v2.

--Andy

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v2 2/2] x86,vdso: Fix cross-compilation from big-endian architectures
  2014-05-30 20:34                     ` Andy Lutomirski
@ 2014-05-31  0:14                       ` H. Peter Anvin
  0 siblings, 0 replies; 20+ messages in thread
From: H. Peter Anvin @ 2014-05-31  0:14 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: Paul Gortmaker, Josh Boyer, Ingo Molnar, LKML, tglx@linutronix.de,
	linux-tip-commits@vger.kernel.org, linux-next@vger.kernel.org

On 05/30/2014 01:34 PM, Andy Lutomirski wrote:
>>
>> GET_LE() then?
> 
> Sounds good.
> 
> Are you planning on writing the patch?
> 
> I think my v2 is good -- the only diff I could find in my image.c
> files and Stephen's was in the alt_xyz output, and I think I fixed
> that in v2.
> 

Build testing one now.

	-hpa

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2014-05-31  0:15 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <2c4fcf45524162a34d87fdda1eb046b2a5cecee7.1399317206.git.luto@amacapital.net>
     [not found] ` <tip-6f121e548f83674ab4920a4e60afb58d4f61b829@git.kernel.org>
2014-05-29 19:17   ` [tip:x86/vdso] x86, vdso: Reimplement vdso.so preparation in build-time C Paul Gortmaker
2014-05-29 19:32     ` Andy Lutomirski
2014-05-29 19:43       ` H. Peter Anvin
2014-05-29 19:46         ` Andy Lutomirski
2014-05-29 21:57           ` [PATCH 0/2] x86,vdso: vdso build fixes and improvements Andy Lutomirski
2014-05-29 21:57             ` [PATCH 1/2] x86,vdso: When vdso2c fails, unlink the output Andy Lutomirski
2014-05-29 21:57             ` [PATCH 2/2] x86,vdso: Fix cross-compilation from big-endian architectures Andy Lutomirski
2014-05-29 22:41             ` [PATCH 0/2] x86,vdso: vdso build fixes and improvements Paul Gortmaker
2014-05-29 22:49               ` Andy Lutomirski
2014-05-30  5:42                 ` Stephen Rothwell
2014-05-30 15:40                   ` Andy Lutomirski
2014-05-30 15:48           ` [PATCH v2 " Andy Lutomirski
2014-05-30 15:48             ` [PATCH v2 1/2] x86,vdso: When vdso2c fails, unlink the output Andy Lutomirski
2014-05-30 15:48             ` [PATCH v2 2/2] x86,vdso: Fix cross-compilation from big-endian architectures Andy Lutomirski
2014-05-30 20:02               ` H. Peter Anvin
2014-05-30 20:09                 ` Andy Lutomirski
2014-05-30 20:21                   ` H. Peter Anvin
2014-05-30 20:34                     ` Andy Lutomirski
2014-05-31  0:14                       ` H. Peter Anvin
2014-05-29 19:43       ` [tip:x86/vdso] x86, vdso: Reimplement vdso.so preparation in build-time C Josh Boyer

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).