pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
RTLD_LAZY considered harmful (Re: pltlc and pltlcu problems)
17+ messages / 7 participants
[nested] [flat]

* RTLD_LAZY considered harmful (Re: pltlc and pltlcu problems)
@ 2002-01-20 18:40  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 4 replies; 17+ messages in thread

From: Tom Lane @ 2002-01-20 18:40 UTC (permalink / raw)
  To: Brent Verner <brent@rcfile.org>; +Cc: Murray Prior Hobbs <murray@efone.com>; Lamar Owen <lamar.owen@wgcr.org>; pgsql-hackers@postgresql.org

Brent Verner <brent@rcfile.org> writes:
> Can someone verify that pltcl works on
> their stock redhat 7.2 system?

Indeed it does not.  On a straight-from-the-CD RH 7.2 install and
CVS-tip Postgres, I see both of the behaviors Murray complained of.

What I think is particularly nasty is that we get an exit(127) when
the symbol resolution fails, leading to database restart.  This will
probably happen on *most* systems not only Linux, because we are
specifying RTLD_LAZY in our dlopen() calls, meaning that missing
symbols should be flagged when they are referenced at runtime --- and
if we call a function that should be there and isn't, there's not much
the dynamic loader can do except throw a signal or exit().

What we should be doing is specifying RTLD_NOW to dlopen(), so that
any unresolved symbol failure occurs during dlopen(), when we are
prepared to deal with it in a clean fashion.

I ran into this same behavior years ago on HPUX and fixed it by using
what they call BIND_IMMEDIATE mode; but I now see that most of the
other ports are specifying RTLD_LAZY, and thus have this problem.

Unless I hear a credible counter-argument, I am going to change
RTLD_LAZY to RTLD_NOW in src/backend/port/dynloader/linux.h.  I have
tested that and it produces a clean error with no backend crash.

What I would *like* to do is make the same change in all the
port/dynloader files that reference RTLD_LAZY:
	src/backend/port/dynloader/aix.h
	src/backend/port/dynloader/bsdi.h
	src/backend/port/dynloader/dgux.h
	src/backend/port/dynloader/freebsd.h
	src/backend/port/dynloader/irix5.h
	src/backend/port/dynloader/linux.h
	src/backend/port/dynloader/netbsd.h
	src/backend/port/dynloader/openbsd.h
	src/backend/port/dynloader/osf.h
	src/backend/port/dynloader/sco.h
	src/backend/port/dynloader/solaris.h
	src/backend/port/dynloader/svr4.h
	src/backend/port/dynloader/univel.h
	src/backend/port/dynloader/unixware.h
	src/backend/port/dynloader/win.h
However I'm a bit scared to do that at this late stage of the release
cycle, because perhaps some of these platforms don't support the full
dlopen() API.  Comments?  Can anyone test whether RTLD_NOW works on
any of the above-mentioned ports?

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu problems)
@ 2002-01-20 19:10  Bruce Momjian <pgman@candle.pha.pa.us>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  3 siblings, 0 replies; 17+ messages in thread

From: Bruce Momjian @ 2002-01-20 19:10 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Brent Verner <brent@rcfile.org>; Murray Prior Hobbs <murray@efone.com>; Lamar Owen <lamar.owen@wgcr.org>; pgsql-hackers@postgresql.org

> However I'm a bit scared to do that at this late stage of the release
> cycle, because perhaps some of these platforms don't support the full
> dlopen() API.  Comments?  Can anyone test whether RTLD_NOW works on
> any of the above-mentioned ports?

I can confirm that RTLD_NOW exists on BSD/OS.  Can we do:

	#ifdef RTLD_NOW 
	use RTLD_NOW 
	#else 
	whatever_is_there_now
	#endif

in those ports at least for 7.2 so we can be sure we don't get failures.


-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu
@ 2002-01-20 21:11  Peter Eisentraut <peter_e@gmx.net>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  3 siblings, 1 reply; 17+ messages in thread

From: Peter Eisentraut @ 2002-01-20 21:11 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Brent Verner <brent@rcfile.org>; Murray Prior Hobbs <murray@efone.com>; Lamar Owen <lamar.owen@wgcr.org>; pgsql-hackers@postgresql.org

Tom Lane writes:

> Unless I hear a credible counter-argument, I am going to change
> RTLD_LAZY to RTLD_NOW in src/backend/port/dynloader/linux.h.  I have
> tested that and it produces a clean error with no backend crash.
>
> What I would *like* to do is make the same change in all the
> port/dynloader files that reference RTLD_LAZY:

