[PATCH] ia64: don't fail when converting binary into ELF

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] ia64: don't fail when converting binary into ELF

Sergei Trofimovich-2
From: Sergei Trofimovich <[hidden email]>

In ld/PR25316 ia64 is a rare target that fails the following test:
  $ echo hi > hello.123
  $ ia64-unknown-linux-gnu-ld -r -b binary hello.123 -o hello.o
  ia64-unknown-linux-gnu-ld: failed to merge target specific data of file hello.123

There is no need to support binary merging explicitly (as other targets).

bfd/ChangeLog
2019-12-26  Sergei Trofimovich <[hidden email]>

        * elfnn-ia64.c (elfNN_ia64_merge_private_bfd_data): don't fail
        on binary inputs ld/PR25316.
---
 bfd/ChangeLog    | 5 +++++
 bfd/elfnn-ia64.c | 3 +--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 073bbb6f2b..5448af5305 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2019-12-26  Sergei Trofimovich <[hidden email]>
+
+ * elfnn-ia64.c (elfNN_ia64_merge_private_bfd_data): don't fail
+ on binary inputs ld/PR25316.
+
 2019-12-23  Alan Modra  <[hidden email]>
 
  * vms-alpha.c (add_symbol): Add "max" parameter.  Error on string
diff --git a/bfd/elfnn-ia64.c b/bfd/elfnn-ia64.c
index 459d986c03..338fd5ff93 100644
--- a/bfd/elfnn-ia64.c
+++ b/bfd/elfnn-ia64.c
@@ -4740,10 +4740,9 @@ elfNN_ia64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   flagword in_flags;
   bfd_boolean ok = TRUE;
 
-  /* Don't even pretend to support mixed-format linking.  */
   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
-    return FALSE;
+    return TRUE;
 
   in_flags  = elf_elfheader (ibfd)->e_flags;
   out_flags = elf_elfheader (obfd)->e_flags;
--
2.24.1

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] ia64: don't fail when converting binary into ELF

Alan Modra-3
On Thu, Dec 26, 2019 at 10:40:30AM +0000, Sergei Trofimovich wrote:

> diff --git a/bfd/elfnn-ia64.c b/bfd/elfnn-ia64.c
> index 459d986c03..338fd5ff93 100644
> --- a/bfd/elfnn-ia64.c
> +++ b/bfd/elfnn-ia64.c
> @@ -4740,10 +4740,9 @@ elfNN_ia64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
>    flagword in_flags;
>    bfd_boolean ok = TRUE;
>  
> -  /* Don't even pretend to support mixed-format linking.  */
>    if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
>        || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
> -    return FALSE;
> +    return TRUE;
>  
>    in_flags  = elf_elfheader (ibfd)->e_flags;
>    out_flags = elf_elfheader (obfd)->e_flags;

This is OK as far as it goes, but there is another bug here too.  The
function should only be looking at e_flags for objects known to be
ia64.  See for example elf64-ppc.c ppc64_elf_merge_private_bfd_data
where the test is

  if (!is_ppc64_elf (ibfd) || !is_ppc64_elf (obfd))
    return TRUE;

with
#define is_ppc64_elf(bfd) \
  (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
   && elf_object_id (bfd) == PPC64_ELF_DATA)

Something similar should be done for IA64.

--
Alan Modra
Australia Development Lab, IBM
Reply | Threaded
Open this post in threaded view
|

[PATCH v2] ia64: don't fail when converting binary into ELF

Sergei Trofimovich-2
From: Sergei Trofimovich <[hidden email]>

In ld/PR25316 ia64 is a rare target that fails the following test:
  $ echo hi > hello.123
  $ ia64-unknown-linux-gnu-ld -r -b binary hello.123 -o hello.o
  ia64-unknown-linux-gnu-ld: failed to merge target specific data of file hello.123

There is no need to support binary merging explicitly (as other targets).

bfd/ChangeLog
2019-12-26  Sergei Trofimovich <[hidden email]>

        * elfnn-ia64.c (elfNN_ia64_merge_private_bfd_data): don't fail
        on binary inputs ld/PR25316.
        (is_ia64_elf): new helper to filter on ia64 objects.
---
 bfd/ChangeLog    |  6 ++++++
 bfd/elfnn-ia64.c | 10 ++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 073bbb6f2b..cfbd841f79 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2019-12-27  Sergei Trofimovich <[hidden email]>
+
+ * elfnn-ia64.c (elfNN_ia64_merge_private_bfd_data): don't fail
+ on binary inputs ld/PR25316.
+ (is_ia64_elf): new helper to filter on ia64 objects.
+
 2019-12-23  Alan Modra  <[hidden email]>
 
  * vms-alpha.c (add_symbol): Add "max" parameter.  Error on string
diff --git a/bfd/elfnn-ia64.c b/bfd/elfnn-ia64.c
index 459d986c03..f63c431528 100644
--- a/bfd/elfnn-ia64.c
+++ b/bfd/elfnn-ia64.c
@@ -39,6 +39,10 @@
 #define LOG_SECTION_ALIGN 2
 #endif
 
+#define is_ia64_elf(bfd) \
+  (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
+   && elf_object_id (bfd) == IA64_ELF_DATA)
+
 typedef struct bfd_hash_entry *(*new_hash_entry_func)
   (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
 
@@ -4740,10 +4744,8 @@ elfNN_ia64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   flagword in_flags;
   bfd_boolean ok = TRUE;
 
-  /* Don't even pretend to support mixed-format linking.  */
-  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
-      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
-    return FALSE;
+  if (!is_ia64_elf (ibfd) || !is_ia64_elf (obfd))
+    return TRUE;
 
   in_flags  = elf_elfheader (ibfd)->e_flags;
   out_flags = elf_elfheader (obfd)->e_flags;
--
2.24.1

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v2] ia64: don't fail when converting binary into ELF

Alan Modra-3
On Fri, Dec 27, 2019 at 10:15:05AM +0000, Sergei Trofimovich wrote:

> From: Sergei Trofimovich <[hidden email]>
>
> In ld/PR25316 ia64 is a rare target that fails the following test:
>   $ echo hi > hello.123
>   $ ia64-unknown-linux-gnu-ld -r -b binary hello.123 -o hello.o
>   ia64-unknown-linux-gnu-ld: failed to merge target specific data of file hello.123
>
> There is no need to support binary merging explicitly (as other targets).
>
> bfd/ChangeLog
> 2019-12-26  Sergei Trofimovich <[hidden email]>
>
>         * elfnn-ia64.c (elfNN_ia64_merge_private_bfd_data): don't fail
>         on binary inputs ld/PR25316.
>         (is_ia64_elf): new helper to filter on ia64 objects.

OK.

--
Alan Modra
Australia Development Lab, IBM
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v2] ia64: don't fail when converting binary into ELF

Sergei Trofimovich-2
On Mon, 30 Dec 2019 09:39:38 +1030
Alan Modra <[hidden email]> wrote:

> On Fri, Dec 27, 2019 at 10:15:05AM +0000, Sergei Trofimovich wrote:
> > From: Sergei Trofimovich <[hidden email]>
> >
> > In ld/PR25316 ia64 is a rare target that fails the following test:
> >   $ echo hi > hello.123
> >   $ ia64-unknown-linux-gnu-ld -r -b binary hello.123 -o hello.o
> >   ia64-unknown-linux-gnu-ld: failed to merge target specific data of file hello.123
> >
> > There is no need to support binary merging explicitly (as other targets).
> >
> > bfd/ChangeLog
> > 2019-12-26  Sergei Trofimovich <[hidden email]>
> >
> >         * elfnn-ia64.c (elfNN_ia64_merge_private_bfd_data): don't fail
> >         on binary inputs ld/PR25316.
> >         (is_ia64_elf): new helper to filter on ia64 objects.  
>
> OK.

Thank you!

I'll need someone to push the change to main tree as I have no commit access.

--

  Sergei
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v2] ia64: don't fail when converting binary into ELF

Nick Clifton
Hi Sergei,

>>> bfd/ChangeLog
>>> 2019-12-26  Sergei Trofimovich <[hidden email]>
>>>
>>>         * elfnn-ia64.c (elfNN_ia64_merge_private_bfd_data): don't fail
>>>         on binary inputs ld/PR25316.
>>>         (is_ia64_elf): new helper to filter on ia64 objects.  

> I'll need someone to push the change to main tree as I have no commit access.

Pushed.

Cheers
  Nick