[Issue 13742] undefined reference to __coverage
https://issues.dlang.org/show_bug.cgi?id=13742 --- Comment #8 from github-bugzi...@puremagic.com --- Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/69e7bd18892df18f682906916bf8c8ad87fb30e5 fix Issue 13742 - undefined reference to __coverage - Nested template functions may reference coverage symbols of other modules. Those coverage symbols are either still `null` or already `symbol_reset`, in the former case coverage instrumentation is silently skipped, in the later case the linker will cause an error. This is because the current object file ends up with two `__coverage` symbols, one local BSS symbols and an undefined external symbol (for the other module's coverage). - Fixed by mangling the symbols as _D3pkg3mod__coverageZ (similar to __ModuleInfoZ) and making them global. - Ideally the symbols would use -visibility=hidden, but that ELF backend feature isn't yet accessible from glue.d. - This does not fix missing coverage when the referenced module hasn't yet been codegen'ed (e.g. because it follows on the command line or is part of another separate compilation). Using weak linkage to make this heuristically work would incurr some overhead for the coverage instrumentation. Unconditionally referencing coverage info OTOH might be too excessive, e.g. when the template function is in phobos, which would require to recompile phobos with -cov for successful linking. https://github.com/dlang/dmd/commit/0cb16110c307b608034d49289e2a650e7d7d7dd8 Merge pull request #7654 from MartinNowak/fix13742 fix Issue 13742 - undefined reference to __coverage --
[Issue 13742] undefined reference to __coverage
https://issues.dlang.org/show_bug.cgi?id=13742 github-bugzi...@puremagic.com changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED --
[Issue 13742] undefined reference to __coverage
https://issues.dlang.org/show_bug.cgi?id=13742 Martin Nowakchanged: What|Removed |Added Keywords||pull --- Comment #7 from Martin Nowak --- https://github.com/dlang/dmd/pull/7654 --
[Issue 13742] undefined reference to __coverage
https://issues.dlang.org/show_bug.cgi?id=13742 --- Comment #6 from Martin Nowak--- The problem seems to be that the `performLocked!(() => foo);` has a location in bar.d and tries to increment bar's location, but the bar object is already emitted. When objects are done all symbols get reset and further references from other objects add an external undefined symbol, this seems to trigger the linker bug. As __coverage is local (static) symbol, referencing it from another object file isn't possible atm. anyhow. So I think the root cause is that the compile order bar.d foo.d ends up moving the nested template function pure nothrow @nogc @safe void bar.performLocked!(foo.clear().foo()).performLocked(int) to the foo.o object, where it can no longer reference bar.d's coverage symbol. --
[Issue 13742] undefined reference to __coverage
https://issues.dlang.org/show_bug.cgi?id=13742 --- Comment #5 from Martin Nowak--- Apparently happens because the __coverage symbols is defined twice in foo.o (2.078.0), once as BSS symbols and once as undefined symbol. nm lib.a foo.o: t d __bcoverage b __coverage U __coverage U _D3bar12__ModuleInfoZ Interestingly works when you swap foo.d and bar.d on the command line. --
[Issue 13742] undefined reference to __coverage
https://issues.dlang.org/show_bug.cgi?id=13742 Les De Ridderchanged: What|Removed |Added CC||dl...@lesderid.net --
[Issue 13742] undefined reference to __coverage
https://issues.dlang.org/show_bug.cgi?id=13742 Luís Marqueschanged: What|Removed |Added CC||l...@luismarques.eu --
[Issue 13742] undefined reference to __coverage
https://issues.dlang.org/show_bug.cgi?id=13742 Sönke Ludwigchanged: What|Removed |Added CC||slud...@outerproduct.org --- Comment #4 from Sönke Ludwig --- For completeness sake, this is what I reduced from vibe.d: foo.d --- import bar; void clear() { void foo() {} performLocked!(() => foo); } --- bar.d --- import core.thread; void performLocked(alias PROC)() { assert(false); } --- main.d --- import foo; void main() {} --- dmd -lib -oflib.a bar.d foo.d -cov dmd -oftest lib.a main.d -cov -> lib.a(foo.o):foo.d:function _D3bar50__T13performLockedS28_D3foo5clearFZ9__lambda2MFZvZ13performLockedMFNaNbNiNfZv: error: undefined reference to '__coverage' --
[Issue 13742] undefined reference to __coverage
https://issues.dlang.org/show_bug.cgi?id=13742 Marc Schütz schue...@gmx.net changed: What|Removed |Added CC||schue...@gmx.net --
[Issue 13742] undefined reference to __coverage
https://issues.dlang.org/show_bug.cgi?id=13742 Martin Nowak c...@dawg.eu changed: What|Removed |Added Priority|P1 |P4 --
[Issue 13742] undefined reference to __coverage
https://issues.dlang.org/show_bug.cgi?id=13742 --- Comment #3 from Martin Nowak c...@dawg.eu --- (In reply to jiki from comment #2) I hit this on Windows. Reduced test case is here. Also confirmed for linux. A temporary workaround for your case is to only generate a single object file. dmd -cov -g -c -oftmp.o test.d f.d dmd -cov -g -main tmp.o Hope that also works on Windows. --
[Issue 13742] undefined reference to __coverage
https://issues.dlang.org/show_bug.cgi?id=13742 j...@red.email.ne.jp changed: What|Removed |Added CC||j...@red.email.ne.jp --- Comment #2 from j...@red.email.ne.jp --- I hit this on Windows. Reduced test case is here. COMMAND: dmd -cov -g -c test.d f.d dmd -cov -g -main test.obj f.obj OUTPUT: Error 42: Symbol Undefined ___coverage --- errorlevel 1 SOURCE FILES: f.d - import std.algorithm; void func(alias pred)() { int[] range; range.find!pred(0); } - test.d - import f; enum mypred = (int a, int b)=false; //bool mypred(int a, int b) { return false; } -- WORK AROUND void test() { func!mypred(); } - --
[Issue 13742] undefined reference to __coverage
https://issues.dlang.org/show_bug.cgi?id=13742 --- Comment #1 from Martin Nowak c...@dawg.eu --- Another occurence of this issue. https://github.com/kiith-sa/D-YAML/issues/20 --