public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "doko at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug ada/114424] New: gnat: Ada.Calendar.Clock crashes on 32bit architectures with 64bit time_t Date: Fri, 22 Mar 2024 00:01:16 +0000 [thread overview] Message-ID: <bug-114424-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114424 Bug ID: 114424 Summary: gnat: Ada.Calendar.Clock crashes on 32bit architectures with 64bit time_t Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ada Assignee: unassigned at gcc dot gnu.org Reporter: doko at gcc dot gnu.org CC: dkm at gcc dot gnu.org Target Milestone: --- [forwarded from https://bugs.debian.org/1067453] Ada packages randomly FTBFS on 32 bit architectures with gprbuild: raised CONSTRAINT_ERROR : a-calend.adb:371 overflow check failed The problem originates in the gcc-13 switch to time_t64. gcc/ada/libgnat/s-os_prim__posix.adb is affected by two apparently distinct issues. * s-os_prim.adb allocates 3Long_Integer=3void*=3*32 bits for the timeval C struct, while 2*64bits = 2Long_Long_Integer are now needed. This issue affects other files, but is easy to find and fix. * The switch breaks the call from Ada to the C gettimeofday function. Can anyone explain this, and ideally provide a real fix instead of the ugly work-around below? cat > mycal.c <<EOF #include <sys/time.h> int mygettimeofday(struct timeval *restrict tv, struct timezone *restrict tz) { return gettimeofday(tv, tz); } EOF cat > foo.adb <<EOF with Ada.Text_IO, System.OS_Primitives; procedure Foo is -- On armhf, array(1..3) of Long_Integer gives random usec values. type timeval is array (1 .. 2) of Long_Long_Integer; procedure timeval_to_duration (T : not null access timeval; sec : not null access Long_Long_Integer; usec : not null access Long_Integer); pragma Import (C, timeval_to_duration, "__gnat_timeval_to_duration"); sec : aliased Long_Long_Integer; usec : aliased Long_Integer; TV : aliased timeval; function gettimeofday (Tv : access timeval; Tz : System.Address := System.Null_Address) return Integer; -- On armhf, a direct import of gettimeofday leads to random Tv values. pragma Import (C, gettimeofday, "mygettimeofday"); Result : constant Integer := gettimeofday (TV'Access, System.Null_Address); SOP : constant Duration := System.OS_Primitives.Clock; begin timeval_to_duration (TV'Access, sec'Access, usec'Access); Ada.Text_IO.Put_Line ("local :" & Sec'Img & "." & Usec'Img); Ada.Text_IO.Put_Line ("System.OS_Primitives:" & SOP'Img); end Foo; EOF gcc -c mycal.c -o mycal.o gnatmake -gnat2022 foo -largs mycal.o echo -n 'Machine : '; uname -m date '+Expected : %s' ./foo Machine : x86_64 (amd64 x86_64-linux-gnu) Expected : 1711035183 local : 1711035183. 324545 System.OS_Primitives: 1711035183.324549000 Machine : armv7l (armhf arm-gnu-eabi) Expected : 1711035189 local : 1711035189. 551691 System.OS_Primitives: 1113580361.675821568
next reply other threads:[~2024-03-22 0:01 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-03-22 0:01 doko at gcc dot gnu.org [this message] 2024-03-22 0:05 ` [Bug ada/114424] " pinskia at gcc dot gnu.org 2024-03-22 0:45 ` doko at gcc dot gnu.org 2024-03-23 18:55 ` ebotcazou at gcc dot gnu.org 2024-03-23 23:09 ` doko at gcc dot gnu.org 2024-03-24 8:31 ` ebotcazou at gcc dot gnu.org 2024-03-24 18:44 ` doko at gcc dot gnu.org 2024-03-24 18:59 ` doko at gcc dot gnu.org 2024-03-24 19:42 ` ebotcazou at gcc dot gnu.org 2024-03-25 12:06 ` doko at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-114424-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).