链接器脚本符号用于处理未指定的部分
我有一个对象文件,该文件有一堆我不在乎的编译器生成的部分。当我使用链接脚本将平面二进制链接在一起时,有时可以看到这些部分放置在二进制的开始或结尾处。例如,如果我有链接器脚本:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
语法
/dost/:{ *}
(或/dostard/:{ *( *)}
)丢弃所有其他未命名的部分,例如:一般而言,基本的语法对于部分,放置表达式为
fileGlob [(sectionGlob,[sectionglobs ...])]
,其中特殊截面名称/dost>/dost>/dost/
将删除列出的部分。请注意,订单很重要 - 将
/dostard/:{ *}
在链接器脚本的开头删除所有输入文件的所有部分,即使它们在以后的部分中指定。The syntax
/DISCARD/ : { * }
(or/DISCARD/ : { *(*) }
) discards all otherwise unnamed sections, for example: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.