https://issues.dlang.org/show_bug.cgi?id=16794
--- Comment #7 from [email protected] --- As for building libphobos.a with -fPIC, it's definitely possible, as I described. At least, I managed to get it to work on my system. I'm not sure what is causing problems on your system that makes this impossible. To recap, what I did to make it work is: (1) Bootstrap dmd from an older non-PIE dmd installation: a) create a wrapper script for gcc/g++ (say, g++wrapper) that invokes it with -no-pie. b) run make in the dmd subdir with HOST_CXX set to this wrapper, and HOST_DMD set to your bootstrapping compiler. Make sure the bootstrapping compiler's dmd.conf (preferably dedicated for bootstrapping) that has the right paths to its corresponding version of druntime/phobos (which, presumably, are from a non-PIE release). c) if you're having trouble bootstrapping dmd in spite of this, you may want to check if gcc-specific flags like -Wnarrowing are being passed to gcc when compiling dmd modules. If not, you may need to add a hack to g++wrapper that echoes "g++" when the command-line contains "-version". This is a hack to workaround posix.mak bogonity that tries to parse the output of `cc -version` for identifying signs of gcc, but fails horribly with certain versions of Debian's gcc distribution. (2) (Re)build druntime/phobos with the new compiler, with PIC=1 passed to the makefile to force libphobos.a to be built with -fPIC. (3) Edit dmd.conf (of the bootstrapped compiler) and add -fPIC to the default flags. (4) (optionally) install dmd/libphobos in your system directories. The new compiler should now be able to successfully compile and link PIE executables that are statically linked to libphobos.a. Note that libphobos.a built this way will be PIC, and may not be linkable to non-PIE executables anymore. --
