Linking against older symbol version in a .so file

前端 未结 11 1838
长发绾君心
长发绾君心 2020-11-27 11:25

Using gcc and ld on x86_64 linux I need to link against a newer version of a library (glibc 2.14) but the executable needs to run on a system with an older version (2.5). Si

11条回答
  •  悲&欢浪女
    2020-11-27 11:37

    I found the following working solution. First create file memcpy.c:

    #include 
    
    /* some systems do not have newest memcpy@@GLIBC_2.14 - stay with old good one */
    asm (".symver memcpy, memcpy@GLIBC_2.2.5");
    
    void *__wrap_memcpy(void *dest, const void *src, size_t n)
    {
        return memcpy(dest, src, n);
    }
    

    No additional CFLAGS needed to compile this file. Then link your program with -Wl,--wrap=memcpy.

提交回复
热议问题