Skip to content

Commit

Permalink
Merge pull request #662 from stilor/sh-multilib
Browse files Browse the repository at this point in the history
Fix up the sysroot issue for sh4 in a different way
  • Loading branch information
stilor committed Mar 27, 2017
2 parents de13661 + a596ec5 commit 32909ec
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 55 deletions.
2 changes: 1 addition & 1 deletion samples/sh4-multilib-linux-gnu/crosstool.config
Expand Up @@ -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
2 changes: 1 addition & 1 deletion samples/sh4-multilib-linux-uclibc/crosstool.config
Expand Up @@ -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
7 changes: 6 additions & 1 deletion scripts/build/arch.sh
Expand Up @@ -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 <variable-name> <CFLAGS>
CT_DoArchMultilibTarget() {
Expand Down Expand Up @@ -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}"
Expand Down
23 changes: 23 additions & 0 deletions scripts/build/arch/sh.sh
Expand Up @@ -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}"

Expand Down
54 changes: 2 additions & 52 deletions scripts/build/cc/100-gcc.sh
Expand Up @@ -72,23 +72,6 @@ cc_gcc_lang_list() {
printf "%s" "${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() {
Expand Down Expand Up @@ -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 <sysroot>/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

Expand All @@ -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*
Expand All @@ -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
}

#------------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions scripts/crosstool-NG.sh.in
Expand Up @@ -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!
Expand Down

0 comments on commit 32909ec

Please sign in to comment.