码迷,mamicode.com
首页 > 其他好文 > 详细

weak symbol的设计意图

时间:2015-04-13 12:54:50      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:linux   gcc   

用nm察看elf文件时,会输出各种符号,其中有两种符号,比较特别


           "V"
           "v" The symbol is a weak object.  When a weak defined symbol is linked with a normal defined
               symbol, the normal defined symbol is used with no error.  When a weak undefined symbol is
               linked and the symbol is not defined, the value of the weak symbol becomes zero with no error.
               On some systems, uppercase indicates that a default value has been specified.

           "W"
           "w" The symbol is a weak symbol that has not been specifically tagged as a weak object symbol.
               When a weak defined symbol is linked with a normal defined symbol, the normal defined symbol
               is used with no error.  When a weak undefined symbol is linked and the symbol is not defined,
               the value of the symbol is determined in a system-specific manner without error.  On some
               systems, uppercase indicates that a default value has been specified.
上面是nm的manpage内容,只描述了what,没有why


在网上搜索许久,只能看到what和how,也没有讲why


不行,我要知其然更知其所以然


于是在wikipedia上找到了答案


简言之,就是一种link-time的overloading

weak symbol的设计意图

标签:linux   gcc   

原文地址:http://blog.csdn.net/happen23/article/details/45023609

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!