1

gcc プラグインを使用して、コンパイル時に各構造体のサイズを計算しようとしています。検索して、この記事に出くわしました。

ネイティブの x64 gcc コンパイラを使用して以下のテスト プログラムで試してみたところ、次の結果が得られました。

#include <stdio.h>

struct TEST {
  int a;
  unsigned long b;
  char p[100];
};

int main(int argc, const char *argv[])
{
  struct TEST t;

  t.a = 10;

  t.a += 1;

  scanf("%s", t.p);
  scanf("%lu", &t.b);
  scanf("%d", &t.a);

  printf("%d\n", t.a);

  return 0;
}

結果 :-

Loaded structsizes plugin (GCC 5.4.0..)
ignoring unnamed struct
struct '_IO_FILE' has incomplete type
struct '_IO_FILE' has incomplete type
struct '_IO_FILE' has incomplete type
ignoring unnamed struct
ignoring unnamed struct
ignoring unnamed struct
struct '_IO_jump_t' has incomplete type
struct '_IO_FILE' has incomplete type
struct '_IO_marker' has incomplete type
struct '_IO_FILE' has incomplete type
struct '_IO_marker' has size 192 [bits]
struct '_IO_marker' has size 192 [bits]
struct '_IO_FILE' has incomplete type
struct '_IO_FILE' has size 1728 [bits]
struct '_IO_FILE' has size 1728 [bits]
struct '_IO_FILE_plus' has incomplete type
struct '_IO_FILE_plus' has incomplete type
struct '_IO_FILE_plus' has incomplete type
struct '_IO_FILE_plus' has incomplete type
struct '_IO_FILE' has size 1728 [bits]
struct '_IO_FILE' has size 1728 [bits]
struct '_IO_FILE' has size 1728 [bits]
struct 'TEST' has size 960 [bits]
struct 'TEST' has size 960 [bits]

今度は、aarch64 クロス コンパイラで同じことを試します。私が持っているクロスコンパイラのバージョンは次のとおりです:-

> aarch64-linux-gnu-gcc --version                                                                                                                       
aarch64-linux-gnu-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609

私はgccプラグインを次のようにコンパイルします:-

$ aarch64-linux-gnu-gcc -g -I/usr/lib/gcc-cross/aarch64-linux-gnu/5/plugin/include -fpic -shared -o structsizes.so structsizes.cc

$ file structsizes.so
structsizes.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, BuildID[sha1]=64b00b52af267537f94d8c4c651f3235e7c7b722, not stripped

今、私は test.c を次のようにコンパイルしようとします:-

$ aarch64-linux-gnu-gcc -fplugin=./structsizes.so -fplugin-arg-structsizes-log=/tmp/logfile -o test test.c
cc1: error: cannot load plugin ./structsizes.so
./structsizes.so: cannot open shared object file: No such file or directory

なぜこのエラーが発生するのですか? ダウンロードしたlinaroバイナリツールチェーンでも試してみましたが、同じエラーが発生しました。私は何が欠けていますか?

4

1 に答える 1

1

プラグインはコンパイラの一部として実行されるため、そのコンパイラのターゲットが何であるかに関係なく、ホスト マシン用にビルドする必要があります。それらを構築することは喜ばしいことですが、x86 プログラム自体は、クロスコンパイラーが実際にAArch64 共有オブジェクトを使用することはできません。

于 2016-11-13T23:16:53.620 に答える