Fix obscure linker bug with weak symbols part 1.

We want to search a symbol in the executable itself before looking
at the other opened shared objects. This way weak symbols that are
referenced by the executable will be properly resolved.

Fixes trac #8935.
Do not put symbols in the global scope.

We want to be able to replace a shared object (SO) with a newer version
in GHCi. If we put the symbols of the SO in the local scope we can override
them.

In the global scope the first symbol would be found by looking at the
default handle and the symbols in newly opened SO will not be found.

Fixes #8935.
Remove redundant parameter in internal_dlsym.

The only value that is ever passed to internal_dlsym is
dl_prog_handle. We remove parameter hdl and use dl_prog_handle
directly.

See #8935/
Do not add NULL handle to list of openedSOs.

When dlopen fails there is no new open SO to add.
So just report back the error and add nothing to
list `openedSOs`.

At least on openSUSE Linux the NULL handle is RTLD_DEFAULT and
we look for symbols there first anyway so there is no need to
add the NULL handle to the list of openedSOs.
What happens on systems where RTLD_DEFAULT /= NULL?

See #8935.
fix typo in comment.
Merge branch 'rtld-8935' of github into rtld-8935