Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating link-time error for deprecated functions

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.

Edit: 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?

like image 918
R.. GitHub STOP HELPING ICE Avatar asked Jan 14 '11 19:01

R.. GitHub STOP HELPING ICE


1 Answers

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.

For example,

__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");

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

Typically, the asm directive is wrapped into a macro.

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.

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

like image 90
jilles Avatar answered Sep 22 '22 20:09

jilles