9.29 __attribute__((alias)) function attribute

This function attribute enables you to specify multiple aliases for a function.

Aliases must be defined in the same translation unit as the original function.

Note

You cannot specify aliases in block scope. The compiler ignores aliasing attributes attached to local function definitions and treats the function definition as a normal local definition.
In the output object file, the compiler replaces alias calls with a call to the original function name, and emits the alias alongside the original name. For example:
static int oldname(int x, int y) {
     return x + y;
}
static int newname(int x, int y) __attribute__((alias("oldname")));
int caller(int x, int y) {
     return oldname(x,y) + newname(x,y);
}
This code compiles to:
AREA ||.text||, CODE, READONLY, ALIGN=2
newname                  ; Alternate entry point
oldname PROC
     MOV      r2,r0
     ADD      r0,r2,r1
     BX       lr
     ENDP
caller PROC
     PUSH     {r4,r5,lr}
     MOV      r3,r0
     MOV      r4,r1
     MOV      r1,r4
     MOV      r0,r3
     BL       oldname
     MOV      r5,r0
     MOV      r1,r4
     MOV      r0,r3
     BL       oldname
     ADD      r0,r0,r5
     POP      {r4,r5,pc}
     ENDP
If the original function is defined as static but the alias is defined as extern, then the compiler changes the original function to be external.

Note

This function attribute is a GNU compiler extension that the ARM compiler supports.

Note

Variables names might also be aliased using the corresponding variable attribute __attribute__((alias)).

Syntax

return-type newname([argument-list]) __attribute__((alias("oldname")));
Where:
oldname
is the name of the function to be aliased
newname
is the new name of the aliased function.

Example

#include <stdio.h>
void foo(void)
{
    printf("%s\n", __FUNCTION__);
}
void bar(void) __attribute__((alias("foo")));
void gazonk(void)
{
    bar(); // calls foo
}
Related reference
9.59 __attribute__((alias)) variable attribute
Non-ConfidentialPDF file icon PDF versionARM DUI0375F
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.