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

CLOCK_UPTIME_RAW isn't always available on __APPLE__ #15957

Closed
adamnovak opened this issue Feb 26, 2024 · 5 comments · May be fixed by #16951
Closed

CLOCK_UPTIME_RAW isn't always available on __APPLE__ #15957

adamnovak opened this issue Feb 26, 2024 · 5 comments · May be fixed by #16951
Labels
inactive Denotes the issue/PR has not seen activity in the last 90 days.

Comments

@adamnovak
Copy link

adamnovak commented Feb 26, 2024

Since 76d05d4 and #15554, Protobuf tries to always use CLOCK_UPTIME_RAW if compiled for an __APPLE__ system:

#if !defined(GOOGLE_PROTOBUF_NO_RDTSC)
#if defined(__APPLE__)
// Use a commpage-based fast time function on Apple environments (MacOS,
// iOS, tvOS, watchOS, etc).
s = clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
#elif defined(__x86_64__) && defined(__GNUC__)

But that symbol isn't always defined. On my machine, the MacOSX 14.2 SDK time.h only defines it if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) evaluates to true:

#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
_CLOCK_MONOTONIC_RAW __CLOCK_AVAILABILITY = 4,
#define CLOCK_MONOTONIC_RAW _CLOCK_MONOTONIC_RAW
_CLOCK_MONOTONIC_RAW_APPROX __CLOCK_AVAILABILITY = 5,
#define CLOCK_MONOTONIC_RAW_APPROX _CLOCK_MONOTONIC_RAW_APPROX
_CLOCK_UPTIME_RAW __CLOCK_AVAILABILITY = 8,
#define CLOCK_UPTIME_RAW _CLOCK_UPTIME_RAW
_CLOCK_UPTIME_RAW_APPROX __CLOCK_AVAILABILITY = 9,
#define CLOCK_UPTIME_RAW_APPROX _CLOCK_UPTIME_RAW_APPROX
#endif

And Protobuf doesn't seem to define the appropriate macros to enable non-POSIX Darwin features before it includes time.h:

#if !defined(GOOGLE_PROTOBUF_NO_RDTSC) && defined(__APPLE__)
#include <time.h>
#endif

This leads to a build failure in my project, which defines _POSIX_C_SOURCE to get Posix 2008 features, but does not define _DARWIN_C_SOURCE because it does not directly use Darwin extensions.

    /usr/local/Cellar/protobuf/25.3/include/google/protobuf/map.h:694:31: error: use of undeclared identifier 'CLOCK_UPTIME_RAW'
        s = clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
                                  ^

Protobuf should either set the right macros for the features it needs itself, or else document the macros that user code must (or must not) define to build against Protobuf. Or, Protobuf should check the defined macros and use only features that will be available.

Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

@github-actions github-actions bot added the inactive Denotes the issue/PR has not seen activity in the last 90 days. label May 27, 2024
@adamnovak
Copy link
Author

It doesn't look like this problem has gone away of its own accord; the offending code still seems to be present in the current version.

adamnovak added a commit to adamnovak/protobuf that referenced this issue May 28, 2024
This will fix protocolbuffers#15957 by not trying to use CLOCK_UPTIME_RAW if the feature test macros are not currently set to make it available.

Since the build system is in charge of the feature test macros, and since this header might be included under any end user program's build system, we can't just #define the macros we would like.
@github-actions github-actions bot removed the inactive Denotes the issue/PR has not seen activity in the last 90 days. label May 29, 2024
Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago. This issue will be closed and archived after 14 additional days without activity.

@github-actions github-actions bot added the inactive Denotes the issue/PR has not seen activity in the last 90 days. label Aug 28, 2024
Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 11, 2024
@adamnovak
Copy link
Author

This issue is still active; it is waiting on a review of the associated PR #16951

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inactive Denotes the issue/PR has not seen activity in the last 90 days.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant