diff mbox series

[RFC,1/3] Try to ensure 64 bit time on 32 bit glibcful hosts

Message ID 20221108000828.42824-1-niko.mauno@vaisala.com
State New
Headers show
Series [RFC,1/3] Try to ensure 64 bit time on 32 bit glibcful hosts | expand

Commit Message

Niko Mauno Nov. 8, 2022, 12:08 a.m. UTC
Add default C Preprocessor flags that ensure Y2038 compatible 64 bit
time on 32 bit host applications when glibc is used. Prerequisites
are glibc version 2.34 or newer and Linux kernel version 5.1 or newer.

Example of impact on 32 bit 'qemuarm' machine running
core-image-minimal. Before this change:

  root@qemuarm:~# /bin/busybox date
  Sun Nov  6 06:09:39 UTC 2022
  root@qemuarm:~# /sbin/hwclock.util-linux -w
  root@qemuarm:~# /sbin/hwclock.util-linux
  2022-11-06 06:09:49.994249+00:00
  root@qemuarm:~# /bin/busybox date -s 2040-01-01
  date: invalid date '2040-01-01'
  root@qemuarm:~# /bin/date.coreutils -s 2040-01-01
  Sun Jan  1 00:00:00 UTC 2040
  root@qemuarm:~# /sbin/hwclock.util-linux -w
  root@qemuarm:~# /sbin/hwclock.util-linux
  1931-03-04 06:26:23.000000+00:00
  root@qemuarm:~#

After this change:

  root@qemuarm:~# /bin/busybox date
  Sun Nov  6 06:02:20 UTC 2022
  root@qemuarm:~# /sbin/hwclock.util-linux -w
  root@qemuarm:~# /sbin/hwclock.util-linux
  2022-11-06 06:02:27.989730+00:00
  root@qemuarm:~# /bin/busybox date -s 2040-01-01
  Sun Jan  1 00:00:00 UTC 2040
  root@qemuarm:~# /sbin/hwclock.util-linux -w
  root@qemuarm:~# /sbin/hwclock.util-linux
  2040-01-01 00:00:20.992954+00:00
  root@qemuarm:~#

From here on, the adding of new flags can be disabled on recipe or
global level by resetting the value of associated variable containing
the CPPFLAGS specific for 64 bit time

  GLIBC_64BIT_TIME_CPPFLAGS = ""

which can be useful e.g. when working around failure to compile a
component due to lack of 64 bit time support on 32 bit build in the
component's source code.

Signed-off-by: Niko Mauno <niko.mauno@vaisala.com>
---
 meta/conf/distro/include/tclibc-glibc.inc        | 3 +++
 meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb | 2 ++
 meta/recipes-devtools/pseudo/pseudo_git.bb       | 2 ++
 3 files changed, 7 insertions(+)

Comments

Khem Raj Nov. 8, 2022, 3:30 a.m. UTC | #1
On Mon, Nov 7, 2022 at 4:09 PM Niko Mauno via lists.openembedded.org
<niko.mauno=vaisala.com@lists.openembedded.org> wrote:
>
> Add default C Preprocessor flags that ensure Y2038 compatible 64 bit
> time on 32 bit host applications when glibc is used. Prerequisites
> are glibc version 2.34 or newer and Linux kernel version 5.1 or newer.
>
> Example of impact on 32 bit 'qemuarm' machine running
> core-image-minimal. Before this change:
>
>   root@qemuarm:~# /bin/busybox date
>   Sun Nov  6 06:09:39 UTC 2022
>   root@qemuarm:~# /sbin/hwclock.util-linux -w
>   root@qemuarm:~# /sbin/hwclock.util-linux
>   2022-11-06 06:09:49.994249+00:00
>   root@qemuarm:~# /bin/busybox date -s 2040-01-01
>   date: invalid date '2040-01-01'
>   root@qemuarm:~# /bin/date.coreutils -s 2040-01-01
>   Sun Jan  1 00:00:00 UTC 2040
>   root@qemuarm:~# /sbin/hwclock.util-linux -w
>   root@qemuarm:~# /sbin/hwclock.util-linux
>   1931-03-04 06:26:23.000000+00:00
>   root@qemuarm:~#
>
> After this change:
>
>   root@qemuarm:~# /bin/busybox date
>   Sun Nov  6 06:02:20 UTC 2022
>   root@qemuarm:~# /sbin/hwclock.util-linux -w
>   root@qemuarm:~# /sbin/hwclock.util-linux
>   2022-11-06 06:02:27.989730+00:00
>   root@qemuarm:~# /bin/busybox date -s 2040-01-01
>   Sun Jan  1 00:00:00 UTC 2040
>   root@qemuarm:~# /sbin/hwclock.util-linux -w
>   root@qemuarm:~# /sbin/hwclock.util-linux
>   2040-01-01 00:00:20.992954+00:00
>   root@qemuarm:~#
>
> From here on, the adding of new flags can be disabled on recipe or
> global level by resetting the value of associated variable containing
> the CPPFLAGS specific for 64 bit time
>
>   GLIBC_64BIT_TIME_CPPFLAGS = ""
>
> which can be useful e.g. when working around failure to compile a
> component due to lack of 64 bit time support on 32 bit build in the
> component's source code.
>
> Signed-off-by: Niko Mauno <niko.mauno@vaisala.com>
> ---
>  meta/conf/distro/include/tclibc-glibc.inc        | 3 +++
>  meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb | 2 ++
>  meta/recipes-devtools/pseudo/pseudo_git.bb       | 2 ++
>  3 files changed, 7 insertions(+)
>
> diff --git a/meta/conf/distro/include/tclibc-glibc.inc b/meta/conf/distro/include/tclibc-glibc.inc
> index f48d16939e..95770298e9 100644
> --- a/meta/conf/distro/include/tclibc-glibc.inc
> +++ b/meta/conf/distro/include/tclibc-glibc.inc
> @@ -17,6 +17,9 @@ PREFERRED_PROVIDER_virtual/crypt ?= "libxcrypt"
>
>  CXXFLAGS += "-fvisibility-inlines-hidden"
>
> +GLIBC_64BIT_TIME_CPPFLAGS = "-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64"
> +TARGET_CPPFLAGS += "${GLIBC_64BIT_TIME_CPPFLAGS}"

We only need it for 32bit systems and not for 64bit systems. So
perhaps we need it for only 32bit systems.

> +
>  LIBC_DEPENDENCIES = "\
>                      glibc \
>                      glibc-dbg \
> diff --git a/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb b/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
> index 8bda2ccad6..b3fafa0ea4 100644
> --- a/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
> +++ b/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
> @@ -5,3 +5,5 @@ require gcc-sanitizers.inc
>  # sanitizer_linux.s:5749: Error: lo register required -- `ldr ip,[sp],#8'
>  ARM_INSTRUCTION_SET:armv4 = "arm"
>  ARM_INSTRUCTION_SET:armv5 = "arm"
> +
> +GLIBC_64BIT_TIME_CPPFLAGS = ""
> diff --git a/meta/recipes-devtools/pseudo/pseudo_git.bb b/meta/recipes-devtools/pseudo/pseudo_git.bb
> index c34580b4ff..7734d0fbb0 100644
> --- a/meta/recipes-devtools/pseudo/pseudo_git.bb
> +++ b/meta/recipes-devtools/pseudo/pseudo_git.bb
> @@ -19,3 +19,5 @@ PV = "1.9.0+git${SRCPV}"
>
>  # error: use of undeclared identifier '_STAT_VER'
>  COMPATIBLE_HOST:libc-musl = 'null'
> +
> +GLIBC_64BIT_TIME_CPPFLAGS = ""
> --
> 2.36.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#172939): https://lists.openembedded.org/g/openembedded-core/message/172939
> Mute This Topic: https://lists.openembedded.org/mt/94880624/1997914
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [raj.khem@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Ola x Nilsson Nov. 8, 2022, 10:51 a.m. UTC | #2
I'm working on the same thing, but I put GLIBC_64BIT_TIME_CPPFLAGS in
TARGET_CC_ARCH instead to make sure they applied everywhere.

I'd be interested to hear what others think is the best place to put
these flags.

I'm also looking at QA tests to make sure that no application or shared
object is still using 32bit time or file functions from glibc.

/Ola

On Tue, Nov 08 2022, Niko Mauno via lists.openembedded.org wrote:

> Add default C Preprocessor flags that ensure Y2038 compatible 64 bit
> time on 32 bit host applications when glibc is used. Prerequisites
> are glibc version 2.34 or newer and Linux kernel version 5.1 or newer.
>
> Example of impact on 32 bit 'qemuarm' machine running
> core-image-minimal. Before this change:
>
>   root@qemuarm:~# /bin/busybox date
>   Sun Nov  6 06:09:39 UTC 2022
>   root@qemuarm:~# /sbin/hwclock.util-linux -w
>   root@qemuarm:~# /sbin/hwclock.util-linux
>   2022-11-06 06:09:49.994249+00:00
>   root@qemuarm:~# /bin/busybox date -s 2040-01-01
>   date: invalid date '2040-01-01'
>   root@qemuarm:~# /bin/date.coreutils -s 2040-01-01
>   Sun Jan  1 00:00:00 UTC 2040
>   root@qemuarm:~# /sbin/hwclock.util-linux -w
>   root@qemuarm:~# /sbin/hwclock.util-linux
>   1931-03-04 06:26:23.000000+00:00
>   root@qemuarm:~#
>
> After this change:
>
>   root@qemuarm:~# /bin/busybox date
>   Sun Nov  6 06:02:20 UTC 2022
>   root@qemuarm:~# /sbin/hwclock.util-linux -w
>   root@qemuarm:~# /sbin/hwclock.util-linux
>   2022-11-06 06:02:27.989730+00:00
>   root@qemuarm:~# /bin/busybox date -s 2040-01-01
>   Sun Jan  1 00:00:00 UTC 2040
>   root@qemuarm:~# /sbin/hwclock.util-linux -w
>   root@qemuarm:~# /sbin/hwclock.util-linux
>   2040-01-01 00:00:20.992954+00:00
>   root@qemuarm:~#
>
> From here on, the adding of new flags can be disabled on recipe or
> global level by resetting the value of associated variable containing
> the CPPFLAGS specific for 64 bit time
>
>   GLIBC_64BIT_TIME_CPPFLAGS = ""
>
> which can be useful e.g. when working around failure to compile a
> component due to lack of 64 bit time support on 32 bit build in the
> component's source code.
>
> Signed-off-by: Niko Mauno <niko.mauno@vaisala.com>
> ---
>  meta/conf/distro/include/tclibc-glibc.inc        | 3 +++
>  meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb | 2 ++
>  meta/recipes-devtools/pseudo/pseudo_git.bb       | 2 ++
>  3 files changed, 7 insertions(+)
>
> diff --git a/meta/conf/distro/include/tclibc-glibc.inc b/meta/conf/distro/include/tclibc-glibc.inc
> index f48d16939e..95770298e9 100644
> --- a/meta/conf/distro/include/tclibc-glibc.inc
> +++ b/meta/conf/distro/include/tclibc-glibc.inc
> @@ -17,6 +17,9 @@ PREFERRED_PROVIDER_virtual/crypt ?= "libxcrypt"
>  
>  CXXFLAGS += "-fvisibility-inlines-hidden"
>  
> +GLIBC_64BIT_TIME_CPPFLAGS = "-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64"
> +TARGET_CPPFLAGS += "${GLIBC_64BIT_TIME_CPPFLAGS}"
> +
>  LIBC_DEPENDENCIES = "\
>  		     glibc \
>  		     glibc-dbg \
> diff --git a/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb b/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
> index 8bda2ccad6..b3fafa0ea4 100644
> --- a/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
> +++ b/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
> @@ -5,3 +5,5 @@ require gcc-sanitizers.inc
>  # sanitizer_linux.s:5749: Error: lo register required -- `ldr ip,[sp],#8'
>  ARM_INSTRUCTION_SET:armv4 = "arm"
>  ARM_INSTRUCTION_SET:armv5 = "arm"
> +
> +GLIBC_64BIT_TIME_CPPFLAGS = ""
> diff --git a/meta/recipes-devtools/pseudo/pseudo_git.bb b/meta/recipes-devtools/pseudo/pseudo_git.bb
> index c34580b4ff..7734d0fbb0 100644
> --- a/meta/recipes-devtools/pseudo/pseudo_git.bb
> +++ b/meta/recipes-devtools/pseudo/pseudo_git.bb
> @@ -19,3 +19,5 @@ PV = "1.9.0+git${SRCPV}"
>  
>  # error: use of undeclared identifier '_STAT_VER'
>  COMPATIBLE_HOST:libc-musl = 'null'
> +
> +GLIBC_64BIT_TIME_CPPFLAGS = ""
Khem Raj Nov. 8, 2022, 4:38 p.m. UTC | #3
On Tue, Nov 8, 2022 at 2:56 AM Ola x Nilsson <ola.x.nilsson@axis.com> wrote:
>
>
> I'm working on the same thing, but I put GLIBC_64BIT_TIME_CPPFLAGS in
> TARGET_CC_ARCH instead to make sure they applied everywhere.
>
> I'd be interested to hear what others think is the best place to put
> these flags.
>
> I'm also looking at QA tests to make sure that no application or shared
> object is still using 32bit time or file functions from glibc.

Perhaps another thing is that it might be good to control it via a
distro feature.

>
> /Ola
>
> On Tue, Nov 08 2022, Niko Mauno via lists.openembedded.org wrote:
>
> > Add default C Preprocessor flags that ensure Y2038 compatible 64 bit
> > time on 32 bit host applications when glibc is used. Prerequisites
> > are glibc version 2.34 or newer and Linux kernel version 5.1 or newer.
> >
> > Example of impact on 32 bit 'qemuarm' machine running
> > core-image-minimal. Before this change:
> >
> >   root@qemuarm:~# /bin/busybox date
> >   Sun Nov  6 06:09:39 UTC 2022
> >   root@qemuarm:~# /sbin/hwclock.util-linux -w
> >   root@qemuarm:~# /sbin/hwclock.util-linux
> >   2022-11-06 06:09:49.994249+00:00
> >   root@qemuarm:~# /bin/busybox date -s 2040-01-01
> >   date: invalid date '2040-01-01'
> >   root@qemuarm:~# /bin/date.coreutils -s 2040-01-01
> >   Sun Jan  1 00:00:00 UTC 2040
> >   root@qemuarm:~# /sbin/hwclock.util-linux -w
> >   root@qemuarm:~# /sbin/hwclock.util-linux
> >   1931-03-04 06:26:23.000000+00:00
> >   root@qemuarm:~#
> >
> > After this change:
> >
> >   root@qemuarm:~# /bin/busybox date
> >   Sun Nov  6 06:02:20 UTC 2022
> >   root@qemuarm:~# /sbin/hwclock.util-linux -w
> >   root@qemuarm:~# /sbin/hwclock.util-linux
> >   2022-11-06 06:02:27.989730+00:00
> >   root@qemuarm:~# /bin/busybox date -s 2040-01-01
> >   Sun Jan  1 00:00:00 UTC 2040
> >   root@qemuarm:~# /sbin/hwclock.util-linux -w
> >   root@qemuarm:~# /sbin/hwclock.util-linux
> >   2040-01-01 00:00:20.992954+00:00
> >   root@qemuarm:~#
> >
> > From here on, the adding of new flags can be disabled on recipe or
> > global level by resetting the value of associated variable containing
> > the CPPFLAGS specific for 64 bit time
> >
> >   GLIBC_64BIT_TIME_CPPFLAGS = ""
> >
> > which can be useful e.g. when working around failure to compile a
> > component due to lack of 64 bit time support on 32 bit build in the
> > component's source code.
> >
> > Signed-off-by: Niko Mauno <niko.mauno@vaisala.com>
> > ---
> >  meta/conf/distro/include/tclibc-glibc.inc        | 3 +++
> >  meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb | 2 ++
> >  meta/recipes-devtools/pseudo/pseudo_git.bb       | 2 ++
> >  3 files changed, 7 insertions(+)
> >
> > diff --git a/meta/conf/distro/include/tclibc-glibc.inc b/meta/conf/distro/include/tclibc-glibc.inc
> > index f48d16939e..95770298e9 100644
> > --- a/meta/conf/distro/include/tclibc-glibc.inc
> > +++ b/meta/conf/distro/include/tclibc-glibc.inc
> > @@ -17,6 +17,9 @@ PREFERRED_PROVIDER_virtual/crypt ?= "libxcrypt"
> >
> >  CXXFLAGS += "-fvisibility-inlines-hidden"
> >
> > +GLIBC_64BIT_TIME_CPPFLAGS = "-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64"
> > +TARGET_CPPFLAGS += "${GLIBC_64BIT_TIME_CPPFLAGS}"
> > +
> >  LIBC_DEPENDENCIES = "\
> >                    glibc \
> >                    glibc-dbg \
> > diff --git a/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb b/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
> > index 8bda2ccad6..b3fafa0ea4 100644
> > --- a/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
> > +++ b/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
> > @@ -5,3 +5,5 @@ require gcc-sanitizers.inc
> >  # sanitizer_linux.s:5749: Error: lo register required -- `ldr ip,[sp],#8'
> >  ARM_INSTRUCTION_SET:armv4 = "arm"
> >  ARM_INSTRUCTION_SET:armv5 = "arm"
> > +
> > +GLIBC_64BIT_TIME_CPPFLAGS = ""
> > diff --git a/meta/recipes-devtools/pseudo/pseudo_git.bb b/meta/recipes-devtools/pseudo/pseudo_git.bb
> > index c34580b4ff..7734d0fbb0 100644
> > --- a/meta/recipes-devtools/pseudo/pseudo_git.bb
> > +++ b/meta/recipes-devtools/pseudo/pseudo_git.bb
> > @@ -19,3 +19,5 @@ PV = "1.9.0+git${SRCPV}"
> >
> >  # error: use of undeclared identifier '_STAT_VER'
> >  COMPATIBLE_HOST:libc-musl = 'null'
> > +
> > +GLIBC_64BIT_TIME_CPPFLAGS = ""
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#172959): https://lists.openembedded.org/g/openembedded-core/message/172959
> Mute This Topic: https://lists.openembedded.org/mt/94880624/1997914
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [raj.khem@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Niko Mauno Nov. 9, 2022, 6:33 a.m. UTC | #4
On related note, in this RFC series I was basing on reference set in 
https://github.com/lmajewski/meta-y2038/blob/master/conf/distro/y2038.inc#L8 
where the author has opted to use TARGET_CPPFLAGS.

-Niko

On 11/8/22 12:51, Ola x Nilsson wrote:
> 
> I'm working on the same thing, but I put GLIBC_64BIT_TIME_CPPFLAGS in
> TARGET_CC_ARCH instead to make sure they applied everywhere.
> 
> I'd be interested to hear what others think is the best place to put
> these flags.
> 
> I'm also looking at QA tests to make sure that no application or shared
> object is still using 32bit time or file functions from glibc.
> 
> /Ola
> 
> On Tue, Nov 08 2022, Niko Mauno via lists.openembedded.org wrote:
> 
>> Add default C Preprocessor flags that ensure Y2038 compatible 64 bit
>> time on 32 bit host applications when glibc is used. Prerequisites
>> are glibc version 2.34 or newer and Linux kernel version 5.1 or newer.
>>
>> Example of impact on 32 bit 'qemuarm' machine running
>> core-image-minimal. Before this change:
>>
>>    root@qemuarm:~# /bin/busybox date
>>    Sun Nov  6 06:09:39 UTC 2022
>>    root@qemuarm:~# /sbin/hwclock.util-linux -w
>>    root@qemuarm:~# /sbin/hwclock.util-linux
>>    2022-11-06 06:09:49.994249+00:00
>>    root@qemuarm:~# /bin/busybox date -s 2040-01-01
>>    date: invalid date '2040-01-01'
>>    root@qemuarm:~# /bin/date.coreutils -s 2040-01-01
>>    Sun Jan  1 00:00:00 UTC 2040
>>    root@qemuarm:~# /sbin/hwclock.util-linux -w
>>    root@qemuarm:~# /sbin/hwclock.util-linux
>>    1931-03-04 06:26:23.000000+00:00
>>    root@qemuarm:~#
>>
>> After this change:
>>
>>    root@qemuarm:~# /bin/busybox date
>>    Sun Nov  6 06:02:20 UTC 2022
>>    root@qemuarm:~# /sbin/hwclock.util-linux -w
>>    root@qemuarm:~# /sbin/hwclock.util-linux
>>    2022-11-06 06:02:27.989730+00:00
>>    root@qemuarm:~# /bin/busybox date -s 2040-01-01
>>    Sun Jan  1 00:00:00 UTC 2040
>>    root@qemuarm:~# /sbin/hwclock.util-linux -w
>>    root@qemuarm:~# /sbin/hwclock.util-linux
>>    2040-01-01 00:00:20.992954+00:00
>>    root@qemuarm:~#
>>
>>  From here on, the adding of new flags can be disabled on recipe or
>> global level by resetting the value of associated variable containing
>> the CPPFLAGS specific for 64 bit time
>>
>>    GLIBC_64BIT_TIME_CPPFLAGS = ""
>>
>> which can be useful e.g. when working around failure to compile a
>> component due to lack of 64 bit time support on 32 bit build in the
>> component's source code.
>>
>> Signed-off-by: Niko Mauno <niko.mauno@vaisala.com>
>> ---
>>   meta/conf/distro/include/tclibc-glibc.inc        | 3 +++
>>   meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb | 2 ++
>>   meta/recipes-devtools/pseudo/pseudo_git.bb       | 2 ++
>>   3 files changed, 7 insertions(+)
>>
>> diff --git a/meta/conf/distro/include/tclibc-glibc.inc b/meta/conf/distro/include/tclibc-glibc.inc
>> index f48d16939e..95770298e9 100644
>> --- a/meta/conf/distro/include/tclibc-glibc.inc
>> +++ b/meta/conf/distro/include/tclibc-glibc.inc
>> @@ -17,6 +17,9 @@ PREFERRED_PROVIDER_virtual/crypt ?= "libxcrypt"
>>   
>>   CXXFLAGS += "-fvisibility-inlines-hidden"
>>   
>> +GLIBC_64BIT_TIME_CPPFLAGS = "-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64"
>> +TARGET_CPPFLAGS += "${GLIBC_64BIT_TIME_CPPFLAGS}"
>> +
>>   LIBC_DEPENDENCIES = "\
>>   		     glibc \
>>   		     glibc-dbg \
>> diff --git a/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb b/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
>> index 8bda2ccad6..b3fafa0ea4 100644
>> --- a/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
>> +++ b/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
>> @@ -5,3 +5,5 @@ require gcc-sanitizers.inc
>>   # sanitizer_linux.s:5749: Error: lo register required -- `ldr ip,[sp],#8'
>>   ARM_INSTRUCTION_SET:armv4 = "arm"
>>   ARM_INSTRUCTION_SET:armv5 = "arm"
>> +
>> +GLIBC_64BIT_TIME_CPPFLAGS = ""
>> diff --git a/meta/recipes-devtools/pseudo/pseudo_git.bb b/meta/recipes-devtools/pseudo/pseudo_git.bb
>> index c34580b4ff..7734d0fbb0 100644
>> --- a/meta/recipes-devtools/pseudo/pseudo_git.bb
>> +++ b/meta/recipes-devtools/pseudo/pseudo_git.bb
>> @@ -19,3 +19,5 @@ PV = "1.9.0+git${SRCPV}"
>>   
>>   # error: use of undeclared identifier '_STAT_VER'
>>   COMPATIBLE_HOST:libc-musl = 'null'
>> +
>> +GLIBC_64BIT_TIME_CPPFLAGS = ""
> 
> 
> 
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#172959): https://lists.openembedded.org/g/openembedded-core/message/172959
> Mute This Topic: https://lists.openembedded.org/mt/94880624/3618026
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [niko.mauno@iki.fi]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Alexandre Belloni Nov. 9, 2022, 3:47 p.m. UTC | #5
On 08/11/2022 11:51:58+0100, Ola x Nilsson wrote:
> 
> I'm working on the same thing, but I put GLIBC_64BIT_TIME_CPPFLAGS in
> TARGET_CC_ARCH instead to make sure they applied everywhere.
> 


I would not provide a feature to allow building a recipe without a 64
bits time_t, it is going to build but will fail to run properly so it is
way better to fail at compile time.

> I'd be interested to hear what others think is the best place to put
> these flags.
> 
> I'm also looking at QA tests to make sure that no application or shared
> object is still using 32bit time or file functions from glibc.
> 
> /Ola
> 
> On Tue, Nov 08 2022, Niko Mauno via lists.openembedded.org wrote:
> 
> > Add default C Preprocessor flags that ensure Y2038 compatible 64 bit
> > time on 32 bit host applications when glibc is used. Prerequisites
> > are glibc version 2.34 or newer and Linux kernel version 5.1 or newer.
> >
> > Example of impact on 32 bit 'qemuarm' machine running
> > core-image-minimal. Before this change:
> >
> >   root@qemuarm:~# /bin/busybox date
> >   Sun Nov  6 06:09:39 UTC 2022
> >   root@qemuarm:~# /sbin/hwclock.util-linux -w
> >   root@qemuarm:~# /sbin/hwclock.util-linux
> >   2022-11-06 06:09:49.994249+00:00
> >   root@qemuarm:~# /bin/busybox date -s 2040-01-01
> >   date: invalid date '2040-01-01'
> >   root@qemuarm:~# /bin/date.coreutils -s 2040-01-01
> >   Sun Jan  1 00:00:00 UTC 2040
> >   root@qemuarm:~# /sbin/hwclock.util-linux -w
> >   root@qemuarm:~# /sbin/hwclock.util-linux
> >   1931-03-04 06:26:23.000000+00:00
> >   root@qemuarm:~#
> >
> > After this change:
> >
> >   root@qemuarm:~# /bin/busybox date
> >   Sun Nov  6 06:02:20 UTC 2022
> >   root@qemuarm:~# /sbin/hwclock.util-linux -w
> >   root@qemuarm:~# /sbin/hwclock.util-linux
> >   2022-11-06 06:02:27.989730+00:00
> >   root@qemuarm:~# /bin/busybox date -s 2040-01-01
> >   Sun Jan  1 00:00:00 UTC 2040
> >   root@qemuarm:~# /sbin/hwclock.util-linux -w
> >   root@qemuarm:~# /sbin/hwclock.util-linux
> >   2040-01-01 00:00:20.992954+00:00
> >   root@qemuarm:~#
> >

Be careful because there is no guarantee hwclock is testing what you
want to test. The actual result depends on the RTC which may fail before
2038 anyway.

Note that if your system is using systemd, it will anyway fail in 2038.

> > From here on, the adding of new flags can be disabled on recipe or
> > global level by resetting the value of associated variable containing
> > the CPPFLAGS specific for 64 bit time
> >
> >   GLIBC_64BIT_TIME_CPPFLAGS = ""
> >
> > which can be useful e.g. when working around failure to compile a
> > component due to lack of 64 bit time support on 32 bit build in the
> > component's source code.
> >
> > Signed-off-by: Niko Mauno <niko.mauno@vaisala.com>
> > ---
> >  meta/conf/distro/include/tclibc-glibc.inc        | 3 +++
> >  meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb | 2 ++
> >  meta/recipes-devtools/pseudo/pseudo_git.bb       | 2 ++
> >  3 files changed, 7 insertions(+)
> >
> > diff --git a/meta/conf/distro/include/tclibc-glibc.inc b/meta/conf/distro/include/tclibc-glibc.inc
> > index f48d16939e..95770298e9 100644
> > --- a/meta/conf/distro/include/tclibc-glibc.inc
> > +++ b/meta/conf/distro/include/tclibc-glibc.inc
> > @@ -17,6 +17,9 @@ PREFERRED_PROVIDER_virtual/crypt ?= "libxcrypt"
> >  
> >  CXXFLAGS += "-fvisibility-inlines-hidden"
> >  
> > +GLIBC_64BIT_TIME_CPPFLAGS = "-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64"
> > +TARGET_CPPFLAGS += "${GLIBC_64BIT_TIME_CPPFLAGS}"
> > +
> >  LIBC_DEPENDENCIES = "\
> >  		     glibc \
> >  		     glibc-dbg \
> > diff --git a/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb b/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
> > index 8bda2ccad6..b3fafa0ea4 100644
> > --- a/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
> > +++ b/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
> > @@ -5,3 +5,5 @@ require gcc-sanitizers.inc
> >  # sanitizer_linux.s:5749: Error: lo register required -- `ldr ip,[sp],#8'
> >  ARM_INSTRUCTION_SET:armv4 = "arm"
> >  ARM_INSTRUCTION_SET:armv5 = "arm"
> > +
> > +GLIBC_64BIT_TIME_CPPFLAGS = ""
> > diff --git a/meta/recipes-devtools/pseudo/pseudo_git.bb b/meta/recipes-devtools/pseudo/pseudo_git.bb
> > index c34580b4ff..7734d0fbb0 100644
> > --- a/meta/recipes-devtools/pseudo/pseudo_git.bb
> > +++ b/meta/recipes-devtools/pseudo/pseudo_git.bb
> > @@ -19,3 +19,5 @@ PV = "1.9.0+git${SRCPV}"
> >  
> >  # error: use of undeclared identifier '_STAT_VER'
> >  COMPATIBLE_HOST:libc-musl = 'null'
> > +
> > +GLIBC_64BIT_TIME_CPPFLAGS = ""
> 

> 
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#172959): https://lists.openembedded.org/g/openembedded-core/message/172959
> Mute This Topic: https://lists.openembedded.org/mt/94880624/3617179
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [alexandre.belloni@bootlin.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
diff mbox series

Patch

diff --git a/meta/conf/distro/include/tclibc-glibc.inc b/meta/conf/distro/include/tclibc-glibc.inc
index f48d16939e..95770298e9 100644
--- a/meta/conf/distro/include/tclibc-glibc.inc
+++ b/meta/conf/distro/include/tclibc-glibc.inc
@@ -17,6 +17,9 @@  PREFERRED_PROVIDER_virtual/crypt ?= "libxcrypt"
 
 CXXFLAGS += "-fvisibility-inlines-hidden"
 
+GLIBC_64BIT_TIME_CPPFLAGS = "-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64"
+TARGET_CPPFLAGS += "${GLIBC_64BIT_TIME_CPPFLAGS}"
+
 LIBC_DEPENDENCIES = "\
 		     glibc \
 		     glibc-dbg \
diff --git a/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb b/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
index 8bda2ccad6..b3fafa0ea4 100644
--- a/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
+++ b/meta/recipes-devtools/gcc/gcc-sanitizers_12.2.bb
@@ -5,3 +5,5 @@  require gcc-sanitizers.inc
 # sanitizer_linux.s:5749: Error: lo register required -- `ldr ip,[sp],#8'
 ARM_INSTRUCTION_SET:armv4 = "arm"
 ARM_INSTRUCTION_SET:armv5 = "arm"
+
+GLIBC_64BIT_TIME_CPPFLAGS = ""
diff --git a/meta/recipes-devtools/pseudo/pseudo_git.bb b/meta/recipes-devtools/pseudo/pseudo_git.bb
index c34580b4ff..7734d0fbb0 100644
--- a/meta/recipes-devtools/pseudo/pseudo_git.bb
+++ b/meta/recipes-devtools/pseudo/pseudo_git.bb
@@ -19,3 +19,5 @@  PV = "1.9.0+git${SRCPV}"
 
 # error: use of undeclared identifier '_STAT_VER'
 COMPATIBLE_HOST:libc-musl = 'null'
+
+GLIBC_64BIT_TIME_CPPFLAGS = ""