您的位置:首页 > 产品设计 > UI/UE

[LinkerScript.11] 符号赋值: 规定- Assigning Values to Symbols: PROVIDE

2015-09-06 23:39 459 查看
PROVIDE

In some cases, it is desirable for a linker script to define a symbol only if it is referenced and is not defined by any object included in the link. For example, traditional linkers defined
the symbol ‘etext’. However, ANSI C requires that the user be able to use ‘etext’ as a function name without encountering an error. The PROVIDE keyword may be used to define a symbol, such as ‘etext’, only if it is referenced but not defined. The syntax is
PROVIDE(symbol = expression).


在某些情况下,  由链接器脚本定义的符号,在链接中任何对象仅仅能引用,而不能定义.比如,传统链接器所定义的符号'etext'. 然而,ANSI C要求用户可以使用'etext'作为一个函数名,并且不能报错. PROVIDE关键字用于定义一个符号,如'etext',仅仅是一个引用而不是定义.

该语法是  PROVIDE(symbol = expression)

Here is an example of using PROVIDE to define ‘etext’:
使用PROVIDE定义一个'etext'的例子如下:

     SECTIONS

     {

       .text :

         {

           *(.text)

           _etext = .;

           PROVIDE(etext = .);

         }

     }

In this example, if the program defines ‘_etext’ (with a leading underscore), the linker will give a multiple definition error. If, on the other hand, the program defines ‘etext’ (with no leading underscore), the linker will silently use the definition in the
program. If the program references ‘etext’ but does not define it, the linker will use the definition in the linker script.


在这个例子中,如果程序定义了'_etext' (带有前导下划线), 那么链接器将会报一个多重定义的错误. 另一方面,如果程序定义了'etext'(没有前导下划线),那么链接器将默默地使用程序中的定义.如果程序引用'etext',但没有定义,那么链接器将使用链接器脚本中的定义.

意思是: 在用使用PROVIDE规定一个符号时, 程序中又定义了该符号, 那么程序如果使用该符号,则使用程序中定义的,要是程序中没有定义,则使用链接器脚本中的定义.

PROVIDE_HIDDEN

Similar to PROVIDE. For ELF targeted ports, the symbol will be hidden and won't be exported.


与PROVIDE类似.对于ELF目标文件, 符号将被隐藏并且不会被导出.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: