From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25763 invoked by alias); 14 Jan 2003 00:46:03 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 25749 invoked by uid 71); 14 Jan 2003 00:46:02 -0000 Date: Tue, 14 Jan 2003 00:46:00 -0000 Message-ID: <20030114004602.25748.qmail@sources.redhat.com> To: ljrittle@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Bradford Castalia Subject: Re: c++/7708: g++ -O inserts definition of std::string::replace in library module Reply-To: Bradford Castalia X-SW-Source: 2003-01/txt/msg00851.txt.bz2 List-Id: The following reply was made to PR c++/7708; it has been noted by GNATS. From: Bradford Castalia To: bangerth@dealii.org, Castalia@azstarnet.com, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org Cc: Subject: Re: c++/7708: g++ -O inserts definition of std::string::replace in library module Date: Mon, 13 Jan 2003 17:36:47 -0700 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 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(__gnu_cxx::__normal_iterator, __gnu_cxx::__normal_iterator, char const*, char const*, std::input_iterator_tag) opt-Test.o:00000000 W std::string& std::string::_M_replace_safe<__gnu_cxx::__normal_iterator >(__gnu_cxx::__normal_iterator, __gnu_cxx::__normal_iterator, __gnu_cxx::__normal_iterator, __gnu_cxx::__normal_iterator) opt-Test.o:00000000 W std::string& std::string::_M_replace_safe(__gnu_cxx::__normal_iterator, __gnu_cxx::__normal_iterator, 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(__gnu_cxx::__normal_iterator, __gnu_cxx::__normal_iterator, 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 >(__gnu_cxx::__normal_iterator, __gnu_cxx::__normal_iterator, __gnu_cxx::__normal_iterator, __gnu_cxx::__normal_iterator) new-opt-Test.o:00000000 W std::string& std::string::_M_replace_safe(__gnu_cxx::__normal_iterator, __gnu_cxx::__normal_iterator, 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