Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > 汇编语言 > building an absolute binary with gcc and ld
【标  题】:building an absolute binary with gcc and ld
【关键字】:gcc,ld
【来  源】:http://www.cnandusa.com

building an absolute binary with gcc and ld

Your Ad Here This kind of thing is done by Linux, FreeBSD, etc. in building their
kernels.

First, produce your object files using gcc. Remember - you can`t
use normal C library functions, so you will need to define every
symbol you use.

Then use something like:

  ld -Ttext <addr> -o <whatever> <objects>

to link your object files together, where <addr> is the hexadecimal
origin of the text segment (i.e. the address at which the code will
eventually get loaded). This does the "absolute" part.

(Assuming the entry point is the same as the address at which the
binary gets loaded, the first object file on the ld line will hold
your entry code.)

Finally, produce a plain binary using objcopy (which is included, with
GNU ld, in GNU binutils):

  objcopy -O binary -R .note -R .comment -S <whatever> <outfile>

"-O binary" says to output in plain binary format. "-R .note -R
..comment" removes some unimportant sections produced by gcc (at least
for ELF, and probably for other object file formats that allow
arbitrary sections). "-S" strips out the symbol information.
<outfile> is your binary.

Look at the ld and objcopy man pages for more details.

Dave Wragg
Using gcc and ld to Compile Other Binary Formats:【上一篇】
How It Works:DOS Floppy Disk Boot Sector:【下一篇】
【相关文章】
没有相关文章
【随机文章】
  • VB+Oracle 9i如何构建开发和运行的环境
  • Oracle数据库开发的一些经验积累(包括建立索引等等)
  • SQL学习之查询技巧 排他查询 只是用过某商品的顾客
  • SCJP 310-035考试心得
  • 保持多台服务器数据的一致性
  • 简单的固定资产管理系统 (sql+ado)
  • ASP.NET虚拟主机存在的重大隐患
  • 行政区划程序的设计(六)
  • lsof 快速起步
  • hicom348i中小型ISDN的数字电话交换系统
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.