链接器脚本符号用于处理未指定的部分

发布于 2025-01-28 23:46:39 字数 838 浏览 2 评论 0原文

我有一个对象文件,该文件有一堆我不在乎的编译器生成的部分。当我使用链接脚本将平面二进制链接在一起时,有时可以看到这些部分放置在二进制的开始或结尾处。例如,如果我有链接器脚本:

SECTIONS {
  __START = .;
  .text : { *(.text) }  /* I want all .text to go at the very start. */
  .data : { *(.data) }  /* Followed by .data. */
  /* Every other section can go somewhere here. */
  __END = ;.
}

那么.interp.note.gnu.build-id之类的部分可能会放置在当我真的想要.text开始时,二进制二进制。我可以通过将这些部分放置在结尾处,通过以下方式解决此问题:

SECTIONS {
  __START = .;
  .text : { *(.text) }  /* I want all .text to go at the very start. */
  .data : { *(.data) }  /* Followed by .data. */
  /* Every other section can go somewhere here. */
  .interp : { *(.interp) }
  __END = ;.
}

或者以某种方式让编译器根本不发出该部分,但是我不想为我不知所措的每个部分手动执行此操作。 是否有一种方法可以使我在二进制结束时没有指定的所有部分?

I have an object file that has a bunch of compiler-generated sections I don't care about. When I link together a flat binary using a linker script, I can sometimes see these sections placed at the start or end of my binary. For example, if I have the linker script:

SECTIONS {
  __START = .;
  .text : { *(.text) }  /* I want all .text to go at the very start. */
  .data : { *(.data) }  /* Followed by .data. */
  /* Every other section can go somewhere here. */
  __END = ;.
}

Then it's possible for a section like .interp or .note.gnu.build-id to be placed at the start of the binary when I really want .text to be at the start. I can work around this by placing these sections at the end via:

SECTIONS {
  __START = .;
  .text : { *(.text) }  /* I want all .text to go at the very start. */
  .data : { *(.data) }  /* Followed by .data. */
  /* Every other section can go somewhere here. */
  .interp : { *(.interp) }
  __END = ;.
}

or somehow getting the compiler to just not emit that section at all, but I don't want to manually do this for every section I don't knowingly account for. Is there a way to kinda just "glob" all sections I don't specify at the end of the binary?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

離殇 2025-02-04 23:46:39

语法/dost/:{ *}(或/dostard/:{ *( *)})丢弃所有其他未命名的部分,例如:

SECTIONS {
    section1 : { liba.o(section1a, section1b) }
    section2 : { lib*.o(section2*) }
    /DISCARD/ : { * }
}

一般而言,基本的语法对于部分,放置表达式为fileGlob [(sectionGlob,[sectionglobs ...])],其中特殊截面名称/dost>/dost>/dost/将删除列出的部分。

请注意,订单很重要 - 将/dostard/:{ *}在链接器脚本的开头删除所有输入文件的所有部分,即使它们在以后的部分中指定。

The syntax /DISCARD/ : { * } (or /DISCARD/ : { *(*) }) discards all otherwise unnamed sections, for example:

SECTIONS {
    section1 : { liba.o(section1a, section1b) }
    section2 : { lib*.o(section2*) }
    /DISCARD/ : { * }
}

In general the basic syntax for a section placement expression is fileglob[(sectionglob, [sectionglobs...])], where the special section name /DISCARD/ will drop the sections listed.

Note that order matters - putting /DISCARD/ : { * } at the beginning of the linker script will discard all sections of all input files, even if they are specified in later sections.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文