Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dmd -unittest against a library not compiled with -unittest gives undefined symbols #19342

Open
dlangBugzillaToGithub opened this issue Dec 9, 2017 · 7 comments
Labels

Comments

@dlangBugzillaToGithub
Copy link

Timothee Cour (@timotheecour) reported this on 2017-12-09T00:08:32Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=18049

CC List

  • Johannes Pfau (@jpf91)
  • Rainer Schuetze
  • Timothee Cour

Description

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
@dlangBugzillaToGithub
Copy link
Author

timothee.cour2 commented on 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))

@dlangBugzillaToGithub
Copy link
Author

timothee.cour2 commented on 2017-12-09T00:11:00Z

*** Issue 16477 has been marked as a duplicate of this issue. ***

@dlangBugzillaToGithub
Copy link
Author

timothee.cour2 commented on 2017-12-09T00:20:51Z

same error whether we compile as .a, .dylib, or .o

@dlangBugzillaToGithub
Copy link
Author

timothee.cour2 commented on 2017-12-09T00:23:42Z

likewise with ldc

@dlangBugzillaToGithub
Copy link
Author

r.sagitario commented on 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.

@dlangBugzillaToGithub
Copy link
Author

timothee.cour2 commented on 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?

@dlangBugzillaToGithub
Copy link
Author

r.sagitario commented on 2018-01-05T21:33:40Z

downsides are slower compilation and bloated object files. Should not make a difference in the size of the executable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant