Subject: pkg/10543: Minimal patches for PostgreSQL on the Alpha
To: None <gnats-bugs@gnats.netbsd.org>
From: Kevin P. Neal <kpn@neutralgood.org>
List: netbsd-bugs
Date: 07/08/2000 17:08:13
>Number:         10543
>Category:       pkg
>Synopsis:       Minimal patches for PostgreSQL on the Alpha
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jul 08 17:09:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Kevin P. Neal
>Release:        1.4.1, PostgreSQL 6.5.3? 7? (sorry!)
>Organization:
-- 
Kevin P. Neal                                http://www.pobox.com/~kpn/

"You know, I think I can hear the machine screaming from here...  \
'help me! hellpp meeee!'"  - Heather Flanagan, 14:52:23 Wed Jun 10 1998
>Environment:
System: NetBSD tome.neutralgood.org 1.4.2 NetBSD 1.4.2 (TOME) #42: Fri Jun 2 23:24:20 EDT 2000 kpn@tome.neutralgood.org:/usr/src/sys/arch/alpha/compile/TOME alpha

>Description:
   PostgreSQL doesn't run on the Alpha. Here are my minimal patches to
get it limping along, but it is a long way from actually passing the
self tests. Basic "select * from foo where bar = quux" works.

I don't actually use PostgreSQL anymore (my e-commerce class ended),
but I don't want the patches to get lost. I sent them to the PostgreSQL
people, but last I heard they wanted an "Alpha guru" to .... heck, I 
don't know. 

They told me this, I claimed that my patches work, explained why, and
they subscribed me to pgsql-bugs (or something -- I haven't heard anything
from that list ever). I was also asked if I had a piece of code to
demonstrate the gcc problem. I haven't written one, but I might get around
to it one of these months as a diversion away from my regular work 
(currently, MVS prelinker goo).

>How-To-Repeat:
Try and get PostgreSQL running on NetBSD/Alpha. Notice that gcc
boogers up inlining of a function defined in a header with assembly
in an __asm__ block that uses two registers. The two registers used
(%0 and %1, which expand into whatever at the inline point) are
scheduled for other variables, and so something gets stomped. Blamo,
core dump. 

Oh, and notice that I also fix things so that slock_t is 32 bits in size
on the Alpha.

Sorry, I don't remember exactly which release of PostgreSQL this patch
set is for. It shouldn't matter much, really.

>Fix:
Apply these patches.


*** ./old/src/backend/main/main.c	Wed Jan 26 00:56:30 2000
--- ./new/src/backend/main/main.c	Fri Apr  7 22:19:30 2000
***************
*** 12,27 ****
--- 12,31 ----
   *
   *-------------------------------------------------------------------------
   */
  #include <unistd.h>
  
+ #if defined(__NetBSD__)
+ #include <sys/param.h>
+ #else
  #if defined(__alpha__) && !defined(linux)
  #include <sys/sysinfo.h>
  #include "machine/hal_sysinfo.h"
  #define ASSEMBLER
  #include <sys/proc.h>
  #undef ASSEMBLER
+ #endif
  #endif
  
  #include "postgres.h"
  #ifdef USE_LOCALE
  #include <locale.h>
*** ./old/src/include/port/netbsd.h	Tue Mar  7 20:58:23 2000
--- ./new/src/include/port/netbsd.h	Sun Apr  9 23:49:37 2000
***************
*** 1,43 ****
  #define USE_POSIX_TIME
  
  #if defined(__i386__)
  #define NEED_I386_TAS_ASM
  #define HAS_TEST_AND_SET
  #endif
  
  #if defined(__sparc__)
  #define NEED_SPARC_TAS_ASM
  #define HAS_TEST_AND_SET
  #endif
  
  #if defined(__vax__)
  #define NEED_VAX_TAS_ASM
  #define HAS_TEST_AND_SET
  #endif
  
  #if defined(__ns32k__)
  #define NEED_NS32K_TAS_ASM
  #define HAS_TEST_AND_SET
  #endif
  
  #if defined(__m68k__)
  #define HAS_TEST_AND_SET
  #endif
  
  #if defined(__arm__)
  #define HAS_TEST_AND_SET
  #endif
  
  #if defined(__mips__)
  /* #	undef HAS_TEST_AND_SET */
  #endif
  
! #if defined(__powerpc__)
  #define HAS_TEST_AND_SET
  #endif
  
  #if defined(__powerpc__)
  typedef unsigned int slock_t;
- #else
- typedef unsigned char slock_t;
  #endif
--- 1,50 ----
  #define USE_POSIX_TIME
  
  #if defined(__i386__)
  #define NEED_I386_TAS_ASM
  #define HAS_TEST_AND_SET
+ typedef unsigned char slock_t;
  #endif
  
  #if defined(__sparc__)
  #define NEED_SPARC_TAS_ASM
  #define HAS_TEST_AND_SET
+ typedef unsigned char slock_t;
  #endif
  
  #if defined(__vax__)
  #define NEED_VAX_TAS_ASM
  #define HAS_TEST_AND_SET
+ typedef unsigned char slock_t;
  #endif
  
  #if defined(__ns32k__)
  #define NEED_NS32K_TAS_ASM
  #define HAS_TEST_AND_SET
+ typedef unsigned char slock_t;
  #endif
  
  #if defined(__m68k__)
  #define HAS_TEST_AND_SET
+ typedef unsigned char slock_t;
  #endif
  
  #if defined(__arm__)
  #define HAS_TEST_AND_SET
+ typedef unsigned char slock_t;
  #endif
  
  #if defined(__mips__)
  /* #	undef HAS_TEST_AND_SET */
+ typedef unsigned char slock_t;
  #endif
  
! #if defined(__alpha__)
  #define HAS_TEST_AND_SET
+ typedef unsigned long int slock_t;
  #endif
  
  #if defined(__powerpc__)
+ #define HAS_TEST_AND_SET
  typedef unsigned int slock_t;
  #endif
*** ./old/src/include/storage/s_lock.h	Wed Jan 26 00:58:33 2000
--- ./new/src/include/storage/s_lock.h	Sun Apr  9 23:56:46 2000
***************
*** 260,270 ****
--- 260,275 ----
  #else /* i.e. not __osf__ */
  
  #define TAS(lock) tas(lock)
  #define S_UNLOCK(lock) { __asm__("mb"); *(lock) = 0; }
  
+ #if defined(__GNUC__)
+ static int              /* GCC on the Alpha doesn't appear to handle
+                            inlining of assembly with %0 or %1 properly. */
+ #else
  static __inline__ int
+ #endif
  tas(volatile slock_t *lock)
  {
   register slock_t _res;
  
  __asm__("	 ldq   $0, %0			   \n\
>Release-Note:
>Audit-Trail:
>Unformatted: