次のページ 前のページ 目次へ

8. EABI と legacy ABI

8.1 ABI とは

ここでいう ABI (Application Binary Interface) とは,C コンパイラにおいて

などを定義したものです.

8.2 ABI の種類

現在,ARM Linux 上で使われている ABI には以下の2つの種類があります.

legacy ABI

従来から ARM gcc で使用されている ABI. gcc でのコンパイルオプションは -mabi=apcs-gnu です.

ARM EABI

ARM holdings が定義

http://www.arm.com/products/DevTools/ABI.html
した ABI です. gcc 4.1 以降で使用可能で,コンパイルオプションは -mabi=aapcs-linux です.

8.3 違い

これらの ABI の違いは,Linux カーネルの設定ファイル(linux-2.6.x/arch/arm/Kconfig)によると

Since there are major incompatibilities between the legacy ABI and EABI, especially with regard to structure member alignment, this option also changes the kernel syscall calling convention to disambiguate both ABIs and allow for backward compatibility support (selected with CONFIG_OABI_COMPAT).
ということだそうです. 構造体のアラインメントに違いがあるようです.

以下のプログラムで違いを見てみます.


/* abitest.c */
#include <stdio.h>

struct foo {
        char a;
};

main ( void )
{
        printf ( "sizeof(struct foo) = %d\n", sizeof(struct foo));
}

lagacy ABI のほうは

$ gcc -mabi=apcs-gnu abitest.c
$ ./a.out 
sizeof(struct foo) = 4
$ 

ARM EABI のほうは

$ gcc -mabi=aapcs-linux abitest.c
$ ./a.out 
sizeof(struct foo) = 1
$ 

という結果が得られます. 構造体のアラインメントの違いが見られますね.

8.4 影響と対策

「システム内部で ABI を統一せよ」

これが鉄則です.

オブジェクトファイル・ライブラリ

もちろん,ABI を統一しておかなくてはいけません. ライブラリ関数が仮定している構造体のデータ構造と呼出元が仮定している 構造体のデータ構造が食い違っていては,マトモに動作することは期待できません.

カーネルとユーザランドプログラム

これらも ABI を統一しておく必要かあります. これも同様の理由です.


次のページ 前のページ 目次へ