-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move rarely used sections of documentation to dedicated files.
- Loading branch information
Showing
3 changed files
with
44 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Sometimes you may want to reduce public interface of existing closed-source shared library (e.g. if it's a third-party lib which erroneously exports too many unrelated symbols). | ||
|
||
To achieve this you can generate a wrapper with limited number of symbols and override the callback which loads the library to use `dlmopen` instead of `dlopen` (and thus does not pollute the global namespace): | ||
|
||
``` | ||
$ cat mysymbols.txt | ||
foo | ||
bar | ||
$ cat mycallback.c | ||
#define _GNU_SOURCE | ||
#include <dlfcn.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#ifdef __cplusplus | ||
extern "C" | ||
#endif | ||
// Dlopen callback that loads library to dedicated namespace | ||
void *mycallback(const char *lib_name) { | ||
void *h = dlmopen(LM_ID_NEWLM, lib_name, RTLD_LAZY | RTLD_DEEPBIND); | ||
if (h) | ||
return h; | ||
fprintf(stderr, "dlmopen failed: %s\n", dlerror()); | ||
exit(1); | ||
} | ||
$ implib-gen.py --dlopen-callback=mycallback --symbol-list=mysymbols.txt libxyz.so | ||
$ ... # Link your app with libxyz.tramp.S, libxyz.init.c and mycallback.c | ||
``` | ||
|
||
Similar approach can be used if you want to provide a common interface for several libraries with partially intersecting interfaces (see [this example](tests/multilib/run.sh) for more details). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Sometimes you may need to rename API of existing shared library to avoid name clashes. | ||
|
||
To achieve this you can generate a wrapper with _renamed_ symbols which call to old, non-renamed symbols in original library loaded via `dlmopen` instead of `dlopen` (to avoid polluting global namespace): | ||
|
||
``` | ||
$ cat mycallback.c | ||
... Same as before ... | ||
$ implib-gen.py --dlopen-callback=mycallback --symbol_prefix=MYPREFIX_ libxyz.so | ||
$ ... # Link your app with libxyz.tramp.S, libxyz.init.c and mycallback.c | ||
``` |