How to create shared stub libraries on Linux

Let me first explain what I mean with a common stub library: a shared library that can be used to communicate with (with a specific interface provided by a real library), but does not contain actual code (therefore does not have functionality).

Along with the header files, it provides everything you need for development against the library.

The ends may allow binding to a specific library without the presence of code, but it may also be useful for compatibility with a stub of a specific library for compatibility. See. For example, Linux uses stubs for standard libraries. Why are stubs required?

Ideally, I need a way to create a dummy library from a character map file. This map file, in turn, is created either from the existing .so library, or in the same build process.

Are there any tools for this free access? Or do I need to roll on my own?

+5
source share
1 answer

I assume for simple C libraries you can use nm -D output in your real shared library to make a stub. For example, you can pass it into a small awk script that defines functions with the same name, etc.

Another approach would be to make your little MELT extension to the recent GCC , which would generate a stub (for example, in the form of C ++ or C) when compiling a real library or clear every function body (in a special mode to compile only stub libraries). This will work in any language compiled by GCC (but requires some understanding of the internal components of GCC, such as Trees and Gimples). Ask gcc-melt@googlegroups.com

However, I am not sure to understand the practical interest of such stubs. In practice, the shared library contains some specific encoding rules and their use, and this is not verified using stubs. To be specific, if you use Xlib, you need to first call XOpenDisplay and XCloseDisplay , and such a rule cannot be verified with an automatically generated stub, etc.

+2
source

Source: https://habr.com/ru/post/1201724/


All Articles