gcc链接器选项"--format binary"? [英] gcc linker options "--format binary"?

查看:194
本文介绍了gcc链接器选项"--format binary"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下命令中"--format binary"选项的含义/用途是什么?

What is the meaning/usage of '--format binary' options in below command ?.

ld -m elf_x86_64 --format二进制文件--oformat elf64-x86-64 -r stub -o stub-image.o

ld -m elf_x86_64 --format binary --oformat elf64-x86-64 -r stub -o stub-image.o

推荐答案

-format binary选项指出输入文件(在本例中为stub)是原始的二进制数据块.

The -format binary option states that the input file, in this case named stub, is a raw binary blob of data.

您显示的命令将这个'blob'并包装到 elf 文件中,类似于编译器创建的其他对象,并且适合链接到程序中.例如,如果您有一个ROM编程工具,它需要elf数据而不是原始二进制文件,则这种技巧也很有用.

The command you show takes this 'blob' and wraps it up in an elf file, similar to other objects created by the compiler, and suitable for linking into a program. This sort of trick is also useful if you have a ROM-programming tool, for example, that expects elf data rather than raw binaries.

斑点放在.data部分中,并为您创建了三个符号(又名变量):

The blob is placed in the .data section, and three symbols (a.k.a. variables) are created for you:

  • _binary_stub_start
  • _binary_stub_end
  • _binary_stub_size
  • _binary_stub_start
  • _binary_stub_end
  • _binary_stub_size

如果以通常的方式将stub-image.o与C程序链接,则可以像这样访问数据(可以选择适当的任何指针类型):

If you link stub-image.o with a C program, in the usual way, then you can access the data like this (you can choose whatever pointer type is appropriate):

extern char *binary_stub_start;

这篇关于gcc链接器选项"--format binary"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