Re: Bug in GCC or Linking shared library

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

 



On 9 January 2013 20:04, Vijay N. Majagaonkar wrote:
>> 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.
>
> I think you got my problem, but let me clear why foo() is getting
> called out of liby.so
> When I'm passing only one argument?
> foo() in liby.so expecting 2 argument foo(Y st_y, double  val) but I'm
> calling foo('c') from main()

This is a basic feature of C, it has nothing to do with GCC all C
compilers work this way.

The function foo() is compiled to a symbol called "foo".

The function foo(Y, double) is compiled to a symbol called "foo"

When you call foo('c') the compiler creates a reference to a symbol
called "foo".  The linker resolves that reference by finding a symbol
called "foo". The first symbol called "foo" it finds gets used.  The
linker doesn't know or care what arguments your function takes, it
just sees a symbol called "foo" and it uses it.



> Switching to C++ is out of picture, it's legacy code and colossal code base.
>
>
>> 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.
>
> Thanks for this idea, I have tested by renaming function and works as expected.
>
>>
>> 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!
>
> Sorry it's my bad I just wrote sample code to test, in real code we do
> have function declarations.
>
>
> Thanks
> Vijay
> ;)


[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