GCC plugin compilation issue

655 views Asked by At

I'm trying to cross-compile a custom kernel module (from this git), which depends on a plugin that is originally compiled within the git (it's in $git/buildtools/gcc-nexmon-plugin/nexmon.c).

Originally, this tree is intended to be built directly on the raspberry pi, but I would like to port this feature to a buildroot system, that is, I don't have gcc/g++ on my raspberry pi, I only cross-compile on my laptop.

My problem is how to properly create nexmon.so (the plugin file) so I can later use it while cross-compiling

The original command line to produce nexmon.so was:

g++ -std=c++11 -Wall -fno-rtti -fPIC -I../gcc-arm-noneabi[...]/plugin/include \
     -c -o nexmon.o nexmon.c

g++ -shared -o nexmon.so nexmon.o

As you can see they are including some cross-compiler within the tree ("../gcc-arm..").

Now I understand that the plugin SHOULD NOT be cross-compiled. Remember they want us to run this on the raspberry pi, so "g++" is the embedded "g++". On my side, I have to run "g++" of my laptop.

Unfortunately, I can't seem to get it to work on my laptop, here's what I am trying nowadays:

g++ -std=c++11 -Wall -fno-rtti -fPIC -I/usr/include \
   -I/usr/lib/gcc/x86_64-linux-gnu/8/plugin/include -o nexmon.o -c nexmon.c

Because I'm currently using g++ 8.3.0-6, and I located the corresponding headers for plugin development. If I run this, I am getting a TON of problems,

  • "in included plugin/include/tree.h file: #error Unknown BITS_PER_UNIT"
  • "in included plugin/include/cpplib.h file: #error Cannot find a least 32 bit signed integer type"

Which make me think I am missing some flags to properly define my laptop architecture - but I could be wrong.

Here's a complete PasteBin of my errors: output log

I think I do have stuff to build a plugin, because gcc8/plugin/include exist. I tried to install "gcc-multilib, gcc-8-plugin-dev-i686-linux-gnu, gcc-8-plugin-dev-x86-64-linux-gnux32, gcc-8-plugin-dev". I cannot come back to a previous gcc (like 4.8, 5, 6, 7) because all my debian upgrades removed them, they are not used anymore

Any help would be highly appreciated, no one has been able to help me so far and I ran out of ideas. This point is totally blocking to my project.

1

There are 1 answers

0
gwbres On

I am answering my own question because that might help people in the future

First of all, I was wrong on how to compile a plugin to be later used in a cross-compilation context, the correct way to do this is:

$(HOST_CXX) -fPIC -I$(TARGET_CC)/[..]/plugin/include -shared \
     -o plugin.so plugin.c

Therefore you are not cross-compiling, but calling the plugin developpement environment of your cross-compiler. To figure the correct include path, simply do:

$(TARGET_CXX) -print-file=plugin

My compilation issues were due to the fact this plugin was built for older gcc version (5+), while I am using (8+). My fix for that is was to replace the following line:

#include <plugin.h> 

(I assume, that was the old way to call the plugin dev. environment), by:

#include <gcc-plugin.h>