Skip to content

Add POSIX times() support #51978

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

Open
tenllado opened this issue Nov 4, 2022 · 7 comments
Open

Add POSIX times() support #51978

tenllado opened this issue Nov 4, 2022 · 7 comments
Assignees
Labels
area: Modules area: newlib Newlib C Standard Library area: POSIX POSIX API Library Enhancement Changes/Updates/Additions to existing features

Comments

@tenllado
Copy link
Contributor

tenllado commented Nov 4, 2022

Describe the bug

Using the newlib libc in Zephyr, the clock() and/or time() functions call the _times_r function which requires the _times function to be supplied, but this function is missing and the compilation fails at link time.

I have tested this while trying to create a lua module for Zephyr. Lua uses both the clock() and the time() function and the compilation fails with the following error:

... zephyr-sdk-0.15.0/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m/nofp/libc.a(lib_a-timesr.o): in function _times_r': timesr.c:(.text._times_r+0x2): undefined reference to _times'
collect2: error: ld returned 1 exit status

To Reproduce

I prepared a hello_world example available at: https://github.com/tenllado/zephyr_hello_world_lua

The README.md file contains instructions to compile it as a west workspace. The project includes a file src/missing_stubs.c a definition of _times (and also _unlink, which is also missing in Zephyr). If you comment the _times definition you will obtain the error mentioned above.

Expected behavior
Zephyr should be including a definition of the _times function for the newlib libc library.

Impact
The absence of this function prevents the full support of the lua library for the zephyr project.

Environment (please complete the following information):

  • OS: Linux
  • Toolchain: zephyr-sdk-0.15.0
  • Commit SHA: sha for the zephyr project is 8db84cf
@tenllado tenllado added the bug The issue is a bug, or the PR is fixing a bug label Nov 4, 2022
@stephanosio stephanosio added the area: newlib Newlib C Standard Library label Nov 5, 2022
@stephanosio
Copy link
Member

times is a POSIX function and it is currently not available in the Zephyr POSIX subsystem.

@stephanosio stephanosio added Enhancement Changes/Updates/Additions to existing features area: POSIX POSIX API Library and removed bug The issue is a bug, or the PR is fixing a bug area: newlib Newlib C Standard Library labels Nov 5, 2022
@stephanosio stephanosio changed the title newlib integration: _times isn't mapped to _times_r Add POSIX times() support Nov 5, 2022
@stephanosio
Copy link
Member

Converted to enhancement since newlib cannot map a POSIX function to the POSIX subsystem when it is not implemented by the POSIX subsystem.

@stephanosio stephanosio self-assigned this Nov 5, 2022
@stephanosio stephanosio added the area: newlib Newlib C Standard Library label Nov 5, 2022
@stephanosio
Copy link
Member

I did a brief investigation and the ISO C function clock() does depend on the POSIX times(), which is indeed a problem. I will provide a fix such that clock() does not depend on times().

p.s. ISO C time() does not require POSIX times(); instead, it requires _gettimeofday(), which is already provided by the newlib libc-hooks. That aside, the libc hook implementation depending on the POSIX gettimeofday() should not be the case.

@cfriedt
Copy link
Member

cfriedt commented Nov 22, 2022

Just added the modules label, as this blocks the Lua module

@cfriedt cfriedt modified the milestone: v3.4.0 May 2, 2023
@cfriedt
Copy link
Member

cfriedt commented May 2, 2023

Just dropping this link here for myself mainly.
https://github.com/zephyrproject-rtos/newlib-cygwin/blob/zephyr-newlib-3.3.0/newlib/libc/time/clock.c

I'm trying to recall how I tied this into sysconf() - perhaps it's not as related as I thought.

@cfriedt
Copy link
Member

cfriedt commented Jun 1, 2023

@stephanosio - do you still want to provide a fix for this, or would #57800 work?

Also, not sure if we should consider this an enhancement or a bug.

@cfriedt cfriedt removed this from the v3.4.0 milestone Jun 1, 2023
@tenllado
Copy link
Contributor Author

tenllado commented Jun 1, 2023

I think that #57800 would fix the problems I am having.

@cfriedt cfriedt modified the milestone: v3.5.0 Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Modules area: newlib Newlib C Standard Library area: POSIX POSIX API Library Enhancement Changes/Updates/Additions to existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants