Pull request for branch codesourcery-toolchain-support
Hello,
Here is a resend of my CodeSourcery external toolchain support patch set. I've fixed the merge conflict that Peter had, which was the only feedback I received on this patchset.
Regards,
Thomas
The following changes since commit 65e209ca07416bc040fe98d16b60b6cb4304987f:
Peter Korsgaard (1):
openssl: fix build without ipv6 support
are available in the git repository at:
git://git.busybox.net/~tpetazzoni/git/buildroot codesourcery-toolchain-support
Thomas Petazzoni (4):
external toolchains: take into account architecture variant
external-toolchain: support libraries outside of /lib
external-toolchain: Support for multilib toolchains
busybox: make sure architecture flags are used at link time
package/Makefile.in | 22 +++--- package/busybox/busybox-1.13.x.config | 1 + package/busybox/busybox.mk | 8 +- toolchain/external-toolchain/ext-tool.mk | 109 ++++++++++++++++++++++++----- 4 files changed, 106 insertions(+), 34 deletions(-)
Thanks,
Signature · 1 line
Thomas Petazzoni
PATCH 1/4 external toolchains: take into account architecture variant
Until now, many TARGET_CFLAGS where missing when using an external toolchain, due to how package/Makefile.in was written. Now, a lot more definitions are common between the Buildroot toolchain case and the external toolchain case.
--- package/Makefile.in | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-)
package/Makefile.in +11 -11
@@ -34,16 +34,7 @@ ifeq ($(BR2_DEBUG_3),y) TARGET_DEBUGGING=-g3 endif - -######################################################################### -ifeq ($(BR2_TOOLCHAIN_BUILDROOT),y) -TARGET_CFLAGS=$(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING) \ - -I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include -TARGET_LDFLAGS+=-L$(STAGING_DIR)/lib -L$(STAGING_DIR)/usr/lib -ifeq ($(BR2_TOOLCHAIN_SYSROOT),y) -TARGET_CFLAGS+= $(BR2_SYSROOT) $(BR2_ISYSROOT) -TARGET_LDFLAGS+= $(BR2_SYSROOT) -endif +TARGET_CFLAGS=$(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING) CC_TARGET_TUNE_:=$(call qstrip,$(BR2_GCC_TARGET_TUNE)) CC_TARGET_ARCH_:=$(call qstrip,$(BR2_GCC_TARGET_ARCH))
@@ -86,11 +77,20 @@ ifeq ($(BR2_LARGEFILE),y) TARGET_CFLAGS+=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 endif + +######################################################################### +ifeq ($(BR2_TOOLCHAIN_BUILDROOT),y) +TARGET_CFLAGS+=-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include +TARGET_LDFLAGS+=-L$(STAGING_DIR)/lib -L$(STAGING_DIR)/usr/lib TARGET_CXXFLAGS=$(TARGET_CFLAGS) +ifeq ($(BR2_TOOLCHAIN_SYSROOT),y) +TARGET_CFLAGS+= $(BR2_SYSROOT) $(BR2_ISYSROOT) +TARGET_LDFLAGS+= $(BR2_SYSROOT) +endif ######################################################################### else ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y) -TARGET_CFLAGS=$(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING) --sysroot $(STAGING_DIR)/ +TARGET_CFLAGS+=--sysroot $(STAGING_DIR)/ TARGET_CXXFLAGS=$(TARGET_CFLAGS) TARGET_LDFLAGS=--sysroot $(STAGING_DIR)/ endif
Signature · 1 line
1.6.3.3
PATCH 2/4 external-toolchain: support libraries outside of /lib
In reply to Thomas PetazzoniThe copy_toolchain_lib_root function was making the assumption that all libraries were stored inside the /lib directory of the sysroot directory. However, this isn't true for certain toolchains, particularly for the libstdc++ library.
The function is therefore reworked to find the library and its related symlink either in /lib or /usr/lib in the sysroot, and copies it at the same location in the target directory.
--- toolchain/external-toolchain/ext-tool.mk | 23 +++++++++++++---------- 1 files changed, 13 insertions(+), 10 deletions(-)
toolchain/external-toolchain/ext-tool.mk +13 -10
@@ -1,3 +1,4 @@ + # # This file implements the support for external toolchains, i.e # toolchains that have not been produced by Buildroot itself and that
@@ -45,27 +46,29 @@ copy_toolchain_lib_root = \ DST="$(strip $3)"; \ STRIP="$(strip $4)"; \ \ - LIB_DIR="$${SYSROOT_DIR}/lib" ; \ - for FILE in `find $${LIB_DIR} -maxdepth 1 -name "$${LIB}.*"`; do \ + LIBS=`(cd $${SYSROOT_DIR}; find . -path "./lib/$${LIB}.*" -o -path "./usr/lib/$${LIB}.*")` ; \ + for FILE in $${LIBS} ; do \ LIB=`basename $${FILE}`; \ + LIBDIR=`dirname $${FILE}` ; \ while test \! -z "$${LIB}"; do \ - rm -fr $(TARGET_DIR)$${DST}/$${LIB}; \ - mkdir -p $(TARGET_DIR)$${DST}; \ - if test -h $${LIB_DIR}/$${LIB}; then \ - cp -d $${LIB_DIR}/$${LIB} $(TARGET_DIR)$${DST}/; \ - elif test -f $${LIB_DIR}/$${LIB}; then \ - $(INSTALL) -D -m0755 $${LIB_DIR}/$${LIB} $(TARGET_DIR)$${DST}/$${LIB}; \ + FULLPATH="$${SYSROOT_DIR}/$${LIBDIR}/$${LIB}" ; \ + rm -fr $(TARGET_DIR)/$${LIBDIR}/$${LIB}; \ + mkdir -p $(TARGET_DIR)/$${LIBDIR}; \ + if test -h $${FULLPATH} ; then \ + cp -d $${FULLPATH} $(TARGET_DIR)/$${LIBDIR}/; \ + elif test -f $${FULLPATH}; then \ + $(INSTALL) -D -m0755 $${FULLPATH} $(TARGET_DIR)/$${LIBDIR}/$${LIB}; \ case "$${STRIP}" in \ (0 | n | no) \ ;; \ (*) \ - $(TARGET_CROSS)strip "$(TARGET_DIR)$${DST}/$${LIB}"; \ + $(TARGET_CROSS)strip "$(TARGET_DIR)/$${LIBDIR}/$${LIB}"; \ ;; \ esac; \ else \ exit -1; \ fi; \ - LIB="`readlink $${LIB_DIR}/$${LIB}`"; \ + LIB="`readlink $${FULLPATH}`"; \ done; \ done; \ \
Signature · 1 line
1.6.3.3
PATCH 3/4 external-toolchain: Support for multilib toolchains
In reply to Thomas PetazzoniMultilib toolchains provide different versions of the base libraries for different architecture variants. For example, the ARM Codesourcery toolchain provides base libraries for ARMv5 (default), ARMv4t and Thumb2.
Depending on the -march= argument passed to gcc, the sysroot used by the compiler is therefore different. This means that the sysroot location in CROSS-gcc -v cannot be used. Instead, we must use CROSS-gcc -print-sysroot when available and fall back to the old way if unavailable.
Moreover, we cannot simply copy the full sysroot as we used to do, because the sysroot organization of multilib toolchain is more complicated. In Codesourcery toolchains, we have :
/
etc -- for ARMv5
lib -- for ARMv5
sbin -- for ARMv5
usr -- for ARMv5 (includes headers)
armv4t
etc -- for ARMv4t
lib -- for ARMv4t
sbin -- for ARMv4t
usr -- for ARMv4t (no headers!)
thumb2
etc -- for Thumb2
lib -- for Thumb2
sbin -- for Thumb2
usr -- for Thumb2 (no headers!)So we have the default ARMv5 architecture variant that is installed in the main directory, and we have subdirectories for the ARMv4t and Thumb2 architecture variants.
Copying the full sysroot to the staging directory doesn't work. All our packages are based on the fact that they should install libraries in staging/usr/lib. But if ARMv4t is used, the compiler would only look in staging/armv4t/usr/lib for libraries (even when overriding the sysroot with the --sysroot option, the multilib compiler suffixes the sysroot directory with the architecture variant if it matches a recognized one).
Therefore, we have to copy only the sysroot that we are interested in. This is rendered a little bit complicated by the fact that the armv4t and thumb2 sysroot do not contain the headers since they are shared with the armv5 sysroot.
So, this patch :
* Modifies how we compute SYSROOT_DIR in order to use -print-sysroot if it exists. SYSROOT_DIR contains the location of the main sysroot directory, i.e the sysroot for the default architecture variant.
* Defines ARCH_SUBDIR as the subdirectory in the main sysroot for the currently selected architecture variant (in our case, it can be ".", "armv4t" or "thumb2"). ARCH_SYSROOT_DIR is defined as the full path to the sysroot of the currently selected architecture variant.
* Modifies copy_toolchain_lib_root (which copies a library to the target/ directory) so that libraries are taken from ARCH_SYSROOT_DIR instead of SYSROOT_DIR. This ensures that libraries for the correct architecture variant are properly copied to the target.
* Modifies copy_toolchain_sysroot (which copies the sysroot to the staging/ directory), so that it copies the contents of ARCH_SYSROOT_DIR, and if needed, adds the headers from the main sysroot directory and a symbolic link (armv4t -> . or thumb2 -> .) to make the compiler believe that its sysroot is really in armv4t/ or thumb2/.
Tested with Codesourcery 2009q1 ARM toolchain, Crosstool-NG ARM glibc and ARM uClibc toolchains.
--- toolchain/external-toolchain/ext-tool.mk | 90 ++++++++++++++++++++++++++---- 1 files changed, 79 insertions(+), 11 deletions(-)
toolchain/external-toolchain/ext-tool.mk +79 -11
@@ -2,7 +2,12 @@ # # This file implements the support for external toolchains, i.e # toolchains that have not been produced by Buildroot itself and that -# are already available on the system on which Buildroot runs. +# are already available on the system on which Buildroot runs. So far, +# we have tested this with: +# +# * Toolchains generated by Crosstool-NG +# * Toolchains generated by Buildroot +# * ARM toolchains made available by Codesourcery # # The basic principle is the following #
@@ -35,23 +40,22 @@ # directory to the target directory. Also optionaly strips the # library. # -# $1: sysroot directory +# $1: arch specific sysroot directory # $2: library name # $3: destination directory # $4: strip (y|n), default is to strip # copy_toolchain_lib_root = \ - SYSROOT_DIR="$(strip $1)"; \ + ARCH_SYSROOT_DIR="$(strip $1)"; \ LIB="$(strip $2)"; \ - DST="$(strip $3)"; \ STRIP="$(strip $4)"; \ \ - LIBS=`(cd $${SYSROOT_DIR}; find . -path "./lib/$${LIB}.*" -o -path "./usr/lib/$${LIB}.*")` ; \ + LIBS=`(cd $${ARCH_SYSROOT_DIR}; find . -path "./lib/$${LIB}.*" -o -path "./usr/lib/$${LIB}.*")` ; \ for FILE in $${LIBS} ; do \ LIB=`basename $${FILE}`; \ LIBDIR=`dirname $${FILE}` ; \ while test \! -z "$${LIB}"; do \ - FULLPATH="$${SYSROOT_DIR}/$${LIBDIR}/$${LIB}" ; \ + FULLPATH="$${ARCH_SYSROOT_DIR}/$${LIBDIR}/$${LIB}" ; \ rm -fr $(TARGET_DIR)/$${LIBDIR}/$${LIB}; \ mkdir -p $(TARGET_DIR)/$${LIBDIR}; \ if test -h $${FULLPATH} ; then \
@@ -76,13 +80,54 @@ copy_toolchain_lib_root = \ # # Copy the full external toolchain sysroot directory to the staging -# dir +# dir. The operation of this function is rendered a little bit +# complicated by the support for multilib toolchains. # -# $1: sysroot directory +# We start by copying etc, lib, sbin and usr from the sysroot of the +# selected architecture variant (as pointed by ARCH_SYSROOT_DIR). This +# allows to import into the staging directory the C library and +# companion libraries for the correct architecture variant. We +# explictly only copy etc, lib, sbin and usr since other directories +# might exist for other architecture variants (on Codesourcery +# toolchain, the sysroot for the default architecture variant contains +# the armv4t and thumb2 subdirectories, which are the sysroot for the +# corresponding architecture variants), and we don't want to import +# them. +# +# Then, if the selected architecture variant is not the default one +# (i.e, if SYSROOT_DIR != ARCH_SYSROOT_DIR), then we : +# +# * Import the header files from the default architecture +# variant. Header files are typically shared between the sysroots +# for the different architecture variants. If we use the +# non-default one, header files were not copied by the previous +# step, so we copy them here from the sysroot of the default +# architecture variant. +# +# * Create a symbolic link that matches the name of the subdirectory +# for the architecture variant in the original sysroot. This is +# required as the compiler will by default look in +# sysroot_dir/arch_variant/ for libraries and headers, when the +# non-default architecture variant is used. Without this, the +# compiler fails to find libraries and headers. +# +# $1: main sysroot directory of the toolchain +# $2: arch specific sysroot directory of the toolchain +# $3: arch specific subdirectory in the sysroot # copy_toolchain_sysroot = \ SYSROOT_DIR="$(strip $1)"; \ - cp -a $${SYSROOT_DIR}/* $(STAGING_DIR)/ ; \ + ARCH_SYSROOT_DIR="$(strip $2)"; \ + ARCH_SUBDIR="$(strip $3)"; \ + for i in etc lib sbin usr ; do \ + cp -a $${ARCH_SYSROOT_DIR}/$$i $(STAGING_DIR)/ ; \ + done ; \ + if [ `readlink -f $${SYSROOT_DIR}` != `readlink -f $${ARCH_SYSROOT_DIR}` ] ; then \ + if [ ! -d $${ARCH_SYSROOT_DIR}/usr/include ] ; then \ + cp -a $${SYSROOT_DIR}/usr/include $(STAGING_DIR)/usr ; \ + fi ; \ + ln -s . $(STAGING_DIR)/$(ARCH_SUBDIR) ; \ + fi ; \ find $(STAGING_DIR) -type d | xargs chmod 755 #
@@ -208,7 +253,30 @@ ifeq ($(BR2_INSTALL_LIBSTDCPP),y) EXTERNAL_LIBS+=libstdc++.so endif +# SYSROOT_DIR selection. We first try the -print-sysroot option, +# available in gcc 4.4.x and in some Codesourcery toolchains. If this +# option is not available, we fallback to the value of --with-sysroot +# as visible in CROSS-gcc -v. We don't pass the -march= option to gcc +# as we want the "main" sysroot, which contains all variants of the C +# library in the case of multilib toolchains. +SYSROOT_DIR=$(shell $(TARGET_CC) -print-sysroot 2>/dev/null) +ifeq ($(SYSROOT_DIR),) SYSROOT_DIR=$(shell readlink -f $$(LANG=C $(TARGET_CC) -print-file-name=libc.a |sed -r -e 's:usr/lib/libc\.a::;')) +endif + +# Now, find if the toolchain specifies a sub-directory for the +# specific architecture variant we're interested in. This is the case +# with multilib toolchain, when the selected architecture variant is +# not the default one. To do so, we ask the compiler by passing the +# appropriate -march= flags. ARCH_SUBDIR will contain the +# subdirectory, in the main SYSROOT_DIR, that corresponds to the +# selected architecture variant. ARCH_SYSROOT_DIR will contain the +# full path to this location. +ifneq ($(CC_TARGET_ARCH_),) +TARGET_CC_ARCH_CFLAGS+=-march=$(CC_TARGET_ARCH_) +endif +ARCH_SUBDIR=$(shell $(TARGET_CC) $(TARGET_CC_ARCH_CFLAGS) -print-multi-directory) +ARCH_SYSROOT_DIR=$(SYSROOT_DIR)/$(ARCH_SUBDIR) $(STAMP_DIR)/ext-toolchain-installed: @echo "Checking external toolchain settings"
@@ -228,8 +296,8 @@ endif mkdir -p $(TARGET_DIR)/lib @echo "Copy external toolchain libraries to target..." $(Q)for libs in $(EXTERNAL_LIBS); do \ - $(call copy_toolchain_lib_root,$(SYSROOT_DIR),$$libs,/lib,$(BR2_TOOLCHAIN_EXTERNAL_STRIP)); \ + $(call copy_toolchain_lib_root,$(ARCH_SYSROOT_DIR),$$libs,$(BR2_TOOLCHAIN_EXTERNAL_STRIP)); \ done @echo "Copy external toolchain sysroot to staging..." - $(Q)$(call copy_toolchain_sysroot,$(SYSROOT_DIR)) + $(Q)$(call copy_toolchain_sysroot,$(SYSROOT_DIR),$(ARCH_SYSROOT_DIR),$(ARCH_SUBDIR)) @touch $@
Signature · 1 line
1.6.3.3
PATCH 4/4 busybox: make sure architecture flags are used at link time
In reply to Thomas PetazzoniWhen compiling Busybox, according to readelf -A, all object files were properly compiled according to the select architecture (-march=armv4t for example), but the final busybox binary could be of a different architecture (ARMv5t even if ARMv4t was selected).
This patch changes the way we configure/compile Busybox so that our CFLAGS aren't anymore passed through the make EXTRA_CFLAGS variable, but through the .config CONFIG_EXTRA_CFLAGS variable. Unfortunately, those variables don't have exactly the same semantic for the Busybox build system.
--- package/busybox/busybox-1.13.x.config | 1 + package/busybox/busybox.mk | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-)
package/busybox/busybox-1.13.x.config +1 -0
@@ -47,6 +47,7 @@ CONFIG_FEATURE_SYSLOG=y # CONFIG_FEATURE_SHARED_BUSYBOX is not set # CONFIG_LFS is not set CONFIG_CROSS_COMPILER_PREFIX="" +CONFIG_EXTRA_CFLAGS="" # # Debugging Options
package/busybox/busybox.mk +4 -4
@@ -45,6 +45,8 @@ $(BUSYBOX_DIR)/.config: $(BUSYBOX_DIR)/.unpacked $(BUSYBOX_CONFIG_FILE) cp -f $(BUSYBOX_CONFIG_FILE) $(BUSYBOX_DIR)/.config $(SED) s,^CONFIG_PREFIX=.*,CONFIG_PREFIX=\"$(TARGET_DIR)\", \ $(BUSYBOX_DIR)/.config + $(SED) 's,^CONFIG_EXTRA_CFLAGS=.*,CONFIG_EXTRA_CFLAGS=\"$(BUSYBOX_CFLAGS)\",' \ + $(BUSYBOX_DIR)/.config # id applet breaks on >=1.13.0 with old uclibc unless the bb pwd routines are used ifeq ($(BR2_BUSYBOX_VERSION_1_13_X)$(BR2_BUSYBOX_VERSION_1_14_X)$(BR2_UCLIBC_VERSION_0_9_28_3)$(BR2_UCLIBC_VERSION_0_9_29),yy) if grep -q 'CONFIG_ID=y' $(BUSYBOX_DIR)/.config; \
@@ -105,15 +107,13 @@ endif $(BUSYBOX_DIR)/busybox: $(BUSYBOX_DIR)/.config $(MAKE) CC=$(TARGET_CC) CROSS_COMPILE="$(TARGET_CROSS)" \ CROSS="$(TARGET_CROSS)" PREFIX="$(TARGET_DIR)" \ - ARCH=$(KERNEL_ARCH) \ - EXTRA_CFLAGS="$(BUSYBOX_CFLAGS)" -C $(BUSYBOX_DIR) + ARCH=$(KERNEL_ARCH) -C $(BUSYBOX_DIR) $(TARGET_DIR)/bin/busybox: $(BUSYBOX_DIR)/busybox ifeq ($(BR2_PACKAGE_BUSYBOX_FULLINSTALL),y) $(MAKE) CC=$(TARGET_CC) CROSS_COMPILE="$(TARGET_CROSS)" \ CROSS="$(TARGET_CROSS)" PREFIX="$(TARGET_DIR)" \ - ARCH=$(KERNEL_ARCH) \ - EXTRA_CFLAGS="$(BUSYBOX_CFLAGS)" -C $(BUSYBOX_DIR) install + ARCH=$(KERNEL_ARCH) -C $(BUSYBOX_DIR) install else install -D -m 0755 $(BUSYBOX_DIR)/busybox $(TARGET_DIR)/bin/busybox endif
Signature · 1 line
1.6.3.3
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Thomas" == Thomas Petazzoni <[email protected]> writes:
Thomas> Hello,
Thomas> Here is a resend of my CodeSourcery external toolchain support patch Thomas> set. I've fixed the merge conflict that Peter had, which was the only Thomas> feedback I received on this patchset.
Pulled and pushed, thanks!
Signature · 1 line
Bye, Peter Korsgaard