Re: Bug in GCC or Linking shared library

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9 January 2013 19:13, Vijay N. Majagaonkar wrote:
> Hi Everyone,
>
> I have two shared library linked to executable and both library has a
> function called 'foo()' but both function signature differs. When
> foo() is called in executable the call to foo() is executed from
> unexpected shared library.

This is the expected behaviour, the symbol name of a C function is
only the function name, not its signature.

> Call to function foo()  is depended on order of shared library linked
> while building executable. For example if executable built using
> libx.so first in order then foo() is called out of libx.so library and
> if liby.so is placed first then foo() is called out of liby.so, even
> though foo() in liby.so has a completely different signature but still
> foo() is called out of liby.so if liby.so linked before libx.so.
>
> I have tried with few other gcc flags but all ended with same problem.
>
> It will be great help if somebody help me to fix this issue.

What's the issue?
You've described what happens, but not what you want to happen.

If you just want the linker to determine the right function based only
on the signature then you'll need to switch to use C++ instead of C,
because then functions with different signatures have different linker
symbols, and you could also use namespaces to distinguish functions in
different modules.

If you can't or won't do that, then you could adjust the linkage or
visibility of the symbols in all but one library, so they are not
callable from outside the library. But that will prevent them ever
being called from outside the library, even if you use the right
signature.

> main.c:
>
> int main(int argc, char **argv)  {
>
>      get_num(0);
>      get_char('c');
>
>      return 0;
>
> }

You haven't declared these functions in main.c, if you care about
calling functions with the right signature then you should really
declare your functions properly!


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux