Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@postgresql.org
Date: 2002-02-12T00:49:57Z
Lists: pgsql-hackers
I wrote:
> I hate to sound like a broken record, but I want to re-open that
> discussion about RTLD_LAZY binding that trailed off a week or two
> ago.
> ... I therefore assert that the current coding is effectively untested
> on Linux, which is probably our most popular platform, and therefore
> it should *NOT* be accorded the respect normally due to the status
> quo.  Arguably, 7.2 has introduced breakage here.

After some further digging around on the net, I believe that coding in
the following style is safe and will work on all systems supporting
dlopen():

/*
 * In older systems, like SunOS 4.1.3, the RTLD_NOW flag isn't defined
 * and the mode argument to dlopen must always be 1.  The RTLD_GLOBAL
 * flag is wanted if available, but it doesn't exist everywhere.
 * If it doesn't exist, set it to 0 so it has no effect.
 */
#ifndef RTLD_NOW
#   define RTLD_NOW 1
#endif

#ifndef RTLD_GLOBAL
#   define RTLD_GLOBAL 0
#endif

#define pg_dlopen(f)	dlopen((f), RTLD_NOW | RTLD_GLOBAL)


I also believe that this will produce more consistent cross-platform
behavior: so far as I could learn from googling, systems that do not
define RTLD_NOW/RTLD_LAZY all act as though the mode were RTLD_NOW,
ie, immediate binding.

Any objections to modifying all the port/dynloader files this way?

			regards, tom lane