RTLD_LAZY allows you to load shared library modules that contain circular
references.  I don't know if that's useful or just stupid, but on some
systems the shared library models are pretty, um, different so that the
need for this might arise from time to time.

> However I'm a bit scared to do that at this late stage of the release
> cycle, because perhaps some of these platforms don't support the full
> dlopen() API.  Comments?  Can anyone test whether RTLD_NOW works on
> any of the above-mentioned ports?

I really don't think this is a good change to make now, as we don't know
how well all of this is supported, and the failure scenario is annoying
but not really that harmful.

-- 
Peter Eisentraut   peter_e@gmx.net




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu problems)
@ 2002-01-20 21:43  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Peter Eisentraut <peter_e@gmx.net>
  0 siblings, 0 replies; 17+ messages in thread

From: Tom Lane @ 2002-01-20 21:43 UTC (permalink / raw)
  To: Peter Eisentraut <peter_e@gmx.net>; +Cc: Brent Verner <brent@rcfile.org>; Murray Prior Hobbs <murray@efone.com>; Lamar Owen <lamar.owen@wgcr.org>; pgsql-hackers@postgresql.org

Peter Eisentraut <peter_e@gmx.net> writes:
> Tom Lane writes:
>> Unless I hear a credible counter-argument, I am going to change
>> RTLD_LAZY to RTLD_NOW in src/backend/port/dynloader/linux.h.  I have
>> tested that and it produces a clean error with no backend crash.

> RTLD_LAZY allows you to load shared library modules that contain circular
> references.

Does that not work with RTLD_NOW?  I should think it would.  In any
case, I'm doubtful that we care.

> I really don't think this is a good change to make now, as we don't know
> how well all of this is supported, and the failure scenario is annoying
> but not really that harmful.

A database restart is always very bad news in my mind.  You might be
right that it's too risky to make such a change now for 7.2, but I still
absolutely want to do it for 7.3.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu problems)
@ 2002-01-21 08:12  David Terrell <dbt@meat.net>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  3 siblings, 1 reply; 17+ messages in thread

From: David Terrell @ 2002-01-21 08:12 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Brent Verner <brent@rcfile.org>; Murray Prior Hobbs <murray@efone.com>; Lamar Owen <lamar.owen@wgcr.org>; pgsql-hackers@postgresql.org

On Sun, Jan 20, 2002 at 01:40:17PM -0500, Tom Lane wrote:
> What I would *like* to do is make the same change in all the
> port/dynloader files that reference RTLD_LAZY:
> 	src/backend/port/dynloader/openbsd.h

I can't speak for other platforms but openbsd only has RTLD_LAZY.

-- 
David Terrell            | "... a grandiose, wasteful drug war that will never
dbt@meat.net             | be won as long as so many Americans need to 
Nebcorp Prime Minister   | anesthetize themselves to get through the day." 
http://wwn.nebcorp.com/  |  -Camille Paglia



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu problems)
@ 2002-01-21 08:21  Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  parent: David Terrell <dbt@meat.net>
  0 siblings, 1 reply; 17+ messages in thread

From: Christopher Kings-Lynne @ 2002-01-21 08:21 UTC (permalink / raw)
  To: David Terrell <dbt@meat.net>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Brent Verner <brent@rcfile.org>; Murray Prior Hobbs <murray@efone.com>; Lamar Owen <lamar.owen@wgcr.org>; pgsql-hackers@postgresql.org

> On Sun, Jan 20, 2002 at 01:40:17PM -0500, Tom Lane wrote:
> > What I would *like* to do is make the same change in all the
> > port/dynloader files that reference RTLD_LAZY:
> > 	src/backend/port/dynloader/openbsd.h
>
> I can't speak for other platforms but openbsd only has RTLD_LAZY.

FreeBSD supports both:

     RTLD_LAZY   Each external function reference is resolved when the func-
                 tion is first called.

     RTLD_NOW    All external function references are bound immediately by
                 dlopen().

     RTLD_LAZY is normally preferred, for reasons of efficiency.  However,
     RTLD_NOW is useful to ensure that any undefined symbols are discovered

Chris




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu problems)
@ 2002-01-21 13:09  Bruce Momjian <pgman@candle.pha.pa.us>
  parent: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  0 siblings, 2 replies; 17+ messages in thread

