content_views"
class="htmledit_views">
前两天看到一篇文章c;color:#333333">使用color:#333333">Ccolor:#333333">class="tags" href="/tags/BianYiQi.html" title=编译器>编译器创建无格式的二进制文件(color:#333333">i386+color:#333333">)(color:#333333">1-6color:#333333">)(译)
http://xieyubo.spaces.live.com/blog/cns!55B39819C9DA4A2!282.entry
ckquote style="border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; color:rgb(51,51,51); margin-left:40px; padding-left:0px; padding-right:0px; padding-top:0px; padding-bottom:0px; margin-top:0px; margin-bottom:0px; font-style:italic; font-size:11.5px; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; margin-right:0px; border-width:initial; border-color:initial">
1.
class="tags" href="/tags/GCC.html" title=gcc>gcc -c test.c
ld -o test -Ttext 0x0 -e main test.o
objcopy -R .note -R .comment -S -O binary test test.bin
class="tags" href="/tags/GCC.html" title=gcc>gcc -c test.c
ckquote>
ckquote style="border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; color:rgb(51,51,51); margin-left:40px; padding-left:0px; padding-right:0px; padding-top:0px; padding-bottom:0px; margin-top:0px; margin-bottom:0px; font-style:italic; font-size:11.5px; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; margin-right:0px; border-width:initial; border-color:initial">
ld test.o -o test.bin -Ttext 0x0 -e main -oformat binary
ckquote>
现在假设我们有一个段使用class="tags" href="/tags/HuiBian.html" title=汇编>汇编编写的程序c;而我们又需要将它加入我们最后生成的文件中c;我们可以使用下面的方法:
ckquote style="border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; color:rgb(51,51,51); margin-left:40px; padding-left:0px; padding-right:0px; padding-top:0px; padding-bottom:0px; margin-top:0px; margin-bottom:0px; font-style:italic; font-size:11.5px; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; margin-right:0px; border-width:initial; border-color:initial">
nasm -f elf other.asm -o other.o
class="tags" href="/tags/GCC.html" title=gcc>gcc -c test.c
ld other.o main.o -o kernal.bin -Ttext 0x0 -e _mian --oformat binary
ckquote>
目前class="tags" href="/tags/LINUX.html" title=linux>linux大多都是elf格式目标文件c;所以我们首先将class="tags" href="/tags/HuiBian.html" title=汇编>汇编程序编译为elf的目标文件c;然后使用ld将多个目标文件链接到一起即可。
使用GNU ld (GNU Binutils for Ubuntu) 2.20c; class="tags" href="/tags/GCC.html" title=gcc>gcc (Ubuntu 4.4.1-4class="tags" href="/tags/UBUNTU.html" title=ubuntu>ubuntu8) 4.4.1 c; NASM version 2.05.01