2.6 Migration example

This topic shows you the process of migrating an example code from Arm® Compiler 5 to Arm Compiler 6.

Note:

This topic includes descriptions of [COMMUNITY] features. See Support level definitions.

Compiling with Arm® Compiler 5

For an example startup code that builds with Arm Compiler 5, see Example startup code for Arm® Compiler 5 project.

To compile this example with Arm Compiler 5, enter:

armcc startup_ac5.c --cpu=7-A -c

This command generates a compiled object file for the Armv7‑A architecture.

Compiling with Arm® Compiler 6

Try to compile the startup_ac5.c example with Arm Compiler 6. The first step in the migration is to use the new compiler tool, armclang, and use the correct command-line options for armclang.

To compile this example with Arm Compiler 6, enter:

armclang --target=arm-arm-none-eabi startup_ac5.c -march=armv7-a -c -O1 -std=c90

The following table shows the differences in the command-line options between Arm Compiler 5 and Arm Compiler 6:

Table 2-4 Command-line changes

Description Arm Compiler 5 Arm Compiler 6
Tool armcc armclang
Specifying an architecture --cpu=7-A
  • -march=armv7-a
  • --target is a mandatory option for armclang.
Optimization The default optimization is -O2. The default optimization is -O0. To get similar optimizations as the Arm Compiler 5 default, use -O1.
Source language mode The default source language mode for .c files is c90. The default source language mode for .c files is gnu11 [COMMUNITY]. To compile for c90 in Arm Compiler 6, use -std=c90.

Arm Compiler 6 generates the following errors and warnings when trying to compile the example startup_ac5.c file in c90 mode:

startup_ac5.c:39:22: error: 'main' must return 'int'
__declspec(noreturn) void main (void)
                     ^~~~
                     int
startup_ac5.c:45:9: error: '#pragma import' is an ARM Compiler 5 extension, and is not supported by ARM Compiler 6 [-Warmcc-pragma-import]
#pragma import (__use_no_semihosting)
        ^
startup_ac5.c:60:7: error: expected '(' after 'asm'
__asm void Vectors(void) {
      ^
startup_ac5.c:60:6: error: expected ';' after top-level asm block
__asm void Vectors(void) {
     ^
     ;
startup_ac5.c:61:3: error: use of undeclared identifier 'IMPORT'
  IMPORT Undef_Handler
  ^
startup_ac5.c:80:7: error: expected '(' after 'asm'
__asm void Reset_Handler(void) {
      ^
startup_ac5.c:80:6: error: expected ';' after top-level asm block
__asm void Reset_Handler(void) {
     ^
     ;
startup_ac5.c:83:3: error: use of undeclared identifier 'CPSID'
  CPSID   if                           
  ^
8 errors generated.

The following section describes how to modify the source file to fix these errors and warnings.

Modifying the source code for Arm® Compiler 6

You must make the following changes to the source code to compile with armclang.

  • The return type of function main function cannot be void in standard C. Replace the following line:
    __declspec(noreturn) void main(void)

    With:

    __declspec(noreturn) int main(void)
  • The intrinsic __enable_irq() is not supported in Arm Compiler 6. You must replace the intrinsic with an inline assembler equivalent. Replace the following line:
    __enable_irq();

    With:

    __asm("CPSIE i");
  • The #pragma import is not supported in Arm Compiler 6. You must replace the pragma with an equivalent directive using inline assembler. Replace the following line:
    #pragma import(__use_no_semihosting)

    With:

    __asm(".global __use_no_semihosting");
  • In certain situations, armclang might remove infinite loops that do not have side-effects. You must use the volatile keyword to tell armclang not to remove such code. Replace the following line:
    while(1);

    With:

    while(1) __asm volatile("");
Non-ConfidentialPDF file icon PDF versionDUI0742J
Copyright © 2014–2017, 2019 Arm Limited or its affiliates. All rights reserved.