From: Bruce Momjian @ 2002-01-21 13:09 UTC (permalink / raw)
  To: Christopher Kings-Lynne <chriskl@familyhealth.com.au>; +Cc: David Terrell <dbt@meat.net>; Tom Lane <tgl@sss.pgh.pa.us>; Brent Verner <brent@rcfile.org>; Murray Prior Hobbs <murray@efone.com>; Lamar Owen <lamar.owen@wgcr.org>; pgsql-hackers@postgresql.org

Christopher Kings-Lynne wrote:
> > On Sun, Jan 20, 2002 at 01:40:17PM -0500, Tom Lane wrote:
> > > What I would *like* to do is make the same change in all the
> > > port/dynloader files that reference RTLD_LAZY:
> > > 	src/backend/port/dynloader/openbsd.h
> >
> > I can't speak for other platforms but openbsd only has RTLD_LAZY.
> 
> FreeBSD supports both:
> 
>      RTLD_LAZY   Each external function reference is resolved when the func-
>                  tion is first called.
> 
>      RTLD_NOW    All external function references are bound immediately by
>                  dlopen().
> 
>      RTLD_LAZY is normally preferred, for reasons of efficiency.  However,
>      RTLD_NOW is useful to ensure that any undefined symbols are discovered
> 

Interesting LAZY has better efficiency.  Seems we should just keep LAZY
as our default for future releases and tell people if they link to bad
object files, they should expect trouble.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu
@ 2002-01-21 16:50  Peter Eisentraut <peter_e@gmx.net>
  parent: Bruce Momjian <pgman@candle.pha.pa.us>
  1 sibling, 2 replies; 17+ messages in thread

From: Peter Eisentraut @ 2002-01-21 16:50 UTC (permalink / raw)
  To: Bruce Momjian <pgman@candle.pha.pa.us>; +Cc: Christopher Kings-Lynne <chriskl@familyhealth.com.au>; David Terrell <dbt@meat.net>; Tom Lane <tgl@sss.pgh.pa.us>; Brent Verner <brent@rcfile.org>; Murray Prior Hobbs <murray@efone.com>; Lamar Owen <lamar.owen@wgcr.org>; pgsql-hackers@postgresql.org

Bruce Momjian writes:

> Interesting LAZY has better efficiency.  Seems we should just keep LAZY
> as our default for future releases and tell people if they link to bad
> object files, they should expect trouble.

In practice, we load object files only if we call the function, so symbol
resolution happens either way briefly after loading.  RTLD_NOW includes
some overhead because it checks symbols that we might not end up needing,
but for the typical PostgreSQL extension module, that should really not
matter.

-- 
Peter Eisentraut   peter_e@gmx.net




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu problems)
@ 2002-01-21 16:54  Bruce Momjian <pgman@candle.pha.pa.us>
  parent: Peter Eisentraut <peter_e@gmx.net>
  1 sibling, 0 replies; 17+ messages in thread

From: Bruce Momjian @ 2002-01-21 16:54 UTC (permalink / raw)
  To: Peter Eisentraut <peter_e@gmx.net>; +Cc: Christopher Kings-Lynne <chriskl@familyhealth.com.au>; David Terrell <dbt@meat.net>; Tom Lane <tgl@sss.pgh.pa.us>; Brent Verner <brent@rcfile.org>; Murray Prior Hobbs <murray@efone.com>; Lamar Owen <lamar.owen@wgcr.org>; pgsql-hackers@postgresql.org

Peter Eisentraut wrote:
> Bruce Momjian writes:
> 
> > Interesting LAZY has better efficiency.  Seems we should just keep LAZY
> > as our default for future releases and tell people if they link to bad
> > object files, they should expect trouble.
> 
> In practice, we load object files only if we call the function, so symbol
> resolution happens either way briefly after loading.  RTLD_NOW includes
> some overhead because it checks symbols that we might not end up needing,
> but for the typical PostgreSQL extension module, that should really not
> matter.

OK, I was just throwing out the point in case it was significant.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu problems)
@ 2002-01-21 17:03  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Bruce Momjian <pgman@candle.pha.pa.us>
  1 sibling, 0 replies; 17+ messages in thread

From: Tom Lane @ 2002-01-21 17:03 UTC (permalink / raw)
  To: Bruce Momjian <pgman@candle.pha.pa.us>; +Cc: Christopher Kings-Lynne <chriskl@familyhealth.com.au>; David Terrell <dbt@meat.net>; Brent Verner <brent@rcfile.org>; Murray Prior Hobbs <murray@efone.com>; Lamar Owen <lamar.owen@wgcr.org>; pgsql-hackers@postgresql.org

Bruce Momjian <pgman@candle.pha.pa.us> writes:
> Interesting LAZY has better efficiency.

"Efficiency" by what measure?  I would think that batch resolution of
symbols would be faster than taking a trap for each one.

> Seems we should just keep LAZY
> as our default for future releases and tell people if they link to bad
> object files, they should expect trouble.

(a) How are they going to find out if the object files are bad, other
than by crashing their database?  I *really* don't like the attitude
that a backend crash is okay.  Under any circumstances, development
or not.

(b) Badness may depend on context, eg LD_LIBRARY_PATH.  So it's not
really safe to assume that if it worked before then you don't have to
worry about it crashing you in production.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu problems)
@ 2002-01-21 19:04  Patrick Welche <prlw1@newn.cam.ac.uk>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  3 siblings, 0 replies; 17+ messages in thread

From: Patrick Welche @ 2002-01-21 19:04 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers@postgresql.org

On Sun, Jan 20, 2002 at 01:40:17PM -0500, Tom Lane wrote:
> cycle, because perhaps some of these platforms don't support the full
> dlopen() API.  Comments?  Can anyone test whether RTLD_NOW works on
> any of the above-mentioned ports?

Didn't check it *works*, but from $NetBSD: dlfcn.h,v 1.13 2000/06/13 01:21:53

/* Values for dlopen `mode'. */
#define RTLD_LAZY       1
#define RTLD_NOW        2
#define RTLD_GLOBAL     0x100           /* Allow global searches in object */
#define RTLD_LOCAL      0x200
#if !defined(_XOPEN_SOURCE)
#define DL_LAZY         RTLD_LAZY       /* Compat */
#endif

Cheers,

Patrick



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu
@ 2002-02-11 01:00  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Peter Eisentraut <peter_e@gmx.net>
  1 sibling, 2 replies; 17+ messages in thread

From: Tom Lane @ 2002-02-11 01:00 UTC (permalink / raw)
  To: pgsql-hackers@postgresql.org

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 have just noticed that the 7.0 and 7.1 versions of
src/backend/port/dynloader/linux.h have

#define pg_dlopen(f)	dlopen(f, 2)

which in 7.2 has been changed to

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

But a quick look in /usr/include/bits/dlfcn.h shows that (at least
on RH Linux 7.2), the old coding was equivalent to RTLD_NOW.

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.

