Potential of a compiler that creates the executable at once

Walter Bright newshound2 at digitalmars.com
Sat Feb 12 00:56:44 UTC 2022


On 2/11/2022 1:42 AM, Dennis wrote:
> On Friday, 11 February 2022 at 06:33:20 UTC, Walter Bright wrote:
>> Now suppose X.obj and Y.obj both define foo. Link with:
>>
>>     link X.obj Y.obj A.lib B.lib C.lib
>>
>> You get a message:
>>
>>     Multiple definition of "foo", found in X.obj and Y.obj
> 
> Unless your compiler places all functions in COMDATs of course.
> 
> https://github.com/dlang/dmd/blob/a176f0359a07fa5a252518b512f3b085a43a77d8/src/dmd/backend/backconfig.d#L303 
> 
> https://issues.dlang.org/show_bug.cgi?id=15342
> 

Yes, common blocks (of which COMDATs are) are all treated as identical and one 
is selected, but if and only if they are already added by the linker. If the 
linker finds a COMDAT that resolves an undefined symbol, it is not going looking 
further for another one.

COMDATs came about because C++ has a proclivity to spew identical functions into 
multiple object files. D does, too.


More information about the Digitalmars-d mailing list