Inlining functions from object files
I want to inline some functions of which I don't have the code. They are present in an object file. Is there a way to do it with gcc?
In other words, I want to perform inlining of those functions while linking my own code files with the object file that contain开发者_如何学编程 those functions.
Starting with version 4.5, GCC supports the -flto switch which enables Link Time Optimization (LTO). LTO can inline functions from separate object files.
There's a catch though. Because of the way that -flto
works, it'll only be of use for object files that were compiled using that switch. As I understand it, GCC implements LTO by placing a intermediate form of the source code into the object file - if that intermediate code isn't in the object file, the code in that object file won't be 'inlined'.
See Can the linker inline functions? for some additional details.
What you want to do is just the contrary of inlining. Inlining means that you have the source and you want the compiler to generate code as if that source was defined in place of the caller.
What with some effort perhaps could be done would be to extract the object code and place it inside the newly generated object code for your functions. But this makes not much sense: the only advantage of inlining is that the optimizer can work across the boundaries of functions. E.g to avoid spill of registers, do constant propagation or eliminate dead code. All this would be nearly impossible when you only have the object.
精彩评论