A grep through the 7.1 versions of src/backend/port/dynloader/*.h
shows the following rather motley assortment of dlopen flag choices:

aix.h:61:#define  pg_dlopen(f)  dlopen(f, RTLD_LAZY)
bsdi.h:23:#define         pg_dlopen(f)    dlopen(f, RTLD_LAZY)
dgux.h:26:#define pg_dlopen(f)  dlopen(f,1)
freebsd.h:36:#define           pg_dlopen(f)    BSD44_derived_dlopen(f, 1)
irix5.h:29:#define pg_dlopen(f) dlopen(f,1)
linux.h:34:#define pg_dlopen(f) dlopen(f, 2)
netbsd.h:36:#define        pg_dlopen(f)    BSD44_derived_dlopen(f, 1)
openbsd.h:36:#define           pg_dlopen(f)    BSD44_derived_dlopen(f, 1)
osf.h:31:#define  pg_dlopen(f)  dlopen(f, RTLD_LAZY)
sco.h:29:#define pg_dlopen(f)   dlopen(f,1)
solaris.h:9:#define pg_dlopen(f)    dlopen(f,1)
sunos4.h:29:#define pg_dlopen(f)    dlopen(f, 1)
svr4.h:29:#define pg_dlopen(f)  dlopen(f,RTLD_LAZY)
univel.h:29:#define pg_dlopen(f)    dlopen(f,RTLD_LAZY)
unixware.h:29:#define pg_dlopen(f)  dlopen(f,RTLD_LAZY)
win.h:29:#define pg_dlopen(f)       dlopen(f,1)

In 7.2 these have all been changed to "RTLD_LAZY | RTLD_GLOBAL", but
I am no longer willing to presume that that's equivalent to the
original coding.  Could people who have these platforms look to see
what the numeric values mentioned above actually equate to on their
platforms?

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu
@ 2002-02-11 01:42  Brent Verner <brent@rcfile.org>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 17+ messages in thread

From: Brent Verner @ 2002-02-11 01:42 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers@postgresql.org

[2002-02-10 20:00] Tom Lane said:

| freebsd.h:36:#define           pg_dlopen(f)    BSD44_derived_dlopen(f, 1)
| netbsd.h:36:#define        pg_dlopen(f)    BSD44_derived_dlopen(f, 1)

  freebsd 4.5
  netbsd 1.5.2

#define RTLD_LAZY  1
#define RTLD_GLOBAL        0x100


cheers.
  brent

-- 
"Develop your talent, man, and leave the world something. Records are 
really gifts from people. To think that an artist would love you enough
to share his music with anyone is a beautiful thing."  -- Duane Allman



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu
@ 2002-02-11 02:24  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Brent Verner <brent@rcfile.org>
  0 siblings, 1 reply; 17+ messages in thread

From: Tom Lane @ 2002-02-11 02:24 UTC (permalink / raw)
  To: Brent Verner <brent@rcfile.org>; +Cc: pgsql-hackers@postgresql.org

Brent Verner <brent@rcfile.org> writes:
>   freebsd 4.5
>   netbsd 1.5.2

> #define RTLD_LAZY  1
> #define RTLD_GLOBAL        0x100

Thanks.  Is there an RTLD_NOW symbol on those platforms?

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu
@ 2002-02-11 03:49  Brent Verner <brent@rcfile.org>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 17+ messages in thread

From: Brent Verner @ 2002-02-11 03:49 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers@postgresql.org

[2002-02-10 21:24] Tom Lane said:
| Brent Verner <brent@rcfile.org> writes:
| >   freebsd 4.5
| >   netbsd 1.5.2
| 
| > #define RTLD_LAZY  1
| > #define RTLD_GLOBAL        0x100
| 
| Thanks.  Is there an RTLD_NOW symbol on those platforms?

yes. I've attached the dlfcn.h files from each incase there is
anything else in there that might be of interest.

cheers.
  brent

-- 
"Develop your talent, man, and leave the world something. Records are 
really gifts from people. To think that an artist would love you enough
to share his music with anyone is a beautiful thing."  -- Duane Allman

Attachments:

freebsd-dlfcn.h (text/plain, 3.2K) download /* * Copyright (c) 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD: src/include/dlfcn.h,v 1.10.2.1 2000/09/22 02:22:44 jdp Exp $ */ #ifndef _DLFCN_H_ #define _DLFCN_H_ #include <sys/cdefs.h> /* * Modes and flags for dlopen(). */ #define RTLD_LAZY 1 /* Bind function calls lazily */ #define RTLD_NOW 2 /* Bind function calls immediately */ #define RTLD_MODEMASK 0x3 #define RTLD_GLOBAL 0x100 /* Make symbols globally available */ #define RTLD_LOCAL 0 /* Opposite of RTLD_GLOBAL, and the default */ /* * Special handle arguments for dlsym(). */ #define RTLD_NEXT ((void *) -1) /* Search subsequent objects */ #define RTLD_DEFAULT ((void *) -2) /* Use default search algorithm */ /* * Structure filled in by dladdr(). */ typedef struct dl_info { const char *dli_fname; /* Pathname of shared object */ void *dli_fbase; /* Base address of shared object */ const char *dli_sname; /* Name of nearest symbol */ void *dli_saddr; /* Address of nearest symbol */ } Dl_info; __BEGIN_DECLS int dladdr __P((const void *, Dl_info *)); int dlclose __P((void *)); const char *dlerror __P((void)); void dllockinit __P((void *_context, void *(*_lock_create)(void *_context), void (*_rlock_acquire)(void *_lock), void (*_wlock_acquire)(void *_lock), void (*_lock_release)(void *_lock), void (*_lock_destroy)(void *_lock), void (*_context_destroy)(void *_context))); void *dlopen __P((const char *, int)); void *dlsym __P((void *, const char *)); __END_DECLS #endif /* !_DLFCN_H_ */
netbsd-dlfcn.h (text/plain, 3.1K) download /* $NetBSD: dlfcn.h,v 1.13 2000/06/13 01:21:53 simonb Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Paul Kranenburg. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the NetBSD * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef _DLFCN_H_ #define _DLFCN_H_ #include <sys/cdefs.h> #if !defined(_XOPEN_SOURCE) typedef struct _dl_info { const char *dli_fname; /* File defining the symbol */ void *dli_fbase; /* Base address */ const char *dli_sname; /* Symbol name */ const void *dli_saddr; /* Symbol address */ } Dl_info; #endif /* !defined(_XOPEN_SOURCE) */ /* * User interface to the run-time linker. */ __BEGIN_DECLS void *dlopen __P((const char *, int)); int dlclose __P((void *)); void *dlsym __P((void *, const char *)); #if !defined(_XOPEN_SOURCE) int dladdr __P((const void *, Dl_info *)); int dlctl __P((void *, int, void *)); #endif __aconst char *dlerror __P((void)); __END_DECLS /* Values for dlopen `mode'. */ #define RTLD_LAZY 1 #define RTLD_NOW 2 #define RTLD_GLOBAL 0x100 /* Allow global searches in object */ #define RTLD_LOCAL 0x200 #if !defined(_XOPEN_SOURCE) #define DL_LAZY RTLD_LAZY /* Compat */ #endif /* * dlctl() commands */ #if !defined(_XOPEN_SOURCE) #define DL_GETERRNO 1 #define DL_GETSYMBOL 2 #if 0 #define DL_SETSRCHPATH x #define DL_GETLIST x #define DL_GETREFCNT x #define DL_GETLOADADDR x #endif /* 0 */ #endif /* !defined(_XOPEN_SOURCE) */ #endif /* !defined(_DLFCN_H_) */
^ permalink raw reply [nested|flat] 17+ messages in thread

* Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu
@ 2002-02-12 00:49  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 17+ messages in thread

From: Tom Lane @ 2002-02-12 00:49 UTC (permalink / raw)
  To: pgsql-hackers@postgresql.org

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



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu
@ 2002-02-15 02:08  David Terrell <dbt@meat.net>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 17+ messages in thread

From: David Terrell @ 2002-02-15 02:08 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers@postgresql.org

On Mon, Feb 11, 2002 at 07:49:57PM -0500, Tom Lane wrote:
> 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?

OpenBSD:
     The dlopen() function takes a name of a shared object as its first argu-
     ment.  The shared object is mapped into the address space, relocated, and
     its external references are resolved in the same way as is done with the
     implicitly loaded shared libraries at program startup.

     The path argument can either be an absolute pathname or it can be of the
     form ``lib<name>.so[.xx[.yy]]'' in which case the same library search
     rules apply that are used for ``intrinsic'' shared library searches.  The
     second argument currently has no effect, but should be set to DL_LAZY for
     future compatibility.

That last sentence being key....

-- 
David Terrell             | "War is peace, 
Prime Minister, Nebcorp   | freedom is slavery, 
dbt@meat.net              | ignorance is strength 
http://wwn.nebcorp.com/   | Dishes are clean." - Chris Fester



^ permalink  raw  reply  [nested|flat] 17+ messages in thread


end of thread, other threads:[~2002-02-15 02:08 UTC | newest]

Thread overview: 17+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-01-20 18:40 RTLD_LAZY considered harmful (Re: pltlc and pltlcu problems) Tom Lane <tgl@sss.pgh.pa.us>
2002-01-20 19:10 ` Bruce Momjian <pgman@candle.pha.pa.us>
2002-01-20 21:11 ` Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu Peter Eisentraut <peter_e@gmx.net>
2002-01-20 21:43   ` Tom Lane <tgl@sss.pgh.pa.us>
2002-01-21 08:12 ` David Terrell <dbt@meat.net>
2002-01-21 08:21   ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2002-01-21 13:09     ` Bruce Momjian <pgman@candle.pha.pa.us>
2002-01-21 16:50       ` Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu Peter Eisentraut <peter_e@gmx.net>
2002-01-21 16:54         ` Bruce Momjian <pgman@candle.pha.pa.us>
2002-02-11 01:00         ` Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu Tom Lane <tgl@sss.pgh.pa.us>
2002-02-11 01:42           ` Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu Brent Verner <brent@rcfile.org>
2002-02-11 02:24             ` Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu Tom Lane <tgl@sss.pgh.pa.us>
2002-02-11 03:49               ` Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu Brent Verner <brent@rcfile.org>
2002-02-12 00:49           ` Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu Tom Lane <tgl@sss.pgh.pa.us>
2002-02-15 02:08             ` Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu David Terrell <dbt@meat.net>
2002-01-21 17:03       ` Tom Lane <tgl@sss.pgh.pa.us>
2002-01-21 19:04 ` Patrick Welche <prlw1@newn.cam.ac.uk>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox