Fix variables passing to gdb configure scripts

These changes mainly fix static linking errors when building static
native gdb and gdbserver (tested with gcc 7.2.0 + uClibc-ng 1.0.27 +
binutils 2.29.1 for MIPS):

[ALL  ]    .../lib/libstdc++.a(eh_throw.o): In function `__cxa_throw':
[ALL  ]    (.text.__cxa_throw+0x64): undefined reference to `_Unwind_RaiseException'
[ALL  ]    (.text.__cxa_throw+0x6c): undefined reference to `_Unwind_RaiseException'
[ALL  ]    .../lib/libstdc++.a(eh_throw.o): In function `__cxa_rethrow':
[ALL  ]    (.text.__cxa_rethrow+0x78): undefined reference to `_Unwind_Resume_or_Rethrow'
[ALL  ]    (.text.__cxa_rethrow+0x80): undefined reference to `_Unwind_Resume_or_Rethrow'
...

The problem is in mixing of CPP, CC, CXX, and LD with CPPFLAGS, CFLAGS,
CXXFLAGS, and LDFLAGS before passing to configure scripts.
gcc is sensitive to argument order and the scripts are normally responsible
to combine the variables in a proper way.

Signed-off-by: Sergey Korolev <s.korolev@ndmsystems.com>
This commit is contained in:
Sergey Korolev 2017-12-14 08:27:03 +03:00
parent 01e329051e
commit 70a1584e15

View File

