Porting PostgreSQL to DragonFly BSD

Started by Rumkoalmost 15 years ago10 messages
#1Rumko
rumcic@gmail.com
1 attachment(s)

From what I have checked, all work on making postgresql compile on new
platforms should be posted to this list, so here it goes.

The attached patch (also available at
http://www.rumko.net/0001-DragonFly-BSD-support.patch ) applies cleanly to the
master branch and can be cherry-picked to REL9_0_STABLE branch without
conflicts.

It's based on postgres' FreeBSD support with minimal changes (a few
freebsd->dragonfly renames, removed mips support since dragonfly does not
support it and it also includes a patch to properly define the linker on dfly
as per PR pkg/44617 in http://www.netbsd.org/support/query-pr.html gnats
database).
--
Regards,
Rumko

Attachments:

0001-DragonFly-BSD-support.patchapplication/mbox; name=0001-DragonFly-BSD-support.patchDownload
From 0e6ed29a9862097a0bd959c3eb03ddc45682bba6 Mon Sep 17 00:00:00 2001
From: Rumko <rumko@rumko.net>
Date: Sun, 27 Feb 2011 20:56:11 +0100
Subject: [PATCH] DragonFly BSD support.

Based on FreeBSD port with minimal changes.
---
 configure                              |    1 +
 configure.in                           |    1 +
 src/Makefile.shlib                     |   11 ++++
 src/backend/port/dynloader/dragonfly.c |   92 ++++++++++++++++++++++++++++++++
 src/backend/port/dynloader/dragonfly.h |   59 ++++++++++++++++++++
 src/include/port/dragonfly.h           |    1 +
 src/makefiles/Makefile.dragonfly       |   29 ++++++++++
 7 files changed, 194 insertions(+), 0 deletions(-)
 create mode 100644 src/backend/port/dynloader/dragonfly.c
 create mode 100644 src/backend/port/dynloader/dragonfly.h
 create mode 100644 src/include/port/dragonfly.h
 create mode 100644 src/makefiles/Makefile.dragonfly
 create mode 100644 src/template/dragonfly

diff --git a/configure b/configure
index 0bddb5f..6d208ec 100755
--- a/configure
+++ b/configure
@@ -2196,6 +2196,7 @@ case $host_os in
   darwin*) template=darwin ;;
     dgux*) template=dgux ;;
  freebsd*) template=freebsd ;;
+dragonfly*) template=dragonfly ;;
     hpux*) template=hpux ;;
     irix*) template=irix ;;
  linux*|gnu*|k*bsd*-gnu)
diff --git a/configure.in b/configure.in
index 6aae504..3bc9120 100644
--- a/configure.in
+++ b/configure.in
@@ -60,6 +60,7 @@ case $host_os in
   darwin*) template=darwin ;;
     dgux*) template=dgux ;;
  freebsd*) template=freebsd ;;
+dragonfly*) template=dragonfly ;;
     hpux*) template=hpux ;;
     irix*) template=irix ;;
  linux*|gnu*|k*bsd*-gnu)
diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index a5cf6c6..a78c98c 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -198,6 +198,17 @@ ifeq ($(PORTNAME), netbsd)
   endif
 endif
 
+ifeq ($(PORTNAME), dragonfly)
+  ifdef ELF_SYSTEM
+    LINK.shared 	= $(COMPILER) -shared
+    ifdef soname
+      LINK.shared	+= -Wl,-x,-soname,$(soname)
+    endif
+  else
+    LINK.shared 	= $(LD) -x -Bshareable -Bforcearchive
+  endif
+endif
+
 ifeq ($(PORTNAME), hpux)
   ifdef SO_MAJOR_VERSION
     shlib			= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
