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 /lib32/libc.so.6 has two fopen symbol in it ? identical symbol in same target file should be forbidden ,right?
why readelf -s dump out fopen@@GLIBC_2.1 and fopen@GLIBC_2.0 instead of fopen?
Thanks
Actually multiple definitions of the same symbol are fine and can happen in a number of ways. One of them (which isn't the case here) are weak symbols.
What happens here is that glibc dynamic linker supports symbol versioning and glibc uses that. It exports a version of
fopen
from glibc 2.1 and a backward compatible version from glibc 2.0 with difference interfaces.At dynamic link time the application can chose a specific version or a default one.