bootblock
+ cc boot/bootasm.S
gcc -Iboot/ -fno-builtin -Wall -ggdb -m32 -gstabs -nostdinc -fno-stack-protector -Ilibs/ -Os -nostdinc -c boot/bootasm.S -o obj/boot/bootasm.o
+ cc boot/bootmain.c
gcc -Iboot/ -fno-builtin -Wall -ggdb -m32 -gstabs -nostdinc -fno-stack-protector -Ilibs/ -Os -nostdinc -c boot/bootmain.c -o obj/boot/bootmain.o
+ cc tools/sign.c
gcc -Itools/ -g -Wall -O2 -c tools/sign.c -o obj/sign/tools/sign.o
gcc -g -Wall -O2 obj/sign/tools/sign.o -o bin/sign
上面是bootblock的编译过程, 生成多个可重定位文件,在通过链接器链接到一起。
语法格式 gcc [-c|-S|-E] [-std=standard] [-g] [-pg] [-Olevel] [-Wwarn...] [-Wpedantic] [-Idir...] [-Ldir...] [-Dmacro[=defn]...] [-Umacro] [-foption...] [-mmachine-option...] [-o outfile] [@file] infile...
-I : ①指定头文件目录 ②-L-l一起使用,指定程序的链接库
-fno-builtin 禁用C语言的内建函数
-Wall 显示所有警告
-ggdb Produce debugging information for use by GDB.
-m32 生成32位代码
-gstabs Produce debugging information in stabs format (if that is supported), withoutGDB extensions.
-nostdinc Do not search the standard system directories for header files. Only the directories you have specified with ‘-I’ options
-fno-stack-protector
-Os Optimize for size. ‘-Os’ enables all ‘-O2’ optimizations that do not typically increase code size.
-g Produce debugging information in the operating system’s native format
+ ld bin/bootblock
ld -m elf_i386 -nostdlib -N -e start -Ttext 0x7C00 obj/boot/bootasm.o obj/boot/bootmain.o -o obj/bootblock.o
'obj/bootblock.out' size: 488 bytes
build 512 bytes boot sector: 'bin/bootblock' success!
-m elf_i386
-nostdlib
-N Set the text and data sections to be readable and writable.
-e Use start as the explicit symbol for beginning execution of your program
-Ttext 0x7C00 设置代码段的起始地址
dd if=bin/bootblock of=bin/ucore.img conv=notrunc
1+0 records in
1+0 records out
512 bytes copied, 7.9894e-05 s, 6.4 MB/s
共512字节大小 以0x55AA结尾