为不推荐使用的功能生成链接时错误 [英] Generating link-time error for deprecated functions

查看:87
本文介绍了为不推荐使用的功能生成链接时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gcc和GNU binutils是否可以标记某些函数,以便在使用时在链接时产生错误?我的情况是,为了与现有二进制文件兼容,我没有删除一些库函数,但是我想确保没有新编译的二进制文件尝试使用这些函数.我不能只使用编译时gcc属性,因为有问题的代码将忽略我的标头,并使用configure脚本检测功能的存在并对其进行原型设计.我的目标是为错误的configure脚本生成链接时错误,以使它们停止检测功能的存在.

Is there a way with gcc and GNU binutils to mark some functions such that they will generate an error at link-time if used? My situation is that I have some library functions which I am not removing for the sake of compatibility with existing binaries, but I want to ensure that no newly-compiled binary tries to make use of the functions. I can't just use compile-time gcc attributes because the offending code is ignoring my headers and detecting the presence of the functions with a configure script and prototyping them itself. My goal is to generate a link-time error for the bad configure scripts so that they stop detecting the existence of the functions.

一个想法..会使用程序集为入口点指定错误的.type与动态链接程序兼容,但在尝试链接新程序时会产生链接错误吗?

An idea.. would using assembly to specify the wrong .type for the entry points be compatible with the dynamic linker but generate link errors when trying to link new programs?

推荐答案

FreeBSD 9.x通过ttyslot()函数可以非常接近您想要的功能.此功能对utmpx毫无意义.诀窍是只有该符号的非默认版本.因此,ld将找不到它,但是当运行旧的二进制文件时,rtld将找到版本定义.我不知道如果旧的二进制文件具有未版本化的引用会发生什么,但是如果只有一个定义,这可能是明智的.

FreeBSD 9.x does something very close to what you want with the ttyslot() function. This function is meaningless with utmpx. The trick is that there are only non-default versions of this symbol. Therefore, ld will not find it, but rtld will find the versioned definition when an old binary is run. I don't know what happens if an old binary has an unversioned reference, but it is probably sensible if there is only one definition.

例如,

__asm__(".symver hidden_badfunc, badfunc@MYLIB_1.0");

通常,还会有一个默认版本,例如

Normally, there would also be a default version, like

__asm__(".symver new_badfunc, badfunc@@MYLIB_1.1");

或通过与Solaris兼容的版本脚本,但诀窍不是添加一个.

or via a Solaris-compatible version script, but the trick is not to add one.

通常,asm指令被包装到一个宏中.

Typically, the asm directive is wrapped into a macro.

该技巧取决于使用.symver汇编程序指令定义符号版本的GNU扩展,因此它可能仅在Linux和FreeBSD上有效.与Solaris兼容的版本脚本每个符号只能表示一个定义.

The trick depends on the GNU extensions to define symbol versions with the .symver assembler directive, so it will probably only work on Linux and FreeBSD. The Solaris-compatible version scripts can only express one definition per symbol.

更多信息:info gas中的.symver指令,Ulrich Drepper的如何编写共享库",在

More information: .symver directive in info gas, Ulrich Drepper's "How to write shared libraries", the commit that deprecated ttyslot() at http://gitorious.org/freebsd/freebsd/commit/3f59ed0d571ac62355fc2bde3edbfe9a4e722845

这篇关于为不推荐使用的功能生成链接时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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