correct order of linker options to avoid link errors with recent toolchains
PATCH 1/1 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.
---
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(-)
tools/libxc/Makefile +1 -1
@@ -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)
Olaf Hering writes ("[Xen-devel] [PATCH] correct order of linker options to avoid link errors with recent toolchains"):
Quoted 3 lines
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.
Quoted 1 line
libxenguest.so.$(MAJOR).$(MINOR): LDFLAGS += $(call zlib-options,l)
What is this program "zlib-options" ? I don't have it on my system.
Ian.
Quoted 9 lines · Ian Jackson
Olaf Hering writes ("[Xen-devel] [PATCH] correct order of linker options to avoid link errors with recent toolchains"):
Quoted 4 lines
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:
Quoted 8 lines
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.Quoted 1 line
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
Keir Fraser writes ("Re: [Xen-devel] [PATCH] correct order of linker options to avoid link errors with recent toolchains"):
Quoted 7 lines · Ian Jackson
Quoted 3 lines
Quoted 1 line
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
Makefiledirectly 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.
Quoted 3 lines
Sounds like the right fix would indeed be to define a new
COMPRESSION_LIBSvariable and put it at the end of the linker command line.
Yes. Olaf, would you like to provide a patch to do that ?
Ian.
PATCH 1/1 correct order of linker options to avoid link errors with recent toolchains
In reply to Olaf HeringThe 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.
---
v2: use COMPRESSION_LIBS instead of moving LDFLAGS around
tools/libxc/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/libxc/Makefile +2 -2
@@ -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)