Questions tagged [gcc-plugins]

For Q/A relating to the GCC (Gnu compiler collection) plugins. This API allows you access to internals of the compiler to perform analysis and code modifications via modules loaded at runtime. Question on general use of the plugins are fine, such as how to pass arguments. The tag is NOT for creating other application plugins which are compiling with gcc.

For Q/A relating to the GCC (Gnu compiler collection) plugins. This API allows you access to internals of the compiler to perform analysis and code modifications via modules loaded at runtime. Question on general use of the plugins are fine, such as how to pass arguments. The tag is NOT for creating other application plugins which are compiling with gcc.

Selected online resources

50 questions
65
votes
1 answer

How to add a builtin function in a GCC plugin?

It is possible for a GCC plugin to add a new builtin function? If so, how to do it properly? GCC version is 5.3 (or newer). The code is compiled and processed by the plugin written in C. It is mentioned in the rationale for GCC plugins at…
Eugene
  • 5,977
  • 2
  • 29
  • 46
13
votes
2 answers

GCC Plugin, add new optimizing pragma

I'm creating a GCC plugin. I'm trying to create a plugin for a specific loop transformation - unroll loop exactly N (parameter given) times. I have installed plugins correctly and I can successfully register my pragma in compilation process. When I…
Michal Bukovy
  • 422
  • 3
  • 16
7
votes
2 answers

Getting started with GCC plugins

So after searching the web for a while, Ive decided to try here as it seems to be a good forum for discussion. Im trying to create a simple gcc plugin. The program code is attached in the end of this mail, but in plain english it registers the…
llubder
  • 71
  • 1
  • 2
4
votes
1 answer

Creating custom gcc attribute to instrument specific functions: whitelisting, not blacklisting

I'm using gcc's -finstrument-functions option. To minimize the overhead, I want to instrument only a few functions. However, gcc only lets you blacklist functions (with the no_instrument_function attribute, or by providing a list of paths). It…
4
votes
1 answer

How to embed metadata in object file from GCC plugin

I'm trying to write a GCC plugin that does some domain-specific analysis of the programs it compiles. I'm wondering about the best way to embed the analysis results as some kind of metadata (like debug information) in the generated object…
Isabelle Newbie
  • 9,258
  • 1
  • 20
  • 32
4
votes
1 answer

Valgrind with dynamically linked GCC plugin

I've been using the profiling tool valgrind for a while now. It requires an executable to run, i.e. $ valgrind ./a.out I want to use it on a dynamically linked GCC plugin, and list the time taken and the number of calls by each function used in…
Suryansh
  • 193
  • 2
  • 12
4
votes
5 answers

Insert global variable declaration with a gcc plugin

I would like to know if it's possible to insert a global variable declaration with a gcc plugin. For example if I have the following code: test.c: int main(void) { return 0; } and I want to transform it into: int fake_var; int main(void) { …
Andres Tiraboschi
  • 543
  • 1
  • 7
  • 17
3
votes
1 answer

How to get all system include path in a gcc plugin?

I'm doing a GCC Plugin to check a coding style for C and header files. I check the coding style at the compilation with : register_callback(plugin_info->base_name, PLUGIN_START_UNIT, start_unit_callback,…
neo-jgrec
  • 167
  • 8
3
votes
0 answers

GCC Plugin: Is it possible to move a sequence of a basic block of one function to a basic block of another function?

I'm trying to create a plugin for gcc that allows you to instrument the prologue and the epilogue of a function. The instrumentation code is inserted in two functions "instrument_entry" and "instrument_exit". These two functions are written in a…
Mark
  • 51
  • 6
3
votes
1 answer

Debugging a gcc plugin

I'm currently writing a plugin for gcc (9.2) and am looking for a way to debug said plugin. For this purpose I have built gcc using these instructions to enable debug symbols for gcc. I then try to debug the plugin by invoking gcc within gdb with…
3
votes
1 answer

Register a GIMPLE pass in gcc 5.1.0

Hi I've been doing gcc plugins for gcc 4.8 and 4.9 but I'm having a problem in gcc 5.1.0. The problem is that I can't register a GIMPLE pass in this new gcc version. Here is an example plugin code: int plugin_is_GPL_compatible; static bool…
Andres Tiraboschi
  • 543
  • 1
  • 7
  • 17
3
votes
2 answers

GCC Plugins, GCC Melt or gcc Python plugins to write a gcc extension

I need to write a GCC extension, I am trying to use the GCC Plugins API that is fournished with GCC, but it is poorly documented, and very difficult to use, I can't find any example using the last version of it ... I read that there are many other…
Othman Benchekroun
  • 1,998
  • 2
  • 17
  • 36
2
votes
1 answer

What is the purpose of __mptr in latest container_of macro?

I am reading linux kernel 5.17.5 and now looking at container_of() macro. /** * container_of - cast a member of a structure out to the containing structure * @ptr: the pointer to the member. * @type: the type of the container struct this is…
Puhan Zhou
  • 23
  • 3
2
votes
2 answers

Modification of the AST-tree of the GCC compiler

It is needed to gather the necessary information about the translation unit using the plugin for GCC and to modify AST on its base. I've already understood how to gather information. But I haven't understand yet how to modify AST before it's passed…
niXman
  • 1,698
  • 3
  • 16
  • 40
2
votes
0 answers

Error building program using gcc plugin from linux kernel source tree

I am trying to use a grsecurity gcc plugin that I found on their unofficial linux kernel source tree (the respectre_plugin/ one). My GCC version is 4.7, I modified scripts/gcc-plugins/Makefile to make it compile the plugin, and I built it with the…
Lurricane
  • 21
  • 3
1
2 3 4