' 0005d0c0 T fopen 00109750 T fopen readelf ...">

Why does / lib32 / libc.so.6 have two "fopen" characters in it?

nm -D /lib32/libc.so.6 | grep '\<fopen\>' 0005d0c0 T fopen 00109750 T fopen readelf -s /lib32/libc.so.6 | egrep '0005d0c0|00109750' 181: 0005d0c0 50 FUNC GLOBAL DEFAULT 12 fopen@ @GLIBC_2.1 182: 00109750 136 FUNC GLOBAL DEFAULT 12 fopen@GLIBC _2.0 679: 0005d0c0 50 FUNC GLOBAL DEFAULT 12 _IO_fopen@ @GLIBC_2.1 680: 00109750 136 FUNC GLOBAL DEFAULT 12 _IO_fopen@GLIBC _2.0 

here is my question:

  • why does / lib32 / libc.so.6 have two fopen characters in it? an identical character in the same target file should be prohibited, right?

  • why does readelf -s give fopen @@ GLIBC_2.1 and fopen@GLIBC _2.0 instead of fopen?

thanks

+4
source share
2 answers

In fact, multiple definitions of the same symbol are accurate and can occur in several ways. One of them (which is wrong here) is weak characters.

What happens is that the dynamic glibc linker supports version control of characters, and glibc uses this. It exports the fopen version from glibc 2.1 and the backward compatible version from glibc 2.0 with difference interfaces.

With dynamic link time, an application can select a specific version or default.

+3
source

To understand what is happening here, you first need to understand how binary compatibility is traditionally handled.

The mechanism was used for "external versioning". You started with libfoo.so.1 , and when you needed to change the ABI of an existing function, you had to enter libfoo.so.2 .

Applications that were linked before libfoo.so.2 continued to use libfoo.so.1 with the old ABI, and newer applications used libfoo.so.2 with the new ABI.

All of this is described in more detail here .

But then glibc introduced an extension where instead of introducing a whole new library (which shares 99% of the code with the previous verson), you enter a new character into the existing library.

This extension allows libc.so.6 to remain in version 6 for many years, while allowing old binaries to work, and for the ABI to evolve.

In the particular case of fopen incompatible change to struct FILE was made in version 2.1 glibc. The binaries that were associated with glibc-2.0 systems continue to use the old struct FILE (the only one that was then available) and continue to call _IO_old_fopen (for which fopen@GLIBC _2.0 is an alias). The binaries associated with glibc-2.1 and new use the new struct FILE and call _IO_new_fopen (for which fopen@GLIBC _2.1 is an alias).

@@ is simply the designation of the current default character version.

+9
source

Source: https://habr.com/ru/post/1394963/


All Articles