This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Undefined references to `std::locale::id::_S_highwater'
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Re: Undefined references to `std::locale::id::_S_highwater'
- From: Michael Elizabeth Chastain <chastain at cygnus dot com>
- Date: Sun, 25 Mar 2001 02:39:57 -0800
- Cc: jason at cygnus dot com
I narrowed down the problem:
. I ran libstdc++-v3/src/locale.cc through the preprocessor and boiled
it down to a fifty line test program.
. I date-searched gcc down to a single patch.
My platform is native Red Hat Linux 7. I am using gcc-3_0-branch, but I
think the same code is in mainline. The bug happens when I compile with
"g++ -O2 -S"; it does not happen with "g++ -S".
The problem with the test program is that g++ does not emit a definition
for the static class variable std::locale::id::_S_highwater, or for
the simpler static class variable foo::i. The variables are "static"
in the sense of being class-static, but they do have external linkage.
This problem affects a file in libstdc++ and causes unresolved externals
for std::locale:id::_S_highwater with the latest g++'s.
Michael Elizabeth Chastain
<chastain@redhat.com>
"love without fear"
===
// compile with g++ -O2 -S
// look for the definition of std::locale::id::_S_highwater
// look for the definition of foo::i
// this part comes from libstdc++-v3/src/locale.cc
typedef unsigned int size_t;
namespace std
{
using ::size_t;
}
namespace std
{
class locale;
class locale
{
class id;
};
class locale::id
{
private:
static size_t _S_highwater;
};
}
namespace std
{
size_t locale::id::_S_highwater;
}
// this is a very simple example
class foo
{
public:
static int i;
};
int foo::i;
===
Output of "g++ -O2 -S y1.cc" with a compiler from "2001-03-22 14:40:00 UTC".
This output is good:
.file "y1.cc"
.version "01.01"
gcc2_compiled.:
.comm _ZNSt6locale2id12_S_highwaterE,4,4
.comm _ZN3foo1iE,4,4
.ident "GCC: (GNU) 3.0 20010322 (prerelease)"
Output of "g++ -O2 -S y1.cc" with a compiler from "2001-03-22 14:49:00 UTC".
This output is bad:
.file "y1.cc"
.version "01.01"
gcc2_compiled.:
.ident "GCC: (GNU) 3.0 20010322 (prerelease)"
===
diff -u -r -N -x CVS 2001-03-22-14.40.00/source/gcc/ChangeLog 2001-03-22-14.49.00/source/gcc/ChangeLog
--- 2001-03-22-14.40.00/source/gcc/ChangeLog Thu Mar 22 06:55:30 2001
+++ 2001-03-22-14.49.00/source/gcc/ChangeLog Thu Mar 22 09:46:52 2001
@@ -1,3 +1,8 @@
+2001-03-22 Jason Merrill <jason@redhat.com>
+
+ * toplev.c (wrapup_global_declarations): Don't emit DECL_COMDAT
+ variables unless necessary, either.
+
2001-03-22 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.texi: Remove more obsolete documentation of bugs and
diff -u -r -N -x CVS 2001-03-22-14.40.00/source/gcc/toplev.c 2001-03-22-14.49.00/source/gcc/toplev.c
--- 2001-03-22-14.40.00/source/gcc/toplev.c Wed Mar 14 13:26:32 2001
+++ 2001-03-22-14.49.00/source/gcc/toplev.c Thu Mar 22 09:47:00 2001
@@ -1975,8 +1975,8 @@
defined in a main file, as opposed to an include file. */
if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
- && (! TREE_READONLY (decl)
- || TREE_PUBLIC (decl)
+ && (((! TREE_READONLY (decl) || TREE_PUBLIC (decl))
+ && !DECL_COMDAT (decl))
|| (!optimize
&& flag_keep_static_consts
&& !DECL_ARTIFICIAL (decl))