Repair time/delay/duration time_t issues in gnat. All direct imports of

C functions have been modified to use same-size types on both sides.
There are no checks in gcc to make sure the types match, and it happily
trashes the stack or reads bogus data without this fix.

The C shim in gnatlib is still casting down to long (by design), thus
gnat is not 2038-proof on 32 bit architectures. Fixing this is an
ongoing project, but I'm running out of time for this release.

Getting the timezone offset is now supported; the unused usleep
procedure that snuck in from FreeBSD support got removed.

Tested on all supported architectures, plus new bootstraps due to the
stack trashing, just in case...

Conceptually fine with brad@
deraadt@ is unhappy with the partial solution, fixing this remains a
high priority todo
This commit is contained in:
tobiasu 2014-02-07 01:27:21 +00:00
parent f5263ad576
commit fa5f89b880
18 changed files with 227 additions and 52 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.69 2014/01/15 20:16:03 brad Exp $
# $OpenBSD: Makefile,v 1.70 2014/02/07 01:27:21 tobiasu Exp $
ONLY_FOR_ARCHS = alpha amd64 hppa i386 powerpc sparc64
DPB_PROPERTIES = parallel
@ -7,12 +7,12 @@ V = 4.6.4
FULL_VERSION = $V
FULL_PKGVERSION = $V
ADASTRAP_LIBC-i386 = 70.0
ADASTRAP-i386 = adastrap-i386-$V-3.tar.xz
ADASTRAP_LIBC-amd64 = 70.0
ADASTRAP-amd64 = adastrap-amd64-$V-3.tar.xz
ADASTRAP_LIBC-sparc64 = 70.0
ADASTRAP-sparc64 = adastrap-sparc64-$V-3.tar.xz
ADASTRAP_LIBC-i386 = 73.0
ADASTRAP-i386 = adastrap-i386-$V-4.tar.xz
ADASTRAP_LIBC-amd64 = 73.0
ADASTRAP-amd64 = adastrap-amd64-$V-4.tar.xz
ADASTRAP_LIBC-sparc64 = 73.0
ADASTRAP-sparc64 = adastrap-sparc64-$V-4.tar.xz
PKGNAME-main = gcc-${FULL_PKGVERSION}
PKGNAME-c++ = g++-${FULL_PKGVERSION}
@ -30,7 +30,7 @@ REVISION-c++ = 4
REVISION-f95 = 4
REVISION-java = 4
REVISION-objc = 3
REVISION-ada = 6
REVISION-ada = 7
REVISION-go = 4
SHARED_LIBS = estdc++ 14.0 \

View File

@ -1,10 +1,10 @@
SHA256 (gcc/adastrap-amd64-4.6.4-3.tar.xz) = C6WLt25QtQvzPvas+IiKZKTQgce0WgW0sXunetxihcg=
SHA256 (gcc/adastrap-i386-4.6.4-3.tar.xz) = OS8X16WSASH6aujJhY3x4AWWu2oStJ3VdAxbszkX48o=
SHA256 (gcc/adastrap-sparc64-4.6.4-3.tar.xz) = +dMWKALgebV8UMEZcSAwV7swmHsBWMaQWKDliMcI6lc=
SHA256 (gcc/adastrap-amd64-4.6.4-4.tar.xz) = W7bUWobcq5yaR7NgR2+X9IeEPlDMTivafQ/Mcmz3btk=
SHA256 (gcc/adastrap-i386-4.6.4-4.tar.xz) = DpHZc7Ibkrt3uO8BA3j7VgZaTsgMIg6UWzlk9ggu8Qk=
SHA256 (gcc/adastrap-sparc64-4.6.4-4.tar.xz) = T1UMuUloajJY68QWnddbhuYGqpdxmZik1I3kY+l49oI=
SHA256 (gcc/ecj-4.5.jar) = mP0Sjx03TZ5C/Z1INr3SScbVEevGwN8X+8G535bD14E=
SHA256 (gcc/gcc-4.6.4.tar.bz2) = Na8Wr6C2evm46xXK+3bSvF9WhUBVJSL13CyI3UXZd+g=
SIZE (gcc/adastrap-amd64-4.6.4-3.tar.xz) = 19676880
SIZE (gcc/adastrap-i386-4.6.4-3.tar.xz) = 17405164
SIZE (gcc/adastrap-sparc64-4.6.4-3.tar.xz) = 13902500
SIZE (gcc/adastrap-amd64-4.6.4-4.tar.xz) = 19677348
SIZE (gcc/adastrap-i386-4.6.4-4.tar.xz) = 18556144
SIZE (gcc/adastrap-sparc64-4.6.4-4.tar.xz) = 13904728
SIZE (gcc/ecj-4.5.jar) = 1470676
SIZE (gcc/gcc-4.6.4.tar.bz2) = 72006076

View File

@ -0,0 +1,14 @@
$OpenBSD: patch-gcc_ada_a-calend_adb,v 1.1 2014/02/07 01:27:21 tobiasu Exp $
--- gcc/ada/a-calend.adb.orig Sun Jan 19 01:33:14 2014
+++ gcc/ada/a-calend.adb Sun Jan 19 01:34:06 2014
@@ -1448,9 +1448,7 @@ package body Ada.Calendar is
subtype long is Long_Integer;
type long_Pointer is access all long;
- type time_t is
- range -(2 ** (Standard'Address_Size - Integer'(1))) ..
- +(2 ** (Standard'Address_Size - Integer'(1)) - 1);
+ type time_t is new Long_Long_Integer;
type time_t_Pointer is access all time_t;
procedure localtime_tzoff

View File

@ -1,7 +1,18 @@
$OpenBSD: patch-gcc_ada_adaint_c,v 1.2 2013/05/03 23:13:49 tobiasu Exp $
$OpenBSD: patch-gcc_ada_adaint_c,v 1.3 2014/02/07 01:27:21 tobiasu Exp $
--- gcc/ada/adaint.c.orig Mon Oct 25 17:26:02 2010
+++ gcc/ada/adaint.c Sun Apr 14 03:41:35 2013
@@ -2384,7 +2384,8 @@ __gnat_number_of_cpus (void)
+++ gcc/ada/adaint.c Sun Jan 19 02:45:11 2014
@@ -1414,8 +1414,9 @@ __gnat_file_time_fd (int fd)
/* Set the file time stamp. */
void
-__gnat_set_file_time_name (char *name, time_t time_stamp)
+__gnat_set_file_time_name (char *name, OS_Time ts)
{
+ time_t time_stamp = (time_t) ts;
#if defined (__vxworks)
/* Code to implement __gnat_set_file_time_name for these systems. */
@@ -2384,7 +2385,8 @@ __gnat_number_of_cpus (void)
int cores = 1;
#if defined (linux) || defined (sun) || defined (AIX) \
@ -11,7 +22,7 @@ $OpenBSD: patch-gcc_ada_adaint_c,v 1.2 2013/05/03 23:13:49 tobiasu Exp $
cores = (int) sysconf (_SC_NPROCESSORS_ONLN);
#elif (defined (__mips) && defined (__sgi))
@@ -3686,3 +3687,9 @@ void *__gnat_lwp_self (void)
@@ -3686,3 +3688,9 @@ void *__gnat_lwp_self (void)
return (void *) syscall (__NR_gettid);
}
#endif

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-gcc_ada_adaint_h,v 1.1 2014/02/07 01:27:21 tobiasu Exp $
--- gcc/ada/adaint.h.orig Sun Jan 19 02:40:43 2014
+++ gcc/ada/adaint.h Sun Jan 19 02:41:02 2014
@@ -146,7 +146,7 @@ extern OS_Time __gnat_file_time_name (c
extern OS_Time __gnat_file_time_fd (int);
/* return -1 in case of error */
-extern void __gnat_set_file_time_name (char *, time_t);
+extern void __gnat_set_file_time_name (char *, OS_Time);
extern int __gnat_dup (int);
extern int __gnat_dup2 (int, int);

View File

@ -0,0 +1,16 @@
$OpenBSD: patch-gcc_ada_g-calend_ads,v 1.1 2014/02/07 01:27:21 tobiasu Exp $
--- gcc/ada/g-calend.ads.orig Sun Jan 19 06:14:19 2014
+++ gcc/ada/g-calend.ads Sun Jan 19 06:17:58 2014
@@ -129,7 +129,11 @@ private
-- This is a dummy declaration that should be the largest possible timeval
-- structure of all supported targets.
- type timeval is array (1 .. 2) of Interfaces.C.long;
+ type timeval is
+ record
+ tv_sec : Long_Long_Integer;
+ tv_usec : Interfaces.C.long;
+ end record;
function Julian_Day
(Year : Ada.Calendar.Year_Number;

View File

@ -1,7 +1,7 @@
$OpenBSD: patch-gcc_ada_s-osinte-openbsd_ads,v 1.1 2013/07/18 16:54:08 tobiasu Exp $
--- gcc/ada/s-osinte-openbsd.ads.orig Tue Jun 18 17:49:20 2013
+++ gcc/ada/s-osinte-openbsd.ads Tue Jun 18 17:50:54 2013
@@ -0,0 +1,650 @@
$OpenBSD: patch-gcc_ada_s-osinte-openbsd_ads,v 1.2 2014/02/07 01:27:21 tobiasu Exp $
--- gcc/ada/s-osinte-openbsd.ads.orig Sun Jan 19 01:19:07 2014
+++ gcc/ada/s-osinte-openbsd.ads Sun Jan 19 05:53:48 2014
@@ -0,0 +1,647 @@
+------------------------------------------------------------------------------
+-- --
+-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
@ -228,9 +228,6 @@ $OpenBSD: patch-gcc_ada_s-osinte-openbsd_ads,v 1.1 2013/07/18 16:54:08 tobiasu E
+ end record;
+ pragma Convention (C, struct_timezone);
+
+ procedure usleep (useconds : unsigned_long);
+ pragma Import (C, usleep, "usleep");
+
+ -------------------------
+ -- Priority Scheduling --
+ -------------------------
@ -632,7 +629,7 @@ $OpenBSD: patch-gcc_ada_s-osinte-openbsd_ads,v 1.1 2013/07/18 16:54:08 tobiasu E
+ type pid_t is new int;
+ Self_PID : constant pid_t := 0;
+
+ type time_t is new long;
+ type time_t is new Long_Long_Integer;
+
+ type timespec is record
+ ts_sec : time_t;

View File

@ -0,0 +1,25 @@
$OpenBSD: patch-gcc_ada_s-osprim-posix_adb,v 1.1 2014/02/07 01:27:21 tobiasu Exp $
--- gcc/ada/s-osprim-posix.adb.orig Sun Jan 19 03:46:06 2014
+++ gcc/ada/s-osprim-posix.adb Sun Jan 19 06:31:26 2014
@@ -38,7 +38,7 @@ package body System.OS_Primitives is
-- these declarations in System.OS_Interface and move these ones in
-- the spec.
- type time_t is new Long_Integer;
+ type time_t is new Long_Long_Integer;
type timespec is record
tv_sec : time_t;
@@ -54,7 +54,11 @@ package body System.OS_Primitives is
-----------
function Clock return Duration is
- type timeval is array (1 .. 2) of Long_Integer;
+ type timeval is
+ record
+ tv_sec : time_t;
+ tv_usec : Long_Integer;
+ end record;
procedure timeval_to_duration
(T : not null access timeval;

View File

@ -0,0 +1,13 @@
$OpenBSD: patch-gcc_ada_sysdep_c,v 1.1 2014/02/07 01:27:21 tobiasu Exp $
--- gcc/ada/sysdep.c.orig Sun Jan 19 01:26:27 2014
+++ gcc/ada/sysdep.c Sun Jan 19 01:28:13 2014
@@ -937,7 +937,8 @@ __gnat_localtime_tzoff (const time_t *timer, long *off
struct tm */
#elif defined (__APPLE__) || defined (__FreeBSD__) || defined (linux) ||\
- (defined (__alpha__) && defined (__osf__)) || defined (__GLIBC__)
+ (defined (__alpha__) && defined (__osf__)) || defined (__GLIBC__) ||\
+ defined (__OpenBSD__)
{
localtime_r (timer, &tp);
*off = tp.tm_gmtoff;

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.27 2014/01/15 20:18:36 brad Exp $
# $OpenBSD: Makefile,v 1.28 2014/02/07 01:31:40 tobiasu Exp $
ONLY_FOR_ARCHS = alpha amd64 i386 powerpc sparc64
DPB_PROPERTIES = parallel
@ -7,15 +7,15 @@ V = 4.8.2
FULL_VERSION = $V
FULL_PKGVERSION = $V
ADASTRAP_LIBC-i386 = 71.0
ADASTRAP_LIBC-i386 = 73.0
ADASTRAP_LIBM-i386 = 9.0
ADASTRAP-i386 = adastrap-i386-$V-0.tar.xz
ADASTRAP_LIBC-amd64 = 71.0
ADASTRAP-i386 = adastrap-i386-$V-1.tar.xz
ADASTRAP_LIBC-amd64 = 73.0
ADASTRAP_LIBM-amd64 = 9.0
ADASTRAP-amd64 = adastrap-amd64-$V-0.tar.xz
ADASTRAP_LIBC-sparc64 = 71.0
ADASTRAP-amd64 = adastrap-amd64-$V-1.tar.xz
ADASTRAP_LIBC-sparc64 = 73.0
ADASTRAP_LIBM-sparc64 = 9.0
ADASTRAP-sparc64 = adastrap-sparc64-$V-0.tar.xz
ADASTRAP-sparc64 = adastrap-sparc64-$V-1.tar.xz
PKGNAME-main = gcc-${FULL_PKGVERSION}
PKGNAME-c++ = g++-${FULL_PKGVERSION}
@ -34,7 +34,7 @@ REVISION-c++ = 2
REVISION-f95 = 2
REVISION-java = 2
REVISION-objc = 2
REVISION-ada = 2
REVISION-ada = 3
#REVISION-go =
SHARED_LIBS = estdc++ 16.0 \

View File

@ -1,10 +1,10 @@
SHA256 (gcc/adastrap-amd64-4.8.2-0.tar.xz) = RuHws36Mtj00vwiG8eQUyW0a8MPEDG7k++R4E7kk5jQ=
SHA256 (gcc/adastrap-i386-4.8.2-0.tar.xz) = n4eXFzsFOTPVAcUS+lXgcowttz+N48KvusskDV0ivRo=
SHA256 (gcc/adastrap-sparc64-4.8.2-0.tar.xz) = BMQfTxEuLm5q0Emscm2iBdr8Hp+QUhDSIMS6E2ksed4=
SHA256 (gcc/adastrap-amd64-4.8.2-1.tar.xz) = Q6JfaPw5HpaVq6sglhuoOCLQb/sbtM9FH7xl60BR4qA=
SHA256 (gcc/adastrap-i386-4.8.2-1.tar.xz) = eTJBBkVAjtFZ8Yw9BwyigK3z7FML/4pezIa6KGAlZaQ=
SHA256 (gcc/adastrap-sparc64-4.8.2-1.tar.xz) = L4YdMjWVCxHrzvb9605kX20XuEOzsvJKftbFDrQ7gbA=
SHA256 (gcc/ecj-4.5.jar) = mP0Sjx03TZ5C/Z1INr3SScbVEevGwN8X+8G535bD14E=
SHA256 (gcc/gcc-4.8.2.tar.bz2) = Cdwidsc0JLu/2h293GK7v5AMnxhaz38+HXc84tfjzcg=
SIZE (gcc/adastrap-amd64-4.8.2-0.tar.xz) = 33355120
SIZE (gcc/adastrap-i386-4.8.2-0.tar.xz) = 31194520
SIZE (gcc/adastrap-sparc64-4.8.2-0.tar.xz) = 27195732
SIZE (gcc/adastrap-amd64-4.8.2-1.tar.xz) = 33367392
SIZE (gcc/adastrap-i386-4.8.2-1.tar.xz) = 32559320
SIZE (gcc/adastrap-sparc64-4.8.2-1.tar.xz) = 27201372
SIZE (gcc/ecj-4.5.jar) = 1470676
SIZE (gcc/gcc-4.8.2.tar.bz2) = 85999682

View File

@ -0,0 +1,14 @@
$OpenBSD: patch-gcc_ada_a-calend_adb,v 1.1 2014/02/07 01:31:41 tobiasu Exp $
--- gcc/ada/a-calend.adb.orig Mon Jan 20 00:59:54 2014
+++ gcc/ada/a-calend.adb Mon Jan 20 01:00:33 2014
@@ -684,9 +684,7 @@ package body Ada.Calendar is
type int_Pointer is access all Interfaces.C.int;
type long_Pointer is access all Interfaces.C.long;
- type time_t is
- range -(2 ** (Standard'Address_Size - Integer'(1))) ..
- +(2 ** (Standard'Address_Size - Integer'(1)) - 1);
+ type time_t is new Long_Long_Integer;
type time_t_Pointer is access all time_t;
procedure localtime_tzoff

View File

@ -1,7 +1,18 @@
$OpenBSD: patch-gcc_ada_adaint_c,v 1.2 2013/04/12 10:01:47 tobiasu Exp $
$OpenBSD: patch-gcc_ada_adaint_c,v 1.3 2014/02/07 01:31:41 tobiasu Exp $
--- gcc/ada/adaint.c.orig Wed Feb 6 13:01:20 2013
+++ gcc/ada/adaint.c Wed Apr 10 01:42:27 2013
@@ -2467,7 +2467,8 @@ __gnat_number_of_cpus (void)
+++ gcc/ada/adaint.c Mon Jan 20 01:31:47 2014
@@ -1463,8 +1463,9 @@ __gnat_file_time_fd (int fd)
/* Set the file time stamp. */
void
-__gnat_set_file_time_name (char *name, time_t time_stamp)
+__gnat_set_file_time_name (char *name, OS_Time ts)
{
+ time_t time_stamp = (time_t) ts;
#if defined (__vxworks)
/* Code to implement __gnat_set_file_time_name for these systems. */
@@ -2467,7 +2468,8 @@ __gnat_number_of_cpus (void)
{
int cores = 1;
@ -11,7 +22,7 @@ $OpenBSD: patch-gcc_ada_adaint_c,v 1.2 2013/04/12 10:01:47 tobiasu Exp $
cores = (int) sysconf (_SC_NPROCESSORS_ONLN);
#elif defined (__hpux__)
@@ -3855,3 +3856,9 @@ void __gnat_cpu_set (int cpu, size_t count ATTRIBUTE_U
@@ -3855,3 +3857,9 @@ void __gnat_cpu_set (int cpu, size_t count ATTRIBUTE_U
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-gcc_ada_adaint_h,v 1.1 2014/02/07 01:31:41 tobiasu Exp $
--- gcc/ada/adaint.h.orig Mon Jan 20 01:53:22 2014
+++ gcc/ada/adaint.h Mon Jan 20 01:53:44 2014
@@ -150,7 +150,7 @@ extern OS_Time __gnat_file_time_name (c
extern OS_Time __gnat_file_time_fd (int);
/* return -1 in case of error */
-extern void __gnat_set_file_time_name (char *, time_t);
+extern void __gnat_set_file_time_name (char *, OS_Time);
extern int __gnat_dup (int);
extern int __gnat_dup2 (int, int);

View File

@ -0,0 +1,16 @@
$OpenBSD: patch-gcc_ada_g-calend_ads,v 1.1 2014/02/07 01:31:41 tobiasu Exp $
--- gcc/ada/g-calend.ads.orig Mon Jan 20 03:37:23 2014
+++ gcc/ada/g-calend.ads Mon Jan 20 03:39:20 2014
@@ -162,7 +162,11 @@ private
-- This is a dummy declaration that should be the largest possible timeval
-- structure of all supported targets.
- type timeval is array (1 .. 2) of Interfaces.C.long;
+ type timeval is
+ record
+ tv_sec : Long_Long_Integer;
+ tv_usec : Interfaces.C.long;
+ end record;
function Julian_Day
(Year : Ada.Calendar.Year_Number;

View File

@ -1,7 +1,7 @@
$OpenBSD: patch-gcc_ada_s-osinte-openbsd_ads,v 1.1 2013/07/18 17:04:08 tobiasu Exp $
--- gcc/ada/s-osinte-openbsd.ads.orig Mon Jun 17 16:05:29 2013
+++ gcc/ada/s-osinte-openbsd.ads Mon Jun 17 17:11:52 2013
@@ -0,0 +1,643 @@
$OpenBSD: patch-gcc_ada_s-osinte-openbsd_ads,v 1.2 2014/02/07 01:31:41 tobiasu Exp $
--- gcc/ada/s-osinte-openbsd.ads.orig Mon Jan 20 00:29:13 2014
+++ gcc/ada/s-osinte-openbsd.ads Mon Jan 20 02:52:03 2014
@@ -0,0 +1,640 @@
+------------------------------------------------------------------------------
+-- --
+-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
@ -216,9 +216,6 @@ $OpenBSD: patch-gcc_ada_s-osinte-openbsd_ads,v 1.1 2013/07/18 17:04:08 tobiasu E
+ end record;
+ pragma Convention (C, struct_timezone);
+
+ procedure usleep (useconds : unsigned_long);
+ pragma Import (C, usleep, "usleep");
+
+ -------------------------
+ -- Priority Scheduling --
+ -------------------------
@ -628,7 +625,7 @@ $OpenBSD: patch-gcc_ada_s-osinte-openbsd_ads,v 1.1 2013/07/18 17:04:08 tobiasu E
+ type pid_t is new int;
+ Self_PID : constant pid_t := 0;
+
+ type time_t is new long;
+ type time_t is new Long_Long_Integer;
+
+ type timespec is record
+ ts_sec : time_t;

View File

@ -0,0 +1,25 @@
$OpenBSD: patch-gcc_ada_s-osprim-posix_adb,v 1.1 2014/02/07 01:31:41 tobiasu Exp $
--- gcc/ada/s-osprim-posix.adb.orig Mon Jan 20 02:55:58 2014
+++ gcc/ada/s-osprim-posix.adb Mon Jan 20 02:56:39 2014
@@ -38,7 +38,7 @@ package body System.OS_Primitives is
-- these declarations in System.OS_Interface and move these ones in
-- the spec.
- type time_t is new Long_Integer;
+ type time_t is new Long_Long_Integer;
type timespec is record
tv_sec : time_t;
@@ -54,7 +54,11 @@ package body System.OS_Primitives is
-----------
function Clock return Duration is
- type timeval is array (1 .. 2) of Long_Integer;
+ type timeval is
+ record
+ tv_sec : time_t;
+ tv_usec : Long_Integer;
+ end record;
procedure timeval_to_duration
(T : not null access timeval;

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-gcc_ada_sysdep_c,v 1.1 2014/02/07 01:31:41 tobiasu Exp $
--- gcc/ada/sysdep.c.orig Mon Jan 20 01:02:25 2014
+++ gcc/ada/sysdep.c Mon Jan 20 01:02:58 2014
@@ -851,7 +851,7 @@ __gnat_localtime_tzoff (const time_t *timer, const int
struct tm */
#elif defined (__APPLE__) || defined (__FreeBSD__) || defined (linux) ||\
- defined (__GLIBC__)
+ defined (__GLIBC__) || defined (__OpenBSD__)
{
localtime_r (timer, &tp);
*off = tp.tm_gmtoff;