Thread overview
[Issue 5278] gentoo's 'hardended' gcc doesn't work with dmd
Oct 24, 2016
Martin Nowak
Oct 25, 2016
Lodovico Giaretta
Jun 09, 2017
code@dawg.eu
Jun 09, 2017
Martin Nowak
October 24, 2016
https://issues.dlang.org/show_bug.cgi?id=5278

--- Comment #32 from Martin Nowak <code@dawg.eu> ---
This also affects Ubuntu 16.10 to some degree.

[Hardened system tutorial/patch](http://forum.dlang.org/post/paeiukmlqrmgwieabvun@forum.dlang.org) [Cannot link with libphobos2.a with GCC 6.2 on Ubuntu 16.10](http://forum.dlang.org/post/tppsgztsbsdrtkpcbtak@forum.dlang.org)

Using -fPIC -defaultlib=libphobos2.so (the normal shared flags) was reported to be a workaround for the missing -fPIE support on Ubuntu 16.10.

https://github.com/rejectedsoftware/ddox/issues/134

--
October 25, 2016
https://issues.dlang.org/show_bug.cgi?id=5278

Lodovico Giaretta <lodovico@giaretart.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lodovico@giaretart.net

--- Comment #33 from Lodovico Giaretta <lodovico@giaretart.net> ---
I can confirm that putting `-fPIC -defaultlib=libphobos2.so` in dmd.conf makes DMD work correctly on hardened systems (tested on Ubuntu 16.10).

Binaries built this way are PIE and have Phobos linked dynamically. I didn't manage to find a configuration that allows me to statically link Phobos, with or without PIE.

--
November 30, 2016
https://issues.dlang.org/show_bug.cgi?id=5278

hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh@quickfur.ath.cx

--- Comment #34 from hsteoh@quickfur.ath.cx ---
The only way I've found that works with statically-linked Phobos is to compile druntime and phobos with PIC=1 so that libphobos.a is PIC, in addition to putting -fPIC in dmd.conf (but not -defaultlib=libphobos.so, since that causes phobos to be linked dynamically).  All other combinations seems to fail in one place or another.

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

Alternatively, it *may* be possible to get away with non-PIC libphobos.a if there's a way to coax dmd to invoke gcc (used as the linker) with -no-pie.  I tried -L-no-pie but that didn't seem to do the trick either.  Probably something else is needed to make it work.

--
June 09, 2017
https://issues.dlang.org/show_bug.cgi?id=5278
Issue 5278 depends on issue 7678, which changed state.

Issue 7678 Summary: Add -cflags switch for DMD that allows passing flags to GCC or ${CC} https://issues.dlang.org/show_bug.cgi?id=7678

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--
June 09, 2017
https://issues.dlang.org/show_bug.cgi?id=5278

Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #35 from Martin Nowak <code@dawg.eu> ---
Should work now that we ship phobos with PIC by default (at least on X64). Executables compiled with dmd's `-fPIC` do create PIEs.

--