Symbol Hiding - Linux

This is a discussion on Symbol Hiding - Linux ; Hello all, I am trying symbol hiding in GCC version 4.1, but it seems like i am not doing something right . Please find here in my example /* libhello.c*/ int sizeOfLong() { return sizeof(long); } void hello(void) { printf("size ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Symbol Hiding

  1. Symbol Hiding

    Hello all,

    I am trying symbol hiding in GCC version 4.1, but it seems like i am
    not doing something right .

    Please find here in my example

    /* libhello.c*/
    int sizeOfLong()
    {
    return sizeof(long);
    }

    void hello(void) {

    printf("size of a short is %d\n", sizeOfInt());
    printf("Hello, library world.\n");

    }

    /* libhello.h - demonstrate library use. */
    #define EXPORT __attribute__((visibility("default")))
    EXPORT void hello(void);
    int sizeOfInt();

    now i compile using the following commands:

    gcc -fPIC -fvisibility=hidden -Wall -g -c libhello.c
    gcc -g -shared -Wl,-soname,libhello.so.0 \
    -o libhello.so.0.0 libhello.o -lc

    do nm libhello.so

    I find both functions hello and sizeOfInt() in it why?

    Question 2:

    What is the difference between strip and symbol hiding.

    Thanks

    Newbei


  2. Re: Symbol Hiding

    "newbei" writes:

    > do nm libhello.so
    > I find both functions hello and sizeOfInt() in it why?


    Because you are looking in the wrong place.

    ELF shared objects (and executables) have *two* symbol tables --
    a "regular" one (used mostly for debugging after the exe/DSO
    is built) and a "dynamic" one (used by the dynamic loader for
    inter-library symbol resolution).

    To examine the dynamic symbol table, use 'nm -D' or 'objdump -T'.
    The sizeOfInt should not be in *that* output, and so is "invisible"
    to the dynamic loader.

    > Question 2:
    > What is the difference between strip and symbol hiding.


    Strip manipulates the "regular" symbol table (which you do not care
    about, except for debugging).

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  3. Re: Symbol Hiding

    Dear Paul,

    THanks a lot for taking the time to reply.
    I am sorry for multiple postings.

    >>To examine the dynamic symbol table, use 'nm -D' or 'objdump -T'.

    > The sizeOfInt should not be in *that* output, and so is "invisible"
    > to the dynamic loader.


    I tried doing what you told me but the outputs surprises me even
    more .
    Function hello is hidden in that out put too.

    i did a objdump -T libhello.so , it dint show me any of the symbols
    but hello should have been there.

    so i did

    objdump -t libhello.so, it shows the following:

    000005e0 l F .text 00000000 __do_global_ctors_aux
    00000000 l df *ABS* 00000000 libhello.c
    0000056a l F .text 0000006c .hidden hello
    0000179c l O .data 00000000 .hidden __dso_handle
    0000054c l F .text 0000000a .hidden sizeOfInt
    00000556 l F .text 0000000a .hidden sizeOfShort
    00000545 l F .text 00000000 .hidden
    __i686.get_pc_thunk.bx
    00000560 l F .text 0000000a .hidden sizeOfLong

    doesnt this mean even hello is hidden, but i exported it using the
    macro.

    Thanks

    Newbei

    On Mar 28, 9:58 pm, Paul Pluzhnikov
    wrote:
    > "newbei" writes:
    > > do nm libhello.so
    > > I find both functions hello and sizeOfInt() in it why?

    >
    > Because you are looking in the wrong place.
    >
    > ELF shared objects (and executables) have *two* symbol tables --
    > a "regular" one (used mostly for debugging after the exe/DSO
    > is built) and a "dynamic" one (used by the dynamic loader for
    > inter-library symbol resolution).
    >
    > To examine the dynamic symbol table, use 'nm -D' or 'objdump -T'.
    > The sizeOfInt should not be in *that* output, and so is "invisible"
    > to the dynamic loader.
    >
    > > Question 2:
    > > What is the difference between strip and symbol hiding.

    >
    > Strip manipulates the "regular" symbol table (which you do not care
    > about, except for debugging).
    >
    > Cheers,
    > --
    > In order to understand recursion you must first understand recursion.
    > Remove /-nsp/ for email.




  4. Re: Symbol Hiding

    "newbei" writes:

    > I tried doing what you told me but the outputs surprises me even
    > more . Function hello is hidden in that out put too.


    Sorry for not paying attention.

    It would help if you actually '#include ' into libhello.c
    Your original post didn't appear to (and that is consistent with
    observed result -- hello() also being hidden).

    > On Mar 28, 9:58 pm, Paul Pluzhnikov
    > wrote:


    Please do not top-post.

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  5. Re: Symbol Hiding

    On Mar 28, 11:16 pm, Paul Pluzhnikov
    wrote:
    > "newbei" writes:
    > > I tried doing what you told me but the outputs surprises me even
    > > more . Function hello is hidden in that out put too.

    >
    > Sorry for not paying attention.
    >
    > It would help if you actually '#include ' into libhello.c
    > Your original post didn't appear to (and that is consistent with
    > observed result -- hello() also being hidden).
    >
    > > On Mar 28, 9:58 pm, Paul Pluzhnikov
    > > wrote:

    >
    > Please do not top-post.
    >
    > Cheers,
    > --
    > In order to understand recursion you must first understand recursion.
    > Remove /-nsp/ for email.


    Thanks a lot paul.
    It works , sorry for missing the small detail.

    Newbei


+ Reply to Thread