From 6a4fa7eccb1cca133721a4b1b7ae6d6e0881171e Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Wed, 26 Apr 2000 23:35:34 +0000
Subject: [PATCH] On HPUX, shl_load should be called with options
 BIND_IMMEDIATE rather than BIND_DEFERRED.  That way, if the loaded library
 has unresolved references, shl_load fails cleanly.  As we had it, shl_load
 would succeed and then the dynlinker would call abort() when we try to call
 into the loaded library.  abort()ing a backend is uncool.

---
 src/backend/port/dynloader/hpux.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/backend/port/dynloader/hpux.c b/src/backend/port/dynloader/hpux.c
index 43832779b8f..562b59ee770 100644
--- a/src/backend/port/dynloader/hpux.c
+++ b/src/backend/port/dynloader/hpux.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/port/dynloader/hpux.c,v 1.12 2000/01/26 05:56:44 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/port/dynloader/hpux.c,v 1.13 2000/04/26 23:35:34 tgl Exp $
  *
  *	NOTES
  *		all functions are defined here -- it's impossible to trace the
@@ -20,6 +20,7 @@
 #include <a.out.h>
 
 #include "postgres.h"
+
 #include "dl.h"
 #include "dynloader.h"
 #include "fmgr.h"
@@ -28,7 +29,12 @@
 void *
 pg_dlopen(char *filename)
 {
-	shl_t		handle = shl_load(filename, BIND_DEFERRED, 0);
+	/*
+	 * Use BIND_IMMEDIATE so that undefined symbols cause a failure return
+	 * from shl_load(), rather than an abort() later on when we attempt to
+	 * call the library!
+	 */
+	shl_t		handle = shl_load(filename, BIND_IMMEDIATE | BIND_VERBOSE, 0);
 
 	return (void *) handle;
 }
@@ -54,5 +60,8 @@ pg_dlerror()
 {
 	static char errmsg[] = "shl_load failed";
 
+	if (errno)
+		return strerror(errno);
+
 	return errmsg;
 }
-- 
GitLab