diff --git a/src/backend/port/dynloader/dragonfly.c b/src/backend/port/dynloader/dragonfly.c
new file mode 100644
index 0000000..a752301
--- /dev/null
+++ b/src/backend/port/dynloader/dragonfly.c
@@ -0,0 +1,92 @@
+/* src/backend/port/dynloader/dragonfly.c */
+
+/*
+ * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1990 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. 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)dl.c	5.4 (Berkeley) 2/23/91";
+#endif   /* LIBC_SCCS and not lint */
+
+#include "postgres.h"
+
+#include <nlist.h>
+#include <link.h>
+#include <dlfcn.h>
+
+#include "dynloader.h"
+
+static char error_message[BUFSIZ];
+
+char *
+BSD44_derived_dlerror(void)
+{
+	static char ret[BUFSIZ];
+
+	strcpy(ret, error_message);
+	error_message[0] = 0;
+	return (ret[0] == 0) ? NULL : ret;
+}
+
+void *
+BSD44_derived_dlopen(const char *file, int num)
+{
+	void	   *vp;
+
+	if ((vp = dlopen((char *) file, num)) == NULL)
+		snprintf(error_message, sizeof(error_message),
+				 "dlopen (%s) failed: %s", file, dlerror());
+	return vp;
+}
+
+void *
+BSD44_derived_dlsym(void *handle, const char *name)
+{
+	void	   *vp;
+
+#ifndef __ELF__
+	char		buf[BUFSIZ];
+
+	if (*name != '_')
+	{
+		snprintf(buf, sizeof(buf), "_%s", name);
+		name = buf;
+	}
+#endif
+	if ((vp = dlsym(handle, (char *) name)) == NULL)
+		snprintf(error_message, sizeof(error_message),
+				 "dlsym (%s) failed", name);
+	return vp;
+}
+
+void
+BSD44_derived_dlclose(void *handle)
+{
+	dlclose(handle);
+}
diff --git a/src/backend/port/dynloader/dragonfly.h b/src/backend/port/dynloader/dragonfly.h
new file mode 100644
index 0000000..443aed9
--- /dev/null
+++ b/src/backend/port/dynloader/dragonfly.h
@@ -0,0 +1,59 @@
+/*-------------------------------------------------------------------------
+ *
+ * dragonfly.h
+ *	  port-specific prototypes for DragonFly BSD
+ *
+ * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/backend/port/dynloader/dragonfly.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef PORT_PROTOS_H
+#define PORT_PROTOS_H
+
+#include <sys/types.h>
+#include <nlist.h>
+#include <link.h>
+#include <dlfcn.h>
+
+#include "utils/dynamic_loader.h"
+
+/*
+ * Dynamic Loader on NetBSD 1.0.
+ *
+ * this dynamic loader uses the system dynamic loading interface for shared
+ * libraries (ie. dlopen/dlsym/dlclose). The user must specify a shared
+ * library as the file to be dynamically loaded.
+ *
+ * agc - I know this is all a bit crufty, but it does work, is fairly
+ * portable, and works (the stipulation that the d.l. function must
+ * begin with an underscore is fairly tricky, and some versions of
+ * NetBSD (like 1.0, and 1.0A pre June 1995) have no dlerror.)
+ */
+
+/*
+ * In some older systems, 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)    BSD44_derived_dlopen((f), RTLD_NOW | RTLD_GLOBAL)
+#define		   pg_dlsym		   BSD44_derived_dlsym
+#define		   pg_dlclose	   BSD44_derived_dlclose
+#define		   pg_dlerror	   BSD44_derived_dlerror
+
+char	   *BSD44_derived_dlerror(void);
+void	   *BSD44_derived_dlopen(const char *filename, int num);
+void	   *BSD44_derived_dlsym(void *handle, const char *name);
+void		BSD44_derived_dlclose(void *handle);
+
+#endif   /* PORT_PROTOS_H */
diff --git a/src/include/port/dragonfly.h b/src/include/port/dragonfly.h
new file mode 100644
index 0000000..3ebe8b4
--- /dev/null
+++ b/src/include/port/dragonfly.h
@@ -0,0 +1 @@
+/* src/include/port/dragonfly.h */
diff --git a/src/makefiles/Makefile.dragonfly b/src/makefiles/Makefile.dragonfly
new file mode 100644
index 0000000..839864c
--- /dev/null
+++ b/src/makefiles/Makefile.dragonfly
@@ -0,0 +1,29 @@
+AROPT = cr
+
+ifdef ELF_SYSTEM
+export_dynamic = -Wl,-export-dynamic
+rpath = -Wl,-R'$(rpathdir)'
+endif
+
+DLSUFFIX = .so
+
+CFLAGS_SL = -fPIC -DPIC
+
+ifeq ($(findstring i386,$(host_cpu)), i386)
+allow_nonpic_in_shlib = yes
+endif
+
+
+# Rule for building a shared library from a single .o file
+%.so: %.o
+ifdef ELF_SYSTEM
+	$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $<
+else
+	$(LD) $(LDREL) $(LDOUT) $<.obj -x $<
+	@echo building shared object $@
+	@rm -f $@.pic
+	@${AR} cq $@.pic $<.obj
+	${RANLIB} $@.pic
+	@rm -f $@
+	$(LD) -x -Bshareable -Bforcearchive -o $@ $@.pic
+endif
diff --git a/src/template/dragonfly b/src/template/dragonfly
new file mode 100644
index 0000000..e69de29
-- 
1.7.3.5

#2Peter Eisentraut
peter_e@gmx.net
In reply to: Rumko (#1)
Re: Porting PostgreSQL to DragonFly BSD

On sön, 2011-02-27 at 21:19 +0100, Rumko wrote:

The attached patch (also available at
http://www.rumko.net/0001-DragonFly-BSD-support.patch ) applies cleanly to the
master branch and can be cherry-picked to REL9_0_STABLE branch without
conflicts.

It seems to me that it would be easier to just map dragonfly to the
freebsd template.

#3Rumko
rumcic@gmail.com
In reply to: Peter Eisentraut (#2)
Re: Porting PostgreSQL to DragonFly BSD

On Sunday 27. of February 2011 23:50:17 Peter Eisentraut wrote:

On sön, 2011-02-27 at 21:19 +0100, Rumko wrote:

The attached patch (also available at
http://www.rumko.net/0001-DragonFly-BSD-support.patch ) applies cleanly
to the master branch and can be cherry-picked to REL9_0_STABLE branch
without conflicts.

It seems to me that it would be easier to just map dragonfly to the
freebsd template.

I didn't see a precedence for that kind of introduction of a new platform (all
others seem to have their own templates), so thought it would've had less
chance of being accepted.

Is it preferable to have it linked instead of having it separate like in the
current patch?
--
Regards,
Rumko

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Rumko (#3)
Re: Porting PostgreSQL to DragonFly BSD

Rumko <rumcic@gmail.com> writes:

On Sunday 27. of February 2011 23:50:17 Peter Eisentraut wrote:

It seems to me that it would be easier to just map dragonfly to the
freebsd template.

I didn't see a precedence for that kind of introduction of a new platform (all
others seem to have their own templates), so thought it would've had less
chance of being accepted.

When I looked at that patch, I actually couldn't see anything different
at all from freebsd. We aren't interested in maintaining 99% duplicate
code --- it seems much easier from a maintenance standpoint to introduce
an ifdef or two into the freebsd code, rather than deal with a large cut
and paste job. Please try it that way and see what you come up with.
(It's possible that it'll be so ugly that we agree your original patch
is better, but we need to see the results of the experiment.)

regards, tom lane

#5Rumko
rumcic@gmail.com
In reply to: Tom Lane (#4)
1 attachment(s)
Re: Porting PostgreSQL to DragonFly BSD

On Tuesday 1. of March 2011 16:07:47 Tom Lane wrote:

Rumko <rumcic@gmail.com> writes:

On Sunday 27. of February 2011 23:50:17 Peter Eisentraut wrote:

It seems to me that it would be easier to just map dragonfly to the
freebsd template.

I didn't see a precedence for that kind of introduction of a new platform
(all others seem to have their own templates), so thought it would've had
less chance of being accepted.

When I looked at that patch, I actually couldn't see anything different
at all from freebsd. We aren't interested in maintaining 99% duplicate
code --- it seems much easier from a maintenance standpoint to introduce
an ifdef or two into the freebsd code, rather than deal with a large cut
and paste job. Please try it that way and see what you come up with.
(It's possible that it'll be so ugly that we agree your original patch
is better, but we need to see the results of the experiment.)

regards, tom lane

Well, wouldn't consider it ugly, but the patch (attached and available at
http://www.rumko.net/0001-DragonFly-BSD-support-linked.patch ) is a lot
shorter.

Uses freebsd's template and defines the linker in Makefile.shlib.
--
Regards,
Rumko

Attachments:

0001-DragonFly-BSD-support-linked.patchtext/plain; charset="iso 8859-15"; name=0001-DragonFly-BSD-support-linked.patchDownload
From cf98b549799fac991ee627f16f6131c092913101 Mon Sep 17 00:00:00 2001
From: Rumko <rumko@rumko.net>
Date: Sun, 27 Feb 2011 20:56:11 +0100
Subject: [PATCH] DragonFly BSD support.

Based on FreeBSD port with minimal changes.
---
 configure          |    1 +
 configure.in       |    1 +
 src/Makefile.shlib |   11 +++++++++++
 3 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/configure b/configure
index 0bddb5f..b4da314 100755
--- a/configure
+++ b/configure
@@ -2196,6 +2196,7 @@ case $host_os in
   darwin*) template=darwin ;;
     dgux*) template=dgux ;;
  freebsd*) template=freebsd ;;
+dragonfly*) template=freebsd ;;
     hpux*) template=hpux ;;
     irix*) template=irix ;;
  linux*|gnu*|k*bsd*-gnu)
