Bug 92216 - GDC generate duplicate symbols when mixins and interfaces are used to gather
Summary: GDC generate duplicate symbols when mixins and interfaces are used to gather
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: d (show other bugs)
Version: 9.2.0
: P3 normal
Target Milestone: ---
Assignee: Iain Buclaw
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-24 20:57 UTC by Daniel Kozak
Modified: 2020-05-18 13:19 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-03-16 00:00:00


Attachments
Zip archive with b.d and c.d files (367 bytes, application/zip)
2019-10-24 20:57 UTC, Daniel Kozak
Details
Make thunk weak linking (305 bytes, patch)
2019-10-25 11:30 UTC, Daniel Kozak
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Kozak 2019-10-24 20:57:03 UTC
Created attachment 47109 [details]
Zip archive with b.d and c.d files

There seems to be an issue with generating object symbols for mixins. In some cases gdc generate same symbols (not weak) in object files so there is a collision when linking.

Trying to build gtkd package is one of examples. I have write small example to mitigate this issue. It is add as an attachment.

$ gdc -c -o b.o b.d
$ gdc -c -o c.o c.d
$ gdc -o test.o b.o c.o

ld: c.o: in function `_DT16_D1b1B8__mixin24getSMFZPv':
c.d:(.text+0x27): multiple definition of `_DT16_D1b1B8__mixin24getSMFZPv'; b.o:b.d:(.text+0x38): first defined here

I have try this with gcc 9.2 (gdc (GCC) 9.2.0)

And with git gcc(gdc) 10 (from august)

same issue for both versions
Comment 1 Daniel Kozak 2019-10-25 11:30:47 UTC
Created attachment 47112 [details]
Make thunk weak linking
Comment 2 ibuclaw 2020-03-16 16:35:43 UTC
Hi Daniel,

Thanks for the patch, however instead I've gone with just marking the thunks as non-public.  This is because the body generated for such thunks is different from the case where the thunk and target function are in the same compilation unit.
Comment 3 CVS Commits 2020-03-16 22:06:01 UTC
The master branch has been updated by Iain Buclaw <ibuclaw@gcc.gnu.org>:

https://gcc.gnu.org/g:447d196e75d97a9ac7c6a548dc9d0fe367adf6be

commit r10-7199-g447d196e75d97a9ac7c6a548dc9d0fe367adf6be
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Mon Mar 16 23:04:49 2020 +0100

    d: Fix multiple definition error when using mixins and interfaces.
    
    gcc/d/ChangeLog:
    
            PR d/92216
            * decl.cc (make_thunk): Don't set TREE_PUBLIC on thunks if the target
            function is external to the current compilation.
    
    gcc/testsuite/ChangeLog:
    
            PR d/92216
            * gdc.dg/imports/pr92216.d: New.
            * gdc.dg/pr92216.d: New test.
Comment 4 ibuclaw 2020-03-16 22:28:28 UTC
Fix committed.
Comment 5 Rasmus Thomsen 2020-05-18 09:07:47 UTC
*** Bug 95184 has been marked as a duplicate of this bug. ***
Comment 6 CVS Commits 2020-05-18 13:19:53 UTC
The releases/gcc-9 branch has been updated by Iain Buclaw <ibuclaw@gcc.gnu.org>:

https://gcc.gnu.org/g:3e84ee0fab9cedfa57fe86ea3c00608f6a873ab9

commit r9-8603-g3e84ee0fab9cedfa57fe86ea3c00608f6a873ab9
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Mon Mar 16 23:04:49 2020 +0100

    d: Fix multiple definition error when using mixins and interfaces.
    
    gcc/d/ChangeLog:
    
            PR d/92216
            * decl.cc (make_thunk): Don't set TREE_PUBLIC on thunks if the target
            function is external to the current compilation.
    
    gcc/testsuite/ChangeLog:
    
            PR d/92216
            * gdc.dg/imports/pr92216.d: New.
            * gdc.dg/pr92216.d: New test.