tech-userlevel archive

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

Re: dlopen fails from static binary

On Mon, Apr 18, 2016 at 07:42:57AM +0000, Emmanuel Dreyfus wrote:
> src/lib/libc/dlfcn/dlfcn_elf.c says:
> /*
>  * For ELF, the dynamic linker directly resolves references to its
>  * services to functions inside the dynamic linker itself.  These
>  * weak-symbol stubs are necessary so that "ld" won't complain about
>  * undefined symbols.  The stubs are executed only when the program is  
>  * linked statically, or when a given service isn't implemented in the
>  * dynamic linker.  They must return an error if called, and they must
>  * be weak symbols so that the dynamic linker can override them.
>  */

Ah yes, but is there a reason we have that .o in our libc.a?

> static char dlfcn_error[] = "Service unavailable";
> void *
> dlopen(const char *name, int mode)
> {
>         return NULL;
> }
> That suggests we just need to set errno there. To what value? ENOEXEC?

dlopen returns errors via dlerror(), it is not supposed to set errno,
see POSIX:


    Upon successful completion, dlopen() shall return a symbol table
handle. If file cannot be found, cannot be opened for reading, is not
of an appropriate executable object file format for processing by
dlopen(), or if an error occurs during the process of loading file or
relocating its symbolic references, dlopen() shall return a null
pointer. More detailed diagnostic information shall be available
through dlerror().


    No errors are defined.


Home | Main Index | Thread Index | Old Index