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 回答