Thread overview
[Issue 24129] ImportC: cannot compile any non-trivial program with multiple translation units/files: fatal error LNK1179: invalid or corrupt file: duplicate COMDAT '__acrt_locale_get_ctype_array_value'
Sep 06, 2023
Walter Bright
Sep 06, 2023
Jeffrey H. Johnson
Sep 06, 2023
Jeffrey H. Johnson
Sep 07, 2023
Walter Bright
[Issue 24129] ImportC: MS-Link cannot handle multiple COMDATs with the same name
Sep 08, 2023
Walter Bright
Sep 08, 2023
Dlang Bot
Sep 20, 2023
Dlang Bot
September 06, 2023
https://issues.dlang.org/show_bug.cgi?id=24129

Walter Bright <bugzilla@digitalmars.com> changed:

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

--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> ---
The problem stems from when a.c and b.c are compiled together, as in:

    dmd a.c b.c

The code from both gets placed in one object file, a.obj. Hence there are two copies of __acrt_local_get_ctype_array value, and they conflict with each other.

The workaround is to compile them separately.

The same result is exhibited with this simple test case:

--- a.c ---
inline int test() { return 73; }

void *def() { return &test; }

int main() { return 0; }
----- b.c -------
inline int test() { return 73; }

void *def() { return &test; }
---------------

dmd a.c b.c
a.obj : fatal error LNK1179: invalid or corrupt file: duplicate COMDAT 'test'
Error: linker exited with status 1179

--
September 06, 2023
https://issues.dlang.org/show_bug.cgi?id=24129

--- Comment #2 from Jeffrey H. Johnson <trnsz@pobox.com> ---
(In reply to Walter Bright from comment #1)
> The problem stems from when a.c and b.c are compiled together, as in:
> 
>     dmd a.c b.c
> 
> The code from both gets placed in one object file, a.obj. Hence there are two copies of __acrt_local_get_ctype_array value, and they conflict with each other.
> 
> The workaround is to compile them separately.

Thanks Walter!  Do you think this might be something that can be worked around?

The reason is performance, for example, on Linux:

$ for i in *.c; do dmd -m64 -fPIC -fPIE -O -release -check=off -boundscheck=off
"${i}" -c -of=objout/${i}.o; done
$ dmd -m64 -fPIC -fPIE -O -release -check=off -boundscheck=off objout/*.o
-of=test1
$ strip test1
$ ls -la test1
885 KB Wed Sep  6 19:29:54 2023 test1*

$ rm -rf objout/*
$ dmd -m64 -fPIC -fPIE -O -release -check=off -boundscheck=off *.c -of=test2
$ strip test2
$ ls -la test2
838 KB Wed Sep  6 19:30:27 2023 test2*

It's quite close, but I can show (with statistical confidence) that the test2 build is a bit faster than test1 (in addition to being smaller and easier to compile).  I assume that this is due to some linker optimizations?  Does the compiler optimize better, almsot a "poor mans LTO" and treating it as a single translation unit, perhaps?


I believe that using -inline (when it works, I made bug #24131 for that) also results in faster binaries when they are all built together, rather than separately.

However, as a workaround, this seems acceptable for now, thank you so much. And I assume this is still a bug, so I'll leave this open for now.

--
September 06, 2023
https://issues.dlang.org/show_bug.cgi?id=24129

Jeffrey H. Johnson <trnsz@pobox.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |trnsz@pobox.com

--
September 07, 2023
https://issues.dlang.org/show_bug.cgi?id=24129

--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> ---
It's an important problem to fix. It's a problem only seen with the Microsoft linker - the other linkers automatically remove duplicates, even if they are in the same file. So I'd call it a workaround for an unusual behavior in the Microsoft linker :-)

But I can't fix MS-LINK, so I'll just have to remove the duplicates in dmd.

--
September 08, 2023
https://issues.dlang.org/show_bug.cgi?id=24129

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|ImportC: cannot compile any |ImportC: MS-Link cannot
                   |non-trivial program with    |handle multiple COMDATs
                   |multiple translation        |with the same name
                   |units/files: fatal error    |
                   |LNK1179: invalid or corrupt |
                   |file: duplicate COMDAT      |
                   |'__acrt_locale_get_ctype_ar |
                   |ray_value'                  |

--
September 08, 2023
https://issues.dlang.org/show_bug.cgi?id=24129

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
@WalterBright created dlang/dmd pull request #15585 "fix Issue 24129 - ImportC: MS-Link cannot handle multiple COMDATs wit…" fixing this issue:

- fix Issue 24129 - ImportC: MS-Link cannot handle multiple COMDATs with the same name

https://github.com/dlang/dmd/pull/15585

--
September 20, 2023
https://issues.dlang.org/show_bug.cgi?id=24129

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #15585 "fix Issue 24129 - ImportC: MS-Link cannot handle multiple COMDATs wit…" was merged into master:

- a60429f2eeb738195363ed47f2c519113fe62bd8 by Walter Bright:
  fix Issue 24129 - ImportC: MS-Link cannot handle multiple COMDATs with the
same name

https://github.com/dlang/dmd/pull/15585

--
April 10
https://issues.dlang.org/show_bug.cgi?id=24129

Lance Bachmeier <lance@lancebachmeier.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lance@lancebachmeier.com

--- Comment #6 from Lance Bachmeier <lance@lancebachmeier.com> ---
This is marked RESOLVED FIXED but I get the same error message with DMD 2.108.0.

--