From: Tonu Naks Date: Tue, 5 Aug 2025 11:35:02 +0000 (+0000) Subject: ada: Platform-specific import for read() and write() X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=360a779f07e966b4f911035266df891c20975405;p=thirdparty%2Fgcc.git ada: Platform-specific import for read() and write() 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 --- 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. -- +-- -- +-- 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 -- +-- . -- +-- -- +-- 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;