PR 26198 Failure to merge read only data of machine code object file and LTO object file on MinGW

Message ID CAEZ8vh=WSi+3wR2EfEheoCYW7hQCTMah9gS6ytS9dbxnirA3DA@mail.gmail.com
State New
Headers show
Series
  • PR 26198 Failure to merge read only data of machine code object file and LTO object file on MinGW
Related show

Commit Message

Alan Modra via Binutils July 9, 2020, 9:08 p.m.
Given an object file with a symbol declared in a section with a
".linkonce" directive and

a plugin object file with the same symbol in a
.gnu.linkonce.*.<symbol> section don't

fail with a multiple reference error when the plugin object file
appears after the

native object file.

Comments

Alan Modra via Binutils July 13, 2020, 12:48 a.m. | #1
On Thu, Jul 09, 2020 at 11:08:51PM +0200, Markus Böck via Binutils wrote:
> --- a/bfd/coffgen.c

> +++ b/bfd/coffgen.c

> @@ -2662,7 +2662,8 @@ _bfd_coff_section_already_linked (bfd *abfd,

>     .gnu.linkonce.*.<key>.  */

>        if (((s_comdat != NULL) == (l_comdat != NULL)

>       && strcmp (name, l->sec->name) == 0)

> -    || (l->sec->owner->flags & BFD_PLUGIN) != 0)

> +    || (l->sec->owner->flags & BFD_PLUGIN) != 0

> +          || (sec->owner->flags & BFD_PLUGIN) != 0)

>    {

>      /* The section has already been linked.  See if we should

>         issue a warning.  */


The patch makes sense to me.  Have you tested it with a mingw gcc
build, lto enabled of course, confirming no gcc testsuite regressions?

-- 
Alan Modra
Australia Development Lab, IBM
Alan Modra via Binutils July 14, 2020, 11:12 a.m. | #2
Tested with and without the patch against the entirety of the g++ and gcc
testsuite using the mingw target and lto enable and observed no changes in
test results.

On Mon, Jul 13, 2020 at 2:48 AM Alan Modra <amodra@gmail.com> wrote:

> On Thu, Jul 09, 2020 at 11:08:51PM +0200, Markus Böck via Binutils wrote:

> > --- a/bfd/coffgen.c

> > +++ b/bfd/coffgen.c

> > @@ -2662,7 +2662,8 @@ _bfd_coff_section_already_linked (bfd *abfd,

> >     .gnu.linkonce.*.<key>.  */

> >        if (((s_comdat != NULL) == (l_comdat != NULL)

> >       && strcmp (name, l->sec->name) == 0)

> > -    || (l->sec->owner->flags & BFD_PLUGIN) != 0)

> > +    || (l->sec->owner->flags & BFD_PLUGIN) != 0

> > +          || (sec->owner->flags & BFD_PLUGIN) != 0)

> >    {

> >      /* The section has already been linked.  See if we should

> >         issue a warning.  */

>

> The patch makes sense to me.  Have you tested it with a mingw gcc

> build, lto enabled of course, confirming no gcc testsuite regressions?

>

> --

> Alan Modra

> Australia Development Lab, IBM

>
Alan Modra via Binutils July 14, 2020, 11:03 p.m. | #3
On Tue, Jul 14, 2020 at 01:12:58PM +0200, Markus Böck wrote:
> Tested with and without the patch against the entirety of the g++ and gcc

> testsuite using the mingw target and lto enable and observed no changes in

> test results.


Thanks.  I've also run a full gcc bootstrap and regression test on
x86_64-linux for the corresponding change to
_bfd_elf_section_already_linked.

Committed.

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 3cb4881feb..813e3f219b 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,11 @@
+2020-07-15  Markus Böck  <markus.boeck02@gmail.com>
+	    Alan Modra  <amodra@gmail.com>
+
+	PR 26198
+	* coffgen.c (_bfd_coff_section_already_linked): Allow for plugin
+	objects both before and after normal object files.
+	* elflink.c (_bfd_elf_section_already_linked): Likewise.
+
 2020-07-10  Alan Modra  <amodra@gmail.com>
 
 	* elf64-ppc.h (struct ppc64_elf_params): Add power10_stubs.
diff --git a/bfd/coffgen.c b/bfd/coffgen.c
index 3291b693eb..d49b2ff201 100644
--- a/bfd/coffgen.c
+++ b/bfd/coffgen.c
@@ -2662,7 +2662,8 @@ _bfd_coff_section_already_linked (bfd *abfd,
 	 .gnu.linkonce.*.<key>.  */
       if (((s_comdat != NULL) == (l_comdat != NULL)
 	   && strcmp (name, l->sec->name) == 0)
-	  || (l->sec->owner->flags & BFD_PLUGIN) != 0)
+	  || (l->sec->owner->flags & BFD_PLUGIN) != 0
+	  || (sec->owner->flags & BFD_PLUGIN) != 0)
 	{
 	  /* The section has already been linked.  See if we should
 	     issue a warning.  */
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 998b72f228..6978df56db 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -14534,7 +14534,8 @@ _bfd_elf_section_already_linked (bfd *abfd,
       if (((flags & SEC_GROUP) == (l->sec->flags & SEC_GROUP)
 	   && ((flags & SEC_GROUP) != 0
 	       || strcmp (name, l->sec->name) == 0))
-	  || (l->sec->owner->flags & BFD_PLUGIN) != 0)
+	  || (l->sec->owner->flags & BFD_PLUGIN) != 0
+	  || (sec->owner->flags & BFD_PLUGIN) != 0)
 	{
 	  /* The section has already been linked.  See if we should
 	     issue a warning.  */

-- 
Alan Modra
Australia Development Lab, IBM

Patch

diff --git a/bfd/coffgen.c b/bfd/coffgen.c
index 3291b693eb..f2360aad31 100644
--- a/bfd/coffgen.c
+++ b/bfd/coffgen.c
@@ -2662,7 +2662,8 @@  _bfd_coff_section_already_linked (bfd *abfd,
    .gnu.linkonce.*.<key>.  */
       if (((s_comdat != NULL) == (l_comdat != NULL)
      && strcmp (name, l->sec->name) == 0)
-    || (l->sec->owner->flags & BFD_PLUGIN) != 0)
+    || (l->sec->owner->flags & BFD_PLUGIN) != 0
+          || (sec->owner->flags & BFD_PLUGIN) != 0)
   {
     /* The section has already been linked.  See if we should
        issue a warning.  */
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 9bb68e6991..9e9c9d145b 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,8 @@ 
+2020-07-09  Markus Böck  <markus.boeck02@gmail.com>
+
+  * coffgen.c (_bfd_coff_section_already_linked): Allow
+    .gnu.linkonce section to come after an already linked object.
+
 2020-07-09  Alan Modra  <amodra@gmail.com>

   * dlltool.c: Remove powerpc PE support and comments.