[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] Re: [PATCH] tools: do not link against unused libraries



This follows on from my "tools: build system fix indirect library usage
and --as-needed" series from yesterday.

I figure this sort of thing is inevitably going to cause fallout on
various system so it's probably better to get it into 4.2 as early in
the cycle as possible to give plenty of time to squish the warts.

Ian.

On Wed, 2011-03-16 at 10:38 +0000, Ian Campbell wrote:
> # HG changeset patch
> # User Ian Campbell <ian.campbell@xxxxxxxxxx>
> # Date 1300271932 0
> # Node ID 7e326d27d899a3133479c8b7c983f660cdeda48c
> # Parent  f35234b6636a0410a7d5eaa409e98ebe59080e4f
> tools: do not link against unused libraries.
> 
> A fair few things under tools link against libraries which they don't
> even use.
> 
> Most of this appears to come from copy-and-pasting previous Makefile
> snippets and cargo-culting plus the tendency to define global $(LIBS)
> even for Makefiles which build multiple separate utilities or
> libraries.
> 
> Identified by comparing a build with --as-needed to one without by
> looking at the NEEDED header of all ELF objects.
> 
> Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
> 
> diff -r f35234b6636a -r 7e326d27d899 tools/blktap2/drivers/Makefile
> --- a/tools/blktap2/drivers/Makefile  Tue Mar 15 16:33:59 2011 +0000
> +++ b/tools/blktap2/drivers/Makefile  Wed Mar 16 10:38:52 2011 +0000
> @@ -23,11 +23,7 @@ CFLAGS            += -fPIC
>  CFLAGS            += -fPIC
>  endif
>  
> -LIBS      += -lrt -lz
> -
> -LBLIBS_img := $(LDLIBS_libxenctrl) $(CRYPT_LIB) -lpthread -lz -lm
> -
> -LIBS += -L$(LIBVHDDIR) -lvhd
> +VHDLIBS    := -L$(LIBVHDDIR) -lvhd
>  
>  REMUS-OBJS  := block-remus.o
>  REMUS-OBJS  += hashtable.o
> @@ -88,26 +84,26 @@ all: $(IBIN) lock-util qcow-util
>  all: $(IBIN) lock-util qcow-util
>  
> 
> -tapdisk2: $(TAP-OBJS-y) $(BLK-OBJS-y) $(MISC-OBJS-y) tapdisk2.c
> -     $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) $(AIOLIBS) $(MEMSHRLIBS) 
> $(LBLIBS_img)
> +tapdisk2: $(TAP-OBJS-y) $(BLK-OBJS-y) $(MISC-OBJS-y) tapdisk2.o
> +     $(CC) -o $@ $^ $(LDFLAGS) -lrt -lz $(VHDLIBS) $(AIOLIBS) $(MEMSHRLIBS) 
> -lm 
>  
>  tapdisk-client: tapdisk-client.o
> -     $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)  $(LBLIBS_img)
> +     $(CC) -o $@ $^ $(LDFLAGS) -lrt
>  
>  tapdisk-stream tapdisk-diff: %: %.o $(TAP-OBJS-y) $(BLK-OBJS-y)
> -     $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) $(AIOLIBS) $(MEMSHRLIBS) 
> $(LBLIBS_img)
> +     $(CC) -o $@ $^ $(LDFLAGS) -lrt -lz $(VHDLIBS) $(AIOLIBS) $(MEMSHRLIBS) 
> -lm
>  
>  td-util: td.o tapdisk-utils.o tapdisk-log.o $(PORTABLE-OBJS-y)
> -     $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)  $(LBLIBS_img)
> +     $(CC) -o $@ $^ $(LDFLAGS) $(VHDLIBS)
>  
>  lock-util: lock.c
> -     $(CC) $(CFLAGS) -DUTIL -o lock-util lock.c $(LDFLAGS) $(LIBS)
> +     $(CC) $(CFLAGS) -DUTIL -o lock-util lock.c $(LDFLAGS)
>  
>  .PHONY: qcow-util
>  qcow-util: img2qcow qcow2raw qcow-create
>  
>  img2qcow qcow2raw qcow-create: %: %.o $(TAP-OBJS-y) $(BLK-OBJS-y)
> -     $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) $(AIOLIBS) $(MEMSHRLIBS) 
> $(LBLIBS_img)
> +     $(CC) -o $@ $^ $(LDFLAGS) -lrt -lz $(VHDLIBS) $(AIOLIBS) $(MEMSHRLIBS) 
> -lm
>  
>  install: all
>       $(INSTALL_DIR) -p $(DESTDIR)$(INST_DIR)
> diff -r f35234b6636a -r 7e326d27d899 tools/console/Makefile
> --- a/tools/console/Makefile  Tue Mar 15 16:33:59 2011 +0000
> +++ b/tools/console/Makefile  Wed Mar 16 10:38:52 2011 +0000
> @@ -1,4 +1,3 @@
> -
>  XEN_ROOT=../..
>  include $(XEN_ROOT)/tools/Rules.mk
>  
> @@ -8,9 +7,10 @@ CFLAGS  += $(CFLAGS_libxenstore)
>  CFLAGS  += $(CFLAGS_libxenstore)
>  LDLIBS += $(LDLIBS_libxenctrl)
>  LDLIBS += $(LDLIBS_libxenstore)
> -LDLIBS += $(UTIL_LIBS)
>  LDLIBS += $(SOCKET_LIBS)
> -LDLIBS += -lrt
> +
> +LDLIBS_xenconsoled += $(UTIL_LIBS)
> +LDLIBS_xenconsoled += -lrt
>  
>  BIN      = xenconsoled xenconsole
>  
> @@ -23,10 +23,10 @@ clean:
>       $(RM) client/*.o daemon/*.o
>  
>  xenconsoled: $(patsubst %.c,%.o,$(wildcard daemon/*.c))
> -     $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(LDLIBS)
> +     $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(LDLIBS) $(LDLIBS_xenconsoled)
>  
>  xenconsole: $(patsubst %.c,%.o,$(wildcard client/*.c))
> -     $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(LDLIBS)
> +     $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(LDLIBS) $(LDLIBS_xenconsole)
>  
>  .PHONY: install
>  install: $(BIN)
> diff -r f35234b6636a -r 7e326d27d899 tools/misc/Makefile
> --- a/tools/misc/Makefile     Tue Mar 15 16:33:59 2011 +0000
> +++ b/tools/misc/Makefile     Wed Mar 16 10:38:52 2011 +0000
> @@ -14,6 +14,14 @@ TARGETS-$(CONFIG_X86) += xen-detect xen-
>  TARGETS-$(CONFIG_X86) += xen-detect xen-hvmctx xen-hvmcrash
>  TARGETS-$(CONFIG_MIGRATE) += xen-hptool
>  TARGETS := $(TARGETS-y)
> +
> +LDLIBS_xenperf      := $(LDLIBS_libxenctrl)
> +LDLIBS_xenpm        := $(LDLIBS_libxenctrl)
> +LDLIBS_xenlockprof  := $(LDLIBS_libxenctrl)
> +LDLIBS_xenwatchdogd := $(LDLIBS_libxenctrl)
> +LDLIBS_xen-hvmctx   := $(LDLIBS_libxenctrl)
> +LDLIBS_xen-hvmcrash := $(LDLIBS_libxenctrl)
> +LDLIBS_xen-hptool   := $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) 
> $(LDLIBS_libxenstore)
>  
>  SUBDIRS-$(CONFIG_LOMOUNT) += lomount
>  SUBDIRS-$(CONFIG_MINITERM) += miniterm
> @@ -52,7 +60,7 @@ clean:
>       $(CC) -c $(CFLAGS) -o $@ $<
>  
>  xen-hvmctx xen-hvmcrash xenperf xenpm gtracestat xenlockprof xen-hptool 
> xenwatchdogd: %: %.o Makefile
> -     $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LDLIBS_libxenctrl) 
> $(LDLIBS_libxenguest) $(LDLIBS_libxenstore)
> +     $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LDLIBS_$*)
>  
>  gtraceview: %: %.o Makefile
>       $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(CURSES_LIBS)
> diff -r f35234b6636a -r 7e326d27d899 tools/xcutils/Makefile
> --- a/tools/xcutils/Makefile  Tue Mar 15 16:33:59 2011 +0000
> +++ b/tools/xcutils/Makefile  Wed Mar 16 10:38:52 2011 +0000
> @@ -11,12 +11,20 @@ XEN_ROOT  = ../..
>  XEN_ROOT     = ../..
>  include $(XEN_ROOT)/tools/Rules.mk
>  
> -CFLAGS += -Werror
> -CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore)
>  
>  PROGRAMS = xc_restore xc_save readnotes lsevtchn
>  
> -LDLIBS   = $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore)
> +CFLAGS += -Werror
> +
> +CFLAGS_xc_restore := $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest)
> +CFLAGS_xc_save    := $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) 
> $(CFLAGS_libxenstore)
> +CFLAGS_readnotes  := $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest)
> +CFLAGS_lsevtchn   := $(CFLAGS_libxenctrl)
> +
> +LDLIBS_xc_restore := $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest)
> +LDLIBS_xc_save    := $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) 
> $(LDLIBS_libxenstore)
> +LDLIBS_readnotes  := $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest)
> +LDLIBS_lsevtchn   := $(LDLIBS_libxenctrl)
>  
>  .PHONY: all
>  all: build
> @@ -24,8 +32,11 @@ all: build
>  .PHONY: build
>  build: $(PROGRAMS)
>  
> +%.o: %.c
> +     $(CC) $(CFLAGS) $(CFLAGS_$*) -c $^ -o $@
> +
>  $(PROGRAMS): %: %.o
> -     $(CC) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
> +     $(CC) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) $(LDLIBS_$*) -o $@
>  
>  .PHONY: install
>  install: build
> diff -r f35234b6636a -r 7e326d27d899 tools/xcutils/lsevtchn.c
> --- a/tools/xcutils/lsevtchn.c        Tue Mar 15 16:33:59 2011 +0000
> +++ b/tools/xcutils/lsevtchn.c        Wed Mar 16 10:38:52 2011 +0000
> @@ -4,9 +4,7 @@
>  #include <string.h>
>  #include <stdio.h>
>  
> -#include <xs.h>
>  #include <xenctrl.h>
> -#include <xenguest.h>
>  
>  int main(int argc, char **argv)
>  {



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.