QEMU fails to build on CentOS 5.10 with --disable-pie reporting "/usr/bin/ld: -f may not be used without -shared "

Bug #1258168 reported by Don Slutz
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
QEMU
Invalid
Undecided
Unassigned

Bug Description

fails for (7dc65c0 (HEAD, origin/master, origin/HEAD, master) Open 2.0 development tree):

...
libtool --mode=link --tag=CC cc -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -Wendif-labels -Wmissing-include-dirs -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wold-style-definition -fstack-protector-all -I/usr/include/libpng12 -I/usr/include/nss3 -I/usr/include/nspr4 -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/home/don/qemu/dtc/libfdt -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/home/don/qemu/tests -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -g -Wl,--warn-common -m64 -g -o vscclient libcacard/vscclient.o libcacard.la -Wc,-fstack-protector-all -lrt -pthread -L/lib64 -lgthread-2.0 -lglib-2.0 -lz -L/usr/kerberos/lib64 -lcurl -ldl -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lidn -lssl -lcrypto -lz -luuid
cc -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -Wendif-labels -Wmissing-include-dirs -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wold-style-definition -fstack-protector-all -I/usr/include/libpng12 -I/usr/include/nss3 -I/usr/include/nspr4 -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/home/don/qemu/dtc/libfdt -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/home/don/qemu/tests -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -g -Wl,--warn-common -m64 -g -o .libs/vscclient libcacard/vscclient.o -Wl,-fstack-protector-all -pthread ./.libs/libcacard.so -L/lib64 -L/usr/kerberos/lib64 -lssl3 -lsmime3 -lnss3 -lnssutil3 -lplds4 -lplc4 -lnspr4 -lpthread -lrt -lgthread-2.0 -lglib-2.0 -lcurl -ldl -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lidn -lssl -lcrypto -lz -luuid -Wl,--rpath -Wl,/usr/local/lib
/usr/bin/ld: -f may not be used without -shared
collect2: ld returned 1 exit status
make: *** [vscclient] Error 1

rm -rf out/tmp;mkdir out/tmp;pushd out/tmp;../../configure --disable-pie;make V=1 1>zz1 2>&1;popd
~/qemu/out/tmp ~/qemu
Install prefix /usr/local
BIOS directory /usr/local/share/qemu
binary directory /usr/local/bin
library directory /usr/local/lib
libexec directory /usr/local/libexec
include directory /usr/local/include
config directory /usr/local/etc
local state directory /usr/local/var
Manual directory /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path /home/don/qemu
C compiler cc
Host C compiler cc
C++ compiler c++
Objective-C compiler cc
ARFLAGS rv
CFLAGS -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -g
QEMU_CFLAGS -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -Wendif-labels -Wmissing-include-dirs -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wold-style-definition -fstack-protector-all -I/usr/include/libpng12 -I/usr/include/nss3 -I/usr/include/nspr4 -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I$(SRC_PATH)/dtc/libfdt
LDFLAGS -Wl,--warn-common -m64 -g
make make
install install
python python
smbd /usr/sbin/smbd
host CPU x86_64
host big endian no
target list alpha-softmmu arm-softmmu cris-softmmu i386-softmmu lm32-softmmu m68k-softmmu microblaze-softmmu microblazeel-softmmu mips-softmmu mips64-softmmu mips64el-softmmu mipsel-softmmu moxie-softmmu or32-softmmu ppc-softmmu ppc64-softmmu ppcemb-softmmu s390x-softmmu sh4-softmmu sh4eb-softmmu sparc-softmmu sparc64-softmmu unicore32-softmmu x86_64-softmmu xtensa-softmmu xtensaeb-softmmu alpha-linux-user arm-linux-user armeb-linux-user cris-linux-user i386-linux-user m68k-linux-user microblaze-linux-user microblazeel-linux-user mips-linux-user mips64-linux-user mips64el-linux-user mipsel-linux-user mipsn32-linux-user mipsn32el-linux-user or32-linux-user ppc-linux-user ppc64-linux-user ppc64abi32-linux-user s390x-linux-user sh4-linux-user sh4eb-linux-user sparc-linux-user sparc32plus-linux-user sparc64-linux-user unicore32-linux-user x86_64-linux-user
tcg debug enabled no
gprof enabled no
sparse enabled no
strip binaries yes
profiler no
static build no
-Werror enabled no
pixman system
SDL support yes
GTK support no
curses support yes
curl support yes
mingw32 support no
Audio drivers oss
Block whitelist (rw)
Block whitelist (ro)
VirtFS support yes
VNC support yes
VNC TLS support no
VNC SASL support yes
VNC JPEG support yes
VNC PNG support yes
VNC WS support no
xen support yes
brlapi support no
bluez support no
Documentation yes
GUEST_BASE yes
PIE no
vde support no
Linux AIO support no
ATTR/XATTR support yes
Install blobs yes
KVM support yes
RDMA support no
TCG interpreter no
fdt support yes
preadv support no
fdatasync yes
madvise yes
posix_madvise yes
sigev_thread_id yes
uuid support yes
libcap-ng support no
vhost-net support yes
vhost-scsi support yes
Trace backend nop
Trace output file trace-<pid>
spice support no (/)
rbd support no
xfsctl support no
nss used yes
libusb no
usb net redir no
GLX support yes
libiscsi support no
build guest agent yes
QGA VSS support no
seccomp support no
coroutine backend ucontext
coroutine pool yes
GlusterFS support no
virtio-blk-data-plane no
gcov gcov
gcov enabled no
TPM support no
libssh2 support no
TPM passthrough no
QOM debugging yes
vhdx yes

