Skip to content

Commit a5397e7

Browse files
Build native gdb automatically
We always used to build gdbserver for ARC, but automatic building of full GDB hasn't been implemented. This patch replaced old-schoold gdbserver build with a new shiny process, that will build both GDB and gdbserver. GDB requires ncurses - that is build automatically. Native GDB build can be disabled via option --no-native-gdb. In the latter case GDBserver still will be built - it doesn't need any external dependencies, so there should be no harm in building it. Note that we used to build gdbserver with static linkage, but now it is linked dynamically, regardless of whether native GDB is built or not. Such gdbserver will not work if there is an error in dynamic linker - gdbserver will not start in this case. However such cases are very rare, therefore I don't think it makes sense to sacrifice 99.9% of cases for this one rare case. If somebody needs static gdbserver - they can build it manually, it's not a rocket science. Signed-off-by: Anton Kolesov <[email protected]>
1 parent 694ebed commit a5397e7

File tree

3 files changed

+129
-43
lines changed

3 files changed

+129
-43
lines changed

arc-init.sh

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,17 +434,49 @@ configure_uclibc_stage2() {
434434
fi
435435
}
436436

437+
438+
# Configure application to run on ARC, that is --host=arc-snps-linux-uclibc (or
439+
# whatever is correct for particular case).
440+
# Arguments:
441+
# $1 - source directory
442+
# $2 - target triplet
443+
# rest are passed to configure as is
444+
configure_for_arc() {
445+
echo " configuring..."
446+
447+
local srcdir=$1
448+
local triplet=$2
449+
shift 2
450+
451+
# --prefix must correspond to prefix on *target* system, not where it will
452+
# be installed on build host - prefix value might be stored somewhere in
453+
# final product, therefore stored value should be one which is valid for
454+
# target system. To install files on build host DESTDIR should be set when
455+
# calling "make install". Note - prefix is set to /usr, DESTDIR should
456+
# point to sysroot.
457+
if ! $srcdir/configure --prefix=/usr --host=$triplet \
458+
--with-pkgversion="${version_str}"\
459+
--with-bugurl="$ARC_COMMON_BUGURL" \
460+
CFLAGS="$CFLAGS_FOR_TARGET" $* \
461+
>> "$logfile" 2>&1
462+
then
463+
echo "ERROR: failed while configuring."
464+
echo "See \`$logfile' for details."
465+
exit 1
466+
fi
467+
}
468+
437469
# Arguments:
438470
# $1 - step name. It should be a gerund for proper text representation, as
439471
# "building", not "build".
440-
# remaining - make targets
472+
# remaining - make targets. Although really can be make vars as well, like "A=aa".
441473
make_target() {
442474
local step="$1"
443475
shift
444476
echo " $step..."
445477
if ! make $PARALLEL $* >> "$logfile" 2>&1
446478
then
447-
echo "ERROR: failed while $1."
479+
echo "ERROR: failed while $step."
448480
echo "See \`$logfile' for details."
449481
exit 1
450482
fi
@@ -461,7 +493,7 @@ make_target_ordered() {
461493
echo " $step..."
462494
if ! make $* >> "$logfile" 2>&1
463495
then
464-
echo "ERROR: failed while $1."
496+
echo "ERROR: failed while $step."
465497
echo "See \`$logfile' for details."
466498
exit 1
467499
fi

build-all.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
# [--nptl | --no-nptl]
5151
# [--checkout-config <config>]
5252
# [--host <triplet>]
53+
# [--native-gdb | --no-native-gdb]
5354

5455
# This script is a convenience wrapper to build the ARC GNU 4.4 tool
5556
# chains. It utilizes Joern Rennecke's build-elf32.sh script and Bendan
@@ -272,6 +273,22 @@
272273
# compile software for ARC processors. Note that this makes sense only for
273274
# baremetal (elf32) toolchain.
274275

276+
# --native-gdb | --no-native-gdb
277+
278+
# Whether to build or not to build native GDB - GDB that will run directly
279+
# on ARC Linux. Default is yes. Makes sense only for Linux toolchain
280+
# (--uclibc). Note that GDB requires ncurses, which will be built
281+
# automatically. That has several possible points of failure:
282+
# - ncurses is not part of GNU Toolchain. Its source is autodownloaded.
283+
# Build process will fail if it cannot be downloaded. If you have
284+
# problems, either use --no-native-gdb or put ncurses-5.9.tar.gz into
285+
# toolchain/_download_tmp directory.
286+
# - static ncurses libs will be installed to sysroot. You might experience
287+
# issues if you will build ncurses on your own (or via Buildroot). If that
288+
# is the case - build toolchain without native GDB, and then build GDB
289+
# manually with your ncurses. Buildroot handles this nicely.
290+
# - Due to a bug ncurses has to be built without C++ bindings.
291+
275292
# Where directories are specified as arguments, they are relative to the
276293
# current directory, unless specified as absolute names.
277294

@@ -336,6 +353,7 @@ ISA_CPU="arc700"
336353
UCLIBC_DEFCFG=""
337354
CONFIG_EXTRA=""
338355
DO_PDF="--pdf"
356+
DO_NATIVE_GDB=yes
339357
rel_rpaths="--no-rel-rpaths"
340358
DISABLEWERROR="--disable-werror"
341359
CFLAGS_FOR_TARGET=""
@@ -552,6 +570,14 @@ case ${opt} in
552570
TOOLCHAIN_HOST="$1"
553571
;;
554572

573+
--native-gdb)
574+
DO_NATIVE_GDB=yes
575+
;;
576+
577+
--no-native-gdb)
578+
DO_NATIVE_GDB=no
579+
;;
580+
555581
?*)
556582
echo "Unknown argument $1"
557583
echo
@@ -585,6 +611,7 @@ case ${opt} in
585611
echo " [--nptl | --no-nptl]"
586612
echo " [--checkout-config <config>]"
587613
echo " [--host <triplet>]"
614+
echo " [--native-gdb | --no-native-gdb]"
588615
exit 1
589616
;;
590617

@@ -741,6 +768,7 @@ export ISA_CPU
741768
export DO_SIM
742769
export CONFIG_EXTRA
743770
export DO_PDF
771+
export DO_NATIVE_GDB
744772
export PARALLEL
745773
export UCLIBC_DEFCFG
746774
export DISABLEWERROR

build-uclibc.sh

Lines changed: 66 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -541,48 +541,74 @@ done
541541
echo " finished creating symlinks"
542542

543543
# -----------------------------------------------------------------------------
544-
# gdbserver has to be built on its own.
545-
546-
echo "Building gdbserver to run on an ARC ..." | tee -a "${logfile}"
547-
echo "=======================================" >> "${logfile}"
548-
549-
build_dir_init gdbserver
550-
551-
# ARC_COMMON_BUGURL is defined in arc-init.sh, which has been source.
552-
config_path=$(calcConfigPath "${ARC_GNU}")/gdb/gdb/gdbserver
553-
if "${config_path}"/configure \
554-
--with-pkgversion="${version_str}"\
555-
--with-bugurl="$ARC_COMMON_BUGURL" \
556-
--host=${triplet} >> "${logfile}" 2>> "${logfile}"
557-
then
558-
echo " finished configuring gdbserver"
559-
else
560-
echo "ERROR: gdbserver configure failed. Please see"
561-
echo " \"${logfile}\" for details."
562-
exit 1
563-
fi
564-
565-
CC=${triplet}-gcc
566-
export CC
567-
if make ${PARALLEL} \
568-
CFLAGS="-static -fcommon -mno-sdata -O3 ${CFLAGS_FOR_TARGET}" \
569-
>> "${logfile}" 2>&1
570-
then
571-
echo " finished building gdbserver to run on an arc"
572-
else
573-
echo "ERROR: gdbserver build was not successful. Please see"
574-
echo " \"${logfile}\" for details."
575-
exit 1
576-
fi
544+
# Native GDB
545+
546+
if [ $DO_NATIVE_GDB = yes ]; then
547+
548+
# GDB needs ncurses (termcap to be exact).
549+
# Since ncurses is a separate product it is an outlier with regards of build process.
550+
echo "Building native ncurses to run on an ARC ..." | tee -a "${logfile}"
551+
552+
ncurses_version=5.9
553+
ncurses_url_base=http://ftp.gnu.org/pub/gnu/ncurses
554+
ncurses_tar=ncurses-${ncurses_version}.tar.gz
555+
ncurses_url=$ncurses_url_base/$ncurses_tar
556+
cd "$ARC_GNU/toolchain"
557+
mkdir -p _download_tmp
558+
if [ ! -s _download_tmp/$ncurses_tar ]; then
559+
wget -nv -O _download_tmp/$ncurses_tar $ncurses_url
560+
fi
577561

578-
mkdir -p ${INSTALLDIR}/target-bin
579-
if cp gdbserver ${INSTALLDIR}/target-bin
580-
then
581-
echo " finished installing gdbserver to run on an ARC"
562+
build_dir_init ncurses
563+
tar xaf $ARC_GNU/toolchain/_download_tmp/$ncurses_tar --strip-components=1
564+
# Ada is not supported on ARC, so it has to be disabled, otherwise dumb
565+
# configure script might find Ada compiler for host system and will try to
566+
# use it as a compiler for ARC.
567+
# C++ has to be disabled because of STAR9000908736 - there is an error when
568+
# linking its demo application. Otherwise there is no reason to disable C++
569+
# support.
570+
configure_for_arc . $triplet --without-cxx-binding --without-ada
571+
make_target building
572+
make_target_ordered installing install DESTDIR=$SYSROOTDIR
573+
574+
echo "Building native GDB to run on an ARC ..." | tee -a "${logfile}"
575+
576+
build_dir_init native_gdb
577+
578+
config_path=$(calcConfigPath "${ARC_GNU}")/gdb
579+
configure_for_arc "$config_path" $triplet \
580+
--disable-gas --disable-ld --disable-binutils
581+
make_target building
582+
# For reasons I do not know arc-linux-strip is ignored by install-sh, even
583+
# though gdb/Makefile sets STRIPPROG. But it installs it in some
584+
# funny/complex way, which perhaps is source of an issue. To avoid any
585+
# troubles just set STRIPPROG to arc-linux-strip. Note: STRIP is Makefile
586+
# variable; STRIPPROG is variable used by install-sh; STRIP is already set
587+
# correctly, but STRIPPROG is not.
588+
# Unforunately strip will strip complete symbol table, instead of just
589+
# debug symbols.
590+
make_target_ordered installing install-strip-gdb DESTDIR=$SYSROOTDIR \
591+
STRIPPROG=${triplet}-strip
582592
else
583-
echo "ERROR: gdbserver install was not successful. Please see"
584-
echo " \"${logfile}\" for details."
585-
exit 1
593+
# If native GDB has been disabled, then simple gdbserver still will be
594+
# built. It doesn't need ncurses.
595+
echo "Building gdbserver to run on an ARC ..." | tee -a "$logfile"
596+
597+
build_dir_init gdbserver
598+
# Static options are same as when gdbserver is configured by the top-level
599+
# configure script.
600+
config_path=$(calcConfigPath "${ARC_GNU}")/gdb/gdb/gdbserver
601+
LDFLAGS="-static-libstdc++ -static-libgcc" \
602+
configure_for_arc "$config_path" $triplet
603+
make_target building
604+
605+
# gdbserver makefile lacks install-strip target. It is possible to trick
606+
# gdbserver Makefile to install stripped binary by setting INSTAL_PROGRAM
607+
# Makefile variable to 'install -c -s', however this way gdbserver would be
608+
# stripped from all symbols, not just debug symbols.
609+
# Note that $SYSROOTDIR/usr/bin might not exist yet.
610+
mkdir -p $SYSROOTDIR/usr/bin
611+
${triplet}-objcopy -g gdbserver $SYSROOTDIR/usr/bin/gdbserver
586612
fi
587613

588614
echo "DONE UCLIBC: $(date)" | tee -a "${logfile}"

0 commit comments

Comments
 (0)