[cfe-dev] Overriding static
Jon Wilson via cfe-dev
cfe-dev at lists.llvm.org
Thu Nov 2 04:20:00 PDT 2017
I would like to be able to test some third-party C code, which is quite large and has a large build system. I would like to call functions within the code and to provide alternative implementations (e.g. Mocks) of some of the functions (or indeed some of the data structures) which it implements (and link my code using -z muldefs). I am trying to find a generic solution which I will be able to apply to multiple projects without having to patch the original code.
For the code in question (and I expect many other projects) many of the methods and data are defined as static or inline. I can of course use the “-fno-inline” parameter to prevent functions from being inlined, but I cannot see any options which will allow or the static definition of methods or data to be removed (e.g. to make them global).
You can of course use the pre-processor to remove the keyword (e.g. -Dstatic=) but this has obvious problems. First, the pre-processor will replace the token wherever it is found (not just where it is used as an access modifier). Secondly, removing the token from a method declaration makes the method global, but removing it from a local variable within a function changes the behaviour.
Can I achieve what I need through existing flags to the compilation process? Or will I need to make some modifications to the compiler? If so then any hints to help navigate my way to the correct part of the code would be very welcome.
Many thanks for your advice.
More information about the cfe-dev