1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
[[!meta copyright="Copyright © 2011, 2012, 2013, 2016 Free Software
Foundation, Inc."]]
[[!meta license="""[[!toggle id="license" text="GFDL 1.2+"]][[!toggleable
id="license" text="Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License, Version 1.2 or
any later version published by the Free Software Foundation; with no Invariant
Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license
is included in the section entitled [[GNU Free Documentation
License|/fdl]]."]]"""]]
[[!meta title="Enable Ada programming (GCC: GNAT)"]]
[[!tag open_issue_gcc]]
Make the Ada programming language available on GNU/Hurd in its [[GCC]] GNAT
implementation, and enable Hurd-specific features.
There is a [[!FF_project 259]][[!tag bounty]] on this task.
---
# Part I
First, make the language functional, have its test suite pass without errors.
Using, for example, the build instructions from [[GCC]], you'll need to add
`ada` to `--enable-languages`.
## Original [[community/GSoC]] Task Description
[[!inline pages=community/gsoc/project_ideas/gnat feeds=no]]
## Debian GCC
There has a patch been added for GNU/kFreeBSD:
`bfe081336914729fc0180c07ab4afa41965100f2`, `git-svn-id:
svn://svn.debian.org/gcccvs/branches/sid@5638
6ca36cf4-e1d1-0310-8c6f-e303bb2178ca'
## IRC, freenode, #hurd, 2012-07-17
<gnu_srs> I've found the remaining problem with gnat backtrace for Hurd!
Related to the stack frame.
<gnu_srs> This version does not work: one relying on static assumptions
about the frame layout
<gnu_srs> Causing segfaults.
<gnu_srs> Any interest to create a test case out of that piece of code,
taken from gcc/ada/tracebak.c?
<braunr> gnu_srs: sure
### IRC, freenode, #hurd, 2012-07-18
<braunr> "Digging further revealed that the GNU/Hurd stack frame does not
seem to
<braunr> be static enough to define USE_GENERIC_UNWINDER in
gcc/ada/tracebak.c.
<braunr> "
<braunr> what do you mean by a "stack frame does not seem to be static
enough" ?
<gnu_srs> I can qoute from the source file if you want. Otherwise look at
the code yourself: gcc/ada/tracebak,c
<gnu_srs> I mean that something is wrong with the stack frame for
Hurd. This is the code I wanted to use as a test case for the stack.
<gnu_srs> Remember?
<braunr> more or less
<braunr> ah, "static assumptions"
<braunr> all right, i don't think anything is "wrong" with stack frames
<braunr> but if you use a recent version of gcc, as indicated in the code,
-fomit-frame-pointer is enabled by default
<braunr> so your stack frame won't look like it used to be without the
option
<braunr> hence the need for USE_GCC_UNWINDER
<braunr> http://en.wikipedia.org/wiki/Call_stack explains this very well
<gnu_srs> However, kfreebsd does not seem to need USE_GCC_UNWINDER, how
come?
<braunr> i guess they don't omit the frame pointer
<braunr> your fix is good btw
<gnu_srs> thanks
### IRC, freenode, #hurd, 2012-07-19
<gnu_srs> tschwinge: The bug in #681998 should go upstream. Applied in
Debian already. Hopefully this is the last patch needed for the port of
GNAT to Hurd.
### 2015-11-27
Is this related to:
`gcc/ada/tracebak.c`:
#if (defined (__x86_64__) || defined (__linux__)) && !defined (__USING_SJLJ_EXCEPTIONS__)
#define USE_GCC_UNWINDER
#else
#define USE_GENERIC_UNWINDER
## Svante's patch
A basic port has been done by Svante, [[!debbug 668425]], [[!debbug 681998]],
[[!message-id "1333104917.2962.439.camel@s1499.it.kth.se"]], but there's still
lots of work remaining.
The port is not yet upstream: the maintainer raised some concerns that
[[I|tschwinge]] have not yet found the time to follow up on, [[!message-id
"1339857758-5032-1-git-send-email-thomas@codesourcery.com"]].
While the test
results of the GCC/GNAT testsuite don't look bad (but there are a few
unresolved issues, and the testsuite appears to be a rather small one), I don't
know if the port has yet seen any real-world usage, such as using it for any
bigger Ada code bases, or any Ada testsuites.
### "try2"
[[!message-id "1456875776.5852.194.camel@gmail.com"]].
GCC trunk r234252.
`gcc/ada/s-osinte-gnu.adb`: r235467 (on trunk)/r235468 (on gcc-6-branch).
`getpagesize` patch: r235896 (on trunk)/r235897 (on gcc-6-branch).
Still incomplete? (Changes to generic files?)
### 2016-12-14
Based on commit 17f0f5acdcfb9181203ca9b6d8f8cbc64e5ce843, [[tschwinge]] tried
to build with `--enable-languages=all,ada`, but both with `--disable-bootstrap`
and `--enable-bootstrap` we run into:
[...]
make[3]: Entering directory '/media/erich/home/thomas/tmp/gcc/hurd/master.build/gcc/ada/tools'
../../gnatbind -I- -I../rts -I. -I/home/thomas/tmp/gcc/hurd/master/gcc/ada -o b_gnatm.adb gnatmake.ali
error: "system.ads" has restriction No_Implicit_Dynamic_Code
error: but the following files violate this restriction:
error: "make.adb"
error: "makeutl.adb"
error: "prj.adb"
error: "prj-env.adb"
error: "prj-conf.adb"
error: "prj-nmsc.adb"
../gcc-interface/Makefile:2987: recipe for target 'b_gnatm.adb' failed
make[3]: *** [b_gnatm.adb] Error 5
make[3]: Leaving directory '/media/erich/home/thomas/tmp/gcc/hurd/master.build/gcc/ada/tools'
Makefile:194: recipe for target 'gnattools-native' failed
make[2]: *** [gnattools-native] Error 2
make[2]: Leaving directory '/media/erich/home/thomas/tmp/gcc/hurd/master.build/gnattools'
Makefile:9650: recipe for target 'all-gnattools' failed
make[1]: *** [all-gnattools] Error 2
make[1]: Leaving directory '/media/erich/home/thomas/tmp/gcc/hurd/master.build'
Makefile:895: recipe for target 'all' failed
make: *** [all] Error 2
(Partial) review of differences:
`gcc/ada/gcc-interface/Makefile.in`, Linux vs. Hurd
LIBGNAT_TARGET_PAIRS = \
a-intnam.ads<a-intnam-linux.ads vs. a-intnam.ads<a-intnam-freebsd.ads
a-synbar.adb<a-synbar-posix.adb vs. nil
a-synbar.ads<a-synbar-posix.ads vs. nil
s-inmaop.adb<s-inmaop-posix.adb
s-intman.adb<s-intman-posix.adb
s-tpopsp.adb<s-tpopsp-tls.adb vs. s-tpopsp.adb<s-tpopsp-posix-foreign.adb
g-sercom.adb<g-sercom-linux.adb vs. nil
a-exetim.adb<a-exetim-posix.adb vs. nil
a-exetim.ads<a-exetim-default.ads vs. nil
s-linux.ads<s-linux.ads vs. nil
s-osinte.adb<s-osinte-posix.adb vs. s-osinte.adb<s-osinte-gnu.adb
$(ATOMICS_TARGET_PAIRS)
system.ads<system-linux-x86.ads vs. system.ads<system-freebsd-x86.ads
$(X86_TARGET_PAIRS)
s-mudido.adb<s-mudido-affinity.adb vs. nil
s-osinte.ads<s-osinte-linux.ads vs. s-osinte.ads<s-osinte-gnu.ads
s-osprim.adb<s-osprim-posix.adb
s-taprop.adb<s-taprop-linux.adb vs. s-taprop.adb<s-taprop-posix.adb
s-tasinf.ads<s-tasinf-linux.ads vs. nil
s-tasinf.adb<s-tasinf-linux.adb vs. nil
s-taspri.ads<s-taspri-posix.ads
EH_MECHANISM=-gcc
THREADSLIB = -lpthread -lrt vs. THREADSLIB = -lpthread
EXTRA_GNATRTL_NONTASKING_OBJS += g-sse.o g-ssvety.o
EXTRA_GNATRTL_TASKING_OBJS=s-linux.o a-exetim.o vs. nil
TOOLS_TARGET_PAIRS = \
mlib-tgt-specific.adb<mlib-tgt-specific-linux.adb
indepsw.adb<indepsw-gnu.adb
GNATLIB_SHARED = gnatlib-shared-dual
MISCLIB = -ldl vs. nil
GMEM_LIB = gmemlib
LIBRARY_VERSION := $(LIB_VERSION)
TOOLS1_LIBS=-ldl vs. nil
Eventually [[tschwinge]] found <http://gcc.gnu.org/PR57188>, and similarly
fixed the issue.
## `getcontext`/`makecontext`/`setcontext`/`swapcontext` usage analysis
In context of [[glibc/t/tls-threadvar]]. Looking at GCC trunk commit
f6568ea476aa52a6e23c6db43b3e240cde55783a (2013-04-26).
gcc/ada/init.c: sigaltstack (&stack, NULL);
gcc/ada/init.c: sigaltstack (&stack, NULL);
gcc/ada/init.c: sigaltstack (&stack, NULL);
gcc/ada/s-osinte-aix.ads: function sigaltstack
gcc/ada/s-osinte-aix.ads: pragma Import (C, sigaltstack, "sigaltstack");
gcc/ada/s-osinte-android.ads: function sigaltstack
gcc/ada/s-osinte-android.ads: pragma Import (C, sigaltstack, "sigaltstack");
gcc/ada/s-osinte-darwin.ads: function sigaltstack
gcc/ada/s-osinte-darwin.ads: pragma Import (C, sigaltstack, "sigaltstack");
gcc/ada/s-osinte-freebsd.ads: function sigaltstack
gcc/ada/s-osinte-freebsd.ads: pragma Import (C, sigaltstack, "sigaltstack");
gcc/ada/s-osinte-hpux.ads: function sigaltstack
gcc/ada/s-osinte-hpux.ads: pragma Import (C, sigaltstack, "sigaltstack");
gcc/ada/s-osinte-kfreebsd-gnu.ads: function sigaltstack
gcc/ada/s-osinte-kfreebsd-gnu.ads: pragma Import (C, sigaltstack, "sigaltstack");
gcc/ada/s-osinte-linux.ads: function sigaltstack
gcc/ada/s-osinte-linux.ads: pragma Import (C, sigaltstack, "sigaltstack");
gcc/ada/s-osinte-rtems.adb: -- sigaltstack --
gcc/ada/s-osinte-rtems.adb: function sigaltstack
gcc/ada/s-osinte-rtems.adb: end sigaltstack;
gcc/ada/s-osinte-rtems.ads: function sigaltstack
gcc/ada/s-osinte-solaris-posix.ads: function sigaltstack
gcc/ada/s-osinte-solaris-posix.ads: pragma Import (C, sigaltstack, "sigaltstack");
gcc/ada/s-taprop-linux.adb: Result := sigaltstack (Stack'Access, null);
gcc/ada/s-taprop-posix.adb: Result := sigaltstack (Stack'Access, null);
gcc/ada/init.c: stack.ss_sp = __gnat_alternate_stack;
gcc/ada/init.c: stack.ss_sp = __gnat_alternate_stack;
gcc/ada/init.c: stack.ss_sp = __gnat_alternate_stack;
gcc/ada/s-osinte-aix.ads: ss_sp : System.Address;
gcc/ada/s-osinte-android.ads: ss_sp : System.Address;
gcc/ada/s-osinte-darwin.ads: ss_sp : System.Address;
gcc/ada/s-osinte-darwin.ads: uc_stack : stack_t; -- Stack Used By This Context
gcc/ada/s-osinte-freebsd.ads: ss_sp : System.Address;
gcc/ada/s-osinte-hpux.ads: ss_sp : System.Address;
gcc/ada/s-osinte-kfreebsd-gnu.ads: ss_sp : System.Address;
gcc/ada/s-osinte-linux.ads: ss_sp : System.Address;
gcc/ada/s-osinte-rtems.ads: ss_sp : System.Address;
gcc/ada/s-osinte-solaris-posix.ads: ss_sp : System.Address;
gcc/ada/s-osinte-solaris.ads: ss_sp : System.Address;
gcc/ada/s-osinte-solaris.ads: uc_stack : record_type_2;
gcc/ada/s-taprop-linux.adb: Stack.ss_sp := Self_ID.Common.Task_Alternate_Stack;
gcc/ada/s-taprop-posix.adb: Stack.ss_sp := Self_ID.Common.Task_Alternate_Stack;
gcc/ada/init.c: act.sa_flags |= SA_ONSTACK;
gcc/ada/init.c: act.sa_flags |= SA_ONSTACK;
gcc/ada/init.c: act.sa_flags = SA_SIGINFO | SA_ONSTACK;
gcc/ada/init.c: act.sa_flags |= SA_ONSTACK;
gcc/ada/s-intman-posix.adb: act.sa_flags := act.sa_flags + SA_ONSTACK;
gcc/ada/s-linux-alpha.ads: SA_ONSTACK : constant := 16#01#;
gcc/ada/s-linux-hppa.ads: SA_ONSTACK : constant := 16#01#;
gcc/ada/s-linux-mipsel.ads: SA_ONSTACK : constant := 16#08000000#;
gcc/ada/s-linux-sparc.ads: SA_ONSTACK : constant := 16#001#;
gcc/ada/s-linux.ads: SA_ONSTACK : constant := 16#08000000#;
gcc/ada/s-osinte-aix.ads: SA_ONSTACK : constant := 16#0001#;
gcc/ada/s-osinte-android.ads: SA_ONSTACK : constant := System.Linux.SA_ONSTACK;
gcc/ada/s-osinte-darwin.ads: SA_ONSTACK : constant := 16#0001#;
gcc/ada/s-osinte-freebsd.ads: SA_ONSTACK : constant := 16#0001#;
gcc/ada/s-osinte-hpux-dce.ads: SA_ONSTACK : constant := 16#01#;
gcc/ada/s-osinte-hpux.ads: SA_ONSTACK : constant := 16#01#;
gcc/ada/s-osinte-kfreebsd-gnu.ads: SA_ONSTACK : constant := 16#0001#;
gcc/ada/s-osinte-linux.ads: SA_ONSTACK : constant := System.Linux.SA_ONSTACK;
gcc/ada/s-osinte-lynxos.ads: SA_ONSTACK : constant := 16#00#;
gcc/ada/s-osinte-lynxos.ads: -- SA_ONSTACK is not defined on LynxOS, but it is referred to in the POSIX
gcc/ada/s-osinte-rtems.ads: SA_ONSTACK : constant := 16#00#;
gcc/ada/s-osinte-rtems.ads: -- SA_ONSTACK is not defined on RTEMS, but it is referred to in the POSIX
gcc/ada/s-osinte-solaris-posix.ads: SA_ONSTACK : constant := 16#0001#;
gcc/ada/s-osinte-vxworks.ads: SA_ONSTACK : constant := 16#0004#;
## TODO
diff --git ./gcc/ada/init.c ./gcc/ada/init.c
@@ -2002,6 +2021,15 @@ __gnat_install_handler (void)
trap_0_entry->inst_fourth = 0xa1480000;
#endif
{+#if (defined (i386) || defined (__i386__)) && !defined (VTHREADS)+}
{+ /* By experiment, found that sysModel () returns the following string+}
{+ prefix for vxsim when running on Linux and Windows. */+}
{+ model = sysModel ();+}
{+ if ((strncmp (model, "Linux", 5) == 0)+}
{+ || (strncmp (model, "Windows", 7) == 0))+}
{+ is_vxsim = 1;+}
{+#endif+}
__gnat_handler_installed = 1;
}
diff --git ./gcc/ada/sigtramp.h ./gcc/ada/sigtramp.h
@@ -62,8 +62,14 @@ typedef struct ucontext
system headers so call it something unique. */
typedef void __sigtramphandler_t (int signo, void *siginfo, void *sigcontext);
{+#if CPU == SIMNT || CPU == SIMPENTIUM || CPU == SIMLINUX+}
{+ /* Vxsim requires a specially compiled handler. */+}
{+ void __gnat_sigtramp_vxsim (int signo, void *siginfo, void *sigcontext,+}
{+ __sigtramphandler_t * handler);+}
{+#else+}
void __gnat_sigtramp (int signo, void *siginfo, void *sigcontext,
__sigtramphandler_t * handler);
{+#endif+}
diff --git ./gcc/ada/gcc-interface/Makefile.in ./gcc/ada/gcc-interface/Makefile.in
@@ -923,13 +928,49 @@ ifeq ($(strip $(filter-out %86 wrs vxworks vxworks7,$(target_cpu) $(target_vendo
{+ VXSIM_CPU =+}
{+ ifeq ($(strip $(filter-out vxworks rtp rtp-smp,$(target_os) $(THREAD_KIND))),)+}
{+ VXSIM_CPU = SIMPENTIUM+}
{+ else+}
{+ ifeq ($(strip $(filter-out kernel kernel-smp rtp rtp-smp,$(THREAD_KIND))),)+}
{+ ifeq ($(strip $(filter-out linux%,$(host_os))),)+}
{+ # Linux+}
{+ VXSIM_CPU = SIMLINUX+}
{+ else+}
{+ # Windows+}
{+ VXSIM_CPU = SIMNT+}
{+ endif+}
{+ endif+}
diff --git ./gcc/ada/gcc-interface/Makefile.in ./gcc/ada/gcc-interface/Makefile.in
@@ -2413,6 +2468,14 @@ ifeq ($(filter a-except%,$(LIBGNAT_TARGET_PAIRS)),)
{+# Configuration of host tools+}
{+# Under linux, host tools need to be linked with -ldl+}
{+ifeq ($(strip $(filter-out linux%,$(host_os))),)+}
{+ TOOLS1_LIBS=-ldl+}
{+endif+}
diff --git ./gcc/ada/s-osinte-linux.ads ./gcc/ada/s-osinte-linux.ads
@@ -224,6 +224,10 @@ package System.OS_Interface is
{+function clock_gettime+}
{+ (clock_id : clockid_t; tp : access timespec) return int;+}
{+ pragma Import (C, clock_gettime, "clock_gettime");+}
diff --git ./gcc/ada/s-taprop-linux.adb ./gcc/ada/s-taprop-linux.adb
@@ -39,7 +39,6 @@ pragma Polling (Off);
with Interfaces.C;
[-with Interfaces.C.Extensions;-]
@@ -64,7 +63,6 @@ package body System.Task_Primitives.Operations is
use Interfaces.C;
[- use Interfaces.C.Extensions;-]
@@ -629,30 +627,14 @@ package body System.Task_Primitives.Operations is
function Monotonic_Clock return Duration is
[-use Interfaces;-]
[- procedure timeval_to_duration-]
[- (T : not null access timeval;-]
[- sec : not null access C.Extensions.long_long;-]
[- usec : not null access C.long);-]
[- pragma Import (C, timeval_to_duration, "__gnat_timeval_to_duration");-]
[- Micro : constant := 10**6;-]
[- sec : aliased C.Extensions.long_long;-]
[- usec : aliased C.long;-]
[- TV-]{+TS+} : aliased [-timeval;-]{+timespec;+}
Result : int;
[- function gettimeofday-]
[- (Tv : access timeval;-]
[- Tz : System.Address := System.Null_Address) return int;-]
[- pragma Import (C, gettimeofday, "gettimeofday");-]
begin
Result := [-gettimeofday (TV'Access, System.Null_Address);-]{+clock_gettime+}
{+ (clock_id => OSC.CLOCK_RT_Ada, tp => TS'Unchecked_Access);+}
pragma Assert (Result = 0);
[-timeval_to_duration (TV'Access, sec'Access, usec'Access);-]
return [-Duration (sec) + Duration (usec) / Micro;-]{+To_Duration (TS);+}
end Monotonic_Clock;
diff --git ./gcc/ada/adaint.c ./gcc/ada/adaint.c
@@ -3220,6 +3220,107 @@ __gnat_kill (int pid, int sig, int close ATTRIBUTE_UNUSED)
#endif
}
{+void __gnat_killprocesstree (int pid, int sig_num)+}
{+{+}
{+[...]+}
{+#elif defined (__linux__)+}
{+ DIR *dir;+}
{+ struct dirent *d;+}
{+ /* read all processes' pid and ppid */+}
{+ dir = opendir ("/proc");+}
{+[...]+}
{+ /* kill process */+}
{+ __gnat_kill (pid, sig_num, 1);+}
{+#else+}
{+ __gnat_kill (pid, sig_num, 1);+}
{+#endif+}
{+[...]+}
{+}+}
diff --git ./gcc/ada/s-os_lib.ads ./gcc/ada/s-os_lib.ads
@@ -740,6 +744,19 @@ package System.OS_Lib is
{+ procedure Kill_Process_Tree (Pid : Process_Id; Hard_Kill : Boolean := True);+}
{+ -- Kill the process designated by Pid and all it's children processes.+}
{+ -- [...]
{+ -- Note that this routine is not atomic and is supported only on Linux+}
{+ -- and Windows. On other OS it will only kill the process identified by+}
{+ -- Pid.+}
GCC includes (TODO: some version of) the Ada Conformity Assessment Test Suite
(ACATS), <http://ada-auth.org/acats.html>. Additional tests to be found at
<http://ada-auth.org/submit.html>. TODO: results?
---
# Part II
Next, Hurd-specific features can be added. Add an interface to the
language/environment for being able to do [[RPC]] calls, in order to program
[[hurd/translator]]s natively in Ada.
## Original [[community/GSoC]] Task Description
[[!inline pages=community/gsoc/project_ideas/language_bindings feeds=no]]
|