@ -11,6 +11,19 @@ do_debug_gdb_extract() {
do_debug_gdb_build() { do_debug_gdb_build() {
local -a extra_config local -a extra_config
# These variables should be global and shared between all packages.
local CT_TARGET_CPP="${CT_TARGET}-cpp"
local CT_TARGET_CC="${CT_TARGET}-gcc"
local CT_TARGET_CXX="${CT_TARGET}-g++"
local CT_TARGET_LD="${CT_TARGET}-ld"
local CT_HOST_CPP="${CT_HOST}-cpp"
local CT_HOST_CC="${CT_HOST}-gcc"
local CT_HOST_CXX="${CT_HOST}-g++"
local CT_HOST_LD="${CT_HOST}-ld"
local CT_CXXFLAGS_FOR_HOST=${CT_CFLAGS_FOR_HOST}
local CT_TARGET_CXXFLAGS=${CT_TARGET_CFLAGS}
gdb_src_dir="${CT_SRC_DIR}/gdb" gdb_src_dir="${CT_SRC_DIR}/gdb"
if [ "${CT_GDB_HAS_PKGVERSION_BUGURL}" = "y" ]; then if [ "${CT_GDB_HAS_PKGVERSION_BUGURL}" = "y" ]; then
@ -21,6 +34,7 @@ do_debug_gdb_build() {
if [ "${CT_GDB_CROSS}" = "y" ]; then if [ "${CT_GDB_CROSS}" = "y" ]; then
local -a cross_extra_config local -a cross_extra_config
local gcc_version p _p local gcc_version p _p
local cross_CPPFLAGS cross_CFLAGS cross_CXXFLAGS cross_LDFLAGS
CT_DoStep INFO "Installing cross-gdb" CT_DoStep INFO "Installing cross-gdb"
CT_DoLog EXTRA "Configuring cross-gdb" CT_DoLog EXTRA "Configuring cross-gdb"
@ -46,6 +60,7 @@ do_debug_gdb_build() {
none) cross_extra_config+=("--disable-threads");; none) cross_extra_config+=("--disable-threads");;
*) cross_extra_config+=("--enable-threads");; *) cross_extra_config+=("--enable-threads");;
esac esac
if [ "${CT_GDB_CROSS_PYTHON}" = "y" ]; then if [ "${CT_GDB_CROSS_PYTHON}" = "y" ]; then
if [ -z "${CT_GDB_CROSS_PYTHON_BINARY}" ]; then if [ -z "${CT_GDB_CROSS_PYTHON_BINARY}" ]; then
for p in python python3 python2; do for p in python python3 python2; do
@ -64,29 +79,33 @@ do_debug_gdb_build() {
else else
cross_extra_config+=("--with-python=no") cross_extra_config+=("--with-python=no")
fi fi
if [ "${CT_GDB_CROSS_SIM}" = "y" ]; then if [ "${CT_GDB_CROSS_SIM}" = "y" ]; then
cross_extra_config+=("--enable-sim") cross_extra_config+=("--enable-sim")
else else
cross_extra_config+=("--disable-sim") cross_extra_config+=("--disable-sim")
fi fi
if [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ]; then if [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ]; then
cross_extra_config+=("--disable-nls") cross_extra_config+=("--disable-nls")
fi fi
CPP_for_gdb="${CT_HOST}-cpp ${CT_CFLAGS_FOR_HOST}" cross_CPPFLAGS="${CT_CPPFLAGS_FOR_HOST}"
CC_for_gdb="${CT_HOST}-gcc ${CT_CFLAGS_FOR_HOST} ${CT_LDFLAGS_FOR_HOST}" cross_CFLAGS="${CT_CFLAGS_FOR_HOST}"
CXX_for_gdb="${CT_HOST}-g++ ${CT_CFLAGS_FOR_HOST} ${CT_LDFLAGS_FOR_HOST}" cross_CXXFLAGS="${CT_CXXFLAGS_FOR_HOST}"
LD_for_gdb="${CT_HOST}-ld ${CT_LDFLAGS_FOR_HOST}" cross_LDFLAGS="${CT_LDFLAGS_FOR_HOST}"
if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
CC_for_gdb+=" -static" cross_CFLAGS+=("-static")
CXX_for_gdb+=" -static" cross_CXXFLAGS+=("-static")
LD_for_gdb+=" -static" cross_LDFLAGS+=("-static")
fi fi
case "${CT_HOST}" in case "${CT_HOST}" in
*darwin*) *darwin*)
# FIXME: Really, we should be testing for host compiler being clang. # FIXME: Really, we should be testing for host compiler being clang.
CC_for_gdb+=" -Qunused-arguments" cross_CFLAGS+=("-Qunused-arguments")
CXX_for_gdb+=" -Qunused-arguments" cross_CXXFLAGS+=("-Qunused-arguments")
# clang detects the line from gettext's _ macro as format string # clang detects the line from gettext's _ macro as format string
# not being a string literal and produces a lot of warnings - which # not being a string literal and produces a lot of warnings - which
# ct-ng's logger faithfully relays to user if this happens in the # ct-ng's logger faithfully relays to user if this happens in the
@ -99,10 +118,10 @@ do_debug_gdb_build() {
# are multiple consecutive spaces: sub-configure scripts replace them with a # are multiple consecutive spaces: sub-configure scripts replace them with a
# single space and then complain that $CC value changed from that in # single space and then complain that $CC value changed from that in
# the master directory. # the master directory.
CPP_for_gdb=`echo $CPP_for_gdb` cross_CPPFLAGS=`echo ${cross_CPPFLAGS}`
CC_for_gdb=`echo $CC_for_gdb` cross_CFLAGS=`echo ${cross_CFLAGS}`
CXX_for_gdb=`echo $CXX_for_gdb` cross_CXXFLAGS=`echo ${cross_CXXFLAGS}`
LD_for_gdb=`echo $LD_for_gdb` cross_LDFLAGS=`echo ${cross_LDFLAGS}`
# Disable binutils options when building from the binutils-gdb repo. # Disable binutils options when building from the binutils-gdb repo.
cross_extra_config+=("--disable-binutils") cross_extra_config+=("--disable-binutils")
@ -112,13 +131,14 @@ do_debug_gdb_build() {
CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'" CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
CT_DoExecLog CFG \ CT_DoExecLog CFG \
CC_FOR_BUILD="${CT_BUILD}-gcc" \ CPP="${CT_HOST_CPP}" \
CFLAGS_FOR_BUILD="${CT_CFLAGS_FOR_BUILD}" \ CC="${CT_HOST_CC}" \
LDFLAGS_FOR_BUILD="${CT_LDFLAGS_FOR_BUILD}" \ CXX="${CT_HOST_CXX}" \
CPP="${CPP_for_gdb}" \ LD="${CT_HOST_LD}" \
CC="${CC_for_gdb}" \ CPPFLAGS="${cross_CPPFLAGS}" \
CXX="${CXX_for_gdb}" \ CFLAGS="${cross_CFLAGS}" \
LD="${LD_for_gdb}" \ CXXFLAGS="${cross_CXXFLAGS}" \
LDFLAGS="${cross_LDFLAGS}" \
${CONFIG_SHELL} \ ${CONFIG_SHELL} \
"${gdb_src_dir}/configure" \ "${gdb_src_dir}/configure" \
--build=${CT_BUILD} \ --build=${CT_BUILD} \
@ -167,8 +187,13 @@ do_debug_gdb_build() {
# TBD combine GDB native and gdbserver backends, build either or both in a single pass. # TBD combine GDB native and gdbserver backends, build either or both in a single pass.
if [ "${CT_GDB_NATIVE}" = "y" ]; then if [ "${CT_GDB_NATIVE}" = "y" ]; then
local -a native_extra_config local -a native_extra_config
local native_CPPFLAGS native_CFLAGS native_CXXFLAGS native_LDFLAGS
CT_DoStep INFO "Installing native gdb" CT_DoStep INFO "Installing native gdb"
CT_DoLog EXTRA "Configuring native gdb"
mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
cd "${CT_BUILD_DIR}/build-gdb-native"
native_extra_config=("${extra_config[@]}") native_extra_config=("${extra_config[@]}")
@ -201,32 +226,25 @@ do_debug_gdb_build() {
native_extra_config+=("--with-expat") native_extra_config+=("--with-expat")
native_extra_config+=("--without-libexpat-prefix") native_extra_config+=("--without-libexpat-prefix")
CT_DoLog EXTRA "Configuring native gdb"
mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
cd "${CT_BUILD_DIR}/build-gdb-native"
case "${CT_THREADS}" in case "${CT_THREADS}" in
none) native_extra_config+=("--disable-threads");; none) native_extra_config+=("--disable-threads");;
*) native_extra_config+=("--enable-threads");; *) native_extra_config+=("--enable-threads");;
esac esac
[ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && \ if [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ]; then
native_extra_config+=("--disable-nls") native_extra_config+=("--disable-nls")
CPP_for_gdb="${CT_TARGET}-cpp ${CT_TARGET_CFLAGS}"
CC_for_gdb="${CT_TARGET}-${CT_CC} ${CT_TARGET_CFLAGS} ${CT_TARGET_LDFLAGS}"
CXX_for_gdb="${CT_TARGET}-g++ ${CT_TARGET_CFLAGS} ${CT_TARGET_LDFLAGS}"
LD_for_gdb="${CT_TARGET}-ld ${CT_TARGET_LDFLAGS}"
if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
CC_for_gdb+=" -static"
CXX_for_gdb+=" -static"
LD_for_gdb+=" -static"
fi fi
CPP_for_gdb=`echo $CPP_for_gdb`
CC_for_gdb=`echo $CC_for_gdb` native_CPPFLAGS="${CT_TARGET_CPPFLAGS}"
CXX_for_gdb=`echo $CXX_for_gdb` native_CFLAGS="${CT_TARGET_CFLAGS}"
LD_for_gdb=`echo $LD_for_gdb` native_CXXFLAGS="${CT_TARGET_CXXFLAGS}"
native_LDFLAGS="${CT_TARGET_LDFLAGS}"
if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
native_CFLAGS+=("-static")
native_CXXFLAGS+=("-static")
native_LDFLAGS+=("-static")
fi
export ac_cv_func_strncmp_works=yes export ac_cv_func_strncmp_works=yes
@ -235,16 +253,22 @@ do_debug_gdb_build() {
native_extra_config+=("--disable-ld") native_extra_config+=("--disable-ld")
native_extra_config+=("--disable-gas") native_extra_config+=("--disable-gas")
native_CPPFLAGS=`echo ${native_CPPFLAGS}`
native_CFLAGS=`echo ${native_CFLAGS}`
native_CXXFLAGS=`echo ${native_CXXFLAGS}`
native_LDFLAGS=`echo ${native_LDFLAGS}`
CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'" CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
CT_DoExecLog CFG \ CT_DoExecLog CFG \
CC_FOR_BUILD="${CT_BUILD}-gcc" \ CPP="${CT_TARGET_CPP}" \
CFLAGS_FOR_BUILD="${CT_CFLAGS_FOR_BUILD}" \ CC="${CT_TARGET_CC}" \
LDFLAGS_FOR_BUILD="${CT_LDFLAGS_FOR_BUILD}" \ CXX="${CT_TARGET_CXX}" \
CPP="${CPP_for_gdb}" \ LD="${CT_TARGET_LD}" \
CC="${CC_for_gdb}" \ CPPFLAGS="${native_CPPFLAGS}" \
CXX="${CXX_for_gdb}" \ CFLAGS="${native_CFLAGS}" \
LD="${LD_for_gdb}" \ CXXFLAGS="${native_CXXFLAGS}" \
LDFLAGS="${native_LDFLAGS}" \
${CONFIG_SHELL} \ ${CONFIG_SHELL} \
"${gdb_src_dir}/configure" \ "${gdb_src_dir}/configure" \
--build=${CT_BUILD} \ --build=${CT_BUILD} \
@ -278,7 +302,7 @@ do_debug_gdb_build() {
if [ "${CT_GDB_GDBSERVER}" = "y" ]; then if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
local -a gdbserver_extra_config local -a gdbserver_extra_config
local gdbserver_LDFLAGS local gdbserver_CPPFLAGS gdbserver_CFLAGS gdbserver_CXXFLAGS gdbserver_LDFLAGS
CT_DoStep INFO "Installing gdbserver" CT_DoStep INFO "Installing gdbserver"
CT_DoLog EXTRA "Configuring gdbserver" CT_DoLog EXTRA "Configuring gdbserver"
@ -291,15 +315,6 @@ do_debug_gdb_build() {
# Bah, GNU folks strike again... :-( # Bah, GNU folks strike again... :-(
chmod +x "${gdb_src_dir}/gdb/gdbserver/configure" chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
gdbserver_LDFLAGS=
if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
gdbserver_LDFLAGS=-static
fi
if [ "${CT_GDB_GDBSERVER_STATIC_LIBSTDCXX}" = "y" ]; then
gdbserver_LDFLAGS+=" -static-libstdc++"
fi
gdbserver_extra_config=("${extra_config[@]}") gdbserver_extra_config=("${extra_config[@]}")
# We may not have C++ language configured for target # We may not have C++ language configured for target
@ -309,9 +324,9 @@ do_debug_gdb_build() {
if [ "${CT_GDB_GDBSERVER_HAS_IPA_LIB}" = "y" ]; then if [ "${CT_GDB_GDBSERVER_HAS_IPA_LIB}" = "y" ]; then
if [ "${CT_GDB_GDBSERVER_BUILD_IPA_LIB}" = "y" ]; then if [ "${CT_GDB_GDBSERVER_BUILD_IPA_LIB}" = "y" ]; then
gdbserver_extra_config+=( --enable-inprocess-agent ) gdbserver_extra_config+=("--enable-inprocess-agent")
else else
gdbserver_extra_config+=( --disable-inprocess-agent ) gdbserver_extra_config+=("--disable-inprocess-agent")
fi fi
fi fi
@ -320,23 +335,34 @@ do_debug_gdb_build() {
gdbserver_extra_config+=("--disable-ld") gdbserver_extra_config+=("--disable-ld")
gdbserver_extra_config+=("--disable-gas") gdbserver_extra_config+=("--disable-gas")
CPP_for_gdb="${CT_TARGET}-cpp ${CT_TARGET_CFLAGS}" gdbserver_CPPFLAGS="${CT_TARGET_CPPFLAGS}"
CC_for_gdb="${CT_TARGET}-${CT_CC} ${CT_TARGET_CFLAGS} ${CT_TARGET_LDFLAGS}" gdbserver_CFLAGS="${CT_TARGET_CFLAGS}"
CXX_for_gdb="${CT_TARGET}-g++ ${CT_TARGET_CFLAGS} ${CT_TARGET_LDFLAGS}" gdbserver_CXXFLAGS="${CT_TARGET_CXXFLAGS}"
LD_for_gdb="${CT_TARGET}-ld ${CT_TARGET_LDFLAGS}" gdbserver_LDFLAGS="${CT_TARGET_LDFLAGS}"
CPP_for_gdb=`echo $CPP_for_gdb`
CC_for_gdb=`echo $CC_for_gdb` if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
CXX_for_gdb=`echo $CXX_for_gdb` gdbserver_LDFLAGS+=("-static")
LD_for_gdb=`echo $LD_for_gdb` fi
if [ "${CT_GDB_GDBSERVER_STATIC_LIBSTDCXX}" = "y" ]; then
gdbserver_LDFLAGS+=("-static-libstdc++")
fi
gdbserver_CPPFLAGS=`echo ${gdbserver_CPPFLAGS}`
gdbserver_CFLAGS=`echo ${gdbserver_CFLAGS}`
gdbserver_CXXFLAGS=`echo ${gdbserver_CXXFLAGS}`
gdbserver_LDFLAGS=`echo ${gdbserver_LDFLAGS}`
CT_DoLog DEBUG "Extra config passed: '${gdbserver_extra_config[*]}'"
CT_DoExecLog CFG \ CT_DoExecLog CFG \
CC_FOR_BUILD="${CT_BUILD}-gcc" \ CPP="${CT_TARGET_CPP}" \
CFLAGS_FOR_BUILD="${CT_CFLAGS_FOR_BUILD}" \ CC="${CT_TARGET_CC}" \
LDFLAGS_FOR_BUILD="${CT_LDFLAGS_FOR_BUILD}" \ CXX="${CT_TARGET_CXX}" \
CPP="${CPP_for_gdb}" \ LD="${CT_TARGET_LD}" \
CC="${CC_for_gdb}" \ CPPFLAGS="${gdbserver_CPPFLAGS}" \
CXX="${CXX_for_gdb}" \ CFLAGS="${gdbserver_CFLAGS}" \
LD="${LD_for_gdb}" \ CXXFLAGS="${gdbserver_CXXFLAGS}" \
LDFLAGS="${gdbserver_LDFLAGS}" \ LDFLAGS="${gdbserver_LDFLAGS}" \
${CONFIG_SHELL} \ ${CONFIG_SHELL} \
"${gdb_src_dir}/gdb/gdbserver/configure" \ "${gdb_src_dir}/gdb/gdbserver/configure" \