使用arm64交叉编译器的GCC插件:无法打开共享对象文件



我试图在编译时使用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("%dn", 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共享对象,正如它告诉您的。

最新更新