连接使用GCC工具链ARM任意数据 [英] linking arbitrary data using GCC ARM toolchain

查看:277
本文介绍了连接使用GCC工具链ARM任意数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在原始的二进制数据链接。我想无论是把它放在一个特定的地址,或将其链接到一个符号(字符* MYDATA,例如)我在code定义。因为它不是一个OBJ文件,我不能简单地联系起来。

I want to link in raw binary data. I'd like to either put it at a particular address, or have it link to a symbol (char* mydata, for instance) I have defined in code. Since it's not an obj file, I can't simply link it in.

一个类似的职位(<一个href=\"http://stackoverflow.com/questions/327609/include-binary-file-with-gnu-ld-linker-script/328137#328137\">Include与GNU劳工处连接脚本二进制文件)建议使用objcopy把与 -B bfdarch 选项。 objcopy把响应archictecture bfdarch未知。

A similar post (Include binary file with GNU ld linker script) suggests using objcopy with the -B bfdarch option. objcopy responds with "archictecture bfdarch unknown".

又一答案建议变换对象到定制的LD脚本,然后包括从主LD脚本。在这一点上,我可能也只是使用一个C头文件(这就是我现在所做的),所以我宁愿不这么做。

Yet another answer suggests transforming the object into a custom LD script and then include that from the main LD script. At this point, I may as well just be using a C include file (which is what I am doing Now) so I'd rather not do that.

我可以用objcopy把要做到这一点,或有另一种方式?

Can I use objcopy to accomplish this, or is there another way?

推荐答案

下面的例子对我的作品:

The following example works for me:

$ dd if=/dev/urandom of=binblob bs=1024k count=1
$ objcopy -I binary -O elf32-little binblob binblob.o
$ file binblob.o
binblob.o: ELF 32-bit LSB relocatable, no machine, version 1 (SYSV), not stripped
$ nm  -S -t d binblob.o
0000000001048576 D _binary_binblob_end
0000000001048576 A _binary_binblob_size
0000000000000000 D _binary_binblob_start

即。不需要指定BFD拱二进制的数据的(这是唯一有用/必要为code)。只是说输入是二进制和输出...,它会创建你的文件。由于纯二进制数据不是架构特定的,你需要告诉它的输出是32位( ELF32 -... )或64位( ELF64 -... ),以及它是否是小端/ LSB( ...-小,作为ARM / x86平台)或大端/ MSB( ...-大,因为如在SPARC / m68k的)。

I.e. no need to specify the BFD arch for binary data (it's only useful / necessary for code). Just say "the input is binary", and "the output is ...", and it'll create you the file. Since pure binary data isn't architecture-specific, all you need to tell it is whether the output is 32bit (elf32-...) or 64bit (elf64-...), and whether it's little endian / LSB (...-little, as on ARM/x86) or big endian / MSB (...-big, as e.g. on SPARC/m68k).

编辑:
上的选项为澄清 objcopy把


  • -O ... 选项控制的用法:

    • 位宽(ELF文件是否是32位或64位)

    • 字节序(ELF文件是否会LSB或MSB)

    • the usage of the -O ... option controls:
      • bit width (whether the ELF file will be 32-bit or 64-bit)
      • endianness (whether the ELF file will be LSB or MSB)

      带有应用于specifiy的 -O ... -B ... 是可选的。所不同的是最好的一个小例子来说明:

      You have to specifiy the -O ... but the -B ... is optional. The difference is best illustrated by a little example:

      $ objcopy -I binary -O elf64-x86-64 foobar foobar.o
      $ file foobar.o
      foobar.o: ELF 64-bit LSB relocatable, no machine, version 1 (SYSV), not stripped
      
      $ objcopy -I binary -O elf64-x86-64 -B i386 foobar foobar.o
      $ file foobar.o
      foobar.o: ELF 64-bit LSB relocatable, AMD x86-64, version 1 (SYSV), not stripped

      即。只是输出格式说明 ELF64-X86-64 不扎生成的二进制到一个特定的架构(这​​就是为什么文件没有机)。用法如果 -B I386 这样做 - 在这种情况下,你告诉他们这是现在 AMD的x86-64

      I.e. just the output format specifier elf64-x86-64 doesn't tie the generated binary to a specific architecture (that's why file says no machine). The usage if -B i386 does so - and in that case, you're told this is now AMD x86-64.

      这同样适用于ARM; -O ELF32-小 -O ELF32-littlearm -B手臂的是,在前一种情况下,你最终了一个 ELF 32位LSB重定位的,没有机器,... 而在后者,这将是一个 ELF 32位LSB重新定位,ARM ...

      The same would apply to ARM; -O elf32-little vs. -O elf32-littlearm -B arm is that in the former case, you end up with a ELF 32-bit LSB relocatable, no machine, ... while in the latter, it'll be an ELF 32-bit LSB relocatable, ARM....

      有在这里还有一些相互依存;你必须使用 -O精灵{32 | 64} - &LT;拱&GT; (而不是普通的精灵{32 | 64} - {小|大} )的输出选项,能够让 -B ... 认可。

      There's some interdependency here as well; you have to use -O elf{32|64}-<arch> (not the generic elf{32|64}-{little|big}) output option to be able to make -B ... recognized.

      请参阅 objcopy把--info 为ELF格式/ BFD类型的binutils您可以处理名单。

      See objcopy --info for the list of ELF formats / BFD types that your binutils can deal with.

      这篇关于连接使用GCC工具链ARM任意数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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