Skip to content

Commit 87c9c01

Browse files
More robust clobbering of ARM builtins on host (#2657)
Since ARM hosts have builtins listed in hardware/sync.h, these builtins should be clobbered. Newer versions of LLVM/Clang emit an error when clobbering these builtins, so this switches the overrides to use the same patterns as pico_atomic to clobber the builtins.
1 parent 17b9144 commit 87c9c01

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/host/hardware_sync/include/hardware/sync.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ extern "C" {
109109

110110
void __sev();
111111

112-
void __wev();
113-
114112
void __wfi();
115113

116114
void __wfe();

src/host/hardware_sync/sync_core0_only.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,44 @@ void PICO_WEAK_FUNCTION_IMPL_NAME(spin_unlock)(spin_lock_t *lock, uint32_t saved
9393
spin_unlock_unsafe(lock);
9494
}
9595

96-
PICO_WEAK_FUNCTION_DEF(__sev)
96+
// These are defined on ARM hosts, but don't do what we want for the host
97+
// since this is a simulated build.
98+
99+
#if PICO_C_COMPILER_IS_GNU || !__has_builtin(__sev)
100+
#define __sev_c __sev
101+
#else
102+
#pragma redefine_extname __sev_c __sev
103+
#endif
104+
105+
#if PICO_C_COMPILER_IS_GNU || !__has_builtin(__wfi)
106+
#define __wfi_c __wfi
107+
#else
108+
#pragma redefine_extname __wfi_c __wfi
109+
#endif
110+
111+
#if PICO_C_COMPILER_IS_GNU || !__has_builtin(__wfe)
112+
#define __wfe_c __wfe
113+
#else
114+
#pragma redefine_extname __wfe_c __wfe
115+
#endif
116+
117+
PICO_WEAK_FUNCTION_DEF(__sev_c)
97118

98119
volatile bool event_fired;
99120

100-
void PICO_WEAK_FUNCTION_IMPL_NAME(__sev)() {
121+
void PICO_WEAK_FUNCTION_IMPL_NAME(__sev_c)() {
101122
event_fired = true;
102123
}
103124

104-
PICO_WEAK_FUNCTION_DEF(__wfi)
125+
PICO_WEAK_FUNCTION_DEF(__wfi_c)
105126

106-
void PICO_WEAK_FUNCTION_IMPL_NAME(__wfi)() {
127+
void PICO_WEAK_FUNCTION_IMPL_NAME(__wfi_c)() {
107128
panic("Can't wait on irq for host core0 only implementation");
108129
}
109130

110-
PICO_WEAK_FUNCTION_DEF(__wfe)
131+
PICO_WEAK_FUNCTION_DEF(__wfe_c)
111132

112-
void PICO_WEAK_FUNCTION_IMPL_NAME(__wfe)() {
133+
void PICO_WEAK_FUNCTION_IMPL_NAME(__wfe_c)() {
113134
while (!event_fired) tight_loop_contents();
114135
}
115136

@@ -146,4 +167,4 @@ int PICO_WEAK_FUNCTION_IMPL_NAME(spin_lock_claim_unused)(bool required) {
146167
PICO_WEAK_FUNCTION_DEF(spin_lock_num)
147168
uint PICO_WEAK_FUNCTION_IMPL_NAME(spin_lock_num)(spin_lock_t *lock) {
148169
return 0;
149-
}
170+
}

0 commit comments

Comments
 (0)