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

option -lib difference from dmd #579

Closed
smolt opened this issue Feb 5, 2014 · 4 comments
Closed

option -lib difference from dmd #579

smolt opened this issue Feb 5, 2014 · 4 comments

Comments

@smolt
Copy link
Member

smolt commented Feb 5, 2014

LDC: ldc2-0.13.0-alpha1-osx-x86_64.tar.xz

Issue description:
ldmd2 -lib option behaves different from dmd. dmd splits a D module into separate compilation units before building the library. ldmd2 does not split the module.

$ cat >testlib.d <<eof
void foo() {}
void bar() {}
void xyzzy() {}
eof
$ dmd -lib -oflibtest.a testlib.d
$ nm libtest.a

libtest.a(testlib.o):
0000000000000050 D _D7testlib12__ModuleInfoZ
0000000000000030 T _D7testlib15__unittest_failFiZv
0000000000000000 T _D7testlib7__arrayZ
0000000000000018 T _D7testlib8__assertFiZv
U __d_array_bounds
U __d_assertm
U __d_unittestm

libtest.a(testlib_1_144.o):
0000000000000000 S _D7testlib3fooFZv

libtest.a(testlib_2_135.o):
0000000000000000 S _D7testlib3barFZv

libtest.a(testlib_3_25e.o):
0000000000000000 S _D7testlib5xyzzyFZv

Also, noticed that dmd and ldmd2 default library naming is different when -of is not specified. dmd calls the library testlib.a where ldmd2 calls it libtestlib.a.

$ dmd --help
DMD64 D Compiler v2.064
Copyright (c) 1999-2013 by Digital Mars written by Walter Bright

$ ldmd2 --help
LDC - the LLVM D compiler (0.13.0-alpha1):
based on DMD v2.064 and LLVM 3.4

redstar added a commit that referenced this issue Feb 5, 2014
dmd has the same behaviour. This fixes issue #579.
@redstar
Copy link
Member

redstar commented Feb 5, 2014

Thanks for the great report. It was easier to fix then I expected. :-)

@redstar redstar closed this as completed Feb 5, 2014
@smolt
Copy link
Member Author

smolt commented Feb 5, 2014

Wow - that was fast! -lib will be nice for breaking up modules like dmain2.d which has the C main embedded in it. This should allow one to link in another C main() to replace dmain2 C main() without hacking runtime code. And could make for smaller statically linked executables!

@redstar
Copy link
Member

redstar commented Feb 5, 2014

As I said - it was easy to fix. I asked for the report because it helps to track issues (especially if I can't fix them in ten minutes. :-)

@smolt
Copy link
Member Author

smolt commented May 21, 2014

I missed something key here. Went to build phobos using -lib but found modules still not broken into multiple .o's. Turns out it is dmd -multiobj option that is not implemented in ldc. -multiobj breaks up a module into separate obj files, which should help make smaller apps when linking to phobos (link only the functions you need). I didn't realize what was going on until I searched the dmd source code and see that -multiobj is turned on by -lib automatically. Idmd2 accepts -multiobj but does not use.

redstar pushed a commit that referenced this issue Sep 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants