Bug 8769 – Template instantiation emitted into wrong file on multi-obj compilation

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-06T12:09:00Z
Last change time
2013-04-07T12:04:53Z
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2012-10-06T12:09:43Z
Consider the following test case: --- // algorithm.d auto filter(alias pred, Range)(Range rs) { return FilterResult!(pred, Range)(rs); } struct FilterResult(alias pred, Range) { this(Range r) {} } --- --- // file.d import algorithm; struct DirIterator {} auto dirEntries() { void f() {} return filter!f(DirIterator()); } void main() {} --- --- dmd -c algorithm.d file.d dmd algorithm.o file.o # Works fine # Now recompile algorithm. dmd -c algorithm.d # ... and try to link again: dmd algorithm.o file.o --- The second attempt to link fails with file.d:(.text._D4file10dirEntriesFZS4file10dirEntries66__T12FilterResultS25_D4file10dirEntries1fMFZvTS4file11DirIteratorZ12FilterResult59__T6filterS25_D4file10dirEntries1fMFZvTS4file11DirIteratorZ6filterMFS4file11DirIteratorZS4file10dirEntries66__T12FilterResultS25_D4file10dirEntries1fMFZvTS4file11DirIteratorZ12FilterResult+0x1e): undefined reference to `_D4file10dirEntriesFZS4file10dirEntries66__T12FilterResultS25_D4file10dirEntries1fMFZvTS4file11DirIteratorZ12FilterResult66__T12FilterResultS25_D4file10dirEntries1fMFZvTS4file11DirIteratorZ12FilterResult6__ctorMFS4file11DirIteratorZS4file10dirEntries66__T12FilterResultS25_D4file10dirEntries1fMFZvTS4file11DirIteratorZ12FilterResult' because DMD initially emitted the symbol in question to algorithm.o instead of file.o. I'm not quite sure about an easy way to fix this. The simple heuristic in https://github.com/D-Programming-Language/dmd/blob/67681b916f7880432c7da14a714404af0254278e/src/template.c#L4854 unfortunately fails once algorithm.d is present on the command line itself, because then (<algorithm>.importedFrom == <algorithm>). We likely need to track the template instantiation "origin" over the whole chain.
Comment #1 by code — 2013-04-07T12:04:53Z
*** This issue has been marked as a duplicate of issue 3274 ***