Questions on problems encountered building gcc cross-toolchain for armel in Jessie

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Questions on problems encountered building gcc cross-toolchain for armel in Jessie

Jim Heck-2
Recently I decided to try to build a cross-toolchain in Jessie for armel.  I managed to succeed, but I ran into several problems and I wanted to get some feedback before submitting proposed patches.  As background in my use case, I am attempting to build a cross-toolchain targeting armel to be run on i386.  Additionally, I build this toolchain statically and with a custom prefix so that I can relocate the resulting binaries easily to work in a stand alone make environment (e.g. not a standard Debian installation).

I want to talk specifically about two of the problems I ran into compiling GCC.  I also ran into a problem statically compiling binutils, but this was just a simple breakage of the install-static-cross-stamp target, for which I have already filed a bug 766485.  There are full details below along with my patches, as well as a full outline of my build steps are at the end of this message.

When statically compiling GCC, I ran into a problem in that a static compilation seems to be incompatible with GCC plugins.  This seems logical I guess, since plugins by their nature are dynamic.  I had to disable plugins to get the static build to work.  I have a patch below that makes this modification based on a deb build option 'static' already present in the Debian GCC makefiles.  So the question I have is does this make sense?

The next problem I ran into that I want to discuss, regards libssp.  I found when building that /debian/control.m4 excludes control information for libssp when TARGET is defined.  I had earlier found a problem in the Debian makefiles regarding libssp when building libgcc.  I worked around both problems by setting 'with_libssp' to 'no' when DEB_CROSS is defined.  I am left wondering if it makes sense to have libssp in a cross toolchain.  The control file would seem to indicate that it does not.  Is this correct?

I found one additional problem when building libstdcxx.  There was a missing call to shlibdirs_to_search preventing the build from locating dependencies.  This could have been stimulated by the use of a custom prefix.

So with respect to the plugin and libssp questions, I would like to know from the community if my changes make sense before I open bugs against GCC.

Best Regards,

-Jim Heck


Detailed build information and patches follow:


Problems building gcc statically as a crosscompiler for armel

1. Static build is not compatible with plugins, which I think makes sense, since these require dynamic loading.  Fixed this with a modification to debian/rules.defs and debian/rules.d/binary-cpp.mk

######## PATCH FILE START ###########
diff -Naur a/debian/rules.d/binary-cpp.mk b/debian/rules.d/binary-cpp.mk
--- a/debian/rules.d/binary-cpp.mk 2014-10-23 10:21:43.000000000 -0400
+++ b/debian/rules.d/binary-cpp.mk 2014-10-24 13:29:42.478092929 -0400
@@ -13,8 +13,13 @@
 
 files_cpp = \
  $(PF)/bin/$(cmd_prefix)cpp$(pkg_ver) \
- $(gcc_lexec_dir)/cc1 \
+ $(gcc_lexec_dir)/cc1
+
+# Static builds exclude plugins and so do not have liblto_plugin.so
+ifeq (,$(findstring static,$(DEB_BUILD_OPTIONS)))
+  files_cpp += \
  $(gcc_lexec_dir)/liblto_plugin.so{,.0,.0.0.0}
+endif
 
 ifneq ($(GFDL_INVARIANT_FREE),yes)
   files_cpp += \
diff -Naur a/debian/rules.defs b/debian/rules.defs
--- a/debian/rules.defs 2014-10-23 10:21:43.000000000 -0400
+++ b/debian/rules.defs 2014-10-24 07:04:00.634984659 -0400
@@ -1062,7 +1062,11 @@
 endif
 
 # plugins --------------------
+ifneq (,$(findstring static,$(DEB_BUILD_OPTIONS)))
+with_plugins := no
+else
 with_plugins := yes
+endif
 
 endif # ifndef DEB_STAGE
######## PATCH FILE END ###########


2. Ran into problem with redundant move of libssp_nonshared.a library in the course of building libgcc.

!!!!! Failed with

: # If building a flavour, add a lintian override
mv debian/tmp/opt/crosstools/arm/arm-linux-gnueabi/lib/libssp*.a debian/libgcc-4.9-dev-armel-cross/opt/crosstools/arm/lib/gcc-cross/arm-linux-gnueabi/4.9/
rm -f debian/tmp/opt/crosstools/arm/arm-linux-gnueabi/lib/libssp*.{la,so}
dh_link -plibgcc-4.9-dev-armel-cross /opt/crosstools/arm/arm-linux-gnueabi/lib/libssp.so.0 /opt/crosstools/arm/lib/gcc-cross/arm-linux-gnueabi/4.9/libssp.so
mv debian/tmp/opt/crosstools/arm/arm-linux-gnueabi/lib/libssp_nonshared.a debian/libgcc-4.9-dev-armel-cross/opt/crosstools/arm/lib/gcc-cross/arm-linux-gnueabi/4.9/;
mv: cannot stat 'debian/tmp/opt/crosstools/arm/arm-linux-gnueabi/lib/libssp_nonshared.a': No such file or directory
make[1]: *** [stamps/08-binary-stamp-libgcc-dev] Error 1
debian/rules.d/binary-libgcc.mk:360: recipe for target 'stamps/08-binary-stamp-libgcc-dev' failed
make[1]: Leaving directory '/home/jheck/opt-build-static-armel/gcc-4.9-4.9.1'
make: *** [binary] Error 2
dpkg-buildpackage: error: fakeroot debian/rules binary gave error exit status 2
debian/rules:94: recipe for target 'binary' failed

!!!!! This stemed from lines starting at line 223 in gcc-4.9-4.9.1/debian/rules.d/binary-libgcc.mk that tries to move this file twice

$(if $(filter yes, $(with_libssp)),
$(call install_gcc_lib,libssp,$(SSP_SONAME),$(1),$(2))
)
$(if $(filter yes, $(with_ssp)),
mv $(4)/libssp_nonshared.a debian/$(2)/$(3)/;
)

!!!!! Not sure of exact logic to coordinate these two 'with_' flags, but I just commented out the second to get further in my build

3. Ran into problem with a missing call to shlibdirs_to_search in the course of building libstdcxx at line 461 in debian/rules.d/binary-libstdcxx.mk

######## PATCH FILE START ###########
diff -Naur a/debian/rules.d/binary-libstdcxx.mk b/debian/rules.d/binary-libstdcxx.mk
--- a/debian/rules.d/binary-libstdcxx.mk 2014-10-23 10:21:43.000000000 -0400
+++ b/debian/rules.d/binary-libstdcxx.mk 2014-10-24 11:37:15.818352900 -0400
@@ -461,7 +461,7 @@
 #else
 # $(ignshld)DIRNAME=$(subst n,,$(2)) $(cross_shlibdeps) dh_shlibdeps -p$(p_dev) -p$(p_pic) -p$(p_dbg) -Xlib32/debug
 #endif
- $(ignshld)DIRNAME=$(subst n,,$(2)) $(cross_shlibdeps) dh_shlibdeps -p$(p_dev) -p$(p_pic) -p$(p_dbg)
+ $(ignshld)DIRNAME=$(subst n,,$(2)) $(cross_shlibdeps) dh_shlibdeps -p$(p_dev) -p$(p_pic) -p$(p_dbg) $(call shlibdirs_to_search,,$(2))
  $(call cross_mangle_substvars,$(p_dbg))
  $(cross_gencontrol) dh_gencontrol -p$(p_dev) -p$(p_pic) -p$(p_dbg) \
  -- -v$(DEB_VERSION) $(common_substvars)
######## PATCH FILE END ###########


4. Ran into problems with missing control information for installation of libssp.  Looking at debain/control.m4 it looks like libssp doesn't get included in the control file if TARGET is defined.  Should this library be included for a cross compiler toolchain? 


