[COMMITTED] ada: Decouple size of addresses and pointers from size of memory space
Checks
Commit Message
From: Eric Botcazou <ebotcazou@adacore.com>
This decouples the size of the types representing addresses and pointers,
which is Standard'Address_Size, from the size of the memory space, which
is System.Memory_Size (more precisely log2 of it). They are tied through
the definition of System.Address:
type Address is mod Memory_Size;
so Standard'Address_Size >= log2 (System.Memory_Size) necessarily, but the
equality does not hold on platforms where addresses and pointers contain
additional bits of metadata.
gcc/ada/
* libgnat/a-ststio.adb (Set_Mode): Test System.Memory_Size.
* libgnat/g-debuti.ads (Address_64): Likewise.
* libgnat/i-c.ads: Add with clause for System.
(ptrdiff_t): Define based on the size of memory space.
(size_t): Likewise.
* libgnat/s-crtl.ads (size_t): Likewise.
(ssize_t): Likewise.
* libgnat/s-memory.ads (size_t): Likewise.
* libgnat/s-parame.ads (Size_Type): Likewise.
* libgnat/s-parame__hpux.ads (Size_Type): Likewise.
* libgnat/s-parame__posix2008.ads (Size_Type): Likewise.
* libgnat/s-parame__vxworks.ads (Size_Type): Likewise.
* libgnat/s-putima.adb (Signed_Address): Likewise.
(Unsigned_Address): Likewise.
* libgnat/s-stoele.ads (Storage_Offset): Likewise.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/libgnat/a-ststio.adb | 4 +++-
gcc/ada/libgnat/g-debuti.ads | 4 ++--
gcc/ada/libgnat/i-c.ads | 6 +++---
gcc/ada/libgnat/s-crtl.ads | 5 ++---
gcc/ada/libgnat/s-memory.ads | 2 +-
gcc/ada/libgnat/s-parame.ads | 4 +---
gcc/ada/libgnat/s-parame__hpux.ads | 4 +---
gcc/ada/libgnat/s-parame__posix2008.ads | 4 +---
gcc/ada/libgnat/s-parame__vxworks.ads | 4 +---
gcc/ada/libgnat/s-putima.adb | 5 ++---
gcc/ada/libgnat/s-stoele.ads | 7 +------
11 files changed, 18 insertions(+), 31 deletions(-)
@@ -367,11 +367,13 @@ package body Ada.Streams.Stream_IO is
FIO.Append_Set (AP (File));
if File.Mode = FCB.Append_File then
- if Standard'Address_Size = 64 then
+ pragma Warnings (Off, "condition is always *");
+ if Memory_Size = 2**64 then
File.Index := Count (ftell64 (File.Stream)) + 1;
else
File.Index := Count (ftell (File.Stream)) + 1;
end if;
+ pragma Warnings (On);
end if;
File.Last_Op := Op_Other;
@@ -39,8 +39,8 @@ with System;
package GNAT.Debug_Utilities is
pragma Pure;
- Address_64 : constant Boolean := Standard'Address_Size = 64;
- -- Set true if 64 bit addresses (assumes only 32 and 64 are possible)
+ Address_64 : constant Boolean := System.Memory_Size = 2**64;
+ -- Set true if 64-bit addresses (assumes only 32 and 64 are possible)
Address_Image_Length : constant := 13 + 10 * Boolean'Pos (Address_64);
-- Length of string returned by Image function for an address
@@ -24,6 +24,7 @@ pragma Assertion_Policy (Pre => Ignore,
Contract_Cases => Ignore,
Ghost => Ignore);
+with System;
with System.Parameters;
package Interfaces.C
@@ -82,10 +83,9 @@ is
-- a non-private system.address type.
type ptrdiff_t is
- range -(2 ** (System.Parameters.ptr_bits - Integer'(1))) ..
- +(2 ** (System.Parameters.ptr_bits - Integer'(1)) - 1);
+ range -System.Memory_Size / 2 .. System.Memory_Size / 2 - 1;
- type size_t is mod 2 ** System.Parameters.ptr_bits;
+ type size_t is mod System.Memory_Size;
-- Boolean type
@@ -55,10 +55,9 @@ package System.CRTL is
subtype off_t is Long_Integer;
- type size_t is mod 2 ** Standard'Address_Size;
+ type size_t is mod System.Memory_Size;
- type ssize_t is range -(2 ** (Standard'Address_Size - 1))
- .. +(2 ** (Standard'Address_Size - 1)) - 1;
+ type ssize_t is range -Memory_Size / 2 .. Memory_Size / 2 - 1;
type int64 is new Long_Long_Integer;
-- Note: we use Long_Long_Integer'First instead of -2 ** 63 to allow this
@@ -43,7 +43,7 @@
package System.Memory is
pragma Elaborate_Body;
- type size_t is mod 2 ** Standard'Address_Size;
+ type size_t is mod Memory_Size;
-- Note: the reason we redefine this here instead of using the
-- definition in Interfaces.C is that we do not want to drag in
-- all of Interfaces.C just because System.Memory is used.
@@ -53,9 +53,7 @@ package System.Parameters is
-- Task And Stack Allocation Control --
---------------------------------------
- type Size_Type is range
- -(2 ** (Integer'(Standard'Address_Size) - 1)) ..
- +(2 ** (Integer'(Standard'Address_Size) - 1)) - 1;
+ type Size_Type is range -Memory_Size / 2 .. Memory_Size / 2 - 1;
-- Type used to provide task stack sizes to the runtime. Sized to permit
-- stack sizes of up to half the total addressable memory space. This may
-- seem excessively large (even for 32-bit systems), however there are many
@@ -53,9 +53,7 @@ package System.Parameters is
-- Task And Stack Allocation Control --
---------------------------------------
- type Size_Type is range
- -(2 ** (Integer'(Standard'Address_Size) - 1)) ..
- +(2 ** (Integer'(Standard'Address_Size) - 1)) - 1;
+ type Size_Type is range -Memory_Size / 2 .. Memory_Size / 2 - 1;
-- Type used to provide task stack sizes to the runtime. Sized to permit
-- stack sizes of up to half the total addressable memory space. This may
-- seem excessively large (even for 32-bit systems), however there are many
@@ -53,9 +53,7 @@ package System.Parameters is
-- Task And Stack Allocation Control --
---------------------------------------
- type Size_Type is range
- -(2 ** (Integer'(Standard'Address_Size) - 1)) ..
- +(2 ** (Integer'(Standard'Address_Size) - 1)) - 1;
+ type Size_Type is range -Memory_Size / 2 .. Memory_Size / 2 - 1;
-- Type used to provide task stack sizes to the runtime. Sized to permit
-- stack sizes of up to half the total addressable memory space. This may
-- seem excessively large (even for 32-bit systems), however there are many
@@ -53,9 +53,7 @@ package System.Parameters is
-- Task And Stack Allocation Control --
---------------------------------------
- type Size_Type is range
- -(2 ** (Integer'(Standard'Address_Size) - 1)) ..
- +(2 ** (Integer'(Standard'Address_Size) - 1)) - 1;
+ type Size_Type is range -Memory_Size / 2 .. Memory_Size / 2 - 1;
-- Type used to provide task stack sizes to the runtime. Sized to permit
-- stack sizes of up to half the total addressable memory space. This may
-- seem excessively large (even for 32-bit systems), however there are many
@@ -118,9 +118,8 @@ package body System.Put_Images is
(S : in out Sink'Class; X : Long_Long_Long_Unsigned)
renames LLL_Integer_Images.Put_Image;
- type Signed_Address is range
- -2**(Standard'Address_Size - 1) .. 2**(Standard'Address_Size - 1) - 1;
- type Unsigned_Address is mod 2**Standard'Address_Size;
+ type Signed_Address is range -Memory_Size / 2 .. Memory_Size / 2 - 1;
+ type Unsigned_Address is mod Memory_Size;
package Hex is new Generic_Integer_Images
(Signed_Address, Unsigned_Address, Base => 16);
@@ -45,12 +45,7 @@ package System.Storage_Elements is
pragma Annotate (GNATprove, Always_Return, Storage_Elements);
- type Storage_Offset is range
- -(2 ** (Integer'(Standard'Address_Size) - 1)) ..
- +(2 ** (Integer'(Standard'Address_Size) - 1)) - Long_Long_Integer'(1);
- -- Note: the reason for the Long_Long_Integer qualification here is to
- -- avoid a bogus ambiguity when this unit is analyzed in an rtsfind
- -- context.
+ type Storage_Offset is range -Memory_Size / 2 .. Memory_Size / 2 - 1;
subtype Storage_Count is Storage_Offset range 0 .. Storage_Offset'Last;