Hacking Assembly Code Generated by G++_C/C++_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > C/C++ > Hacking Assembly Code Generated by G++

Hacking Assembly Code Generated by G++

 2013/6/19 11:18:51  yaojingguo  程序员俱乐部  我要评论(0)
  • 摘要:ForthefollowingC++code:classperson{public:person(){}person(constperson&rhs){}};voidfunc(personp){}intmain(intargc,constchar*argv[]){personyao;func(yao);return0;}Run"g++-S"produces(some.cfidirectivesremoved):.file"clean.cpp".section.text
  • 标签:SEM

For the following C++ code:

?

class="cpp" name="code">class person {
  public:
    person() {}
    person(const person& rhs) {}
};
void func(person p) {
}
int main(int argc, const char *argv[]) 
{
  person yao; 
  func(yao);
  return 0;
}

?

Run "g++ -S" produces (some .cfi directives removed):

?

	.file	"clean.cpp"
	.section	.text._ZN6personC2Ev,"axG",@progbits,_ZN6personC5Ev,comdat
	.align 2
	.weak	_ZN6personC2Ev
	.type	_ZN6personC2Ev, @function
_ZN6personC2Ev:
.LFB1:
	pushl	%ebp
	movl	%esp, %ebp
	popl	%ebp
	ret
.LFE1:
	.size	_ZN6personC2Ev, .-_ZN6personC2Ev
	.section	.text._ZN6personC2ERKS_,"axG",@progbits,_ZN6personC5ERKS_,comdat
	.align 2
	.weak	_ZN6personC2ERKS_
	.type	_ZN6personC2ERKS_, @function
_ZN6personC2ERKS_:
.LFB4:
	pushl	%ebp
	movl	%esp, %ebp
	popl	%ebp
	ret
.LFE4:
	.size	_ZN6personC2ERKS_, .-_ZN6personC2ERKS_
	.text
	.globl	_Z4func6person
	.type	_Z4func6person, @function
_Z4func6person:
.LFB6:
	pushl	%ebp
	movl	%esp, %ebp
	popl	%ebp
	ret
.LFE6:
	.size	_Z4func6person, .-_Z4func6person
	.globl	main
	.type	main, @function
main:
.LFB7:
	pushl	%ebp
	movl	%esp, %ebp
	andl	$-16, %esp
	subl	$32, %esp
	leal	30(%esp), %eax
	movl	%eax, (%esp)
	call	_ZN6personC1Ev
	leal	30(%esp), %eax
	movl	%eax, 4(%esp)
	leal	31(%esp), %eax
	movl	%eax, (%esp)
	call	_ZN6personC1ERKS_
	leal	31(%esp), %eax
	movl	%eax, (%esp)
	call	_Z4func6person
	movl	$0, %eax
	leave
	ret
.LFE7:
	.size	main, .-main
	.weak	_ZN6personC1Ev
	.set	_ZN6personC1Ev,_ZN6personC2Ev
	.weak	_ZN6personC1ERKS_
	.set	_ZN6personC1ERKS_,_ZN6personC2ERKS_
	.ident	"GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
	.section	.note.GNU-stack,"",@progbits

?

?To see the meaningful names for the mangle function names, user c++filt. For how gcc does name mangling on Linux, see?http://refspecs.linux-foundation.org/cxxabi-1.83.html#mangling.

?

For the source code, we can have the following conclusion. A person object is created using its constructor. Before calling func, a new person object is created using its copy constructor.

发表评论
用户名: 匿名