I have a daemon I'm working on that seems to bomb out in the middle of strcmp, WAY down in the bowels of the ODBC library. It would run for hours, then just mysteriously quit (well, as mysteriously as a SIGSEGV can be)- classic memory corruption symptom. So, I built it with Electric Fence (which, at least superficially, seems a pretty nifty product). When I start it with gdb, this is what I get, pretty much immediately, as the program is initializing:

Note the shared libraries
#0 0xa7996270 in strcmp () from /lib/tls/libc.so.6
#1 0xa794a0d9 in setlocale () from /lib/tls/libc.so.6
#2 0xa60c43fa in my_SQLExtendedFetch () from /usr/lib/odbc/libmyodbc.so
#3 0xa60c45b6 in SQLFetch () from /usr/lib/odbc/libmyodbc.so
#4 0xa7a7d798 in SQLFetch () from /usr/lib/libodbc.so.1
#5 0x0805604b in t_dbBuffer<topic>::GetNext (this=0xa6a8cfd8,
at /home/anw/SoftwareProducts/Headers/dbTempDef.h:195
#6 0x08050844 in rssd::InitRSS (this=0xa6d4cf1c) at rssd.cpp:808
#7 0x08050997 in rssd::AppInit (this=0xa6d4cf1c) at rssd.cpp:667
#8 0x0805c9b6 in main (argc=1, argv=0xafe3e6a4) at App.cpp:47

I've got at least two questions here: I wrote my own quick and dirty strcmp to at least try and find out what the comparison strings were, but, although all the code I wrote picks up my strcmp, this part of the code doesn't.

Why would it use two different copies of strcmp?
How do I force it to use my version?

Here's the compile line, with all make substitutions done:

gcc rssd.cpp topic.o user.o subscription.o smsClt.o -o rssd -g -D_LINUX -I ~anw/Software/Headers -I /usr/include/nptl -L /usr/lib/debug -L~anw/Software/Libraries -L /usr/lib/nptl -D _LINUX -DNETDATASVC_EXPORTS -lApp -lLog -lxml -lxerces-c -lstdc++ -lpthread -lSimpleNet -lSerPort -lodbc -lDBUtils -lefence
rm topic.o subscription.o user.o smsClt.o

My strcmp is in the library ~anw/Software/Libraries/libDBUtils.a.

Note, also, that I have the debug versions of the standard libraries installed (the -L /usr/lib/debug switch), and, evidently, it's not picking up those either.


9 Years
Discussion Span
Last Post by Salem

>Why would it use two different copies of strcmp?
Presumably the two copies are the standard strcmp and your own strcmp with the same name. Overriding a standard function with a custom function of the same name is tricky business.

>How do I force it to use my version?
Give your version a unique name and make sure that the unique name is used instead of strcmp.


> Here's the compile line, with all make substitutions done:
Is that what doing "gcc -v" told you?

I'm at least a little suspicious about whether ~ expansions work or not in this context.

Also, why are you using gcc to compile C++?
The usual method would be to use g++, then you get all the correct libraries and startup code executed.


The whole point is to replace the standard strcmp with my own; I want setlocale, in particular to use it because that is where the problem is. I don't want just my code to use it.

Why is it picking up the libc version instead of mine? And, if it wants to get the system version, why won't it take the debug version in the directory specified with the -L /usr/lib/debug switch, since that is first on the library line?



No, that's not what gcc -v told me, it's what make echo'd back. Will that not be the same?

Good point about ~expansions. I'll try that.

Also good point about gcc vs. g++. Don't know what the differences are; I've compiled a lot of C++ code with gcc, but I think now is a good time to start using the right tool for the job. Could be there is some weird interaction between all these strange new libraries I'm using and not using g++. xerces is specifically a C++ package, and odbc is specifically a C package. I'll make that particular change right now.


You compile c++ with gcc, you are joking aren't you?

Saying g++ means that all the correct options get passed to the linker (not just -lstdc++, lot of other goodies as well no doubt).

One important thing may be arranging for global constructors and destructors to be called.

> strcmp()
Look up the --wrap linker command line switch, which allows you to replace one function with another.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.