* anonymous namespaces and possible linker trouble
@ 2003-01-05 20:27 Gianni Mariani
2003-01-07 8:38 ` Gianni Mariani
0 siblings, 1 reply; 5+ messages in thread
From: Gianni Mariani @ 2003-01-05 20:27 UTC (permalink / raw)
To: gcc
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: anonymous namespaces and possible linker trouble
2003-01-05 20:27 anonymous namespaces and possible linker trouble Gianni Mariani
@ 2003-01-07 8:38 ` Gianni Mariani
2003-01-08 5:04 ` Gianni Mariani
0 siblings, 1 reply; 5+ messages in thread
From: Gianni Mariani @ 2003-01-07 8:38 UTC (permalink / raw)
To: gmariani; +Cc: gcc
Repost:
Can anyone comment ?
I'm basically asking what are the possibilities of conflicts of the same
symbols in different anonymous namesspaces and compilation units. This
was a problem I had seen in the past and I'd like to know wether I may
suffer this problem with gcc if I created a large number of files with
anonymous namespaces but with identical symbol names ?
G
Gianni Mariani wrote:
>
> 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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: anonymous namespaces and possible linker trouble
2003-01-07 8:38 ` Gianni Mariani
@ 2003-01-08 5:04 ` Gianni Mariani
2003-01-09 2:23 ` Joe Buck
0 siblings, 1 reply; 5+ messages in thread
From: Gianni Mariani @ 2003-01-08 5:04 UTC (permalink / raw)
To: gmariani; +Cc: gcc
Second repost:
So if no-one is capable/willing to help, can anyone be kind enough to
point me to the source files in gcc that are involved with creating the
symbol names for anonymous namespaces so I can figure it out myself. I
promise I'll report what I find.
G
Gianni Mariani wrote:
>
> Repost:
>
> Can anyone comment ?
>
> I'm basically asking what are the possibilities of conflicts of the
> same symbols in different anonymous namesspaces and compilation
> units. This was a problem I had seen in the past and I'd like to know
> wether I may suffer this problem with gcc if I created a large number
> of files with anonymous namespaces but with identical symbol names ?
>
> G
>
> Gianni Mariani wrote:
>
>>
>> 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
>>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: anonymous namespaces and possible linker trouble
2003-01-08 5:04 ` Gianni Mariani
@ 2003-01-09 2:23 ` Joe Buck
2003-01-09 10:25 ` Gianni Mariani
0 siblings, 1 reply; 5+ messages in thread
From: Joe Buck @ 2003-01-09 2:23 UTC (permalink / raw)
To: Gianni Mariani; +Cc: gcc
On Tue, Jan 07, 2003 at 05:21:14PM -0800, Gianni Mariani wrote:
>
> Second repost:
Instead of nagging us into responding, please search Google for
"anonymous namespace", and read the first result that you find
(or click "I'm feeling lucky"). It will give you a mailing list
message; please click "Thread Index" and follow the whole thread.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: anonymous namespaces and possible linker trouble
2003-01-09 2:23 ` Joe Buck
@ 2003-01-09 10:25 ` Gianni Mariani
0 siblings, 0 replies; 5+ messages in thread
From: Gianni Mariani @ 2003-01-09 10:25 UTC (permalink / raw)
To: Joe Buck; +Cc: gcc
Joe Buck wrote:
>On Tue, Jan 07, 2003 at 05:21:14PM -0800, Gianni Mariani wrote:
>
>
>>Second repost:
>>
>>
>
>Instead of nagging us into responding, please search Google for
>"anonymous namespace", and read the first result that you find
>(or click "I'm feeling lucky"). It will give you a mailing list
>message; please click "Thread Index" and follow the whole thread.
>
>
OK - my bad .... apologies etc etc ...
G
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-01-09 4:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-05 20:27 anonymous namespaces and possible linker trouble Gianni Mariani
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
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).