带有 arm64 交叉编译器的 gcc 插件:无法打开共享对象文件

gcc plugins with arm64 cross compiler : cannot open shared object file

我正在尝试使用 gcc 插件在编译时计算每个结构的大小。搜索时,我遇到了 this article.

我使用本机 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 二进制工具链进行了尝试,但得到了同样的错误。我错过了什么?

该插件作为编译器的一部分运行,因此仍然需要为主机构建,无论该编译器的目标是什么。虽然很高兴构建它们,但作为 x86 程序本身,您的交叉编译器实际上不能使用 AArch64 共享对象,正如它告诉您的那样。