Commit f3c7f77
committed
features_cpu, rcheevos: shim clock_gettime on pre-10.12 macOS
clock_gettime() was added to Darwin in macOS 10.12 Sierra / iOS 10.0
(2016). On Leopard (10.5) and every other pre-10.12 macOS target,
the symbol doesn't exist in libSystem and the link fails:
undefined reference to 'clock_gettime'
Two call sites in the current build:
libretro-common/features/features_cpu.c:
Already has an ra_clock_gettime shim that falls back to
gettimeofday(), but the gate is iOS-only:
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 100000
On macOS the shim is bypassed and ra_clock_gettime is
#define'd to clock_gettime, producing the link error.
FIX: introduce RA_NEEDS_CLOCK_GETTIME_SHIM defined when either
iOS deployment target < 10.0 or macOS deployment target < 10.12,
and use that flag instead of the iOS-only check. Add the
required #include <AvailabilityMacros.h>.
deps/rcheevos/src/rc_client.c:
Direct call in rc_client_clock_get_now_millisecs(), guarded by
#if defined(CLOCK_MONOTONIC). The function has a perfectly good
#else fallback using clock()+time().
FIX: #undef CLOCK_MONOTONIC at file scope on pre-10.12 macOS so
the function's #if cascade falls through to the clock()+time()
path. <time.h> is transitively included through rc_api_info.h
at the top of the file, so the #undef takes effect. No rcheevos
logic changed - this is a preprocessor-level selector flip.
Both gates use MIN_REQUIRED (deployment target) rather than
MAX_ALLOWED (SDK version). That's correct here: Apple weak-links
clock_gettime when the deployment target is < 10.12, even when
compiling against a modern SDK where the declaration is visible.
The question is "can this binary run on a pre-10.12 system," which
is exactly what MIN_REQUIRED answers.
audio/librsound.c's clock_gettime call is already fenced behind a
__MACH__ check that routes macOS through host_get_clock_service
instead, so no change needed there.
No behavioral change on 10.12+ macOS, iOS 10.0+, or any other
platform: the shim is only compiled in when the deployment target
predates those versions.1 parent f8774b4 commit f3c7f77
2 files changed
Lines changed: 33 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
24 | 43 | | |
25 | 44 | | |
26 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| 118 | + | |
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
| |||
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
131 | 140 | | |
132 | 141 | | |
133 | 142 | | |
| |||
141 | 150 | | |
142 | 151 | | |
143 | 152 | | |
144 | | - | |
| 153 | + | |
145 | 154 | | |
146 | 155 | | |
147 | 156 | | |
| |||
0 commit comments