All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Add remaining parts for ppc64le environment
@ 2015-06-30 12:56 Paulo Flabiano Smorigo
  2015-06-30 12:56 ` [PATCH 1/2] Add powerpc little-endian (ppc64le) flags Paulo Flabiano Smorigo
  2015-06-30 12:56 ` [PATCH 2/2] Suport for bi-endianess in elf file Paulo Flabiano Smorigo
  0 siblings, 2 replies; 23+ messages in thread
From: Paulo Flabiano Smorigo @ 2015-06-30 12:56 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Paulo Flabiano Smorigo

It's almost the same as the one that I sent in the beginning of the year.
The only difference is that the I remove a flag from the first patch.

Paulo Flabiano Smorigo (2):
  Add powerpc little-endian (ppc64le) flags
  Suport for bi-endianess in elf file

 configure.ac           |  8 ++++++
 grub-core/kern/elf.c   | 60 +++++++++++++++++++++++++++++++++++++++--
 grub-core/kern/elfXX.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+), 2 deletions(-)

-- 
2.1.0



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

* [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-06-30 12:56 [PATCH 0/2] Add remaining parts for ppc64le environment Paulo Flabiano Smorigo
@ 2015-06-30 12:56 ` Paulo Flabiano Smorigo
  2015-06-30 14:03   ` Vladimir 'phcoder' Serbinenko
  2015-06-30 12:56 ` [PATCH 2/2] Suport for bi-endianess in elf file Paulo Flabiano Smorigo
  1 sibling, 1 reply; 23+ messages in thread
From: Paulo Flabiano Smorigo @ 2015-06-30 12:56 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Paulo Flabiano Smorigo

libgcc dependency was removed *just* for this target because
the distros that use ppc64el doesn't have 32-bit support on it.

* configure.ac: Add targets for powerpc64el and skip libgcc.
* Makefile.am: Likewise.
---
 configure.ac | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/configure.ac b/configure.ac
index fd8a62e..0a79fad 100644
--- a/configure.ac
+++ b/configure.ac
@@ -116,6 +116,7 @@ if test "x$with_platform" = x; then
     x86_64-*) platform=pc ;;
     powerpc-*) platform=ieee1275 ;;
     powerpc64-*) platform=ieee1275 ;;
+    powerpc64le-*) platform=ieee1275 ;;
     sparc64-*) platform=ieee1275 ;;
     mipsel-*) platform=loongson ;;
     mips-*) platform=arc ;;
@@ -138,6 +139,7 @@ case "$target_cpu"-"$platform" in
   x86_64-none) ;;
   x86_64-*) target_cpu=i386 ;;
   powerpc64-ieee1275) target_cpu=powerpc ;;
+  powerpc64le-ieee1275) target_cpu=powerpc ;;
 esac
 
 # Check if the platform is supported, make final adjustments.
@@ -601,6 +603,12 @@ if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
   TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
 fi
 
+if test x$target_cpu = xpowerpc; then
+  TARGET_CFLAGS="$TARGET_CFLAGS -mbig-endian"
+  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mbig-endian"
+  TARGET_LDFLAGS="$TARGET_LDFLAGS -static -mbig-endian"
+fi
+
 if test "x$target_m32" = x1; then
   # Force 32-bit mode.
   TARGET_CFLAGS="$TARGET_CFLAGS -m32"
-- 
2.1.0



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

* [PATCH 2/2] Suport for bi-endianess in elf file
  2015-06-30 12:56 [PATCH 0/2] Add remaining parts for ppc64le environment Paulo Flabiano Smorigo
  2015-06-30 12:56 ` [PATCH 1/2] Add powerpc little-endian (ppc64le) flags Paulo Flabiano Smorigo
@ 2015-06-30 12:56 ` Paulo Flabiano Smorigo
  2015-06-30 15:03   ` Andrei Borzenkov
  1 sibling, 1 reply; 23+ messages in thread
From: Paulo Flabiano Smorigo @ 2015-06-30 12:56 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Paulo Flabiano Smorigo

* grub-core/kern/elf.c: check and switch endianess with grub_{be,le}_to
cpu functions.
* grub-core/kern/elfXX.c: Likewise.

Also-by: Tomohiro B Berry <tbberry@us.ibm.com>
---
 grub-core/kern/elf.c   | 60 +++++++++++++++++++++++++++++++++++++++--
 grub-core/kern/elfXX.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 131 insertions(+), 2 deletions(-)

diff --git a/grub-core/kern/elf.c b/grub-core/kern/elf.c
index 5f99c43..de90811 100644
--- a/grub-core/kern/elf.c
+++ b/grub-core/kern/elf.c
@@ -28,6 +28,11 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
+void grub_elf32_check_endianess (grub_elf_t elf);
+void grub_elf64_check_endianess (grub_elf_t elf);
+grub_err_t grub_elf32_check_version (grub_elf_t elf);
+grub_err_t grub_elf64_check_version (grub_elf_t elf);
+
 /* Check if EHDR is a valid ELF header.  */
 static grub_err_t
 grub_elf_check_header (grub_elf_t elf)
@@ -38,10 +43,22 @@ grub_elf_check_header (grub_elf_t elf)
       || e->e_ident[EI_MAG1] != ELFMAG1
       || e->e_ident[EI_MAG2] != ELFMAG2
       || e->e_ident[EI_MAG3] != ELFMAG3
-      || e->e_ident[EI_VERSION] != EV_CURRENT
-      || e->e_version != EV_CURRENT)
+      || e->e_ident[EI_VERSION] != EV_CURRENT)
     return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF magic"));
 
+  if (grub_elf_is_elf32 (elf))
+    {
+      grub_elf32_check_endianess (elf);
+      grub_elf32_check_version (elf);
+    }
+  else if (grub_elf_is_elf64 (elf))
+    {
+      grub_elf64_check_endianess (elf);
+      grub_elf64_check_version (elf);
+    }
+  else
+    return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic"));
+
   return GRUB_ERR_NONE;
 }
 
@@ -127,7 +144,20 @@ grub_elf_open (const char *name)
 #define grub_elf_is_elfXX grub_elf_is_elf32
 #define grub_elfXX_load_phdrs grub_elf32_load_phdrs
 #define ElfXX_Phdr Elf32_Phdr
+#define ElfXX_Ehdr Elf32_Ehdr
 #define grub_uintXX_t grub_uint32_t
+#define grub_be_to_halfXX grub_be_to_cpu16
+#define grub_be_to_wordXX grub_be_to_cpu32
+#define grub_be_to_addrXX grub_be_to_cpu32
+#define grub_be_to_offXX grub_be_to_cpu32
+#define grub_be_to_XwordXX grub_be_to_wordXX
+#define grub_le_to_halfXX grub_le_to_cpu16
+#define grub_le_to_wordXX grub_le_to_cpu32
+#define grub_le_to_addrXX grub_le_to_cpu32
+#define grub_le_to_offXX grub_le_to_cpu32
+#define grub_le_to_XwordXX grub_le_to_wordXX
+#define grub_elfXX_check_endianess grub_elf32_check_endianess
+#define grub_elfXX_check_version grub_elf32_check_version
 
 #include "elfXX.c"
 
@@ -140,7 +170,20 @@ grub_elf_open (const char *name)
 #undef grub_elf_is_elfXX
 #undef grub_elfXX_load_phdrs
 #undef ElfXX_Phdr
+#undef ElfXX_Ehdr
 #undef grub_uintXX_t
+#undef grub_be_to_halfXX
+#undef grub_be_to_wordXX
+#undef grub_be_to_addrXX
+#undef grub_be_to_offXX
+#undef grub_be_to_XwordXX
+#undef grub_le_to_halfXX
+#undef grub_le_to_wordXX
+#undef grub_le_to_addrXX
+#undef grub_le_to_offXX
+#undef grub_le_to_XwordXX
+#undef grub_elfXX_check_endianess
+#undef grub_elfXX_check_version
 
 \f
 /* 64-bit */
@@ -153,6 +196,19 @@ grub_elf_open (const char *name)
 #define grub_elf_is_elfXX grub_elf_is_elf64
 #define grub_elfXX_load_phdrs grub_elf64_load_phdrs
 #define ElfXX_Phdr Elf64_Phdr
+#define ElfXX_Ehdr Elf64_Ehdr
 #define grub_uintXX_t grub_uint64_t
+#define grub_be_to_halfXX grub_be_to_cpu16
+#define grub_be_to_wordXX grub_be_to_cpu32
+#define grub_be_to_addrXX grub_be_to_cpu64
+#define grub_be_to_offXX grub_be_to_cpu64
+#define grub_be_to_XwordXX grub_be_to_cpu64
+#define grub_le_to_halfXX grub_le_to_cpu16
+#define grub_le_to_wordXX grub_le_to_cpu32
+#define grub_le_to_addrXX grub_le_to_cpu64
+#define grub_le_to_offXX grub_le_to_cpu64
+#define grub_le_to_XwordXX grub_le_to_cpu64
+#define grub_elfXX_check_endianess grub_elf64_check_endianess
+#define grub_elfXX_check_version grub_elf64_check_version
 
 #include "elfXX.c"
diff --git a/grub-core/kern/elfXX.c b/grub-core/kern/elfXX.c
index 1d09971..ecf9df6 100644
--- a/grub-core/kern/elfXX.c
+++ b/grub-core/kern/elfXX.c
@@ -154,3 +154,76 @@ grub_elfXX_load (grub_elf_t elf, const char *filename,
 
   return grub_errno;
 }
+
+void
+grub_elfXX_check_endianess (grub_elf_t elf)
+{
+  ElfXX_Ehdr *e = &(elf->ehdr.ehdrXX);
+  ElfXX_Phdr *phdr;
+
+  if (e->e_ident[EI_DATA] == ELFDATA2MSB)
+    {
+      e->e_type = grub_be_to_halfXX (e->e_type);
+      e->e_machine = grub_be_to_halfXX (e->e_machine);
+      e->e_version = grub_be_to_wordXX (e->e_version);
+      e->e_entry = grub_be_to_addrXX (e->e_entry);
+      e->e_phoff = grub_be_to_offXX (e->e_phoff);
+      e->e_shoff = grub_be_to_offXX (e->e_shoff);
+      e->e_flags = grub_be_to_wordXX (e->e_flags);
+      e->e_ehsize = grub_be_to_halfXX (e->e_ehsize);
+      e->e_phentsize = grub_be_to_halfXX (e->e_phentsize);
+      e->e_phnum = grub_be_to_halfXX (e->e_phnum);
+      e->e_shentsize = grub_be_to_halfXX (e->e_shentsize);
+      e->e_shnum = grub_be_to_halfXX (e->e_shnum);
+      e->e_shstrndx = grub_be_to_halfXX (e->e_shstrndx);
+
+      FOR_ELFXX_PHDRS (elf,phdr)
+        {
+          phdr->p_type = grub_be_to_wordXX (phdr->p_type);
+          phdr->p_flags = grub_be_to_wordXX (phdr->p_flags);
+          phdr->p_offset = grub_be_to_offXX (phdr->p_offset);
+          phdr->p_vaddr = grub_be_to_addrXX (phdr->p_vaddr);
+          phdr->p_paddr = grub_be_to_addrXX (phdr->p_paddr);
+          phdr->p_filesz = grub_be_to_XwordXX (phdr->p_filesz);
+          phdr->p_memsz = grub_be_to_XwordXX (phdr->p_memsz);
+          phdr->p_align = grub_be_to_XwordXX (phdr->p_align);
+        }
+    }
+  else if (e->e_ident[EI_DATA] == ELFDATA2LSB)
+    {
+      e->e_type = grub_le_to_halfXX (e->e_type);
+      e->e_machine = grub_le_to_halfXX (e->e_machine);
+      e->e_version = grub_le_to_wordXX (e->e_version);
+      e->e_entry = grub_le_to_addrXX (e->e_entry);
+      e->e_phoff = grub_le_to_offXX (e->e_phoff);
+      e->e_shoff = grub_le_to_offXX (e->e_shoff);
+      e->e_flags = grub_le_to_wordXX (e->e_flags);
+      e->e_ehsize = grub_le_to_halfXX (e->e_ehsize);
+      e->e_phentsize = grub_le_to_halfXX (e->e_phentsize);
+      e->e_phnum = grub_le_to_halfXX (e->e_phnum);
+      e->e_shentsize = grub_le_to_halfXX (e->e_shentsize);
+      e->e_shnum = grub_le_to_halfXX (e->e_shnum);
+      e->e_shstrndx = grub_le_to_halfXX (e->e_shstrndx);
+
+      FOR_ELFXX_PHDRS (elf,phdr)
+        {
+          phdr->p_type = grub_le_to_wordXX (phdr->p_type);
+          phdr->p_flags = grub_le_to_wordXX (phdr->p_flags);
+          phdr->p_offset = grub_le_to_offXX (phdr->p_offset);
+          phdr->p_vaddr = grub_le_to_addrXX (phdr->p_vaddr);
+          phdr->p_paddr = grub_le_to_addrXX (phdr->p_paddr);
+          phdr->p_filesz = grub_le_to_XwordXX (phdr->p_filesz);
+          phdr->p_memsz = grub_le_to_XwordXX (phdr->p_memsz);
+          phdr->p_align = grub_le_to_XwordXX (phdr->p_align);
+        }
+    }
+}
+
+grub_err_t
+grub_elfXX_check_version (grub_elf_t elf)
+{
+  if (elf->ehdr.ehdrXX.e_version != EV_CURRENT)
+    return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF magic"));
+
+  return GRUB_ERR_NONE;
+}
-- 
2.1.0



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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-06-30 12:56 ` [PATCH 1/2] Add powerpc little-endian (ppc64le) flags Paulo Flabiano Smorigo
@ 2015-06-30 14:03   ` Vladimir 'phcoder' Serbinenko
  2015-06-30 14:29     ` Andrei Borzenkov
  0 siblings, 1 reply; 23+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2015-06-30 14:03 UTC (permalink / raw)
  To: The development of GRUB 2; +Cc: Paulo Flabiano Smorigo

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

Which compilers support these flags? I'm concerned of breaking old compilers
Le 30 juin 2015 14:57, "Paulo Flabiano Smorigo" <
pfsmorigo@linux.vnet.ibm.com> a écrit :

> libgcc dependency was removed *just* for this target because
> the distros that use ppc64el doesn't have 32-bit support on it.
>
> * configure.ac: Add targets for powerpc64el and skip libgcc.
> * Makefile.am: Likewise.
> ---
>  configure.ac | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/configure.ac b/configure.ac
> index fd8a62e..0a79fad 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -116,6 +116,7 @@ if test "x$with_platform" = x; then
>      x86_64-*) platform=pc ;;
>      powerpc-*) platform=ieee1275 ;;
>      powerpc64-*) platform=ieee1275 ;;
> +    powerpc64le-*) platform=ieee1275 ;;
>      sparc64-*) platform=ieee1275 ;;
>      mipsel-*) platform=loongson ;;
>      mips-*) platform=arc ;;
> @@ -138,6 +139,7 @@ case "$target_cpu"-"$platform" in
>    x86_64-none) ;;
>    x86_64-*) target_cpu=i386 ;;
>    powerpc64-ieee1275) target_cpu=powerpc ;;
> +  powerpc64le-ieee1275) target_cpu=powerpc ;;
>  esac
>
>  # Check if the platform is supported, make final adjustments.
> @@ -601,6 +603,12 @@ if test "x$target_cpu" = xi386 && test "x$platform"
> != xemu; then
>    TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
>  fi
>
> +if test x$target_cpu = xpowerpc; then
> +  TARGET_CFLAGS="$TARGET_CFLAGS -mbig-endian"
> +  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mbig-endian"
> +  TARGET_LDFLAGS="$TARGET_LDFLAGS -static -mbig-endian"
> +fi
> +
>  if test "x$target_m32" = x1; then
>    # Force 32-bit mode.
>    TARGET_CFLAGS="$TARGET_CFLAGS -m32"
> --
> 2.1.0
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

[-- Attachment #2: Type: text/html, Size: 2928 bytes --]

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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-06-30 14:03   ` Vladimir 'phcoder' Serbinenko
@ 2015-06-30 14:29     ` Andrei Borzenkov
  2015-06-30 14:33       ` Vladimir 'phcoder' Serbinenko
  2015-06-30 14:33       ` Paulo Flabiano Smorigo
  0 siblings, 2 replies; 23+ messages in thread
From: Andrei Borzenkov @ 2015-06-30 14:29 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Paulo Flabiano Smorigo

On Tue, Jun 30, 2015 at 5:03 PM, Vladimir 'phcoder' Serbinenko
<phcoder@gmail.com> wrote:
> Which compilers support these flags? I'm concerned of breaking old compilers
>

-static and -mbig-endian are listed in gcc 2.95.3 documentation for PPC.

> Le 30 juin 2015 14:57, "Paulo Flabiano Smorigo"
> <pfsmorigo@linux.vnet.ibm.com> a écrit :
>>
>> libgcc dependency was removed *just* for this target because
>> the distros that use ppc64el doesn't have 32-bit support on it.
>>
>> * configure.ac: Add targets for powerpc64el and skip libgcc.
>> * Makefile.am: Likewise.
>> ---
>>  configure.ac | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/configure.ac b/configure.ac
>> index fd8a62e..0a79fad 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -116,6 +116,7 @@ if test "x$with_platform" = x; then
>>      x86_64-*) platform=pc ;;
>>      powerpc-*) platform=ieee1275 ;;
>>      powerpc64-*) platform=ieee1275 ;;
>> +    powerpc64le-*) platform=ieee1275 ;;
>>      sparc64-*) platform=ieee1275 ;;
>>      mipsel-*) platform=loongson ;;
>>      mips-*) platform=arc ;;
>> @@ -138,6 +139,7 @@ case "$target_cpu"-"$platform" in
>>    x86_64-none) ;;
>>    x86_64-*) target_cpu=i386 ;;
>>    powerpc64-ieee1275) target_cpu=powerpc ;;
>> +  powerpc64le-ieee1275) target_cpu=powerpc ;;
>>  esac
>>
>>  # Check if the platform is supported, make final adjustments.
>> @@ -601,6 +603,12 @@ if test "x$target_cpu" = xi386 && test "x$platform"
>> != xemu; then
>>    TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
>>  fi
>>
>> +if test x$target_cpu = xpowerpc; then
>> +  TARGET_CFLAGS="$TARGET_CFLAGS -mbig-endian"
>> +  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mbig-endian"
>> +  TARGET_LDFLAGS="$TARGET_LDFLAGS -static -mbig-endian"
>> +fi
>> +
>>  if test "x$target_m32" = x1; then
>>    # Force 32-bit mode.
>>    TARGET_CFLAGS="$TARGET_CFLAGS -m32"
>> --
>> 2.1.0
>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>


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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-06-30 14:29     ` Andrei Borzenkov
@ 2015-06-30 14:33       ` Vladimir 'phcoder' Serbinenko
  2015-06-30 18:05         ` Paulo Flabiano Smorigo
  2015-06-30 14:33       ` Paulo Flabiano Smorigo
  1 sibling, 1 reply; 23+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2015-06-30 14:33 UTC (permalink / raw)
  To: The development of GRUB 2; +Cc: Paulo Flabiano Smorigo

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

What about clang?
Le 30 juin 2015 16:30, "Andrei Borzenkov" <arvidjaar@gmail.com> a écrit :

> On Tue, Jun 30, 2015 at 5:03 PM, Vladimir 'phcoder' Serbinenko
> <phcoder@gmail.com> wrote:
> > Which compilers support these flags? I'm concerned of breaking old
> compilers
> >
>
> -static and -mbig-endian are listed in gcc 2.95.3 documentation for PPC.
>
> > Le 30 juin 2015 14:57, "Paulo Flabiano Smorigo"
> > <pfsmorigo@linux.vnet.ibm.com> a écrit :
> >>
> >> libgcc dependency was removed *just* for this target because
> >> the distros that use ppc64el doesn't have 32-bit support on it.
> >>
> >> * configure.ac: Add targets for powerpc64el and skip libgcc.
> >> * Makefile.am: Likewise.
> >> ---
> >>  configure.ac | 8 ++++++++
> >>  1 file changed, 8 insertions(+)
> >>
> >> diff --git a/configure.ac b/configure.ac
> >> index fd8a62e..0a79fad 100644
> >> --- a/configure.ac
> >> +++ b/configure.ac
> >> @@ -116,6 +116,7 @@ if test "x$with_platform" = x; then
> >>      x86_64-*) platform=pc ;;
> >>      powerpc-*) platform=ieee1275 ;;
> >>      powerpc64-*) platform=ieee1275 ;;
> >> +    powerpc64le-*) platform=ieee1275 ;;
> >>      sparc64-*) platform=ieee1275 ;;
> >>      mipsel-*) platform=loongson ;;
> >>      mips-*) platform=arc ;;
> >> @@ -138,6 +139,7 @@ case "$target_cpu"-"$platform" in
> >>    x86_64-none) ;;
> >>    x86_64-*) target_cpu=i386 ;;
> >>    powerpc64-ieee1275) target_cpu=powerpc ;;
> >> +  powerpc64le-ieee1275) target_cpu=powerpc ;;
> >>  esac
> >>
> >>  # Check if the platform is supported, make final adjustments.
> >> @@ -601,6 +603,12 @@ if test "x$target_cpu" = xi386 && test "x$platform"
> >> != xemu; then
> >>    TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
> >>  fi
> >>
> >> +if test x$target_cpu = xpowerpc; then
> >> +  TARGET_CFLAGS="$TARGET_CFLAGS -mbig-endian"
> >> +  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mbig-endian"
> >> +  TARGET_LDFLAGS="$TARGET_LDFLAGS -static -mbig-endian"
> >> +fi
> >> +
> >>  if test "x$target_m32" = x1; then
> >>    # Force 32-bit mode.
> >>    TARGET_CFLAGS="$TARGET_CFLAGS -m32"
> >> --
> >> 2.1.0
> >>
> >>
> >> _______________________________________________
> >> Grub-devel mailing list
> >> Grub-devel@gnu.org
> >> https://lists.gnu.org/mailman/listinfo/grub-devel
> >
> >
> > _______________________________________________
> > Grub-devel mailing list
> > Grub-devel@gnu.org
> > https://lists.gnu.org/mailman/listinfo/grub-devel
> >
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

[-- Attachment #2: Type: text/html, Size: 4485 bytes --]

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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-06-30 14:29     ` Andrei Borzenkov
  2015-06-30 14:33       ` Vladimir 'phcoder' Serbinenko
@ 2015-06-30 14:33       ` Paulo Flabiano Smorigo
  1 sibling, 0 replies; 23+ messages in thread
From: Paulo Flabiano Smorigo @ 2015-06-30 14:33 UTC (permalink / raw)
  To: Andrei Borzenkov, The development of GNU GRUB

On 2015-06-30 11:29, Andrei Borzenkov wrote:
> On Tue, Jun 30, 2015 at 5:03 PM, Vladimir 'phcoder' Serbinenko
> <phcoder@gmail.com> wrote:
>> Which compilers support these flags? I'm concerned of breaking old compilers
>>
>
> -static and -mbig-endian are listed in gcc 2.95.3 documentation for PPC.

I asked some toolchain folks and this flag is really old. IIUC even 
before GCC 2.95, which was released at March 16, 2001.

>
>> Le 30 juin 2015 14:57, "Paulo Flabiano Smorigo"
>> <pfsmorigo@linux.vnet.ibm.com> a écrit :
>>>
>>> libgcc dependency was removed *just* for this target because
>>> the distros that use ppc64el doesn't have 32-bit support on it.
>>>
>>> * configure.ac: Add targets for powerpc64el and skip libgcc.
>>> * Makefile.am: Likewise.
>>> ---
>>>   configure.ac | 8 ++++++++
>>>   1 file changed, 8 insertions(+)
>>>
>>> diff --git a/configure.ac b/configure.ac
>>> index fd8a62e..0a79fad 100644
>>> --- a/configure.ac
>>> +++ b/configure.ac
>>> @@ -116,6 +116,7 @@ if test "x$with_platform" = x; then
>>>       x86_64-*) platform=pc ;;
>>>       powerpc-*) platform=ieee1275 ;;
>>>       powerpc64-*) platform=ieee1275 ;;
>>> +    powerpc64le-*) platform=ieee1275 ;;
>>>       sparc64-*) platform=ieee1275 ;;
>>>       mipsel-*) platform=loongson ;;
>>>       mips-*) platform=arc ;;
>>> @@ -138,6 +139,7 @@ case "$target_cpu"-"$platform" in
>>>     x86_64-none) ;;
>>>     x86_64-*) target_cpu=i386 ;;
>>>     powerpc64-ieee1275) target_cpu=powerpc ;;
>>> +  powerpc64le-ieee1275) target_cpu=powerpc ;;
>>>   esac
>>>
>>>   # Check if the platform is supported, make final adjustments.
>>> @@ -601,6 +603,12 @@ if test "x$target_cpu" = xi386 && test "x$platform"
>>> != xemu; then
>>>     TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
>>>   fi
>>>
>>> +if test x$target_cpu = xpowerpc; then
>>> +  TARGET_CFLAGS="$TARGET_CFLAGS -mbig-endian"
>>> +  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mbig-endian"
>>> +  TARGET_LDFLAGS="$TARGET_LDFLAGS -static -mbig-endian"
>>> +fi
>>> +
>>>   if test "x$target_m32" = x1; then
>>>     # Force 32-bit mode.
>>>     TARGET_CFLAGS="$TARGET_CFLAGS -m32"
>>> --
>>> 2.1.0
>>>
>>>
>>> _______________________________________________
>>> Grub-devel mailing list
>>> Grub-devel@gnu.org
>>> https://lists.gnu.org/mailman/listinfo/grub-devel
>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
>>
>


-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center



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

* Re: [PATCH 2/2] Suport for bi-endianess in elf file
  2015-06-30 12:56 ` [PATCH 2/2] Suport for bi-endianess in elf file Paulo Flabiano Smorigo
@ 2015-06-30 15:03   ` Andrei Borzenkov
  2015-06-30 18:06     ` Paulo Flabiano Smorigo
  0 siblings, 1 reply; 23+ messages in thread
From: Andrei Borzenkov @ 2015-06-30 15:03 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Paulo Flabiano Smorigo

Did you intentionally ignore my comments to previous version?

Отправлено с iPhone

> 30 июня 2015 г., в 15:56, Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> написал(а):
> 
> * grub-core/kern/elf.c: check and switch endianess with grub_{be,le}_to
> cpu functions.
> * grub-core/kern/elfXX.c: Likewise.
> 
> Also-by: Tomohiro B Berry <tbberry@us.ibm.com>
> ---
> grub-core/kern/elf.c   | 60 +++++++++++++++++++++++++++++++++++++++--
> grub-core/kern/elfXX.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 131 insertions(+), 2 deletions(-)
> 
> diff --git a/grub-core/kern/elf.c b/grub-core/kern/elf.c
> index 5f99c43..de90811 100644
> --- a/grub-core/kern/elf.c
> +++ b/grub-core/kern/elf.c
> @@ -28,6 +28,11 @@
> 
> GRUB_MOD_LICENSE ("GPLv3+");
> 
> +void grub_elf32_check_endianess (grub_elf_t elf);
> +void grub_elf64_check_endianess (grub_elf_t elf);
> +grub_err_t grub_elf32_check_version (grub_elf_t elf);
> +grub_err_t grub_elf64_check_version (grub_elf_t elf);
> +
> /* Check if EHDR is a valid ELF header.  */
> static grub_err_t
> grub_elf_check_header (grub_elf_t elf)
> @@ -38,10 +43,22 @@ grub_elf_check_header (grub_elf_t elf)
>       || e->e_ident[EI_MAG1] != ELFMAG1
>       || e->e_ident[EI_MAG2] != ELFMAG2
>       || e->e_ident[EI_MAG3] != ELFMAG3
> -      || e->e_ident[EI_VERSION] != EV_CURRENT
> -      || e->e_version != EV_CURRENT)
> +      || e->e_ident[EI_VERSION] != EV_CURRENT)
>     return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF magic"));
> 
> +  if (grub_elf_is_elf32 (elf))
> +    {
> +      grub_elf32_check_endianess (elf);
> +      grub_elf32_check_version (elf);
> +    }
> +  else if (grub_elf_is_elf64 (elf))
> +    {
> +      grub_elf64_check_endianess (elf);
> +      grub_elf64_check_version (elf);
> +    }
> +  else
> +    return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic"));
> +
>   return GRUB_ERR_NONE;
> }
> 
> @@ -127,7 +144,20 @@ grub_elf_open (const char *name)
> #define grub_elf_is_elfXX grub_elf_is_elf32
> #define grub_elfXX_load_phdrs grub_elf32_load_phdrs
> #define ElfXX_Phdr Elf32_Phdr
> +#define ElfXX_Ehdr Elf32_Ehdr
> #define grub_uintXX_t grub_uint32_t
> +#define grub_be_to_halfXX grub_be_to_cpu16
> +#define grub_be_to_wordXX grub_be_to_cpu32
> +#define grub_be_to_addrXX grub_be_to_cpu32
> +#define grub_be_to_offXX grub_be_to_cpu32
> +#define grub_be_to_XwordXX grub_be_to_wordXX
> +#define grub_le_to_halfXX grub_le_to_cpu16
> +#define grub_le_to_wordXX grub_le_to_cpu32
> +#define grub_le_to_addrXX grub_le_to_cpu32
> +#define grub_le_to_offXX grub_le_to_cpu32
> +#define grub_le_to_XwordXX grub_le_to_wordXX
> +#define grub_elfXX_check_endianess grub_elf32_check_endianess
> +#define grub_elfXX_check_version grub_elf32_check_version
> 
> #include "elfXX.c"
> 
> @@ -140,7 +170,20 @@ grub_elf_open (const char *name)
> #undef grub_elf_is_elfXX
> #undef grub_elfXX_load_phdrs
> #undef ElfXX_Phdr
> +#undef ElfXX_Ehdr
> #undef grub_uintXX_t
> +#undef grub_be_to_halfXX
> +#undef grub_be_to_wordXX
> +#undef grub_be_to_addrXX
> +#undef grub_be_to_offXX
> +#undef grub_be_to_XwordXX
> +#undef grub_le_to_halfXX
> +#undef grub_le_to_wordXX
> +#undef grub_le_to_addrXX
> +#undef grub_le_to_offXX
> +#undef grub_le_to_XwordXX
> +#undef grub_elfXX_check_endianess
> +#undef grub_elfXX_check_version
> 
> \f
> /* 64-bit */
> @@ -153,6 +196,19 @@ grub_elf_open (const char *name)
> #define grub_elf_is_elfXX grub_elf_is_elf64
> #define grub_elfXX_load_phdrs grub_elf64_load_phdrs
> #define ElfXX_Phdr Elf64_Phdr
> +#define ElfXX_Ehdr Elf64_Ehdr
> #define grub_uintXX_t grub_uint64_t
> +#define grub_be_to_halfXX grub_be_to_cpu16
> +#define grub_be_to_wordXX grub_be_to_cpu32
> +#define grub_be_to_addrXX grub_be_to_cpu64
> +#define grub_be_to_offXX grub_be_to_cpu64
> +#define grub_be_to_XwordXX grub_be_to_cpu64
> +#define grub_le_to_halfXX grub_le_to_cpu16
> +#define grub_le_to_wordXX grub_le_to_cpu32
> +#define grub_le_to_addrXX grub_le_to_cpu64
> +#define grub_le_to_offXX grub_le_to_cpu64
> +#define grub_le_to_XwordXX grub_le_to_cpu64
> +#define grub_elfXX_check_endianess grub_elf64_check_endianess
> +#define grub_elfXX_check_version grub_elf64_check_version
> 
> #include "elfXX.c"
> diff --git a/grub-core/kern/elfXX.c b/grub-core/kern/elfXX.c
> index 1d09971..ecf9df6 100644
> --- a/grub-core/kern/elfXX.c
> +++ b/grub-core/kern/elfXX.c
> @@ -154,3 +154,76 @@ grub_elfXX_load (grub_elf_t elf, const char *filename,
> 
>   return grub_errno;
> }
> +
> +void
> +grub_elfXX_check_endianess (grub_elf_t elf)
> +{
> +  ElfXX_Ehdr *e = &(elf->ehdr.ehdrXX);
> +  ElfXX_Phdr *phdr;
> +
> +  if (e->e_ident[EI_DATA] == ELFDATA2MSB)
> +    {
> +      e->e_type = grub_be_to_halfXX (e->e_type);
> +      e->e_machine = grub_be_to_halfXX (e->e_machine);
> +      e->e_version = grub_be_to_wordXX (e->e_version);
> +      e->e_entry = grub_be_to_addrXX (e->e_entry);
> +      e->e_phoff = grub_be_to_offXX (e->e_phoff);
> +      e->e_shoff = grub_be_to_offXX (e->e_shoff);
> +      e->e_flags = grub_be_to_wordXX (e->e_flags);
> +      e->e_ehsize = grub_be_to_halfXX (e->e_ehsize);
> +      e->e_phentsize = grub_be_to_halfXX (e->e_phentsize);
> +      e->e_phnum = grub_be_to_halfXX (e->e_phnum);
> +      e->e_shentsize = grub_be_to_halfXX (e->e_shentsize);
> +      e->e_shnum = grub_be_to_halfXX (e->e_shnum);
> +      e->e_shstrndx = grub_be_to_halfXX (e->e_shstrndx);
> +
> +      FOR_ELFXX_PHDRS (elf,phdr)
> +        {
> +          phdr->p_type = grub_be_to_wordXX (phdr->p_type);
> +          phdr->p_flags = grub_be_to_wordXX (phdr->p_flags);
> +          phdr->p_offset = grub_be_to_offXX (phdr->p_offset);
> +          phdr->p_vaddr = grub_be_to_addrXX (phdr->p_vaddr);
> +          phdr->p_paddr = grub_be_to_addrXX (phdr->p_paddr);
> +          phdr->p_filesz = grub_be_to_XwordXX (phdr->p_filesz);
> +          phdr->p_memsz = grub_be_to_XwordXX (phdr->p_memsz);
> +          phdr->p_align = grub_be_to_XwordXX (phdr->p_align);
> +        }
> +    }
> +  else if (e->e_ident[EI_DATA] == ELFDATA2LSB)
> +    {
> +      e->e_type = grub_le_to_halfXX (e->e_type);
> +      e->e_machine = grub_le_to_halfXX (e->e_machine);
> +      e->e_version = grub_le_to_wordXX (e->e_version);
> +      e->e_entry = grub_le_to_addrXX (e->e_entry);
> +      e->e_phoff = grub_le_to_offXX (e->e_phoff);
> +      e->e_shoff = grub_le_to_offXX (e->e_shoff);
> +      e->e_flags = grub_le_to_wordXX (e->e_flags);
> +      e->e_ehsize = grub_le_to_halfXX (e->e_ehsize);
> +      e->e_phentsize = grub_le_to_halfXX (e->e_phentsize);
> +      e->e_phnum = grub_le_to_halfXX (e->e_phnum);
> +      e->e_shentsize = grub_le_to_halfXX (e->e_shentsize);
> +      e->e_shnum = grub_le_to_halfXX (e->e_shnum);
> +      e->e_shstrndx = grub_le_to_halfXX (e->e_shstrndx);
> +
> +      FOR_ELFXX_PHDRS (elf,phdr)
> +        {
> +          phdr->p_type = grub_le_to_wordXX (phdr->p_type);
> +          phdr->p_flags = grub_le_to_wordXX (phdr->p_flags);
> +          phdr->p_offset = grub_le_to_offXX (phdr->p_offset);
> +          phdr->p_vaddr = grub_le_to_addrXX (phdr->p_vaddr);
> +          phdr->p_paddr = grub_le_to_addrXX (phdr->p_paddr);
> +          phdr->p_filesz = grub_le_to_XwordXX (phdr->p_filesz);
> +          phdr->p_memsz = grub_le_to_XwordXX (phdr->p_memsz);
> +          phdr->p_align = grub_le_to_XwordXX (phdr->p_align);
> +        }
> +    }
> +}
> +
> +grub_err_t
> +grub_elfXX_check_version (grub_elf_t elf)
> +{
> +  if (elf->ehdr.ehdrXX.e_version != EV_CURRENT)
> +    return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF magic"));
> +
> +  return GRUB_ERR_NONE;
> +}
> -- 
> 2.1.0
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel


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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-06-30 14:33       ` Vladimir 'phcoder' Serbinenko
@ 2015-06-30 18:05         ` Paulo Flabiano Smorigo
  2015-06-30 18:28           ` Andrei Borzenkov
  0 siblings, 1 reply; 23+ messages in thread
From: Paulo Flabiano Smorigo @ 2015-06-30 18:05 UTC (permalink / raw)
  To: grub-devel

On 2015-06-30 11:33, Vladimir 'phcoder' Serbinenko wrote:
> What about clang?

Not good news about clang support. This is what the toolchain team said 
about it:

The -mbig-endian option was added around April 10th, 2014. 
Unfortunately, those who implemented it only implemented it for ARM and 
one other architecture.

The option is currently accepted on Power systems, but does not have any 
affect on the code generation for Power.


So, what can we do here? Maybe add a constrain in the configure file 
saying that it's not possible to build GRUB in a LE environment using clang.
>
> Le 30 juin 2015 16:30, "Andrei Borzenkov" <arvidjaar@gmail.com
> <mailto:arvidjaar@gmail.com>> a écrit :
>
>     On Tue, Jun 30, 2015 at 5:03 PM, Vladimir 'phcoder' Serbinenko
>     <phcoder@gmail.com <mailto:phcoder@gmail.com>> wrote:
>      > Which compilers support these flags? I'm concerned of breaking
>     old compilers
>      >
>
>     -static and -mbig-endian are listed in gcc 2.95.3 documentation for PPC.
>
>      > Le 30 juin 2015 14:57, "Paulo Flabiano Smorigo"
>      > <pfsmorigo@linux.vnet.ibm.com
>     <mailto:pfsmorigo@linux.vnet.ibm.com>> a écrit :
>      >>
>      >> libgcc dependency was removed *just* for this target because
>      >> the distros that use ppc64el doesn't have 32-bit support on it.
>      >>
>      >> * configure.ac <http://configure.ac>: Add targets for
>     powerpc64el and skip libgcc.
>      >> * Makefile.am: Likewise.
>      >> ---
>      >> configure.ac <http://configure.ac> | 8 ++++++++
>      >>  1 file changed, 8 insertions(+)
>      >>
>      >> diff --git a/configure.ac <http://configure.ac> b/configure.ac
>     <http://configure.ac>
>      >> index fd8a62e..0a79fad 100644
>      >> --- a/configure.ac <http://configure.ac>
>      >> +++ b/configure.ac <http://configure.ac>
>      >> @@ -116,6 +116,7 @@ if test "x$with_platform" = x; then
>      >>      x86_64-*) platform=pc ;;
>      >>      powerpc-*) platform=ieee1275 ;;
>      >>      powerpc64-*) platform=ieee1275 ;;
>      >> +    powerpc64le-*) platform=ieee1275 ;;
>      >>      sparc64-*) platform=ieee1275 ;;
>      >>      mipsel-*) platform=loongson ;;
>      >>      mips-*) platform=arc ;;
>      >> @@ -138,6 +139,7 @@ case "$target_cpu"-"$platform" in
>      >>    x86_64-none) ;;
>      >>    x86_64-*) target_cpu=i386 ;;
>      >>    powerpc64-ieee1275) target_cpu=powerpc ;;
>      >> +  powerpc64le-ieee1275) target_cpu=powerpc ;;
>      >>  esac
>      >>
>      >>  # Check if the platform is supported, make final adjustments.
>      >> @@ -601,6 +603,12 @@ if test "x$target_cpu" = xi386 && test
>     "x$platform"
>      >> != xemu; then
>      >>    TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
>      >>  fi
>      >>
>      >> +if test x$target_cpu = xpowerpc; then
>      >> +  TARGET_CFLAGS="$TARGET_CFLAGS -mbig-endian"
>      >> +  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mbig-endian"
>      >> +  TARGET_LDFLAGS="$TARGET_LDFLAGS -static -mbig-endian"
>      >> +fi
>      >> +
>      >>  if test "x$target_m32" = x1; then
>      >>    # Force 32-bit mode.
>      >>    TARGET_CFLAGS="$TARGET_CFLAGS -m32"
>      >> --
>      >> 2.1.0
>      >>
>      >>
>      >> _______________________________________________
>      >> Grub-devel mailing list
>      >> Grub-devel@gnu.org <mailto:Grub-devel@gnu.org>
>      >> https://lists.gnu.org/mailman/listinfo/grub-devel
>      >
>      >
>      > _______________________________________________
>      > Grub-devel mailing list
>      > Grub-devel@gnu.org <mailto:Grub-devel@gnu.org>
>      > https://lists.gnu.org/mailman/listinfo/grub-devel
>      >
>
>     _______________________________________________
>     Grub-devel mailing list
>     Grub-devel@gnu.org <mailto:Grub-devel@gnu.org>
>     https://lists.gnu.org/mailman/listinfo/grub-devel
>
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>


-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center



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

* Re: [PATCH 2/2] Suport for bi-endianess in elf file
  2015-06-30 15:03   ` Andrei Borzenkov
@ 2015-06-30 18:06     ` Paulo Flabiano Smorigo
  0 siblings, 0 replies; 23+ messages in thread
From: Paulo Flabiano Smorigo @ 2015-06-30 18:06 UTC (permalink / raw)
  To: grub-devel

On 2015-06-30 12:03, Andrei Borzenkov wrote:
> Did you intentionally ignore my comments to previous version?

OH no, sorry, I will take a look.

>
> Отправлено с iPhone
>
>> 30 июня 2015 г., в 15:56, Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> написал(а):
>>
>> * grub-core/kern/elf.c: check and switch endianess with grub_{be,le}_to
>> cpu functions.
>> * grub-core/kern/elfXX.c: Likewise.
>>
>> Also-by: Tomohiro B Berry <tbberry@us.ibm.com>
>> ---
>> grub-core/kern/elf.c   | 60 +++++++++++++++++++++++++++++++++++++++--
>> grub-core/kern/elfXX.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++
>> 2 files changed, 131 insertions(+), 2 deletions(-)
>>
>> diff --git a/grub-core/kern/elf.c b/grub-core/kern/elf.c
>> index 5f99c43..de90811 100644
>> --- a/grub-core/kern/elf.c
>> +++ b/grub-core/kern/elf.c
>> @@ -28,6 +28,11 @@
>>
>> GRUB_MOD_LICENSE ("GPLv3+");
>>
>> +void grub_elf32_check_endianess (grub_elf_t elf);
>> +void grub_elf64_check_endianess (grub_elf_t elf);
>> +grub_err_t grub_elf32_check_version (grub_elf_t elf);
>> +grub_err_t grub_elf64_check_version (grub_elf_t elf);
>> +
>> /* Check if EHDR is a valid ELF header.  */
>> static grub_err_t
>> grub_elf_check_header (grub_elf_t elf)
>> @@ -38,10 +43,22 @@ grub_elf_check_header (grub_elf_t elf)
>>        || e->e_ident[EI_MAG1] != ELFMAG1
>>        || e->e_ident[EI_MAG2] != ELFMAG2
>>        || e->e_ident[EI_MAG3] != ELFMAG3
>> -      || e->e_ident[EI_VERSION] != EV_CURRENT
>> -      || e->e_version != EV_CURRENT)
>> +      || e->e_ident[EI_VERSION] != EV_CURRENT)
>>      return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF magic"));
>>
>> +  if (grub_elf_is_elf32 (elf))
>> +    {
>> +      grub_elf32_check_endianess (elf);
>> +      grub_elf32_check_version (elf);
>> +    }
>> +  else if (grub_elf_is_elf64 (elf))
>> +    {
>> +      grub_elf64_check_endianess (elf);
>> +      grub_elf64_check_version (elf);
>> +    }
>> +  else
>> +    return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic"));
>> +
>>    return GRUB_ERR_NONE;
>> }
>>
>> @@ -127,7 +144,20 @@ grub_elf_open (const char *name)
>> #define grub_elf_is_elfXX grub_elf_is_elf32
>> #define grub_elfXX_load_phdrs grub_elf32_load_phdrs
>> #define ElfXX_Phdr Elf32_Phdr
>> +#define ElfXX_Ehdr Elf32_Ehdr
>> #define grub_uintXX_t grub_uint32_t
>> +#define grub_be_to_halfXX grub_be_to_cpu16
>> +#define grub_be_to_wordXX grub_be_to_cpu32
>> +#define grub_be_to_addrXX grub_be_to_cpu32
>> +#define grub_be_to_offXX grub_be_to_cpu32
>> +#define grub_be_to_XwordXX grub_be_to_wordXX
>> +#define grub_le_to_halfXX grub_le_to_cpu16
>> +#define grub_le_to_wordXX grub_le_to_cpu32
>> +#define grub_le_to_addrXX grub_le_to_cpu32
>> +#define grub_le_to_offXX grub_le_to_cpu32
>> +#define grub_le_to_XwordXX grub_le_to_wordXX
>> +#define grub_elfXX_check_endianess grub_elf32_check_endianess
>> +#define grub_elfXX_check_version grub_elf32_check_version
>>
>> #include "elfXX.c"
>>
>> @@ -140,7 +170,20 @@ grub_elf_open (const char *name)
>> #undef grub_elf_is_elfXX
>> #undef grub_elfXX_load_phdrs
>> #undef ElfXX_Phdr
>> +#undef ElfXX_Ehdr
>> #undef grub_uintXX_t
>> +#undef grub_be_to_halfXX
>> +#undef grub_be_to_wordXX
>> +#undef grub_be_to_addrXX
>> +#undef grub_be_to_offXX
>> +#undef grub_be_to_XwordXX
>> +#undef grub_le_to_halfXX
>> +#undef grub_le_to_wordXX
>> +#undef grub_le_to_addrXX
>> +#undef grub_le_to_offXX
>> +#undef grub_le_to_XwordXX
>> +#undef grub_elfXX_check_endianess
>> +#undef grub_elfXX_check_version
>>
>> \f
>> /* 64-bit */
>> @@ -153,6 +196,19 @@ grub_elf_open (const char *name)
>> #define grub_elf_is_elfXX grub_elf_is_elf64
>> #define grub_elfXX_load_phdrs grub_elf64_load_phdrs
>> #define ElfXX_Phdr Elf64_Phdr
>> +#define ElfXX_Ehdr Elf64_Ehdr
>> #define grub_uintXX_t grub_uint64_t
>> +#define grub_be_to_halfXX grub_be_to_cpu16
>> +#define grub_be_to_wordXX grub_be_to_cpu32
>> +#define grub_be_to_addrXX grub_be_to_cpu64
>> +#define grub_be_to_offXX grub_be_to_cpu64
>> +#define grub_be_to_XwordXX grub_be_to_cpu64
>> +#define grub_le_to_halfXX grub_le_to_cpu16
>> +#define grub_le_to_wordXX grub_le_to_cpu32
>> +#define grub_le_to_addrXX grub_le_to_cpu64
>> +#define grub_le_to_offXX grub_le_to_cpu64
>> +#define grub_le_to_XwordXX grub_le_to_cpu64
>> +#define grub_elfXX_check_endianess grub_elf64_check_endianess
>> +#define grub_elfXX_check_version grub_elf64_check_version
>>
>> #include "elfXX.c"
>> diff --git a/grub-core/kern/elfXX.c b/grub-core/kern/elfXX.c
>> index 1d09971..ecf9df6 100644
>> --- a/grub-core/kern/elfXX.c
>> +++ b/grub-core/kern/elfXX.c
>> @@ -154,3 +154,76 @@ grub_elfXX_load (grub_elf_t elf, const char *filename,
>>
>>    return grub_errno;
>> }
>> +
>> +void
>> +grub_elfXX_check_endianess (grub_elf_t elf)
>> +{
>> +  ElfXX_Ehdr *e = &(elf->ehdr.ehdrXX);
>> +  ElfXX_Phdr *phdr;
>> +
>> +  if (e->e_ident[EI_DATA] == ELFDATA2MSB)
>> +    {
>> +      e->e_type = grub_be_to_halfXX (e->e_type);
>> +      e->e_machine = grub_be_to_halfXX (e->e_machine);
>> +      e->e_version = grub_be_to_wordXX (e->e_version);
>> +      e->e_entry = grub_be_to_addrXX (e->e_entry);
>> +      e->e_phoff = grub_be_to_offXX (e->e_phoff);
>> +      e->e_shoff = grub_be_to_offXX (e->e_shoff);
>> +      e->e_flags = grub_be_to_wordXX (e->e_flags);
>> +      e->e_ehsize = grub_be_to_halfXX (e->e_ehsize);
>> +      e->e_phentsize = grub_be_to_halfXX (e->e_phentsize);
>> +      e->e_phnum = grub_be_to_halfXX (e->e_phnum);
>> +      e->e_shentsize = grub_be_to_halfXX (e->e_shentsize);
>> +      e->e_shnum = grub_be_to_halfXX (e->e_shnum);
>> +      e->e_shstrndx = grub_be_to_halfXX (e->e_shstrndx);
>> +
>> +      FOR_ELFXX_PHDRS (elf,phdr)
>> +        {
>> +          phdr->p_type = grub_be_to_wordXX (phdr->p_type);
>> +          phdr->p_flags = grub_be_to_wordXX (phdr->p_flags);
>> +          phdr->p_offset = grub_be_to_offXX (phdr->p_offset);
>> +          phdr->p_vaddr = grub_be_to_addrXX (phdr->p_vaddr);
>> +          phdr->p_paddr = grub_be_to_addrXX (phdr->p_paddr);
>> +          phdr->p_filesz = grub_be_to_XwordXX (phdr->p_filesz);
>> +          phdr->p_memsz = grub_be_to_XwordXX (phdr->p_memsz);
>> +          phdr->p_align = grub_be_to_XwordXX (phdr->p_align);
>> +        }
>> +    }
>> +  else if (e->e_ident[EI_DATA] == ELFDATA2LSB)
>> +    {
>> +      e->e_type = grub_le_to_halfXX (e->e_type);
>> +      e->e_machine = grub_le_to_halfXX (e->e_machine);
>> +      e->e_version = grub_le_to_wordXX (e->e_version);
>> +      e->e_entry = grub_le_to_addrXX (e->e_entry);
>> +      e->e_phoff = grub_le_to_offXX (e->e_phoff);
>> +      e->e_shoff = grub_le_to_offXX (e->e_shoff);
>> +      e->e_flags = grub_le_to_wordXX (e->e_flags);
>> +      e->e_ehsize = grub_le_to_halfXX (e->e_ehsize);
>> +      e->e_phentsize = grub_le_to_halfXX (e->e_phentsize);
>> +      e->e_phnum = grub_le_to_halfXX (e->e_phnum);
>> +      e->e_shentsize = grub_le_to_halfXX (e->e_shentsize);
>> +      e->e_shnum = grub_le_to_halfXX (e->e_shnum);
>> +      e->e_shstrndx = grub_le_to_halfXX (e->e_shstrndx);
>> +
>> +      FOR_ELFXX_PHDRS (elf,phdr)
>> +        {
>> +          phdr->p_type = grub_le_to_wordXX (phdr->p_type);
>> +          phdr->p_flags = grub_le_to_wordXX (phdr->p_flags);
>> +          phdr->p_offset = grub_le_to_offXX (phdr->p_offset);
>> +          phdr->p_vaddr = grub_le_to_addrXX (phdr->p_vaddr);
>> +          phdr->p_paddr = grub_le_to_addrXX (phdr->p_paddr);
>> +          phdr->p_filesz = grub_le_to_XwordXX (phdr->p_filesz);
>> +          phdr->p_memsz = grub_le_to_XwordXX (phdr->p_memsz);
>> +          phdr->p_align = grub_le_to_XwordXX (phdr->p_align);
>> +        }
>> +    }
>> +}
>> +
>> +grub_err_t
>> +grub_elfXX_check_version (grub_elf_t elf)
>> +{
>> +  if (elf->ehdr.ehdrXX.e_version != EV_CURRENT)
>> +    return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF magic"));
>> +
>> +  return GRUB_ERR_NONE;
>> +}
>> --
>> 2.1.0
>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>


-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center



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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-06-30 18:05         ` Paulo Flabiano Smorigo
@ 2015-06-30 18:28           ` Andrei Borzenkov
  2015-06-30 19:34             ` Vladimir 'phcoder' Serbinenko
  2015-07-15 16:46             ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 2 replies; 23+ messages in thread
From: Andrei Borzenkov @ 2015-06-30 18:28 UTC (permalink / raw)
  To: Paulo Flabiano Smorigo; +Cc: grub-devel

В Tue, 30 Jun 2015 15:05:46 -0300
Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> пишет:

> On 2015-06-30 11:33, Vladimir 'phcoder' Serbinenko wrote:
> > What about clang?
> 
> Not good news about clang support. This is what the toolchain team said 
> about it:
> 
> The -mbig-endian option was added around April 10th, 2014. 
> Unfortunately, those who implemented it only implemented it for ARM and 
> one other architecture.
> 
> The option is currently accepted on Power systems, but does not have any 
> affect on the code generation for Power.
> 
> 
> So, what can we do here? Maybe add a constrain in the configure file 
> saying that it's not possible to build GRUB in a LE environment using clang.

If I understand it correctly, it is possible to build for big-endian
PowerPC using

clang -target=powerpc

but then we depend on clang being built with BE target support; and
e.g. openSUSE builds it with

cmake -G "Ninja" \
      -DBUILD_SHARED_LIBS=OFF \
      -DCMAKE_BUILD_TYPE=Release \
      -DLLVM_ENABLE_ASSERTIONS=OFF \
      -DLLVM_TARGETS_TO_BUILD=host \
      -DCMAKE_C_FLAGS="-O0" \
      -DCMAKE_CXX_FLAGS="-O0" \
      -DLLVM_HOST_TRIPLE=%{host_triple} \

so as I understand on ppc64le it does not build support for any other
target. Actually openSUSE does not even build clang on ppc at all.



> >
> > Le 30 juin 2015 16:30, "Andrei Borzenkov" <arvidjaar@gmail.com
> > <mailto:arvidjaar@gmail.com>> a écrit :
> >
> >     On Tue, Jun 30, 2015 at 5:03 PM, Vladimir 'phcoder' Serbinenko
> >     <phcoder@gmail.com <mailto:phcoder@gmail.com>> wrote:
> >      > Which compilers support these flags? I'm concerned of breaking
> >     old compilers
> >      >
> >
> >     -static and -mbig-endian are listed in gcc 2.95.3 documentation for PPC.
> >
> >      > Le 30 juin 2015 14:57, "Paulo Flabiano Smorigo"
> >      > <pfsmorigo@linux.vnet.ibm.com
> >     <mailto:pfsmorigo@linux.vnet.ibm.com>> a écrit :
> >      >>
> >      >> libgcc dependency was removed *just* for this target because
> >      >> the distros that use ppc64el doesn't have 32-bit support on it.
> >      >>
> >      >> * configure.ac <http://configure.ac>: Add targets for
> >     powerpc64el and skip libgcc.
> >      >> * Makefile.am: Likewise.
> >      >> ---
> >      >> configure.ac <http://configure.ac> | 8 ++++++++
> >      >>  1 file changed, 8 insertions(+)
> >      >>
> >      >> diff --git a/configure.ac <http://configure.ac> b/configure.ac
> >     <http://configure.ac>
> >      >> index fd8a62e..0a79fad 100644
> >      >> --- a/configure.ac <http://configure.ac>
> >      >> +++ b/configure.ac <http://configure.ac>
> >      >> @@ -116,6 +116,7 @@ if test "x$with_platform" = x; then
> >      >>      x86_64-*) platform=pc ;;
> >      >>      powerpc-*) platform=ieee1275 ;;
> >      >>      powerpc64-*) platform=ieee1275 ;;
> >      >> +    powerpc64le-*) platform=ieee1275 ;;
> >      >>      sparc64-*) platform=ieee1275 ;;
> >      >>      mipsel-*) platform=loongson ;;
> >      >>      mips-*) platform=arc ;;
> >      >> @@ -138,6 +139,7 @@ case "$target_cpu"-"$platform" in
> >      >>    x86_64-none) ;;
> >      >>    x86_64-*) target_cpu=i386 ;;
> >      >>    powerpc64-ieee1275) target_cpu=powerpc ;;
> >      >> +  powerpc64le-ieee1275) target_cpu=powerpc ;;
> >      >>  esac
> >      >>
> >      >>  # Check if the platform is supported, make final adjustments.
> >      >> @@ -601,6 +603,12 @@ if test "x$target_cpu" = xi386 && test
> >     "x$platform"
> >      >> != xemu; then
> >      >>    TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
> >      >>  fi
> >      >>
> >      >> +if test x$target_cpu = xpowerpc; then
> >      >> +  TARGET_CFLAGS="$TARGET_CFLAGS -mbig-endian"
> >      >> +  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mbig-endian"
> >      >> +  TARGET_LDFLAGS="$TARGET_LDFLAGS -static -mbig-endian"
> >      >> +fi
> >      >> +
> >      >>  if test "x$target_m32" = x1; then
> >      >>    # Force 32-bit mode.
> >      >>    TARGET_CFLAGS="$TARGET_CFLAGS -m32"
> >      >> --
> >      >> 2.1.0
> >      >>
> >      >>
> >      >> _______________________________________________
> >      >> Grub-devel mailing list
> >      >> Grub-devel@gnu.org <mailto:Grub-devel@gnu.org>
> >      >> https://lists.gnu.org/mailman/listinfo/grub-devel
> >      >
> >      >
> >      > _______________________________________________
> >      > Grub-devel mailing list
> >      > Grub-devel@gnu.org <mailto:Grub-devel@gnu.org>
> >      > https://lists.gnu.org/mailman/listinfo/grub-devel
> >      >
> >
> >     _______________________________________________
> >     Grub-devel mailing list
> >     Grub-devel@gnu.org <mailto:Grub-devel@gnu.org>
> >     https://lists.gnu.org/mailman/listinfo/grub-devel
> >
> >
> >
> > _______________________________________________
> > Grub-devel mailing list
> > Grub-devel@gnu.org
> > https://lists.gnu.org/mailman/listinfo/grub-devel
> >
> 
> 



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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-06-30 18:28           ` Andrei Borzenkov
@ 2015-06-30 19:34             ` Vladimir 'phcoder' Serbinenko
  2015-07-04  6:46               ` Andrei Borzenkov
  2015-07-15 16:46             ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 1 reply; 23+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2015-06-30 19:34 UTC (permalink / raw)
  To: The development of GRUB 2; +Cc: Paulo Flabiano Smorigo

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

I think those flags disable only runtime libraries, not the code generation
Le 30 juin 2015 20:29, "Andrei Borzenkov" <arvidjaar@gmail.com> a écrit :

> В Tue, 30 Jun 2015 15:05:46 -0300
> Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> пишет:
>
> > On 2015-06-30 11:33, Vladimir 'phcoder' Serbinenko wrote:
> > > What about clang?
> >
> > Not good news about clang support. This is what the toolchain team said
> > about it:
> >
> > The -mbig-endian option was added around April 10th, 2014.
> > Unfortunately, those who implemented it only implemented it for ARM and
> > one other architecture.
> >
> > The option is currently accepted on Power systems, but does not have any
> > affect on the code generation for Power.
> >
> >
> > So, what can we do here? Maybe add a constrain in the configure file
> > saying that it's not possible to build GRUB in a LE environment using
> clang.
>
> If I understand it correctly, it is possible to build for big-endian
> PowerPC using
>
> clang -target=powerpc
>
> but then we depend on clang being built with BE target support; and
> e.g. openSUSE builds it with
>
> cmake -G "Ninja" \
>       -DBUILD_SHARED_LIBS=OFF \
>       -DCMAKE_BUILD_TYPE=Release \
>       -DLLVM_ENABLE_ASSERTIONS=OFF \
>       -DLLVM_TARGETS_TO_BUILD=host \
>       -DCMAKE_C_FLAGS="-O0" \
>       -DCMAKE_CXX_FLAGS="-O0" \
>       -DLLVM_HOST_TRIPLE=%{host_triple} \
>
> so as I understand on ppc64le it does not build support for any other
> target. Actually openSUSE does not even build clang on ppc at all.
>
>
>
> > >
> > > Le 30 juin 2015 16:30, "Andrei Borzenkov" <arvidjaar@gmail.com
> > > <mailto:arvidjaar@gmail.com>> a écrit :
> > >
> > >     On Tue, Jun 30, 2015 at 5:03 PM, Vladimir 'phcoder' Serbinenko
> > >     <phcoder@gmail.com <mailto:phcoder@gmail.com>> wrote:
> > >      > Which compilers support these flags? I'm concerned of breaking
> > >     old compilers
> > >      >
> > >
> > >     -static and -mbig-endian are listed in gcc 2.95.3 documentation
> for PPC.
> > >
> > >      > Le 30 juin 2015 14:57, "Paulo Flabiano Smorigo"
> > >      > <pfsmorigo@linux.vnet.ibm.com
> > >     <mailto:pfsmorigo@linux.vnet.ibm.com>> a écrit :
> > >      >>
> > >      >> libgcc dependency was removed *just* for this target because
> > >      >> the distros that use ppc64el doesn't have 32-bit support on it.
> > >      >>
> > >      >> * configure.ac <http://configure.ac>: Add targets for
> > >     powerpc64el and skip libgcc.
> > >      >> * Makefile.am: Likewise.
> > >      >> ---
> > >      >> configure.ac <http://configure.ac> | 8 ++++++++
> > >      >>  1 file changed, 8 insertions(+)
> > >      >>
> > >      >> diff --git a/configure.ac <http://configure.ac> b/configure.ac
> > >     <http://configure.ac>
> > >      >> index fd8a62e..0a79fad 100644
> > >      >> --- a/configure.ac <http://configure.ac>
> > >      >> +++ b/configure.ac <http://configure.ac>
> > >      >> @@ -116,6 +116,7 @@ if test "x$with_platform" = x; then
> > >      >>      x86_64-*) platform=pc ;;
> > >      >>      powerpc-*) platform=ieee1275 ;;
> > >      >>      powerpc64-*) platform=ieee1275 ;;
> > >      >> +    powerpc64le-*) platform=ieee1275 ;;
> > >      >>      sparc64-*) platform=ieee1275 ;;
> > >      >>      mipsel-*) platform=loongson ;;
> > >      >>      mips-*) platform=arc ;;
> > >      >> @@ -138,6 +139,7 @@ case "$target_cpu"-"$platform" in
> > >      >>    x86_64-none) ;;
> > >      >>    x86_64-*) target_cpu=i386 ;;
> > >      >>    powerpc64-ieee1275) target_cpu=powerpc ;;
> > >      >> +  powerpc64le-ieee1275) target_cpu=powerpc ;;
> > >      >>  esac
> > >      >>
> > >      >>  # Check if the platform is supported, make final adjustments.
> > >      >> @@ -601,6 +603,12 @@ if test "x$target_cpu" = xi386 && test
> > >     "x$platform"
> > >      >> != xemu; then
> > >      >>    TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
> > >      >>  fi
> > >      >>
> > >      >> +if test x$target_cpu = xpowerpc; then
> > >      >> +  TARGET_CFLAGS="$TARGET_CFLAGS -mbig-endian"
> > >      >> +  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mbig-endian"
> > >      >> +  TARGET_LDFLAGS="$TARGET_LDFLAGS -static -mbig-endian"
> > >      >> +fi
> > >      >> +
> > >      >>  if test "x$target_m32" = x1; then
> > >      >>    # Force 32-bit mode.
> > >      >>    TARGET_CFLAGS="$TARGET_CFLAGS -m32"
> > >      >> --
> > >      >> 2.1.0
> > >      >>
> > >      >>
> > >      >> _______________________________________________
> > >      >> Grub-devel mailing list
> > >      >> Grub-devel@gnu.org <mailto:Grub-devel@gnu.org>
> > >      >> https://lists.gnu.org/mailman/listinfo/grub-devel
> > >      >
> > >      >
> > >      > _______________________________________________
> > >      > Grub-devel mailing list
> > >      > Grub-devel@gnu.org <mailto:Grub-devel@gnu.org>
> > >      > https://lists.gnu.org/mailman/listinfo/grub-devel
> > >      >
> > >
> > >     _______________________________________________
> > >     Grub-devel mailing list
> > >     Grub-devel@gnu.org <mailto:Grub-devel@gnu.org>
> > >     https://lists.gnu.org/mailman/listinfo/grub-devel
> > >
> > >
> > >
> > > _______________________________________________
> > > Grub-devel mailing list
> > > Grub-devel@gnu.org
> > > https://lists.gnu.org/mailman/listinfo/grub-devel
> > >
> >
> >
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

[-- Attachment #2: Type: text/html, Size: 9585 bytes --]

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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-06-30 19:34             ` Vladimir 'phcoder' Serbinenko
@ 2015-07-04  6:46               ` Andrei Borzenkov
  2015-07-05 17:38                 ` Andrei Borzenkov
  2015-07-15 17:36                 ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 2 replies; 23+ messages in thread
From: Andrei Borzenkov @ 2015-07-04  6:46 UTC (permalink / raw)
  To: Vladimir 'phcoder' Serbinenko
  Cc: The development of GRUB 2, Paulo Flabiano Smorigo

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

В Tue, 30 Jun 2015 21:34:10 +0200
"Vladimir 'phcoder' Serbinenko" <phcoder@gmail.com> пишет:

> I think those flags disable only runtime libraries, not the code generation

Yes, you are right. Clang seems to be built for the whole family, i.e.
PowerPC, which seems to automatically include all three versions (ppc,
ppc64, ppc64le)

See below for details.

> Le 30 juin 2015 20:29, "Andrei Borzenkov" <arvidjaar@gmail.com> a écrit :
> 
> > В Tue, 30 Jun 2015 15:05:46 -0300
> > Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> пишет:
> >
> > > On 2015-06-30 11:33, Vladimir 'phcoder' Serbinenko wrote:
> > > > What about clang?
> > >
> > > Not good news about clang support. This is what the toolchain team said
> > > about it:
> > >
> > > The -mbig-endian option was added around April 10th, 2014.
> > > Unfortunately, those who implemented it only implemented it for ARM and
> > > one other architecture.
> > >
> > > The option is currently accepted on Power systems, but does not have any
> > > affect on the code generation for Power.
> > >

Support for it looks rather trivial; see attached patch. Anyone has good
connection to clang development community?

Using this patch the

clang --target=powerpc64le -mbig-endian -m32 produces code for PPC32
BE, so just works:

bor@opensuse:~/build/clang-ppc/bin> ./clang  --target=powerpc64le   -c -mbig-endian -m32 /tmp/foo.c
/tmp/foo.c:1:1: warning: type specifier missing, defaults to 'int'
      [-Wimplicit-int]
foo()
^
1 warning generated.
bor@opensuse:~/build/clang-ppc/bin> file foo.o
foo.o: ELF 32-bit MSB relocatable, PowerPC or cisco 4500, version 1 (SYSV), not stripped

The problem is that in this case we do not really have any way to test
if it works in configure, so no way to fail gracefully.

> > >
> > > So, what can we do here? Maybe add a constrain in the configure file
> > > saying that it's not possible to build GRUB in a LE environment using
> > clang.
> >
> > If I understand it correctly, it is possible to build for big-endian
> > PowerPC using
> >
> > clang -target=powerpc
> >
> > but then we depend on clang being built with BE target support; and
> > e.g. openSUSE builds it with
> >

Yes, that works too. But I'm not sure how we can test for it. Brute
force would of course be

$TARGET_CC --version | grep clang && TARGET_CFLAGS=--target=powerpc

Comments? I'm inclined to use this workaround. This still may have
issues when using external assembler, but here we can simply mandate
support for clang 3.6 at the minimum, which should use integrated
assembler on PPC by default.

[-- Attachment #2: clang-ppc-endian-switch.patch --]
[-- Type: text/x-patch, Size: 1275 bytes --]

From: Andrei Borzenkov <arvidjaar@gmail.com>
Subject: [PATCH] support -big-endian/-mlittle-endian on PowerPC64

Signed-off-by: Andrei Borzenkov <arvidjaar@gmail.com>

---
 lib/Driver/Driver.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index d4b47a4..b7a6a66 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -1947,6 +1947,8 @@ static llvm::Triple computeTargetTriple(StringRef DefaultTargetTriple,
         Target.setArch(llvm::Triple::mips64el);
       else if (Target.getArch() == llvm::Triple::aarch64_be)
         Target.setArch(llvm::Triple::aarch64);
+      else if (Target.getArch() == llvm::Triple::ppc64)
+        Target.setArch(llvm::Triple::ppc64le);
     } else {
       if (Target.getArch() == llvm::Triple::mipsel)
         Target.setArch(llvm::Triple::mips);
@@ -1954,6 +1956,8 @@ static llvm::Triple computeTargetTriple(StringRef DefaultTargetTriple,
         Target.setArch(llvm::Triple::mips64);
       else if (Target.getArch() == llvm::Triple::aarch64)
         Target.setArch(llvm::Triple::aarch64_be);
+      else if (Target.getArch() == llvm::Triple::ppc64le)
+        Target.setArch(llvm::Triple::ppc64);
     }
   }
 
-- 
tg: (76af433..) e/ppc-mendian (depends on: master)

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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-07-04  6:46               ` Andrei Borzenkov
@ 2015-07-05 17:38                 ` Andrei Borzenkov
  2015-07-15 17:42                   ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-07-15 17:36                 ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 1 reply; 23+ messages in thread
From: Andrei Borzenkov @ 2015-07-05 17:38 UTC (permalink / raw)
  To: Vladimir 'phcoder' Serbinenko
  Cc: The development of GRUB 2, Paulo Flabiano Smorigo

В Sat, 4 Jul 2015 09:46:59 +0300
Andrei Borzenkov <arvidjaar@gmail.com> пишет:

> В Tue, 30 Jun 2015 21:34:10 +0200
> "Vladimir 'phcoder' Serbinenko" <phcoder@gmail.com> пишет:
> 
> > I think those flags disable only runtime libraries, not the code generation
> 
> Yes, you are right. Clang seems to be built for the whole family, i.e.
> PowerPC, which seems to automatically include all three versions (ppc,
> ppc64, ppc64le)
> 
> See below for details.
> 
> > Le 30 juin 2015 20:29, "Andrei Borzenkov" <arvidjaar@gmail.com> a écrit :
> > 
> > > В Tue, 30 Jun 2015 15:05:46 -0300
> > > Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> пишет:
> > >
> > > > On 2015-06-30 11:33, Vladimir 'phcoder' Serbinenko wrote:
> > > > > What about clang?
> > > >
> > > > Not good news about clang support. This is what the toolchain team said
> > > > about it:
> > > >
> > > > The -mbig-endian option was added around April 10th, 2014.
> > > > Unfortunately, those who implemented it only implemented it for ARM and
> > > > one other architecture.
> > > >
> > > > The option is currently accepted on Power systems, but does not have any
> > > > affect on the code generation for Power.
> > > >
> 
> Support for it looks rather trivial; see attached patch. Anyone has good
> connection to clang development community?
> 
> Using this patch the
> 
> clang --target=powerpc64le -mbig-endian -m32 produces code for PPC32
> BE, so just works:
> 
> bor@opensuse:~/build/clang-ppc/bin> ./clang  --target=powerpc64le   -c -mbig-endian -m32 /tmp/foo.c
> /tmp/foo.c:1:1: warning: type specifier missing, defaults to 'int'
>       [-Wimplicit-int]
> foo()
> ^
> 1 warning generated.
> bor@opensuse:~/build/clang-ppc/bin> file foo.o
> foo.o: ELF 32-bit MSB relocatable, PowerPC or cisco 4500, version 1 (SYSV), not stripped
> 
> The problem is that in this case we do not really have any way to test
> if it works in configure, so no way to fail gracefully.
> 
> > > >
> > > > So, what can we do here? Maybe add a constrain in the configure file
> > > > saying that it's not possible to build GRUB in a LE environment using
> > > clang.
> > >
> > > If I understand it correctly, it is possible to build for big-endian
> > > PowerPC using
> > >
> > > clang -target=powerpc
> > >
> > > but then we depend on clang being built with BE target support; and
> > > e.g. openSUSE builds it with
> > >
> 
> Yes, that works too. But I'm not sure how we can test for it. Brute
> force would of course be
> 
> $TARGET_CC --version | grep clang && TARGET_CFLAGS=--target=powerpc
> 
> Comments? I'm inclined to use this workaround. This still may have
> issues when using external assembler, but here we can simply mandate
> support for clang 3.6 at the minimum, which should use integrated
> assembler on PPC by default.

Unfortunately it fails to link. clang does not pass any explicit
endian flag to linker; endianness is property of target and clang
expects to have tool chain for each target. This is exactly what we
want to avoid (we want to avoid having ppc32 toolchaing on ppc64le), so
clang falls back to generic gcc as linker and it attempts to produce LE
output from BE objects and fails.

I thinks it is clang deficiency. It should pass endianness flags just
as it does currently for -m32/-m64.

It is possible to compile using "--target=powerpc -Wl,-EB" - this works
on all three ppc, ppc64 and ppc64le, but this means hardcoding GNU ld
dependency.

So I'd rather try to produce patch for proper support of
-mbig-endian/-mlittle-endian (including passing it onto gcc linker) and
until then declared clang on ppc64le having limited support (i.e.
support for automatic detection by configure).



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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-06-30 18:28           ` Andrei Borzenkov
  2015-06-30 19:34             ` Vladimir 'phcoder' Serbinenko
@ 2015-07-15 16:46             ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 0 replies; 23+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-07-15 16:46 UTC (permalink / raw)
  To: The development of GNU GRUB


[-- Attachment #1.1: Type: text/plain, Size: 5364 bytes --]

On 30.06.2015 20:28, Andrei Borzenkov wrote:
> В Tue, 30 Jun 2015 15:05:46 -0300
> Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> пишет:
> 
>> On 2015-06-30 11:33, Vladimir 'phcoder' Serbinenko wrote:
>>> What about clang?
>>
>> Not good news about clang support. This is what the toolchain team said 
>> about it:
>>
>> The -mbig-endian option was added around April 10th, 2014. 
>> Unfortunately, those who implemented it only implemented it for ARM and 
>> one other architecture.
>>
>> The option is currently accepted on Power systems, but does not have any 
>> affect on the code generation for Power.
>>
>>
>> So, what can we do here? Maybe add a constrain in the configure file 
>> saying that it's not possible to build GRUB in a LE environment using clang.
> 
> If I understand it correctly, it is possible to build for big-endian
> PowerPC using
> 
> clang -target=powerpc
> 
@pfsmorigo. Please try attached patch
> but then we depend on clang being built with BE target support; and
> e.g. openSUSE builds it with
> 
> cmake -G "Ninja" \
>       -DBUILD_SHARED_LIBS=OFF \
>       -DCMAKE_BUILD_TYPE=Release \
>       -DLLVM_ENABLE_ASSERTIONS=OFF \
>       -DLLVM_TARGETS_TO_BUILD=host \
>       -DCMAKE_C_FLAGS="-O0" \
>       -DCMAKE_CXX_FLAGS="-O0" \
>       -DLLVM_HOST_TRIPLE=%{host_triple} \
> 
> so as I understand on ppc64le it does not build support for any other
> target. Actually openSUSE does not even build clang on ppc at all.
> 
> 
> 
>>>
>>> Le 30 juin 2015 16:30, "Andrei Borzenkov" <arvidjaar@gmail.com
>>> <mailto:arvidjaar@gmail.com>> a écrit :
>>>
>>>     On Tue, Jun 30, 2015 at 5:03 PM, Vladimir 'phcoder' Serbinenko
>>>     <phcoder@gmail.com <mailto:phcoder@gmail.com>> wrote:
>>>      > Which compilers support these flags? I'm concerned of breaking
>>>     old compilers
>>>      >
>>>
>>>     -static and -mbig-endian are listed in gcc 2.95.3 documentation for PPC.
>>>
>>>      > Le 30 juin 2015 14:57, "Paulo Flabiano Smorigo"
>>>      > <pfsmorigo@linux.vnet.ibm.com
>>>     <mailto:pfsmorigo@linux.vnet.ibm.com>> a écrit :
>>>      >>
>>>      >> libgcc dependency was removed *just* for this target because
>>>      >> the distros that use ppc64el doesn't have 32-bit support on it.
>>>      >>
>>>      >> * configure.ac <http://configure.ac>: Add targets for
>>>     powerpc64el and skip libgcc.
>>>      >> * Makefile.am: Likewise.
>>>      >> ---
>>>      >> configure.ac <http://configure.ac> | 8 ++++++++
>>>      >>  1 file changed, 8 insertions(+)
>>>      >>
>>>      >> diff --git a/configure.ac <http://configure.ac> b/configure.ac
>>>     <http://configure.ac>
>>>      >> index fd8a62e..0a79fad 100644
>>>      >> --- a/configure.ac <http://configure.ac>
>>>      >> +++ b/configure.ac <http://configure.ac>
>>>      >> @@ -116,6 +116,7 @@ if test "x$with_platform" = x; then
>>>      >>      x86_64-*) platform=pc ;;
>>>      >>      powerpc-*) platform=ieee1275 ;;
>>>      >>      powerpc64-*) platform=ieee1275 ;;
>>>      >> +    powerpc64le-*) platform=ieee1275 ;;
>>>      >>      sparc64-*) platform=ieee1275 ;;
>>>      >>      mipsel-*) platform=loongson ;;
>>>      >>      mips-*) platform=arc ;;
>>>      >> @@ -138,6 +139,7 @@ case "$target_cpu"-"$platform" in
>>>      >>    x86_64-none) ;;
>>>      >>    x86_64-*) target_cpu=i386 ;;
>>>      >>    powerpc64-ieee1275) target_cpu=powerpc ;;
>>>      >> +  powerpc64le-ieee1275) target_cpu=powerpc ;;
>>>      >>  esac
>>>      >>
>>>      >>  # Check if the platform is supported, make final adjustments.
>>>      >> @@ -601,6 +603,12 @@ if test "x$target_cpu" = xi386 && test
>>>     "x$platform"
>>>      >> != xemu; then
>>>      >>    TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
>>>      >>  fi
>>>      >>
>>>      >> +if test x$target_cpu = xpowerpc; then
>>>      >> +  TARGET_CFLAGS="$TARGET_CFLAGS -mbig-endian"
>>>      >> +  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mbig-endian"
>>>      >> +  TARGET_LDFLAGS="$TARGET_LDFLAGS -static -mbig-endian"
>>>      >> +fi
>>>      >> +
>>>      >>  if test "x$target_m32" = x1; then
>>>      >>    # Force 32-bit mode.
>>>      >>    TARGET_CFLAGS="$TARGET_CFLAGS -m32"
>>>      >> --
>>>      >> 2.1.0
>>>      >>
>>>      >>
>>>      >> _______________________________________________
>>>      >> Grub-devel mailing list
>>>      >> Grub-devel@gnu.org <mailto:Grub-devel@gnu.org>
>>>      >> https://lists.gnu.org/mailman/listinfo/grub-devel
>>>      >
>>>      >
>>>      > _______________________________________________
>>>      > Grub-devel mailing list
>>>      > Grub-devel@gnu.org <mailto:Grub-devel@gnu.org>
>>>      > https://lists.gnu.org/mailman/listinfo/grub-devel
>>>      >
>>>
>>>     _______________________________________________
>>>     Grub-devel mailing list
>>>     Grub-devel@gnu.org <mailto:Grub-devel@gnu.org>
>>>     https://lists.gnu.org/mailman/listinfo/grub-devel
>>>
>>>
>>>
>>> _______________________________________________
>>> Grub-devel mailing list
>>> Grub-devel@gnu.org
>>> https://lists.gnu.org/mailman/listinfo/grub-devel
>>>
>>
>>
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
> 


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: be.diff --]
[-- Type: text/x-diff; name="be.diff", Size: 1935 bytes --]

diff --git a/configure.ac b/configure.ac
index fd8a62e..a4ee419 100644
--- a/configure.ac
+++ b/configure.ac
@@ -116,6 +116,7 @@ if test "x$with_platform" = x; then
     x86_64-*) platform=pc ;;
     powerpc-*) platform=ieee1275 ;;
     powerpc64-*) platform=ieee1275 ;;
+    powerpc64le-*) platform=ieee1275 ;;
     sparc64-*) platform=ieee1275 ;;
     mipsel-*) platform=loongson ;;
     mips-*) platform=arc ;;
@@ -138,6 +139,7 @@ case "$target_cpu"-"$platform" in
   x86_64-none) ;;
   x86_64-*) target_cpu=i386 ;;
   powerpc64-ieee1275) target_cpu=powerpc ;;
+  powerpc64le-ieee1275) target_cpu=powerpc ;;
 esac
 
 # Check if the platform is supported, make final adjustments.
@@ -601,6 +603,33 @@ if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
   TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
 fi
 
+if test x$target_cpu = xpowerpc; then
+  AC_CACHE_CHECK([for options to get big-endian compilation], grub_cv_target_cc_big_endian, [
+    grub_cv_target_cc_big_endian=no
+    for cand in "-target powerpc" \
+		"-mbig-endian"; do
+      if test x"$grub_cv_target_cc_big_endian" != xno ; then
+        break
+      fi
+      CFLAGS="$TARGET_CFLAGS $cand -Werror"
+      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__ORDER_BIG_ENDIAN__ != __BYTE_ORDER__)
+#error still little endian
+#endif
+]], [[]])],
+		        [grub_cv_target_cc_big_endian="$cand"], [])
+    done
+  ])
+
+  if test x"$grub_cv_target_cc_big_endian" = xno ; then
+    AC_MSG_ERROR([could not force big-endian])
+  fi
+
+  TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_big_endian"
+  TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_target_cc_big_endian"
+  TARGET_LDFLAGS="$TARGET_LDFLAGS -static $grub_cv_target_cc_big_endian"
+fi
+
 if test "x$target_m32" = x1; then
   # Force 32-bit mode.
   TARGET_CFLAGS="$TARGET_CFLAGS -m32"

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-07-04  6:46               ` Andrei Borzenkov
  2015-07-05 17:38                 ` Andrei Borzenkov
@ 2015-07-15 17:36                 ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 0 replies; 23+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-07-15 17:36 UTC (permalink / raw)
  To: Andrei Borzenkov; +Cc: The development of GRUB 2, Paulo Flabiano Smorigo

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

On 04.07.2015 08:46, Andrei Borzenkov wrote:
> В Tue, 30 Jun 2015 21:34:10 +0200
> "Vladimir 'phcoder' Serbinenko" <phcoder@gmail.com> пишет:
> 
>> I think those flags disable only runtime libraries, not the code generation
> 
> Yes, you are right. Clang seems to be built for the whole family, i.e.
> PowerPC, which seems to automatically include all three versions (ppc,
> ppc64, ppc64le)
> 
> See below for details.
> 
>> Le 30 juin 2015 20:29, "Andrei Borzenkov" <arvidjaar@gmail.com> a écrit :
>>
>>> В Tue, 30 Jun 2015 15:05:46 -0300
>>> Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com> пишет:
>>>
>>>> On 2015-06-30 11:33, Vladimir 'phcoder' Serbinenko wrote:
>>>>> What about clang?
>>>>
>>>> Not good news about clang support. This is what the toolchain team said
>>>> about it:
>>>>
>>>> The -mbig-endian option was added around April 10th, 2014.
>>>> Unfortunately, those who implemented it only implemented it for ARM and
>>>> one other architecture.
>>>>
>>>> The option is currently accepted on Power systems, but does not have any
>>>> affect on the code generation for Power.
>>>>
> 
> Support for it looks rather trivial; see attached patch. Anyone has good
> connection to clang development community?
> 
Just send it to their ML. They usually have good response. If this patch
is accepted we can probably simplify it in our code
> Using this patch the
> 
> clang --target=powerpc64le -mbig-endian -m32 produces code for PPC32
> BE, so just works:
> 
> bor@opensuse:~/build/clang-ppc/bin> ./clang  --target=powerpc64le   -c -mbig-endian -m32 /tmp/foo.c
> /tmp/foo.c:1:1: warning: type specifier missing, defaults to 'int'
>       [-Wimplicit-int]
> foo()
> ^
> 1 warning generated.
> bor@opensuse:~/build/clang-ppc/bin> file foo.o
> foo.o: ELF 32-bit MSB relocatable, PowerPC or cisco 4500, version 1 (SYSV), not stripped
> 
> The problem is that in this case we do not really have any way to test
> if it works in configure, so no way to fail gracefully.
> 
Just check the defines.
>>>>
>>>> So, what can we do here? Maybe add a constrain in the configure file
>>>> saying that it's not possible to build GRUB in a LE environment using
>>> clang.
>>>
>>> If I understand it correctly, it is possible to build for big-endian
>>> PowerPC using
>>>
>>> clang -target=powerpc
>>>
>>> but then we depend on clang being built with BE target support; and
>>> e.g. openSUSE builds it with
>>>
> 
> Yes, that works too. But I'm not sure how we can test for it. Brute
> force would of course be
> 
> $TARGET_CC --version | grep clang && TARGET_CFLAGS=--target=powerpc
> 
> Comments? I'm inclined to use this workaround. This still may have
> issues when using external assembler, but here we can simply mandate
> support for clang 3.6 at the minimum, which should use integrated
> assembler on PPC by default.
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-07-05 17:38                 ` Andrei Borzenkov
@ 2015-07-15 17:42                   ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-07-16 18:55                     ` Andrei Borzenkov
  2015-07-22  3:23                     ` Andrei Borzenkov
  0 siblings, 2 replies; 23+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-07-15 17:42 UTC (permalink / raw)
  To: Andrei Borzenkov; +Cc: The development of GRUB 2, Paulo Flabiano Smorigo


[-- Attachment #1.1: Type: text/plain, Size: 699 bytes --]


> It is possible to compile using "--target=powerpc -Wl,-EB" - this works
> on all three ppc, ppc64 and ppc64le, but this means hardcoding GNU ld
> dependency.
> 
Thanks for this info.
See attached patch
> So I'd rather try to produce patch for proper support of
> -mbig-endian/-mlittle-endian (including passing it onto gcc linker) and
> until then declared clang on ppc64le having limited support (i.e.
> support for automatic detection by configure).
> 
I agree that this is a better approach in long term. But if we can get
some support for current tools with little work (see patch) and without
risks of breaking other tools I see no reason not to go for it in short term
> 


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: be2.diff --]
[-- Type: text/x-diff; name="be2.diff", Size: 2055 bytes --]

diff --git a/configure.ac b/configure.ac
index fd8a62e..113e7c7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -116,6 +116,7 @@ if test "x$with_platform" = x; then
     x86_64-*) platform=pc ;;
     powerpc-*) platform=ieee1275 ;;
     powerpc64-*) platform=ieee1275 ;;
+    powerpc64le-*) platform=ieee1275 ;;
     sparc64-*) platform=ieee1275 ;;
     mipsel-*) platform=loongson ;;
     mips-*) platform=arc ;;
@@ -138,6 +139,7 @@ case "$target_cpu"-"$platform" in
   x86_64-none) ;;
   x86_64-*) target_cpu=i386 ;;
   powerpc64-ieee1275) target_cpu=powerpc ;;
+  powerpc64le-ieee1275) target_cpu=powerpc ;;
 esac
 
 # Check if the platform is supported, make final adjustments.
@@ -601,6 +603,37 @@ if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
   TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
 fi
 
+if test x$target_cpu = xpowerpc; then
+  AC_CACHE_CHECK([for options to get big-endian compilation], grub_cv_target_cc_big_endian, [
+    grub_cv_target_cc_big_endian=no
+    for cand in "-target powerpc -Wl,-EB" "-target powerpc" \
+		"-mbig-endian"; do
+      if test x"$grub_cv_target_cc_big_endian" != xno ; then
+        break
+      fi
+      CFLAGS="$TARGET_CFLAGS $cand -Werror"
+      AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__ORDER_BIG_ENDIAN__ != __BYTE_ORDER__)
+#error still little endian
+#endif
+asm (".globl start; start:");
+void __main (void);
+void __main (void) {}
+int main (void);
+]], [[]])],
+		        [grub_cv_target_cc_big_endian="$cand"], [])
+    done
+  ])
+
+  if test x"$grub_cv_target_cc_big_endian" = xno ; then
+    AC_MSG_ERROR([could not force big-endian])
+  fi
+
+  TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_big_endian"
+  TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_target_cc_big_endian"
+  TARGET_LDFLAGS="$TARGET_LDFLAGS -static $grub_cv_target_cc_big_endian"
+fi
+
 if test "x$target_m32" = x1; then
   # Force 32-bit mode.
   TARGET_CFLAGS="$TARGET_CFLAGS -m32"

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-07-15 17:42                   ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2015-07-16 18:55                     ` Andrei Borzenkov
  2015-07-16 19:05                       ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-07-22  3:23                     ` Andrei Borzenkov
  1 sibling, 1 reply; 23+ messages in thread
From: Andrei Borzenkov @ 2015-07-16 18:55 UTC (permalink / raw)
  To: Vladimir 'φ-coder/phcoder' Serbinenko
  Cc: The development of GRUB 2, Paulo Flabiano Smorigo

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

В Wed, 15 Jul 2015 19:42:39 +0200
Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:

> 
> > It is possible to compile using "--target=powerpc -Wl,-EB" - this works
> > on all three ppc, ppc64 and ppc64le, but this means hardcoding GNU ld
> > dependency.
> > 
> Thanks for this info.
> See attached patch

Test has to come before asm tests (so that we are sure to compile
for the right target).

But real problem is that -Wl,-EB has to be added to TARGET_LDFLAGS only

 [  106s] configure:24950: clang -c -v -Wall -W -Wshadow
 -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value  -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations -Wcast-align  -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -target powerpc -Wl,-EB -m32 -msoft-float -Werror  -Wall -W  -DGRUB_MACHINE_IEEE1275=1 -DGRUB_MACHINE=POWERPC_IEEE1275 conftest.c >&5 [  106s] clang version 3.6.1 (tags/RELEASE_361/final 238133)
[  106s] Target: powerpc
[  106s] Thread model: posix
[  106s] clang-3.6: error: -Wl,-EB: 'linker' input unused


> > So I'd rather try to produce patch for proper support of
> > -mbig-endian/-mlittle-endian (including passing it onto gcc linker) and
> > until then declared clang on ppc64le having limited support (i.e.
> > support for automatic detection by configure).
> > 
> I agree that this is a better approach in long term. But if we can get
> some support for current tools with little work (see patch) and without
> risks of breaking other tools I see no reason not to go for it in short term
> > 
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-07-16 18:55                     ` Andrei Borzenkov
@ 2015-07-16 19:05                       ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-07-16 19:30                         ` Andrei Borzenkov
  0 siblings, 1 reply; 23+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-07-16 19:05 UTC (permalink / raw)
  To: Andrei Borzenkov; +Cc: The development of GRUB 2, Paulo Flabiano Smorigo


[-- Attachment #1.1: Type: text/plain, Size: 2477 bytes --]

On 16.07.2015 20:55, Andrei Borzenkov wrote:
> В Wed, 15 Jul 2015 19:42:39 +0200
> Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:
> 
>>
>>> It is possible to compile using "--target=powerpc -Wl,-EB" - this works
>>> on all three ppc, ppc64 and ppc64le, but this means hardcoding GNU ld
>>> dependency.
>>>
>> Thanks for this info.
>> See attached patch
> 
> Test has to come before asm tests (so that we are sure to compile
> for the right target).
> 
> But real problem is that -Wl,-EB has to be added to TARGET_LDFLAGS only
> 
Yes, discovered it already and updated the patch
>  [  106s] configure:24950: clang -c -v -Wall -W -Wshadow
>  -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value  -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations -Wcast-align  -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -target powerpc -Wl,-EB -m32 -msoft-float -W
error  -Wall -W  -DGRUB_MACHINE_IEEE1275=1 -DGRUB_MACHINE=POWERPC_IEEE1275 conftest.c >&5 [  106s] clang version 3.6.1 (tags/RELEASE_361/final 238133)
> [  106s] Target: powerpc
> [  106s] Thread model: posix
> [  106s] clang-3.6: error: -Wl,-EB: 'linker' input unused
> 
> 
>>> So I'd rather try to produce patch for proper support of
>>> -mbig-endian/-mlittle-endian (including passing it onto gcc linker) and
>>> until then declared clang on ppc64le having limited support (i.e.
>>> support for automatic detection by configure).
>>>
>> I agree that this is a better approach in long term. But if we can get
>> some support for current tools with little work (see patch) and without
>> risks of breaking other tools I see no reason not to go for it in short term
>>>
>>
> 


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: be.diff --]
[-- Type: text/x-diff; name="be.diff", Size: 2237 bytes --]

diff --git a/configure.ac b/configure.ac
index fd8a62e..e54b9df 100644
--- a/configure.ac
+++ b/configure.ac
@@ -116,6 +116,7 @@ if test "x$with_platform" = x; then
     x86_64-*) platform=pc ;;
     powerpc-*) platform=ieee1275 ;;
     powerpc64-*) platform=ieee1275 ;;
+    powerpc64le-*) platform=ieee1275 ;;
     sparc64-*) platform=ieee1275 ;;
     mipsel-*) platform=loongson ;;
     mips-*) platform=arc ;;
@@ -138,6 +139,7 @@ case "$target_cpu"-"$platform" in
   x86_64-none) ;;
   x86_64-*) target_cpu=i386 ;;
   powerpc64-ieee1275) target_cpu=powerpc ;;
+  powerpc64le-ieee1275) target_cpu=powerpc ;;
 esac
 
 # Check if the platform is supported, make final adjustments.
@@ -560,6 +562,41 @@ AC_COMPILE_IFELSE(
 ]])],
 [grub_cv_cc_target_clang=no], [grub_cv_cc_target_clang=yes])])
 
+if test x$target_cpu = xpowerpc; then
+  AC_CACHE_CHECK([for options to get big-endian compilation], grub_cv_target_cc_big_endian, [
+    grub_cv_target_cc_big_endian=no
+    for cand in "-target powerpc -Wl,-EB" "-target powerpc" \
+		"-target powerpc-linux-gnu -Wl,-EB" "-target powerpc-linux-gnu" \
+		"-mbig-endian"; do
+      if test x"$grub_cv_target_cc_big_endian" != xno ; then
+        break
+      fi
+      CFLAGS="$TARGET_CFLAGS $cand -Werror"
+      AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__ORDER_BIG_ENDIAN__ != __BYTE_ORDER__)
+#error still little endian
+#endif
+asm (".globl start; start:");
+void __main (void);
+void __main (void) {}
+int main (void);
+]], [[]])],
+		        [grub_cv_target_cc_big_endian="$cand"], [])
+    done
+  ])
+
+  if test x"$grub_cv_target_cc_big_endian" = xno ; then
+    AC_MSG_ERROR([could not force big-endian])
+  fi
+
+  skip_linkflags="$(echo "$grub_cv_target_cc_big_endian"|sed 's@-Wl,-EB@@')"
+
+  TARGET_CFLAGS="$TARGET_CFLAGS $skip_linkflags"
+  TARGET_CPPFLAGS="$TARGET_CPPFLAGS $skip_linkflags"
+  TARGET_CCASFLAGS="$TARGET_CCASFLAGS $skip_linkflags"
+  TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_big_endian"
+fi
+
 AC_CACHE_CHECK([for options to compile assembly], [grub_cv_cc_target_asm_compile], [
 test_program=
 case "x$target_cpu-$platform" in

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-07-16 19:05                       ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2015-07-16 19:30                         ` Andrei Borzenkov
  2015-07-20 13:01                           ` Paulo Flabiano Smorigo
  0 siblings, 1 reply; 23+ messages in thread
From: Andrei Borzenkov @ 2015-07-16 19:30 UTC (permalink / raw)
  To: Vladimir 'φ-coder/phcoder' Serbinenko
  Cc: The development of GRUB 2, Paulo Flabiano Smorigo

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

В Thu, 16 Jul 2015 21:05:07 +0200
Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:

> On 16.07.2015 20:55, Andrei Borzenkov wrote:
> > В Wed, 15 Jul 2015 19:42:39 +0200
> > Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:
> > 
> >>
> >>> It is possible to compile using "--target=powerpc -Wl,-EB" - this works
> >>> on all three ppc, ppc64 and ppc64le, but this means hardcoding GNU ld
> >>> dependency.
> >>>
> >> Thanks for this info.
> >> See attached patch
> > 
> > Test has to come before asm tests (so that we are sure to compile
> > for the right target).
> > 
> > But real problem is that -Wl,-EB has to be added to TARGET_LDFLAGS only
> > 
> Yes, discovered it already and updated the patch

Yes, this version builds OK both in native PPC environment as well as
cross-compiling.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-07-16 19:30                         ` Andrei Borzenkov
@ 2015-07-20 13:01                           ` Paulo Flabiano Smorigo
  0 siblings, 0 replies; 23+ messages in thread
From: Paulo Flabiano Smorigo @ 2015-07-20 13:01 UTC (permalink / raw)
  To: The development of GNU GRUB,
	Vladimir 'φ-coder/phcoder' Serbinenko

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

On 2015-07-16 16:30, Andrei Borzenkov wrote:
> В Thu, 16 Jul 2015 21:05:07 +0200
> Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:
>
>> On 16.07.2015 20:55, Andrei Borzenkov wrote:
>>> В Wed, 15 Jul 2015 19:42:39 +0200
>>> Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:
>>>
>>>>> It is possible to compile using "--target=powerpc -Wl,-EB" - this works
>>>>> on all three ppc, ppc64 and ppc64le, but this means hardcoding GNU ld
>>>>> dependency.
>>>>>
>>>> Thanks for this info.
>>>> See attached patch
>>> Test has to come before asm tests (so that we are sure to compile
>>> for the right target).
>>>
>>> But real problem is that -Wl,-EB has to be added to TARGET_LDFLAGS only
>>>
>> Yes, discovered it already and updated the patch
> Yes, this version builds OK both in native PPC environment as well as
> cross-compiling.
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel

Here works too. Both native and cross-compiled.

-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center


[-- Attachment #2: Type: text/html, Size: 2349 bytes --]

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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-07-15 17:42                   ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-07-16 18:55                     ` Andrei Borzenkov
@ 2015-07-22  3:23                     ` Andrei Borzenkov
  2015-07-22 17:00                       ` Paulo Flabiano Smorigo
  1 sibling, 1 reply; 23+ messages in thread
From: Andrei Borzenkov @ 2015-07-22  3:23 UTC (permalink / raw)
  To: Vladimir 'φ-coder/phcoder' Serbinenko
  Cc: The development of GRUB 2, Paulo Flabiano Smorigo

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

В Wed, 15 Jul 2015 19:42:39 +0200
Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:

> 
> > It is possible to compile using "--target=powerpc -Wl,-EB" - this works
> > on all three ppc, ppc64 and ppc64le, but this means hardcoding GNU ld
> > dependency.
> > 
> Thanks for this info.
> See attached patch

I do not think it was right to commit this patch without bi-endian ELF
support; this makes GRUB compile of ppc64le but it still cannot load
kernel.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

* Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags
  2015-07-22  3:23                     ` Andrei Borzenkov
@ 2015-07-22 17:00                       ` Paulo Flabiano Smorigo
  0 siblings, 0 replies; 23+ messages in thread
From: Paulo Flabiano Smorigo @ 2015-07-22 17:00 UTC (permalink / raw)
  To: The development of GNU GRUB,
	Vladimir 'φ-coder/phcoder' Serbinenko

On 2015-07-22 00:23, Andrei Borzenkov wrote:
> В Wed, 15 Jul 2015 19:42:39 +0200
> Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:
>
>>
>>> It is possible to compile using "--target=powerpc -Wl,-EB" - this works
>>> on all three ppc, ppc64 and ppc64le, but this means hardcoding GNU ld
>>> dependency.
>>>
>> Thanks for this info.
>> See attached patch
>
> I do not think it was right to commit this patch without bi-endian ELF
> support; this makes GRUB compile of ppc64le but it still cannot load
> kernel.

Yes, you are right. Let me finish the changes on the second patch so we 
can commit both.

>
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>


-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center



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

end of thread, other threads:[~2015-07-22 17:01 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-30 12:56 [PATCH 0/2] Add remaining parts for ppc64le environment Paulo Flabiano Smorigo
2015-06-30 12:56 ` [PATCH 1/2] Add powerpc little-endian (ppc64le) flags Paulo Flabiano Smorigo
2015-06-30 14:03   ` Vladimir 'phcoder' Serbinenko
2015-06-30 14:29     ` Andrei Borzenkov
2015-06-30 14:33       ` Vladimir 'phcoder' Serbinenko
2015-06-30 18:05         ` Paulo Flabiano Smorigo
2015-06-30 18:28           ` Andrei Borzenkov
2015-06-30 19:34             ` Vladimir 'phcoder' Serbinenko
2015-07-04  6:46               ` Andrei Borzenkov
2015-07-05 17:38                 ` Andrei Borzenkov
2015-07-15 17:42                   ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-07-16 18:55                     ` Andrei Borzenkov
2015-07-16 19:05                       ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-07-16 19:30                         ` Andrei Borzenkov
2015-07-20 13:01                           ` Paulo Flabiano Smorigo
2015-07-22  3:23                     ` Andrei Borzenkov
2015-07-22 17:00                       ` Paulo Flabiano Smorigo
2015-07-15 17:36                 ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-07-15 16:46             ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-06-30 14:33       ` Paulo Flabiano Smorigo
2015-06-30 12:56 ` [PATCH 2/2] Suport for bi-endianess in elf file Paulo Flabiano Smorigo
2015-06-30 15:03   ` Andrei Borzenkov
2015-06-30 18:06     ` Paulo Flabiano Smorigo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.