Hello Raphael and all.
> I'm now sure it's a binutils problem with the search path for
> libraries. Here my analysis of the problem and a patch against
> binutils-cross-2.15-5.patch.20041130 (see Debian bug #231707).
At last I've got some time to review this thing.
It turned that Raphael's fix is not a fix, but just a working workaround.
> The ld/ldmain.c:670 function set_scripts_dir() try to identify
> the location of libraryies. The directory name will be determined
> using the make_relative_prefix() function which create a relative
> path using three informations:
> 1. The path of the arch-linux-ld application (searching PATH)
> 2. The BINDIR (configure option --prefix=/usr + /bin by default)
> 3. The SCRIPTDIR (configure option --libdir by default {prefix}/lib)
>
> Today folowing values are set:
> 1. = /usr/bin/arch-linux-ld
> 2. = /usr/bin
> 3. = /usr/lib
>
> The make_relative_prefix() function create now a relative path
> between (2) and (3). This is "../lib" and applies this to the
> dir's part of (1): "/usr/../lib" This directory will be now used
> to determine the location of *cross* libraries.
Not exactly.
Actually, set_scripts_dir() tries several directories (built by some
strange games with make_relative_prefix()), and looks for ldscripts/
subdir in each one. When ldscripts/ directory is found, it's parent is
appended to the library search path, and search stops.
In normal case, the first try should be the hit. It is a try for the
directory passed in SCRIPTSDIR variable from the Makefile.
In normal case, this should be /usr/$(target-alias)/lib. With upstream
source, this is the case, so cross-ld searches the correct dir.
But in Debian source package it happenes to be /usr/lib
This is caused by debian/patches/001_ld_makefile_patch.dpatch, which
explicitly changed SCRIPTSDIR to /usr/lib. We can only guess what for it
does that; probably to get ldscripts installed to /usr/lib/ldscripts on
Debian.
Anyway, I fixed 001_ld_makefile_patch.dpatch not to change SCRIPTSDIR when
building cross-binutils.
As for Raphael's solution to use --libdir, it's a workaround with
side-effects, such as installation of *native* libs build with binutils
into /usr/$(target-alias)/lib/, and probably some others, at code level. I
think it's somewhat dangerous.
I've updated the patch to fix the cause of the problem. It is attached.
It is still against sarge's version, 2.15-6.
I've updated binary packages in my repository to use this version with this
patch.
Later versions will hopely follow soon.
Nikita
diff -urN binutils-2.15-6/debian/control.cross.in binutils-2.15/debian/control.cross.in
--- binutils-2.15-6/debian/control.cross.in 1970-01-01 03:00:00.000000000 +0300
+++ binutils-2.15/debian/control.cross.in 2005-07-01 13:58:09.000000000 +0400
@@ -0,0 +1,12 @@
+Package: PACKAGE
+Architecture: any
+Depends: binutils, ${shlibs:Depends}
+Suggests: binutils-doc (= ${Source-Version})
+Priority: extra
+OLD_EMDEBIAN_CONFLICT
+Description: The GNU binary utilities, for TARGET target
+ This package provides GNU assembler, linker and binary utilities
+ for TARGET target, for use in cross-compilation environment.
+ .
+ You don't need this package unless you plan to cross-compile programs
+ for TARGET.
diff -urN binutils-2.15-6/debian/patches/001_ld_makefile_patch.dpatch binutils-2.15/debian/patches/001_ld_makefile_patch.dpatch
--- binutils-2.15-6/debian/patches/001_ld_makefile_patch.dpatch 2005-07-01 13:56:11.000000000 +0400
+++ binutils-2.15/debian/patches/001_ld_makefile_patch.dpatch 2005-07-06 23:52:54.000000000 +0400
@@ -6,6 +6,10 @@
## DP: Author: Chris Chimelis <chris@debian.org>
## DP: Upstream status: N/A
## DP: Date: ??
+## DP: Fixed by Nikita Youshchenko <yoush@cs.msu.su> to be correct for
+## DP: cross-binutils - in that case change of $(scriptdir) to /usr/lib causes
+## DP: cross-ld to look for libraries in /usr/lib instead of
+## DP: /usr/$(target-alias)/lib
if [ $# -ne 1 ]; then
echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
@@ -26,27 +30,53 @@
exit 0
@DPATCH@
-diff -urNad /home/james/debian/packages/binutils/binutils-2.14.90.0.6/ld/Makefile.am binutils-2.14.90.0.6/ld/Makefile.am
---- /home/james/debian/packages/binutils/binutils-2.14.90.0.6/ld/Makefile.am 2003-08-21 16:28:48.000000000 +0100
-+++ binutils-2.14.90.0.6/ld/Makefile.am 2003-09-10 23:12:09.000000000 +0100
-@@ -19,7 +19,7 @@
+diff -urNad binutils-2.15-test/ld/Makefile.am /tmp/dpep.KPnTv9/binutils-2.15-test/ld/Makefile.am
+--- binutils-2.15-test/ld/Makefile.am 2005-07-06 23:51:06.000000000 +0400
++++ /tmp/dpep.KPnTv9/binutils-2.15-test/ld/Makefile.am 2005-07-06 23:52:08.086022408 +0400
+@@ -19,7 +19,11 @@
# We put the scripts in the directory $(scriptdir)/ldscripts.
# We can't put the scripts in $(datadir) because the SEARCH_DIR
# directives need to be different for native and cross linkers.
-scriptdir = $(tooldir)/lib
-+scriptdir = $(libdir)
++scriptdir = `if [ "@host@" = "@target@" ] ; then \
++ echo '$(libdir)'; \
++ else \
++ echo '$(tooldir)/lib'; \
++ fi`
EMUL = @EMUL@
EMULATION_OFILES = @EMULATION_OFILES@
-diff -urNad /home/james/debian/packages/binutils/binutils-2.14.90.0.6/ld/Makefile.in binutils-2.14.90.0.6/ld/Makefile.in
---- /home/james/debian/packages/binutils/binutils-2.14.90.0.6/ld/Makefile.in 2003-08-21 16:28:48.000000000 +0100
-+++ binutils-2.14.90.0.6/ld/Makefile.in 2003-09-10 23:12:09.000000000 +0100
-@@ -128,7 +128,7 @@
+@@ -415,7 +419,7 @@
+
+ ldmain.o: ldmain.c config.status
+ $(COMPILE) -c -DDEFAULT_EMULATION='"$(EMUL)"' \
+- -DSCRIPTDIR='"$(scriptdir)"' -DBINDIR='"$(bindir)"' \
++ -DSCRIPTDIR='"'$(scriptdir)'"' -DBINDIR='"$(bindir)"' \
+ -DTOOLBINDIR='"$(tooldir)/bin"' \
+ -DTARGET='"@target@"' @TARGET_SYSTEM_ROOT_DEFINE@ \
+ $(srcdir)/ldmain.c
+diff -urNad binutils-2.15-test/ld/Makefile.in /tmp/dpep.KPnTv9/binutils-2.15-test/ld/Makefile.in
+--- binutils-2.15-test/ld/Makefile.in 2005-07-06 23:51:06.000000000 +0400
++++ /tmp/dpep.KPnTv9/binutils-2.15-test/ld/Makefile.in 2005-07-06 23:52:22.767790440 +0400
+@@ -128,7 +128,11 @@
# We put the scripts in the directory $(scriptdir)/ldscripts.
# We can't put the scripts in $(datadir) because the SEARCH_DIR
# directives need to be different for native and cross linkers.
-scriptdir = $(tooldir)/lib
-+scriptdir = $(libdir)
++scriptdir = `if [ "@host@" = "@target@" ] ; then \
++ echo '$(libdir)'; \
++ else \
++ echo '$(tooldir)/lib'; \
++ fi`
EMUL = @EMUL@
EMULATION_OFILES = @EMULATION_OFILES@
+@@ -1146,7 +1150,7 @@
+
+ ldmain.o: ldmain.c config.status
+ $(COMPILE) -c -DDEFAULT_EMULATION='"$(EMUL)"' \
+- -DSCRIPTDIR='"$(scriptdir)"' -DBINDIR='"$(bindir)"' \
++ -DSCRIPTDIR='"'$(scriptdir)'"' -DBINDIR='"$(bindir)"' \
+ -DTOOLBINDIR='"$(tooldir)/bin"' \
+ -DTARGET='"@target@"' @TARGET_SYSTEM_ROOT_DEFINE@ \
+ $(srcdir)/ldmain.c
diff -urN binutils-2.15-6/debian/patches/00list binutils-2.15/debian/patches/00list
--- binutils-2.15-6/debian/patches/00list 2005-07-01 13:56:11.000000000 +0400
+++ binutils-2.15/debian/patches/00list 2005-07-01 13:59:09.000000000 +0400
@@ -16,3 +16,4 @@
121_ia64_unwind_fixes
122_m68k_undefweak_symbols
123_bfd_overflow_fix
+999_lib64_for_cross
diff -urN binutils-2.15-6/debian/patches/999_lib64_for_cross.dpatch binutils-2.15/debian/patches/999_lib64_for_cross.dpatch
--- binutils-2.15-6/debian/patches/999_lib64_for_cross.dpatch 1970-01-01 03:00:00.000000000 +0300
+++ binutils-2.15/debian/patches/999_lib64_for_cross.dpatch 2005-07-01 13:58:09.000000000 +0400
@@ -0,0 +1,56 @@
+#! /bin/sh -e
+## 999_lib64_for_cross.dpatch by Nikita Youshchenko <yoush@cs.msu.su>
+##
+## DP: Add /usr/${target-alias}/lib${LIBPATH_SUFFIX} to ld's default
+## DP: library search path for cross targets. Needed for cross targets that
+## DP: try to support both 32bit and 64bit emulations.
+
+if [ $# -lt 1 ]; then
+ echo "`basename $0`: script expects -patch|-unpatch as argument" >&2
+ exit 1
+fi
+
+[ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
+patch_opts="${patch_opts:--f --no-backup-if-mismatch} ${2:+-d $2}"
+
+case "$1" in
+ -patch) patch -p1 ${patch_opts} < $0;;
+ -unpatch) patch -R -p1 ${patch_opts} < $0;;
+ *)
+ echo "`basename $0`: script expects -patch|-unpatch as argument" >&2
+ exit 1;;
+esac
+
+exit 0
+
+@DPATCH@
+diff -urNad /home/nikita/debian/binutils/binutils-2.14.90.0.7.cross/ld/genscripts.sh binutils-2.14.90.0.7.cross/ld/genscripts.sh
+--- /home/nikita/debian/binutils/binutils-2.14.90.0.7.cross/ld/genscripts.sh 2003-10-29 20:37:48.000000000 +0300
++++ binutils-2.14.90.0.7.cross/ld/genscripts.sh 2004-07-15 00:29:19.000000000 +0400
+@@ -176,6 +176,26 @@
+ ::) LIB_PATH=${tool_lib} ;;
+ *) LIB_PATH=${tool_lib}:${LIB_PATH} ;;
+ esac
++ # For multilib'ed targets, ensure both ${target_alias}/lib${LIBPATH_SUFFIX}
++ # and ${TOOL_LIB}/lib${LIBPATH_SUFFIX} to default search path, because
++ # 64bit libraries may be in both places, depending on cross-development
++ # setup method (e.g.: /usr/s390x-linux/lib64 vs /usr/s390-linux/lib64)
++ case "${LIBPATH_SUFFIX}:${tool_lib}" in
++ :*) ;;
++ *:*${LIBPATH_SUFFIX}) ;;
++ *)
++ paths="${exec_prefix}/${target_alias}/lib${LIBPATH_SUFFIX}"
++ if [ "${TOOL_LIB}" != x ]; then
++ paths="${paths} ${exec_prefix}/${TOOL_LIB}/lib${LIBPATH_SUFFIX}"
++ fi
++ for path in $paths; do
++ case :${LIB_PATH}: in
++ ::: | *:${path}:*) ;;
++ *) LIB_PATH=${path}:${LIB_PATH} ;;
++ esac
++ done
++ ;;
++ esac
+ fi
+
+ LIB_SEARCH_DIRS=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'`
diff -urN binutils-2.15-6/debian/README.cross binutils-2.15/debian/README.cross
--- binutils-2.15-6/debian/README.cross 1970-01-01 03:00:00.000000000 +0300
+++ binutils-2.15/debian/README.cross 2005-07-01 13:58:09.000000000 +0400
@@ -0,0 +1,12 @@
+Cross-binutils debian packages can be built directly from binutils
+source package.
+
+To build cross-binutils package, download and unpack binutils
+source package, and run
+
+TARGET=your-target fakeroot debian/rules binary-cross
+
+(substitute your target name, e.g. "arm-linux", instead of "your-target")
+
+---
+Nikita Youshchenko <yoush@cs.msu.su>
diff -urN binutils-2.15-6/debian/rules binutils-2.15/debian/rules
--- binutils-2.15-6/debian/rules 2005-07-01 13:56:11.000000000 +0400
+++ binutils-2.15/debian/rules 2005-07-07 00:40:20.000000000 +0400
@@ -377,7 +377,8 @@
endif
$(install_file) $(pwd)/test-summary binutils/NEWS \
- debian/README.Debian $(d_bin)/usr/share/doc/$(p_bin)/
+ debian/README.Debian debian/README.cross \
+ $(d_bin)/usr/share/doc/$(p_bin)/
$(install_file) binutils/ChangeLog $(d_bin)/usr/share/doc/$(p_bin)/changelog
@@ -436,6 +437,101 @@
################################################################################
+#################
+# cross targets #
+#################
+
+p_cross = $(subst _,-,binutils-$(TARGET))
+d_cross = debian/$(p_cross)
+
+ifneq ($(filter sparc-linux powerpc-linux mips-linux, $(TARGET)),)
+ADDITIONAL_TARGETS = --enable-targets=$(TARGET:%-linux=%64-linux)
+endif
+ifneq ($(filter i386-linux i486-linux i586-linux x86-linux, $(TARGET)),)
+ADDITIONAL_TARGETS = --enable-targets=x86_64-linux
+endif
+ifeq ($(TARGET), x86_64-linux)
+ADDITIONAL_TARGETS = --enable-targets=i386-linux
+endif
+ifeq ($(TARGET), mipsel-linux)
+ADDITIONAL_TARGETS = --enable-targets=mips64el-linux
+endif
+ifeq ($(TARGET), sparc64-linux)
+ADDITIONAL_TARGETS = --enable-targets=sparc-linux
+endif
+ifeq ($(TARGET), s390-linux)
+ADDITIONAL_TARGETS = --enable-targets=s390x-linux
+endif
+ifeq ($(TARGET), s390x-linux)
+ADDITIONAL_TARGETS = --enable-targets=s390-linux
+endif
+
+configure-$(TARGET)-stamp: patch-stamp
+ $(checkdir)
+ test "" != "$(TARGET)"
+ rm -rf configure-$(TARGET)-stamp builddir-$(TARGET)
+ mkdir builddir-$(TARGET)
+ cd builddir-$(TARGET) \
+ && env CC="$(CC)" ../configure --host=$(DEB_HOST_GNU_TYPE) \
+ --build=$(DEB_BUILD_GNU_TYPE) --target=$(TARGET) --prefix=/usr \
+ $(ADDITIONAL_TARGETS)
+ touch $@
+
+build-$(TARGET)-stamp: configure-$(TARGET)-stamp
+ $(checkdir)
+ test "" != "$(TARGET)"
+ $(MAKE) -C builddir-$(TARGET) CFLAGS="$(CFLAGS)"
+ touch $@
+
+install-$(TARGET)-stamp: build-$(TARGET)-stamp
+ $(checkdir)
+ test "" != "$(TARGET)"
+ rm -rf $(d_cross)
+ $(MAKE) -C builddir-$(TARGET) prefix=$(pwd)/$(d_cross)/usr \
+ mandir=$(pwd)/$(d_cross)/usr/share/man install
+ rm -rf $(d_cross)/usr/lib $(d_cross)/usr/info $(d_cross)/usr/share/locale
+ $(STRIP) $(d_cross)/usr/bin/*
+ gzip -9 $(d_cross)/usr/share/man/man1/*
+ touch $@
+
+binary-cross: checkroot install-$(TARGET)-stamp
+ $(checkdir)
+ test "" != "$(TARGET)"
+
+ sed '/^$$/ q' < debian/control > debian/control.$(TARGET)
+ case "$(TARGET)" in \
+ arm-linux|powerpc-linux) \
+ sed "s/TARGET/$(TARGET)/g; s/PACKAGE/$(p_cross)/; s/OLD_EMDEBIAN_CONFLICT/Conflicts: binutils-`echo $(TARGET) | sed s/-linux//`/" < debian/control.cross.in >> debian/control.$(TARGET) ;; \
+ *) \
+ grep -v OLD_EMDEBIAN_CONFLICT debian/control.cross.in | sed "s/TARGET/$(TARGET)/g; s/PACKAGE/$(p_cross)/" >> debian/control.$(TARGET) ;; \
+ esac
+
+ $(install_dir) $(d_cross)/DEBIAN
+
+ $(install_dir) $(d_cross)/usr/share/doc/$(p_cross)/
+ $(install_file) debian/changelog $(d_cross)/usr/share/doc/$(p_cross)/changelog.Debian
+ $(install_file) debian/copyright debian/README.cross $(d_cross)/usr/share/doc/$(p_cross)/
+ gzip -f -9 $(d_cross)/usr/share/doc/$(p_cross)/changelog.Debian
+
+ for pkg in bfd gas gprof ld; do \
+ ln -sf ../binutils/$$pkg $(d_cross)/usr/share/doc/$(p_cross)/$$pkg; \
+ done
+
+ rm -f debian/substvars
+ dpkg-shlibdeps $(d_cross)/usr/bin/*
+ dpkg-gencontrol -cdebian/control.$(TARGET) -P$(d_cross) -p$(p_cross)
+ dpkg --build $(d_cross) ..
+
+clean-cross: unpatch
+ $(checkdir)
+ test "" != "$(TARGET)"
+ rm -rf $(d_cross) debian/control.$(TARGET) debian/files debian/substvars \
+ builddir-$(TARGET) {configure,build,install}-$(TARGET)-stamp
+
+.PHONY: binary-cross clean-cross
+
+################################################################################
+
define checkdir
test -f bfd/elf32.c -a -f debian/rules
endef
Attachment:
pgp_xVXHXYPrS.pgp
Description: PGP signature