Skip to content

Commit 1a7a0bc

Browse files
shahab-vahedikolerov
authored andcommitted
mpfr: Add native libmpfr to build native gdb
As of 21-Dec-2022, GDB requires libmpfr to be built natively [1]. Therefore, add libmpfr building to the process of building native gdb. [1] Use toplevel configure for GMP and MPFR for gdb https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=991180627851
1 parent 3d7bf6d commit 1a7a0bc

File tree

3 files changed

+151
-7
lines changed

3 files changed

+151
-7
lines changed

arc-init.sh

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,6 @@ build_ncurses() {
599599
# Helper to build gmp, used by native gdb. Starting from
600600
# GDB 11.1, it requires libgmp to be built natively [1].
601601
# Arguments:
602-
# $1 - target triplet
603602
#
604603
# [1] gdb: Make GMP a required dependency for buidling GDB
605604
# https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=1b4ac058f7d
@@ -629,6 +628,137 @@ build_gmp() {
629628
make_target_ordered installing install DESTDIR=$SYSROOTDIR
630629
}
631630

631+
# Helper to build mpfr, used by native gdb. Since 21-Dec-2022,
632+
# GDB requires libgmp to be built natively [1].
633+
#
634+
# To build mpfr, native libgmp must have already bin built. See
635+
# build_gmp() for that matter.
636+
#
637+
# [1] Use toplevel configure for GMP and MPFR for gdb
638+
# https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=991180627851
639+
#
640+
# Note:
641+
# libmpfr must be built against the native libgmp (--with-libgmp...).
642+
# If this libgmp is built for a sysroot (--prefix=/usr), then its libtool
643+
# script (libgmp.la) contains entries that can be confused with the build
644+
# system's paths:
645+
#
646+
# $ cat /sysroot/usr/lib/libgmp.a
647+
# ...
648+
# libdir=/usr/lib
649+
#
650+
# libtool has a trick to handle these situations, when the effective
651+
# compiler's prefix is not the same as the default one in build system.
652+
# to trigger this trick, one has to pass "--with-sysroot=yes" to the
653+
# configure command [2]. This will result in a successful build AND
654+
# a leading '=' character in some of the libraries names in installed
655+
# libmpfs.la script. This leading character must be ignored on a native
656+
# system. However on a build system, it must be exapnded to the full
657+
# sysroot path. libtool >= 2.4.x is capable of doing this.
658+
#
659+
# [2]
660+
# https://bugs.gentoo.org/show_bug.cgi?id=521184#c8
661+
build_mpfr() {
662+
local triplet=$1
663+
mpfr_version=4.2.1
664+
mpfr_url_base=https://www.mpfr.org/mpfr-current
665+
mpfr_tar=mpfr-${mpfr_version}.tar.xz
666+
mpfr_url=$mpfr_url_base/$mpfr_tar
667+
668+
mkdir -p $toolchain_build_dir/_download_tmp
669+
cd $toolchain_build_dir/_download_tmp
670+
if [ ! -s $mpfr_tar ]; then
671+
$WGET -O $mpfr_tar $mpfr_url
672+
fi
673+
674+
build_dir_init mpfr
675+
tar xf $toolchain_build_dir/_download_tmp/$mpfr_tar --strip-components=1
676+
677+
configure_for_arc . $triplet \
678+
--prefix=/usr \
679+
--sysconfdir=/etc \
680+
--localstatedir=/var \
681+
--program-prefix= \
682+
--enable-static \
683+
--with-sysroot=yes \
684+
--with-gmp=$SYSROOTDIR/usr
685+
686+
make_target building
687+
make_target_ordered installing install DESTDIR=$SYSROOTDIR
688+
}
689+
690+
# This function manipulates two entries. First, it turns
691+
#
692+
# dependency_libs=' -L=/usr/lib =/usr/lib/libgmp.la'
693+
#
694+
# into
695+
#
696+
# #dependency_libs=' -L=/usr/lib =/usr/lib'
697+
# dependency_libs=' -L/sysroot/usr/lib /sysroot/usr/lib/libgmp.la'
698+
#
699+
# And then
700+
#
701+
# libdir='/usr/lib'
702+
#
703+
# into
704+
#
705+
# #libdir='/usr/lib'
706+
# libdir='/sysroot/usr/lib'
707+
#
708+
# Rationale
709+
# ---------
710+
# libmpfr, which is needed for building gdb, installs with a libtool
711+
# script (*.la) with the following entry:
712+
#
713+
# $ cat /sysroot/usr/lib/libmpfr.la
714+
# ...
715+
# dependency_libs=' -L=/usr/lib =/usr/lib/libgmp.la'
716+
#
717+
# The leading '=' character indicates to libtool that this is a
718+
# sysroot path and must be replaced with whatever the compiler returns
719+
# as the sysroot: arc-snps-linux-gnu-gcc --print-sysroot
720+
#
721+
# libtool v2.2.7 that ships with GDB is not recent enough (v2.4+) to
722+
# expand these. Therefore, this function will expand those pesky equal
723+
# signs. Same sort of story goes for 'libdir'. libtool 2.4+ provides
724+
# a "func_resolve_sysroot()" that turns "/usr/lib" into full path on a
725+
# build machine.
726+
la_expand_libs() {
727+
local la_file="$1"
728+
729+
# Duplicate the "dependency_libs=" line while
730+
# keeping the original instance commented out
731+
$SED -i "s/^\(dependency_libs=.*\)/#\1\n\1/" $la_file
732+
733+
# The '=' in '-L=.* should be replaced by SYSROOTDIR
734+
# The '=' in ' =/usr/lib/.*' should be replaced by SYSROOTDIR
735+
$SED -i \
736+
-e "/^dependency_libs=/ s,-L=,-L$SYSROOTDIR,g" \
737+
-e "/^dependency_libs=/ s, =, $SYSROOTDIR,g" \
738+
$la_file
739+
740+
# Duplicate the "libdir=" line ...
741+
$SED -i "s/^\(libdir=.*\)/#\1\n\1/" $la_file
742+
743+
# Add SYSROOTDIR to the beginning of the path in "libdir"
744+
$SED -i "/^libdir=/ s,=',='$SYSROOTDIR," $la_file
745+
}
746+
747+
# Remove the manipulated paths and uncomment the original ones.
748+
la_restore_libs() {
749+
local la_file="$1"
750+
751+
$SED -i \
752+
-e "/^dependency_libs=/d" \
753+
-e "s/^#\(dependency_libs=.*\)/\1/" \
754+
$la_file
755+
756+
$SED -i \
757+
-e "/^libdir=/d" \
758+
-e "s/^#\(libdir=.*\)/\1/" \
759+
$la_file
760+
}
761+
632762
# $1 - a configuration file or a directory with .config
633763
# $2 - option to enable
634764
kconfig_enable_option() {

build-glibc.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,11 @@ echo " finished creating symlinks"
437437
if [ $DO_NATIVE_GDB = yes ]; then
438438

439439
build_ncurses $triplet
440-
441440
build_gmp $triplet
441+
build_mpfr $triplet
442+
443+
la_expand_libs "$SYSROOTDIR/usr/lib/libgmp.la"
444+
la_expand_libs "$SYSROOTDIR/usr/lib/libmpfr.la"
442445

443446
build_dir_init native_gdb
444447

@@ -451,17 +454,21 @@ if [ $DO_NATIVE_GDB = yes ]; then
451454
# C builds.
452455
config_path=$(calcConfigPath "${ARC_GNU}")/gdb
453456
configure_for_arc "$config_path" $triplet \
454-
--with-libgmp-type=static \
455-
--with-libgmp-prefix=$SYSROOTDIR/usr \
457+
--with-libgmp=$SYSROOTDIR/usr \
458+
--with-libmpfr=$SYSROOTDIR/usr \
456459
--disable-build-with-cxx \
457460
--disable-gas --disable-ld --disable-binutils
461+
458462
make_target building
459463

460464
# See comment for stripprog_opt for an explanation why this is needed.
461465
# Strip will strip complete symbol table, not just debug symbols.
462466
make_target_ordered installing install-strip-gdb \
463467
install-strip-gdbserver DESTDIR=$SYSROOTDIR \
464468
STRIPPROG=${triplet}-strip
469+
470+
la_restore_libs "$SYSROOTDIR/usr/lib/libgmp.la"
471+
la_restore_libs "$SYSROOTDIR/usr/lib/libmpfr.la"
465472
else
466473
# If native GDB has been disabled, then simple gdbserver still will be
467474
# built. It doesn't need ncurses.

build-uclibc.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,11 @@ echo " finished creating symlinks"
612612
if [ $DO_NATIVE_GDB = yes ]; then
613613

614614
build_ncurses $triplet
615-
616615
build_gmp $triplet
616+
build_mpfr $triplet
617+
618+
la_expand_libs "$SYSROOTDIR/usr/lib/libgmp.la"
619+
la_expand_libs "$SYSROOTDIR/usr/lib/libmpfr.la"
617620

618621
build_dir_init native_gdb
619622

@@ -626,17 +629,21 @@ if [ $DO_NATIVE_GDB = yes ]; then
626629
# C builds.
627630
config_path=$(calcConfigPath "${ARC_GNU}")/gdb
628631
configure_for_arc "$config_path" $triplet \
629-
--with-libgmp-type=static \
630-
--with-libgmp-prefix=$SYSROOTDIR/usr \
632+
--with-libgmp=$SYSROOTDIR/usr \
633+
--with-libmpfr=$SYSROOTDIR/usr \
631634
--disable-build-with-cxx \
632635
--disable-gas --disable-ld --disable-binutils
636+
633637
make_target building
634638

635639
# See comment for stripprog_opt for an explanation why this is needed.
636640
# Strip will strip complete symbol table, not just debug symbols.
637641
make_target_ordered installing install-strip-gdb \
638642
install-strip-gdbserver DESTDIR=$SYSROOTDIR \
639643
STRIPPROG=${triplet}-strip
644+
645+
la_restore_libs "$SYSROOTDIR/usr/lib/libgmp.la"
646+
la_restore_libs "$SYSROOTDIR/usr/lib/libmpfr.la"
640647
else
641648
# If native GDB has been disabled, then simple gdbserver still will be
642649
# built. It doesn't need ncurses.

0 commit comments

Comments
 (0)