Thread overview
Re: gcc 4.8.1 made it to Debian Sid
Jul 11, 2013
H. S. Teoh
Jul 15, 2013
eles
Jul 15, 2013
Iain Buclaw
Jul 18, 2013
eles
July 11, 2013
On Thu, Jul 11, 2013 at 08:09:33AM +0100, Iain Buclaw wrote:
> On Jul 11, 2013 1:28 AM, "H. S. Teoh" <hsteoh@quickfur.ath.cx> wrote:
[...]
> >   The trouble with this case is that currently gdmd always compiles
> >   each source file separately (following the behaviour of the old
> >   Perl
> 
> Are you sure on that?  :-)

Heh, you're right, I misread the Perl script (or rather, didn't pay attention to that little flag named $combine). The original script does indeed compile everything all at once. I'll have to change my new version to do the same. :)


> My memory might be bad in this respect, but I seem to recall the script explicitly set the output program / object file name. (See below for why that matters ).

I've set up the new version to always specify output filenames too. But I missed the part where separate compilation *isn't* the default. :)


> >   script), so we can't just rename the default test.o to prog.o.
> >   Also, IME, running gdc with too many .d files at once can
> >   sometimes cause memory problems, so doing it one at a time seems
> >   preferable.
> >
> 
> Running dmd with too many .d files causes the same memory problems, but they tend to be short lived due to the speed of the compilation.

I'll have to experiment with that one a little bit more. I have a particular project that appears to use a combination of templates that causes the old gdc-4.6 to crash / produce wrong results when compiled all together, but I haven't tried it with gdc-4.8 yet.


> The difference between single and multiple file compilation is very subtle in gdc since the switch to LTO.
> 
> gdc foo.d bar.d.   # compiled separately.
> gdc foo.d bar.d -o exe   # compiled together.
> 
> People from a dmd background I found expected the latter, and separate compilation also comes with its own quirks that don't occur during single compilation of all sources (the most common suggested work around for this being -femit-templates, though should give the switch -fonly some lovin' someday).
[...]

You're right, I'll have to rewrite gdmd.compile() to do everything in one go instead of compiling separately, as I have it now.


T

-- 
English has the lovely word "defenestrate", meaning "to execute by throwing someone out a window", or more recently "to remove Windows from a computer and replace it with something useful". :-) -- John Cowan
July 15, 2013
On Thursday, 11 July 2013 at 14:42:09 UTC, H. S. Teoh wrote:
> On Thu, Jul 11, 2013 at 08:09:33AM +0100, Iain Buclaw wrote:
>> On Jul 11, 2013 1:28 AM, "H. S. Teoh" <hsteoh@quickfur.ath.cx> wrote:
> Heh, you're right, I misread the Perl script (or rather, didn't pay
> attention to that little flag named $combine). The original script does
> indeed compile everything all at once. I'll have to change my new
> version to do the same. :)

The perl script achieves that by adding the "-combine" option to
the invocation of gdc (perl/l626). That is a deprecated option.
Newer one is to use "-flto" and, also, if the output is an exe,
"-fwhole-program" could be added, too.

see here:

http://lwn.net/Articles/387122/

I think there is no problem to provide "-flto" to gdc even if
there is just only one source file (unlike the "$combine" flag
that is activated only for multiple source files: perl/l490).

More, apparently, since gcc 4.6, that "-combine" flag seems to be
inert:

http://gcc.gnu.org/gcc-4.6/changes.html
July 15, 2013
On 15 July 2013 15:25, eles <eles@eles.com> wrote:
> On Thursday, 11 July 2013 at 14:42:09 UTC, H. S. Teoh wrote:
>>
>> On Thu, Jul 11, 2013 at 08:09:33AM +0100, Iain Buclaw wrote:
>>>
>>> On Jul 11, 2013 1:28 AM, "H. S. Teoh" <hsteoh@quickfur.ath.cx> wrote:
>>
>> Heh, you're right, I misread the Perl script (or rather, didn't pay attention to that little flag named $combine). The original script does indeed compile everything all at once. I'll have to change my new version to do the same. :)
>
>
> The perl script achieves that by adding the "-combine" option to the invocation of gdc (perl/l626). That is a deprecated option. Newer one is to use "-flto" and, also, if the output is an exe, "-fwhole-program" could be added, too.
>

No, simply explicitly setting an -o object file is enough to achieve the behaviour of the old "-combine" switch in prior gcc releases.

You don't want to be using -flto, -flto does not work with the D frontend.

--
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';
July 18, 2013
On Thursday, 11 July 2013 at 14:42:09 UTC, H. S. Teoh wrote:
> On Thu, Jul 11, 2013 at 08:09:33AM +0100, Iain Buclaw wrote:
>> On Jul 11, 2013 1:28 AM, "H. S. Teoh" <hsteoh@quickfur.ath.cx>
> You're right, I'll have to rewrite gdmd.compile() to do everything in
> one go instead of compiling separately, as I have it now.

This? (BTW, how to send github pull requests to a fork of the main repo?)

diff --git a/gdmd.d b/gdmd.d
index bb310aa..dd08900 100644
--- a/gdmd.d
+++ b/gdmd.d
@@ -513,7 +513,7 @@ void parseArgs(Config cfg, string[] _args)
 /**
  * Compiles the given source files.
  */
-void compile(Config cfg)
+void compile_only(Config cfg)
 {
     foreach (srcfile; cfg.sources) {
         auto objfile = cfg.src2obj(srcfile);
@@ -590,18 +590,18 @@ unittest
 }

 /**
- * Links the given sources files into the final executable.
+ * Compiles and links the given sources files into the final executable.
  */
-void link(Config cfg)
+void compile_and_link(Config cfg)
 {
-    /*
+       /*
      * Construct link command
      */
-    auto cmd = [ cfg.linker ] ~ cfg.linkFlags;
+    auto cmd = [ cfg.linker ] ~ cfg.gdcFlags ~ cfg.linkFlags;

     // Collect all object files.
     foreach (srcfile; cfg.sources) {
-        cmd ~= cfg.src2obj(srcfile);
+        cmd ~= srcfile;
     }

     // Create target directory if it doesn't exist yet.
@@ -619,7 +619,7 @@ void link(Config cfg)
     debug writeln("[exec] ", cmd.join(" "));
     auto rc = execute(cmd);
     if (rc.status != 0)
-        throw new Exception("Link failed: %s".format(rc.output));
+        throw new Exception("Compile and link failed: %s".format(rc.output));
 }

 /**
@@ -636,10 +636,12 @@ int main(string[] args)
             exit(0);
         }

-        compile(cfg);
-
-        if (!cfg.dontLink)
-            link(cfg);
+       if (cfg.dontLink) {
+               compile_only(cfg);
+       }
+       else {
+               compile_and_link(cfg);
+       }

         return 0;
     } catch(ExitException e) {