public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* understanding __FUNCTION__ generation
@ 2007-09-11 18:40 Sunzir Deepur
  2007-09-12  0:47 ` Jim Wilson
  0 siblings, 1 reply; 3+ messages in thread
From: Sunzir Deepur @ 2007-09-11 18:40 UTC (permalink / raw)
  To: gcc

hi list,

recently I've encountered a problem in which some removals of
(what seems to be unneeded) lines of header files inflicted changes in
the resulting binary. further inverstigation showed
that the chages were different __FUNCTION__.numbers (in the __FUNCTION__.
xxx symbol names).

can someone please help me understand what can change those numbers ?
how are they generated and what control them ?

thank you all
sunzir

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

* Re: understanding __FUNCTION__ generation
  2007-09-11 18:40 understanding __FUNCTION__ generation Sunzir Deepur
@ 2007-09-12  0:47 ` Jim Wilson
  2007-09-12  6:26   ` Sunzir Deepur
  0 siblings, 1 reply; 3+ messages in thread
From: Jim Wilson @ 2007-09-12  0:47 UTC (permalink / raw)
  To: Sunzir Deepur; +Cc: gcc

Sunzir Deepur wrote:
> recently I've encountered a problem in which some removals of
> (what seems to be unneeded) lines of header files inflicted changes in
> the resulting binary. further inverstigation showed
> that the chages were different __FUNCTION__.numbers (in the __FUNCTION__.
> xxx symbol names).

This would be clearer if you gave an example.  However, I'm guessing 
that the issue here is the names for function local statics.  The names 
for these are unique within a function, but not unique across a file. 
The assembler requires unique names for them, so we add the DECL_UID to 
make them unique.  See lhd_set_decl_assembler_name in langhooks.c.  The 
DECL_UID changes if you add/delete declarations.

For instance, if I compile this with -O -S for an x86_64-linux target
int *sub (void) { static int i = 10; return &i; }
int *sub2 (void) { static int i = 20; return &i; }
I get variables i.1499 and i.1504.  If I add another variable in the 
first line
static int y;
then I now have variables i.1500 and i.1505.

This wouldn't happen with functions unless you have nested functions.

You could see a similar problem if compiling multiple files as one unit, 
since static functions in different files could have the same name, 
which would have to be changed to make them unique.  This is probably 
handled in a different place in the gcc code, but probably handled the 
same way.

Jim

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

* Re: understanding __FUNCTION__ generation
  2007-09-12  0:47 ` Jim Wilson
@ 2007-09-12  6:26   ` Sunzir Deepur
  0 siblings, 0 replies; 3+ messages in thread
From: Sunzir Deepur @ 2007-09-12  6:26 UTC (permalink / raw)
  To: Jim Wilson; +Cc: gcc

Hi Jim,

On 9/12/07, Jim Wilson <wilson@specifix.com> wrote:
> Sunzir Deepur wrote:
> > recently I've encountered a problem in which some removals of
> > (what seems to be unneeded) lines of header files inflicted changes in
> > the resulting binary. further inverstigation showed
> > that the chages were different __FUNCTION__.numbers (in the __FUNCTION__.
> > xxx symbol names).
>
> This would be clearer if you gave an example.

 This is the diff between the old and the new binaries examined
under objdump -d -t :

2c2
< old.o:     file format elf32-i386
---
> new.o:     file format elf32-i386
10c10
< 00000000 l     O .rodata      0000000f __FUNCTION__.4883
---
> 00000000 l     O .rodata      0000000f __FUNCTION__.4848
12c12
< 0000005a l     O .rodata      00000010 __FUNCTION__.4921
---
> 0000005a l     O .rodata      00000010 __FUNCTION__.4886
17c17
< 000000d8 l     O .rodata      00000015 __FUNCTION__.4965
---
> 000000d8 l     O .rodata      00000015 __FUNCTION__.4930
20c20
< 00000119 l     O .rodata      0000000e __FUNCTION__.5002
---
> 00000119 l     O .rodata      0000000e __FUNCTION__.4967
22c22
< 000001a8 l     O .rodata      0000000e __FUNCTION__.5022
---
> 000001a8 l     O .rodata      0000000e __FUNCTION__.4987
24c24
< 0000021b l     O .rodata      00000010 __FUNCTION__.5051
---
> 0000021b l     O .rodata      00000010 __FUNCTION__.5016

> However, I'm guessing
> that the issue here is the names for function local statics.  The names
> for these are unique within a function, but not unique across a file.
> The assembler requires unique names for them, so we add the DECL_UID to
> make them unique.  See lhd_set_decl_assembler_name in langhooks.c.  The
> DECL_UID changes if you add/delete declarations.

Yes ! That is it ! Thanks so much ! I use the __FUNCTION__ macro
in my code, and i guess it is translated into a static variable holding
the function name, which perfectly fits your explanation !

Thanks!!
Sunzir

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

end of thread, other threads:[~2007-09-12  6:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-11 18:40 understanding __FUNCTION__ generation Sunzir Deepur
2007-09-12  0:47 ` Jim Wilson
2007-09-12  6:26   ` Sunzir Deepur

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).