Closed WebDrake closed 7 years ago
@klickverbot assuming I built zlib from source as part of the snap, what's the most convenient way to let the LDC build process know about that library for building phobos?
Phobos includes its own copy of zlib, so that shouldn't be it. Which platform is used for actually building the snaps? 16.04 by any chance? This might be another toolchain/ABI version issue.
Phobos includes its own copy of zlib, so that shouldn't be it.
I thought it needed a pre-existing zlib library to statically link when phobos is built? I was assuming that might be the trouble, since I'm just using the zlib1g-dev
package on Ubuntu.
I thought it needed a pre-existing zlib library to statically link when phobos is built?
There is a copy of zlib in etc/c/zlib. The error message is also from the static phobos library, not some external copy of zlib.
Ah, interesting. I was still going by the (probably very out of date) dependency indications here: https://wiki.dlang.org/Building_LDC_from_source#Prerequisites
I'll edit the snap package to remove the zlib1g-dev
build dependency and see if any change results -- probably not, but can't hurt as a first step.
I was still going by the (probably very out of date) dependency indications here
That's for LDC itself – LLVM (sometimes (?)) depends on zlib as well.
Ah, OK, thanks. Then I'll check things out again on the snapcraft side and see what comes up.
A quick online search turns up a few results that suggest that it is indeed a new relocation type added fairly recently, and binutils might not support it. Did you try the binary packages (which are actually built on 14.04)?
No; I'll give that a go and report back on how they behave.
Sorry for delayed response. The current LDC 1.1.1 download from GitHub works fine, which would support the hypothesis that it's a difference in binutils that is responsible: 14.04 uses binutils 2.24 whereas 16.04 uses 2.26.
@klickverbot the snapcraft folks have suggested passing the flags -Wa,-mrelax-relocations=no
to GCC when it builds zlib. Can you recommend the best way of achieving this? Is it possible just by adding some options when invoking cmake
or would it require some tweaks to the build process?
@WebDrake: We use the regular CMake functions for building C sources, so you can just do cmake -DCMAKE_C_FLAGS=…
(or whatever else is appropriate).
OK, cool. Are there any predefined ones that I should take care not to overwrite? Or will the existing scripts just add anything necessary to whatever I define?
All the flag handling should be additive. The only thing to watch out for would be distro-specific defaults (which I think you should be able to verify using ccmake .
on a default build (t
for advanced flags)).
There don't seem to be any C_FLAGS
defined, according to ccmake
. The weird thing is nothing shows up even if I set things up with cmake -DCMAKE_C_FLAGS="-Wa,-mrelax-relocations=no"
.
Still, might as well try things out with this and see where it goes ;-)
The weird thing is nothing shows up
Did you re-run CMake in a fresh directory?
Did you re-run CMake in a fresh directory?
Yup.
To follow up on here: I've run a snapcraft cleanbuild
with and without the -DCMAKE_C_FLAGS
option, using a verbose build. Here's the result without the flags defined:
[ 50%] Building C object runtime/CMakeFiles/druntime-ldc-debug.dir/druntime/src/core/stdc/errno.c.o
cd /root/parts/ldc/build/runtime && /usr/bin/cc -DLDC_WITH_PGO -I/root/parts/ldc/src/. -I/root/parts/ldc/src/ddmd -I/root/parts/ldc/src/ddmd/root -I/root/parts/ldc/build/ddmd -I/root/parts/ldc/src -isystem /root/parts/llvm/install/include -O3 -DNDEBUG -fPIC -o CMakeFiles/druntime-ldc-debug.dir/druntime/src/core/stdc/errno.c.o -c /root/parts/ldc/src/runtime/druntime/src/core/stdc/errno.c
and with:
[ 56%] Building C object runtime/CMakeFiles/druntime-ldc-debug.dir/druntime/src/core/stdc/errno.c.o
cd /root/parts/ldc/build/runtime && /usr/bin/cc -DLDC_WITH_PGO -I/root/parts/ldc/src/. -I/root/parts/ldc/src/ddmd -I/root/parts/ldc/src/ddmd/root -I/root/parts/ldc/build/ddmd -I/root/parts/ldc/src -I/root/parts/llvm/install/include "-Wa,-mrelax-relocations=no" -o CMakeFiles/druntime-ldc-debug.dir/druntime/src/core/stdc/errno.c.o -c /root/parts/ldc/src/runtime/druntime/src/core/stdc/errno.c
... i.e. for the 'regular' build the C flags are -O3 -DNDEBUG -fPIC
and for the build with this patch, it's "-Wa,-mrelax-relocations=no"
. This would explain why I'm getting the PIC-related errors on 16.10.
It should be straightforward enough to add the extra flags, but I'm wondering if there is a way to avoid this (given the earlier discussion about how C flags should be additive).
Doing a non-clean build (i.e. using the snapcraft
command alone) results in:
[ 49%] Building C object runtime/CMakeFiles/druntime-ldc-debug.dir/druntime/src/core/stdc/errno.c.o
cd /home/joseph/code/snap/ldc2.snap/parts/ldc/build/runtime && /usr/bin/cc -DLDC_WITH_PGO -I/home/joseph/code/snap/ldc2.snap/parts/ldc/src/. -I/home/joseph/code/snap/ldc2.snap/parts/ldc/src/ddmd -I/home/joseph/code/snap/ldc2.snap/parts/ldc/src/ddmd/root -I/home/joseph/code/snap/ldc2.snap/parts/ldc/build/ddmd -I/home/joseph/code/snap/ldc2.snap/parts/ldc/src -I/home/joseph/code/snap/ldc2.snap/parts/llvm/install/include "-Wa,-mrelax-relocations=no" -o CMakeFiles/druntime-ldc-debug.dir/druntime/src/core/stdc/errno.c.o -c /home/joseph/code/snap/ldc2.snap/parts/ldc/src/runtime/druntime/src/core/stdc/errno.c
... i.e. also missing the optimization flags. So I suspect the best way forward with this is to just put all the wanted C flags directly into the snap package definition.
Maybe it's just me misunderstanding how CMAKE_C_FLAGS works and somehow not noticing in a couple of years. It would be good to track down where exactly the flags are overwritten (e.g. by having a look at the CMake cache, directly or using ccmake).
A simple test program using zlib:
Compiling this on 14.04 fails at the link stage with the following message:
The same issue is not observed on 16.04 or 16.10.