This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
On 06/30/2016 12:33 PM, Goswin von Brederlow wrote:
> On Thu, Jun 30, 2016 at 11:55:27AM +0200, john smith wrote:
>> All static symbol have a short number attached to its name, for example:
>>
>> static const int def[9999999] = {1};
>>
>> shows up as:
>>
>> 0000000000400920 r def.2802
>>
>> What does this number represent? I know I can change it using
>> __asm__("def").
>>
>> I read this https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40831 and
>> this https://patchwork.ozlabs.org/patch/118607/ but I couldn't find a
>> definitive explanations of what these numbers mean.
>
> I'm guessing that is just a unique number generated to avoid name
> colisions in the binary. Think about this:
>
> Say you have two compilation units (files) and both have:
>
> static const int def[9999999] = {1};
>
> Since the variable is static you actually do have 2 separate variables
> called "def" and that is perfectly alright. But you can not have two
> symbols called "def" in the binary. The extra ".xxxx" keeps them
> distinct.
>
> MfG
> Goswin
>
Two files, x1.c and x2.c:
x1.c:
int
main(int argc, char **argv)
{
return(0);
}
static int staticsymbol;
int *pointer1 = &staticsymbol;
x2.c:
static int staticsymbol;
int *pointer2 = &staticsymbol;
Now:
gcc -o x x1.c x2.c
nm -n x
...
0804a008 D __data_start
0804a008 W data_start
0804a00c D __dso_handle
0804a010 D pointer1
0804a014 D pointer2
0804a018 A __bss_start
0804a018 A _edata
0804a018 b completed.5522
0804a01c b dtor_idx.5524
0804a020 b staticsymbol
0804a024 b staticsymbol
0804a028 A _end
It is perfectly ok to have several non-global symbols with the same name
(at least with coff and elf).
The number will only be attached when you declare the symbol within a
function.
x1.c (modified):
int
main(int argc, char **argv)
{
static int staticsymbol1;
return(0);
}
static int staticsymbol;
int *pointer1 = &staticsymbol;
now:
gcc -c x1.c
nm -n x1.o
00000000 T main
00000000 D pointer1
00000000 b staticsymbol
00000004 b staticsymbol1.1216
the number is necessary to avoid name clashes with symbols defined at
files scope.
regards, Matthias
--
Matthias Pfaller Software Entwicklung
marco Systemanalyse und Entwicklung GmbH Tel +49 8131 5161 41
Hans-Böckler-Str. 2, D 85221 Dachau Fax +49 8131 5161 66
http://www.marco.de/ Email leo@marco.de
Geschäftsführer Martin Reuter HRB 171775 Amtsgericht München
Attachment:
smime.p7s
Description: S/MIME Cryptographic Signature
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |