]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Platform-specific import for read() and write()
authorTonu Naks <naks@adacore.com>
Tue, 5 Aug 2025 11:35:02 +0000 (11:35 +0000)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 9 Sep 2025 12:40:00 +0000 (14:40 +0200)
read() and write() return int on windows, whereas
on Posix systems the return type is ssize_t (effectively long_int).

The object file was added to GNAT_ADA_OBJS only, although the unit is also
in the compilation closure of GNATbind, but this was harmless because the
object file was essentially empty; that is no longer the case.

gcc/ada/ChangeLog:

* libgnat/s-crtl.ads (read, write): remove import
* libgnat/s-crtl__mingw.adb: body for windows
* libgnat/s-crtl.adb: body for all the other targets
* Makefile.rtl: configure s-crtl.adb/libgnat/s-crtl__mingw.adb
* gcc-interface/Make-lang.in (GNAT_ADA_OBJS): Alphabetize.
(GNATBIND_OBJS): Add ada/libgnat/s-crtl.o.

Co-authored-by: Eric Botcazou <ebotcazou@adacore.com>
gcc/ada/Makefile.rtl
gcc/ada/gcc-interface/Make-lang.in
gcc/ada/libgnat/s-crtl.adb [new file with mode: 0644]
gcc/ada/libgnat/s-crtl.ads
gcc/ada/libgnat/s-crtl__mingw.adb [new file with mode: 0644]

index 50e683aa80a78d9ed744d060d2eea489328419c0..9d8c2f1aeae482ce63e6b331ac3942e989410d13 100644 (file)
@@ -2261,6 +2261,7 @@ ifeq ($(strip $(filter-out cygwin% mingw32% pe,$(target_os))),)
   endif
   LIBGNAT_TARGET_PAIRS += \
   a-dirval.adb<libgnat/a-dirval__mingw.adb \
+  s-crtl.adb<libgnat/s-crtl__mingw.adb \
   s-gloloc.adb<libgnat/s-gloloc__mingw.adb \
   s-inmaop.adb<libgnarl/s-inmaop__dummy.adb \
   s-taspri.ads<libgnarl/s-taspri__mingw.ads \
index bbbd697eb6f411141c26afd8226c8caf480b5492..e768ef60ddf7930a79b1615a6afccf7b89f6683d 100644 (file)
@@ -532,7 +532,6 @@ GNAT_ADA_OBJS+= \
  ada/libgnat/s-carun8.o        \
  ada/libgnat/s-casuti.o \
  ada/libgnat/s-cautns.o \
- ada/libgnat/s-crtl.o  \
  ada/libgnat/s-conca2.o        \
  ada/libgnat/s-conca3.o        \
  ada/libgnat/s-conca4.o        \
@@ -542,6 +541,7 @@ GNAT_ADA_OBJS+= \
  ada/libgnat/s-conca8.o        \
  ada/libgnat/s-conca9.o        \
  ada/libgnat/s-crc32.o \
+ ada/libgnat/s-crtl.o  \
  ada/libgnat/s-excdeb.o        \
  ada/libgnat/s-except.o        \
  ada/libgnat/s-excmac.o        \
@@ -690,7 +690,7 @@ GNATBIND_OBJS +=  \
  ada/libgnat/g-cstyin.o   \
  ada/libgnat/g-hesora.o   \
  ada/libgnat/g-htable.o   \
- ada/libgnat/i-c.o           \
+ ada/libgnat/i-c.o        \
  ada/libgnat/i-cstrin.o   \
  ada/libgnat/interfac.o   \
  ada/libgnat/s-addope.o   \
@@ -707,6 +707,7 @@ GNATBIND_OBJS +=  \
  ada/libgnat/s-conca8.o   \
  ada/libgnat/s-conca9.o   \
  ada/libgnat/s-crc32.o    \
+ ada/libgnat/s-crtl.o     \
  ada/libgnat/s-excdeb.o   \
  ada/libgnat/s-except.o   \
  ada/libgnat/s-excmac.o   \
