From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934503AbaE3UJt (ORCPT ); Fri, 30 May 2014 16:09:49 -0400 Received: from mail-ve0-f173.google.com ([209.85.128.173]:56514 "EHLO mail-ve0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754324AbaE3UJq (ORCPT ); Fri, 30 May 2014 16:09:46 -0400 MIME-Version: 1.0 In-Reply-To: <5388E3EF.6030700@zytor.com> References: <2cf258df123cb24bad63c274c8563c050547d99d.1401464755.git.luto@amacapital.net> <5388E3EF.6030700@zytor.com> From: Andy Lutomirski Date: Fri, 30 May 2014 13:09:25 -0700 Message-ID: Subject: Re: [PATCH v2 2/2] x86,vdso: Fix cross-compilation from big-endian architectures 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" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 30, 2014 at 1:02 PM, H. Peter Anvin 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 >> --- >> 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