diff mbox

[RFC] Add support for glibc style endianess detection

Message ID 1493842026-9345-1-git-send-email-akshay.adiga@linux.vnet.ibm.com
State RFC
Headers show

Commit Message

Akshay Adiga May 3, 2017, 8:07 p.m. UTC
CCAN defines HAVE_LITTLE_ENDIAN or HAVE_BIG_ENDIAN to endianess of the
system and code developed on top of glibc expect __BYTE_ORDER to
tell the endianess.

Suggested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
---
Other attempt:
1) when named as include/endian.h, conflicted with host include
files (gcov build failed).

 include/glibc_endian.h | 36 ++++++++++++++++++++++++++++++++++++
 include/skiboot.h      |  2 +-
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 include/glibc_endian.h

Comments

Benjamin Herrenschmidt May 3, 2017, 9:56 p.m. UTC | #1
On Thu, 2017-05-04 at 01:37 +0530, Akshay Adiga wrote:
> CCAN defines HAVE_LITTLE_ENDIAN or HAVE_BIG_ENDIAN to endianess of the
> system and code developed on top of glibc expect __BYTE_ORDER to
> tell the endianess.
> 
> Suggested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
> ---
> Other attempt:
> 1) when named as include/endian.h, conflicted with host include
> files (gcov build failed).

I'd rather we fix the host include problem by using the proper
guards in that file for example if we can and call it "endian.h"
> 
>  include/glibc_endian.h | 36 ++++++++++++++++++++++++++++++++++++
>  include/skiboot.h      |  2 +-
>  2 files changed, 37 insertions(+), 1 deletion(-)
>  create mode 100644 include/glibc_endian.h
> 
> diff --git a/include/glibc_endian.h b/include/glibc_endian.h
> new file mode 100644
> index 0000000..8b1ce5f
> --- /dev/null
> +++ b/include/glibc_endian.h
> @@ -0,0 +1,36 @@
> +/* Copyright 2013-2014 IBM Corp.
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + * 	http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> + * implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +#ifndef GLIBC_ENDIAN_H
> +#define GLIBC_ENDIAN_H
> +
> +#include <ccan/endian/endian.h>
> +
> +/*
> + *  CCAN does not export __BYTE_ORDER hence copying definitions from
> + *  glibc
> + */
> +#define	__LITTLE_ENDIAN	1234
> +#define	__BIG_ENDIAN	4321
> +#ifdef HAVE_LITTLE_ENDIAN
> +	#define __BYTE_ORDER __LITTLE_ENDIAN
> +#elif HAVE_BIG_ENDIAN
> +	#define __BYTE_ORDER __BIG_ENDIAN
> +#else
> +	#error
> +#endif
> +#endif
> +
> diff --git a/include/skiboot.h b/include/skiboot.h
> index 5c8b0c8..519c5fe 100644
> --- a/include/skiboot.h
> +++ b/include/skiboot.h
> @@ -27,13 +27,13 @@
>  #include <errno.h>
>  #include <bitutils.h>
>  #include <types.h>
> +#include <glibc_endian.h>
>  
>  #include <ccan/container_of/container_of.h>
>  #include <ccan/list/list.h>
>  #include <ccan/short_types/short_types.h>
>  #include <ccan/build_assert/build_assert.h>
>  #include <ccan/array_size/array_size.h>
> -#include <ccan/endian/endian.h>
>  #include <ccan/str/str.h>
>  
>  #include <libflash/blocklevel.h>
Akshay Adiga May 4, 2017, 2:43 a.m. UTC | #2
On 05/04/2017 03:26 AM, Benjamin Herrenschmidt wrote:
> On Thu, 2017-05-04 at 01:37 +0530, Akshay Adiga wrote:
> > CCAN defines HAVE_LITTLE_ENDIAN or HAVE_BIG_ENDIAN to endianess of the
> > system and code developed on top of glibc expect __BYTE_ORDER to
> > tell the endianess.
> >
> > Suggested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> > Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
> > ---
> > Other attempt:
> > 1) when named as include/endian.h, conflicted with host include
> > files (gcov build failed).
>
> I'd rather we fix the host include problem by using the proper
> guards in that file for example if we can and call it "endian.h"

I can do that.

[snip..]
> > --- a/include/skiboot.h
> > +++ b/include/skiboot.h
> > @@ -27,13 +27,13 @@
> >  #include <errno.h>
> >  #include <bitutils.h>
> >  #include <types.h>
> > +#include <glibc_endian.h>

I can rename "glibc_endian.h" to "endian.h" and change include to :
+#include "endian.h"

Thanks Ben it works. posting it as patch now.
Akshay Adiga May 4, 2017, 3:51 a.m. UTC | #3
On 05/04/2017 08:13 AM, Akshay Adiga wrote:
>
> On 05/04/2017 03:26 AM, Benjamin Herrenschmidt wrote:
> > On Thu, 2017-05-04 at 01:37 +0530, Akshay Adiga wrote:
> > > CCAN defines HAVE_LITTLE_ENDIAN or HAVE_BIG_ENDIAN to endianess of the
> > > system and code developed on top of glibc expect __BYTE_ORDER to
> > > tell the endianess.
> > >
> > > Suggested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> > > Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
> > > ---
> > > Other attempt:
> > > 1) when named as include/endian.h, conflicted with host include
> > > files (gcov build failed).
> >
> > I'd rather we fix the host include problem by using the proper
> > guards in that file for example if we can and call it "endian.h"
>
> I can do that.
>
> [snip..]
> > > --- a/include/skiboot.h
> > > +++ b/include/skiboot.h
> > > @@ -27,13 +27,13 @@
> > >  #include <errno.h>
> > >  #include <bitutils.h>
> > >  #include <types.h>
> > > +#include <glibc_endian.h>
>
> I can rename "glibc_endian.h" to "endian.h" and change include to :
> +#include "endian.h"
>
> Thanks Ben it works. posting it as patch now.

I am wrong it does not solve the issue. this file gets included,
as Makefile is adding "-I. -I include" explicitly. It fails to take
glibc include.

Let me explain what's happening.

I rename it as "endian.h"

build fails for extract-gcov.c as it expects GLIBC endian.h and not CCAN.

If i rename it as "/usr/include/endian.h" , it builds fine.

It used to work fine because $(SKIBOOT)/include/ will not have endian.h
and fall back to GLIBC include.

Is there a way around it ?
Benjamin Herrenschmidt May 4, 2017, 12:56 p.m. UTC | #4
On Thu, 2017-05-04 at 09:21 +0530, Akshay Adiga wrote:
> build fails for extract-gcov.c as it expects GLIBC endian.h and not CCAN.
> 
> If i rename it as "/usr/include/endian.h" , it builds fine.
> 
> It used to work fine because $(SKIBOOT)/include/ will not have endian.h
> and fall back to GLIBC include.
> 
> Is there a way around it ?

extract-gcov.c is a host binary right ? I shouldn't include our stuff
by default in its -I directive.

Ben.
Murilo Opsfelder Araujo May 4, 2017, 2:34 p.m. UTC | #5
On 05/03/2017 05:07 PM, Akshay Adiga wrote:
> CCAN defines HAVE_LITTLE_ENDIAN or HAVE_BIG_ENDIAN to endianess of the
> system and code developed on top of glibc expect __BYTE_ORDER to
> tell the endianess.
> 
> Suggested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
> ---
> Other attempt:
> 1) when named as include/endian.h, conflicted with host include
> files (gcov build failed).
> 
>  include/glibc_endian.h | 36 ++++++++++++++++++++++++++++++++++++
>  include/skiboot.h      |  2 +-
>  2 files changed, 37 insertions(+), 1 deletion(-)
>  create mode 100644 include/glibc_endian.h
> 
> diff --git a/include/glibc_endian.h b/include/glibc_endian.h
> new file mode 100644
> index 0000000..8b1ce5f
> --- /dev/null
> +++ b/include/glibc_endian.h
> @@ -0,0 +1,36 @@
> +/* Copyright 2013-2014 IBM Corp.

Shouldn't it be 2017?
Akshay Adiga May 4, 2017, 5:25 p.m. UTC | #6
On 05/04/2017 08:04 PM, Murilo Opsfelder Ara├║jo wrote:
> On 05/03/2017 05:07 PM, Akshay Adiga wrote:
>> CCAN defines HAVE_LITTLE_ENDIAN or HAVE_BIG_ENDIAN to endianess of the
>> system and code developed on top of glibc expect __BYTE_ORDER to
>> tell the endianess.
>>
>> Suggested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
>> Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
>> ---
>> Other attempt:
>> 1) when named as include/endian.h, conflicted with host include
>> files (gcov build failed).
>>
>>  include/glibc_endian.h | 36 ++++++++++++++++++++++++++++++++++++
>>  include/skiboot.h      |  2 +-
>>  2 files changed, 37 insertions(+), 1 deletion(-)
>>  create mode 100644 include/glibc_endian.h
>>
>> diff --git a/include/glibc_endian.h b/include/glibc_endian.h
>> new file mode 100644
>> index 0000000..8b1ce5f
>> --- /dev/null
>> +++ b/include/glibc_endian.h
>> @@ -0,0 +1,36 @@
>> +/* Copyright 2013-2014 IBM Corp.
>
> Shouldn't it be 2017?
>
Thanks, I will correct the year.
diff mbox

Patch

diff --git a/include/glibc_endian.h b/include/glibc_endian.h
new file mode 100644
index 0000000..8b1ce5f
--- /dev/null
+++ b/include/glibc_endian.h
@@ -0,0 +1,36 @@ 
+/* Copyright 2013-2014 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 	http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef GLIBC_ENDIAN_H
+#define GLIBC_ENDIAN_H
+
+#include <ccan/endian/endian.h>
+
+/*
+ *  CCAN does not export __BYTE_ORDER hence copying definitions from
+ *  glibc
+ */
+#define	__LITTLE_ENDIAN	1234
+#define	__BIG_ENDIAN	4321
+#ifdef HAVE_LITTLE_ENDIAN
+	#define __BYTE_ORDER __LITTLE_ENDIAN
+#elif HAVE_BIG_ENDIAN
+	#define __BYTE_ORDER __BIG_ENDIAN
+#else
+	#error
+#endif
+#endif
+
diff --git a/include/skiboot.h b/include/skiboot.h
index 5c8b0c8..519c5fe 100644
--- a/include/skiboot.h
+++ b/include/skiboot.h
@@ -27,13 +27,13 @@ 
 #include <errno.h>
 #include <bitutils.h>
 #include <types.h>
+#include <glibc_endian.h>
 
 #include <ccan/container_of/container_of.h>
 #include <ccan/list/list.h>
 #include <ccan/short_types/short_types.h>
 #include <ccan/build_assert/build_assert.h>
 #include <ccan/array_size/array_size.h>
-#include <ccan/endian/endian.h>
 #include <ccan/str/str.h>
 
 #include <libflash/blocklevel.h>