Incremental compilation with DMD

Walter Bright newshound1 at digitalmars.com
Sat Sep 12 21:29:25 PDT 2009


Tom S wrote:
> Walter Bright wrote:
>> Tom S wrote:
>>> As for my own impressions of this idea, its biggest drawback probably 
>>> is that the multitude of object files created via -multiobj strains 
>>> the filesystem.
>>
>> Sure, but -multiobj and -lib generate exactly the same object files, 
>> it's just that -lib puts them all into a library so it doesn't strain 
>> the file system.
>>
>> Extracting the obj files from the lib is pretty simple, you can see 
>> the libomf.c for the format.
> 
> You're right, I'm sorry. I must've overlooked something in the lib dumps 
> and assumed one module overwrites the other.
> 
> So with -lib, it should be possible to only extract the object files 
> that contain static constructors and the main function and keep the rest 
> packed up. Does that sound about right?

All the .lib file is, is:

[header]
[all the object files concatenated together and aligned]
[dictionary and index]

Linux .a libraries are the same idea, just a different format for the 
header, dictionary and index. The obj files are unmodified in the 
library. You can extract them based on whatever criteria you need.

> By the way, using -lib causes DMD to eat a LOT of memory compared to the 
> 'normal' mode - in one of my projects, it eats up easily > 1.2GB and 
> dies. This could be a downside to this approach. I haven't tested 
> whether it's the same with -multiobj

Hmm. I build Phobos with -lib, and haven't experienced any problems, but 
it's possible as dmd doesn't ever discard any memory.


> Would it be hard to add an option to DMD to control template emission? 
> Apparently GDC has -femit-templates, so it's doable ;) LDC outputs 
> instantiations to all objects.

I've found the LDC approach to be generally a poor one (having much 
experience with it for C++, where there is no choice). It generates huge 
object files and there are often linker problems trying to remove the 
duplicates. I really got tired of "COMDAT" problems with linkers, and 
no, it wasn't just with Optlink. Having each template instantiation in 
its own obj file works out great, eliminating all those problems.

I don't really understand why the -lib approach is not working for your 
needs.



More information about the Digitalmars-d mailing list