Bug 18049 – dmd -unittest against a library not compiled with -unittest gives undefined symbols

Status
NEW
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2017-12-09T00:08:32Z
Last change time
2024-12-13T18:55:19Z
Assigned to
No Owner
Creator
Timothee Cour
Moved to GitHub: dmd#19342 →

Comments

Comment #0 by timothee.cour2 — 2017-12-09T00:08:32Z
This is a serious blocker, which could potentially lead to not being able to compile with -unittest some code that depends on another library that was not compiled with -unittest (eg could be phobos if phobos code uses pattern shown in this bug) dmd -lib -unittest -oflibfun.a fun.d dmd -main -unittest main.d libfun.a #works dmd -lib -oflibfun.a fun.d dmd -main -unittest main.d libfun.a Undefined symbols for architecture x86_64: "_D3fun__T1ATtZQf8opEqualsMxFNaNbNiNfSQBj__TQBiTtZQBoZb", referenced from: _D3fun__T1ATtZQf11__xopEqualsFKxSQBf__TQBeTtZQBkKxQsZb in main.o ld: symbol(s) not found for architecture x86_64 ------------------ fun.d: module fun; struct A(T){ bool opEquals(A!T) const { auto a=typeid(A!T); return true; } unittest { alias b = A!(ushort); } } enum ignore = A!int(); main.d: module main; import fun; NOTE: this was obtained after painful manual reduction from https://issues.dlang.org/show_bug.cgi?id=16477
Comment #1 by timothee.cour2 — 2017-12-09T00:10:07Z
demangled error: echo _D3fun__T1ATtZQf8opEqualsMxFNaNbNiNfSQBj__TQBiTtZQBoZb|ddemangle const pure nothrow @nogc @safe bool fun.A!(ushort).A.opEquals(fun.A!(ushort).A) echo _D3fun__T1ATtZQf11__xopEqualsFKxSQBf__TQBeTtZQBkKxQsZb|ddemangle bool fun.A!(ushort).A.__xopEquals(ref const(fun.A!(ushort).A), ref const(fun.A!(ushort).A))
Comment #2 by timothee.cour2 — 2017-12-09T00:11:00Z
*** Issue 16477 has been marked as a duplicate of this issue. ***
Comment #3 by timothee.cour2 — 2017-12-09T00:20:51Z
same error whether we compile as .a, .dylib, or .o
Comment #4 by timothee.cour2 — 2017-12-09T00:23:42Z
likewise with ldc
Comment #5 by r.sagitario — 2018-01-05T09:14:53Z
That's a use case where the dreaded -allinst was added for: seperate compilation with different version, debug or unittest settings. In that case the template emission optimization fails to work because it assumes that the template is already emitted. It's a bit strange that the optimization does not also avoid generating any code for the unittests, though.
Comment #6 by timothee.cour2 — 2018-01-05T15:25:21Z
confirmed that adding -allinst works (both with dmd and ldc), but indeed, this should be fixed. question: what are downsides of -allinst?
Comment #7 by r.sagitario — 2018-01-05T21:33:40Z
downsides are slower compilation and bloated object files. Should not make a difference in the size of the executable.
Comment #8 by robert.schadek — 2024-12-13T18:55:19Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19342 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB