About GNAT
Ada is a modern programming language designed for large, long-lived
applications — and embedded systems in particular — where
reliability and efficiency are essential. It has a set of unique
technical features that make it highly effective for use in large,
complex and safety-critical projects.
The compiler and associated tools on this page are known as the
GNAT technology, developed by the
Adacore company, using the GCC
backend.
Nowadays, not many packages use this language, but if you come
across a package that uses it, this package will enable that
support.
Additional Downloads
If you have not already built or downloaded GNAT tools, this download is required as
GNAT is written in Ada.
GNAT Dependencies
Optional
GDB,
Graphviz
(some tests use it if installed; note that if it's installed but
not built with libpng,
these tests will fail), and
Valgrind (for tests)
Note
This may take a while to build. Feel free to do something else
while this is building.
Installation of GNAT Binaries
As GNAT is written in Ada, Ada
tools need to be on the system in order to build GNAT. If you already built such tools or have
the binaries on your system, you can skip to the next section.
Install the GNAT binaries by
running the following commands as the root
user while still in the directory the
tarball is in:
tar -xf gnat-x86_64-linux-14.2.0-1.tar.gz -C /opt &&
ln -sv gnat-x86_64-linux-14.2.0-1 /opt/gnat &&
chown -R root:root /opt/gnat
Now adjust the PATH
variable so the
GNAT software can be found and
used:
PATH_HOLD=$PATH &&
export PATH=/opt/gnat/bin:$PATH_HOLD
Ensure ld and
as from the
GNAT package aren't used as to
prevent issues with aging by issuing the following as the
root
user:
find /opt/gnat/bin -name ld -exec mv -v {} {}.old \; &&
find /opt/gnat/bin -name as -exec mv -v {} {}.old \;
Installation of GNAT
Important
Even if you specify only languages other than Ada, C, and C++ to
the ./configure command below, the installation process will
overwrite your existing GCC C and C++ compilers and libraries.
Running the full suite of tests is recommended.
Do not continue with the make
install command until you are confident the build
was successful. You can compare your test results with those
found at https://gcc.gnu.org/ml/gcc-testresults/.
You may also want to refer to the information found in the GCC
section of Chapter 8 in the LFS book (https://www.linuxfromscratch.org/lfs/view/development/chapter08/gcc.html).
The instructions below are intentionally performing a “bootstrap” process.
Bootstrapping is needed for robustness and is highly recommended
when upgrading the compilers version. To disable bootstrap anyway,
add --disable-bootstrap
to
the ../configure
options below.
First, ensure the right library directory is used on x86_64:
case $(uname -m) in
x86_64)
sed -e '/m64=/s/lib64/lib/' \
-i.orig gcc/config/i386/t-linux64
;;
esac
Create the build directory and check for multilib support:
mkdir build &&
cd build &&
if [[ $(uname -m) == "x86_64" ]]; then
echo "int main(){}" > dummy.c &&
# cc is used here as the GNAT binaries don't have multilib support,
# but cc is not supplied in the distribution, meaning the system-installed
# C compiler will be used for this process. If cc is not linked to gcc,
# then use /usr/bin/gcc instead of cc.
if $(cc -m32 dummy.c &> /dev/null); then
MULTILIB="--enable-multilib"
MULTILIB_FLAGS="--with-multilib-list=m64,m32"
# This makes -mstackrealign the default for 32-bit objects
sed '/STACK_REALIGN_DEFAULT/s/0/(!TARGET_64BIT \&\& TARGET_SSE)/' \
-i ../gcc/config/i386/i386.h
if $(cc -mx32 dummy.c &> /dev/null); then
MULTILIB_FLAGS+=",mx32"
fi
elif $(cc -mx32 dummy.c &> /dev/null); then
MULTILIB="--enable-multilib"
MULTILIB_FLAGS="--with-multilib-list=m64,mx32"
else
MULTILIB="--disable-multilib"
fi
rm -v dummy.c
else
MULTILIB="--disable-multilib"
fi
Now install GNAT by running the
following commands:
../configure \
--prefix=/usr \
$(echo "$MULTILIB") \
$(echo "$MULTILIB_FLAGS") \
--with-system-zlib \
--enable-default-pie \
--enable-default-ssp \
--disable-fixincludes \
--enable-languages=ada,c,c++ &&
unset MULTILIB MULTILIB_FLAGS &&
make
Note
When you recompile GCC, make
sure to include ada
in
the --enable-languages=
parameter, or else you will lose Ada support and will need to
install the GNAT binaries again.
If running tests, as in LFS, remove/fix several known test
failures:
sed -e '/cpython/d' -i ../gcc/testsuite/gcc.dg/plugin/plugin.exp &&
sed -e 's/no-pic /&-no-pie /' -i ../gcc/testsuite/gcc.target/i386/pr113689-1.c &&
sed -e 's/300000/(1|300000)/' -i ../libgomp/testsuite/libgomp.c-c++-common/pr109062.c &&
sed -e 's/{ target nonpic } //' \
-e '/GOTPCREL/d' -i ../gcc/testsuite/gcc.target/i386/fentryname3.c
If you have installed additional packages such as valgrind and gdb, the GCC
part of the test suite will run more tests than in LFS. Some of
those will report FAIL and others XPASS (pass when expected to
FAIL). As of GCC-14.2.0, about 74 FAIL occur in the “guality”
suite, as well as miscellaneous failures throughout the rest of the
test suite. If all the compilers above are built, there will be a
little over 110 unexpected failures out of over 617,000 tests. To
run the tests, issue:
ulimit -s 32768 &&
make -k check
The tests are very long, and the results may be hard to find in the
logs, especially if you use parallel jobs with make. You can get a
summary of the tests with:
../contrib/test_summary
Now, as the root
user:
make install &&
mkdir -pv /usr/share/gdb/auto-load/usr/lib &&
mv -v /usr/lib/*gdb.py /usr/share/gdb/auto-load/usr/lib &&
chown -v -R root:root \
/usr/lib/gcc/*linux-gnu/14.2.0/include{,-fixed} \
/usr/lib/gcc/*linux-gnu/14.2.0/ada{lib,include} &&
ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/14.2.0/liblto_plugin.so \
/usr/lib/bfd-plugins/
Cleaning Up and Testing
Now that GNAT has been installed,
it is time to clean up and test your installation to make sure
everything is working as expected.
If you downloaded the GNAT
binaries, remove them as the root
user:
rm -rf /opt/gnat*
If you downloaded the GNAT
binaries, restore the PATH
variable
to what it was beforehand:
export PATH=$PATH_HOLD &&
unset PATH_HOLD
Now it's time to test the installation. First confirm that the C
and C++ compilers are working correctly:
echo "int main(){}" > main.c &&
cp -v main.c main.cpp &&
gcc main.c &&
./a.out &&
rm -v a.out &&
g++ main.cpp &&
./a.out &&
rm -v a.out main.{c,cpp}
If you have 32-bit multilib support:
echo "int main(){}" > main.c &&
cp -v main.c main.cpp &&
gcc -m32 main.c &&
./a.out &&
rm -v a.out &&
g++ -m32 main.cpp &&
./a.out &&
rm -v a.out main.{c,cpp}
If you have x32-bit multilib support:
echo "int main(){}" > main.c &&
cp -v main.c main.cpp &&
gcc -mx32 main.c &&
./a.out &&
rm -v a.out &&
g++ -mx32 main.cpp &&
./a.out &&
rm -v a.out main.{c,cpp}
And finally, test the GNAT compiler:
cat > testgnat.adb << "EOF" &&
with Ada.Text_IO; use Ada.Text_IO;
procedure Testgnat is
begin
Put_Line("Success!");
end Testgnat;
EOF
gnatmake testgnat.adb &&
./testgnat &&
rm -v testgnat*
The commands above should have no errors, otherwise something went
wrong with the installation.
Command Explanations
mkdir build; cd
build: The GCC
documentation recommends building the package in a dedicated build
directory.
if [[ $(uname -m) == "x86_64" ]];
then...: These commands check for multilib support.
$(echo
"$MULTILIB{,_FLAGS}"): These commands pass the
results from the commands explained above as parameters to
../configure
to allow for automating
what needs to be set for multilib support if applicable.
--with-system-zlib
: Uses
the system zlib instead of the
bundled one. zlib is used for
compressing and decompressing GCC's intermediate language in LTO (Link Time
Optimization) object files.
--enable-default-pie
: Makes
the -fpie
option the default when
compiling programs. Together with the ASLR feature enabled in the kernel, this
defeats some kind of attacks based on known memory layouts.
--enable-default-ssp
: Makes
the -fstack-protector-strong
option the
default when compiling programs. SSP is a technique preventing alteration of
the program flow by corrupting the parameter stack.
--enable-languages=ada,c,c++
: This
command builds support for Ada, C, and C++. Refer to https://linuxfromscratch.org/blfs/view/svn/general/gcc.html
to find what other languages are supported. Make sure to add
ada
to the option if you
recompile GCC.
ulimit -s 32768: This
command prevents several tests from running out of stack space.
make -k check: This
command runs the test suite without stopping if any errors are
encountered.
../contrib/test_summary: This
command will produce a summary of the test suite results. You can
append | grep -A7
Summ to the command to produce an even more
condensed version of the summary. You may also wish to redirect the
output to a file for review and comparison later on.
mv -v /usr/lib/*gdb.py
...: The installation stage puts some files used by
gdb under the /usr/lib
directory. This generates spurious error
messages when performing ldconfig. This command moves the
files to another location.
chown -v -R root:root
/usr/lib/gcc/*linux-gnu/...: If the package is
built by a user other than root, the ownership of the installed
include
directory (and its content)
will be incorrect. This command changes the ownership to the
root
user and group.
Contents
Installed Programs:
gnat, gnatbind, gnatchop, gnatclean,
gnatkr, gnatlink, gnatls, gnatmake, gnatname, and
gnatprep
Installed Libraries:
libgnarl.{so,a}, libgnat.{so,a} in
/usr/lib/gcc/<arch-triplet>/14.2.0/adalib
Installed Directories:
/usr/lib/gcc/<arch-triplet>/14.2.0/ada{include,lib}
and
/usr/lib/gcc/<arch-triplet>/14.2.0/plugin/include/ada
Only the Ada specific files are listed here. Others can be found at
https://www.linuxfromscratch.org/lfs/view/development/chapter08/gcc.html#contents-gcc
as they were initially installed during the building of LFS.
Short Descriptions
gnat
|
is a wrapper that accepts a number of commands and calls
the corresponding tool from the list below
|
gnatbind
|
is used to bind compiled objects
|
gnatchop
|
is useful for renaming files to meet the standard
Ada default file naming
conventions
|
gnatclean
|
is used to remove files associated with a GNAT project
|
gnatkr
|
is used to determine the crunched name for a given file,
when crunched to a specified maximum length
|
gnatlink
|
is used to link programs and build an executable file
|
gnatls
|
is the compiled unit browser
|
gnatmake
|
is the Ada compiler,
which performs compilation, binding and linking
|
gnatname
|
will list the files associated with a GNAT project
|
gnatprep
|
is the GNAT external
preprocessor
|