public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/18077] New: Members of anonymous namespaces get name mangled with first global variable instead of file name
@ 2004-10-20 12:47 fafa at freesurf dot ch
  2004-10-20 13:06 ` [Bug c++/18077] [3.3/3.4/4.0 Regression] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: fafa at freesurf dot ch @ 2004-10-20 12:47 UTC (permalink / raw)
  To: gcc-bugs

Members of anonymous namespaces should get a name that is mangled in a way so 
as to make them unique. This is not the case if a global variable is defined 
before the keyword "namespace" is used. In that case the first global variable 
name is used for the name mangling. If I then link with "-z muldefs" I get 
wrong symbol resolution.

Example:
foo1.cpp:
  #include <stdio.h>

  int iii;
  namespace {
    void f() { printf("foo1\n"); }
  }

  void foo1() { f(); }

foo2.cpp:
  #include <stdio.h>

  int iii;
  namespace {
    void f() { printf("foo2\n"); }
  }

  void foo2() { f(); }

main.cpp:
  extern void foo1();
  extern void foo2();

  int main() {
    foo1();
    foo2();
    return 0;
  }

g++ -o foo foo1.cpp foo2.cpp main.cpp -z muldefs

./foo
generates the output
  foo1
  foo1
instead of
  foo1
  foo2
because both mangled names for the functions f are "_ZN14_GLOBAL__N_iii1fEv", 
and the linker chosses one of the two for both calls.

The error vanishes if I just write
  namespace {}
before the definition of iii, because then the mangled name of f changes 
to "_ZN25_GLOBAL__N_foo1.cppgmEtmb1fEv" which seems the correct name to me.

-- 
           Summary: Members of anonymous namespaces get name mangled with
                    first global variable instead of file name
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fafa at freesurf dot ch
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18077


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/18077] [3.3/3.4/4.0 Regression] Members of anonymous namespaces get name mangled with first global variable instead of file name
  2004-10-20 12:47 [Bug c++/18077] New: Members of anonymous namespaces get name mangled with first global variable instead of file name fafa at freesurf dot ch
@ 2004-10-20 13:06 ` pinskia at gcc dot gnu dot org
  2004-10-28  6:04 ` mmitchel at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-20 13:06 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-10-20 13:05 -------
Confirmed, a regression from 3.0.4.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |wrong-code
      Known to fail|                            |3.3.3 3.4.0 4.0.0
      Known to work|                            |3.0.4
   Last reconfirmed|0000-00-00 00:00:00         |2004-10-20 13:05:57
               date|                            |
            Summary|Members of anonymous        |[3.3/3.4/4.0 Regression]
                   |namespaces get name mangled |Members of anonymous
                   |with first global variable  |namespaces get name mangled
                   |instead of file name        |with first global variable
                   |                            |instead of file name
   Target Milestone|---                         |3.4.3


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18077


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/18077] [3.3/3.4/4.0 Regression] Members of anonymous namespaces get name mangled with first global variable instead of file name
  2004-10-20 12:47 [Bug c++/18077] New: Members of anonymous namespaces get name mangled with first global variable instead of file name fafa at freesurf dot ch
  2004-10-20 13:06 ` [Bug c++/18077] [3.3/3.4/4.0 Regression] " pinskia at gcc dot gnu dot org
@ 2004-10-28  6:04 ` mmitchel at gcc dot gnu dot org
  2004-10-28 17:27 ` fafa at freesurf dot ch
  2004-11-02  7:22 ` bugzilla at familie-koegl dot de
  3 siblings, 0 replies; 5+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2004-10-28  6:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From mmitchel at gcc dot gnu dot org  2004-10-28 06:04 -------
Using -z muldefs is beyond the scope of the C++ standard.

There is no way to win for everyone here; some people really do not want the
random names because they want predictability from the compiler.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18077


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/18077] [3.3/3.4/4.0 Regression] Members of anonymous namespaces get name mangled with first global variable instead of file name
  2004-10-20 12:47 [Bug c++/18077] New: Members of anonymous namespaces get name mangled with first global variable instead of file name fafa at freesurf dot ch
  2004-10-20 13:06 ` [Bug c++/18077] [3.3/3.4/4.0 Regression] " pinskia at gcc dot gnu dot org
  2004-10-28  6:04 ` mmitchel at gcc dot gnu dot org
@ 2004-10-28 17:27 ` fafa at freesurf dot ch
  2004-11-02  7:22 ` bugzilla at familie-koegl dot de
  3 siblings, 0 replies; 5+ messages in thread
From: fafa at freesurf dot ch @ 2004-10-28 17:27 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From fafa at freesurf dot ch  2004-10-28 17:27 -------
(In reply to comment #2)
> Using -z muldefs is beyond the scope of the C++ standard.
> 
> There is no way to win for everyone here; some people really do not want the
> random names because they want predictability from the compiler.

If the name of a symbol depends on the order of definition of variables which 
have nothing to do with this symbol, it's just as "random". And if I use the 
unnamed namespace first, I get what you call "random name" anyway. Is this 
predictable ?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18077


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/18077] [3.3/3.4/4.0 Regression] Members of anonymous namespaces get name mangled with first global variable instead of file name
  2004-10-20 12:47 [Bug c++/18077] New: Members of anonymous namespaces get name mangled with first global variable instead of file name fafa at freesurf dot ch
                   ` (2 preceding siblings ...)
  2004-10-28 17:27 ` fafa at freesurf dot ch
@ 2004-11-02  7:22 ` bugzilla at familie-koegl dot de
  3 siblings, 0 replies; 5+ messages in thread
From: bugzilla at familie-koegl dot de @ 2004-11-02  7:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bugzilla at familie-koegl dot de  2004-11-02 07:22 -------
(In reply to comment #2)
> Using -z muldefs is beyond the scope of the C++ standard.
> There is no way to win for everyone here; some people really do not want the
> random names because they want predictability from the compiler.

Yeah, and that's exactly why I would have expected the <= 3.0.4 behavior: the 
randomness in names results from later GCC's incorporating the name of the 
first global symbol in the symbol names of the unnamed namespace entities. I 
really don't see how the new behavior is less random or more predictable. 
Especially when one can switch back to the old behavior by including a file 
containing nothing but 'namespace {}' via -include. So what was the rationale 
for having changed the behavior at all?

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18077


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-11-02  7:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-20 12:47 [Bug c++/18077] New: Members of anonymous namespaces get name mangled with first global variable instead of file name fafa at freesurf dot ch
2004-10-20 13:06 ` [Bug c++/18077] [3.3/3.4/4.0 Regression] " pinskia at gcc dot gnu dot org
2004-10-28  6:04 ` mmitchel at gcc dot gnu dot org
2004-10-28 17:27 ` fafa at freesurf dot ch
2004-11-02  7:22 ` bugzilla at familie-koegl dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).