comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Ada  "library only" compiler ?
Date: Sat, 21 Jul 2012 00:51:47 +0200
Date: 2012-07-21T00:51:47+02:00	[thread overview]
Message-ID: <87mx2ucags.fsf@ludovic-brenta.org> (raw)
In-Reply-To: xO-dndcH8ZJTR5TNRVn_vwA@giganews.com

Peter C. Chapin writes on comp.lang.ada:
> On 2012-07-20 17:11, Niklas Holsti wrote:
>
>> GNAT runs on operating systems (Windows, Linux, etc.) in which the
>> Application Programming Interface is defined in C. In order to open a
>> file under Linux, the application (here GNAT) *must* use the open()
>> or fopen() functions, which are defined in the API as C
>> functions. Trying to open a file using "low-level Ada" would be
>> breaking the OS interface which is obviously a bad idea (and probably
>> impossible because an application does not have the necessary
>> low-level access rights for that).
>
> I don't think this is quite right. Entrance into the operating system
> is ultimately done in machine language. The C API functions you're
> talking about are thin wrappers that present a C callable interface
> and then do what must be done to actually invoke the system. For some
> systems "doing what must be done" involves executing exotic
> instructions that (standard) C compilers can't generate. Thus one
> supposes that functions like open(), etc, are written in assembly
> language or its moral equivalent.

Just two days ago I spent some time browsing the sources of glibc to
discover how the stat(2) C library call translates to a _stat64 kernel
call then converts the 64-bit result back to 32-bit, explicitly detects
overflows, sets ERRNO and returns a status code (0=success, -1=error).
This alone involves several dozen lines of C, interspersed with dozens
of #define, #ifdef and #endif.  glibc must work at least with Linux,
kFreeBSD and HURD.  This increases its complexity and would likewise
increase the complexity of a raw Ada-to-kernel interface.

Add to this that glibc has maintained strict binary compatibility since
January 1997, resorting to more magic ("symbol versioning") that most
anyone would care to learn about.  Achieving the same thing in Ada would
require a careful definition of "semantic dependence" such that
recompiling the kernel-interface library does not systematically
invalidate all compilation units that depend on it, per ARM 10.1.4(5).
IOW, magic at the source level in addition to the binary level.

So the conclusion is: while it is theoretically possible to write an Ada
run-time library that interfaces directly with the kernel, it is
practically undesirable.  The huge effort required would bring almost no
benefit and should be spent elsewhere.

For the same reason, Florist (the free implementation of POSIX.3) uses C
wrappers and the C library.

-- 
Ludovic Brenta.



  reply	other threads:[~2012-07-26 14:30 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-20 20:05 Ada "library only" compiler ? Patrick
2012-07-20 21:11 ` Niklas Holsti
2012-07-20 21:47   ` Ludovic Brenta
2012-07-20 22:25   ` Peter C. Chapin
2012-07-20 22:51     ` Ludovic Brenta [this message]
2012-07-21  0:32       ` Randy Brukardt
2012-07-21 12:39         ` Pascal Obry
2012-07-22  4:59           ` Shark8
2012-07-22  7:04             ` Pascal Obry
2012-07-22 10:17           ` Florian Weimer
2012-07-24  1:54           ` Randy Brukardt
2012-07-24 16:50             ` Pascal Obry
2012-07-24 18:01               ` Vasiliy Molostov
2012-07-24 21:30                 ` Pascal Obry
2012-07-25  6:33                   ` Vasiliy Molostov
2012-07-25 23:44                   ` sbelmont700
2012-07-25 23:34               ` Randy Brukardt
2012-07-21 11:05     ` Niklas Holsti
2012-07-20 23:30   ` Patrick
2012-07-21 16:47     ` Niklas Holsti
2012-07-21 17:47       ` Patrick
2012-07-21 19:22         ` Simon Wright
2012-07-21 19:38           ` Patrick
2012-07-21 22:53         ` Brian Drummond
2012-07-22  3:25           ` Patrick
2012-07-22 17:54             ` Brian Drummond
2012-07-22 17:59               ` Brian Drummond
2012-07-22 18:44                 ` Patrick
2012-07-22 21:03                   ` Brian Drummond
2012-07-25 19:10                   ` J-P. Rosen
     [not found]               ` <m2a9yrsbf5.fsf@nidhoggr.home>
     [not found]                 ` <jui36a$hs0$1@dont-email.me>
2012-07-23 10:10                   ` Simon Wright
2012-07-24 10:55                     ` Brian Drummond
2012-07-22 21:25             ` Niklas Holsti
2012-07-22 22:00               ` Patrick
2012-07-22 21:18         ` Niklas Holsti
2012-07-21  0:27   ` Randy Brukardt
2012-07-21  7:36     ` Dmitry A. Kazakov
2012-07-21 13:31     ` Niklas Holsti
     [not found]   ` <olpj085ii9fpifpligh6jerghoaieiim1d@invalid.netcom.com>
2012-07-20 23:38     ` Patrick
2012-07-21 13:12     ` Niklas Holsti
2012-07-23  5:02 ` Miles Bader
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox