Last Update 2020/09/24
-x assembler-with-cpp
コンパイラへ供給するファイルの言語を明示的に指定
assembler-with-cpp : プリプロセスが必要なアセンブラファイル
assembler-with-cpp : プリプロセスが必要なアセンブラファイル
テスト概要
言語指定を「-x assembler-with-cpp」として、プリプロセスが必要なアセンブラファイルをコンパイル
PASS
コンパイル終了・実行ファイル生成
言語指定を「-x assembler-with-cpp」として、プリプロセスが不要なアセンブラファイルをコンパイル
PASS
コンパイル終了・実行ファイル生成
実行環境
GCC-8.2.0
GNU C Library 2.28
GNU Binutils 2.31.1
GNU C Library 2.28
GNU Binutils 2.31.1
コード例・出力内容中の表記
・実行例中の太字表記部分は、コマンドなどの入力された文字列を示します。
・「︙」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。
・「︙」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。
使用ファイル
sample.c
/* -x オプション動作確認用ソースファイル */
#include
int main(void)
{
printf("-x オプション動作確認用ソースファイル\n");
return 0;
}
言語指定を「-x assembler-with-cpp」として、プリプロセスが必要なファイルをコンパイル
テスト用アセンブラファイルの生成
$ ls -l
total 4
-rw-r--r-- 1 ****** ******** 190 *** ** **:** sample.c
$ gcc -v -S sample.c <--- アセンブル直前で停止させるためSオプションでコンパイル
Using built-in specs.
︙
/usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -quiet -v sample.c ... -o sample.s
︙
COLLECT_GCC_OPTIONS='-v' '-S' '-mtune=generic' '-march=x86-64' <--- アセンブル以降の処理は未実施
$ ls -l
total 8
-rw-r--r-- 1 ****** ******** 190 *** ** **:** sample.c
-rw-r--r-- 1 ****** ******** 634 *** ** **:** sample.s <--- 作成されたアセンブラファイル
$
sample.s(生成されたアセンブラファイル)
.file "sample.c"
.text
.section .rodata
.align 8
.LC0:
.string "-x \343\202\252\343\203\227\343\202\267\343\203\247\343\..."
.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
movl $.LC0, %edi
call puts
movl $0, %eax
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (GNU) 8.2.0"
.section .note.GNU-stack,"",@progbits
sample.sの以下の箇所を変更して、sample2.sとして保存
(1) 1行目として追加
#define TESTSTR "\343\202\252\343\203\227\343\202\267\343\203\247\343\203\263"
(2) 6行目を変更
.string TESTSTR
言語指定を「-x assembler-with-cpp」としてコンパイル
$ ls -l
total 12
-rw-r--r-- 1 ****** ******** 515 *** ** **:** sample2.s
-rw-r--r-- 1 ****** ******** 190 *** ** **:** sample.c
-rw-r--r-- 1 ****** ******** 517 *** ** **:** sample.s
$ gcc -v -x assembler-with-cpp sample2.s
Using built-in specs.
︙
/usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -E -lang-asm -quiet -v sample2.s ... -o /tmp/cclWnYx0.s
︙ ^^^ sample2.sのコンパイル
as -v --64 -o /tmp/ccKxH6bL.o /tmp/cclWnYx0.s
︙
/usr/libexec/c/x86_64-pc-linux-gnu/8.2.0/collect2 ...
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
$ ls -l
total 32
-rwxr-xr-x 1 ****** ******** 18328 *** ** **:** a.out <--- アセンブラファイルから実行ファイルを生成
-rw-r--r-- 1 ****** ******** 515 *** ** **:** sample2.s
-rw-r--r-- 1 ****** ******** 190 *** ** **:** sample.c
-rw-r--r-- 1 ****** ******** 517 *** ** **:** sample.s
$ ./a.out
-x オプション <--- プリプロセッサで定義した文字列を出力
$
言語指定を「-x assembler-with-cpp」として、プリプロセスが不要なファイルをコンパイル
コンパイル結果
$ ls -l
total 12
-rw-r--r-- 1 ****** ******** 515 *** ** **:** sample2.s
-rw-r--r-- 1 ****** ******** 190 *** ** **:** sample.c
-rw-r--r-- 1 ****** ******** 634 *** ** **:** sample.s
$ gcc -v -x assembler-with-cpp sample.s
Using built-in specs.
︙
/usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -E -lang-asm -quiet -v sample.s ... -o /tmp/ccEqqOPp.s
︙ ^^^ sample.sのコンパイル
as -v --64 -o /tmp/ccogiGal.o /tmp/ccEqqOPp.s
︙
/usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/collect2 ...
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
$ ls -l
total 32
-rwxr-xr-x 1 ****** ******** 18328 *** ** **:** a.out <--- アセンブラファイルから実行ファイルを生成
-rw-r--r-- 1 ****** ******** 515 *** ** **:** sample2.s
-rw-r--r-- 1 ****** ******** 190 *** ** **:** sample.c
-rw-r--r-- 1 ****** ******** 634 *** ** **:** sample.s
$ ./a.out
-x オプション動作確認用ソースファイル <--- sample.sの出力内容
$