From: Tonu Naks <n...@adacore.com>

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 <ebotca...@adacore.com>

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/Makefile.rtl               |  1 +
 gcc/ada/gcc-interface/Make-lang.in |  5 ++-
 gcc/ada/libgnat/s-crtl.adb         | 60 +++++++++++++++++++++++++++++
 gcc/ada/libgnat/s-crtl.ads         |  6 ++-
 gcc/ada/libgnat/s-crtl__mingw.adb  | 62 ++++++++++++++++++++++++++++++
 5 files changed, 130 insertions(+), 4 deletions(-)
 create mode 100644 gcc/ada/libgnat/s-crtl.adb
 create mode 100644 gcc/ada/libgnat/s-crtl__mingw.adb

diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/Makefile.rtl
index 50e683aa80a..9d8c2f1aeae 100644
--- a/gcc/ada/Makefile.rtl
+++ b/gcc/ada/Makefile.rtl
@@ -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 \
diff --git a/gcc/ada/gcc-interface/Make-lang.in 
b/gcc/ada/gcc-interface/Make-lang.in
index bbbd697eb6f..e768ef60ddf 100644
--- a/gcc/ada/gcc-interface/Make-lang.in
+++ b/gcc/ada/gcc-interface/Make-lang.in
@@ -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
index 00000000000..89818487fd8
--- /dev/null
+++ b/gcc/ada/libgnat/s-crtl.adb
@@ -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;
diff --git a/gcc/ada/libgnat/s-crtl.ads b/gcc/ada/libgnat/s-crtl.ads
index 42b31440683..196b0109ab5 100644
--- a/gcc/ada/libgnat/s-crtl.ads
+++ b/gcc/ada/libgnat/s-crtl.ads
@@ -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
index 00000000000..6b103597451
--- /dev/null
+++ b/gcc/ada/libgnat/s-crtl__mingw.adb
@@ -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;
-- 
2.43.0

Reply via email to