From: Gianni Mariani <gmariani@chaincast.com>
To: gcc@gcc.gnu.org
Subject: anonymous namespaces and possible linker trouble
Date: Sun, 05 Jan 2003 20:27:00 -0000 [thread overview]
Message-ID: <3E18924B.2020100@chaincast.com> (raw)
This is a question of how I could get into trouble.
I've had problems in the past with anonymous namespaces and symbol
clashes in the linker. While the code below seems to link fine in the
past (I don't remember which compiler) I had linker trouble on duplicate
definitions of "int xx".
How is this fixed in gcc now ?
I notice that symbols are still global:
.LFE1:
.Lfe1:
.size _Z1bi,.Lfe1-_Z1bi
.globl _ZN16_GLOBAL__N__Z1bi2xxE
.bss
.align 4
.type _ZN16_GLOBAL__N__Z1bi2xxE,@object
.size _ZN16_GLOBAL__N__Z1bi2xxE,4
_ZN16_GLOBAL__N__Z1bi2xxE:
.zero 4
.text
.align 2
So I'm thinking that some strange heristic is used to create a symbol
name that will likely no clash - but that's not guarenteed.
Why do symbols defined in anonymous namespaces need to have global
linkage ? Why can't they be defined using local linkage ?
like:
.local xx
.comm xx,4,4
.text
G
>>>> a.cpp
void b( int a );
namespace {
int xx;
};
void a( int a )
{
b( xx );
}
>>>>>>> b.cpp
void a( int xx );
void b( int a )
{
}
namespace {
int xx;
};
int main()
{
a( xx );
return 0;
}
>>>>> Makefile
xx : a.o b.o
$(CXX) -o xx $^
clean:
rm *.o xx
next reply other threads:[~2003-01-05 20:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-05 20:27 Gianni Mariani [this message]
2003-01-07 8:38 ` Gianni Mariani
2003-01-08 5:04 ` Gianni Mariani
2003-01-09 2:23 ` Joe Buck
2003-01-09 10:25 ` Gianni Mariani
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3E18924B.2020100@chaincast.com \
--to=gmariani@chaincast.com \
--cc=gcc@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).