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