64bit-time compile error in sys/unix/sys_time.c

Hi,
short version:

Why does sys/unix/sys_time.c undefine _FILE_OFFSET_BITS and _LARGEFILE_SOURCE?

Long version:

I’m trying to cross compile for a 32bit ARM system using Yocto 4.3.1.

It seems that Yocto tools now set ‘-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64’
by default. I assume it is a Y2038 thing.

However, this throws an error in sys_time.c (using c92b340bb5):

arm-poky-linux-gnueabi-gcc -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 --sysroot=/opt/yocto/4.3.1/sysroots/cortexa9hf-neon-poky-linux-gnueabi -Werror=undef -Werror=implicit -Werror=return-type  -fno-strict-aliasing -fno-common -Os -I/u1/no_backup/otp_arm32/erts/arm-unknown-linux-gnueabi   -D_GNU_SOURCE  -DHAVE_CONFIG_H -Wall -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes -Wdeclaration-after-statement -DUSE_THREADS -D_THREAD_SAFE -D_REENTRANT -DPOSIX_THREADS -D_POSIX_THREAD_SAFE_FUNCTIONS  -DERLANG_GIT_VERSION="\"c92b340bb5\"" -Iarm-unknown-linux-gnueabi/opt/emu -Ibeam -Isys/unix -Isys/common -Iarm-unknown-linux-gnueabi -Ipcre -Iryu -Iopenssl/include -I../include -I../include/arm-unknown-linux-gnueabi -I../include/internal -I../include/internal/arm-unknown-linux-gnueabi -c sys/unix/sys_time.c -o obj/arm-unknown-linux-gnueabi/opt/emu/sys_time.o
In file included from /opt/yocto/4.3.1/sysroots/cortexa9hf-neon-poky-linux-gnueabi/usr/include/features.h:394,
                 from /opt/yocto/4.3.1/sysroots/cortexa9hf-neon-poky-linux-gnueabi/usr/include/bits/libc-header-start.h:33,
                 from /opt/yocto/4.3.1/sysroots/cortexa9hf-neon-poky-linux-gnueabi/usr/include/stdlib.h:26,
                 from sys/unix/sys_time.c:35:
/opt/yocto/4.3.1/sysroots/cortexa9hf-neon-poky-linux-gnueabi/usr/include/features-time64.h:26:5: error: #error "_TIME_BITS=64 is allowed only with _FILE_OFFSET_BITS=64"
   26 | #   error "_TIME_BITS=64 is allowed only with _FILE_OFFSET_BITS=64"
      |     ^~~~~
make[4]: *** [arm-unknown-linux-gnueabi/Makefile:912: obj/arm-unknown-linux-gnueabi/opt/emu/sys_time.o] Error 1
make[4]: Leaving directory '/u1/no_backup/otp_arm32/erts/emulator'

features-time64.h throws this error because _FILE_OFFSET_BITS is undefined :

#if defined _TIME_BITS
# if _TIME_BITS == 64
#  if ! defined (_FILE_OFFSET_BITS) || _FILE_OFFSET_BITS != 64
#   error "_TIME_BITS=64 is allowed only with _FILE_OFFSET_BITS=64"

_FILE_OFFSET_BITS and _LARGEFILE_SOURCE are both undefined early in sys_time.c.

The comment says “These need to be undef:ed to not break activation of micro
level process accounting on /proc/self” which, to me, is rather fuzzy.

This code seems to date back to the pre-git era, so git does not offer any
more clues.

If I comment out ‘#undef _FILE_OFFSET_BITS’ everything builds and boots.

But why are the undef’s there in the first place?

1 Like

That’s rather unclear, so I’ve opened a PR to see if whatever it tried to do is still an issue on modern systems (I suspect it isn’t). Thanks for your report!

1 Like

Thanks, I tried your patch on 26.2.
I have cross compiled for my 32bit ARM system and successfully booted using Yocto 4.0.14, 4.2.3 and 4.3.1 versions.

Great, let’s wait and see if it breaks anything :smiley:

Hi,

I can confirm that for Yocto based 32 bits machine architectures are also affected. Not only for 32 bits ARM.

If the tests went well, would it be possible to merge the patch into 26.x as well ?

Thanks.

It seems this workaround was added sometime between R10B and R11B, which is pre-git. Doesn’t the OTP team have access to the pre-git source code repository? (I forgot what it was called.)

Having said that, this code seems specific for Solaris, and possibly even Solaris < 10, so I think it might be appropriate to just delete it.

We don’t have access to clearcase anymore. We did for a couple of years after we migrated to git, but since we very rarely used it and it needs a server (and possibly license) to run it was shut down some years ago. So the best we have access to is otp-history.

otp-history gives me a 404.

I realize that you wouldn’t want to keep clearcase around indefinitely, what I meant was that you might have converted the repo to something open-source (like git or svn) in order to preserve history.

I didn’t realise that it was a private repo, I wonder why… anyway it is just a clone of GitHub - mfoemmel/erlang-otp: All of the public Erlang/OTP source releases (since R6B-0 in 1999) in convenient git form (created this way: Extending the history of Erlang OTP · erlang/otp Wiki · GitHub)

I (fortunately?) did not get to use clearcase all that much, but from what I’ve understood it is significantly different from how git/svn/anyotherVCS works that any type of export would have been hard to do… and thus all that information has been lost.

1 Like