Olaf Hering
2010-Jul-23 12:11 UTC
[Xen-devel] [PATCH] correct order of linker options to avoid link errors with recent toolchains
The order of objects and linked libraries is important with recent toolchain when --as-needed is used. Move LDFLAGS to the end of cc commandline options. Without this change, symbols in libbzip2 are not found when building with openSuSE 11.2 and newer. Signed-off-by: Olaf Hering <olaf@aepfle.de> --- There are more places like this. I will find and fix them when required. tools/libxc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- xen-unstable.hg-4.1.21836.orig/tools/libxc/Makefile +++ xen-unstable.hg-4.1.21836/tools/libxc/Makefile @@ -181,7 +181,7 @@ xc_dom_bzimageloader.opic: CFLAGS += $(c libxenguest.so.$(MAJOR).$(MINOR): LDFLAGS += $(call zlib-options,l) libxenguest.so.$(MAJOR).$(MINOR): $(GUEST_PIC_OBJS) libxenctrl.so - $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $(GUEST_PIC_OBJS) -lz -lxenctrl $(PTHREAD_LIBS) + $(CC) $(CFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $(GUEST_PIC_OBJS) $(LDFLAGS) -lz -lxenctrl $(PTHREAD_LIBS) -include $(DEPS) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Jackson
2010-Jul-23 16:44 UTC
Re: [Xen-devel] [PATCH] correct order of linker options to avoid link errors with recent toolchains
Olaf Hering writes ("[Xen-devel] [PATCH] correct order of linker options to avoid link errors with recent toolchains"):> The order of objects and linked libraries is important with recent toolchain > when --as-needed is used. Move LDFLAGS to the end of cc commandline options. > Without this change, symbols in libbzip2 are not found when building with openSuSE 11.2 and newer.Thanks, but: I infer that libbzip2 is in LDFLAGS (as -lbzip2, I guess). Is that right ? But I think that libraries should be in *_LIBS, not LDFLAGS. LDFLAGS needs to stay at the beginning so that it can work if you set it to -static or something.> libxenguest.so.$(MAJOR).$(MINOR): LDFLAGS += $(call zlib-options,l)What is this program "zlib-options" ? I don''t have it on my system. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2010-Jul-23 16:53 UTC
Re: [Xen-devel] [PATCH] correct order of linker options to avoid link errors with recent toolchains
On 23/07/2010 17:44, "Ian Jackson" <Ian.Jackson@eu.citrix.com> wrote:> Olaf Hering writes ("[Xen-devel] [PATCH] correct order of linker options to > avoid link errors with recent toolchains"): >> The order of objects and linked libraries is important with recent toolchain >> when --as-needed is used. Move LDFLAGS to the end of cc commandline options. >> Without this change, symbols in libbzip2 are not found when building with >> openSuSE 11.2 and newer. > > Thanks, but: > > I infer that libbzip2 is in LDFLAGS (as -lbzip2, I guess). Is that > right ? But I think that libraries should be in *_LIBS, not LDFLAGS. > LDFLAGS needs to stay at the beginning so that it can work if you set > it to -static or something. > >> libxenguest.so.$(MAJOR).$(MINOR): LDFLAGS += $(call zlib-options,l) > > What is this program "zlib-options" ? I don''t have it on my system.It''s right there in the same Makefile directly above the line you quoted. Yes, the above line can add -l<lib> items to LDFLAGS. Sounds like the right fix would indeed be to define a new COMPRESSION_LIBS variable and put it at the end of the linker command line. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Jackson
2010-Jul-23 16:57 UTC
Re: [Xen-devel] [PATCH] correct order of linker options to avoid link errors with recent toolchains
Keir Fraser writes ("Re: [Xen-devel] [PATCH] correct order of linker options to avoid link errors with recent toolchains"):> On 23/07/2010 17:44, "Ian Jackson" <Ian.Jackson@eu.citrix.com> wrote: > >> libxenguest.so.$(MAJOR).$(MINOR): LDFLAGS += $(call zlib-options,l) > > > > What is this program "zlib-options" ? I don''t have it on my system. > > It''s right there in the same Makefile directly above the line you quoted. > Yes, the above line can add -l<lib> items to LDFLAGS.Oh, duh. I''m confusing $(call ...) with $(shell ...) so I looked in entirely the wrong place.> Sounds like the right fix would indeed be to define a new > COMPRESSION_LIBS variable and put it at the end of the linker > command line.Yes. Olaf, would you like to provide a patch to do that ? Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Olaf Hering
2010-Jul-23 19:55 UTC
[Xen-devel] [PATCH] correct order of linker options to avoid link errors with recent toolchains
The order of objects and linked libraries is important with recent toolchain when --as-needed is used. Introduce new variable COMPRESSION_LIBS and place it at the end of cc commandline options. Without this change, symbols in libbzip2 are not found when building with openSuSE 11.2 and newer. Signed-off-by: Olaf Hering <olaf@aepfle.de> --- v2: use COMPRESSION_LIBS instead of moving LDFLAGS around tools/libxc/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- xen-unstable.hg-4.1.21836.orig/tools/libxc/Makefile +++ xen-unstable.hg-4.1.21836/tools/libxc/Makefile @@ -179,9 +179,9 @@ endif xc_dom_bzimageloader.o: CFLAGS += $(call zlib-options,D) xc_dom_bzimageloader.opic: CFLAGS += $(call zlib-options,D) -libxenguest.so.$(MAJOR).$(MINOR): LDFLAGS += $(call zlib-options,l) +libxenguest.so.$(MAJOR).$(MINOR): COMPRESSION_LIBS = $(call zlib-options,l) libxenguest.so.$(MAJOR).$(MINOR): $(GUEST_PIC_OBJS) libxenctrl.so - $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $(GUEST_PIC_OBJS) -lz -lxenctrl $(PTHREAD_LIBS) + $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $(GUEST_PIC_OBJS) $(COMPRESSION_LIBS) -lz -lxenctrl $(PTHREAD_LIBS) -include $(DEPS) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel