Bug 18188 – rdmd ignores dependency in 'static this()'
Status
RESOLVED
Resolution
WONTFIX
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2018-01-03T17:29:55Z
Last change time
2019-05-11T16:14:14Z
Assigned to
No Owner
Creator
Dragos Carp
Comments
Comment #0 by dragoscarp — 2018-01-03T17:29:55Z
There are cases when rdmd ignores the local imports defined in 'static this()'. Moving 'import baz' out of static this will give the expected result.
See the example bellow.
// foo.d
void main()
{
import bar;
}
// bar.d
static this()
{
import baz : baz;
baz;
}
// baz.d
int baz()
{
return 0;
}
$ rdmd --build-only --chatty foo.d
mkdirRecurse /tmp/.rdmd-500
mkdirRecurse /tmp/.rdmd-500/rdmd-foo.d-882FBF761B809294731EC3E5E391C36F
lock /tmp/.rdmd-500/rdmd-foo.d-882FBF761B809294731EC3E5E391C36F/rdmd.lock
mkdirRecurse /tmp/.rdmd-500/rdmd-foo.d-882FBF761B809294731EC3E5E391C36F/objs
stat /tmp/.rdmd-500/rdmd-foo.d-882FBF761B809294731EC3E5E391C36F/rdmd.deps
spawn ["/usr/bin/dmd", "-v", "-o-", "foo.d", "-I."]
read /tmp/.rdmd-500/rdmd-foo.d-882FBF761B809294731EC3E5E391C36F/rdmd.deps
which /usr/bin/dmd
stat /etc/dmd.conf
stat /tmp/.rdmd-500/rdmd-foo.d-882FBF761B809294731EC3E5E391C36F/.built
stat ./foo
stat foo.d
stat foo.d
stat /etc/dmd.conf
stat bar.d
stat /usr/bin/dmd
stat ./foo
spawn ["/usr/bin/dmd", "-of./foo.tmp", "-od/tmp/.rdmd-500/rdmd-foo.d-882FBF761B809294731EC3E5E391C36F/objs", "-I.", "foo.d", "bar.d"]
/tmp/.rdmd-500/rdmd-foo.d-882FBF761B809294731EC3E5E391C36F/objs/foo.o: In function `_D3bar12_staticCtor1FZv':
bar.d:(.text._D3bar12_staticCtor1FZv[_D3bar12_staticCtor1FZv]+0x5): undefined reference to `_D3bazQeFZi'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
Comment #1 by dragoscarp — 2018-01-10T22:58:55Z
The problem is caused by `dmd -v` output, that is parsed and used by rdmd.
$ dmd -v -o- foo.d
predefs DigitalMars Posix linux ELFv1 LittleEndian D_Version2 all D_SIMD D_InlineAsm_X86_64 X86_64 CRuntime_Glibc D_LP64 D_PIC assert D_HardFloat
binary dmd
version v2.078.0
config /etc/dmd.conf
parse foo
importall foo
import object (/usr/include/dmd/druntime/import/object.d)
semantic foo
entry main foo.d
semantic2 foo
semantic3 foo
import bar (bar.d)
Calling dmd with -deps option fixes the problem:
$ dmd -v -o- foo.d -deps=/dev/null
predefs DigitalMars Posix linux ELFv1 LittleEndian D_Version2 all D_SIMD D_InlineAsm_X86_64 X86_64 CRuntime_Glibc D_LP64 D_PIC assert D_HardFloat
binary dmd
version v2.078.0
config /etc/dmd.conf
parse foo
importall foo
import object (/usr/include/dmd/druntime/import/object.d)
semantic foo
entry main foo.d
semantic2 foo
semantic3 foo
import bar (bar.d)
import baz (baz.d)
Consequently rdmd command also functions when -deps option is added:
$ rdmd --build-only --chatty -deps=/dev/null foo.d
mkdirRecurse /tmp/.rdmd-500
mkdirRecurse /tmp/.rdmd-500/rdmd-foo.d-2D7BE73D8EB3145BDB8A563EF51C3756
lock /tmp/.rdmd-500/rdmd-foo.d-2D7BE73D8EB3145BDB8A563EF51C3756/rdmd.lock
mkdirRecurse /tmp/.rdmd-500/rdmd-foo.d-2D7BE73D8EB3145BDB8A563EF51C3756/objs
stat /tmp/.rdmd-500/rdmd-foo.d-2D7BE73D8EB3145BDB8A563EF51C3756/rdmd.deps
spawn ["/usr/bin/dmd", "-deps=/dev/null", "-v", "-o-", "foo.d", "-I."]
read /tmp/.rdmd-500/rdmd-foo.d-2D7BE73D8EB3145BDB8A563EF51C3756/rdmd.deps
which /usr/bin/dmd
stat /etc/dmd.conf
stat /tmp/.rdmd-500/rdmd-foo.d-2D7BE73D8EB3145BDB8A563EF51C3756/.built
stat ./foo
stat foo.d
stat foo.d
stat /etc/dmd.conf
stat baz.d
stat bar.d
stat /usr/bin/dmd
stat ./foo
spawn ["/usr/bin/dmd", "-deps=/dev/null", "-of./foo.tmp", "-od/tmp/.rdmd-500/rdmd-foo.d-2D7BE73D8EB3145BDB8A563EF51C3756/objs", "-I.", "foo.d", "baz.d", "bar.d"]
stat /tmp/.rdmd-500/rdmd-foo.d-2D7BE73D8EB3145BDB8A563EF51C3756/objs
rmdirRecurse /tmp/.rdmd-500/rdmd-foo.d-2D7BE73D8EB3145BDB8A563EF51C3756/objs
mv ./foo.tmp ./foo
touch /tmp/.rdmd-500/rdmd-foo.d-2D7BE73D8EB3145BDB8A563EF51C3756/.built