`
yaojingguo
  • 浏览: 202401 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Hacking Assembly Code Generated by G++

阅读更多

For the following C++ 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.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics