public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* assembly code produced from G++
@ 2011-08-18 13:53 charfi asma
  2011-08-18 14:11 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: charfi asma @ 2011-08-18 13:53 UTC (permalink / raw)
  To: gcc-help


Hello,

I look at the assembly code generated from this c++ file:

class MyClass { 
public : void signal_operation (fsm_events evt) {
// code of the function };
}

int main() {
MyClass c;
c.signal_operation(e1);
....
}

G++ change the name of the functions and the variables and this raise the 
assembly code size : signal_operation is changed to 
_ZN7MyClass16signal_operationE10fsm_events

file    "NSC.cpp"
    .section   
 .text._ZN7MyClass16signal_operationE10fsm_events,"axG",@progbits,_ZN7MyClass16signal_operationE10fsm_events,comdat

    .align 2
    .weak    _ZN7MyClass16signal_operationE10fsm_events
    .type    _ZN7MyClass16signal_operationE10fsm_events, @function
_ZN7MyClass16signal_operationE10fsm_events:
.LFB0:
    movl    (%rdi), %eax
    cmpl    $1, %eax
.....
.globl    main
    .type    main, @function
main:
........
    movl    $0, 12(%rsp)
    call    _ZN7MyClass16signal_operationE10fsm_events
 ......

However, when I compile the same C++ code (produce the same GIMPLE form) using 
my own front end I get nearly the same assembly without this names change.

.file    "NSC.cpp"
    .text
    .type    signal_operation.26, @function
signal_operation.26:
.LFB0:
    movl    (%rdi), %eax
    cmpl    $1, %eax
.....
.globl    main
    .type    main, @function
main:
.....
movl    $0, 12(%rsp)
call    signal_operation.26
 ......

I have 2 questions:
- Did my front end generate a bad assembly ? Is the name change necesseray to 
execute the code ?
- My assembly file did not contain those 3 lines for the signal_operation 
function:

    .section   
 .text._ZN7MyClass16signal_operationE10fsm_events,"axG",@progbits,_ZN7MyClass16signal_operationE10fsm_events,comdat

    .align 2
    .weak    _ZN7MyClass16signal_operationE10fsm_events 

are they essentiel to produce the right .o or the right  .out ? 

thank you very much

Asma

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

* Re: assembly code produced from G++
  2011-08-18 13:53 assembly code produced from G++ charfi asma
@ 2011-08-18 14:11 ` Jonathan Wakely
  2011-08-18 14:42   ` Re : " charfi asma
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2011-08-18 14:11 UTC (permalink / raw)
  To: charfi asma; +Cc: gcc-help

Names in C++ are mangled to ensure that MyClass::foo(int) is a
distinct symbol from MyClass::foo(char) and AnotherClass::foo(int)

The mangling needs to be repeatable, so that if I compile
MyClass::foo(int) into an object file, and you compile another object
file which depends on MyClass::foo(int), the two symbols have the same
name and can be linked.

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

* Re : assembly code produced from G++
  2011-08-18 14:11 ` Jonathan Wakely
@ 2011-08-18 14:42   ` charfi asma
  0 siblings, 0 replies; 3+ messages in thread
From: charfi asma @ 2011-08-18 14:42 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

Thank you for your quick answer. If I understand, names mangled are helpful in 
some cases but not necesseray to produce the .o nor the .out
and thus, my assembly file generated withour mangled names is valid. 
thank you again.

Asma



----- Message d'origine ----
De : Jonathan Wakely <jwakely.gcc@gmail.com>
À : charfi asma <charfiasma@yahoo.fr>
Cc : gcc-help@gcc.gnu.org
Envoyé le : Jeu 18 août 2011, 16h 10min 48s
Objet : Re: assembly code produced from G++

Names in C++ are mangled to ensure that MyClass::foo(int) is a
distinct symbol from MyClass::foo(char) and AnotherClass::foo(int)

The mangling needs to be repeatable, so that if I compile
MyClass::foo(int) into an object file, and you compile another object
file which depends on MyClass::foo(int), the two symbols have the same
name and can be linked.

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

end of thread, other threads:[~2011-08-18 14:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-18 13:53 assembly code produced from G++ charfi asma
2011-08-18 14:11 ` Jonathan Wakely
2011-08-18 14:42   ` Re : " charfi asma

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