【问题标题】:What's the difference between data and data1 sections and the difference between rodata and rodata1 sections in a ELF file?ELF 文件中的 data 和 data1 部分以及 rodata 和 rodata1 部分之间的区别是什么?
【发布时间】:2014-07-01 08:39:03
【问题描述】:

我在这里查看了 ELF 规范 http://www.cs.cmu.edu/afs/cs/academic/class/15213-f00/docs/elf.pdf 但是,没有提到任何区别。

【问题讨论】:

    标签: linker elf


    【解决方案1】:

    我没有找到强制执行此操作的单个文档,但 .rodata1 通常位于以 .rodata 开头的所有内容之后。您可以查看系统上的链接器脚本来验证这一点(通常是 /usr/lib/ldscripts/)。

    这使得一些美好的事情成为可能,例如在本节中为校验和放置一个变量。这确保了它在剩下的只读内容后面,然后一个工具可以计算校验和并修补到二进制文件中。

    在运行时,您可以根据校验和检查您的代码。这对于 PC 来说听起来很愚蠢,但它在嵌入式固件中很常见。 我猜该部分的动机是由于各种原因在编译器生成的代码“外部”有一个部分,但从未完整记录。

    【讨论】:

      【解决方案2】:

      据我所知,它们是一样的。

      它也依赖于编译器。一些编译器会将这 2 个部分(可能还有更多部分)连接到“.data”中。

      【讨论】:

        【解决方案3】:

        从 binutils-gdb 源中的一些 git 考古学来看,它看起来像:

        提交 252b5132c753(“19990502 源件导入”)有一个差异,其中提到:

        +Fri Jul 23 13:51:09 1993  Ken Raeburn  (raeburn@cambridge.cygnus.com)
        +
        +       * scripttempl/elf.sc: Add support for .init, .fini, .ctors,
        +       .dtors, .data1, .rodata1 sections, instead of combining them into
        +       other sections.  For `-r', set all section start addresses to
        +       zero.
        

        是我能找到的最早的参考资料。我怀疑 binutils 那时已被移植到 gdb 的源代码中。我似乎找不到 26 多年前存在的预导入资源。他们的邮件存档似乎始于 1999 年。rodata1 的错误跟踪器中没有错误。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-03-31
          • 1970-01-01
          • 1970-01-01
          • 2018-04-29
          • 2013-12-18
          • 2012-11-27
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多