zoukankan      html  css  js  c++  java
  • objcopy

    objcopy的作用是拷贝一个目标文件的内容到另一个目标文件中。objcopy使用GNU BFD库去读或写目标文件。objcopy可以使用不同于源目标文件的格式来写目的目标文件(也即是说可以将一种格式的目标文件转换成另一种格式的目标文件)。objcopy在进行目标文件的转换时,将生成一个临时文件,转换完成后就将这个临时文件删掉。objcopy使用BFD做转换工作。如果没有明确地格式要求,则objcopy将访问所有在BFD库中已经描述了的并且它可以识别的格式。

    请注意objcopy 所能支持的机器架构,及目标文件格式。

    mipsel-linux-objcopy –-info显示出该objcopy所支持的architecture 与目标文件格式。

    通过使用srec作为输出目标(使用命令行选项-O srec),objcopy可以产生S记录格式文件。

    通过使用binary作为输出目标(使用命令行选项-O binary),objcopy可以产生原始的二进制文件。

    使用objcopy生成S记录格式文件或者原始的二进制文件的过程中,-S选项和-R选项可能会比较有用。-S选项是用来删掉包含调试信息的部分,-R选项是用来删掉包含了二进制文件不需要的内容的那些部分。 

    input-file

    outfile

    参数input-fileoutfile分别表示输入目标文件(源目标文件)和输出目标文件(目的目标文件)。如果在命令行中没有明确地指定outfile,那么objcopy将创建一个临时文件来存放目标结果,然后使用input-file的名字来重命名这个临时文件(这时候,原来的input-file将被覆盖)。

    -I bfdname

    --input-target=bfdname

    明确告诉objcopy,源文件的格式是什么,bfdnameBFD库中描述的标准格式名。这样做要比让objcopy自己去分析源文件的格式,然后去和BFD中描述的各种格式比较,通过而得知源文件的目标格式名的方法要高效得多。

    -O bfdname

    --output-target= bfdname

    使用指定的格式来写输出文件(即目标文件),bfdnameBFD库中描述的标准格式名。

    -B bfdarch

    --binary-architecture=bfdarch

    对于一个没有指定架构的文件转换成目标文件时是有用的。此时,目标文件架构将被指定为bfdarch 。但是当objcopy能够识别输入文件架构时该选项将被忽略。在该转换过程中将会产生一些符号:

    _binary_objfile_start,_binary_objfile_end,_binary_objfile_size,在其他的文件中我们能引用这些符号以此来获得相应的数据。例如,当我们可以将一幅图片转换成目标文件,而后在程序中使用这些符号。

    --reverse-bytes=num改变大小端,看示例

    Reversing takes place before the interleaving is performed.

    Consider a simple file with a section containing the following eight bytes: 12345678.

    Using --reverse-bytes=2 for the above example, the bytes in the output file would be ordered 21436587.

    Using --reverse-bytes=4 for the above example, the bytes in the output file would be ordered 43218765. By using --reverse-bytes=2 for the above example, followed by --reverse-bytes=4 on the output file, the bytes in the second output file would be ordered 34127856.

      

    以下涉及到不同编译器对符号的处理问题。比如我们写个汇编文件,汇编后,汇编文件中的符号未变,但是当我们写个C文件再生成目标文件后,源文件中的符号前可能加了下划线,当两者之间发生引用关系时可能无法连接,此时我们会用到下面的命令。

     --change-leading-char

    Some object file formats use special characters at the start of symbols. The most common such character is underscore, which compilers often add before every symbol. This option tells objcopy to change the leading character of every symbol when it converts between object file formats. If the object file formats use the same leading character, this option has no effect. Otherwise, it will add a character, or remove a character, or change a character, as appropriate.

    --remove-leading-char

    If the first character of a global symbol is a special symbol leading character used by the object file format, remove the character. The most common symbol leading character is underscore. This option will remove a leading underscore from all global symbols. This can be useful if you want to link together objects of different file formats with different conventions for symbol names. This is different from --change-leading-char because it always changes the symbol name when appropriate, regardless of the object file format of the output file. 

    --prefix-symbols=string

    Prefix all symbols in the output file with string.

    --prefix-sections=string

    Prefix all section names in the output file with string.

    --prefix-alloc-sections=string

    Prefix all the names of all allocated sections in the output file with string.

     

     

     

    -i interleave

    --interleave=interleave

    interleave字节组成一组,我们只在这一组中选择一个字节(具体是哪个由-b bytebyte指定)

    -b byte

    --byte=byte

    interleave字节所构成的组中选择第byte个字节(从0开始计)。

  • 相关阅读:
    异常
    带参数的方法
    变量,基本类型,数据类型和运算符
    数据类型转换(针对数字类型)
    this关键字
    面向对象DAO模式
    常见类 Object
    方法和包
    final关键字
    abstract关键字
  • 原文地址:https://www.cnblogs.com/openix/p/2437384.html
Copyright © 2011-2022 走看看