On Thu, Mar 17, 2011 at 9:59 PM, Pan ruochen <panruochen@xxxxxxxxx> wrote: > Hi Ian, > > Yes, setting the environment LD_DYNAMIC_WEAK did work. > Now I get another question about weak symbols of glibc. > I find there are some symbols with the same names existing both in libc > and in libpthread. All these symbols are weak. I guess the libpthread > provides multi-threading safe functions rather than libc provides > single-threading versions. But since all these symbols are weak, how the > dynamic loader choose the symbol in libpthread if libpthread is linked > against the application? > > $nm -D libpthread.so.0 | grep '\<sendto\>' > 00010d54 W sendto > $nm -D libc-2.8.so | grep '\<sendto\>' > 000e0704 W sendto > >From gABI: NOTE: The behavior of weak symbols in areas not specified by this document is implementation defined. Weak symbols are intended primarily for use in system software. Applications using weak symbols are unreliable since changes in the runtime environment might cause the execution to fail. In another word, you should use weak symbols only in ways specified in gABI, which are Global and weak symbols differ in two major ways. * When the link editor combines several relocatable object files, it does not allow multiple definitions of STB_GLOBAL symbols with the same name. On the other hand, if a defined global symbol exists, the appearance of a weak symbol with the same name will not cause an error. The link editor honors the global definition and ignores the weak ones. Similarly, if a common symbol exists (that is, a symbol whose st_shndx field holds SHN_COMMON), the appearance of a weak symbol with the same name will not cause an error. The link editor honors the common definition and ignores the weak ones. * When the link editor searches archive libraries [see ``Archive File'' in Chapter 7], it extracts archive members that contain definitions of undefined global symbols. The member's definition may be either a global or a weak symbol. The link editor does not extract archive members to resolve undefined weak symbols. Unresolved weak symbols have a zero value. Any other usage is implementation defined. -- H.J.