www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13631] New: [REG2.067-git-master] New no-op module ctors

https://issues.dlang.org/show_bug.cgi?id=13631

          Issue ID: 13631
           Summary: [REG2.067-git-master] New no-op module ctors cause
                    circular dependencies.
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Keywords: wrong-code
          Severity: regression
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: Marco.Leise gmx.de

Based on commit 15b68997d0ae2332ed653658e5d7643fcf0d354f

In some cases dmd now seems to emit module ctors/dtors for empty modules just
depending on what they import. This in turn causes new circular dependency
conflicts that weren't there previously.

I didn't reduce my code base, but it probably rings a bell already when I say
that this file now gets an auto-generated(?) module ctor:

------------------
module Lib.Audio.Sample;

import Lib.Audio.AudioLoader;
------------------

(AudioLoader itself also imports Lib.Audio.Sample.)

The generated file is ~810 KiB large and the output of nm for
`Lib.Audio.Sample.o` contains as well as a lot of symbols from Phobos like
std.parallelism or std.container:

0000000000000000 T _D3Lib5Audio6Sample9__modctorFZv
0000000000000000 T _D3Lib5Audio6Sample9__moddtorFZv

objdump further reveals that DMD now emulates -ffunction-sections and that the
code it generates for the module ctor/dtor is a glorified no-op.

Disassembly of section .text._D3Lib5Audio6Sample9__modctorFZv:

0000000000000000 <_D3Lib5Audio6Sample9__modctorFZv>:
   0:   push   rbp
   1:   mov    rbp,rsp
   4:   push   rbx
   5:   mov    rax,QWORD PTR fs:0x0
   e:   mov    rcx,QWORD PTR [rip+0x0]
  15:   inc    DWORD PTR [rax+rcx*1]
  18:   mov    rdx,QWORD PTR fs:0x0
  21:   mov    rbx,QWORD PTR [rip+0x0]
  28:   inc    DWORD PTR [rdx+rbx*1]
  2b:   pop    rbx
  2c:   pop    rbp
  2d:   ret    
  2e:   xchg   ax,ax

Disassembly of section .text._D3Lib5Audio6Sample9__moddtorFZv:

0000000000000000 <_D3Lib5Audio6Sample9__moddtorFZv>:
   0:   push   rbp
   1:   mov    rbp,rsp
   4:   call   9 <_D3Lib5Audio6Sample9__moddtorFZv+0x9>
   9:   call   e <_D3Lib5Audio6Sample9__moddtorFZv+0xe>
   e:   pop    rbp
   f:   ret

--
Oct 18 2014