Thread overview | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
October 17, 2015 Phobos still being statically linked in? | ||||
---|---|---|---|---|
| ||||
I went back to see my first post here in the D world two years ago: http://forum.dlang.org/post/mailman.413.1369930723.13711.digitalmars-d-learn@puremagic.com I had noted then with surprise that the most basic Hello World program took 300K+ with rdmd, but now it seems it's much more i.e. 600K+ with dmd (since rdmd doesn't seem to leave out any executables any more). ldc2 is much better at 300K+ but still doesn't compare to C/C++... $ cat namaste.d import std.stdio; void main () { writeln("Namaste!"); } $ dmd namaste.d && ls -l namaste* -rwxrwxr-x 1 samjnaa samjnaa 645544 Oct 17 15:21 namaste -rw-rw-r-- 1 samjnaa samjnaa 56 Oct 17 15:20 namaste.d -rw-r--r-- 1 samjnaa samjnaa 14932 Oct 17 15:21 namaste.o $ ldc2 namaste.d && ls -l namaste* -rwxrwxr-x 1 samjnaa samjnaa 346144 Oct 17 15:21 namaste -rw-rw-r-- 1 samjnaa samjnaa 56 Oct 17 15:20 namaste.d -rw-rw-r-- 1 samjnaa samjnaa 25456 Oct 17 15:21 namaste.o $ dmd --version DMD64 D Compiler v2.068.2 Copyright (c) 1999-2015 by Digital Mars written by Walter Bright $ ldc2 -version LDC - the LLVM D compiler (0.16.0-beta2): based on DMD v2.067.1 and LLVM 3.7.0 Default target: x86_64-unknown-linux-gnu Host CPU: haswell I was told then (http://forum.dlang.org/post/op.wxwn0jys54xghj@puck.auriga.bhead.co.uk) that the reason was that the library was linked in statically. Is this still true as it seems to be? If so, how do I tell dmd/ldc2 not to do that, but to use the available SO at: /usr/lib/x86_64-linux-gnu/libphobos2.so.0.68.2 -- Shriramana Sharma, Penguin #395953 |
October 17, 2015 Re: Phobos still being statically linked in? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shriramana Sharma | Yes, it's still linked statically by default, at least with DMD. I don't know why this wasn't changed yet, I just tried linking against libphobos.so and it worked. The resulting binary is then down to 13 Kb, after stripping. On the topic of executable size, Vladimir Panteleev did some work to check it automatically for each version of DMD: http://blog.thecybershadow.net/2015/05/05/is-d-slim-yet/ http://digger.k3.1azy.net/trend/ |
October 17, 2015 Re: Phobos still being statically linked in? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz | Marc Schütz wrote: > Yes, it's still linked statically by default, at least with DMD. I don't know why this wasn't changed yet, I just tried linking against libphobos.so and it worked. The resulting binary is then down to 13 Kb, after stripping. Wow that's nice to hear! Can you outline the steps to link any given .d file against libphobos.so? Thanks! -- Shriramana Sharma, Penguin #395953 |
October 17, 2015 Re: Phobos still being statically linked in? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz | Marc Schütz wrote: > Yes, it's still linked statically by default, at least with DMD. I don't know why this wasn't changed yet, I just tried linking against libphobos.so and it worked. The resulting binary is then down to 13 Kb, after stripping. Filed https://issues.dlang.org/show_bug.cgi?id=15218 -- Shriramana Sharma, Penguin #395953 |
October 17, 2015 Re: Phobos still being statically linked in? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shriramana Sharma | On Saturday, 17 October 2015 at 13:54:12 UTC, Shriramana Sharma wrote:
> Marc Schütz wrote:
>
>> Yes, it's still linked statically by default, at least with DMD. I don't know why this wasn't changed yet, I just tried linking against libphobos.so and it worked. The resulting binary is then down to 13 Kb, after stripping.
>
> Wow that's nice to hear! Can you outline the steps to link any given .d file against libphobos.so?
Unfortunately, I haven't found a switch that makes DMD use dynamic linking. Maybe I just missed it... So, you have to do it step by step:
1) Use the `-c` switch to make the compiler output:
dmd -O -inline -c foo.d
This generates `foo.o`.
2) Link by calling `gcc`:
gcc -o foo foo.o -lphobos2
This calls `ld` with the right options and results in a binary `foo`.
3) Optionally, strip the binary to make it smaller:
strip foo
|
October 17, 2015 Re: Phobos still being statically linked in? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shriramana Sharma | On Saturday, 17 October 2015 at 10:00:20 UTC, Shriramana Sharma wrote:
> Is this still true as it seems to be? If so, how do I tell dmd/ldc2 not to do that, but to use the available SO at:
I'm not sure about ldc but the dmd option `-defaultlib=libphobos2.so` should do it. I think ldmd also works with that.
|
October 18, 2015 Re: Phobos still being statically linked in? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shriramana Sharma | For the Gentoo Linux DMD package I made dynamic linking the default. It's not just Phobos but other libraries as well, like GtkD and what else you link into your executable.
A simple GUI converting text in the clipboard on button press is at around 553 KiB now. With static linking it is 6 MiB.
--
Marco
|
October 18, 2015 Re: Phobos still being statically linked in? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz | On 2015-10-17 13:28, Marc Schütz wrote: > Yes, it's still linked statically by default, at least with DMD. I don't > know why this wasn't changed yet 1. It makes it easier to distribute binaries since most computers won't have a Phobos and druntime installed 2. There's no guaranteed ABI compatibly between different release of D -- /Jacob Carlborg |
October 19, 2015 Re: Phobos still being statically linked in? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marco Leise | On 10/18/2015 01:37 PM, Marco Leise wrote:
> For the Gentoo Linux DMD package I made dynamic linking the
> default. It's not just Phobos but other libraries as well,
> like GtkD and what else you link into your executable.
>
> A simple GUI converting text in the clipboard on button press
> is at around 553 KiB now. With static linking it is 6 MiB.
How large is Hello, word when dynamically linked? -- Andrei
|
October 19, 2015 Re: Phobos still being statically linked in? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Monday, 19 October 2015 at 16:07:02 UTC, Andrei Alexandrescu wrote:
> On 10/18/2015 01:37 PM, Marco Leise wrote:
>> For the Gentoo Linux DMD package I made dynamic linking the
>> default. It's not just Phobos but other libraries as well,
>> like GtkD and what else you link into your executable.
>>
>> A simple GUI converting text in the clipboard on button press
>> is at around 553 KiB now. With static linking it is 6 MiB.
>
> How large is Hello, word when dynamically linked? -- Andrei
And how much of it is pulled in via Object.factory ? I'd bet a lot.
|
Copyright © 1999-2021 by the D Language Foundation