KEEP在链接描述文件中是什么意思? [英] What does KEEP mean in a linker script?

查看:1160
本文介绍了KEEP在链接描述文件中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

LD手册没有说明什么KEEP命令执行.下面是具有KEEP的第三方链接程序脚本的摘录. KEEP命令在ld中起什么作用?

The LD manual does not explain what the KEEP command does. Below is a snippet from a third-party linker script that features KEEP. What does the KEEP command do in ld?

SECTIONS
{  
    .text :
    {
        . = ALIGN(4);
        _text = .;
        PROVIDE(stext = .);
        KEEP(*(.isr_vector))
        KEEP(*(.init))
        *(.text .text.*)        
        *(.rodata .rodata.*)        
        *(.gnu.linkonce.t.*)
        *(.glue_7)
        *(.glue_7t)
        *(.gcc_except_table)
        *(.gnu.linkonce.r.*)
        . = ALIGN(4);
        _etext = .;
        _sidata = _etext;
        PROVIDE(etext = .);   
            _fini = . ;
                *(.fini)

    } >flash

推荐答案

即使未引用符号,Afaik LD也会将符号保留在该部分中. (--gc-sections).

Afaik LD keeps the symbols in the section even if symbols are not referenced. (--gc-sections).

通常用于二进制启动过程中具有某些特殊含义的部分,或多或少地用于标记依赖关系树的根.

Usually used for sections that have some special meaning in the binary startup process, more or less to mark the roots of the dependency tree.

(对于下面的Sabuncu)

(For Sabuncu below)

依赖树:

如果消除了未使用的代码,则需要分析代码并标记所有可访问的部分(代码+全局变量+常量).

If you eliminate unused code, you analyze the code and mark all reachable sections (code+global variables + constants).

因此,您选择一个部分,将其标记为已使用",然后查看其引用的其他部分,然后将这些部分标记为已使用",并检查其引用的内容,等等.

So you pick a section, mark it as "used" and see what other section it references, then you mark those section as "used", and check what they reference etc.

未标记为已使用"的部分将成为多余的,可以将其删除.

The section that are not marked "used" are then redundant, and can be eliminated.

由于一个节可以引用多个其他节(例如,一个过程调用了其他三个不同的节),因此如果绘制结果,则会得到一棵树.

Since a section can reference multiple other sections (e.g. one procedure calling three different other ones), if you would draw the result you get a tree.

根:

但是,上述原理给我们带来了一个问题:始终使用的第一"部分是什么?可以这么说树的第一个节点(根)?这就是"keep()"的作用,它告诉链接器哪些部分(如果有)是第一个要查看的部分.结果,这些总是链接在一起.

The above principle however leaves us with a problem: what is the "first" section that is always used? The first node (root) of the tree so to speak? This is what "keep()" does, it tells the linker which sections (if available) are the first ones to look at. As a consequence these are always linked in.

通常,这些是从程序加载器中调用的部分,用于执行与动态链接(可以是可选的,并且取决于OS/fileformat)和程序的入口点有关的任务.

Typically these are sections that are called from the program loader to perform tasks related to dynamic linking (can be optional, and OS/fileformat dependent), and the entry point of the program.

这篇关于KEEP在链接描述文件中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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