From 79d306c84abbe1b55ac70b966d35feb09dedf6a8 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 29 Oct 2008 16:06:47 +0000 Subject: Support for Sun Studio compiler on Linux This basically takes some build system code that was previously labeled "Solaris" and ties it to the compiler rather than the operating system. Author: Julius Stroffek --- src/Makefile.global.in | 3 +- src/backend/port/Makefile | 6 ++-- src/backend/port/tas/solaris_sparc.s | 42 ---------------------------- src/backend/port/tas/solaris_x86.s | 34 ----------------------- src/backend/port/tas/sunstudio_sparc.s | 51 ++++++++++++++++++++++++++++++++++ src/backend/port/tas/sunstudio_x86.s | 43 ++++++++++++++++++++++++++++ src/include/storage/s_lock.h | 6 ++-- src/template/linux | 25 ++++++++++++++++- src/template/solaris | 16 +++++------ 9 files changed, 134 insertions(+), 92 deletions(-) delete mode 100644 src/backend/port/tas/solaris_sparc.s delete mode 100644 src/backend/port/tas/solaris_x86.s create mode 100644 src/backend/port/tas/sunstudio_sparc.s create mode 100644 src/backend/port/tas/sunstudio_x86.s (limited to 'src') diff --git a/src/Makefile.global.in b/src/Makefile.global.in index f5ca618400a..a562cd116dd 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -1,5 +1,5 @@ # -*-makefile-*- -# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.244 2008/10/03 15:35:17 petere Exp $ +# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.245 2008/10/29 16:06:46 petere Exp $ #------------------------------------------------------------------------------ # All PostgreSQL makefiles include this file and use the variables it sets, @@ -213,6 +213,7 @@ endif # not PGXS CC = @CC@ GCC = @GCC@ +SUN_STUDIO_CC = @SUN_STUDIO_CC@ CFLAGS = @CFLAGS@ # Kind-of compilers diff --git a/src/backend/port/Makefile b/src/backend/port/Makefile index 6a71ef3a2b5..47980426564 100644 --- a/src/backend/port/Makefile +++ b/src/backend/port/Makefile @@ -13,7 +13,7 @@ # be converted to Method 2. # # IDENTIFICATION -# $PostgreSQL: pgsql/src/backend/port/Makefile,v 1.26 2008/02/19 15:29:58 petere Exp $ +# $PostgreSQL: pgsql/src/backend/port/Makefile,v 1.27 2008/10/29 16:06:46 petere Exp $ # #------------------------------------------------------------------------- @@ -33,8 +33,8 @@ endif include $(top_srcdir)/src/backend/common.mk tas.o: tas.s -ifeq ($(PORTNAME), solaris) -# preprocess assembler file with cpp, used by x86 +ifeq ($(SUN_STUDIO_CC), yes) +# preprocess assembler file with cpp $(CC) $(CFLAGS) -c -P $< mv $*.i $*_cpp.s $(CC) $(CFLAGS) -c $*_cpp.s -o $@ diff --git a/src/backend/port/tas/solaris_sparc.s b/src/backend/port/tas/solaris_sparc.s deleted file mode 100644 index 183cea18504..00000000000 --- a/src/backend/port/tas/solaris_sparc.s +++ /dev/null @@ -1,42 +0,0 @@ -!======================================================================= -! solaris_sparc.s -- compare and swap for solaris_sparc -!======================================================================= - -! Fortunately the Sun compiler can process cpp conditionals with -P - -! '/' is the comment for x86, while '!' is the comment for Sparc - -#if defined(__sparcv9) || defined(__sparc) - - .section ".text" - .align 8 - .skip 24 - .align 4 - - .global pg_atomic_cas -pg_atomic_cas: - - ! "cas" only works on sparcv9 and sparcv8plus chips, and - ! requies a compiler targeting these CPUs. It will fail - ! on a compiler targeting sparcv8, and of course will not - ! be understood by a sparcv8 CPU. gcc continues to use - ! "ldstub" because it targets sparcv7. - ! - ! There is actually a trick for embedding "cas" in a - ! sparcv8-targeted compiler, but it can only be run - ! on a sparcv8plus/v9 cpus: - ! - ! http://cvs.opensolaris.org/source/xref/on/usr/src/lib/libc/sparc/threads/sparc.il - ! - -#if defined(__sparcv9) || defined(__sparcv8plus) - cas [%o0],%o2,%o1 -#else - ldstub [%o0],%o1 -#endif - mov %o1,%o0 - retl - nop - .type pg_atomic_cas,2 - .size pg_atomic_cas,(.-pg_atomic_cas) -#endif diff --git a/src/backend/port/tas/solaris_x86.s b/src/backend/port/tas/solaris_x86.s deleted file mode 100644 index db1dea7c291..00000000000 --- a/src/backend/port/tas/solaris_x86.s +++ /dev/null @@ -1,34 +0,0 @@ -/======================================================================= -/ solaris_i386.s -- compare and swap for solaris_i386 -/======================================================================= - -/ Fortunately the Sun compiler can process cpp conditionals with -P - -/ '/' is the comment for x86, while '!' is the comment for Sparc - - .file "tas.s" - -#if defined(__amd64) - .code64 -#endif - - .globl pg_atomic_cas - .type pg_atomic_cas, @function - - .section .text, "ax" - .align 16 - -pg_atomic_cas: -#if defined(__amd64) - movl %edx,%eax - lock - cmpxchgl %esi,(%rdi) -#else - movl 4(%esp), %edx - movl 8(%esp), %ecx - movl 12(%esp), %eax - lock - cmpxchgl %ecx, (%edx) -#endif - ret - .size pg_atomic_cas, . - pg_atomic_cas diff --git a/src/backend/port/tas/sunstudio_sparc.s b/src/backend/port/tas/sunstudio_sparc.s new file mode 100644 index 00000000000..56d85f4514f --- /dev/null +++ b/src/backend/port/tas/sunstudio_sparc.s @@ -0,0 +1,51 @@ +!------------------------------------------------------------------------- +! +! sunstudio_sparc.s +! compare and swap for Sun Studio on Sparc +! +! Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group +! Portions Copyright (c) 1994, Regents of the University of California +! +! IDENTIFICATION +! $PostgreSQL: pgsql/src/backend/port/tas/sunstudio_sparc.s,v 1.1 2008/10/29 16:06:47 petere Exp $ +! +!------------------------------------------------------------------------- + +! Fortunately the Sun compiler can process cpp conditionals with -P + +! '/' is the comment for x86, while '!' is the comment for Sparc + +#if defined(__sparcv9) || defined(__sparc) + + .section ".text" + .align 8 + .skip 24 + .align 4 + + .global pg_atomic_cas +pg_atomic_cas: + + ! "cas" only works on sparcv9 and sparcv8plus chips, and + ! requies a compiler targeting these CPUs. It will fail + ! on a compiler targeting sparcv8, and of course will not + ! be understood by a sparcv8 CPU. gcc continues to use + ! "ldstub" because it targets sparcv7. + ! + ! There is actually a trick for embedding "cas" in a + ! sparcv8-targeted compiler, but it can only be run + ! on a sparcv8plus/v9 cpus: + ! + ! http://cvs.opensolaris.org/source/xref/on/usr/src/lib/libc/sparc/threads/sparc.il + ! + +#if defined(__sparcv9) || defined(__sparcv8plus) + cas [%o0],%o2,%o1 +#else + ldstub [%o0],%o1 +#endif + mov %o1,%o0 + retl + nop + .type pg_atomic_cas,2 + .size pg_atomic_cas,(.-pg_atomic_cas) +#endif diff --git a/src/backend/port/tas/sunstudio_x86.s b/src/backend/port/tas/sunstudio_x86.s new file mode 100644 index 00000000000..1680ccc6358 --- /dev/null +++ b/src/backend/port/tas/sunstudio_x86.s @@ -0,0 +1,43 @@ +/------------------------------------------------------------------------- +/ +/ sunstudio_x86.s +/ compare and swap for Sun Studio on x86 +/ +/ Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group +/ Portions Copyright (c) 1994, Regents of the University of California +/ +/ IDENTIFICATION +/ $PostgreSQL: pgsql/src/backend/port/tas/sunstudio_x86.s,v 1.1 2008/10/29 16:06:47 petere Exp $ +/ +/------------------------------------------------------------------------- + +/ Fortunately the Sun compiler can process cpp conditionals with -P + +/ '/' is the comment for x86, while '!' is the comment for Sparc + + .file "tas.s" + +#if defined(__amd64) + .code64 +#endif + + .globl pg_atomic_cas + .type pg_atomic_cas, @function + + .section .text, "ax" + .align 16 + +pg_atomic_cas: +#if defined(__amd64) + movl %edx,%eax + lock + cmpxchgl %esi,(%rdi) +#else + movl 4(%esp), %edx + movl 8(%esp), %ecx + movl 12(%esp), %eax + lock + cmpxchgl %ecx, (%edx) +#endif + ret + .size pg_atomic_cas, . - pg_atomic_cas diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h index 7d9448fb7e4..e67b0ab3185 100644 --- a/src/include/storage/s_lock.h +++ b/src/include/storage/s_lock.h @@ -66,7 +66,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/storage/s_lock.h,v 1.164 2008/01/01 19:45:59 momjian Exp $ + * $PostgreSQL: pgsql/src/include/storage/s_lock.h,v 1.165 2008/10/29 16:06:47 petere Exp $ * *------------------------------------------------------------------------- */ @@ -578,7 +578,7 @@ typedef unsigned char slock_t; #endif -#endif /* __GNUC__ */ +#endif /* defined(__GNUC__) || defined(__INTEL_COMPILER) */ @@ -782,7 +782,7 @@ typedef unsigned char slock_t; #endif -#if defined(__sun) && (defined(__i386) || defined(__x86_64__) || defined(__sparc__) || defined(__sparc)) +#if defined(__SUNPRO_C) && (defined(__i386) || defined(__x86_64__) || defined(__sparc__) || defined(__sparc)) #define HAS_TEST_AND_SET #if defined(__i386) || defined(__x86_64__) || defined(__sparcv9) || defined(__sparcv8plus) diff --git a/src/template/linux b/src/template/linux index ed800d23f12..19904bc22e1 100644 --- a/src/template/linux +++ b/src/template/linux @@ -1,7 +1,30 @@ -# $PostgreSQL: pgsql/src/template/linux,v 1.30 2007/09/21 02:33:46 tgl Exp $ +# $PostgreSQL: pgsql/src/template/linux,v 1.31 2008/10/29 16:06:47 petere Exp $ # Force _GNU_SOURCE on; plperl is broken with Perl 5.8.0 otherwise CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE" # If --enable-profiling is specified, we need -DLINUX_PROFILE PLATFORM_PROFILE_FLAGS="-DLINUX_PROFILE" + +if test "$SUN_STUDIO_CC" = "yes" ; then + CC="$CC -Xa" # relaxed ISO C mode + CFLAGS="-v" # -v is like gcc -Wall + if test "$enable_debug" != yes; then + CFLAGS="$CFLAGS -O" # any optimization breaks debug + fi + + # Pick the right test-and-set (TAS) code for the Sun compiler. + # We would like to use in-line assembler, but the compiler + # requires *.il files to be on every compile line, making + # the build system too fragile. + case $host_cpu in + sparc) + need_tas=yes + tas_file=sunstudio_sparc.s + ;; + i?86|x86_64) + need_tas=yes + tas_file=sunstudio_x86.s + ;; + esac +fi diff --git a/src/template/solaris b/src/template/solaris index 07efcc0bda4..40e3a68c88e 100644 --- a/src/template/solaris +++ b/src/template/solaris @@ -1,22 +1,22 @@ -if test "$GCC" != yes ; then +if test "$SUN_STUDIO_CC" = yes ; then CC="$CC -Xa" # relaxed ISO C mode - CFLAGS="-v -DSUNOS4_CC" # -v is like gcc -Wall + CFLAGS="-v" # -v is like gcc -Wall if test "$enable_debug" != yes; then CFLAGS="$CFLAGS -O" # any optimization breaks debug fi # Pick the right test-and-set (TAS) code for the Sun compiler. # We would like to use in-line assembler, but the compiler - # requires *.il files to be on every compile line, making + # requires *.il files to be on every compile line, making # the build system too fragile. - case $host in - sparc-*-solaris*) + case $host_cpu in + sparc) need_tas=yes - tas_file=solaris_sparc.s + tas_file=sunstudio_sparc.s ;; - i?86-*-solaris*) + i?86|x86_64) need_tas=yes - tas_file=solaris_x86.s + tas_file=sunstudio_x86.s ;; esac fi -- cgit v1.2.3