8

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?)

fche
  • 2,641
  • 20
  • 28
Dolda2000
  • 25,216
  • 4
  • 51
  • 92

1 Answers1

3

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.)

fche
  • 2,641
  • 20
  • 28
  • Is that the only way to do it? It would be nice not to have to modify the source code just to alter linkage. Is there no way to tell the linker to choose a symbol version when producing the final executable, rather than doing it at the source code level? – Dolda2000 Jan 29 '14 at 03:48
  • Thanks for the link, by the way! – Dolda2000 Jan 29 '14 at 03:48
  • That's a way to do it by hand, at the symbol versioning level, which is what I thought you were after. The simpler way is to get hold of an older software installation, with the old .a / .so / .h files, and compile/link against them. – fche Jan 29 '14 at 12:57