gcc linker options “--format binary”?

天大地大妈咪最大 提交于 2020-06-13 06:50:56

问题


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

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


回答1:


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

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.

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

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;


来源:https://stackoverflow.com/questions/20278489/gcc-linker-options-format-binary

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!