29
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

gccでアセンブリ出力したときに.cfi_startprocなどが邪魔なので抑制する方法

Last updated at Posted at 2019-01-18

gcc -Sでアセンブリを出力すると、.cfi_startproc,.cfi_offsetなどがごちゃごちゃと書かれていてコードが読みづらいです。

これらは "CFI directive"というもので、デバグ用の特殊なディレクティブらしいです。

hello worldをアセンブル。

$ gcc -S hello-world.c  -o hello-world.s

デフォルトだとこうなる。

	.file	"hello-world.c"
	.text
	.section	.rodata
.LC0:
	.string	"hello world"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	.LC0(%rip), %rdi
	call	puts@PLT
	movl	$0, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 7.3.0-16ubuntu3) 7.3.0"
	.section	.note.GNU-stack,"",@progbits

CFI directiveを無効にする方法

-fno-asynchronous-unwind-tables というオプションを付ければ無効にできます。

$ gcc  -fno-asynchronous-unwind-tables  -S hello-world.c -o hello-world.s

無効にした結果。
見やすい!

	.file	"hello-world.c"
	.text
	.section	.rodata
.LC0:
	.string	"hello world"
	.text
	.globl	main
	.type	main, @function
main:
	pushq	%rbp
	movq	%rsp, %rbp
	leaq	.LC0(%rip), %rdi
	call	puts@PLT
	movl	$0, %eax
	popq	%rbp
	ret
	.size	main, .-main
	.ident	"GCC: (Ubuntu 7.3.0-16ubuntu3) 7.3.0"
	.section	.note.GNU-stack,"",@progbits

参考: https://stackoverflow.com/questions/2529185/what-are-cfi-directives-in-gnu-assembler-gas-used-for

29
11
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
29
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?