What is going on with the ubuntu/debian debacle ?

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 25 14:52:18 PST 2016


On Wednesday, 23 November 2016 at 14:00:15 UTC, ZombineDev wrote:
> On Tuesday, 22 November 2016 at 21:19:13 UTC, H. S. Teoh wrote:
>> On Sat, Nov 19, 2016 at 11:03:05PM +0000, deadalnix via 
>> Digitalmars-d wrote:
>>> A lot of users are reporting errors on debian and ubuntu. .o 
>>> generated by dmd do not link and libphobos.a is unusable.
>>> 
>>> This is very bad and we should consider a hotfix. Is someone 
>>> on it ?
>>
>> FWIW, I'm using Debian/unstable and compiling 
>> dmd/druntime/phobos directly from git HEAD, and it seems to 
>> work fine.
>>
>> Does this problem only happen for the shipped .deb packages?
>>
>>
>> T
>
> I think it's not a problem for you, because your system's 
> linker probably adds fPIC by default when you're building 
> druntime and phobos. In contrast the binaries available on 
> dlang.org/download were probably built on machine that does not 
> add -fPIC by default.

Haha, I spoke too soon.  It appears that the reason I didn't see 
this problem was because I hadn't upgraded gcc in a while. After 
updating to the latest gcc-6.2 a couple of days ago, dmd now 
fails horribly with linker errors.  I couldn't even rebuild dmd 
because the bootstrapping dmd 2.069 that I'm using also doesn't 
have Phobos compiled with -fPIC, so it dies when trying to 
compile idgen.

Anyway, I needed things working again, so I did some further 
investigation. Here's what I found:

- Under the latest Debian/Ubuntu gcc-6.2, it's *still* possible 
to retain the old (working) behaviour by specifying -no-pie to 
all invocations of gcc.  (By "all invocations" I mean also 
internal calls to gcc from inside dmd.)  Using this workaround in 
a wrapper script specified in HOST_CXX to dmd's posix.mak, it's 
possible to bootstrap dmd successfully from an older dmd that 
doesn't have Phobos compiled with -fPIC.

- Druntime and Phobos' makefiles already support the PIC=1 
option, which will build libphobos2.a with -fPIC.  To get dmd 
working again, make sure you `make clean; make PIC=1` in druntime 
followed by phobos (in that order, since otherwise libphobos2.a 
may pick up old non-PIC objects from druntime and it will break).

- After this is done, libphobos2.a is now built with -fPIC, so it 
is now compatible with Debian/Ubuntu's PIE-by-default 
configuration.  However, there is one last thing: dmd itself will 
emit a dmd-personality-v0 symbol in the generated object file(s), 
which will fail to link with the new libphobos2.a because, by 
default, this symbol is not specified as PIC, so the linker 
considers it incompatible with the new libphobos2.a.  So now we 
need to append "-fPIC" to the settings in the system dmd.conf, 
wherever you installed it (in my case, it was in /etc/dmd.conf), 
otherwise you will have to manually type "-fPIC" every time you 
invoke dmd.

- I did some googling, and found references to compiling with 
`-fPIC -defaultlib=libphobos2.so` instead, i.e., if you don't 
want to recompile druntime/phobos with -fPIC yourself.  This also 
works, *provided* you install the Phobos .so's in your system's 
lib directories.  If you're running dmd off the git repos 
directly, like I am, this requires symlinking libphobos2.*.so 
into /usr/local/lib or /usr/lib, otherwise none of your D 
executables will run.  I consider this too intrusive, especially 
for the bleeding edge phobos off git HEAD, so I settled for 
building libphobos.a with -fPIC instead, as described above.

Hope this info will be helpful to anyone else who's experiencing 
this problem. It cost me almost 2-3 hours' worth of frustration. 
:-/


More information about the Digitalmars-d mailing list