実験コードを載せます。
C
1 1 #include<stdio.h> 2 2 3 3 int a = 100; 4 4 int c; 5 5 6 6 int main(){ 7 7 const int i = 0; 8 8 char *buf = "you will make me happy"; 9 9 10 10 printf("%d, %d, %d ,%s\n", a, c, i, buf); 11 11 return 0; 12 12 } 13 13
以下にアセンブリコードを載せます。
1 .file "global.c" 2 .globl a 3 .data 4 .align 4 5 .type a, @object 6 .size a, 4 7 a: 8 .long 100 9 .comm c,4,4 10 .section .rodata 11 .LC0: 12 .string "you will make me happy" 13 .LC1: 14 .string "%d, %d, %d ,%s\n" 15 .text 16 .globl main 17 .type main, @function 18 main: 19 .LFB0: 20 .cfi_startproc 21 pushq %rbp 22 .cfi_def_cfa_offset 16 23 .cfi_offset 6, -16 24 movq %rsp, %rbp 25 .cfi_def_cfa_register 6 26 subq $16, %rsp 27 movl $0, -4(%rbp) 28 leaq .LC0(%rip), %rax 29 movq %rax, -16(%rbp) 30 movl c(%rip), %edx 31 movl a(%rip), %eax 32 movq -16(%rbp), %rsi 33 movl -4(%rbp), %ecx 34 movq %rsi, %r8 35 movl %eax, %esi 36 leaq .LC1(%rip), %rdi 37 movl $0, %eax 38 call printf@PLT 39 movl $0, %eax 40 leave 41 .cfi_def_cfa 7, 8 42 ret 43 .cfi_endproc 44 .LFE0: 45 .size main, .-main 46 .ident "GCC: (Debian 6.3.0-18) 6.3.0 20170516" 47 .section .note.GNU-stack,"",@progbits
このドットから始まる行に焦点を当てます。
セクションについて
アセンブラ言語の翻訳
gasのディレクティブについて
ドットから始まる行は、疑似命令であり、ディレクティブであり、サブセクション(??)であるんですかね?
readelf --segment a.out で、セクションとセグメントを表示できます。
これとは全くの別物ですよね??
(例えば、dataセクション、textセクションは、デレクティブの疑似命令に同じ名前が使用されている。)
サブセクションは疑似命令とは明確に区別されるんですか??
.LC0:は、ラベルであり、疑似命令であると言えるんですかね?
機械語のコードは、textセクションに配置さるはずです。
しかし、
.section .rodata ・・・・?
.section ディレクティブを利用すると、その指定以降の部分(コードなり変数なり)を置くセクションを指定することが出来る。
sectionディレクティブは1回しか出てきていません。
え?機械語がrodataセクションに配置されるってこと??
意味がわかりません。
movl c(%rip), %edx
Cなんてラベルないけど・・・?
確かにC言語の方には、初期化をしていないグローバル変数として、Cはありますが、アセンブリ言語の方にはCというラベルすらない状態です。どういうことでしょうか?
実行コードを逆アセンブルするとこれらの、疑似命令はなくなります。
つまり、プログラムがセクションに分割されるのは、アセンブラ実行の後ということですよね?
疑似命令、ディレクティブの読み方を教えてください。
Linux 64bit Gasです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/07 14:18
2017/07/07 14:24
2017/07/07 14:53
2017/07/07 14:58
2017/07/11 00:03