From a596ec5b39f900b1f4b481cc46afd20b0e5457d2 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sun, 26 Mar 2017 23:32:27 -0700 Subject: Fix up the sysroot issue for sh4 in a different way (see the comments in the code for details on the issue) Old workaround in 100-gcc.sh stopped working (probably, due to one of GCC version upgrades), so switch to the other approach originally described there: adjust the list of multilibs to not include the default target explicitly. Signed-off-by: Alexey Neyman diff --git a/samples/sh4-multilib-linux-gnu/crosstool.config b/samples/sh4-multilib-linux-gnu/crosstool.config index 56af7bf..2055126 100644 --- a/samples/sh4-multilib-linux-gnu/crosstool.config +++ b/samples/sh4-multilib-linux-gnu/crosstool.config @@ -3,7 +3,7 @@ CT_ARCH_SH_SH4=y CT_TARGET_VENDOR="multilib" CT_KERNEL_linux=y CT_BINUTILS_PLUGINS=y -CT_CC_GCC_MULTILIB_LIST="m4,m4a" +CT_CC_GCC_MULTILIB_LIST="m4a" CT_CC_LANG_CXX=y CT_DEBUG_gdb=y # CT_GDB_CROSS_PYTHON is not set diff --git a/samples/sh4-multilib-linux-uclibc/crosstool.config b/samples/sh4-multilib-linux-uclibc/crosstool.config index 26ad038..2c61643 100644 --- a/samples/sh4-multilib-linux-uclibc/crosstool.config +++ b/samples/sh4-multilib-linux-uclibc/crosstool.config @@ -5,7 +5,7 @@ CT_KERNEL_linux=y CT_BINUTILS_PLUGINS=y CT_LIBC_uClibc=y CT_CC_GCC_V_4_9_4=y -CT_CC_GCC_MULTILIB_LIST="m4,m4a,m3" +CT_CC_GCC_MULTILIB_LIST="m4a,m3" CT_CC_LANG_CXX=y CT_DEBUG_gdb=y # CT_GDB_CROSS_PYTHON is not set diff --git a/scripts/build/arch.sh b/scripts/build/arch.sh index 75d3e21..5a8d84c 100644 --- a/scripts/build/arch.sh +++ b/scripts/build/arch.sh @@ -5,6 +5,11 @@ CT_DoArchTupleValues() { :; } +# Adjust the list of multilibs for the target +CT_DoArchMultilibList() { + :; +} + # Multilib: change the target triplet according to CFLAGS # Usage: CT_DoArchGlibcAdjustTuple CT_DoArchMultilibTarget() { @@ -43,7 +48,7 @@ CT_DoArchUClibcCflags() { # Likely, any non-default cflags need to be reflected into the config. # It may work if we just pass them into EXTRA_CFLAGS, but we have no - # idea as they might interact with the CFLAGS inferred by uClibc from + # idea how they might interact with the CFLAGS inferred by uClibc from # the configuration file. if [ "${cflags}" != "" ]; then CT_DoLog WARN "Multilib configuration not supported for uClibc/${CT_ARCH}" diff --git a/scripts/build/arch/sh.sh b/scripts/build/arch/sh.sh index 6761435..59bc08a 100644 --- a/scripts/build/arch/sh.sh +++ b/scripts/build/arch/sh.sh @@ -36,6 +36,29 @@ CT_DoArchTupleValues () { CT_ARCH_FLOAT_CFLAG= } +CT_DoArchMultilibList() { + local save_ifs="${IFS}" + local new + local x + + # In a configuration for SuperH, GCC list of multilibs shall not include + # the default CPU. E.g. if configuring for sh4-*-*, we need to remove + # "sh4" or "m4" from the multilib list. Otherwise, the resulting compiler + # will fail when that CPU is selected explicitly "sh4-multilib-linux-gnu-gcc -m4 ..." + # as it will fail to find the sysroot with that suffix. + IFS=, + for x in ${CT_CC_GCC_MULTILIB_LIST}; do + if [ "${x}" = "${CT_ARCH_SH_VARIANT}" -o "sh${x#m}" = "${CT_ARCH_SH_VARIANT}" ]; then + CT_DoLog WARN "Ignoring '${x}' in multilib list: it is the default multilib" + continue + fi + new="${new:+${new},}${x}" + done + IFS="${save_ifs}" + CT_CC_GCC_MULTILIB_LIST="${new}" + CT_DoLog DEBUG "Adjusted CT_CC_GCC_MULTILIB_LIST to '${CT_CC_GCC_MULTILIB_LIST}'" +} + CT_DoArchUClibcConfig() { local cfg="${1}" diff --git a/scripts/build/cc/100-gcc.sh b/scripts/build/cc/100-gcc.sh index 5743c08..f7c1a9c 100644 --- a/scripts/build/cc/100-gcc.sh +++ b/scripts/build/cc/100-gcc.sh @@ -73,23 +73,6 @@ cc_gcc_lang_list() { } #------------------------------------------------------------------------------ -# Return a value of a requested GCC spec -cc_gcc_get_spec() { - local spec=$1 - local cc_and_cflags=$2 - - # GCC does not provide a facility to request a value of a spec string. - # The only way to do that I found was to augment the spec file with - # some dummy suffix handler that does nothing except printing it. - touch temp-input.spec_eval - { - echo ".spec_eval:" - echo "echo %(${spec})" - } > "tmp-specs-${spec}" - ${cc_and_cflags} -specs="tmp-specs-${spec}" -E temp-input.spec_eval -} - -#------------------------------------------------------------------------------ # Report the type of a GCC option cc_gcc_classify_opt() { # Options present in multiple architectures @@ -168,30 +151,16 @@ evaluate_multilib_cflags() # is disabled - so that it lists the default GCC/OS directory, which may differ # from the default 'lib'). It then performs a few multilib checks/quirks: # -# 1. On SuperH target, configuring with default CPU (e.g. by supplying the target -# name as 'sh4', which is what CT-NG does) results in the compiler being unable to -# run if that same switch is passed to the resulting gcc (e.g. 'gcc -m4'). The reason -# for this behavior is that the script that determines the sysroot suffix is not -# aware of the default multilib selection, so it generates /m4 as the -# suffixed sysroot. But the main driver, knowing that -m4 is the default, does not -# even attempt to fall back to the non-suffixed sysroot (as it does with non-default -# multilibs) - as a result, gcc fails to find any library if invoked with -m4. -# The right solution would be to drop the default CPU from the multilib list -# completely, or make the print-sysroot-suffix.sh script aware of the defaults -# (which is not easy, as the defaults are not in tmake_file, but rather in tm_file...) -# -# 2. On MIPS target, gcc (or rather, ld, which it invokes under the hood) chokes +# 1. On MIPS target, gcc (or rather, ld, which it invokes under the hood) chokes # if supplied with two -mabi=* options. I.e., 'gcc -mabi=n32' and 'gcc -mabi=32' both # work, but 'gcc -mabi=32 -mabi=n32' produces an internal error in ld. Thus we do # not supply target's CFLAGS in multilib builds - and after compiling pass-1 gcc, # attempt to determine which CFLAGS need to be filtered out. # -# 3. If "demultilibing" is in effect, create top-level directories for any +# 2. If "demultilibing" is in effect, create top-level directories for any # multilibs not in lib/ as symlinks to lib. cc_gcc_multilib_housekeeping() { local cc host - local multilib_defaults - local suffix sysroot base lnk local ml_arch ml_abi ml_cpu ml_tune ml_fpu ml_float ml_endian ml_mode ml_unknown ml local new_cflags @@ -207,10 +176,6 @@ cc_gcc_multilib_housekeeping() { cc="${CT_BUILDTOOLS_PREFIX_DIR}/bin/${CT_TARGET}-${CT_CC}" fi - # sed: prepend dashes or do nothing if default is empty string - multilib_defaults=( $( cc_gcc_get_spec multilib_defaults "${cc}" | \ - sed 's/\(^\|[[:space:]]\+\)\([^[:space:]]\)/ -\2/g' ) ) - CT_DoLog EXTRA "gcc default flags: '${multilib_defaults}'" CT_IterateMultilibs evaluate_multilib_cflags evaluate_cflags # Filtering out some of the options provided in CT-NG config. Then *prepend* @@ -236,21 +201,6 @@ cc_gcc_multilib_housekeeping() { CT_EnvModify CT_ARCH_TARGET_LDFLAGS_MULTILIB "" fi CT_DoLog DEBUG "Filtered target LDFLAGS: '${CT_ARCH_TARGET_LDFLAGS_MULTILIB}'" - - # Sysroot suffix fixup for the multilib default. - suffix=$( cc_gcc_get_spec sysroot_suffix_spec "${cc} ${multilib_defaults}" ) - if [ -n "${suffix}" ]; then - base=${suffix%/*} - sysroot=$( "${cc}" -print-sysroot ) - if [ -n "${base}" ]; then - CT_DoExecLog ALL mkdir -p "${sysroot}${base}" - lnk=$( echo "${base#/}" | sed -e 's,[^/]*,..,g' ) - else - lnk=. - fi - CT_DoExecLog ALL rm -f "${sysroot}${suffix}" - CT_DoExecLog ALL ln -sfv "${lnk}" "${sysroot}${suffix}" - fi } #------------------------------------------------------------------------------ diff --git a/scripts/crosstool-NG.sh.in b/scripts/crosstool-NG.sh.in index 368f9d2..0b20fe3 100644 --- a/scripts/crosstool-NG.sh.in +++ b/scripts/crosstool-NG.sh.in @@ -231,6 +231,9 @@ CT_SYS_GCC=$(${CT_BUILD_PREFIX}gcc${CT_BUILD_SUFFIX} -dumpversion) CT_SYS_TARGET=$(CT_DoConfigGuess) CT_TOOLCHAIN_ID="crosstool-${CT_VERSION} build ${CT_STAR_DATE_HUMAN} by ${CT_SYS_USER}@${CT_SYS_HOSTNAME}" +# Adjust the list of multilibs, if needed +CT_DoArchMultilibList + CT_DoLog EXTRA "Preparing working directories" # Ah! The build directory shall be eradicated, even if we restart! -- cgit v0.10.2-6-g49f6