Dolda2000
Dolda2000

Reputation: 25855

How to create backwards-compatible dynamic linkage?

It seems that glibc 2.14 introduced a new version of memcpy (to fix bug 12518). Programs compiled against glibc 2.14+, then, will contain a dynamic link to memcpy@GLIBC_2.14, which is clearly not available in older versions of glibc.

However, glibc 2.14+ obviously still contains the old memcpy@GLIBC_2.2.5 symbol for backwards compatibility. I'd like to be able to compile a few programs in such a way that they are binary-compatible with older glibc versions. How would one do to compile a program, on a system which has glibc 2.14+, so that it uses this old symbol version? If the procedure necessarily is compiler-specific, I'm using GCC (but it would be nice to know how to do it on other compilers as well).

(On a side note, I must admit don't know a whole lot about versioned symbols, such as how to produce them and how to use them, or whether they are ELF-specific or should be considered a standard part of modern ABIs; and I haven't managed to find any documentation about it. Are there any good sources of information on the subject?)

Upvotes: 8

Views: 882

Answers (1)

fche
fche

Reputation: 2790

The canonical document on shared libraries, symbol versioning, and related issues is Ulrich Drepper's http://www.akkadia.org/drepper/dsohowto.pdf‎ .

To make a reference to an older symbol, you would need to find a header that declares it, then use an assembler directive:

extern void nftw_old (int) ;
asm (".symver nftw_old,nftw@GLIBC_2.3.3");
void main ()
{
   nftw_old(0);
}

Note that the "nm" of the compiled executable refers to the expected previous-ABI nftw@GLIBC_2.3.3 implementation. (Don't try to run this program - the real nftw(3) function signature is different.)

Upvotes: 3

Related Questions