ifdef(`TARGET', `', `
ifenabled(`ssp',`
Package: libssp`'SSP_SO`'LS
Architecture: any
ifdef(`MULTIARCH', `Multi-Arch: same
Pre-Depends: multiarch-support
')`'dnl
...
')`'dnl
')`'dnl native

!!!!! The build error was

dpkg-gencontrol: error: package libssp0 not in control info
dh_gencontrol: dpkg-gencontrol -plibssp0 -ldebian/changelog -Tdebian/libssp0.substvars -Pdebian/libssp0 -v4.9.1-17 -Vlibgcc:Version=1:4.9.1-17 -Vgcc:Version=4.9.1-17 -Vgcc:EpochVersion=1:4.9.1-17 -Vgcc:SoftVersion=4.9 -Vgdc:Version=4.9.1-17 -Vgcj:Version=4.9.1-17 -Vgcj:SoftVersion=4.9 -Vgcj:BaseVersion=4.9 -Vgnat:Version=4.9.1-17 -Vbinutils:Version=2.24.51.20141001 -Vdep:libgcc=libgcc1-armel-cross (>= 1:4.9.1-17) -Vdep:libgccdev=libgcc-4.9-dev-armel-cross (>= 4.9.1-17) -Vdep:libgccbiarch= -Vdep:libgccbiarchdev= -Vdep:libc=libc6 (>= 2.11) -Vdep:libcdev=libc6-dev-armel-cross (>= 2.13-5) -Vdep:libcbiarch= -Vdep:libcbiarchdev= -Vdep:libunwinddev= -Vdep:libcxxbiarchdev= -Vdep:libcxxbiarchdbg= -Vdep:libgnat= -Vdep:ecj= -Vdep:libcloog= -Vdep:gold=binutils-gold (>= 2.24.51.20141001) -Vdep:libssp=libssp0-armel-cross (>= ${gcc:Version}) -Vdep:libgomp=libgomp1-armel-cross (>= ${gcc:Version}) -Vdep:libatomic=libatomic1-armel-cross (>= ${gcc:Version}) -Vdep:libasan=libasan1-armel-cross (>= ${gcc:Version}) -Vdep:libubsan=libubsan0-armel-cross (>= ${gcc:Version}) -Vdep:gcj=gcc-4.9 (>= 4.9) -Vdep:gcjcross=gcj-4.9 (>= 4.9) -Vdep:gdccross=gdc-4.9 (>= 4.9) -Vdep:phobosdev=libphobos-4.9-dev-armel-cross (>= 4.9) -Vdep:gdccross=gdc-4.9 (>= 4.9) -Vmultiarch:breaks=gcc-4.3 (<< 4.3.6-1), gcc-4.4 (<< 4.4.6-4), gcc-4.5 (<< 4.5.3-2) -VBuilt-Using=gcc-4.9 (= 4.9.1-16),  -Vfortran:mod-version=gfortran-mod-12 returned exit code 255
make[1]: *** [stamps/08-binary-stamp-libssp] Error 2
debian/rules.d/binary-libssp.mk:54: recipe for target 'stamps/08-binary-stamp-libssp' failed
make[1]: Leaving directory '/home/jheck/opt-build-static-armel/gcc-4.9-4.9.1'
make: *** [binary] Error 2
dpkg-buildpackage: error: fakeroot debian/rules binary gave error exit status 2
debian/rules:94: recipe for target 'binary' failed


!!!!! The only way I found around this problem was to go back and define 'with_libssp' to 'no' in debian/rules.defs.  This also eliminates problem 2. above

######## PATCH FILE START ###########
diff -Naur a/debian/rules.defs b/debian/rules.defs
--- a/debian/rules.defs 2014-10-23 10:21:43.000000000 -0400
+++ b/debian/rules.defs 2014-10-24 16:29:34.513677078 -0400
@@ -1100,6 +1100,8 @@
   ifeq ($(with_ssp)-$(with_common_libs),yes-yes)
     #ifneq ($(DEB_CROSS),yes)
       with_libssp := $(if $(wildcard $(builddir)/gcc/auto-host.h),$(shell if grep -qs '^\#define TARGET_LIBC_PROVIDES_SSP 1' $(builddir)/gcc/auto-host.h; then echo 'libc provides ssp'; else echo 'yes'; fi))
+    #else
+      with_libssp := no
     #endif
   endif
######## PATCH FILE END ###########




-------------------------------------------------------------------------------------------------------------------------------------------------------
Full outline of steps used to create cross toolchain:


1. Edit /etc/dpkg-cross/cross-compile
++++++++++++++++++++++++++++++++++++++++
crossbase = /opt/crosstools/arm
----------------------------------------

2. Install crosslibs to build binutils
++++++++++++++++++++++++++++++++++++++++
xapt -m -a armel -S jessie libc6-dev libc6 linux-libc-dev libc-dev-bin libc-bin libgcc1 gcc-4.9-base
----------------------------------------

3. Create directory to build as user e.g. /home/jheck/opt-build-static-armel

4. Get source for binutils

++++++++++++++++++++++++++++++++++++++++
apt-get source binutils; cd binutils-*
----------------------------------------

5. Patch binutils 

++++++++++++++++++++++++++++++++++++++++
diff -Naur a/debian/rules b/debian/rules
--- a/debian/rules 2014-10-23 08:18:33.000000000 -0400
+++ b/debian/rules 2014-10-23 08:38:16.569668294 -0400
@@ -1227,7 +1227,22 @@
  $(MAKE) -C builddir-$(TARGET) $(NJOBS) CFLAGS="$(CFLAGS)" LDFLAGS="-all-static"
  touch $@
 
-install-static-cross-stamp: build-static-cross-stamp install-cross-stamp
+install-static-cross-stamp: build-static-cross-stamp
+ $(checkdir)
+ test "" != "$(TARGET)"
+ rm -rf $(d_cross)
+ $(MAKE) -C builddir-$(TARGET) prefix=$(pwd)/$(d_cross)/$(PF) \
+ mandir=$(pwd)/$(d_cross)/$(PF)/share/man install
+ rm -rf $(d_cross)/$(PF)/lib* $(d_cross)/$(PF)/info $(d_cross)/$(PF)/share/locale
+
+ $(call strip_static_package, $(p_cross), $(d_cross),$(DEB_HOST_GNU_TYPE)/$(TARGET))
+ chmod ugo-x $(d_cross)/$(PF)/$(DEB_HOST_GNU_TYPE)/$(TARGET)/lib/*.a
+
+ : # Get rid of .la files since libtool obviously has no idea about transient paths
+ rm -f $(d_cross)/$(PF)/$(DEB_HOST_GNU_TYPE)/$(TARGET)/lib/*.la
+
+ gzip -9 $(d_cross)/$(PF)/share/man/man1/*
+ touch $@
 
 binary-cross: 
  @echo "Please use dpkg-buildpackage instead of calling binary-cross directly; see README.cross"
@@ -1251,9 +1266,20 @@
  $(STRIP) --strip-unneeded $2/$(PF)/$3/lib/libopcodes-*so
  $(STRIP) $$(file $2/$(PF)/bin/* |awk -F: '$$0 !~ /script/ {print $$1}')
 endef
+define strip_static_package
+ : # Strip shared libraries
+ if which pkg_create_dbgsym >/dev/null 2>&1; then \
+  pkg_create_dbgsym $1 $2; \
+ fi
+ $(STRIP) --strip-unneeded $2/$(PF)/$3/lib/libbfd*.a
+ $(STRIP) --strip-unneeded $2/$(PF)/$3/lib/libopcodes*.a
+ $(STRIP) $$(file $2/$(PF)/bin/* |awk -F: '$$0 !~ /script/ {print $$1}')
+endef
 else
 define strip_package
 endef
+define strip_static_package
+endef
 endif
 
 remove-gfdl-files:
----------------------------------------

6. Build static cross binutils

++++++++++++++++++++++++++++++++++++++++
 PF=opt/crosstools/arm DEB_BUILD_OPTIONS="static-cross nogold" TARGET=armel dpkg-buildpackage -b -uc -us |tee ../binutils-2.24.51.20141001.prefix.static.log
----------------------------------------

7. Install static binutils

++++++++++++++++++++++++++++++++++++++++
dpkg -i binutils-arm-linux-gnueabi_2.24.51.20141001-2_i386.deb
----------------------------------------

8. Install some more cross libs

++++++++++++++++++++++++++++++++++++++++
xapt -m -a armel -S jessie zlib1g-dev libmpfr-dev libmpfr4 zlib1g libgmp3-dev libgmpxx4ldbl libstdc++6

xapt -m -a armel -S jessie libmpc-dev
----------------------------------------

9. Get the source for GCC

++++++++++++++++++++++++++++++++++++++++
apt-get source gcc-4.9; cd gcc-4.9-*
----------------------------------------

10. Patch the source for GCC

++++++++++++++++++++++++++++++++++++++++
diff -Naur a/debian/rules.d/binary-cpp.mk b/debian/rules.d/binary-cpp.mk
--- a/debian/rules.d/binary-cpp.mk 2014-10-23 10:21:43.000000000 -0400
+++ b/debian/rules.d/binary-cpp.mk 2014-10-24 13:29:42.478092929 -0400
@@ -13,8 +13,13 @@
 
 files_cpp = \
  $(PF)/bin/$(cmd_prefix)cpp$(pkg_ver) \
- $(gcc_lexec_dir)/cc1 \
+ $(gcc_lexec_dir)/cc1
+
+# Static builds exclude plugins and so do not have liblto_plugin.so
+ifeq (,$(findstring static,$(DEB_BUILD_OPTIONS)))
+  files_cpp += \
  $(gcc_lexec_dir)/liblto_plugin.so{,.0,.0.0.0}
+endif
 
 ifneq ($(GFDL_INVARIANT_FREE),yes)
   files_cpp += \
diff -Naur a/debian/rules.defs b/debian/rules.defs
--- a/debian/rules.defs 2014-10-23 10:21:43.000000000 -0400
+++ b/debian/rules.defs 2014-10-24 07:04:00.634984659 -0400
@@ -1062,7 +1062,11 @@
 endif
 
 # plugins --------------------
+ifneq (,$(findstring static,$(DEB_BUILD_OPTIONS)))
+with_plugins := no
+else
 with_plugins := yes
+endif
 
 endif # ifndef DEB_STAGE
----------------------------------------

++++++++++++++++++++++++++++++++++++++++
diff -Naur a/debian/rules.d/binary-libstdcxx.mk b/debian/rules.d/binary-libstdcxx.mk
--- a/debian/rules.d/binary-libstdcxx.mk 2014-10-23 10:21:43.000000000 -0400
+++ b/debian/rules.d/binary-libstdcxx.mk 2014-10-24 11:37:15.818352900 -0400
@@ -461,7 +461,7 @@
 #else
 # $(ignshld)DIRNAME=$(subst n,,$(2)) $(cross_shlibdeps) dh_shlibdeps -p$(p_dev) -p$(p_pic) -p$(p_dbg) -Xlib32/debug
 #endif
- $(ignshld)DIRNAME=$(subst n,,$(2)) $(cross_shlibdeps) dh_shlibdeps -p$(p_dev) -p$(p_pic) -p$(p_dbg)
+ $(ignshld)DIRNAME=$(subst n,,$(2)) $(cross_shlibdeps) dh_shlibdeps -p$(p_dev) -p$(p_pic) -p$(p_dbg) $(call shlibdirs_to_search,,$(2))
  $(call cross_mangle_substvars,$(p_dbg))
  $(cross_gencontrol) dh_gencontrol -p$(p_dev) -p$(p_pic) -p$(p_dbg) \
  -- -v$(DEB_VERSION) $(common_substvars)
----------------------------------------

++++++++++++++++++++++++++++++++++++++++
diff -Naur a/debian/rules.defs b/debian/rules.defs
--- a/debian/rules.defs 2014-10-23 10:21:43.000000000 -0400
+++ b/debian/rules.defs 2014-10-24 16:29:34.513677078 -0400
@@ -1100,6 +1100,8 @@
   ifeq ($(with_ssp)-$(with_common_libs),yes-yes)
     #ifneq ($(DEB_CROSS),yes)
       with_libssp := $(if $(wildcard $(builddir)/gcc/auto-host.h),$(shell if grep -qs '^\#define TARGET_LIBC_PROVIDES_SSP 1' $(builddir)/gcc/auto-host.h; then echo 'libc provides ssp'; else echo 'yes'; fi))
+    #else
+      with_libssp := no
     #endif
   endif
----------------------------------------

11. Compile GCC

++++++++++++++++++++++++++++++++++++++++
PF=opt/crosstools/arm DEB_BUILD_OPTIONS=static GCC_TARGET=armel DEB_CROSS=yes fakeroot debian/rules control |tee ../gcc-4.9-4.9.1.prefix.static.control.log
PF=opt/crosstools/arm DEB_BUILD_OPTIONS=static GCC_TARGET=armel DEB_CROSS=yes dpkg-buildpackage -us -uc -rfakeroot |tee ../gcc-4.9-4.9.1.prefix.static.log
----------------------------------------

12. Install GCC (partial)

++++++++++++++++++++++++++++++++++++++++
dpkg -i libgomp1-armel-cross_4.9.1-17_all.deb gcc-4.9-arm-linux-gnueabi_4.9.1-17_i386.deb libstdc++6-armel-cross_4.9.1-17_all.deb libgcc-4.9-dev-armel-cross_4.9.1-17_all.deb libgcc1-armel-cross_4.9.1-17_all.deb libatomic1-armel-cross_4.9.1-17_all.deb libasan1-armel-cross_4.9.1-17_all.deb libubsan0-armel-cross_4.9.1-17_all.deb libstdc++-4.9-dev-armel-cross_4.9.1-17_all.deb

dpkg -i gcc-4.9-arm-linux-gnueabi_4.9.1-17_i386.deb gcc-4.9-arm-linux-gnueabi-base_4.9.1-17_i386.deb g++-4.9-arm-linux-gnueabi_4.9.1-17_i386.deb
----------------------------------------