Bug 20668 – Unresolved symbol (array equality) when using separate compilation

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2020-03-11T20:00:28Z
Last change time
2024-12-13T19:07:33Z
Assigned to
No Owner
Creator
moonlightsentinel
Moved to GitHub: dmd#17945 →

Comments

Comment #0 by moonlightsentinel — 2020-03-11T20:00:28Z
The following example results in a linker error when every file is compiled separately: ------------------------------------------------- module test11931a; import test11931d; import test11931b; class Engine { Signal!void onLeftUp; } ------------------------------------------------- module test11931b; import test11931c; import test11931d; class GUIElement { Signal!void onSubmit; } ------------------------------------------------- module test11931c; import test11931a; ------------------------------------------------- struct Signal(T, A...) { alias D = T delegate(); D[] _arr; } void main() {} ------------------------------------------------- dmd -m64 -g -L/OPT:NOICF -od=objects -c test11931a.d dmd -m64 -g -L/OPT:NOICF -od=objects -c test11931b.d dmd -m64 -g -L/OPT:NOICF -od=objects -c test11931c.d dmd -m64 -g -L/OPT:NOICF -od=objects -c test11931d.d dmd -m64 -g -od=objects -of=objects\link11931.exe objects\test11931a.obj objects\test11931b.obj objects\test11931c.obj objects\test11931d.obj test11931a.obj : error LNK2019: unresolved external symbol _D4core8internal5array8equality__T8__equalsTxDFZvTxQgZQuFNaNbNiNfAxQwQeZb referenced in function _D10test11931d__T6SignalTvZQk11__xopEqualsFKxSQBs__TQBjTvZQBpKxQsZb test11931b.obj : error LNK2001: unresolved external symbol _D4core8internal5array8equality__T8__equalsTxDFZvTxQgZQuFNaNbNiNfAxQwQeZb objects\link11931.exe : fatal error LNK1120: 1 unresolved externals Error: linker exited with status 1120 ------------------------------------------------- Missing function: _D4core8internal5array8equality__T8__equalsTxDFZvTxQgZQuFNaNbNiNfAxQwQeZb pure nothrow @nogc @safe bool core.internal.array.equality.__equals!(const(void delegate()), const(void delegate())).__equals(const(void delegate())[], cols(const(void delegate())[], const(void delegate())[]) Calling function: _D10test11931d__T6SignalTvZQk11__xopEqualsFKxSQBs__TQBjTvZQBpKxQsZb bool test11931d.Signal!(void).Signal.__xopEquals(ref const(test11931d.Signal!(void).Signal), ref const(test11931d.Signal!(void).Signal)) ------------------------------------------------- This example is reduced from DMDs runnable/link11931.d which fails to compile if you replace the Phobos imports (filter, array) with dummy templates.
Comment #1 by a.horodniceanu — 2024-04-28T22:54:04Z
This has come up as an issue in tilix (https://github.com/gnunn1/tilix/issues/2210) making it uncompilable with dmd and gdc when using meson due to these linking errors. The reduced files for tilix are: --------- module terminal; import common; import session; class Terminal { GenericEvent!() event; } --------- module common; struct GenericEvent() { int[] arr; } --------- module session; import common; import terminal; class Session { GenericEvent!() event; } --------- Compile with: ---- dmd -c terminal.d dmd -c session.d dmd -c common.d dmd -of=main -main common.o session.o terminal.o ---- The results are: ---- /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: session.o: in function `_D6common__T12GenericEventZQp11__xopEqualsMxFKxSQBu__TQBqZQBuZb': session.d:(.text._D6common__T12GenericEventZQp11__xopEqualsMxFKxSQBu__TQBqZQBuZb[_D6common__T12GenericEventZQp11__xopEqualsMxFKxSQBu__TQBqZQBuZb]+0x25): undefined reference to `_D4core8internal5array8equality__T8__equalsTiTiZQoFNaNbNiNeMxAiMxQeZb' collect2: error: ld returned 1 exit status Error: linker exited with status 1 cc common.o session.o terminal.o main.o -o main -m64 -Xlinker --export-dynamic -Xlinker -rpath=/usr/lib/dmd/2.108/lib64 -L/usr/lib/dmd/2.108/lib64 -lphobos2 -lpthread -lm -lrt -ldl ----
Comment #2 by alphaglosined — 2024-04-28T23:43:39Z
This is likely a template emission eliding bug. Try with ``-allinst`` to force emittance.
Comment #3 by a.horodniceanu — 2024-04-29T05:29:46Z
(In reply to Richard Cattermole from comment #2) > This is likely a template emission eliding bug. > > Try with ``-allinst`` to force emittance. This fixes it, thanks! This issue with tilix has been bugging me for a while, nice to have found a solution.
Comment #4 by robert.schadek — 2024-12-13T19:07:33Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17945 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB