tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

__strong_alias



I have trouble to understand how __strong_alias should work.  In the
example below, I would expect libtest_foo() to be called after dlopen(),
but it still use main_foo(). Anyone can explain?

--- cut here ---
/* cc -o test test.c */
#include <stdio.h>
#include <err.h>
#include <sysexits.h>
#include <dlfcn.h>

void foo(void);

__weak_alias(foo, main_foo);

void
main_foo(void)
{
        printf("%s\n", __func__);
}

int
main(void)
{
        void *h;

        foo();

        if ((h = dlopen("./libtest.so",  RTLD_NOW)) == NULL)
                errx(EX_OSERR, "dlopen failed: %s\n", dlerror());

        foo();
                
        return 0;
}
--- cut here ---

--- cut here ---
/* cc -shared -dynamic -o libtest.so libtest.c */
#include <stdio.h>

void libtest_foo(void);

__strong_alias(foo, libtest_foo);

void
libtest_foo(void)
{
        printf("%s\n", __func__);
}
--- cut here ---

-- 
Emmanuel Dreyfus
http://hcpnet.free.fr/pubz
manu%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index