• How do I link against a specific version-script tag?

    From Johann Klammer@21:1/5 to All on Wed Jan 16 10:41:08 2019
    Hello,

    I am just writing a library. It's buggy as hell.
    It's the first compilable version after an episode of intense edits.
    It's a malloc preload lib. with the default symbol names,
    Of course the gdb will crash at startup.
    So, I'd like to rename the symbols.
    So I can run a minimal test.

    in the c file I have(besides the malloc etc..)
    the following aliases:
    ///malloc replacement
    void *bmalloc (size_t sz) __attribute__ (( alias ("malloc")));
    ///free replacement
    void bfree (void *ptr) __attribute__ (( alias ("free")));
    ///posix_memalign replacement
    int bposix_memalign (void **memptr, size_t alignment, size_t size) __attribute__ (( alias ("posix_memalign")));
    ///valloc replacement
    void *bvalloc (size_t size) __attribute__ (( alias ("valloc")));
    ///memalign replacement
    void *bmemalign (size_t boundary, size_t size) __attribute__ (( alias ("memalign")));
    ///calloc replacement
    void *bcalloc (size_t nmemb, size_t size) __attribute__ (( alias ("calloc")));
    ///realloc replacement
    void *brealloc (void *ptr, size_t size) __attribute__ (( alias ("realloc"))); struct ptr_info bptr_info (void *ptr) __attribute__ (( alias ("ptr_info")));


    the version script is:

    NORMAL {
    global:
    malloc;
    calloc;
    realloc;
    free;
    posix_memalign;
    valloc;
    memalign;
    ptr_info;
    envGetVal;
    envGetNum;
    envGetNumLim;
    int_to_string;
    local:
    *;
    };

    DEBUG {
    global:
    bmalloc;
    bcalloc;
    brealloc;
    bfree;
    bposix_memalign;
    bvalloc;
    bmemalign;
    bptr_info;
    envGetVal;
    envGetNum;
    envGetNumLim;
    int_to_string;
    local:
    *;
    };


    linking the test program against the generated lib fails.
    I've tried setting the soname to libbmalloc.so.DEBUG and linking to that filename
    with

    cc -D_REENTRANT -g -O0 -lpthread --library :../../libbmalloc.so.DEBUG -I../.. -Wall ./main.c


    but none of the symbols are known. /home/klammerj/projects/alc/src/libbmalloc/tests/burn_in/./main.c:48: undefined reference to `bfree'

    how do I do this?

    Regards,
    Johann

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Johann Klammer@21:1/5 to Johann Klammer on Fri Jan 18 23:06:31 2019
    On 01/16/2019 10:41 AM, Johann Klammer wrote:
    Hello,

    I am just writing a library. It's buggy as hell.
    It's the first compilable version after an episode of intense edits.
    It's a malloc preload lib. with the default symbol names,
    Of course the gdb will crash at startup.
    So, I'd like to rename the symbols.
    So I can run a minimal test.

    in the c file I have(besides the malloc etc..)
    the following aliases:
    ///malloc replacement
    void *bmalloc (size_t sz) __attribute__ (( alias ("malloc")));
    ///free replacement
    void bfree (void *ptr) __attribute__ (( alias ("free")));
    ///posix_memalign replacement
    int bposix_memalign (void **memptr, size_t alignment, size_t size) __attribute__ (( alias ("posix_memalign")));
    ///valloc replacement
    void *bvalloc (size_t size) __attribute__ (( alias ("valloc")));
    ///memalign replacement
    void *bmemalign (size_t boundary, size_t size) __attribute__ (( alias ("memalign")));
    ///calloc replacement
    void *bcalloc (size_t nmemb, size_t size) __attribute__ (( alias ("calloc")));
    ///realloc replacement
    void *brealloc (void *ptr, size_t size) __attribute__ (( alias ("realloc")));
    struct ptr_info bptr_info (void *ptr) __attribute__ (( alias ("ptr_info")));


    the version script is:

    NORMAL {
    global:
    malloc;
    calloc;
    realloc;
    free;
    posix_memalign;
    valloc;
    memalign;
    ptr_info;
    envGetVal;
    envGetNum;
    envGetNumLim;
    int_to_string;
    local:
    *;
    };

    DEBUG {
    global:
    bmalloc;
    bcalloc;
    brealloc;
    bfree;
    bposix_memalign;
    bvalloc;
    bmemalign;
    bptr_info;
    envGetVal;
    envGetNum;
    envGetNumLim;
    int_to_string;
    local:
    *;
    };


    linking the test program against the generated lib fails.
    I've tried setting the soname to libbmalloc.so.DEBUG and linking to that filename
    with

    cc -D_REENTRANT -g -O0 -lpthread --library :../../libbmalloc.so.DEBUG -I../.. -Wall ./main.c


    but none of the symbols are known. /home/klammerj/projects/alc/src/libbmalloc/tests/burn_in/./main.c:48: undefined reference to `bfree'

    how do I do this?

    Regards,
    Johann

    nevermind, it was missing a -Wl,...
    also, it seems the -l:../../stuff
    doesn't quite work without an additional path setting... -L../..
    I seem to recall this is mentioned differently in some documentation.... (either the program library howto or info ld)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)