[PATCH] Fix -flto on mingw (PR ld/18199)

Kwok Cheung Yeung kcy@codesourcery.com
Thu Dec 10 22:40:00 GMT 2015


I have committed this patch on the main branch. Is this OK to commit this to 
binutils-2_26-branch too, as this bug was a regression introduced in 
binutils-2.25.1?

Kwok Cheung Yeung

On 10/12/2015 2:58 PM, H.J. Lu wrote:
> On Thu, Dec 10, 2015 at 5:45 AM, Kwok Cheung Yeung <kcy@codesourcery.com> wrote:
>> On 10/12/2015 3:47 AM, H.J. Lu wrote:
>>>
>>>
>>> How about this patch instead?
>>>
>>
>> I agree it is probably better to do it during the bfd_create (as the
>> implementation might change at a later date), though calling
>> bfd_plugin_target_p twice in the function is a bit inelegant.
>
> You can cache it.
>
>> I will get this committed later today, thanks!
>>
>> Kwok Cheung Yeung
>
>
>
-------------- next part --------------
From 4a07dc81356ed8728e204e9aabeb256703c59aef Mon Sep 17 00:00:00 2001
From: Kwok Cheung Yeung <kcy@codesourcery.com>
Date: Thu, 10 Dec 2015 16:11:07 +0000
Subject: [PATCH] ld: Fix LTO for MinGW targets

When creating a dummy BFD for an IR file, the output BFD is used as
a template for the new BFD, when it needs to be the input BFD passed
into the function when not dealing with a BFD plugin.

On most targets this is not an issue as the input and output formats
are the same anyway, but on MinGW targets, there are two variant
formats used (pe-i386/pe-x86-64 and pei-i386/pei-x86-64) which are
similar but not interchangeable here.

	PR ld/18199
	* plugin.c (plugin_get_ir_dummy_bfd): Use srctemplate as the
	template when calling bfd_create if it does not use the BFD
	plugin target vector.
---
 ld/ChangeLog | 7 +++++++
 ld/plugin.c  | 6 ++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/ld/ChangeLog b/ld/ChangeLog
index 0f622d0..576e3dc 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,10 @@
+2015-12-10  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+	PR ld/18199
+	* plugin.c (plugin_get_ir_dummy_bfd): Use srctemplate as the
+	template when calling bfd_create if it does not use the BFD
+	plugin target vector.
+
 2015-12-02  Alan Modra  <amodra@gmail.com>
 
 	* configure.ac (--enable-initfini-array): Remove run test.  Default
diff --git a/ld/plugin.c b/ld/plugin.c
index 8e53255..b0e2a5f 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -295,16 +295,18 @@ static bfd *
 plugin_get_ir_dummy_bfd (const char *name, bfd *srctemplate)
 {
   bfd *abfd;
+  bfd_boolean bfd_plugin_target;
 
   bfd_use_reserved_id = 1;
+  bfd_plugin_target = bfd_plugin_target_p (srctemplate->xvec);
   abfd = bfd_create (concat (name, IRONLY_SUFFIX, (const char *) NULL),
-		     link_info.output_bfd);
+		     bfd_plugin_target ? link_info.output_bfd : srctemplate);
   if (abfd != NULL)
     {
       abfd->flags |= BFD_LINKER_CREATED | BFD_PLUGIN;
       if (!bfd_make_writable (abfd))
 	goto report_error;
-      if (! bfd_plugin_target_p (srctemplate->xvec))
+      if (!bfd_plugin_target)
 	{
 	  bfd_set_arch_info (abfd, bfd_get_arch_info (srctemplate));
 	  bfd_set_gp_size (abfd, bfd_get_gp_size (srctemplate));
-- 
2.6.3



More information about the Binutils mailing list