This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Define _LP64 on x86-64?
Richard Henderson <rth at redhat dot com> writes:
> On Wed, Mar 12, 2003 at 08:44:54AM +0100, Andreas Jaeger wrote:
>> To get the size of the pointer I use TYPE_PRECISION (size_type_node).
>> I tried TYPE_PRECISON(ptr_type_node) but this is always zero. Is
>> size_type_node the right think to do or is there a better solution?
>
> POINTER_SIZE is exactly what you want.
Thanks.
>> + /* Definitions for LP64 model. */
>> + if (TYPE_PRECISION (long_integer_type_node) == 64
>> + && TYPE_PRECISION (size_type_node) == 64
>> + && TYPE_PRECISION (integer_type_node) == 32)
>
> I guess this is ok. I'm agnostic as to whether "int" matters
> here one way or another.
>
> You'll want to document this in cpp.texi.
Ok.
I'm appending a complete patch. Ok to commit?
Ok also for 3.3 with the change of using c-common.c instead of
c-cppbuiltin?
I'm testing now again on Linux/x86-64.
Andreas
2003-03-12 Andreas Jaeger <aj at suse dot de>
* doc/cpp.texi (Common Predefined Macros): Document __LP64__ and
_LP64.
* c-cppbuiltin.c (cb_register_builtins): Define LP64 builtins for
LP64 targets.
* config/ia64/ia64.h (TARGET_CPU_CPP_BUILTINS): Do not define
_LP64 macros here.
* config/pa/pa.h (TARGET_CPU_CPP_BUILTINS): Likewise.
* config/alpha/netbsd.h (TARGET_OS_CPP_BUILTINS): Remove call to
NETBSD_OS_CPP_BUILTINS_LP64.
* config/sh/netbsd-elf.h (TARGET_OS_CPP_BUILTINS): Likewise.
* config/sparc/netbsd-elf.h (TARGET_OS_CPP_BUILTINS): Likewise.
* config/netbsd.h (NETBSD_OS_CPP_BUILTINS_LP64): Remove.
============================================================
Index: gcc/c-cppbuiltin.c
--- gcc/c-cppbuiltin.c 12 Mar 2003 06:58:38 -0000 1.4
+++ gcc/c-cppbuiltin.c 12 Mar 2003 10:09:16 -0000
@@ -339,6 +339,15 @@ cb_register_builtins (pfile)
/* Misc. */
builtin_define_with_value ("__VERSION__", version_string, 1);
+ /* Definitions for LP64 model. */
+ if (TYPE_PRECISION (long_integer_type_node) == 64
+ && POINTER_SIZE == 64
+ && TYPE_PRECISION (integer_type_node) == 32)
+ {
+ cpp_define (pfile, "_LP64");
+ cpp_define (pfile, "__LP64__");
+ }
+
/* Other target-independent built-ins determined by command-line
options. */
if (optimize_size)
============================================================
Index: gcc/doc/cpp.texi
--- doc/cpp.texi 26 Jan 2003 20:56:09 -0000 1.53
+++ doc/cpp.texi 12 Mar 2003 10:09:16 -0000
@@ -2031,6 +2031,11 @@ This macro is defined, with value 1, if
(as in @option{-fnext-runtime}) is in use for Objective-C. If the GNU
runtime is used, this macro is not defined, so that you can use this
macro to determine which runtime (NeXT or GNU) is being used.
+
+ at item __LP64__
+ at item _LP64
+These macros are defined, with value 1, if (and only if) the compilation
+is for a target where both @code{long int} and pointer use 64-bits.
@end table
@node System-specific Predefined Macros
============================================================
Index: gcc/config/alpha/netbsd.h
--- config/alpha/netbsd.h 24 Nov 2002 23:19:19 -0000 1.18
+++ config/alpha/netbsd.h 12 Mar 2003 10:09:19 -0000
@@ -1,6 +1,6 @@
/* Definitions of target machine for GNU compiler,
for Alpha NetBSD systems.
- Copyright (C) 1998, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU CC.
@@ -25,7 +25,6 @@ Boston, MA 02111-1307, USA. */
#define TARGET_OS_CPP_BUILTINS() \
do { \
NETBSD_OS_CPP_BUILTINS_ELF(); \
- NETBSD_OS_CPP_BUILTINS_LP64(); \
} while (0)
============================================================
Index: gcc/config/netbsd.h
--- config/netbsd.h 28 Feb 2003 19:05:26 -0000 1.24
+++ config/netbsd.h 12 Mar 2003 10:09:19 -0000
@@ -29,14 +29,6 @@ Boston, MA 02111-1307, USA. */
} \
while (0)
-/* TARGET_OS_CPP_BUILTINS() common to all LP64 NetBSD targets. */
-#define NETBSD_OS_CPP_BUILTINS_LP64() \
- do \
- { \
- builtin_define ("_LP64"); \
- } \
- while (0)
-
/* CPP_SPEC parts common to all NetBSD targets. */
#define NETBSD_CPP_SPEC \
"%{posix:-D_POSIX_SOURCE} \
============================================================
Index: gcc/config/ia64/ia64.h
--- config/ia64/ia64.h 3 Mar 2003 22:10:44 -0000 1.143
+++ config/ia64/ia64.h 12 Mar 2003 10:09:19 -0000
@@ -1,5 +1,5 @@
/* Definitions of target machine GNU compiler. IA-64 version.
- Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
Contributed by James E. Wilson <wilson at cygnus dot com> and
David Mosberger <davidm at hpl dot hp dot com>.
@@ -40,11 +40,6 @@ do { \
builtin_define("__ia64__"); \
builtin_define("__itanium__"); \
builtin_define("__ELF__"); \
- if (!TARGET_ILP32) \
- { \
- builtin_define("_LP64"); \
- builtin_define("__LP64__"); \
- } \
if (TARGET_BIG_ENDIAN) \
builtin_define("__BIG_ENDIAN__"); \
} while (0)
============================================================
Index: gcc/config/pa/pa.h
--- config/pa/pa.h 4 Mar 2003 06:20:17 -0000 1.185
+++ config/pa/pa.h 12 Mar 2003 10:09:19 -0000
@@ -356,11 +356,6 @@ do { \
builtin_assert("machine=hppa"); \
builtin_define("__hppa"); \
builtin_define("__hppa__"); \
- if (TARGET_64BIT) \
- { \
- builtin_define("_LP64"); \
- builtin_define("__LP64__"); \
- } \
if (TARGET_PA_20) \
builtin_define("_PA_RISC2_0"); \
else if (TARGET_PA_11) \
============================================================
Index: gcc/config/sh/netbsd-elf.h
--- config/sh/netbsd-elf.h 11 Aug 2002 19:24:09 -0000 1.4
+++ config/sh/netbsd-elf.h 12 Mar 2003 10:09:19 -0000
@@ -1,5 +1,5 @@
/* Definitions for SH running NetBSD using ELF
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003 Free Software Foundation, Inc.
Contributed by Wasabi Systems, Inc.
This file is part of GNU CC.
@@ -52,8 +52,6 @@ Boston, MA 02111-1307, USA. */
do \
{ \
NETBSD_OS_CPP_BUILTINS_ELF(); \
- if (TARGET_SHMEDIA64) \
- NETBSD_OS_CPP_BUILTINS_LP64(); \
builtin_define ("__NO_LEADING_UNDERSCORES__"); \
} \
while (0)
============================================================
Index: gcc/config/sparc/netbsd-elf.h
--- config/sparc/netbsd-elf.h 16 Dec 2002 18:21:58 -0000 1.13
+++ config/sparc/netbsd-elf.h 12 Mar 2003 10:09:19 -0000
@@ -1,6 +1,6 @@
/* Definitions of target machine for GNU compiler, for ELF on NetBSD/sparc
and NetBSD/sparc64.
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003 Free Software Foundation, Inc.
Contributed by Matthew Green (mrg at eterna dot com dot au).
This file is part of GNU CC.
@@ -26,7 +26,6 @@ Boston, MA 02111-1307, USA. */
NETBSD_OS_CPP_BUILTINS_ELF(); \
if (TARGET_ARCH64) \
{ \
- NETBSD_OS_CPP_BUILTINS_LP64(); \
builtin_define ("__sparc64__"); \
builtin_define ("__sparc_v9__"); \
} \
--
Andreas Jaeger
SuSE Labs aj at suse dot de
private aj at arthur dot inka dot de
http://www.suse.de/~aj