diff --git a/configure.in b/configure.in
index 6aae504..5178570 100644
--- a/configure.in
+++ b/configure.in
@@ -60,6 +60,7 @@ case $host_os in
   darwin*) template=darwin ;;
     dgux*) template=dgux ;;
  freebsd*) template=freebsd ;;
+dragonfly*) template=freebsd ;;
     hpux*) template=hpux ;;
     irix*) template=irix ;;
  linux*|gnu*|k*bsd*-gnu)
diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index a5cf6c6..a78c98c 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -198,6 +198,17 @@ ifeq ($(PORTNAME), netbsd)
   endif
 endif
 
+ifeq ($(PORTNAME), dragonfly)
+  ifdef ELF_SYSTEM
+    LINK.shared 	= $(COMPILER) -shared
+    ifdef soname
+      LINK.shared	+= -Wl,-x,-soname,$(soname)
+    endif
+  else
+    LINK.shared 	= $(LD) -x -Bshareable -Bforcearchive
+  endif
+endif
+
 ifeq ($(PORTNAME), hpux)
   ifdef SO_MAJOR_VERSION
     shlib			= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
-- 
1.7.3.5

#6Peter Eisentraut
peter_e@gmx.net
In reply to: Rumko (#5)
Re: Porting PostgreSQL to DragonFly BSD

On tis, 2011-03-01 at 22:22 +0100, Rumko wrote:

Well, wouldn't consider it ugly, but the patch (attached and available at
http://www.rumko.net/0001-DragonFly-BSD-support-linked.patch ) is a lot
shorter.

Uses freebsd's template and defines the linker in Makefile.shlib.

The piece in Makefile.shlib you add is dead code because PORTNAME will
never be "dragonfly" (it would be "freebsd"). I see there is a
difference between the existing freebsd code and what you propose to add
in that freebsd doesn't use shared object minor versions. Is that also
or not the case on DragonFly BSD?

#7Rumko
rumcic@gmail.com
In reply to: Peter Eisentraut (#6)
Re: Porting PostgreSQL to DragonFly BSD

On Tuesday 1. of March 2011 22:44:16 Peter Eisentraut wrote:

On tis, 2011-03-01 at 22:22 +0100, Rumko wrote:

Well, wouldn't consider it ugly, but the patch (attached and available at
http://www.rumko.net/0001-DragonFly-BSD-support-linked.patch ) is a lot
shorter.

Uses freebsd's template and defines the linker in Makefile.shlib.

The piece in Makefile.shlib you add is dead code because PORTNAME will
never be "dragonfly" (it would be "freebsd").

Ah, good to know.

I see there is a
difference between the existing freebsd code and what you propose to add
in that freebsd doesn't use shared object minor versions. Is that also
or not the case on DragonFly BSD?

Due to pkgsrc being the default on NetBSD and DragonFly BSD, it should create
the libs in the same way ... maybe instead of using PORTNAME, we could use
host_os to differentiate?
--
Regards,
Rumko

#8Rumko
rumcic@gmail.com
In reply to: Rumko (#7)
1 attachment(s)
Re: Porting PostgreSQL to DragonFly BSD

On Tuesday 1. of March 2011 23:05:17 Rumko wrote:

On Tuesday 1. of March 2011 22:44:16 Peter Eisentraut wrote:

On tis, 2011-03-01 at 22:22 +0100, Rumko wrote:

Well, wouldn't consider it ugly, but the patch (attached and available
at http://www.rumko.net/0001-DragonFly-BSD-support-linked.patch ) is a
lot shorter.

Uses freebsd's template and defines the linker in Makefile.shlib.

The piece in Makefile.shlib you add is dead code because PORTNAME will
never be "dragonfly" (it would be "freebsd").

Ah, good to know.

I see there is a
difference between the existing freebsd code and what you propose to add
in that freebsd doesn't use shared object minor versions. Is that also
or not the case on DragonFly BSD?

Due to pkgsrc being the default on NetBSD and DragonFly BSD, it should
create the libs in the same way ... maybe instead of using PORTNAME, we
could use host_os to differentiate?

What about this patch (
http://www.rumko.net/0001-DragonFly-BSD-support-linked-nbsd.patch )? instead
of linking to freebsd, it's linked to netbsd and It still compiles due to the
two templates being similar enough.
--
Regards,
Rumko

Attachments:

0001-DragonFly-BSD-support-linked-nbsd.patchtext/plain; charset="iso 8859-15"; name=0001-DragonFly-BSD-support-linked-nbsd.patchDownload
From 1ba04688d97d8e6d489d2d44b335cf03c64564bb Mon Sep 17 00:00:00 2001
From: Rumko <rumko@rumko.net>
Date: Sun, 27 Feb 2011 20:56:11 +0100
Subject: [PATCH] DragonFly BSD support.

Based on NetBSD port.
---
 configure    |    1 +
 configure.in |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/configure b/configure
index 0bddb5f..e55714c 100755
--- a/configure
+++ b/configure
@@ -2196,6 +2196,7 @@ case $host_os in
   darwin*) template=darwin ;;
     dgux*) template=dgux ;;
  freebsd*) template=freebsd ;;
+dragonfly*) template=netbsd ;;
     hpux*) template=hpux ;;
     irix*) template=irix ;;
  linux*|gnu*|k*bsd*-gnu)
