[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#223391: marked as done (gcc-3.2: Anonymous namespaces can sometimes still cause cross-object symbol conflicts)



Your message dated Tue, 13 Jan 2004 20:24:10 +0100
with message-id <16388.17882.43832.554714@gargle.gargle.HOWL>
and subject line Bug#223391: gcc-3.2: Anonymous namespaces can sometimes still cause cross-object symbol conflicts
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--------------------------------------
Received: (at submit) by bugs.debian.org; 9 Dec 2003 01:38:39 +0000
>From apenwarr@nit.ca Mon Dec 08 19:38:09 2003
Return-path: <apenwarr@nit.ca>
Received: from ptr-64-201-187-81.ptr.terago.ca (mars.net-itech.com) [64.201.187.81] 
	by master.debian.org with smtp (Exim 3.35 1 (Debian))
	id 1ATWHP-0003dp-00; Mon, 08 Dec 2003 19:03:11 -0600
Received: (qmail 32723 invoked from network); 9 Dec 2003 01:03:10 -0000
Received: from unknown (HELO insight.internal.nit.ca) (192.168.12.100)
  by mars.net-itech.com with SMTP; 9 Dec 2003 01:02:51 -0000
Received: from apenwarr by insight.internal.nit.ca with local (Exim 3.34 #1 (Debian))
	id 1ATWGe-0001ZU-00; Mon, 08 Dec 2003 20:02:24 -0500
Received: from apenwarr by insight.internal.nit.ca with local (Exim 3.34 #1 (Debian))
	id 1ATWBI-0001YC-00; Mon, 08 Dec 2003 19:56:52 -0500
From: Avery Pennarun <apenwarr@insight.nit.ca>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: gcc-3.2: Anonymous namespaces can sometimes still cause cross-object symbol conflicts
X-Mailer: reportbug 1.50
Date: Mon, 08 Dec 2003 19:56:51 -0500
Message-Id: <E1ATWBI-0001YC-00@insight.internal.nit.ca>
Resent-From: apenwarr@worldvisions.ca
Resent-Date: Mon, 8 Dec 2003 20:02:24 -0500
Resent-To: submit@bugs.debian.org
Resent-Message-Id: <E1ATWGe-0001ZU-00@insight.internal.nit.ca>
Delivered-To: submit@bugs.debian.org
X-Spam-Checker-Version: SpamAssassin 
	2.60-master.debian.org_2003_11_25-bugs.debian.org_2003_11_20 
	(1.212-2003-09-23-exp) on master.debian.org
X-Spam-Status: No, hits=-2.4 required=4.0 tests=BAYES_99,HAS_PACKAGE,
	NO_DNS_FOR_FROM autolearn=no 
	version=2.60-master.debian.org_2003_11_25-bugs.debian.org_2003_11_20
X-Spam-Level: 

Package: gcc-3.2
Version: 1:3.2.3-0pre9
Severity: normal

The attached test program, when compiled with

	make CXX=g++-2.95
	
produces this output:

	creating test2.o
	creating test1.o
	starting

but when compiled with

	make CXX=g++-3.2
	
produces this output:

	creating test1.o
	creating test1.o
	starting

This is because C++ anonymous namespaces (namespaces created without names,
ie. namespace { ... };) are actually exported from object files using weak
symbols, and only one of the symbols is actually linked into the final
program.  The weak symbols have funny auto-generated names that are intended
to avoid name conflicts between object files, but the name-generation scheme
used in gcc 3.2 is based on the *source* filename, which might be the same
for two different object files.  In my example, the makefile does this:

	g++-3.2 -c -o test1.o -DTEST='"test1.o"' testx.cc
	g++-3.2 -c -o test2.o -DTEST='"test2.o"' testx.cc

This makes the compiler output different for the two object files, although
the symbol names end up being the same (as you can see with 'nm -D
test1.o').

Note that:

 - gcc-2.95 (debian 2.95.4-0.01042) does *not* exhibit this problem; it
   seems to use a random number for its random namespace symbol names.
   
 - there is probably no reason to make the symbols from that namespace
   anything other than file-local anyway.  Anonymous namespaces are
   explicitly not expected to be accessible from any other object.
   
Source code follows.

Have fun,

Avery



-- System Information
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux insight 2.4.19 #1 mer sep 4 10:52:04 EDT 2002 i686
Locale: LANG=fr_CA, LC_CTYPE=fr_CA

Versions of packages gcc-3.2 depends on:
ii  binutils                2.13.90.0.18-1.7 The GNU assembler, linker and bina
ii  cpp-3.2                 1:3.2.3-0pre9    The GNU C preprocessor
ii  gcc-3.2-base            1:3.2.3-0pre9    The GNU Compiler Collection (base 
ii  libc6                   2.3.2.ds1-10     GNU C Library: Shared libraries an
ii  libgcc1                 1:3.3-2          GCC support library


>>>>>>>>>>>>>>>>>>>>>>>> Makefile >>>>>>>>>>>>>>>>>


main: main.o test1.o test2.o
	$(CXX) -o main $^

test%.o: testx.cc
	$(CXX) -c -o $@ -DTEST='"$@"' $^

clean:
	rm -f *.o *~ *.so main


>>>>>>>>>>>>>>>>>>>>>>>> main.cc >>>>>>>>>>>>>>>>>>>>>>

#include <stdio.h>

int main()
{
	printf("starting\n");
	return 0;
}


>>>>>>>>>>>>>>>>>>>>>>>> testx.cc >>>>>>>>>>>>>>>>>>>>>>>

#include <stdio.h>

namespace {
	struct Blah {
		Blah() { printf("creating %s\n", TEST); }
	};

	static Blah blah;
};



>>>>>>>>>>>>>>>>>>>>>> END >>>>>>>>>>>>>>>>>>>>



---------------------------------------
Received: (at 223391-done) by bugs.debian.org; 13 Jan 2004 20:29:17 +0000
>From doko@cs.tu-berlin.de Tue Jan 13 14:29:17 2004
Return-path: <doko@cs.tu-berlin.de>
Received: from mail.cs.tu-berlin.de [130.149.17.13] 
	by master.debian.org with esmtp (Exim 3.35 1 (Debian))
	id 1AgUF3-0005tK-00; Tue, 13 Jan 2004 13:30:21 -0600
Received: from bolero.cs.tu-berlin.de (doko@bolero.cs.tu-berlin.de [130.149.19.1])
	by mail.cs.tu-berlin.de (8.9.3p2/8.9.3) with ESMTP id UAA20937;
	Tue, 13 Jan 2004 20:24:10 +0100 (MET)
Received: (from doko@localhost)
	by bolero.cs.tu-berlin.de (8.12.10+Sun/8.12.8/Submit) id i0DJOAMs017501;
	Tue, 13 Jan 2004 20:24:10 +0100 (MET)
From: Matthias Klose <doko@cs.tu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-ID: <16388.17882.43832.554714@gargle.gargle.HOWL>
Date: Tue, 13 Jan 2004 20:24:10 +0100
To: Avery Pennarun <apenwarr@insight.nit.ca>, 223391-done@bugs.debian.org
Subject: Re: Bug#223391: gcc-3.2: Anonymous namespaces can sometimes still cause cross-object symbol conflicts
In-Reply-To: <E1ATWBI-0001YC-00@insight.internal.nit.ca>
References: <E1ATWBI-0001YC-00@insight.internal.nit.ca>
X-Mailer: VM 7.03 under 21.4 (patch 6) "Common Lisp" XEmacs Lucid
Delivered-To: 223391-done@bugs.debian.org
X-Spam-Checker-Version: SpamAssassin 2.60-bugs.debian.org_2004_01_13 
	(1.212-2003-09-23-exp) on master.debian.org
X-Spam-Status: No, hits=-3.0 required=4.0 tests=HAS_BUG_NUMBER autolearn=no 
	version=2.60-bugs.debian.org_2004_01_13
X-Spam-Level: 

This is fixed in current gcc-3.3, which is the default gcc in
Debian. Therefore closing the report.

Avery Pennarun writes:
> Package: gcc-3.2
> Version: 1:3.2.3-0pre9
> Severity: normal
> 
> The attached test program, when compiled with
> 
> 	make CXX=g++-2.95
> 	
> produces this output:
> 
> 	creating test2.o
> 	creating test1.o
> 	starting
> 
> but when compiled with
> 
> 	make CXX=g++-3.2
> 	
> produces this output:
> 
> 	creating test1.o
> 	creating test1.o
> 	starting
> 
> This is because C++ anonymous namespaces (namespaces created without names,
> ie. namespace { ... };) are actually exported from object files using weak
> symbols, and only one of the symbols is actually linked into the final
> program.  The weak symbols have funny auto-generated names that are intended
> to avoid name conflicts between object files, but the name-generation scheme
> used in gcc 3.2 is based on the *source* filename, which might be the same
> for two different object files.  In my example, the makefile does this:
> 
> 	g++-3.2 -c -o test1.o -DTEST='"test1.o"' testx.cc
> 	g++-3.2 -c -o test2.o -DTEST='"test2.o"' testx.cc
> 
> This makes the compiler output different for the two object files, although
> the symbol names end up being the same (as you can see with 'nm -D
> test1.o').
> 
> Note that:
> 
>  - gcc-2.95 (debian 2.95.4-0.01042) does *not* exhibit this problem; it
>    seems to use a random number for its random namespace symbol names.
>    
>  - there is probably no reason to make the symbols from that namespace
>    anything other than file-local anyway.  Anonymous namespaces are
>    explicitly not expected to be accessible from any other object.
>    
> Source code follows.
> 
> Have fun,
> 
> Avery
> 
> 
> 
> -- System Information
> Debian Release: testing/unstable
> Architecture: i386
> Kernel: Linux insight 2.4.19 #1 mer sep 4 10:52:04 EDT 2002 i686
> Locale: LANG=fr_CA, LC_CTYPE=fr_CA
> 
> Versions of packages gcc-3.2 depends on:
> ii  binutils                2.13.90.0.18-1.7 The GNU assembler, linker and bina
> ii  cpp-3.2                 1:3.2.3-0pre9    The GNU C preprocessor
> ii  gcc-3.2-base            1:3.2.3-0pre9    The GNU Compiler Collection (base 
> ii  libc6                   2.3.2.ds1-10     GNU C Library: Shared libraries an
> ii  libgcc1                 1:3.3-2          GCC support library
> 
> 
> >>>>>>>>>>>>>>>>>>>>>>>> Makefile >>>>>>>>>>>>>>>>>
> 
> 
> main: main.o test1.o test2.o
> 	$(CXX) -o main $^
> 
> test%.o: testx.cc
> 	$(CXX) -c -o $@ -DTEST='"$@"' $^
> 
> clean:
> 	rm -f *.o *~ *.so main
> 
> 
> >>>>>>>>>>>>>>>>>>>>>>>> main.cc >>>>>>>>>>>>>>>>>>>>>>
> 
> #include <stdio.h>
> 
> int main()
> {
> 	printf("starting\n");
> 	return 0;
> }
> 
> 
> >>>>>>>>>>>>>>>>>>>>>>>> testx.cc >>>>>>>>>>>>>>>>>>>>>>>
> 
> #include <stdio.h>
> 
> namespace {
> 	struct Blah {
> 		Blah() { printf("creating %s\n", TEST); }
> 	};
> 
> 	static Blah blah;
> };
> 
> 
> 
> >>>>>>>>>>>>>>>>>>>>>> END >>>>>>>>>>>>>>>>>>>>
> 
> 
> 
> 
> -- 
> To UNSUBSCRIBE, email to debian-gcc-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org



Reply to: