July 31, 2015
https://issues.dlang.org/show_bug.cgi?id=14828

--- Comment #11 from Kenji Hara <k.hara.pg@gmail.com> ---
(In reply to Timothee Cour from comment #9)
> duplicate symbol _D4foo212__ModuleInfoZ in:
>     out.o
>     libproj6.a(foo2.o)
> ld: 1 duplicate symbol for architecture x86_64
> clang: error: linker command failed with exit code 1 (use -v to see
> invocation)

The duplicated symbol name is same with in win32.

--
July 31, 2015
https://issues.dlang.org/show_bug.cgi?id=14828

Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Attachment #1534|0                           |1
        is obsolete|                            |

--- Comment #12 from Kenji Hara <k.hara.pg@gmail.com> ---
Created attachment 1538
  --> https://issues.dlang.org/attachment.cgi?id=1538&action=edit
A little updated test case

OK, I understand the issue mechanism. It's obvious from the list files of libproj.lib and out.obj. (`make genlist`)

With the `make a1f` command, the last link for out.exe will pull foo2.obj in the lib file, because:

The instantiated function _D5stdio12__T7writelnZ7writelnFNaNbNiNfAyaZv uses _D5stdio7__arrayZ for array bounds check, but it's stored in foo2.obj in the lib.

By that, the symbol _D4foo212__ModuleInfoZ in lib will also linked because it's in foo2.obj.

On the other hand, out.obj also contains _D4foo212__ModuleInfoZ, then they conflicts each other.

----

The essential fix I think is: when the lib file is compiled, the helper
functions
(__array, etc) of non-root modules (e.g. stdio) should be separated their own
obj file.

--
July 31, 2015
https://issues.dlang.org/show_bug.cgi?id=14828

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #13 from Walter Bright <bugzilla@digitalmars.com> ---
The module info symbol should only be generated by compiling foo2 from the command line. Why is it generated into out.obj?

--
July 31, 2015
https://issues.dlang.org/show_bug.cgi?id=14828

--- Comment #14 from Kenji Hara <k.hara.pg@gmail.com> ---
(In reply to Walter Bright from comment #13)
> The module info symbol should only be generated by compiling foo2 from the command line. Why is it generated into out.obj?

foo2.d is compiled twice. One generated obj is stored into the lib file, one another is stored into out.obj.

This is the issue case from the original case.

all1_order_flipped:
    ${dmd} -oflibproj6.a -lib -g project2.d foo2.d foo1.d
    ${dmd} -ofout -g libproj6.a foo2.d main.d

--
July 31, 2015
https://issues.dlang.org/show_bug.cgi?id=14828

Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |link-failure, pull
           Hardware|x86                         |All
            Summary|duplicate symbol            |[REG2.067] duplicate symbol
                   |__ModuleInfoZ depending on  |__ModuleInfoZ depending on
                   |ordering of files passed to |ordering of files passed to
                   |dmd                         |dmd
                 OS|Mac OS X                    |All

--- Comment #15 from Kenji Hara <k.hara.pg@gmail.com> ---
(In reply to Kenji Hara from comment #12)
> The essential fix I think is: when the lib file is compiled, the helper
> functions
> (__array, etc) of non-root modules (e.g. stdio) should be separated their
> own obj file.

Implemented.

https://github.com/D-Programming-Language/dmd/pull/4851

--
August 04, 2015
https://issues.dlang.org/show_bug.cgi?id=14828

--- Comment #16 from Walter Bright <bugzilla@digitalmars.com> ---
Different fix:

https://github.com/D-Programming-Language/dmd/pull/4859

--
August 04, 2015
https://issues.dlang.org/show_bug.cgi?id=14828

--- Comment #17 from github-bugzilla@puremagic.com ---
Commits pushed to stable at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/679275df8615740fcc1b1f8efb064ef0174e9d6d fix Issue 14828 - duplicate symbol __ModuleInfoZ

- always emit __arrayZ/__assertZ/__unittest_failZ helpers (even in release)
  to avoid linkage issues when instantiating a template of that module
  with different compiler flags

- also fixes Issue 14748 - Removing std.stdio import causes 2x increase in
"Hello, world"
  same underlying issue, some undefined helper function drag in a different
  module which happens to have weak definitions of those helpers

https://github.com/D-Programming-Language/dmd/commit/2e15e16658a0416003e9fcf9ed7dfcd45e0da844 Merge pull request #4858 from MartinNowak/fix14828

fix Issue 14828 - duplicate symbol __ModuleInfoZ

--
August 04, 2015
https://issues.dlang.org/show_bug.cgi?id=14828

--- Comment #18 from Walter Bright <bugzilla@digitalmars.com> ---
The fix that was actually pulled: https://github.com/D-Programming-Language/dmd/pull/4858

--
August 04, 2015
https://issues.dlang.org/show_bug.cgi?id=14828

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=846

--
August 05, 2015
https://issues.dlang.org/show_bug.cgi?id=14828

--- Comment #19 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/679275df8615740fcc1b1f8efb064ef0174e9d6d fix Issue 14828 - duplicate symbol __ModuleInfoZ

https://github.com/D-Programming-Language/dmd/commit/2e15e16658a0416003e9fcf9ed7dfcd45e0da844 Merge pull request #4858 from MartinNowak/fix14828

--