I bisect'd this to:

dcs-xen-53:~/qemu>git-bisect good
37746c5eacf309fa019ea0fa45f776c36c561457 is the first bad commit
commit 37746c5eacf309fa019ea0fa45f776c36c561457
Author: Marc-André Lureau <email address hidden>
Date: Mon Feb 25 23:31:12 2013 +0100

    build-sys: must link with -fstack-protector

    It is needed to give that flag to the linker as well, but latest
    libtool 2.4.2 still swallows that argument, so let's pass it with
    libtool -Wc argument.

    qemu-1.4.0/stubs/arch-query-cpu-def.c:6: undefined reference to `__stack_chk_guard'

    Signed-off-by: Marc-André Lureau <email address hidden>
    Reviewed-by: Alon Levy <email address hidden>

:100755 100755 33d3354ea30838694020660f5822f551293d7e9a ee2e7e8ad9b8a23af96e4e404e3f7658efcbe74b M configure
:100644 100644 edc2552f0886c99608b97f85bd932460fa50da73 36aba2de1fa9e0f8acde7640818e94a28dd03c80 M rules.mak

Revision history for this message
Don Slutz (dslutz) wrote :

Using the hack:

git diff
diff --git a/configure b/configure
index 0666228..cf8123b 100755
--- a/configure
+++ b/configure
@@ -1292,7 +1292,9 @@ done

 if compile_prog "-Werror -fstack-protector-all" "" ; then
     QEMU_CFLAGS="$QEMU_CFLAGS -fstack-protector-all"
- LIBTOOLFLAGS="$LIBTOOLFLAGS -Wc,-fstack-protector-all"
+ if test "$pie" != "no" ; then
+ LIBTOOLFLAGS="$LIBTOOLFLAGS -Wc,-fstack-protector-all"
+ fi
 fi

 # Workaround for http://gcc.gnu.org/PR55489. Happens with -fPIE/-fPIC and

I now get:

/home/don/qemu/libcacard/vscclient.c: In function 'do_socket_read':
/home/don/qemu/libcacard/vscclient.c:410: warning: implicit declaration of function 'g_warn_if_reached'
/home/don/qemu/libcacard/vscclient.c:410: warning: nested extern declaration of 'g_warn_if_reached'
/home/don/qemu/libcacard/vscclient.c: In function 'main':
/home/don/qemu/libcacard/vscclient.c:763: warning: implicit declaration of function 'g_byte_array_unref'
/home/don/qemu/libcacard/vscclient.c:763: warning: nested extern declaration of 'g_byte_array_unref'
...
libcacard/vscclient.o: In function `do_socket_read':
/home/don/qemu/libcacard/vscclient.c:410: undefined reference to `g_warn_if_reached'
libcacard/vscclient.o: In function `main':
/home/don/qemu/libcacard/vscclient.c:763: undefined reference to `g_byte_array_unref'
collect2: ld returned 1 exit status
make: *** [vscclient] Error 1

Revision history for this message
Don Slutz (dslutz) wrote :

This is the same as listed in:

https://lists.gnu.org/archive/html/qemu-devel/2013-05/msg01667.html

rpm -q glib2
glib2-2.12.3-4.el5_3.1
glib2-2.12.3-4.el5_3.1

Using:
http://pidgin.im/pipermail/commits/2011-February/018919.html

I came up with:

diff --git a/libcacard/vscclient.c b/libcacard/vscclient.c
index a3cb776..5c9cec8 100644
--- a/libcacard/vscclient.c
+++ b/libcacard/vscclient.c
@@ -407,7 +407,13 @@ do_socket_read(GIOChannel *source,
             }
             break;
         default:
+#if GLIB_CHECK_VERSION(2, 16 ,0)
             g_warn_if_reached();
+#else
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+ "(%s:%d):%s%s code should not be reached",
+ __FILE__, __LINE__, G_STRFUNC, G_STRFUNC[0] ? ":" : "");
+#endif
             return FALSE;
         }

@@ -760,7 +766,11 @@ main(

     g_io_channel_unref(channel_stdin);
     g_io_channel_unref(channel_socket);
+#if GLIB_CHECK_VERSION(2, 22, 0)
     g_byte_array_unref(socket_to_send);
+#else
+ g_byte_array_free(socket_to_send, TRUE);
+#endif

     closesocket(sock);
     return 0;

And I get a clean compile.

Revision history for this message
Robin Lee (cheeselee) wrote :

We met the same problem when compiling qemu 2.0.0 on CentOS6, and fixed it with a similar patch to the configure script.

Revision history for this message
Paolo Bonzini (bonzini) wrote :

Can you please test this patch?

Revision history for this message
Don Slutz (dslutz) wrote :

My testing of this patch is that it does not help.

  LINK qemu-bridge-helper
  CC qmp-marshal.o
lt LINK vscclient
/usr/bin/ld: -f may not be used without -shared
collect2: ld returned 1 exit status
make: *** [vscclient] Error 1
make: *** Waiting for unfinished jobs....
dcs-xen-53:~/qemu/out/bug-1258168>git show
commit cceddd04255cdacacf91562d43fdb7afcec91242
Author: Paolo Bonzini <email address hidden>
Date: Thu Nov 13 16:34:16 2014 +0000

    configure: test patch for 1258168

diff --git a/configure b/configure
index 47048f0..b7bf30a 100755
--- a/configure
+++ b/configure
@@ -140,8 +140,10 @@ do_libtool() {
 }

 libtool_prog() {
- do_libtool --mode=compile $QEMU_CFLAGS -c -fPIE -DPIE -o $TMPO $TMPC || return $?
- do_libtool --mode=link $LDFLAGS -o $TMPA $TMPL -rpath /usr/local/lib
+ local_cflags="$1"
+ local_ldflags="$2"
+ do_libtool --mode=compile $QEMU_CFLAGS $local_cflags -c -fPIE -DPIE -o $TMPO $TMPC || return $?
+ do_libtool --mode=link $LDFLAGS $local_ldflags -o $TMPA $TMPL -rpath /usr/local/lib
 }

 # symbolically link $1 to $2. Portable version of "ln -sf".
@@ -1501,13 +1503,16 @@ if test "$stack_protector" != "no"; then
   for flag in $gcc_flags; do
     # We need to check both a compile and a link, since some compiler
     # setups fail only on a .c->.o compile and some only at link time
- if do_cc $QEMU_CFLAGS -Werror $flag -c -o $TMPO $TMPC &&
- compile_prog "-Werror $flag" ""; then
- QEMU_CFLAGS="$QEMU_CFLAGS $flag"
- LIBTOOLFLAGS="$LIBTOOLFLAGS -Wc,$flag"
- sp_on=1
- break
+ do_cc $QEMU_CFLAGS -Werror $flag -c -o $TMPO $TMPC || continue
+ compile_prog "-Werror $flag" "" || continue
+ if test -n "$libtool"; then
+ libtool_prog "-Werror $flag" "-Wc,$flag" || continue
     fi
+
+ QEMU_CFLAGS="$QEMU_CFLAGS $flag"
+ LIBTOOLFLAGS="$LIBTOOLFLAGS -Wc,$flag"
+ sp_on=1
+ break
   done
   if test "$stack_protector" = yes; then
     if test $sp_on = 0; then
@@ -1608,7 +1613,7 @@ g(unsigned char *buf, int len)
 }

 EOF
- if ! libtool_prog; then
+ if ! libtool_prog "" ""; then
     echo "Disabling libtool due to broken toolchain support"
     libtool=
   fi
dcs-xen-53:~/qemu/out/bug-1258168>git log -2
commit cceddd04255cdacacf91562d43fdb7afcec91242
Author: Paolo Bonzini <email address hidden>
Date: Thu Nov 13 16:34:16 2014 +0000

    configure: test patch for 1258168

commit b56cb288954d900dec79cc55128efa61bebf6178
Merge: e08d300 953ea14
Author: Peter Maydell <email address hidden>
Date: Thu Nov 13 13:02:31 2014 +0000

    Merge remote-tracking branch 'remotes/kraxel/tags/pull-seabios-1.7.5.1-20141113-1' into staging

    update seabios to 1.7.5.1 stable release

    # gpg: Signature made Thu 13 Nov 2014 11:03:05 GMT using RSA key ID D3E87138
    # gpg: Good signature from "Gerd Hoffmann (work) <email address hidden>"
    # gpg: aka "Gerd Hoffmann <email address hidden>"
    # gpg: aka "Gerd Hoffmann (private) <email address hidden>"

    * remotes/kraxel/tags/pull-seabios-1.7.5.1-20141113-1:
      update seabios to 1.7.5.1 stable release

    Signed-off-by: Peter Maydell <email address hidden>

Revision history for this message
Thomas Huth (th-huth) wrote :

libcacard has been removed from the QEMU sources and is an external project now, so this problem should not exist anymore with the latest version of QEMU. If it still persists, please feel free to re-open this ticket.

Changed in qemu:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.