注意:
:基本的なコンパイラオプション使用して
-E(前処理)
-S(アセンブリ言語にコンパイル)
-C(オブジェクトコードにコンパイル)
、実行可能ファイルにリンクされた
アセンブリ言語および実行ファイルobjdumpの分解を。
用例:
メイクファイル:
APP_NAME = compileopt
APP_OBJS = compileopt.o
CC = gcc
INC = ./
CFLAG += -g
.PHONY : all
all : $(APP_NAME) prev_compile post_compile
$(APP_NAME) : $(APP_OBJS)
$(CC) $(CFLAG) $(APP_OBJS) -o $(APP_NAME)
compileopt.o : compileopt.s
$(CC) -c compileopt.s -o compileopt.o
compileopt.s : compileopt.c
$(CC) -S compileopt.c -o compileopt.s
prev_compile :
$(CC) -E compileopt.c -o compileopt.i
post_compile :
objdump -s -d $(APP_NAME) > $(APP_NAME).txt
.PHONY : clean
clean :
rm -f *.o *.s *.i *.txt
rm -f $(APP_NAME) $(APP_OBJS)
ソースファイル:
/* compileopt.c */
#include <stdio.h>
#include <stdlib.h>
void printFunc(int i)
{
printf("hello world! a+b=%d\n", i);
}
int main()
{
int a = 1;
int b = 2;
printf("a+b=%d\n", a + b);
printFunc(a+b);
exit(0);
}