public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ada/114424] New: gnat: Ada.Calendar.Clock crashes on 32bit architectures with 64bit time_t
@ 2024-03-22  0:01 doko at gcc dot gnu.org
  2024-03-22  0:05 ` [Bug ada/114424] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: doko at gcc dot gnu.org @ 2024-03-22  0:01 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-03-25 12:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-22  0:01 [Bug ada/114424] New: gnat: Ada.Calendar.Clock crashes on 32bit architectures with 64bit time_t doko at gcc dot gnu.org
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

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).