diff --git a/gcc/ada/libgnat/s-crtl.adb b/gcc/ada/libgnat/s-crtl.adb
new file mode 100644 (file)
index 0000000..8981848
--- /dev/null
@@ -0,0 +1,60 @@
+------------------------------------------------------------------------------
+--                                                                          --
+--                        GNAT RUN-TIME COMPONENTS                          --
+--                                                                          --
+--                          S Y S T E M . C R T L                           --
+--                                                                          --
+--                                 S p e c                                  --
+--                                                                          --
+--          Copyright (C) 2003-2025, Free Software Foundation, Inc.         --
+--                                                                          --
+-- GNAT is free software;  you can  redistribute it  and/or modify it under --
+-- terms of the  GNU General Public License as published  by the Free Soft- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
+-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
+--                                                                          --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.               --
+--                                                                          --
+-- You should have received a copy of the GNU General Public License and    --
+-- a copy of the GCC Runtime Library Exception along with this program;     --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
+-- <http://www.gnu.org/licenses/>.                                          --
+--                                                                          --
+-- GNAT was originally developed  by the GNAT team at  New York University. --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
+--                                                                          --
+------------------------------------------------------------------------------
+
+package body System.CRTL is
+
+   ----------
+   -- read --
+   ----------
+
+   function read (fd : int; buffer : chars; count : size_t) return ssize_t
+   is
+      function read_raw
+        (fd : int; buffer : chars; count : size_t) return ssize_t;
+      pragma Import (C, read_raw, "read");
+   begin
+      return read_raw (fd, buffer, count);
+   end read;
+
+   -----------
+   -- write --
+   -----------
+
+   function write (fd : int; buffer : chars; count : size_t) return ssize_t
+   is
+      function write_raw
+        (fd : int; buffer : chars; count : size_t) return ssize_t;
+      pragma Import (C, write_raw, "write");
+   begin
+      return write_raw (fd, buffer, count);
+   end write;
+
+end System.CRTL;
index 42b31440683d742a9befbb72105addefb545df53..196b0109ab558a20b194f2e6c1eed5203c74e53d 100644 (file)
@@ -231,9 +231,11 @@ package System.CRTL is
    pragma Import (C, close, "close");
 
    function read (fd : int; buffer : chars; count : size_t) return ssize_t;
-   pragma Import (C, read, "read");
+   pragma Inline (read);
+   --  Different return types on Windows and Posix, requires body
 
    function write (fd : int; buffer : chars; count : size_t) return ssize_t;
-   pragma Import (C, write, "write");
+   pragma Inline (write);
+   --  Different return types on Windows and Posix, requires body
 
 end System.CRTL;
diff --git a/gcc/ada/libgnat/s-crtl__mingw.adb b/gcc/ada/libgnat/s-crtl__mingw.adb
new file mode 100644 (file)
index 0000000..6b10359
--- /dev/null
@@ -0,0 +1,62 @@
+------------------------------------------------------------------------------
+--                                                                          --
+--                        GNAT RUN-TIME COMPONENTS                          --
+--                                                                          --
+--                          S Y S T E M . C R T L                           --
+--                                                                          --
+--                                 S p e c                                  --
+--                                                                          --
+--          Copyright (C) 2003-2025, Free Software Foundation, Inc.         --
+--                                                                          --
+-- GNAT is free software;  you can  redistribute it  and/or modify it under --
+-- terms of the  GNU General Public License as published  by the Free Soft- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
+-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
+--                                                                          --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.               --
+--                                                                          --
+-- You should have received a copy of the GNU General Public License and    --
+-- a copy of the GCC Runtime Library Exception along with this program;     --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
+-- <http://www.gnu.org/licenses/>.                                          --
+--                                                                          --
+-- GNAT was originally developed  by the GNAT team at  New York University. --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
+--                                                                          --
+------------------------------------------------------------------------------
+
+--  This is the Windows specific version of the System.CRTL
+
+package body System.CRTL is
+
+   ----------
+   -- read --
+   ----------
+
+   function read (fd : int; buffer : chars; count : size_t) return ssize_t
+   is
+      function read_raw
+        (fd : int; buffer : chars; count : size_t) return int;
+      pragma Import (C, read_raw, "read");
+   begin
+      return ssize_t (read_raw (fd, buffer, count));
+   end read;
+
+   -----------
+   -- write --
+   -----------
+
+   function write (fd : int; buffer : chars; count : size_t) return ssize_t
+   is
+      function write_raw
+        (fd : int; buffer : chars; count : size_t) return int;
+      pragma Import (C, write_raw, "write");
+   begin
+      return ssize_t (write_raw (fd, buffer, count));
+   end write;
+
+end System.CRTL;