This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/7708: g++ -O inserts definition of std::string::replace in library module
- From: Bradford Castalia <Castalia at azstarnet dot com>
- To: bangerth at dealii dot org, Castalia at azstarnet dot com, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
- Date: Mon, 13 Jan 2003 17:36:47 -0700
- Subject: Re: c++/7708: g++ -O inserts definition of std::string::replace in library module
- Organization: idaeim
- References: <20021220021953.11703.qmail@sources.redhat.com>
- Reply-to: Castalia at azstarnet dot com
I've just installed the gcc32 package from the FreePSG ports site:
idaeim:castalia>> g++ --version
g++ (GCC) 3.2.1
After running the test cases, as well as the full recompile of my project code,
I can confirm that the -O switch no longer generates library symbol definitions
for the std::string::replace method.
Using a Test.h file:
#include <string>
class Test
{
public:
Test (const std::string& message = "");
void message (const std::string& message);
private:
std::string Message;
};
And a Test.cpp file:
#include "Test.h"
Test::Test (const std::string& message) : Message (message)
{
if (! Message.empty () && Message[Message.size () - 1] == '\n')
Message.erase (Message.size () - 1);
}
void Test::message (const std::string& new_message)
{
Message.replace (std::string::size_type(0), Message.length (), new_message);
if (! Message.empty () && Message[Message.size () - 1] == '\n')
Message.erase (Message.size () - 1);
}
Building an object module compiled with g++ 3.1.1 20020617 (prerelease) [FreeBSD]
(g++31 -O -c -o opt-Test.o Test.cpp) and then examing the object symbols reveals,
in addition to the weak symbols, a text symbol for "replace":
idaeim:castalia>> nm -g -o -C opt-Test.o | grep replace
opt-Test.o:00000000 W std::string& std::string::_M_replace<char const*>(__gnu_cxx::__normal_iterator<char*, std::string>, __gnu_cxx::__normal_iterator<char*, std::string>, char const*, char const*, std::input_iterator_tag)
opt-Test.o:00000000 W std::string& std::string::_M_replace_safe<__gnu_cxx::__normal_iterator<char*, std::string> >(__gnu_cxx::__normal_iterator<char*, std::string>, __gnu_cxx::__normal_iterator<char*, std::string>, __gnu_cxx::__normal_iterator<char*, std::string>, __gnu_cxx::__normal_iterator<char*, std::string>)
opt-Test.o:00000000 W std::string& std::string::_M_replace_safe<char const*>(__gnu_cxx::__normal_iterator<char*, std::string>, __gnu_cxx::__normal_iterator<char*, std::string>, char const*, char const*)
opt-Test.o:000001f0 T std::string::replace(unsigned, unsigned, char const*, unsigned)
Building an object module compiled with g++ 3.2.1 and then examing the symbols
reveals that the text symbol is now an undefined reference to "replace" as expected:
idaeim:castalia>> nm -g -o -C new-opt-Test.o | grep replace
new-opt-Test.o:00000000 W std::string& std::string::_M_replace<char const*>(__gnu_cxx::__normal_iterator<char*, std::string>, __gnu_cxx::__normal_iterator<char*, std::string>, char const*, char const*, std::input_iterator_tag)
new-opt-Test.o:00000000 W std::string& std::string::_M_replace_safe<__gnu_cxx::__normal_iterator<char*, std::string> >(__gnu_cxx::__normal_iterator<char*, std::string>, __gnu_cxx::__normal_iterator<char*, std::string>, __gnu_cxx::__normal_iterator<char*, std::string>, __gnu_cxx::__normal_iterator<char*, std::string>)
new-opt-Test.o:00000000 W std::string& std::string::_M_replace_safe<char const*>(__gnu_cxx::__normal_iterator<char*, std::string>, __gnu_cxx::__normal_iterator<char*, std::string>, char const*, char const*)
new-opt-Test.o: U std::string::replace(unsigned, unsigned, char const*, unsigned)
The problem of problem of multiple definitions at link time has now been fixed.
Thnx!
--
Bradford Castalia
Systems Analyst
bangerth@dealii.org wrote:
>
> Synopsis: g++ -O inserts definition of std::string::replace in library module
>
> State-Changed-From-To: open->feedback
> State-Changed-By: bangerth
> State-Changed-When: Thu Dec 19 18:19:52 2002
> State-Changed-Why:
> I tried your program with gcc3.2, but on x86 linux. I can
> confirm that the mentioned symbols are present in the
> object file. However, they are weak:
> 00000000 W std::string& std::string::_M_replace<....
>
> Weak symbols means: they can be in multiple object files,
> and one of these copies is picked at link time.
>
> Could you possibly check whether the problem still exists
> on your platform with gcc3.2.1?
>
> Thanks
> Wolfgang
>
> http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7708
Wolfgang Bangerth wrote:
>
> On Sun, 22 Dec 2002, Bradford Castalia wrote:
>
> > When I get gcc3.2.1 (or greater) installed on the FreeBSD workstation
> > (hasn't happened yet, sorry) I will definately run the test files
> > again. You will probably get a faster response from one of the FreeBSD
> > developers (http://www.FreeBSD.org).
>
> Please let us know about your results. Maybe someone of the FeeBSD
> maintainers could also try to look into this?
>
> Regards
> Wolfgang
>
> -------------------------------------------------------------------------
> Wolfgang Bangerth email: bangerth@ticam.utexas.edu
> www: http://www.ticam.utexas.edu/~bangerth