https://gcc.gnu.org/g:8fc9e03a70fd08b54449b05833b00e7f8ad01c25
commit r16-1064-g8fc9e03a70fd08b54449b05833b00e7f8ad01c25 Author: Robert Dubner <rdub...@symas.com> Date: Mon Jun 2 15:55:20 2025 -0400 cobol: Honor HAVE_CLOCK_GETTIME and HAVE_GETTIMEOFDAY. [PR119975] These changes cause genapi.cc to use whichever of clock_gettime() or gettimeofday() are available. This prevents compilation errors on systems where clock_gettime() is not available. gcc/cobol/ChangeLog: PR cobol/119975 * genapi.cc (parser_intrinsic_call_0): Use get_time_64() function. * genutil.cc (get_time_64): Definition created. * genutil.h (get_time_64): Declaration created. Diff: --- gcc/cobol/genapi.cc | 4 +++- gcc/cobol/genutil.cc | 23 +++++++++++++++++++++++ gcc/cobol/genutil.h | 3 +++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index 2ce9cad5c0d6..5e983ab503c2 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -10491,7 +10491,9 @@ parser_intrinsic_call_0(cbl_field_t *tgt, { // Pass __gg__when_compiled() the time from right now. struct timespec tp; - clock_gettime(CLOCK_REALTIME, &tp); // time_t tv_sec; long tv_nsec + uint64_t now = get_time_64(); + tp.tv_sec = now / 1000000000; + tp.tv_nsec = now % 1000000000; store_location_stuff(function_name); gg_call(VOID, diff --git a/gcc/cobol/genutil.cc b/gcc/cobol/genutil.cc index d0aaf2b3215f..e971043164c7 100644 --- a/gcc/cobol/genutil.cc +++ b/gcc/cobol/genutil.cc @@ -2119,3 +2119,26 @@ qualified_data_location(cbl_refer_t &refer) return gg_add(member(refer.field->var_decl_node, "data"), refer_offset(refer)); } + +uint64_t +get_time_64() +{ + // This code was unabashedly stolen from gcc/timevar.cc. + // It returns the Unix epoch with nine decimal places. + + uint64_t retval = 0; + +#ifdef HAVE_CLOCK_GETTIME + struct timespec ts; + clock_gettime (CLOCK_REALTIME, &ts); + retval = ts.tv_sec * 1000000000 + ts.tv_nsec; + return retval; +#endif +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv; + gettimeofday (&tv, NULL); + retval = tv.tv_sec * 1000000000 + tv.tv_usec * 1000; + return retval; +#endif + return retval; +} \ No newline at end of file diff --git a/gcc/cobol/genutil.h b/gcc/cobol/genutil.h index 2f4bc36eace7..43102d7cc544 100644 --- a/gcc/cobol/genutil.h +++ b/gcc/cobol/genutil.h @@ -155,4 +155,7 @@ void build_array_of_fourplets( int ngroup, size_t N, cbl_refer_t *refers); void get_depending_on_value_from_odo(tree retval, cbl_field_t *odo); +uint64_t get_time_64(); + + #endif