18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: LGPL-2.1-only OR MIT */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * rseq/compiler.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Work-around asm goto compiler bugs.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * (C) Copyright 2021 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef RSEQ_COMPILER_H
118c2ecf20Sopenharmony_ci#define RSEQ_COMPILER_H
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/*
148c2ecf20Sopenharmony_ci * gcc prior to 4.8.2 miscompiles asm goto.
158c2ecf20Sopenharmony_ci * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci * gcc prior to 8.1.0 miscompiles asm goto at O1.
188c2ecf20Sopenharmony_ci * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103908
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci * clang prior to version 13.0.1 miscompiles asm goto at O2.
218c2ecf20Sopenharmony_ci * https://github.com/llvm/llvm-project/issues/52735
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * Work around these issues by adding a volatile inline asm with
248c2ecf20Sopenharmony_ci * memory clobber in the fallthrough after the asm goto and at each
258c2ecf20Sopenharmony_ci * label target.  Emit this for all compilers in case other similar
268c2ecf20Sopenharmony_ci * issues are found in the future.
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_ci#define rseq_after_asm_goto()	asm volatile ("" : : : "memory")
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#endif  /* RSEQ_COMPILER_H_ */
31