Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails if gmtime_s() or gmtime_r() are not available #1907

Closed
RonEld opened this issue Jul 31, 2018 · 7 comments
Closed

Build fails if gmtime_s() or gmtime_r() are not available #1907

RonEld opened this issue Jul 31, 2018 · 7 comments
Labels

Comments

@RonEld
Copy link
Contributor

RonEld commented Jul 31, 2018

Description

  • Type: Bug
  • Priority: Major

Bug

OS
Mbed OS
mbed TLS build:
Version: 2.12.0
Compiler and options (if you used a pre-built binary, please indicate how you obtained it): ARM Compiler
Additional environment information:

Expected behavior
build to succeed
Actual behavior
build failure:

"/tmp/H7cWpV", line 124 (column 3): Warning: L6312W: Empty Execution region description for region RW_IRAM1
Error: L6218E: Undefined symbol gmtime_r (referred from BUILD/K64F/ARM/mbed-os/features/mbedtls/src/x509.o).
Finished: 0 information, 1 warning and 1 error messages.
[ERROR] "/tmp/H7cWpV", line 124 (column 3): Warning: L6312W: Empty Execution region description for region RW_IRAM1
Error: L6218E: Undefined symbol gmtime_r (referred from BUILD/K64F/ARM/mbed-os/features/mbedtls/src/x509.o).

Steps to reproduce
build an mbed OS application, with Mbed TLS 2.12.0, using mbed-cli

This is from change introduced in 512b4ee

@ciarmcom
Copy link

ARM Internal Ref: IOTSSL-2436

@gilles-peskine-arm
Copy link
Contributor

That's not a problem with armcc, it's a problem with libc compatibility. If the toolchain makes a difference, it's because it's picking up a different libc. gmtime_r is a POSIX function, not a standard C function. It's legitimate for a libc to have gmtime but not gmtime_r. We should use gmtime_r where it's present and gmtime otherwise.

@gilles-peskine-arm
Copy link
Contributor

The documentation for MBEDTLS_HAVE_TIME_DATE states:

System has time.h and time(), gmtime() and the clock is correct.

#1198 added the requirement that the platform must have gmtime_r or gmtime_s, but didn't change the documentation. I do think we should support MBEDTLS_HAVE_TIME_DATE on platforms with gmtime only. Mbed OS is a pretty compelling use case.

@andresag01
Copy link
Contributor

To expand on the information above:

  • This problem occurs with Mbed TLS version 2.12.0 and the current Mbed OS master (1023280)
  • As @gilles-peskine-arm, this is a problem with the libc used to build Mbed OS and Mbed TLS as gmtime_r is a POSIX function
  • I have tested and can confirm that the problem happens with the Mbed OS cli toolchain options uARM and ARM. I suspect the problem also happens with IAR and ARMC6, but I have not tested this.
  • From the Mbed TLS side, the issue was introduced in gmtime_r and mbedtls_time on Windows #1198, and from the Mbed OS side the issue was introduced in Integrate mbed OS RTC with mbed TLS ARMmbed/mbed-os#4846 which enables MBEDTLS_HAVE_TIME_DATE

@gilles-peskine-arm: I agree that the problem can be solved by detecting whether the libc is POSIX (by checking _POSIX_VERSION for example) and then using the appropriate function. However, as pointed out in #1198, the issue is that gmtime() is not thread safe. Do you think we should provide some sort of _ALT option, perhaps something else, to allow platforms like Mbed OS to deal with this sort of problem safely?

@simonbutcher simonbutcher changed the title Build failure with ARM C toolchain Build fails if gmtime_s() or gmtime_r() are not available Aug 22, 2018
@simonbutcher
Copy link
Contributor

There's actually an underlying problem here that armcc doesn't actually support gmtime() either! It actually always returns NULL.

The fix in #1927 will doubtless help someone, but it doesn't help Mbed OS. The PR in #1927 will now allow the code to build - but it still won't yield a useful date and time nor do the right certificate date checks.

Therefore, I've changed the title to 'Build fails if gmtime_s() or gmtime_r() are not available' and created a new bug of #1975 - 'Arm C Compiler doesn't support gmtime()'.

@andresag01
Copy link
Contributor

@sbutcher-arm: Thanks for the information regarding the state of gmtime() for armcc.

While the PR #1927 does not fully resolve the armcc situation for Mbed OS, I do think that it is a first step towards fixing the issue for Mbed OS. This is because #1927 allows us to configure an implementation for gmtime() at compile time. So in the case of Mbed OS, we could detect the supported toolchains/libcs that do not have a gmtime() and automatically configure a suitable implementation.

@simonbutcher
Copy link
Contributor

The Arm C Compiler does not support gmtime() or gmtime_r(). It's not intended that the Mbed TLS project should provide implementations for these functions when the platform doesn't so on platforms where it's not available, we now have in PR #1927 which has now been merged support to allow 3rd parties to provide their own implementation.

In addition, on Mbed OS, date/time support is now disabled by default with Mbed OS PR #7868, so the build is no longer broken. Therefore this issue can now be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants