2

I'm writing a gcc (version 5.4.0) plugin, which is intend to instrument some codes in functions. It's easy to do that by inserting some rtx or gimple instructions in a certain function:

a = foo();
instrument codes here;
b = foo();

But since the context in functions could be different, I'd like to instrument a call to my function, like:

a = foo();
call to instrument my function;
b = foo();

The problem is that I can't find a way to add my function, neither in gcc or with plugin. There's a related question: how-to-add-a-builtin-function-in-a-gcc-plugin, but it doesn't solve my problem. Any suggestions?

artless noise
  • 21,212
  • 6
  • 68
  • 105
liubenxi
  • 91
  • 9
  • Can you provide some reference about what you try to do -- a reference in the gcc manual -- ? – alinsoar Jun 06 '17 at 08:17
  • I want to append a function to the output elf file, and instrument some calls to the function, with gcc plugin. The function is defined by myself, it can be defined in C file, or created during compiling. Sorry but I didn't find anything related to my problem in [gcc internal](https://gcc.gnu.org/onlinedocs/gccint/). – liubenxi Jun 06 '17 at 08:30
  • If you manage to find a reference within the gcc or some related soft you have bigger chances for other to understand... – alinsoar Jun 06 '17 at 08:32
  • Maybe you want to modify the linker scripts of ld ? https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/simple-example.html – alinsoar Jun 06 '17 at 08:34
  • I want to create, and append functions in an optimization pass. GCC allows insertion of new function during compilation, and there is a certain function: `cgraph_node::add_new_function()`. I may modify the instructions in new functions , so I need the internal represents of new functions during compilation(like `treenodes`). ld can be used to add codes to executables, but it won't solve my problem. The idea is somehow like this one: [https://gcc.gnu.org/ml/gcc-help/2016-09/msg00026.html](https://gcc.gnu.org/ml/gcc-help/2016-09/msg00026.html). – liubenxi Jun 06 '17 at 09:15
  • I think you need and go on @gcc mailing lists and explain them the problem, it is too gcc-specific. They will provide you the answer within a few hours. If you get the answer paste it here . – alinsoar Jun 06 '17 at 10:24

0 Answers0