I am trying to compute the sizes of each struct at compile time using a gcc plugin. Searching, I came across this article.
I tried it out on a test program below with my native x64 gcc compiler and got the following results.
#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;
}
Results :-
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]
Now I try the same for my aarch64 cross compiler. The version of the cross compiler I have is :-
> aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609
I compile the gcc plugin as :-
$ 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
Now, I try to compile test.c as :-
$ 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
Why does this error occur? I tried it with a linaro binary toolchain that I downloaded as well and got the same error. What am I missing?