Nios II Classic Software Developer’s Handbook

ID 683282
Date 5/14/2015
Public
Document Table of Contents

4.11.3.1. GNU Compiler Tool Chain

The Nios II compiler tool chain is based on the standard GNU GCC compiler, assembler, linker, and make facilities. Altera provides and supports the standard GNU compiler tool chain for the Nios II processor.

For more information about installing the Altera Complete Design Suite, refer to the Altera Software Installation and Licensing Manual.

The following options are new for the GCC toolchain:

Code density and performance

Use of the -mgpopt=global setting is recommended as it generally deliver results with better code density *and* performance. (Note: this requires that everything is compiled with the same -Gn switch setting; use of -Gn is not generally recommended).

C++ code size reduction: -fno-exceptions

When a developer is using C++ but trying not to link in the (big) C++ exception-handling machinery nios2-elf-g++ will, in some cases, link in the exception-handling machinery where it is not actually required. This switch suppresses that behaviour, which results in a smaller code footprint for those situations.

Response to address 0x00 access: -fdelete-null-pointer-checks

Developers often have RAM at address 0x00 (== NULL pointer in gcc and most C compilers). From gcc 4.9 onwards, by default gcc detects attempts to read or write to address 0x00 and converts them to traps; typically in embedded/Nios II-based systems, these traps are not handled so the code will fail silently. This means that code that works when compiled with earlier versions of gcc could silently fail when compiled with gcc-4.9 (onwards).

In order to avoid this for Nios II this behaviour has been modified so that accesses to address 0x00 will work as expected for Nios II systems but there may be a slight negative effect on code performance. In Nios II systems that are known not to read/write RAM at address 0x00, use of the switch --fdelete-null-pointer-checks restores the original gcc behaviour and may provide a small performance boost.

Expansion of __builtin_trap

The latest versions of GCC now produce trap 3 instead of break 3 in the expansion of the __builtin_trap function and in other situations where a trap is emitted to indicate undefined runtime behaviour. This is for compliance with the Nios II ABI for Linux targets, which does not permit the use of the break instruction in user code.

GDB breakpoint instruction

GDB now uniformly uses trap 31 instead of a break instruction for software breakpoints. This is for consistency with the Nios II ABI for Linux targets.

GNU tools for the Nios II processor are generally named nios2-elf-<tool name>. The following list shows some examples:

  • nios2-elf-gcc
  • nios2-elf-as
  • nios2-elf-ld
  • nios2-elf-objdump
  • nios2-elf-size

The exception is the make utility, which is simply named make.

The Nios II GNU tools reside in the following location:

  • <Nios II EDS install path>/bin/gnu directory

Refer to the following additional sources of information:

  • For more information about managing GCC toolchains in the SBT for Eclipse— “Managing Toolchains in Eclipse” in the "Getting Started with the Graphical User Interface" chapter.
  • For more information about selecting the toolchain on the command line—the "Getting Started from the Command Line" chapter.
  • For more information about a comprehensive list of Nios II GNU tools—the GNU HTML documentation, refer to the Nios II Embedded Design Suite Support page on the Intel FPGA website.
  • For more information about GNU, refer to the Free Software Foundation website.