From: Olivier Hainque <hain...@adacore.com> Building an aarch64-android compiler with the current sources initially intended for arm-android expectedly trips on problems.
This change is meant to address: ``` .../gcc/ada/rts % ../../gnat1 -quiet ... a-stbufi.adb -I. s-osinte.ads:591:07: error: component "sa_flags" overlaps "sa_mask" at line 590 ``` s-linux__android.ads makes hardcoded assumptions on the size of sigset_t, based on observations performed in the course of the arm port. Then sysem headers show sa_flags placed VERY differently between the 32 and the 64 bits variants. See android-sysroot/usr/include/bits/signal_types.h ``` %if defined(__LP64__) int sa_flags; \ union { \ sighandler_t sa_handler; \ void (*sa_sigaction)(int, struct siginfo*, void*); \ }; \ sigset_t sa_mask; \ void (*sa_restorer)(void); \ %else union { sighandler_t sa_handler; void (*sa_sigaction)(int, struct siginfo*, void*); }; sigset_t sa_mask; int sa_flags; void (*sa_restorer)(void); ``` gcc/ada/ChangeLog: * libgnarl/s-linux__android-arm.ads: New file, renaming of ... * libgnarl/s-linux__android.ads: ... this file. * libgnarl/s-linux__android-aarch64.ads: New file. Based on the -arm variant, with sa_ field positions adjusted. * Makefile.rtl (arm/aarch64-android pairs): Adjust accordingly. * libgnarl/s-osinte__android.ads: Rather than making assumptions on the actual type of the C sigset_t, use Os_Constants.SIZEOF_sigset_t to define an Ada sigset_t type of the proper size. Use C.int instead of unsigned_long for sa_flags. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/Makefile.rtl | 5 +- gcc/ada/libgnarl/s-linux__android-aarch64.ads | 133 ++++++++++++++++++ ...__android.ads => s-linux__android-arm.ads} | 0 gcc/ada/libgnarl/s-osinte__android.ads | 10 +- 4 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 gcc/ada/libgnarl/s-linux__android-aarch64.ads rename gcc/ada/libgnarl/{s-linux__android.ads => s-linux__android-arm.ads} (100%) diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/Makefile.rtl index 9f4c6cd99dc..d4607e95eff 100644 --- a/gcc/ada/Makefile.rtl +++ b/gcc/ada/Makefile.rtl @@ -1414,7 +1414,6 @@ ifeq ($(strip $(filter-out arm% aarch64 linux-android%,$(target_cpu) $(target_os a-intnam.ads<libgnarl/a-intnam__linux.ads \ s-inmaop.adb<libgnarl/s-inmaop__posix.adb \ s-intman.adb<libgnarl/s-intman__android.adb \ - s-linux.ads<libgnarl/s-linux__android.ads \ s-osinte.adb<libgnarl/s-osinte__android.adb \ s-osinte.ads<libgnarl/s-osinte__android.ads \ s-oslock.ads<libgnat/s-oslock__posix.ads \ @@ -1439,11 +1438,15 @@ ifeq ($(strip $(filter-out arm% aarch64 linux-android%,$(target_cpu) $(target_os EH_MECHANISM=-arm SIGTRAMP_OBJ=sigtramp-armdroid.o + LIBGNAT_TARGET_PAIRS += \ + s-linux.ads<libgnarl/s-linux__android-arm.ads else SELECTED_PAIRS=aarch64-android EH_MECHANISM=-gcc SIGTRAMP_OBJ= + LIBGNAT_TARGET_PAIRS += \ + s-linux.ads<libgnarl/s-linux__android-aarch64.ads LIBGNAT_TARGET_PAIRS += $(GNATRTL_128BIT_PAIRS) EXTRA_GNATRTL_NONTASKING_OBJS = $(GNATRTL_128BIT_OBJS) diff --git a/gcc/ada/libgnarl/s-linux__android-aarch64.ads b/gcc/ada/libgnarl/s-linux__android-aarch64.ads new file mode 100644 index 00000000000..6c64626c294 --- /dev/null +++ b/gcc/ada/libgnarl/s-linux__android-aarch64.ads @@ -0,0 +1,133 @@ +------------------------------------------------------------------------------ +-- -- +-- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS -- +-- -- +-- S Y S T E M . L I N U X -- +-- -- +-- S p e c -- +-- -- +-- Copyright (C) 2014-2024, Free Software Foundation, Inc. -- +-- -- +-- GNARL 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. -- +-- -- +-- In particular, you can freely distribute your programs built with the -- +-- GNAT Pro compiler, including any required library run-time units, using -- +-- any licensing terms of your choosing. See the AdaCore Software License -- +-- for full details. -- +-- -- +-- -- +------------------------------------------------------------------------------ + +-- This is the Android version of this package + +-- This package encapsulates cpu specific differences between implementations +-- of GNU/Linux, in order to share s-osinte-linux.ads. + +-- PLEASE DO NOT add any with-clauses to this package or remove the pragma +-- Preelaborate. This package is designed to be a bottom-level (leaf) package + +with Interfaces.C; +with System.Parameters; + +package System.Linux is + pragma Preelaborate; + + ---------- + -- Time -- + ---------- + + subtype long is Interfaces.C.long; + subtype suseconds_t is Interfaces.C.long; + type time_t is range -2 ** (System.Parameters.time_t_bits - 1) + .. 2 ** (System.Parameters.time_t_bits - 1) - 1; + subtype clockid_t is Interfaces.C.int; + + type timespec is record + tv_sec : time_t; + tv_nsec : long; + end record; + pragma Convention (C, timespec); + + type timeval is record + tv_sec : time_t; + tv_usec : suseconds_t; + end record; + pragma Convention (C, timeval); + + ----------- + -- Errno -- + ----------- + + EAGAIN : constant := 11; + EINTR : constant := 4; + EINVAL : constant := 22; + ENOMEM : constant := 12; + EPERM : constant := 1; + ETIMEDOUT : constant := 110; + + ------------- + -- Signals -- + ------------- + + SIGHUP : constant := 1; -- hangup + SIGINT : constant := 2; -- interrupt (rubout) + SIGQUIT : constant := 3; -- quit (ASCD FS) + SIGILL : constant := 4; -- illegal instruction (not reset) + SIGTRAP : constant := 5; -- trace trap (not reset) + SIGIOT : constant := 6; -- IOT instruction + SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future + SIGFPE : constant := 8; -- floating point exception + SIGKILL : constant := 9; -- kill (cannot be caught or ignored) + SIGBUS : constant := 7; -- bus error + SIGSEGV : constant := 11; -- segmentation violation + SIGPIPE : constant := 13; -- write on a pipe with no one to read it + SIGALRM : constant := 14; -- alarm clock + SIGTERM : constant := 15; -- software termination signal from kill + SIGUSR1 : constant := 10; -- user defined signal 1 + SIGUSR2 : constant := 12; -- user defined signal 2 + SIGCLD : constant := 17; -- alias for SIGCHLD + SIGCHLD : constant := 17; -- child status change + SIGPWR : constant := 30; -- power-fail restart + SIGWINCH : constant := 28; -- window size change + SIGURG : constant := 23; -- urgent condition on IO channel + SIGPOLL : constant := 29; -- pollable event occurred + SIGIO : constant := 29; -- I/O now possible (4.2 BSD) + SIGLOST : constant := 29; -- File lock lost + SIGSTOP : constant := 19; -- stop (cannot be caught or ignored) + SIGTSTP : constant := 20; -- user stop requested from tty + SIGCONT : constant := 18; -- stopped process has been continued + SIGTTIN : constant := 21; -- background tty read attempted + SIGTTOU : constant := 22; -- background tty write attempted + SIGVTALRM : constant := 26; -- virtual timer expired + SIGPROF : constant := 27; -- profiling timer expired + SIGXCPU : constant := 24; -- CPU time limit exceeded + SIGXFSZ : constant := 25; -- filesize limit exceeded + SIGUNUSED : constant := 31; -- unused signal (GNU/Linux) + SIGSTKFLT : constant := 16; -- coprocessor stack fault (Linux) + SIG32 : constant := 32; -- glibc internal signal + SIG33 : constant := 33; -- glibc internal signal + SIG34 : constant := 34; -- glibc internal signal + + -- struct_sigaction offsets + + -- sa_flags come first on aarch64-android (sa_flags, sa_handler, sa_mask) + + sa_flags_pos : constant := 0; + sa_handler_pos : constant := sa_flags_pos + Interfaces.C.int'Size / 8; + sa_mask_pos : constant := sa_handler_pos + Standard'Address_Size / 8; + + SA_SIGINFO : constant := 16#00000004#; + SA_ONSTACK : constant := 16#08000000#; + SA_RESTART : constant := 16#10000000#; + SA_NODEFER : constant := 16#40000000#; + +end System.Linux; diff --git a/gcc/ada/libgnarl/s-linux__android.ads b/gcc/ada/libgnarl/s-linux__android-arm.ads similarity index 100% rename from gcc/ada/libgnarl/s-linux__android.ads rename to gcc/ada/libgnarl/s-linux__android-arm.ads diff --git a/gcc/ada/libgnarl/s-osinte__android.ads b/gcc/ada/libgnarl/s-osinte__android.ads index 8e1b5a267b7..62389061fec 100644 --- a/gcc/ada/libgnarl/s-osinte__android.ads +++ b/gcc/ada/libgnarl/s-osinte__android.ads @@ -175,7 +175,7 @@ package System.OS_Interface is type struct_sigaction is record sa_handler : System.Address; sa_mask : sigset_t; - sa_flags : Interfaces.C.unsigned_long; + sa_flags : Interfaces.C.int; sa_restorer : System.Address; end record; pragma Convention (C, struct_sigaction); @@ -580,16 +580,18 @@ package System.OS_Interface is private - type sigset_t is new Interfaces.C.unsigned_long; + type sigset_t is + array (0 .. OS_Constants.SIZEOF_sigset - 1) of unsigned_char; pragma Convention (C, sigset_t); for sigset_t'Alignment use Interfaces.C.unsigned_long'Alignment; pragma Warnings (Off); for struct_sigaction use record sa_handler at Linux.sa_handler_pos range 0 .. Standard'Address_Size - 1; - sa_mask at Linux.sa_mask_pos range 0 .. sigset_t'Size - 1; + sa_mask at Linux.sa_mask_pos + range 0 .. OS_Constants.SIZEOF_sigset * 8 - 1; sa_flags at Linux.sa_flags_pos - range 0 .. Interfaces.C.unsigned_long'Size - 1; + range 0 .. Interfaces.C.int'Size - 1; end record; -- We intentionally leave sa_restorer unspecified and let the compiler -- append it after the last field, so disable corresponding warning. -- 2.43.0