Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update arc-release branch for arc-2024.06 release #629

Merged
merged 7 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 39 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ While the top of *development* branches should build and run reliably, there
is no guarantee of this. Users who encountered an error are welcomed to create
a new bug report at GitHub Issues for this `toolchain` project.

## Documentation

There are several documentation sites for ARC GNU toolchain:

1. [GNU toolchain documentation site](https://foss-for-synopsys-dwc-arc-processors.github.io/documentation) - the documentation site for ARC Classic targets.
2. [ARC-V Processors Getting Started](https://foss-for-synopsys-dwc-arc-processors.github.io/arc-v-getting-started) - the documentation for ARC-V targets.
3. [Old GNU toolchain documentation site](https://foss-for-synopsys-dwc-arc-processors.github.io/toolchain/) - the documentation site for ARC Classic targets
for release 2023.03 and earlier.

## Build environment

The toolchain building is being done by [Crosstool-NG](https://github.com/crosstool-ng/crosstool-ng)
Expand Down Expand Up @@ -211,6 +220,8 @@ The following pre-defined configurations (they are called "samples" on Crosstool
1. `snps-arc64-snps-linux-gnu` - Linux glibc cross-toolchain for for ARC HS6x processors for 64-bit Linux hosts
1. `snps-arc64-snps-native-gnu` - Linux glibc "native" toolchain from ARC HS6x processors
1. `snps-arc64-unknown-elf` - Bare-metal cross-toolchain for ARC HS6x processors for 64-bit Linux hosts
1. `snps-riscv64-unknown-elf` - Bare-metal cross-toolchain for ARC-V processors for 64-bit Linux hosts
1. `snps-riscv64-win-elf` - Bare-metal cross-toolchain for ARC-V processors for 64-bit Windows hosts

And to get Crosstool-NG configured with either of those samples just say: `./ct-ng sample_name`. For example, to get bare-metal toolchain for ARCompact/ARCv2 processors say: `./ct-ng snps-arc-multilib-elf32`.

Expand All @@ -225,9 +236,9 @@ and make all the settings manually. For that just say `./ct-ng menuconfig` and u

The most interesting options for toolchain users might be:

* Selection of the default target CPU model. To change it go to `Target options -> Emit assembly for CPU` and specify one of the possible values for GCC's `-mcpu` option, see <https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/wiki/Understanding-GCC-mcpu-option> for the reference.
* Selection of ARC64 processors. For that go to `Target options -> Bitness` and select `64-bit`.
* `CFLAGS` to be used for compilation of libraries for the target. Those might be set in `Target options -> Target CFLAGS`.
* Selection of the default target CPU model. To change it go to `Target options -> Emit assembly for CPU` and specify one of the possible values for GCC's `-mcpu` option (refer to [documentation](https://foss-for-synopsys-dwc-arc-processors.github.io/documentation/2024.06/toolchain/target-options/) for details).
* Selection of ARC64 processors. For that go to `Target options -> Bitness` and select `64-bit`.
* `CFLAGS` to be used for compilation of libraries for the target. Those might be set in `Target options -> Target CFLAGS`.

## Building a toolchain with Crosstool-NG

Expand All @@ -238,6 +249,15 @@ And now, when all the preparations are done, it's required only to start build p
./ct-ng build
```

> :warning: There is set of samples which correspond to
> native toolchains. Such toolchains are used inside of ARC targets.
> If you want to build a native toolchain then a corresponding
> cross-toolchain must be presented in `PATH`. E.g., if you want to
> build `snps-arc64-snps-native-gnu` sample for a native toolchain
> then you need to build `snps-arc64-snps-linux-gnu` sample for
> a cross-compiler first and add `bin` directory of this cross-compiler
> to `PATH`.

## Building toolchain for Windows

### Preparation for building ARC cross-toolchain for Windows host
Expand Down Expand Up @@ -312,8 +332,16 @@ Prefixes which start with `arc-` correspond to little endian toolchains. Prefixe
`arceb-` correspond to big endian toolchains. E.g., GDB for big endian ARCv2 baremetal toolchain is
`arceb-elf32-gdb`. However, big endian tools are not available for ARCv3 yet.

You can find more information about variants of toolchains, `-mcpu` values
and matching TCF files on [Toolchains for ARC Processors](https://foss-for-synopsys-dwc-arc-processors.github.io/documentation/2024.06/toolchain/) page.

### Using nSIM simulator to run bare metal ARC applications

> Refer to [nSIM](https://foss-for-synopsys-dwc-arc-processors.github.io/documentation/2024.06/simulators/nsim/)
> page of the documentation for details. Refer to
> [GNU tools for ARC-V](https://foss-for-synopsys-dwc-arc-processors.github.io/arc-v-getting-started/synopsys-tools/gnu.html)
> for details regarding running ARC-V applications on simulators.

nSIM simulator supports GNU IO hostlink used by the libc library of bare metal
GNU toolchain for ARC. nSIM option `nsim_emt=1` enables GNU IO hostlink. nSIM
simulator also supports semihosting, which is essential for ARC-V targets, more
Expand Down Expand Up @@ -392,25 +420,24 @@ developing for hardware platform which doesn't have hostlink support is that
while `exit` functions `nosys.specs` is an infinite loop. For more details
please see [documentation](https://foss-for-synopsys-dwc-arc-processors.github.io/toolchain/baremetal/index.html).

### Using EM Starter Kit to run bare metal ARC EM application
### Using HS Development Kit to run bare metal applications

> A custom linker script is required to link applications for EM Starter Kit.
> Refer to the section "Building an application" of our EM Starter Kit page:
> <https://foss-for-synopsys-dwc-arc-processors.github.io/toolchain/baremetal/em-starter-kit.html>

Build instructions for OpenOCD are available at its page:
<https://github.com/foss-for-synopsys-dwc-arc-processors/openocd/blob/arc-2021.09/doc/README.ARC>
> Refer to [Getting OpenOCD](https://foss-for-synopsys-dwc-arc-processors.github.io/documentation/2024.06/platforms/get-openocd/)
> and [Using OpenOCD](https://foss-for-synopsys-dwc-arc-processors.github.io/documentation/2024.06/platforms/use-openocd/)
> pages of the documentation for details regarding OpenOCD. Refer to
> [Baremetal Targets](https://foss-for-synopsys-dwc-arc-processors.github.io/documentation/2024.06/baremetal/)
> regarding building and running applications on boards.

To run OpenOCD:

```shell
openocd -f /usr/local/share/openocd/scripts/board/snps_em_sk_v2.3.cfg
openocd -f board/snps_hsdk.cfg
```

Compile test application and run:

```shell
$ arc-elf32-gcc -mcpu=em4_dmips -g --specs=emsk_em9d.specs simple.c
$ arc-elf32-gcc -mcpu=hs38_linux -specs=hsdk.specs -g simple.c
$ arc-elf32-gdb --quiet a.out
(gdb) target remote :3333
(gdb) load
Expand All @@ -423,66 +450,6 @@ $ arc-elf32-gdb --quiet a.out
(gdb) quit
```

### Using Ashling Opella-XD debug probe to debug bare metal applications

> A custom linker script is required to link applications for EM Starter Kit.
> Refer to the section "Building an application" of our EM Starter Kit page:
> <https://foss-for-synopsys-dwc-arc-processors.github.io/toolchain/baremetal/em-starter-kit.html>
> For different hardware configurations other changes might be required.
>
> The Ashling Opella-XD debug probe and its drivers are not part of the GNU
> tools distribution and should be obtained separately.

The Ashling Opella-XD drivers distribution contains gdbserver for GNU toolchain.
Command to start it:

```shell
$ ./ash-arc-gdb-server --jtag-frequency 8mhz --device arc \
--arc-reg-file <core.xml>
```

Where <core.xml> is a path to XML file describing AUX registers of target core.
The Ashling drivers distribution contain files for ARC 600 (arc600-core.xml)
and ARC 700 (arc700-core.xml). However due to recent changes in GDB with
regards of support of XML target descriptions those files will not work out of
the box, as order of some registers changed. To use Ashling GDB server with GDB
starting from 2015.06 release, it is required to use modified files that can be
found in this `toolchain` repository in `extras/opella-xd` directory.

*Before* connecting GDB to an Opella-XD gdbserver it is essential to specify
path to XML target description file that is aligned to `<core.xml>` file passed
to GDB server. All registers described in `<core.xml>` also must be described
in XML target description file in the same order. Otherwise GDB will not
function properly.

```shell
(gdb) set tdesc filename <path/to/opella-CPU-tdesc.xml>
```

XML target description files are provided in the same `extras/opella-xd`
directory as Ashling GDB server core files.

Then connect to the target as with the OpenOCD/Linux gdbserver. For example a
full session with an Opella-XD controlling an ARC EM target could start as
follows:

```shell
$ arc-elf32-gcc -mcpu=arcem -g --specs=nsim.specs simple.c
$ arc-elf32-gdb --quiet a.out
(gdb) set tdesc filename toolchain/extras/opella-xd/opella-arcem-tdesc.xml
(gdb) target remote :2331
(gdb) load
(gdb) break main
(gdb) continue
(gdb) break exit
(gdb) continue
# Register R0 contains exit code of function main()
(gtb) info reg r0
(gdb) quit
```

Similar to OpenOCD hostlink is not available in GDB with Ashling Opella-XD.

### Debugging applications on Linux for ARC

Compile application:
Expand Down
132 changes: 131 additions & 1 deletion arc-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,6 @@ build_ncurses() {
# Helper to build gmp, used by native gdb. Starting from
# GDB 11.1, it requires libgmp to be built natively [1].
# Arguments:
# $1 - target triplet
#
# [1] gdb: Make GMP a required dependency for buidling GDB
# https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=1b4ac058f7d
Expand Down Expand Up @@ -629,6 +628,137 @@ build_gmp() {
make_target_ordered installing install DESTDIR=$SYSROOTDIR
}

# Helper to build mpfr, used by native gdb. Since 21-Dec-2022,
# GDB requires libgmp to be built natively [1].
#
# To build mpfr, native libgmp must have already bin built. See
# build_gmp() for that matter.
#
# [1] Use toplevel configure for GMP and MPFR for gdb
# https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=991180627851
#
# Note:
# libmpfr must be built against the native libgmp (--with-libgmp...).
# If this libgmp is built for a sysroot (--prefix=/usr), then its libtool
# script (libgmp.la) contains entries that can be confused with the build
# system's paths:
#
# $ cat /sysroot/usr/lib/libgmp.a
# ...
# libdir=/usr/lib
#
# libtool has a trick to handle these situations, when the effective
# compiler's prefix is not the same as the default one in build system.
# to trigger this trick, one has to pass "--with-sysroot=yes" to the
# configure command [2]. This will result in a successful build AND
# a leading '=' character in some of the libraries names in installed
# libmpfs.la script. This leading character must be ignored on a native
# system. However on a build system, it must be exapnded to the full
# sysroot path. libtool >= 2.4.x is capable of doing this.
#
# [2]
# https://bugs.gentoo.org/show_bug.cgi?id=521184#c8
build_mpfr() {
local triplet=$1
mpfr_version=4.2.1
mpfr_url_base=https://www.mpfr.org/mpfr-current
mpfr_tar=mpfr-${mpfr_version}.tar.xz
mpfr_url=$mpfr_url_base/$mpfr_tar

mkdir -p $toolchain_build_dir/_download_tmp
cd $toolchain_build_dir/_download_tmp
if [ ! -s $mpfr_tar ]; then
$WGET -O $mpfr_tar $mpfr_url
fi

build_dir_init mpfr
tar xf $toolchain_build_dir/_download_tmp/$mpfr_tar --strip-components=1

configure_for_arc . $triplet \
--prefix=/usr \
--sysconfdir=/etc \
--localstatedir=/var \
--program-prefix= \
--enable-static \
--with-sysroot=yes \
--with-gmp=$SYSROOTDIR/usr

make_target building
make_target_ordered installing install DESTDIR=$SYSROOTDIR
}

# This function manipulates two entries. First, it turns
#
# dependency_libs=' -L=/usr/lib =/usr/lib/libgmp.la'
#
# into
#
# #dependency_libs=' -L=/usr/lib =/usr/lib'
# dependency_libs=' -L/sysroot/usr/lib /sysroot/usr/lib/libgmp.la'
#
# And then
#
# libdir='/usr/lib'
#
# into
#
# #libdir='/usr/lib'
# libdir='/sysroot/usr/lib'
#
# Rationale
# ---------
# libmpfr, which is needed for building gdb, installs with a libtool
# script (*.la) with the following entry:
#
# $ cat /sysroot/usr/lib/libmpfr.la
# ...
# dependency_libs=' -L=/usr/lib =/usr/lib/libgmp.la'
#
# The leading '=' character indicates to libtool that this is a
# sysroot path and must be replaced with whatever the compiler returns
# as the sysroot: arc-snps-linux-gnu-gcc --print-sysroot
#
# libtool v2.2.7 that ships with GDB is not recent enough (v2.4+) to
# expand these. Therefore, this function will expand those pesky equal
# signs. Same sort of story goes for 'libdir'. libtool 2.4+ provides
# a "func_resolve_sysroot()" that turns "/usr/lib" into full path on a
# build machine.
la_expand_libs() {
local la_file="$1"

# Duplicate the "dependency_libs=" line while
# keeping the original instance commented out
$SED -i "s/^\(dependency_libs=.*\)/#\1\n\1/" $la_file

# The '=' in '-L=.* should be replaced by SYSROOTDIR
# The '=' in ' =/usr/lib/.*' should be replaced by SYSROOTDIR
$SED -i \
-e "/^dependency_libs=/ s,-L=,-L$SYSROOTDIR,g" \
-e "/^dependency_libs=/ s, =, $SYSROOTDIR,g" \
$la_file

# Duplicate the "libdir=" line ...
$SED -i "s/^\(libdir=.*\)/#\1\n\1/" $la_file

# Add SYSROOTDIR to the beginning of the path in "libdir"
$SED -i "/^libdir=/ s,=',='$SYSROOTDIR," $la_file
}

# Remove the manipulated paths and uncomment the original ones.
la_restore_libs() {
local la_file="$1"

$SED -i \
-e "/^dependency_libs=/d" \
-e "s/^#\(dependency_libs=.*\)/\1/" \
$la_file

$SED -i \
-e "/^libdir=/d" \
-e "s/^#\(libdir=.*\)/\1/" \
$la_file
}

# $1 - a configuration file or a directory with .config
# $2 - option to enable
kconfig_enable_option() {
Expand Down
13 changes: 10 additions & 3 deletions build-glibc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,11 @@ echo " finished creating symlinks"
if [ $DO_NATIVE_GDB = yes ]; then

build_ncurses $triplet

build_gmp $triplet
build_mpfr $triplet

la_expand_libs "$SYSROOTDIR/usr/lib/libgmp.la"
la_expand_libs "$SYSROOTDIR/usr/lib/libmpfr.la"

build_dir_init native_gdb

Expand All @@ -451,17 +454,21 @@ if [ $DO_NATIVE_GDB = yes ]; then
# C builds.
config_path=$(calcConfigPath "${ARC_GNU}")/gdb
configure_for_arc "$config_path" $triplet \
--with-libgmp-type=static \
--with-libgmp-prefix=$SYSROOTDIR/usr \
--with-libgmp=$SYSROOTDIR/usr \
--with-libmpfr=$SYSROOTDIR/usr \
--disable-build-with-cxx \
--disable-gas --disable-ld --disable-binutils

make_target building

# See comment for stripprog_opt for an explanation why this is needed.
# Strip will strip complete symbol table, not just debug symbols.
make_target_ordered installing install-strip-gdb \
install-strip-gdbserver DESTDIR=$SYSROOTDIR \
STRIPPROG=${triplet}-strip

la_restore_libs "$SYSROOTDIR/usr/lib/libgmp.la"
la_restore_libs "$SYSROOTDIR/usr/lib/libmpfr.la"
else
# If native GDB has been disabled, then simple gdbserver still will be
# built. It doesn't need ncurses.
Expand Down
13 changes: 10 additions & 3 deletions build-uclibc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,11 @@ echo " finished creating symlinks"
if [ $DO_NATIVE_GDB = yes ]; then

build_ncurses $triplet

build_gmp $triplet
build_mpfr $triplet

la_expand_libs "$SYSROOTDIR/usr/lib/libgmp.la"
la_expand_libs "$SYSROOTDIR/usr/lib/libmpfr.la"

build_dir_init native_gdb

Expand All @@ -626,17 +629,21 @@ if [ $DO_NATIVE_GDB = yes ]; then
# C builds.
config_path=$(calcConfigPath "${ARC_GNU}")/gdb
configure_for_arc "$config_path" $triplet \
--with-libgmp-type=static \
--with-libgmp-prefix=$SYSROOTDIR/usr \
--with-libgmp=$SYSROOTDIR/usr \
--with-libmpfr=$SYSROOTDIR/usr \
--disable-build-with-cxx \
--disable-gas --disable-ld --disable-binutils

make_target building

# See comment for stripprog_opt for an explanation why this is needed.
# Strip will strip complete symbol table, not just debug symbols.
make_target_ordered installing install-strip-gdb \
install-strip-gdbserver DESTDIR=$SYSROOTDIR \
STRIPPROG=${triplet}-strip

la_restore_libs "$SYSROOTDIR/usr/lib/libgmp.la"
la_restore_libs "$SYSROOTDIR/usr/lib/libmpfr.la"
else
# If native GDB has been disabled, then simple gdbserver still will be
# built. It doesn't need ncurses.
Expand Down
Loading
Loading