<div dir="ltr"><div><div><div><div><div>Ok, it seems I isolated the problem.<br></div>The linking error shows up only on FreeBSD with gcc toolchain installed, because it does not support pie. With clang everything is fine.<br>
</div><br>There is an issue with detection mechanism. Currently, it is done in configure script with:<br>    gcc -std=gnu99 -o conftest -g -O2 -x c -fPIE -DPIE -D_THREAD_SAFE conftest.c -lintl<br></div>It succeeds, so the scripts enables PIE. However, all further binaries are built with additional "-pie" flag.<br>
   /bin/sh ../libtool  --tag=CC   --mode=link gcc -std=gnu99 <some_stuff...>   -fPIE -DPIE  -g <other_stuff...> -pie   -o libvirt_iohelper util/libvirt_iohelper-iohelper.o <a href="http://libvirt_util.la">libvirt_util.la</a> ../gnulib/lib/<a href="http://libgnu.la">libgnu.la</a>  -lintl <br>
</div>This one fails with <br>/usr/local/bin/ld: /usr/lib/crt1.o: relocation R_X86_64_32 against `_DYNAMIC' can not be used when making a shared object; recompile with -fPIC<br>/usr/lib/crt1.o: error adding symbols: Bad value<br>
collect2: ld returned 1 exit status<br><br></div>If I modify configuration line to<br><div>   gcc -std=gnu99 -o conftest -g -O2 -x c -fPIE -DPIE -pie -D_THREAD_SAFE conftest.c -lintl<br><br></div><div>then it correctly detects lack of pie and build succeeds.<br>
<br>configure:61033: checking whether C compiler handles -fPIE -DPIE<br>configure:61052: gcc -std=gnu99 -o conftest -g -O2  -pie -fPIE -DPIE  -D_THREAD_SAFE  conftest.c -lintl  >&5<br>/usr/local/bin/ld: /usr/lib/crt1.o: relocation R_X86_64_32 against `_DYNAMIC' can not be used when making a shared object; recompile with -fPIC<br>
/usr/lib/crt1.o: error adding symbols: Bad value<br>collect2: ld returned 1 exit status<br>configure:61052: $? = 1<br><br><br><br></div><div>Do you think it would be reasonable to add "-pie" to configure script?<br>
<br></div><div>Regards,<br>Wojtek<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-03-20 15:51 GMT+01:00 Daniel P. Berrange <span dir="ltr"><<a href="mailto:berrange@redhat.com" target="_blank">berrange@redhat.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Thu, Mar 20, 2014 at 09:39:20AM +0100, Wojciech Macek wrote:<br>
> Add possibility to choose whether the code is compiled with PIE<br>
> or without. New configuration flags:<br>
> --enable-pie (default)<br>
> --disable-pie<br>
> ---<br>
>  <a href="http://configure.ac" target="_blank">configure.ac</a> | 14 +++++++++++++-<br>
>  1 file changed, 13 insertions(+), 1 deletion(-)<br>
><br>
> diff --git a/<a href="http://configure.ac" target="_blank">configure.ac</a> b/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
> index 62b74c5..96a7038 100644<br>
> --- a/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
> +++ b/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
> @@ -215,7 +215,6 @@ fi<br>
>  # Check for compiler and library settings.<br>
><br>
>  LIBVIRT_COMPILE_WARNINGS<br>
> -LIBVIRT_COMPILE_PIE<br>
>  LIBVIRT_LINKER_RELRO<br>
>  LIBVIRT_LINKER_NO_INDIRECT<br>
><br>
> @@ -581,7 +580,20 @@ if test x"$enable_debug" = x"yes"; then<br>
>     AC_DEFINE([ENABLE_DEBUG], [], [whether debugging is enabled])<br>
>  fi<br>
><br>
> +dnl --enable-pie=(yes|no)<br>
> +AC_ARG_ENABLE([pie],<br>
> +              [AS_HELP_STRING([--enable-pie=@<:@no|yes@:>@],<br>
> +                             [enable Position-Independent-Executables @<:@default=yes@:>@])],<br>
> +  [],[enable_pie=yes])<br>
> +AM_CONDITIONAL([ENABLE_PIE], test x"$enable_pie" = x"yes")<br>
> +if test x"$enable_debug" = x"yes"; then<br>
> +   AC_DEFINE([ENABLE_PIE], [], [whether Position-Independent-Executables are enabled])<br>
> +fi<br>
><br>
> +# Check if Position-Independent-Executables should be supported<br>
> +if test "$enable_pie" = "yes" ; then<br>
> +LIBVIRT_COMPILE_PIE<br>
> +fi<br>
<br>
</div></div>IMHO the rationale behind this is pretty dubious. Can you elaborate<br>
on exactly what errors you're getting with PIE builds, since presumably<br>
they're working find for FreeBSD devs in general. If there are problems<br>
that can't be avoided, then adding a configure flag is still the wrong<br>
way to deal with them. We already probe to see if PIE mode works, so<br>
if that's not detecting a problem we must improve that detection.<br>
<br>
<br>
Regards,<br>
Daniel<br>
<span class="HOEnZb"><font color="#888888">--<br>
|: <a href="http://berrange.com" target="_blank">http://berrange.com</a>      -o-    <a href="http://www.flickr.com/photos/dberrange/" target="_blank">http://www.flickr.com/photos/dberrange/</a> :|<br>
|: <a href="http://libvirt.org" target="_blank">http://libvirt.org</a>              -o-             <a href="http://virt-manager.org" target="_blank">http://virt-manager.org</a> :|<br>
|: <a href="http://autobuild.org" target="_blank">http://autobuild.org</a>       -o-         <a href="http://search.cpan.org/~danberr/" target="_blank">http://search.cpan.org/~danberr/</a> :|<br>
|: <a href="http://entangle-photo.org" target="_blank">http://entangle-photo.org</a>       -o-       <a href="http://live.gnome.org/gtk-vnc" target="_blank">http://live.gnome.org/gtk-vnc</a> :|<br>
</font></span></blockquote></div><br></div>