Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hiding functions in C

I have application that has a function f1 void f1 ()

In addition, I have a library that I load using LD_PRELOAD.

The library has several code files and several header file, and it compiled to .so file.

On of the header files also uses a function named f1 with same signature as above. The latest f1 is used only in the library. (I can not change it to static method)

The problem is that when I load the library (using LD_PRELOAD) f1 from the library overrides f1 of the application.

Is there a way to configure f1 of the library to be visible only to the library?

like image 574
dk7 Avatar asked Mar 10 '13 12:03

dk7


1 Answers

If you can modify the header files at all, make the function static to make it visible only in that compilation unit, or mark it with __attribute__ ((visibility ("hidden"))) (GCC only) to make it visible only in that library:

__attribute__ ((visibility ("hidden"))) void f1();
like image 88
nneonneo Avatar answered Oct 01 '22 23:10

nneonneo