diff --git a/configure.in b/configure.in
index 6aae504..d45cbc8 100644
--- a/configure.in
+++ b/configure.in
@@ -60,6 +60,7 @@ case $host_os in
   darwin*) template=darwin ;;
     dgux*) template=dgux ;;
  freebsd*) template=freebsd ;;
+dragonfly*) template=netbsd ;;
     hpux*) template=hpux ;;
     irix*) template=irix ;;
  linux*|gnu*|k*bsd*-gnu)
-- 
1.7.3.5

#9Peter Eisentraut
peter_e@gmx.net
In reply to: Rumko (#8)
Re: Porting PostgreSQL to DragonFly BSD

On ons, 2011-03-02 at 09:10 +0100, Rumko wrote:

What about this patch (
http://www.rumko.net/0001-DragonFly-BSD-support-linked-nbsd.patch )?
instead of linking to freebsd, it's linked to netbsd and It still
compiles due to the two templates being similar enough.

Looks good. Committed.

#10Rumko
rumcic@gmail.com
In reply to: Peter Eisentraut (#9)
Re: Porting PostgreSQL to DragonFly BSD

On Wednesday 2. of March 2011 20:18:08 Peter Eisentraut wrote:

On ons, 2011-03-02 at 09:10 +0100, Rumko wrote:

What about this patch (
http://www.rumko.net/0001-DragonFly-BSD-support-linked-nbsd.patch )?
instead of linking to freebsd, it's linked to netbsd and It still
compiles due to the two templates being similar enough.

Looks good. Committed.

Thank you.
--
Regards,
Rumko