www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - static linking

reply "Laeeth Isharc" <laeethnospam nospamlaeeth.com> writes:
Hi.

Is static linking with dmd still broken on linux?  If so, can I 
link statically with gdc or ldc, and if so how?

https://issues.dlang.org/show_bug.cgi?id=12268

I am trying to compile a D binary to run on AWS lambda.  If I 
cannot link statically, which files should I include in the zip 
upload - libphobos2.so, libdruntime-linux64so.o ?

Thanks.


Laeeth.
Jul 25 2015
next sibling parent reply Daniel Kozak via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Sat, 25 Jul 2015 18:02:46 +0000
Laeeth Isharc via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:

 Hi.
 
 Is static linking with dmd still broken on linux?  If so, can I 
 link statically with gdc or ldc, and if so how?
 
 https://issues.dlang.org/show_bug.cgi?id=12268
 
 I am trying to compile a D binary to run on AWS lambda.  If I 
 cannot link statically, which files should I include in the zip 
 upload - libphobos2.so, libdruntime-linux64so.o ?
 
 Thanks.
 
 
 Laeeth.
Do you mean dynamic linking? I do not have any problems with dmd. Can you please post more details what you are trying? *.so are dynamic, *.[l]a are static
Jul 25 2015
parent reply "Laeeth Isharc" <laeethnospam nospamlaeeth.com> writes:
On Saturday, 25 July 2015 at 18:37:18 UTC, Daniel Kozak wrote:
 On Sat, 25 Jul 2015 18:02:46 +0000
 Laeeth Isharc via Digitalmars-d-learn 
 <digitalmars-d-learn puremagic.com> wrote:

 Hi.
 
 Is static linking with dmd still broken on linux?  If so, can 
 I link statically with gdc or ldc, and if so how?
 
 https://issues.dlang.org/show_bug.cgi?id=12268
 
 I am trying to compile a D binary to run on AWS lambda.  If I 
 cannot link statically, which files should I include in the 
 zip upload - libphobos2.so, libdruntime-linux64so.o ?
 
 Thanks.
 
 
 Laeeth.
Do you mean dynamic linking? I do not have any problems with dmd. Can you please post more details what you are trying? *.so are dynamic, *.[l]a are static
I meant that I would prefer to link statically, and if that is possible with dmd, what is the right command to pass to dmd and the linker (64 bit linux, arch)? If not, can I do so with gdc and ldc, and what are the right commands? And failing that, which library files should I include if only dynamic linking works. The bug report seemed to suggest static linking might not be possible with dmd, if I understand it correctly (which I am not certain I do). It's not working currently, but the error message I get back from AWS (I have to call via nodejs) is uninformative, and it might also be because I am compiling on arch, and I think amazon linux is closest to centos 6. AWS lambda seems a pretty cool idea. I am not sure if it will be much use for what I want to do, but it might do, and so I wanted to play around with it a little. Thanks. Laeeth.
Jul 25 2015
parent "Laeeth Isharc" <laeethnospam nospamlaeeth.com> writes:
On Sunday, 26 July 2015 at 01:05:46 UTC, Laeeth Isharc wrote:
 On Saturday, 25 July 2015 at 18:37:18 UTC, Daniel Kozak wrote:
 On Sat, 25 Jul 2015 18:02:46 +0000
 Laeeth Isharc via Digitalmars-d-learn 
 <digitalmars-d-learn puremagic.com> wrote:

 Hi.
 
 Is static linking with dmd still broken on linux?  If so, can 
 I link statically with gdc or ldc, and if so how?
 
 https://issues.dlang.org/show_bug.cgi?id=12268
 
 I am trying to compile a D binary to run on AWS lambda.  If I 
 cannot link statically, which files should I include in the 
 zip upload - libphobos2.so, libdruntime-linux64so.o ?
 
 Thanks.
 
 
 Laeeth.
Do you mean dynamic linking? I do not have any problems with dmd. Can you please post more details what you are trying? *.so are dynamic, *.[l]a are static
I meant that I would prefer to link statically, and if that is possible with dmd, what is the right command to pass to dmd and the linker (64 bit linux, arch)? If not, can I do so with gdc and ldc, and what are the right commands? And failing that, which library files should I include if only dynamic linking works. The bug report seemed to suggest static linking might not be possible with dmd, if I understand it correctly (which I am not certain I do). It's not working currently, but the error message I get back from AWS (I have to call via nodejs) is uninformative, and it might also be because I am compiling on arch, and I think amazon linux is closest to centos 6. AWS lambda seems a pretty cool idea. I am not sure if it will be much use for what I want to do, but it might do, and so I wanted to play around with it a little. Thanks. Laeeth.
So dynamic linking works fine if I bundle the shared libraries with the zip (doable since the zip is only 3.3 Mb and limit is 50), and it turns out arch doesn't provide statically linked system libraries as a matter of policy. So that's good enough for now to experiment, I think.
Jul 25 2015
prev sibling parent reply "Martin Nowak" <code dawg.eu> writes:
On Saturday, 25 July 2015 at 18:02:48 UTC, Laeeth Isharc wrote:
 I am trying to compile a D binary to run on AWS lambda.  If I 
 cannot link statically, which files should I include in the zip 
 upload - libphobos2.so, libdruntime-linux64so.o ?
I think dicebot who maitains the arch linux package change dmd to dynamically link with phobos by default (we don't yet do that on any other platform). You should be able to link statically using -L-l:libphobos2.a or -defaultlib=libphobos2.a.
Jul 25 2015
parent reply "Laeeth Isharc" <laeethnospam nospamlaeeth.com> writes:
On Sunday, 26 July 2015 at 05:22:14 UTC, Martin Nowak wrote:
 On Saturday, 25 July 2015 at 18:02:48 UTC, Laeeth Isharc wrote:
 I am trying to compile a D binary to run on AWS lambda.  If I 
 cannot link statically, which files should I include in the 
 zip upload - libphobos2.so, libdruntime-linux64so.o ?
I think dicebot who maitains the arch linux package change dmd to dynamically link with phobos by default (we don't yet do that on any other platform). You should be able to link statically using -L-l:libphobos2.a or -defaultlib=libphobos2.a.
Thanks, Martin. I appreciate your time. I guess I was mixing up two things - total static linking so the executable doesn't depend on normal libraries, versus static linking with phobos and friends only. The former is trickier on arch in particular (not related to Dicebot's choice) because they don't distributed static versions of library files as a matter of policy. But it's really the latter that I would need to do, and I think what you suggest will do the job. How do I do the same on gdc and ldc ? Since running times may be a matter of seconds, speed and startup time counts especially for lambda. Probably starting via nodejs is an unnecessary tax, but I guess they will get rid of that requirement in time.
Jul 26 2015
next sibling parent Martin Nowak <code+news.digitalmars dawg.eu> writes:
On 07/26/2015 05:19 PM, Laeeth Isharc wrote:
 
 How do I do the same on gdc and ldc ?  Since running times may be a
 matter of seconds, speed and startup time counts especially for lambda. 
 Probably starting via nodejs is an unnecessary tax, but I guess they
 will get rid of that requirement in time.
AFAIK only ldc supports a dynamic phobos library ATM, and it shouldn't be default. But in both cases -L-l:libphobos2.a should do the job, though I think it's called libgphobos2.a for gdc and libphobos2-ldc.a for ldc.
Jul 26 2015
prev sibling parent reply Martin Nowak <code+news.digitalmars dawg.eu> writes:
On 07/26/2015 05:19 PM, Laeeth Isharc wrote:
 The former is trickier on arch in particular (not related to Dicebot's
 choice) because they don't distributed static versions of library files
 as a matter of policy.
Yes, quite a few distributions no longer support fully static linking. Some, e.g. hardened gentoo, don't allow it for security reasons (they use ASLR on PIE).
Jul 26 2015
parent Jonathan M Davis via Digitalmars-d-learn writes:
On Sunday, July 26, 2015 19:17:59 Martin Nowak via Digitalmars-d-learn wrote:
 On 07/26/2015 05:19 PM, Laeeth Isharc wrote:
 The former is trickier on arch in particular (not related to Dicebot's
 choice) because they don't distributed static versions of library files
 as a matter of policy.
Yes, quite a few distributions no longer support fully static linking. Some, e.g. hardened gentoo, don't allow it for security reasons (they use ASLR on PIE).
As I understand, it's considered a _very_ bad idea to statically link to glibc at this point, which sucks, since having a program that just keeps working when other stuff on the system is updated can be nice. It _is_ a security problem on some level though - particularly with stuff like openssl - since if you statically link, you don't get updates when the libraries you depend on get security fixes. But it's definitely statically linking everything that doesn't work with dmd (or at least didn't the last time I checked), because it doesn't pass -static through to gcc properly. Statically linking phobos should work just fine. - Jonathan M Davis
Jul 26 2015