[swift-users] statically link the standard library on Linux

Dmitri Gribenko gribozavr at gmail.com
Wed Feb 17 15:49:39 CST 2016


On Wed, Feb 17, 2016 at 12:40 PM, Drew Crawford via swift-users
<swift-users at swift.org> wrote:
> I traced this down to the sourcecode after I posted here:
> https://bugs.swift.org/browse/SR-730
>
> tll;dr the standard library is forcibly dynamically-linked on Linux, and we
> need a way to opt out of that from the swift frontend.  I have not gone
> further with that since A) my C++-foo is not very excellent and B) core
> hasn't blessed any particular solution I proffered in that thread.  If you
> can make progress there I would be grateful.
>
> Then it is just a matter of getting the flags right; in practice, OSX wants
> -L path/to/swift_static -lc++ -framework Foundation -Xlinker
> -force_load_swift_libs, whereas Linux wants (I believe) -licuuc -licu18n
> -lbsd /path/to/swift_static/a.a /path/to/swift_static/b.a
> /path/to/swift_static/c.a ...  There may be an equivalent to
> force_load_swift_libs that knows what libs to load, but I haven't found it
> yet.

We also want to move to using swift_begin.o and swift_end.o files
instead of the linker script.  With these files, it is *critical* that
they are added at the very beginning and at the very end of the
command line, otherwise one is guaranteed to get a subtle silent
miscompile.

I think we need to add a user-friendly driver-level flag for static
linking, that allows to decide on per-library basis.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-users mailing list