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

时间:2016-11-13 10:55:19

标签: c gcc plugins arm64

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

1 个答案:

答案 0 :(得分:1)

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