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

Deferred Binding of Function Pointers in SHLIB



Hi

Consider this case:
---
$ cat libmain.c
#include <stdio.h>
extern void foo(void);
void (*func_p)(void) = foo;
void libmain()
{
    printf("printf()\n");
    (*func_p)();
}

$ cc -shared -fpic libmain.c -o libmain.so
$ cc main.c -L. -lmain -Wl,--unresolved-symbols=ignore-all

$ LD_LIBRARY_PATH=. ./a.out
./a.out: symbol lookup error: ./libmain.so: undefined symbol: foo
---

Though lazy binding is default, it does not seem to be applicable to shared libraries. However, if the same libmain.c is made into an executable, as in:
---
$ cat libmain.c
#include <stdio.h>
extern void foo(void);
void (*func_p)(void) = foo;
int main()
{
    printf("printf()\n");
    (*func_p)();
    return 0;
}

$ cc libmain.c -Wl,--unresolved-symbols=ignore-all

$ ./a.out
printf()
Segmentation fault (core dumped)
---

That means lazy binding has happened. I would like to see both shlibs and executable behavior same here. What is the problem if we make this change? This can be part of the GNU-gABI itself.

--
Supra